WeBWorK Problems

UnorderedAnswer macro problems

UnorderedAnswer macro problems

by tim Payer -
Number of replies: 2
I managed to use the unorderedAnswer with success for a few problems until I encountered this problem.

The error I am getting is:

What would cause such a glitch?
The only difference from previous problems is that there are three answer blocks rather than two.

Any help is most appreciated!

Tim

# DESCRIPTION  Problem 4
# Algebra_Review
# WeBWorK problem written by TimPayer <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Algebra)
## DBchapter(Factoring)
## DBsection(Factoring Difference of Squares)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(reduce, difference of squares)

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"unorderedAnswer.pl",
"PGcourse.pl"
);

Context("Numeric");
$a = (list_random(2,3,4,5)); 
do {$b = Real(random(2,11,1));} until (gcd($a,$b) == 1);
do {$c = Real(random(2,11,1));} until (gcd($a,$c) == 1) and (gcd($b,$c) == 1);
$A = Compute("$a*$b*$b");
$B = Compute("$a*$c*$c");
$bb = Compute("$b*$b");
$cc = Compute("$c*$c");

Context()->variables->add(y=>"Real");
$ans1 =$a;
$ans2 =Formula("$b*x+$c*y");
$ans3 =Formula("$b*x-$c*y");


BEGIN_PGML
>> Factor the expression of   [``[$A] x^2 -[$B] y^2``]  completely.<<  
>> Given that the factored form can be expressed as<<  
>> A(Bx + C)(Bx - C), <<  
>>Find the given factors: <<  

>> A = [__________] <<  
>> (Bx + Cy) = [__________] <<  
>> (Bx - Cy) = [__________] <<  
END_PGML

$showPartialCorrectAnswers = 0;
install_problem_grader(~~&std_problem_grader);

UNORDERED_ANS( 
$ans1->cmp(), 
$ans2->cmp(),
$ans3->cmp(), 
);

BEGIN_PGML_SOLUTION

*SOLUTION*

A preliminary check for all factoring problems is to be sure that all common factors have been pulled. Here there are common factors to pull:  
[``[$A] x^2 -[$B] y^2 =[$a]\cdot[$bb] x^2-[$a]\cdot[$cc] y^2=[$a]\left([$bb] x^2-[$cc] y^2\right)``]
Next, given the difference of two terms, [``[$a]\left([$bb] x^2-[$cc] y^2\right)``], consider whether the two terms are a difference of squares  in the form of [`A^2-B^2`] ? If so this can be reduced using the conjugate pairs of the square roots of each term. Specifically [`A^2-B^2 = (A + B)(A - B)`]  
Then we should "see" that [``[$bb] x^2 = \left([$b] x\right)^2``], then [`[$b] x = A`].  
Additionally we can see that [``[$cc] = \left([$c] y\right)^2``], then [`[$c] y = B`].  
It follows that since [`A^2-B^2 = (A + B)(A - B)`], then so will:
[``[$A] x^2 -[$B] y^2=[$a]([$b] x +[$c] y)([$b] x -[$c] y)``].


END_PGML_SOLUTION

ENDDOCUMENT();

In reply to tim Payer

Re: UnorderedAnswer macro problems

by Alex Jordan -
It looks like your $ans1 is just a perl real. So it has no checker. Try changing the definition of $ans1 to be

$ans1 = Real($a);

which makes $ans1 a MathObject Real.

If you were declaring the answer within the PGML block, using [___]{$ans1}, it would be OK to leave $ans1 as a perl real, because in that scenario PGML will wrap a Compute() around $ans1 before settling on a checker to use. But using UNORDERED_ANS outside of the PGML block this way, you need to make $ans1 something "bigger" than just a perl real.