ANS($ans->cmp(limits=>[0,1]));
We've implemented this on the problem but something it still throws the same error on some seeds (specifically seed value 1728). I've changed the limits interval to different values but to no avail. I was wondering if someone could tell us what we're doing wrong. I've attached a screenshot of the error and Ive included the problem file below (I've highlighted the limit declaration part).
Also, this happens on a MultiAnswer problem so perhaps that has something to do with it.
Thank you!
Patrick Spencer
Problem file source:
DOCUMENT();
loadMacros(
"MathObjects.pl",
"PeriodicRerandomization.pl",
"PGstandard.pl",
"contextLimitedPowers.pl",
"parserMultiAnswer.pl",
"unionTables.pl",
"AnswerFormatHelp.pl",
);
TEXT(beginproblem());
PeriodicRerandomization("3");
$showPartialCorrectAnswers = 1;
###########################################################################
# setup contexts and variables
###########################################################################
Context("Numeric");
LimitedPowers::OnlyPositiveIntegers();
@vars = ("x","y","z","r","s","t","m","n","p","q");
$ch1 = random(0,scalar(@vars)-1,1);
do {$ch2 = random(0,scalar(@vars)-1,1)} until ($ch2 != $ch1);
$v1 = $vars[$ch1];
$v2 = $vars[$ch2];
Context()->variables->are($v1=>"Real", $v2=>"Real");
$a = random(2,13);
$a2 = ($a)**2;
$p = 2*random(1,7);
$q = list_random(1,2,4,6,8,10);
$case = random(0,1,1);
if ($q == 1) {</font></div><div><font face="courier new, courier, monospace" size="2"> $case = 0;</font></div><div><font face="courier new, courier, monospace" size="2">}
if ($case == 0) {</font></div><div><font face="courier new, courier, monospace" size="2"> $f = ($q != 1) ? "\sqrt{\frac{$v1^{$p} $v2^{$q}}{$a2}}" : "\sqrt{\frac{$v1^{$p} $v2}{$a2}}";
$num = ($q != 1) ? Formula("$v1^{$p/2} $v2^{$q/2}")->reduce : Formula("$v1^{$p/2} sqrt($v2)")->reduce;
$den = Formula("$a");
} else {</font></div><div><font face="courier new, courier, monospace" size="2"> $f = ($q != 1) ? "\sqrt{\frac{$v1^{$p}}{$a2 $v2^{$q}}}" : "\sqrt{\frac{$v1^{$p}}{$a2 $v2}}";
$num = Formula("$v1^{$p/2}")->reduce;
$den = ($q != 1) ? Formula("$a $v2^{$q/2}")->reduce : Formula("$a sqrt($v2)")->reduce;
}
$multians = MultiAnswer($num, $den)->with(
singleResult => 0,
allowBlankAnswers => 1,
checker => sub {</font></div><div><font face="courier new, courier, monospace" size="2"> my ( $correct, $student, $self ) = @_;</font></div><div><font face="courier new, courier, monospace" size="2"> my ( $c1, $c2 ) = @{$correct};
my ( $s1, $s2 ) = @{$student};
my ( $r1, $r2 ) = (0,0);
$s1 = Formula($s1) unless ($s1->type eq 'Formula' || $s1->type eq 'String');
$s2 = Formula($s2) unless ($s2->type eq 'Formula' || $s2->type eq 'String');
$s1 = Formula("0.1 $v1^{1000}") if ($s1->type eq 'String'); #bogus answer
$s2 = Formula("0.01$v2^{500}") if ($s2->type eq 'String'); #bogus answer
$r1 = 1 if ($c1 == $s1);
$r2 = 1 if ($c2 == $s2);
($r1,$r2) = (1,1) if ($c1 == -$s1 && $c2 == -$s2);
if ($c1*$s2 == $c2*$s1 && $c1 != $s1 && $c1 != -$s1) {</font></div><div><font face="courier new, courier, monospace" size="2"> $self->setMessage(1,"Your answer can be simplified further");</font></div><div><font face="courier new, courier, monospace" size="2"> $self->setMessage(2,"Your answer can be simplified further");</font></div><div><font face="courier new, courier, monospace" size="2"> }
return [$r1,$r2];
}
);
if ($displayMode eq 'TeX') {</font></div><div><font face="courier new, courier, monospace" size="2"> $displayfrac =</font></div><div><font face="courier new, courier, monospace" size="2"> "\[ $f = ".$multians->ans_rule(10).$multians->ans_rule(10)." \]";</font></div><div><font face="courier new, courier, monospace" size="2">} else {</font></div><div><font face="courier new, courier, monospace" size="2"> $displayfrac =</font></div><div><font face="courier new, courier, monospace" size="2"> ColumnTable(</font></div><div><font face="courier new, courier, monospace" size="2"> "\( \displaystyle $f = \)",</font></div><div><font face="courier new, courier, monospace" size="2"> $multians->ans_rule(20).$BR.$HR.$multians->ans_rule(20),</font></div><div><font face="courier new, courier, monospace" size="2"> indent => 0, separation => 10, valign => "MIDDLE"</font></div><div><font face="courier new, courier, monospace" size="2"> );</font></div><div><font face="courier new, courier, monospace" size="2">}
$num->{limits} = [100,101];
$den->{limits} = [100,101];
###########################################################################
# state the problem
###########################################################################
Context()->texStrings;
BEGIN_TEXT
Simplify the radical expression. Assume that all variables represent positive quantities.
$PAR
$BCENTER
$displayfrac
$ECENTER
$BR
Write your answer using radical notation if necessary.
END_TEXT
###########################################################################
# check the answer
###########################################################################
ANS($multians->cmp());
###########################################################################
# use PeriodicRerandomization to write the answer and generate a new
# version of the problem
###########################################################################
if ($attempts_modp == 0 && $actualAttempts != 0) {</font></div><div><font face="courier new, courier, monospace" size="2"> BEGIN_TEXT</font></div><div><font face="courier new, courier, monospace" size="2"> $PAR</font></div><div><font face="courier new, courier, monospace" size="2"> ${BBOLD}Answer:${EBOLD} \(\displaystyle \frac{$num}{$den}\)
$PAR
END_TEXT
} else {</font></div><div><font face="courier new, courier, monospace" size="2"> BEGIN_TEXT</font></div><div><font face="courier new, courier, monospace" size="2"> $PAR</font></div><div><font face="courier new, courier, monospace" size="2"> ${BBOLD}Help:${EBOLD}
\{ AnswerFormatHelp("exponents", "Click here for help writing exponents and square roots.") \}
$BR
END_TEXT
}
Context()->normalStrings;
PeriodicStatus();
COMMENT('Features Periodic Rerandomization');
ENDDOCUMENT()