## WeBWorK Problems by Nathan Wodarz -
Number of replies: 1
Is there any good way to handle answers involving large integers?

For example, I'd like to ask my students to take the nth derivative of cos(2x) or sin(2x), where 50 < n < 100.

I'm running into an issue: if I ask for the derivative itself, the correct answer may be marked incorrect because of floating point issues. As an example, entering -(2^82)*cos(2x) for the 82nd derivative of cos(2x) is marked incorrect, but -(4.8357*e+24)*cos(2x) is marked correct. (I'm using MathObjects, so the function is defined as a Formula object). ### Re: Answers involving large integers.

by Davide Cervone -
Can you tell me how you have specified your correct answer within the problem? The exact form of the Formula will impact the numerical stability, so knowing how you have written the correct answer will make a difference.

One way to get a sense of what is happening is to add diagnostics=>1 to the answer checker, as in

    ANS(\$f->cmp(diagnostics=>1));

This will cause the problem to generate a diagnostic table showing the values used within the comparison for both the student and correct answers and whether they were within the tolerances or not. Often this can help determine what is going wrong.

Formulas involving very large and very small values tend to be problematic, and setting the tolerances and limits properly can be very important. In my experience, one of the most important caveats is to try to avoid the zeros of the function, as relative tolerances work poorly near values of zero.

Note that in your case, the default limits of -2 to 2 in the x value will include several zeros of the function, and depending on the problem seed, that course lead to incorrect results like what you have seen. You may find that restricting the limits to a range where the function is non-zero will help, say -pi/6 to pi/6 in your case.

Alternatively, you may need to use a custom answer checker for this. For example, it could evaluate the student function at x=0 (to determine the constant used by the student) and if it is not correct, mark the answer as false, while if it is correct, it could divide the student answer by that constant and compare it to cos(2x), which will no longer be enormously large values. I haven't tried that, but I think it would work. Anyway, it is worth a try.

Davide