WeBWorK Problems

small number woes

small number woes

by Zak Zarychta -
Number of replies: 3
Hi,

I cannot get WeBWorK answer checker to correctly process numbers of a small magnitude

I'm authoring questions for a quantum physics module where answers are often of a small magnitude. I have some constants set such as Planck's constant. I have an answer for a question that is 1.441e-29

having followed the advice in the following thread
Setting zeroLevel to allow small numbers seems to have no effect.

Trying

ANS(Real(1.441E-29)->cmp(
tolType => 'absolute',
tolerance => 1.441E-31,
));


still grades as incorrect 1.441E-29 and gives the correct answer as 0. Infact the numerical example cited in the thread yields the same result

Any ideas, what I am doing wrong?
In reply to Zak Zarychta

Re: small number woes

by Zak Zarychta -
So with the answer checker I have found that setting the zero level small works for example

Context("Numeric");
Context()->flags->set(
zeroLevel => 1E-36,
zeroLevelTol => 1E-38
);

However, it will still not work with units in the question. So

ANS(Real($ans)->cmp()); # Works

but

ANS( num_cmp( $ans, units=>"kg m s^-1" ) ); # does not work

However defining $ans as

$ans = NumberWithUnits("1E-30 kg m s^-1");

works with the first answer checker and the zero tolerance accordingly set

Could anyone elaborate why this might be so?
In reply to Zak Zarychta

Re: small number woes

by Joel Trussell -
I realize that you desire the standard MKS units but changing to CGS moves you a bit further up the scale ( by 10^5) . We have some similar problems in electrical engineering. Fortunately we have terahertz  to Hertz, picofarads to farads, etc, so it is easier. 
In reply to Zak Zarychta

Re: small number woes

by Davide Cervone -
Some history is needed to understand this. The MathObjects library was not in the original versions of WeBWorK, and the answer checkers that were available at the time where the ones like num_cmp() that you reference above. Each answer checker worked in isolation, and there was no Context() command. In 2004, the first version of MathObjects was developed, and that is the library that included Context(), and the various ->cmp() methods. Eventually, the traditional answer checkers like num_cmp() were rewritten to use MathObjects internally, but (in order to remain compatible with the original versions), they don't use the active Context(), but instead use their own internal contexts. So the changes you make to the MathObejct context doesn't affect num_cmp(), as you have seen.

The values that are stored in the Context() for MathObject traditionally were stored as plain variables, so if you set

$zeroLevel = 1E-36;
$zeroLevelTol = 1E-38;

instead of the Context() command, then the num_cmp() call should use those.