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:

Context()->flags->set(reduceConstants=>0);

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?

Thanks,

- Brian

D. Brian Walton

James Madison University

loadMacro("contextFraction.pl"); Context("Fraction"); $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.

Davide