WeBWorK Problems

contextLimitedPolynomial

contextLimitedPolynomial

by Kenneth Appel -
Number of replies: 1
Davide,
In revising some working problems that are written for rather stilted str_cmp
type answers I decided to try out contextLimitedPolynomial. I seem to have
done something quite wrong, but the warning message leaves me puzzled. In
particular, besides the error message, it gives me the answer of a number although I can't see anywhere that x is given a value.
Here is the code

#DESCRIPTION
##Type of
#ENDDESCRIPTION

DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
#"PGgraphmacros.pl",
"MathObjects.pl",
# "compoundProblem.pl",
# "unionLists.pl",
#"unionMacros.pl",
"contextLimitedPolynomial.pl",

);
Context("Numeric");
Context()->variables->are(x=>'Real',y=>'Real');
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
$a = random(6,9,1);
$b = random(3,7,1);


$e=random(2,6,2);
$f=random(3,7,2);

BEGIN_TEXT
$PAR
Simplify each of the following expressions

$PAR
\(($a+$b x^2+$e x^3)($f x-12(x+1))\)= \{ans_rule(15)\}
$PAR


END_TEXT
Context("LimitedPolynomial")->flags->set(singlePowers=>1);
Context()->variables->are(x=>'Real',y=>'Real');

ANS(Formula(($a+$b*x**2+$e*x**3)*($f*x-12*(x+1)))->cmp);

ENDDOCUMENT()

Warning messages (note that line numbers no longer

correspond since I have edited out some irrelevant text The line nmber is
referred to is the answer line.

  • Operator or semicolon missing before *x at line 43 of (eval 154932)
  • Ambiguous use of * resolved as operator * at line 43 of (eval 154932)
  • Operator or semicolon missing before *x at line 43 of (eval 154932)
  • Ambiguous use of * resolved as operator * at line 43 of (eval 154932)
  • Operator or semicolon missing before *x at line 43 of (eval 154932)
  • Ambiguous use of * resolved as operator * at line 43 of (eval 154932)


In reply to Kenneth Appel

Re: contextLimitedPolynomial

by Davide Cervone -
Your formula needs to be in quotation marks. Without them, Perl tries to interpret the expression instead of the MathObjects parser.

Note, however, that you will not be able to enter the equation in the LimitedPolynomial context, since it is not a simplified polynomial. You need to provide the answer in the required format (so that WeBWorK can give a correct answer when requested).

Finally, your Context("Numeric") and Context() variables settings will have no effect, since no MathObjects are created between there and the following Context("LimitedPolynomail") call.

Davide