WeBWorK Problems

Error with multiple use of custom answer checker

Error with multiple use of custom answer checker

by Ted Shifrin -
Number of replies: 4
My apologies if this has been addressed elsewhere. I have a problem with three equations of planes. I want each problem graded with the adaptive parameter custom answer checker. So I call that routine three separate times.

The grader works perfectly if I enter all three answers simultaneously. However, if I enter only one or two, I get the dreaded pink page with the warning message (with multiplicity)

Please inform your instructor that an error occurred while checking your answer at [PG]/lib/Value/AnswerChecker.pm line 273

Is this a known bug?
In reply to Ted Shifrin

Re: Error with multiple use of custom answer checker

by Ted Shifrin -
Here's the complete code. The problem is a bit complicated because there's a choice of 3 different functions, then (left over from a previous version, where I had matching and wanted the linear equations to have no common integer factor) some ad hoc stuff for getting rid of gcd's. But, as I say, the problem works and grades correctly except for the error message.

DOCUMENT();
loadMacros("PGstandard.pl",
"PGunion.pl",
"PGcourse.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"MathObjects.pl",
"Parser.pl",
);

$showPartialCorrectAnswers = 0;

TEXT(beginproblem);

Context("Vector")->variables->are(x=>'Real',y=>'Real',z=>'Real');

$f = 'f\left(\begin{array}{c} x\\y\\z \end{array}\right)';

# defining a procedure to repeat in case any partial derivative comes out 0

PROC:
{
$a=non_zero_random(-2,2,1);
$b=non_zero_random(-2,2,1);
$c=non_zero_random(-2,2,1);
$P = ColumnVector($a,$b,$c);

$d=non_zero_random(-5,5,1);
$e=random(1,5,1);
$j=non_zero_random(-5,5,1);
do{$k=random(1,5,1)} until ($k!=$e);
$l=random(-3,3,2);

@fn = ("x^2 + y^3 + z^4",
"x^3 + $d x z^2+ y^2 z+ $e y^3",
"$e y z^2 + $d x^$k z^5",
"e^($c x - $a z) tan($c y - $b z + $l pi/4) + x y + $j z",
"e^($d x-y+$j z+(-$a*$d+$b-$c*$j)) + $e xz^2");

@choice = NchooseK($#fn,3);
@subfn = @fn[@choice];

for ($i=0; $i<3; $i++)
{$f[$i]=Formula("$subfn[$i]")->reduce;

$fx[$i]=$f[$i]->D('x')->eval(x=>$a, y=>$b, z=>$c);
$fy[$i]=$f[$i]->D('y')->eval(x=>$a, y=>$b, z=>$c);
$fz[$i]=$f[$i]->D('z')->eval(x=>$a, y=>$b, z=>$c);

$fval[$i]=$f[$i]->eval(x=>$a, y=>$b, z=>$c);
$ques[$i]=Formula("$f[$i]")->TeX;


$gcd1[$i]=gcd($fx[$i],$fy[$i]); $gcd[$i]=gcd($gcd1[$i],$fz[$i]);
if($gcd[$i]>1) {$fx[$i]=$fx[$i]/$gcd[$i]; $fy[$i]=$fy[$i]/$gcd[$i];
$fz[$i]=$fz[$i]/$gcd[$i];}
if($fx[$i]<0) {$fx[$i]=-$fx[$i]; $fy[$i]=-$fy[$i];
$fz[$i]=-$fz[$i];}

$ans[$i]=Formula("$fx[$i]x+$fy[$i]y+$fz[$i]z")->reduce;
$ansrh[$i]=$ans[$i]->eval(x=>$a, y=>$b, z=>$c);
redo PROC if ($fx[$i]*$fy[$i]*$fz[$i]==0);
$plane[$i] = Formula("$ans[$i]-$ansrh[$i]")->reduce;}}

Context() -> texStrings;

BEGIN_TEXT

Let \(\mathbf{a} = $P \). Give an equation of the tangent plane of the given level surface \($f = c\ \) at \(\mathbf{a}\).
Note that the constant \(c\) is chosen so that \(f(\mathbf a) = c\).
$PAR
Note that in each case we have provided the right-hand side "\( = 0\)" of your equation.
$PAR
(a) \($f=$ques[0]=$fval[0]\)
$BR
\{ans_rule(50)\} \( = 0\)
$PAR
(b) \($f=$ques[1]=$fval[1]\)
$BR
\{ans_rule(50)\} \( = 0\)
$PAR
(c) \($f=$ques[2]=$fval[2]\)
$BR
\{ans_rule(50)\} \( = 0\)
$PAR

END_TEXT

ANS($plane[0]->cmp(checker => sub {
my ( $correct, $student, $self ) = @_;
my $context = Context()->copy;
return 0 if $student == 0;
$context->flags->set(no_parameters=>0);
$context->variables->add('C0'=>'Parameter');
my $c0 = Formula($context,'C0');
$student = Formula($context,$student);
$correct = Formula($context, "$c0 * ($plane[0])");
return $correct == $student;
}));

ANS($plane[1]->cmp(checker => sub {
my ( $correct, $student, $self ) = @_;
my $context = Context()->copy;
return 0 if $student == 0;
$context->flags->set(no_parameters=>0);
$context->variables->add('C1'=>'Parameter');
my $c1 = Formula($context,'C1');
$student = Formula($context,$student);
$correct = Formula($context, "$c1 * ($plane[1])");
return $correct == $student;
}));

ANS($plane[2]->cmp(checker => sub {
my ( $correct, $student, $self ) = @_;
my $context = Context()->copy;
return 0 if $student == 0;
$context->flags->set(no_parameters=>0);
$context->variables->add('C2'=>'Parameter');
my $c2 = Formula($context,'C2');
$student = Formula($context,$student);
$correct = Formula($context, "$c2 * ($plane[2])");
return $correct == $student;
}));

ENDDOCUMENT();

In reply to Ted Shifrin

Re: Error with multiple use of custom answer checker

by Paul Pearson -
Hi Ted,

The answers to the three parts of this question are all equations for planes, so why not use parserImplicitPlane.pl ? A complete example is given at:

http://webwork.maa.org/wiki/ImplicitPlane1#.T9j2w5jh_To

If you really want to continue to ask the question in its current form, I would recommend you look at:

http://webwork.maa.org/wiki/AnswerUpToMultiplication1#.T9j3mpjh_To

Good luck!

Paul Pearson
In reply to Paul Pearson

Re: Error with multiple use of custom answer checker

by Ted Shifrin -
Thanks, Paul. I have already read the latter page.

I gather ImplicitPlane is far more stable than ImplicitEquation, which I have had problems with (and which the WeBWork pages themselves disparage). Thanks, I'll give it a shot!

So much to learn :)
In reply to Ted Shifrin

Re: Error with multiple use of custom answer checker

by Paul Pearson -
Hi Ted,

In my experience, ImplicitPlane is very reliable and robust. ImplicitPlane should work 100% of the time, unlike ImplicitEquation, which (in my opinion) uses an algorithm that has a few shortcomings.

-Paul