## WeBWorK Problems

### Limiting operations allowed in formulas ### Limiting operations allowed in formulas

by Kenneth Appel -
Number of replies: 1
Davide,
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?
Ken

DOCUMENT();
"PGstandard.pl",
"PGchoicemacros.pl",
#"PGgraphmacros.pl",
# "MathObjects.pl",
# "compoundProblem.pl",
#"contextCurrency.pl",
#"contextInequalities.pl",
# "unionLists.pl",
#"unionMacros.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;$a = random(6,9,1);
$b = random(3,7,1);$c=$a+$b;

$e=random(2,6,2);$f=random(3,7,2);
$c1=$e*$f;$c2=$b*$f;

BEGIN_TEXT
$PAR Simplify each of the following expressions$PAR
$$(a+m)+b$$ \{ans_rule(5)\}
$PAR $$e\cdot(k\cdot f)$$ \{ans_rule(5)\}$PAR
$$b(x + f)$$ \{ans_rule(5)\}
END_TEXT
Context("Numeric");
Context()->variables->are(k=>'Real', m=>'Real', x=>'Real');

ANS(Formula("m+$c")->cmp); ANS(Formula("$c1*k")->cmp);
ANS(Formula("$b*x+$c2")->cmp);

ENDDOCUMENT() ### 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:

http://wwrk.maa.org/moodle/mod/forum/discuss.php?d=356

Davide

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.