I am trying to write a problem for the students to practice the distributive property. The students must enter a polynomial -- not factors. I would like the correct answer to show up as a polynomial. Here is the code I have:
loadMacros(
"PGstandard.pl",
"Parser.pl",
"MathObjects.pl",
"contextLimitedPolynomial.pl"
);
TEXT(&beginproblem);
######################################
# Setup
$a1 = random(2,4,1);
$a2 = random(2,4,1);
$a3 = random(1,8,1);
$b1 = random(-4,-2,1);
$b2 = random(2,4,1);
$b3 = random(1,8,1);
######################################
# Main text
BEGIN_TEXT
Use the distributive property to write the expressions without parenthesis:
$PAR
a) \( $a1($a2 x + $a3) = \) \{ ans_rule(10) \}
$PAR
b) \( $b1($b2 x + $b3) = \) \{ ans_rule(10) \}
$PAR
$BR
END_TEXT
######################################
# Answers
Context("LimitedPolynomial")->flags->set(singlePowers=>1);
$ans_a = Formula("$a1*$a2 x + $a1*$a3")->reduce;
ANS($ans_a->cmp);
$ans_b = Formula("$b1*$b2 x + $b1 * $b3")->reduce;
ANS($ans_b->cmp);
Two problems:
1) I get an error when the leading coefficient is negative:
Error messages
You can only use '-' with monomials at line 253 of [PG]/macros/contextLimitedPolynomial.pl Died within LimitedPolynomial::UOP::_check called at line 21 of [PG]/lib/Parser/UOP.pm from within Parser::UOP::new called at line 154 of [PG]/lib/Parser/UOP.pm from within Parser::UOP::Neg called at line 61 of [PG]/lib/Parser/BOP/subtract.pm from within Parser::BOP::subtract::_reduce called at line 72 of [PG]/lib/Parser/BOP.pm from within Parser::BOP::reduce called at line 39 of [PG]/lib/Parser/BOP/add.pm from within Parser::BOP::add::_reduce called at line 72 of [PG]/lib/Parser/BOP.pm from within Parser::BOP::reduce called at line 638 of [PG]/lib/Parser.pm from within Parser::reduce called at line 75 of [TMPL]/Problems/setAlgebra_01_02_OperationsWithRealNumbers/IntAlg_22_OperationsWithReals.pg
2) For the problem, 2(3x+5), I can enter 6x+10 and 2*3x+ 10 and the answer is evaluated as correct in both cases. I would like only the first answer to be considered as correct.
Thanks -- rac