I'm puzzled by what I'm seeing in the LimitedFraction context.

When the correct answer is -4/3, the checker does reject -8/6 and warns the student that his/her answer is not reduced.

But when I assign 0 as the correct answer, the checker accepts 0/5 as correct, and when I assign

-4 as the answer, the checker accepts -8/2.

I would like the checker to reject any rational expression m/n when the answer is actually an integer (when in the LimitedFraction context).

#-------

loadMacros(

"PGstandard.pl", # Standard macros for PG language

"MathObjects.pl",

"contextFraction.pl",

);

Context("LimitedFraction");

$ans1 = Compute("-4/3");

$ans2 = Compute("0");

$ans3 = Compute("-4");

Context()->flags->set(formatStudentAnswer=>'parsed');

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

Context()->texStrings;

BEGIN_TEXT

$PAR

1. \{ ans_rule(4) \} 2. \{ ans_rule(4) \} 3. \{ans_rule(4) \}

END_TEXT

Context()->normalStrings;

ANS( $ans1->cmp(studentsMustReduceFractions=>1,showProperFractions=>0) );

ANS( $ans2->cmp(studentsMustReduceFractions=>1,showProperFractions=>0) );

ANS( $ans3->cmp(studentsMustReduceFractions=>1,showProperFractions=>0) );

#---

Thanks.

Bruce

$ans1 = Fraction("-4/3"); $ans2 = Fraction("0"); $ans3 = Fraction("-4");should work. (This is one of the few cases where you want to use the explicit constructor rather than

`Compute()`

, because you are coercing one object type to be another.)
Note also that

Context()->flags->set(formatStudentAnswer=>'parsed'); Context()->flags->set(reduceConstantFunctions=>0);are not needed, here(but may be used by other parts of your actual problem). In any case, you can combine them as

Context()->flags->set( formatStudentAnswer=>'parsed', reduceConstantFunctions=>0, );if you do need them.

Finally, note that ` studentsMustReduceFractions=>1, showProperFractions=>0`

are the default for the `LimitedFraction`

context, and so do not need to be given explicitly in the `ANS()`

calls. You can just do

ANS( $ans1->cmp ); ANS( $ans2->cmp ); ANS( $ans3->cmp );and still have the same effect. If you really DO want to specify these values explicitly, you can add them to the context so that you don't have to enter them three times:

Context()->flags->set( studentsMustReduceFractions=>1, showProperFractions=>0, ); ANS( $ans1->cmp ); ANS( $ans2->cmp ); ANS( $ans3->cmp );but again, these are already set in the

`LimitedFraction`

context.
Hope that does the trick for you.

Davide

Thanks, that helped.

But I found that I needed to keep

$ans1 = Compute("-4/3");

because when I used

$ans1 = Fraction("-4/3");

WeBWorK marked the answer -4/3 as incorrect, showing the correct answer as

-1333333/1000000

And then I did seem to need

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

Things do now seem to work as I'd like.

Bruce

I'm glad you have things working now.

Davide