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();