WeBWorK Problems

disabling the evaluation of constants

disabling the evaluation of constants

by Michael Miller -
Number of replies: 1
I am having difficulty disabling the evaluation of constants, as the following example shows.

Context()->flags->set(reduceConstants=>0);
Context()->flags->set(reduceConstantFunctions=>0);
$f = Formula("2^x");
$df = $f->D();

The resulting value for $df is (0.693147*2^x) .

How can I get it to be ln(2)*2^x ?

In reply to Michael Miller

Re: disabling the evaluation of constants

by Gavin LaRose -
Hi Michael,

If you use Compute() instead of Formula(), the correct answer string is set to the input string: see http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2321 for an example. This may require that you actually code the derivative as $df = Compute("ln(2)*2^x"), rather than using the MathObjects differentiation method, however.

This is harder if you are working with Real valued answers; there are some threads in the Forum on fractional answer evaluation that may be of interest if you end up on that particular road.

Gavin