Answer Checkers and the Context
Disabling Functions
Some things, like whether trigonometric functions are allowed in the answer, are controlled through the Context()
rather than through the MathObjects answer checker itself. For example,
Context()->functions->disable('sin','cos','tan');
would remove those three functions from use. One would need to remove cot
, sec
, csc
, arcsin
, asin
, etc., to do this properly, however. It is also possible to remove whole categories of functions once, e.g.
Context()->functions->disable('Trig');
would disable all trig functions, while
Context()->functions->disable('All'); Context()->functions->enable('sqrt');
would allow only the sqrt
function to be used in student answers. The available categories are the following:
Category | Functions Included |
---|---|
SimpleTrig
|
sin , cos , tan , sec , csc , cot
|
InverseTrig
|
asin , acos , atan , asec , acsc , acot , arcsin , arccos , arctan , arcsec , arccsc , arccot , atan2
|
SimpleHyperbolic
|
sinh , cosh , tanh , sech , csch , coth
|
InverseHyperbolic
|
asinh , acosh , atanh , asech , acsch , acoth , arcsinh , arccosh , arctanh , arcsech , arccsch , arccoth
|
Numeric
|
log , log10 , exp , sqrt , abs , int , sgn , ln , logten
|
Vector
|
norm , unit
|
Complex
|
arg , mod , Re , Im , conj
|
Hyperbolic
|
all of SimpleHyperbolic and InverseHyperbolic
|
Trig
|
all of SimpleTrig , InverseTrig , and Hyperbolic
|
All
|
all of Trig , Numeric , Vector , and Complex
|
Note that some functions can be obtained via operators (e.g., abs(x)
can be obtained via |x|
and sqrt(x)
can be obtained by
x^(1/2)
or x^.5
, so you might need to remove more than just the named functions to limit these operations).
Disabling Operators
Which arithmetic operations are available is controlled through Context()->operations
. For example,
Context()->operations->undefine('^','**');
would disable the ability for students to enter powers. Note that multiplication and division have several forms (in order to make a non-standard precedence that allows things like sin(2x)
to be entered as sin 2x
). So if you want to disable them you need to include all of them. E.g.,
Context()->operations->undefine('*',' *','* '); Context()->operations->undefine('/',' /','/ ','//');
would be required in order to make multiplication and division unavailable.
Finally, absolute values are treated as a specialized form of parenthesis, so to remove them, use
Context()->parens->remove('|');
The pg/macros/ directory contains a number of predefined contexts that limit the operations that can be performed in a student answer. For example, the contextLimitedNumeric.pl
file defines contexts in which students can enter numbers, but no operations, so they would have to reduce their answer to a single number by hand. There are limited contexts for complex numbers, points, and vectors, and there are also specialized contexts for entering polynomials, or where powers are restricted in various ways.
Tolerances and Limits
The tolerances used in comparing numbers are part of the Context aswell. You can set these via:
Context()->flags->set( tolerance => .0001, # the relative or absolute tolerance tolType => 'relative', # or 'absolute' zeroLevel => 1E-14, # when to use zeroLevelTol zeroLevelTol => 1E-12, # smaller than this matches zero # when one of the two is less # than zeroLevel limits => [-2,2], # limits for variables in formulas num_points => 5, # the number of test points );
Note that for testing formulas, you can override these values by setting these fields of the formula itself:
$f = Formula("sqrt(x-10)"); $f->{limits} = [10,12]; $f = Formula("log(xy)"); $f->{limits} = [[.1,2],[.1,2]]; # x and y limits
You can also specify the test points explicitly:
$f = Formula("sqrt(x-10)"); $f->{test_at} = [[11],[11.5],[12]]; # use these plus random ones $f = Formula("log(xy)"); $f->{test_points} = [[.1,.1],[.1,.5],[.1,.75], [.5,.1],[.5,.5],[.5,.75]]; # test only at these
You can specify the value at the same time you create the object, as in
$f = Formula("sqrt(x-1)")->with(limits=>[10,12]);
It is also possible to set the limits of variables in the context itself,
Context()->variables->set(x => {limits => [10,12]});
or when a variable is created in the Context,
Context()->variables->add(t => ['Real',limits=>[1,2]]);
or even when the answer checker is specified,
ANS($f->cmp(limits=>[10,12]));