AnswerChecker - Implements the compare method for Value objects.
Implements the ->cmp method for Value objects. Otherwise known as MathObjects. This produces an answer checker appropriate for the type of object. Additional options can be passed to the cmp method to modify its action.
Usage:
$num = Real(3.45); # Real can be replaced by any other MathObject
ANS($num->cmp(compareOptionName => compareOptionValue, ... ))
The individual Value packages are modified below to add the needed methods.
Internal use. Set default flags for the answer checker in this object
showTypeWarnings => 1
showEqualErrors => 1
ignoreStrings => 1
studentsMustReduceUnions => 1
showUnionReduceWarnings => 1
Options for cmp
for Value::Real
:
Usage:
ANS( Real(3.56)->cmp() )
Compares response to a real value using 'fuzzy' comparison compareOptions and default values:
showTypeWarnings => 1,
showEqualErrors => 1,
ignoreStrings => 1,
Options for cmp
for Value::String
:
Usage:
$s = String("pole");
ANS($s->cmp(typeMatch => Complex("4+i")));
compare to response 'pole', don't complain about complex number responses.
compareOptions and default values:
showTypeWarnings => 1,
showEqualErrors => 1,
ignoreStrings => 1, # don't complain about string-valued responses
typeMatch => 'Value::Real'
Leading and trailing spaces are ignored when comparing strings.
Options for cmp
for Value::Point
:
Usage:
$pt = Point("(3,6)"); # preferred
$pt = Point(3,6);
$pt = Point([3,6]);
ANS($pt->cmp());
compareOptions and default values:
showTypeWarnings => 1, # warns if student response is of incorrect type
showEqualErrors => 1,
ignoreStrings => 1,
showDimensionHints => 1, # reports incorrect number of coordinates
showCoordinateHints =>1, # flags individual coordinates that are incorrect
Options for cmp
for Value::Vector
:
Usage:
$vec = Vector("<3,6,7>");
$vec = Vector(3,6,7);
$vec = Vector([3,6,7]);
ANS($vec->cmp());
compareOptions and default values:
showTypeWarnings => 1, # warns if student response is of incorrect type
showEqualErrors => 1,
ignoreStrings => 1,
showDimensionHints => 1, # reports incorrect number of coordinates
showCoordinateHints => 1, # flags individual coordinates which are incorrect
promotePoints => 0, # allow students to enter vectors as points (3,5,6)
parallel => 1, # response is correct if it is parallel to correct answer
sameDirection => 1, # response is correct if it has same orientation as correct answer
# (only has an effect when parallel => 1 is specified)
Options for cmp
for Value::Matrix
:
Usage:
$ma = Matrix([[3,6],[2,5]])
$ma = Matrix([3,6],[2,5])
ANS($ma->cmp());
compareOptions and default values:
showTypeWarnings => 1, # warns if student response is of incorrect type
showEqualErrors => 1, # reports messages that occur during element comparisons
ignoreStrings => 1,
showDimensionHints => 1, # reports incorrect number of coordinates
showCoordinateHints => 1, # flags individual coordinates which are incorrect
Usage:
$interval = Interval("(1,2]");
$interval = Interval('(',1,2,']');
ANS($inteval->cmp);
compareOptions and default values:
showTypeWarnings => 1,
showEqualErrors => 1,
ignoreStrings => 1,
showEndpointHints => 1, # show hints about which end point values are correct
showEndTypeHints => 1, # show hints about endpoint types
requireParenMatch => 1,
Options for cmp
for Value::Set
:
Usage:
$set = Set(5,6,'a', 'b')
$set = Set("{5, 6, a, b}")
The object is a finite set of real numbers. It can be used with Union and Interval.
Examples:
Interval("(-inf,inf)") - Set(0)
Compute("R-{0}") # in Interval context: Context("Interval");
Usage:
$union = Union("[4,5] U [6,7]");
$union = Union(Interval("[4,5]",Interval("[6,7]"));
ANS($union->cmp());
Options for cmp
for Value::List
:
Usage:
$lst = List("1, x, <4,5,6>"); # list of a real, a formula and a vector.
$lst = List(Real(1), Formula("x"), Vector(4,5,6));
ANS($lst->cmp(showHints=>1));
compareOptions and default values:
showTypeWarnings => 1,
showEqualErrors => 1, # show errors produced when checking equality of entries
ignoreStrings => 1, # don't show type warnings for strings
studentsMustReduceUnions => 1,
showUnionReduceWarnings => 1,
showHints => undef, # automatically set to 1 if $showPartialCorrectAnswers == 1
showLengthHints => undef, # automatically set to 1 if $showPartialCorrectAnswers == 1
showParenHints => undef, # automatically set to 1 if $showPartialCorrectAnswers == 1
partialCredit => undef, # automatically set to 1 if $showPartialCorrectAnswers == 1
ordered => 0, # 1 = must be in same order as correct answer
entry_type => undef, # determined from first entry
list_type => undef, # determined automatically
typeMatch => $element, # used for type checking the entries
firstElement => $element,
extra => undef, # used to check syntax of incorrect answers
requireParenMatch => 1, # student parens must match correct parens
removeParens => 1, # remove outermost parens, if any
implicitList => 1, # force single answers to be lists (even if they ARE lists)
Usage:
$fun = Formula("x^2-x+1");
$set = Formula("[-1, x) U (x, 2]");
A formula can have any of the other math object types as its range. Union, List, Number (Complex or Real),