MathObjects - Object system for manipulating mathematics in PG.

From WeBWorK

Jump to: navigation

NAME

MathObjects - Object system for manipulating mathematics in PG.

OVERVIEW

This directory contains the documentation for a new mathematical-expression parser written in perl. It was developed for use with the WeBWorK on-line homework system, but it can be used in any perl program.

The goal was to process vector-valued expressions, but the parser was designed to be extensible, so that you could add your own functions, operators, and data types. It is still a work in progress, but should provide a framework for building more sophisticated expression handling.

Currenlty, the parser understands:

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

Most of the documentation still needs to be written, but you can get some ideas from the samples in the problems and extensions directories, and by reading the files in the docs directory.

INSTALLATION

The parser should already be installed as part of the WeBWorK 2.1 distribution, so you should not need to install it separately. If you don't seem to have it installed, then it can be obtained from the Union CVS repository at http://devel.webwork.rochester.edu/twiki/bin/view/Webwork/WeBWorKCVS

The README file in that directory contains the installation instructions.

SAMPLE FILES

Sample problems are given in the problems and extensions directories. Move these to the templates directory of a course where you want to test the Parser, 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.

EXAMPLE FILES

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

problems/sample01.pg

Uses the parser 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 objects generated by the parser, and what some error messages look like.

examples/1-function.pg

Adds a single-variable function to the parsers 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.

examples/8-answer.pg

Implements a simple vector-valued answer checker using the parser's computation and comparison ability.

SEE ALSO

sample01.pg in the problems manpage.

union_problib