WeBWorK Problems

Requiring a simplified exact answer with pi in it

Requiring a simplified exact answer with pi in it

by Paul Seeburger -
Number of replies: 1

I am trying to require that students enter a simplified exact answer that may contain pi.  Thanks to Davide, I have a figured out a way to not allow decimals.

But now I am trying to figure out a way to require that students actually simplify their answers.

For example, for an answer of 256*pi/9, the checker accepts 512*pi/18 as correct, etc.

Another related issue I am having is that the displayed correct answer is actually not being correctly reduced either.

Here I have used the following code to set up the correct answer:

$ans = Formula("$aa^3*pi/18")->reduce();



$aa = Real(random(5,15));

and in the specific scenario above $aa = 8.

Is there something I have missed that will at least display the correct answer in a the truly reduced form each time?



In reply to Paul Seeburger

Re: Requiring a simplified exact answer with pi in it

by Davide Cervone -
You may be able to take advantage of the Fraction MathObject class, though it may not be exactly what you want. It allows you to require reduced fractions from students. So you should be able to require (1/2)pi, though pi/2 would still be a problem.

A similar idea would be to use an answer rule followed by the pi, so the student only enters the fraction, not the pi itself.

To really do what you are after, there are two possibilities, both rather difficult. One would be to write a post-filter that first checks if the answer is correct, and then analyzes the student's formula to see if it is of the correct form and is reduced. Such tests are notoriously hard to get right, as students can be quite varied in the way they format their answers.

The second is to develop a context in which only the type of answer you are interested in is syntactically correct. This is possible, but it is an advanced technique and not many know how to do it (maybe just me). To do that, you would have to really specify what is to be allowed in the answers. Would pi/2 + pi be acceptable, for example, or would it have to be 3pi/2? How about (1+2)pi/2? and so on.

[It also might be possible to abuse the LimitedPolynomial context to force an answer that looks like a pi /b, and combine that with a post-filter to check for reduced fractions, but it would be a bit awkward.]

In terms of your use of the reduce method, that does not reduce fractions in the form that you have them, as you have found out. MathObjects is not a full-features CAS, and the reduction rules are pretty rudimentary (mainly designed to make it easier to use random variables in formulas and still avoid things like "x + -3" or "1 x + 0".

You could use the Fraction object to get a reduced fraction and then insert the results into a formula, or there is a reduce() function in PGauxiliaryFunctions.pl that you could use to reduce a pair of integers.