## PREP 2014 Question Authoring - Archived

by Chrissy Safranski -
Number of replies: 2
What am I doing wrong?  Everything seems to be working as I want it to, except that I can't get the answer hint to show up for the denominator if students enter the first denominator times the second denominator, instead of the least common denominator.

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. In reply to Chrissy Safranski ### Re: answerHints message doesn't appear by Davide Cervone - The problem is that the values for $denom and Formula("$p") are in two different contents, and you can only compare formulas when they are in the same context. So the comparison in AnswerHints fails (silently). So I'd recommend creating $p just below $denom, which will let you give it in the factored form as well. There are a number of other small issues with the problem as well. For example, you can just use $p => "This is not the lowest common denominator",

as $p is already a formula (no need to turn it into a string a re-parse it). Also, you can use the Context's {error}{msg} object to adjust the answer message for the numerator rather than having to provide a custom post filter (see below). Here is a modified version that includes these changes. DOCUMENT(); loadMacros( "PGstandard.pl", "contextLimitedPolynomial.pl", "answerHints.pl", "PGcourse.pl", ); Context("Numeric");$a=non_zero_random(3,6);
$b=non_zero_random(1,5); if ($b==$a) {$b++};
$c=non_zero_random(2,5); if ($c==$a) {$c++};

$denom=Compute("x^2-$a^2");
$p = Formula("(x^2-$a^2)(x+$a)");$aa = $a**2; Context("LimitedPolynomial-Strict"); Context()->{error}{msg} {"Multiplication can only be used between coefficients and variables"} = "This needs to be multiplied out and simplified";$A = $b+1;$B = $c+$a*$b;$num=Compute("$A x -$B")->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); ANS($denom->cmp()->withPostFilter(AnswerHints(
\$p => "This is not the lowest common denominator.",
)));

ENDDOCUMENT();