WeBWorK Problems

Question about answer checker

Question about answer checker

by Bentley Garrett -
Number of replies: 2

I have 2 main questions:

1) For one particular problem, we have set up the following context and correct answer:


$answer = Formula(" 1/(cosx(1-3tanx)^(1/3)) ")

The answer checker code used is:

ANS( $answer->cmp( ));

When I enter the equivalent answer: 1/((cosx)^3 - 3sinx(cosx)^2)^(1/3)
and submit this answer over and over again, sometimes it tells me it's correct and sometimes it tells me it's incorrect, so the student won't know if it is correct if it is initially marked as incorrect.
Is this common in WW?
Would I have to put in a test vector myself - or would something else be better?
How would I know which functions cause this and which don't?

2) Here is another problem, with context and correct answer:


$answer = Formula(" 2/(t^2sqrt(8e^t-8e+1)) ");

It has the same answer checker code: ANS( $answer->cmp( ));

If I enter the equivalent answer: 1/sqrt((1/4 - 2e)t^4 + 2(e^t)t^4)
and I repeatedly submit this answer, sometimes is is marked correct, and sometimes I get the message: Can't generate enough valid points for comparison.
I'm guessing this has to do with whether the random test vector has enough values in the domain or not.

My questions about this problem are the same as for item 1 above.

Any help would be appreciated!

-Bentley Garrett

In reply to Bentley Garrett

Re: Question about answer checker

by Alex Jordan -
It helps to understand how math object Formulas like these are compared. The context has limits for each variable that can be set like:
or in the case of two variables like x and y, alphabetically ordered
When cmp is run, random x and y values are taken from these ranges and both the correct answer and student answer are evaluated. If there is always agreement, the formulas are declared equivalent.

If for all randomly chosen test points, neither the correct answer nor the student's evaluate to anything, you get the "not enough valid points..." message. This is what I suspect is happening in the second problem. For small values of t, the function is not defined (square roots of negative values) regardless of which equivalent expression you use. So you could set the limits carefully there.

For the first problem, something similar could be happening, and more care to the limits might fix the problem. Note that you are using "^(1/3)", and sometimes machines have trouble raising negative numbers to non-integer powers. Usually they apply a logarithm to try to compute x^y as exp(y*log(x)), and if x is negative, this goes bad. Also, 1/3 could be rounded by the machine to something like 0.333 (with a lot more digits) and you can see another reason why (negative value)^(1/3) could cause problems. So maybe restricting the limits to an interval where you know the input to the cube roots would be positive would help.
In reply to Alex Jordan

Re: Question about answer checker

by Bentley Garrett -
Hi Alex:

So, in summary, if I manually choose a test vector range that is inside the domain of the function every time, then I should be safe.

A belated "thanks" for your reply. This was very helpful!