FormattingCorrectAnswers: NumbersAndFormulas

From WeBWorK_wiki
Revision as of 19:23, 22 June 2021 by Berndsing (talk | contribs) (added tag)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

There are a number of ways to affect the way the correct answer is displayed to the student. The interaction between eval() , substitute() , reduceConstants , reduceConstantFunctions .
Note:PGLabs is an efficient way to check code.

# Context()->flags->set(reduceConstants=>0);
$f = Compute("sqrt(5^2+6x)");
$df = $f->D;
$dfx = Compute( $df->eval(x=>"pi") );
displays: 0.453042

The correct answer is a number because we used eval() instead of substitute() .

Context()->flags->set(reduceConstants=>0);
$f = Compute("sqrt(5^2+6x)");
$df = $f->D;
$dfx = Compute( $df->eval(x=>"pi") );
displays: 0.453042

Clearly, reduceConstants has no effect on eval() .

Context()->flags->set(reduceConstants=>0);
$f = Compute("sqrt(5^2+6x)");
$df = $f->D;
$dfx = Compute( $df->substitute(x=>"pi") );
displays:  (6*1/[2*sqrt(25+6*3.14159)])

Now, the correct answer is an unreduced Formula since substitute() was used instead of eval() .

#Context()->flags->set(reduceConstants=>0);
$f = Compute("sqrt(5^2+6x)");
$df = $f->D;
$dfx = Compute( $df->substitute(x=>"pi"));
displays (0.453042)

Now the correct answer is still a formula, but the constants have been reduced since reduceConstants has been set to 0. Surprisingly, sqrt(constant) is also reduced in this case.

To explore this further:

Context()->flags->set(reduceConstants=>0);
# Context()->flags->set(reduceConstantFunctions=>0);
$f = Compute("sqrt(x)");
$df = $f->D;
$dfx = Compute( $df->substitute(x=>"5") );
display  (1/(2*2.23607))

The correct answer is a Formula because we used substitute() , but the function sqrt(x) is simplified.

Context()->flags->set(reduceConstants=>0);
Context()->flags->set(reduceConstantFunctions=>0);
$f = Compute("sqrt(x)");
$df = $f->D;
$dfx = Compute( $df->substitute(x=>"5") );
displays  (1/[2*sqrt(5)])

This time the Formula is not simplified because reduceConstantFunctions has been set to 0.


However:

Context()->flags->set(reduceConstants=>0);
# Context()->flags->set(reduceConstantFunctions=>0);
$f = Compute("sqrt(5^2+6x)");
$df = $f->D;
$dfx = Compute( $df->substitute(x=>"5") );
displays: (6*1/[2*sqrt(25+6*5)])

Surprisingly, this function is not reduced even though reduceConstantFunctions is 1 (the default). This appears to be because the input to the function is complicated. This might be considered a bug.