WeBWorK Problems

MathObjects: reduce and reduceConstants

MathObjects: reduce and reduceConstants

by D. Brian Walton -
Number of replies: 1
I would like to display MathObjects formulas with fractions expressed as rational numbers, but allowing the student to submit answers in either decimal or fraction form.

If I set the context using the reduceConstants setting:


then the formula appears with fractions not being reduced.

However, suppose that I wish to use the reduce method to simplify other aspects of the formula (such as change x^1 to x, or -(-x) to +x, etc.). This does not respect the reduceConstants setting and collapses the fraction back to a decimal approximation.

Is there a way to use the reduce method while retaining fractions?

- Brian

D. Brian Walton
James Madison University
In reply to D. Brian Walton

Re: MathObjects: reduce and reduceConstants

by Davide Cervone -
Have you tried using the Fraction context? It is in the pg/macros/contextFraction.pl file.

    $F = Formula("(1/3)x^1-(-x)+0")->reduce;
yields $F equal to "(1/3)*x+x". I think that should do what you want.

Read the comments in the file for additional details.