# MathObjects - Object system for manipulating mathematics in PG.

### From WeBWorK

# NAME

MathObjects - Object system for manipulating mathematics in PG.

# OVERVIEW

This directory contains documentation for the MathObjects library that is part of the WeBWorK on-line homework and testing system. MathObjects let you work with mathematical functions and values within your WeBWorK problems in a mathematically natural way, and provides a uniform way of creating answer checkers, processing student input, and generating mathematical output as part of your questions.

Currenlty, the MathObject library includes:

**real and complex numbers,****points, vectors, and matrices (with real or complex entries)****arbitrary lists of elements****intervals, set, and unions****predefined strings like 'NONE' and 'DNE'****infinity and negative infinity****formulas whose inputs and outpus are any of the objects above**

Some other useful features of MathObjects are that you can write sin^2 x for (sin(x))^2 and sin^-1 x for arcsin(x), and so on.

The the MathObject library was designed to be extensible, so that you could add your own functions, operators, and data types. WeBWorK comes with a number of extensions already (found in the pg/macros directory), which implement specialized types, like scientific notation, currency values, fractions, chemical reactions, factored polynomials, rational functions, and so on.

# SAMPLE FILES

Sample problems are given in the 'problems' and 'extensions' directories of this directory. Move their contents to the templates directory of a course where you want to try out MathOjects, and move the contents of the macros directory to that course's macros directory.

Now try looking at these problems using the Library Browser. Edit the source to see how they work, and to read the comments within the code itself. A large number of practical examples using MathObjects are available on the WeBWorK wiki (http://webwork.maa.org/wiki/Category:Authors).

The 'problems' directory contains several examples that show how to use MathObjects within your problem files.

**problems/sample01.pg**-
Uses MathObjects to make a string into a formula that you can evaluate and print in TeX form.

**problems/sample02.pg**-
Shows how to create formulas using perl's usual mathematical expressions rather than character strings.

**problems/sample03.pg**-
Shows how to use the parser's differentiation abilities.

**problems/sample04.pg****problems/sample05.pg**-
Use the parser in conjunction with the graphics macros to generate function graphs on the fly. These also show how to create a perl function to evaluate an expression.

**problems/sample06.pg**-
Shows some simple use of vectors in a problem.

**problems/sample07.pg**-
Example if using the build-in Real object and its answer checker

**problems/sample08.pg**-
Uses complex numbers and the built-in checker

**problems/sample09.pg****problems/sample10.pg**-
Demonstrates points and vectors and their answer checkers

**problems/sample11.pg****problems/sample12.pg**-
Shows the answer checkers for intervals and unions.

**problems/sample13.pg****problems/sample14.pg****problems/sample15.pg**-
Demonstrate various list checkers, including a check for the word 'NONE', which is a predefined string.

**problems/sample16.pg****problems/sample17.pg****problems/sample18.pg**-
These show the multi-variable function checker in use (for functions of the form R->R, R^2->R and R->R^3).

**problems/sample19.pg**-
Uses the function checker to implement a "constant" that can be used in formulas.

**problems/sample20.pg**-
Shows how to use the parser's substitution abilities.

**problems/sample21.pg**-
Checks for a list of points.

**problems/sample22.pg**-
Shows how to provide named constants that the student can use in his answer.

The 'examples' directory contains samples that show how to extend the parser to include your own functions, operators, and so on. There are also some samples of how to call the methods available for Formula MathObjects, and what some error messages look like.

**examples/1-function.pg**-
Adds a single-variable function to the parser's list of functions.

**examples/2-function.pg**-
Adds a two-variable function to the parser.

**examples/3-operator.pg**-
Adds a binary operator to the parser. (Unary operators are similar.)

**examples/4-list.pg**-
Adds a new "list type" object. In this case, it's really an operation [n,r] that returns n choose r.

**examples/5-list.pg**-
Add a new "equality" operator that you can use to handle answers like "x+y=0".

**examples/6-precedence.pg**-
Shows an experimental precedence setting that can be used to make sin 2x return

`sin(2x)`

rather than (sin(2))x. **examples/7-context.pg**-
Shows how to switch contexts (in this case, to complex and to vector contexts), and how this affects the parsing.