`reduce()`

method is to get rid of coefficients like `1x`

, to remove terms like `0x`

, and to make things like `x + (-2)`

into `x-2`

. The only algebraic changes it makes is to factor our minus signs so that it can cancel them, and it will rewrite `-2x+3`

as `3-2x`

. other than that, it leaves your expression alone. The complete list of reductions is available on the Wiki, and you can see that it is not extensive. That is what I mean by "MathObject is not a CAS".

If you want to have the derivative formula in a particular form that is not what the

`D()`

method produces, you will need to enter that as a `Formula()`

yourself.

**Is there a way that I can require students to enter their answers in a reduced form and perhaps prompt them to reduce such an answer?**No, there is no context that enforces that at the moment. WeBWorK's philosophy in general is to allow any equation that is equivalent to the answer, rather than enforcing particular formats for the problems. For example, there is nothing stopping a student from entering

`x+1-1`

for an answer that expects `x`

. We have found that trying to enforce too much structure on the answer is counter productive in general.Would you disallow

`5/6x + 2/3x`

for example? Both fractions are reduced, and the answer is equivalent. Once you allow some computation (as you do in a Formula), it becomes much more difficult to tell students which operations are allow and which are not. For many equations, it is not clear what the "most reduced" form should be, and students get quite frustrated if they have the "right" answer but WeBWorK doesn't accept it because the form is different from what the instructor wants. For example, you have not indicated that the answer has to be an any particular reduced form, so it would come as a surprise if their answer were marked wrong when it is numerically correct.A note about fomat: you are using a heading for your formula, which is a bad idea, in general, since your question is

*not*a heading. This may not seem like much of an issue, but you should not misuse the semantics of the layout that you are creating. For example, students with visual challenges who need screen readers will get the wrong idea from your problem, since they will be informed that your question is a 3rd-level heading, and this will be extra confusing because there is no 1st or 2nd-level headings. If you want bold lettering, use bold, not headings (but I'd still recommend you not use bold either, as there is no need for it to be highlighted).

Do not over specify layout. You may think you are making things look nicer, but you are just making things harder for people in the long run.

WeBWorK does have a few contexts for certain well-defined situations. One is the LimitedPolynomial context defined

`contextLimitedPolynomial.pl`

. It provides a means of requires polynomials in expanded form, so would allow `x^2-2xy+y^2`

but not `(x-y)^2`

. So that could be used for the second version.For the first, there is a RationalFunction context defined in

`contextRationalFunction.pl`

that forces the student answer to be a rational function (a quotient of polynomials), but it doesn't require the quotient to be reduced. You could use this to ensure that the result is a rational function equal to the right answer, and then use a custom checker to take apart the fraction and test the numerator to see if it matches the numerator of the correct answer. That would ensure that it is reduced (provided the correct answer is).This approach could be used for Tim Payer's 9/6x as well, but I would not want to use the RationalFunction context there, as that would give away something about the form of the answer if the student entered certain incorrect answers. But a custom checker that checked if the answer is correct, is a fraction, and has numerator equal to what you expect could be used to check for the reduced fraction.

I'll see if I can put tougher an example before class today.

DOCUMENT(); loadMacros( "PGstandard.pl" "MathObejcts.pl", "PGML.pl", "contextRationalFunction.pl", "PGcourse.pl", ); Context("RationalFunction"); Context()->variables->are(x=>'Real',y=>'Real'); $f = Formula("4x^2/y^2"); $cmp = $f->cmp(checker => sub { my ($correct,$student,$ans) = @_; return 0 unless $correct == $student; return 0 unless $student->{tree}->class eq "BOP" && $student->{tree}{bop} eq "/"; my $cnum = Formula($correct->{tree}{lop}); my $snum = Formula($student->{tree}{lop}); Value->Error("Your answer isn't reduced") unless $cnum == $snum; return 1; }); BEGIN_PGML [:8x^3/(2xy^2):] reduces to [_____________]{$cmp} END_PGML ENDDOCUMENT();

The custom checker tests whether the student and correct answer are equal (and return 0 if not), then checks if they student answer is a fraction (so that we know we can remove its numerator for the next test), and if so, it takes the numerators of both the correct and student answers and makes them in to Formula objects on their own, and compares them. If they are not equal, we produce a message for the student telling her that the answer isn't reduced (we already know it is correct). Otherwise, we return 1 for full credit.

Tim could use essentially the same custom checker for his situation, but in the Numeric context. Note, however, that this would not prevent answers like `3/(1+1)x`

or `3/(2x-x)`

in his case, since we are not enforcing polynomial format in the Numeric context.