bizzaroArithmetic.pl redefines arithmetic operators in a way that can be...

... leveraged to distinguish different forms of answers. This is applied in contextLimitedRadical.pl (for requiring reduced radicals) and in contextLimitedFactor.pl (for requiring a factorization that matches the author's)

bizarroArithmetic.pl is the real contribution here, but it may be hard to see what it is good for by itself. So we are submitting contextLimitedFactor.pl and contextLimitedRadical.pl at the same time. These two contexts use bizarroArithmetic.pl, which we are using regularly at lower levels where instructors want limited flexibility in the forms of answers. Here are some example problems:

In this one, see the feedback from entering partially factored answers. Keep in mind that at lower levels instructors will want answers factored over Z[x], not over R[x].
DOCUMENT();
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "PGML.pl",
  "contextLimitedFactor.pl",
);
##############################################
Context("LimitedFactor");
Context()->noreduce('(-x)-y','(-x)+y');
Context()->variables->are("x"=>'Real');
Context()->strings->add("cannot be factored"=>{},
    "cannot be factored."=>{alias=>"cannot be factored"});
Context()->strings->add('prime'=>{}, 'it is prime'=>{alias=>'prime'});
# the coefficients
$a = random(1,3,1);
do {$b = random(1,3,1)} until ($a!=$b);
$question = Formula("$a^4*x^4-$b^4")->reduce;
$ans = Formula("($a*x-$b)($a*x+$b)($a^2*x^2+$b^2)")->reduce;
##############################################
TEXT(beginproblem());
BEGIN_PGML
Factor the given polynomial 

    [`[$question]=`] [___________________________]{$ans}

If the expression cannot be factored then answer with *prime*.
END_PGML
ENDDOCUMENT();



In this one, see the feedback from trying various numerically correct answers that are not simplified:
DOCUMENT();
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "PGML.pl",
  "contextFraction.pl",
  "contextLimitedRadical.pl",
);
######################################
Context("LimitedRadical");
$a = random(2,9,1);
$b = random(2,9,1);
$c = $a*$b;
$d =list_random(2,5,11);
$e =list_random(3,13,7);
$f = $d*$e;
$h = Formula("$c*sqrt($f)");

######################################
TEXT(beginproblem());
BEGIN_PGML
Simplify the expression. Use *sqrt()* for the square root symbol. For example: [`\sqrt{2} =`]  *sqrt(2)*.

    [`[$a]\sqrt{[$e]} \cdot [$b]\sqrt{[$d]}=`] [_____________]{$h}

END_PGML

ENDDOCUMENT();