WeBWorK Main Forum

combining contexts (piecewise functions and fractions)

Re: combining contexts (piecewise functions and fractions)

by Alex Jordan -
Number of replies: 0
I'm afraid not, at least not with any context I am familiar with. I think that the definition of the / symbol would have to be enhanced to do that. Maybe if its two operands could both be identified as simple integers, then maybe there would be a way to make that happen. But I'm pretty certain that you won't get things like Formula("2x/4") to automatically become "\frac{x}{2}" without external help from a CAS.

But back to those three examples. If I am in a situation where I need to use Formula("$a/$b x"), then along with turning off the reduceConstants flag, I also use the Fraction context to make $frac=Fraction($a,$b), and then make Formula("$frac x"). This will leave each of the three cases that you gave displaying as you want.

Just to be clear, all of this is about how Formulas will be displayed. If you want simplified expressions from students, then other techniques are needed (like bizarroArithmetic.pl).