Hi!
I'm having an issue with a question that ask the students to factorize a polynomial expression using the quadratic formula. The thing is that the expression can be factorize in the forme of (ax + b)^2 and it work with the contextPolynomialFactors. But, it doesn't work if the answer is in the forme of a^2(x+b/a)^2. This forme is obtained if the student use the quadratic formula. Since it is a correct answer, i'm trying to find a workaround to force the answer to be accepted. Any idea?
Here is the code i use:
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"contextPolynomialFactors.pl",
"contextLimitedPowers.pl",
);
TEXT(beginproblem());
#######################################
# Set-up
#Context("PolynomialFactors");
Context("PolynomialFactors-Strict");
Context()->flags->set(singleFactors=>0);
Context()->{error}{msg}{"Each factor can appear only once (combine like factors)"}
= "Combiner les facteurs communs en un seul facteur";
#(ax+b)^2 = a^2 x^2 +2ab x + b^2 où b < 0
$var = "x";
do {
$a = random(2,4,1);
$b = random(-10,-2,1);
}
until (gcd($a,$b)==1);
$signe = "négative";
$signe1 = "positive";
$coef1 = $a * $a;
$coef2 = 2*$a*$b;
$coef3 = $b * $b;
$s = $coef2;
$p = $coef1 * $coef3;
$ab = $a * $b;
$abs = abs($b);
$racine1 = $b;
$racine2 = "$a $var";
$a2 = $a*$a;
$terme1 = "$coef1 $var^2";
$terme2 = "$coef2 $var";
$terme3 = "$coef3";
$expression = Formula("$terme1 + $terme2 + $terme3")->reduce;
@terme = ("\textcolor{blue}{$terme1}",
"\textcolor{red}{$terme2}",
"\textcolor{blue}{$terme3}",
"\textcolor{blue}{$terme3 \ \cdot \ $terme1}",
"\textcolor{red}{$ab $var}",
"$racine2($racine2+$racine1)",
"$racine1($racine2+$racine1)",
"(\textcolor{blue}{$racine2}+\textcolor{blue}{$racine1})");
@coef = ("\textcolor{red}{$s}",
"\textcolor{blue}{$p}",
"\textcolor{red}{$terme2}");
$answer = Compute("($racine2 + $racine1)^2")->reduce;
################################################
# Main text
Context()->texStrings;
BEGIN_TEXT
Factorise le trinôme suivant. $BR
$PAR
$BCENTER
\($expression \quad = \quad \) \{ ans_rule(30) \} <button type="button" class="btn btn-link" data-toggle="collapse" data-target="#demo">
<b> Notation </b>
</button>
<br> <br>
<div id="demo" class="collapse">
<table width="60%" border="1" cellspacing="0">
<tr class="btn-primary">
<td valign="top" align="left" width="100%">
<text style="color:white;padding-left:15px;">Notation de la réponse</text>
</td>
</tr>
<tr style="background-color:#fdfdfe;">
<td colspan="2"style="color:black;padding:15px;">
<p align="left">
<u>Exemple</u> : Pour écrire \( x^2 \), vous devez inscrire <b> x^2</b>.
</p>
</td>
</tr>
</table>
</div>
$ECENTER
END_TEXT
Context()->normalStrings;
################################################
# Answer evaluation
$showPartialCorrectAnswers = 1;
ANS($answer->cmp(
checker => sub {
my ($correct,$student,$ans) = @_;
$answer1 = Compute("(-$racine2 - $racine1)^2")->reduce;
$answer2 = Compute("($racine1 + $racine2)^2")->reduce;
$answer3 = Compute("(-$racine1 - $racine2)^2")->reduce;
$answer4 = Compute("$a2($racine1/$a + $racine2/$a)^2")->reduce;
if($student == $correct) {
if ($student eq $expression) {
return 0;
} elsif ($student eq $answer || $student eq $answer1 || $student eq $answer2 || $student eq $answer3 || $student eq $answer4){
return 1;
} else {
return 0;
}
} else {
return 0;
}
}
));
Thanks!