The Mathematica Journal
Download This Issue
Feature Articles
Graphics Gallery
Tricks of the Trade
In and Out
The Mathematica Programmer
New Products
New Publications
News Bulletins
Editor's Pick
Write Us
About the Journal
Staff and Contributors
Back Issues

Generating Programs

In the context of an object-oriented programming language such as C++, which has been used to implement EM, an "object" usually refers to an abstraction in the program that incorporates both data structure and behavior. All objects of a given type (class) share the same "behavior" but maintain their own data structure. The data structure of each object is initialized when the object is constructed. Because EM implements the "behavior" for all "known" types of objects, in order to create an exercise we only need to specify what types of objects are involved and provide appropriate information (attributes) needed to initialize their data structures. This is exactly the purpose of the generating program. It should define the entire collection of objects as a list and assign this list to the symbol exerciseList.


Any of the objects should be defined as


Forming two separate sublists of exerciseList is a convention used to distinguish the objects in the problem statement from those in the answer template. In the object definition list, object-tag and object-type are strings. Of course, object-type should be among the "known" types mentioned before. object-tag will be used by EM as a symbol to which an expression may be assigned. This is explained later in more detail. We distinguish between the object-value of an object and the rest of its object-attributes. The value is an attribute, which is also an expression. It carries the mathematical essence of the object. It is either a double nested list of integers for objects of type Matrix or MatrixEntry, or a list of True/False symbols for objects of type CheckBoxes or RadioControls. Since we calculate this value by using random numbers, it is different each time the generating program is evaluated. The other attributes, which are only used to determine the visual outlook of the objects in the names of matrices seen by students, labels of check boxes, or radio controls, etc., should be given as strings.

As an example, consider the generating program of the "Add Two Matrices" exercise (see Figure 2) given in Listing 1. It uses several functions implemented in a package which EM loads at startup. This utility package significantly simplifies the creation of new matrix algebra exercises since various useful functions can be readily used. From this package, GenValues generates values for the symbols in the first list of its arguments by calling the standard Random function with arguments given in the second list. Similarly, GenMatrix generates a matrix. LoMatrixQ, UpMatrixQ, and DiagMatrixQ are predicates evaluating to True if the argument is lower-triangular, upper-triangular, or diagonal matrix, respectively. The program first generates the size of the matrices into n. Then two square matrices of size n are generated and assigned to a and b. The sum of a and b is assigned to c. Then we assign to rightBx a list to be used as the value of the CheckBoxes object. The final step is to construct exerciseList. There are two object definitions in the problem statement (the left pane in Figure 2), both of type Matrix. The answer template (the right pane in Figure 2) is comprised of one object of type MatrixEntry and one of type CheckBoxes.

Listing 1. Generating program for "Add Two Matrices."

Converted by Mathematica      October 5, 1999

[Prev Page][Next Page]