This shows how to disable functions allowed in student answers.
Download file: DisableFunctions.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
Preamble
These standard macros need to be loaded.# Disable exponents in the context.
Context()->operators->undefine('^', '**');
# Disable the 'sin', 'cos', 'tan', 'abs', and 'sqrt' functions.
Context()->functions->undefine('sin', 'cos', 'tan', 'abs', 'sqrt');
# Remove the '|' parenthesis operator which starts and ends an absolute value.
# This needs to be done in addition to disabling the 'abs' function to fully
# disable absolute values.
Context()->parens->remove('|');
# Give consistent error messages if the '|' absolute value parenthesis operator
# is attempted to be used by the student.
Context()->{error}{convert} = sub {
my $message = shift;
$message =~ s/Unexpected character '~~|'/Absolute value is not allowed/;
return $message;
};
$ans = Compute('1/2');
Setup
Specific operations in the context can be disabled with
Context()->operations->undefine. The predefined
operations are * (multiplication), /
(division), + (addition), - (subtraction),
! (factorial), >< (cross product),
U (union), ^ (exponent), **
(exponent), . (dot product), and , (list
creation).
After disabling an operation, it can be re-enabled with
Context()->operators->redefine, e.g.,
Context()->operators->redefine('^').
Operators can be removed from the context with
Context()->operators->remove, but this is not
recommended as it makes it completely unknown in the context so that
students will not get helpful error messages if they try to use
them.
Specific functions can be disabled in the context with
Context()->functions->undefine. The predefined
functions are sin, cos, tan,
sec, csc, cot, asin,
acos, atan, asec,
acsc, acot, sinh,
cosh, tanh, sech,
csch, coth, asinh,
acosh, atanh, asech,
csch, acoth, ln,
log, log10, exp,
sqrt, abs, int, sgn,
atan2, norm, unit,
arg, mod, Re, Im,
and conj.
In addition, classes of functions can be disabled by passing one of
the following arguments to
Context()->functions->disable:
Trig: disables all trig functions listed in both
SimpleTrig and InverseTrig functionsSimpleTrig: disables sin,
cos, tan, sec, csc,
cotInverseTrig: disables asin,
acos, atan, asec,
acsc, acot, atan2Hyperbolic: disables all hyperbolic functions in both
SimpleHyperbolic and InverseHyperbolic
functionsSimpleHyperbolic: disables sinh,
cosh, tanh, sech,
csch, cothInverseHyperbolic: disables asinh,
acosh, atanh, asech,
acsch, acothNumeric: disables ln, log,
log10, exp, sqrt,
abs, int, sgnVector: disables norm,
unitComplex: disables arg, mod,
Re, Im, conjAll: diables all predefined functionsAlternatively, the following syntax can be used.
Parser::Context::Functions::Disable('All');BEGIN_PGML
Find the numerical value: [`\sin^2(\pi / 4) =`] [____]{$ans}
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.