Formulas up to additive constants.
Download file: FormulasToConstants.pg
DOCUMENT(); loadMacros( 'PGstandard.pl', 'PGML.pl', 'parserFormulaUpToConstant.pl', 'PGcourse.pl' );
Preamble
There are two types of comparison demonstrated here. One is “an antiderivative of f(x)”, and the other is “the most general antiderivative of f(x)”. The former requires that the student answers F(x), F(x) + 1, F(x) - sqrt(8), etc., all be marked correct, and the latter, that F(x) + C, F(x) + 5 - k, etc., all be marked correct.
To check the most general antiderivative of a function, that is, a formula up to an arbitrary additive constant, the parserFormulaUpToConstant.pl
macro is used. To evaluate an antiderivative of a function, that is, a formula that is unique up to a (specified) additive constant, this macro is not needed.
$func = Formula('sin(x)'); $gfunc = FormulaUpToConstant('sin(x) + C');
Setup
Define an antiderivative function $func
and the most general antiderivative function $gfunc
. For the latter is is not required to include + C
. It would be equivalent to specify $gfunc = FormulaUpToConstant('sin(x)')
.
BEGIN_PGML An antiderivative of [`\cos(x)`] is [_]{$func->cmp(upToConstant => 1)} The most general antiderivative is [_]{$gfunc} END_PGML ENDDOCUMENT();
Statement
Call the MathObjects cmp()
method and specify the upToConstant => 1
flag. This allows the student’s answer to differ from the correct answer by any constant. Both sin(x)
and sin(x) + 5
would be marked correct, but sin(x) + C
is not correct since it is a family of answers and not a specific antiderivative. Note that for the formula up to an arbitrary constant the comparison will correctly mark student’s answers that have different arbitrary constants. Thus, a student answer to the second question of sin(x) + k
will be marked correct as will sin(x) + c
.