WeBWorK Problems

Limiting operations allowed in formulas

Limiting operations allowed in formulas

by Kenneth Appel -
Number of replies: 1
This may be asking too much. I originally had this working with
str_cmp but realized that I wanted to allow alternative forms.
However, when I made the change to Context()->variables...
I forgot that unsimplified answers would be accepted. Is there
any way to modify Context()->variables to require answers without
sums of integers?

# "MathObjects.pl",
# "compoundProblem.pl",
# "unionLists.pl",
$showPartialCorrectAnswers = 1;
$a = random(6,9,1);
$b = random(3,7,1);



Simplify each of the following expressions

\(($a+m)+$b\) \{ans_rule(5)\}
\($e\cdot(k\cdot $f)\) \{ans_rule(5)\}
\($b(x + $f)\) \{ans_rule(5)\}
Context()->variables->are(k=>'Real', m=>'Real', x=>'Real');



In reply to Kenneth Appel

Re: Limiting operations allowed in formulas

by Davide Cervone -
What you are sking could be accomplished through a custom context, but I don't think there is one right now that will do what you want.

The only possibility I can think of at the moment is the LimitedPolynomial-Strict context defined in contextLimitedPolynomial.pl. This would do what you ask, but the error messages would probably not be what you want, as they would refer to polynomials. There is a message translation facility that could be used to convert the bad errors into more appropriate ones if you want to go that route.

The other approach would be to use a custom answer checker to first check if the two answers are equal, and then if they are, and then check the parse tree to make sure it does not include extra operations. This would be something like the checker I wrote for you in the discussion at:



P.S., I split this into a new discussion since it no longer is about the TF context that was the topic of the previous discussion.