WeBWorK Problems

interesting formulauptoconstant feature/bug

interesting formulauptoconstant feature/bug

by Gavin LaRose -
Number of replies: 1
Hi all,

I found the following in one of the problems we use from the problem library, Michigan/Chap7Sec1/Q19.pg. This discussion relates to that problem with seed 504. The solution in this problem is defined as a FormulaUpToConstant. I believe the actual formula doesn't matter; in this case it's the antiderivative of a function of the form (x^r + a)^2. For example, we might have the antiderivative of (x^7 + 9)^2, which is the case for this eed.

A common error will be to integrate assuming that we can reverse the chain rule and divide by the missing factor of x^{r-1}: e.g., getting \int ( x^7 + 9 )^2 dx = \frac{1}{21 x^6}(x^7 + 9)^3 + C (the actual input is (1/(21x^6))(x^7+9)^3 + C). For this problem and seed, one of the test points is very close to zero, which means that the student's answer is very large. Interestingly, this generates a WeBWorK warning:

Warning -- there may be something wrong with this question. Please inform your instructor including the warning messages below.

The warning messages below are: "Use of uninitialized value $result in numeric eq (==) at line 301 of (eval 10523)" (and a similar error reported at lines 302, 311 and 312).

Interestingly, changing C in the input answer to c results in the error message vanishing and the answer being marked incorrect (which it should) with the message "This answer is equivalent to the one you just submitted." My guess is that the issue is a numerical one with the calculation of the shift C, which is not manifest with a different name for the constant because that adds another parameter to the system and therefore changes the calculation.

In any case, the work-around is to restrict the domain away from zero, though that could presumably still run into trouble if someone inexplicably entered something like 1/(21(x-.5)^6).

All for what it's worth, in any case.


In reply to Gavin LaRose

Re: interesting formulauptoconstant feature/bug

by Davide Cervone -
It turns out that this error message is coming from when FormulaUpToConstant is trying to figure out what error messages to give the student, if any, when the answer is incorrect. The code uses adaptive parameters to decide if the student answer matches the correct one, and in this case, the adaptive parameters can't be found, and that produces a null result near the location of the warning message that you are seeing. Unfortunately, the code didn't check for that, and it should. An easy fix is to change
    my $result = Parser::Eval(sub {return $ans->{correct_value}  $student});
    my $result = Parser::Eval(sub {return $ans->{correct_value}  $student}) || 0;
at around line 300 of parserFormulaUpToConstant.pl.

When the student uses +c rather than +C, that means there is an extra variable (c in addition to C), and so the random points used are different, and so the numeric problem doesn't occur.