I'm writing a problem which asks students to simplify an expression of the form ax^b, where:

- a is randomly either 1 or -1,
- x and b are both random integers which are not too large, and
- b is not negative if x is zero.

I'm using the **LimitedFraction** context and assigning the answer flag **studentMustReduceFractions**.

The issue occurs when the base x happens to be equal to 0, and in this case the final answer (which should be 0) is not being correctly computed. I'm having difficulties inserting the screenshot into the post, but I've included a link to the image here: https://imgur.com/a/YnxQmo9

For context, I've included the full problem as an attachment, but for the purpose of my question here is a MWE that produces the issue:

DOCUMENT(); loadMacros( "PGstandard.pl", "contextFraction.pl", "PGML.pl" ); TEXT(beginproblem()); Context("Fraction"); $ans = Fraction(0,1)->cmp(studentsMustReduceFractions => 1); $ans = -$ans; BEGIN_PGML What does the fraction [`\frac{0}{1}`] reduce to? Answer: [___]{$ans} END_PGML ENDDOCUMENT();

The problem is caused only by the combination of applying the answer flag, and then replacing the answer with its negation. If either the flag application or the negation assignment are removed, the problem disappears.

Fortunately this does yield a work-around (applied in the attachment), which consists of applying the answer flag only if x is not equal to 0, but I'm going crazy trying to figure out what exactly is happening here.

Can anyone explain this issue? or is it possibly a bug?