If I change the required input (where I have "$p") to a constant number, then it works and the message shows up. But if I change it to 'x' or '6 x' or anything else, and try entering that as the denominator, it just says that it's incorrect, no customized message. Why is it doing that?
------------------------------------------------
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextLimitedPolynomial.pl",
"contextPolynomialFactors.pl",
"contextLimitedPowers.pl",
"answerHints.pl"
);
Context("Numeric");
$a=non_zero_random(3,6);
$aa=$a**2;
$b=non_zero_random(1,5);
if ($b==$a) {$b++};
$c=non_zero_random(2,5);
if ($c==$a) {$c++};
$denom=Compute("x^2-$aa");
Context("LimitedPolynomial-Strict");
$p[0]=$b+1;
$p[1]=-$c-$a*$b;
$num=Compute("$p[0] x+$p[1]")->reduce;
Context()->texStrings;
BEGIN_TEXT
$BBOLD Simplifying Rational Expressions. $EBOLD Understand how to
manipulate rational expressions. They work just like fractions!
$BR
\[\frac{x-$c}{x^2-$aa} + \frac{$b}{x+$a} = \frac{A}{B} \]
where \(A\) and \(B\)
are polynomials of degree as low as possible
and the leading coefficient of \(B\) is 1.
$BR
A= \{ ans_rule(15) \} $BR
B=\{ ans_rule(15) \}
$PAR
Your numerator should be simplified (multiplied out and combined), while your denominator can be simplified or left in factored form. However, make sure that it has the lowest possible degree!
END_TEXT
Context()->normalStrings;
ANS($num->cmp->withPostFilter(sub {
my $ans = shift;
$ans->{ans_message} = 'This needs to be multiplied out and simplified.'
if $ans->{ans_message} eq "Multiplication can only be used between coefficients and variables";
return $ans;
}));
# $p = Formula("(x^2-$aa)(x+$a)");
$aaa=$a**3;
$p = Formula("x^3-$aa x+$a x^2 -$aaa");
ANS($denom->cmp()->withPostFilter(AnswerHints(
Formula("$p") => "This is not the lowest common denominator.",
)));
----------------------------
The problem is with the last line.