Context flags

From WeBWorK_wiki
Revision as of 14:15, 11 August 2012 by Dpvc (talk | contribs) (Finished Intervals, Unions, Sets section -- only Formulas left)
Jump to navigation Jump to search

Using Context Flags

Each Context object contains a collection of flags that control various aspects of how the Context operates. The main flags are described below, though some contexts may have additional flags. To view the flags for the current Context, enter

   TEXT( pretty_print(Context()->flags->all));

to your PG file. (The interactive PGLabs page is an easy place to do this.)

You can change the value of one or more Context flags as in the following examples:

   Context()->flags->set(
      reduceContstants => 0,
      reduceConstantFunctions => 0
   );
   
   Context()->flags->set(formatStudentAnswers => 'parsed');
   
   Context()->flags->set(limits => [0,1]);

Many flags can be applied directly to a MathObject to override the setting in the Context. For example,

   $f = Formula("sqrt(x-5)")->with(limits => [5,7]);

sets the limits for $f without changing the default used for other Formulas.

Similarly, some flags can be overridden in the answer checker's option list:

   ANS($f->cmp(formatStudentAnswers => 'parsed'));
   ANS($r->cmp(tolerance => .05, tolType => 'absolute'));

In this way, it is not always necessary to change the Context itself in order to affect the flag values.

Further Reading


Table of Context Flags

Flags for Reals

Flag Description Default
useFuzzyReals Do/don't use tolerance and toltype to determine when two numbers are equal. When 1, the comparisons are "fuzzy" (meaning allowed to be slightly off), when 0 the native Perl comparison is used. Note that this applies to all comparisons of MathObjects, both in Perl code as well as in student answer checking. So when set, Real(1) == Real(1.0000001) will be true (in the default Context settings). This lets you perform comparisons in exactly the same way that the answer checkers do. 1
tolerance The allowed error when comparing numbers for equality. When tolType is "absolute", the absolute value of the difference must be less than this; when tolType is "relative", then the difference of the two divided by the first must be less than this in absolute value, provided both are sufficiently larger than zero as determined by the zeroLevel (if one is closer to zero than that, then the zeroLevelTol is used instead as an absolute tolerance). .001
tolType Determines whether checks for equality use absolute or relative tolerances. See tolerance for details. "relative"
zeroLevel When tolType is "relative", then numbers smaller than this in absolute value will cause equality checks to switch to absolute comparisons with tolerance given by zeroLevelTol. This prevents the relative tolerance computations from blowing up. 1E-14
zeroLevelTol The tolerance to use when tolType is "relative", and one of the numbers being compared is smaller than the zeroLevel. See zeroLevelTol and tolerance for details. 1E-12
useBaseTenLog Do/don't use base 10 when computing log(). When 0, use base [math]e[/math]. 0

Flags for Formulas

Flag Description Default
1
checkUndefinedPoints
default: 0
Usage: $context->flags->set(checkUndefinedPoints=>1);
Description: If the answer to a question is a formula, then checkUndefinedPoints allows possible test points at which to compare the student answer with the correct answer to be points where the correct answer is undefined. For example, a student answer of ln(|x|) when the correct answer is ln(x) may be accepted as correct if checkUndefinedPoints=>0 since all test points would be positive numbers and may not if checkUndefinedPoints=>1 since some test points may not be positive.
See also: limits, max_undefined
limits
default: [-2 , 2]
Usage: $context->flags->set(x=>{limits=>[-1,1]});
Description: If the answer to a question is a formula in the variable x, this sets the interval over which the values of x are selected to compare the student's entered formula to the correct formula.
See also: resolution, granularity, num_points
max_adapt
default: 100000000
max_undefined
default:
Usage: $context->flags->set(max_undefined=>1);
Description: If the answer to a question is a formula, and we have allowed undefined test points at which to compare the student answer with the correct answer, max_undefined specifies the maximum number of possible test points where the correct answer is undefined. In our example, max_undefined=>1 means that at most one test can be taken as a point where the correct answer is undefined.
See also: checkUndefinedPoints
num_points
default: 5
Usage: $context->flags->set(num_points=>5);
Description: If the answer to a question is a formula in the variable x, this sets the number of values of x are selected to compare the student's entered formula to the correct formula.
See also: limits, granularity, resolution
granularity
default: 1000
Usage: $context->flags->set(granularity=>5000);
Description: If the answer to a question is a formula, then granularity sets the minimum distance between possible test points at which to compare the student answer with the correct answer. The distance is determined by dividing the length of the interval specified by limits by granularity. In our example, with the default limits, the check points would be no closer than 4/5000.
See also: limits, num_points, resolution
reduceConstantFunctions
default: 1
reduceConstants
default: 1
resolution
default:
Usage: $context->flags->set(resolution=>1/2);
Description: If the answer to a question is a formula, then beginning at the left endpoint of the limits, this sets the spacing between possible test points at which to compare the student answer with the correct answer. In our example, with the default limits, the only possible check points will be -2,-1.5,-1,-.5,0,.5,1,1.5,2.
See also: limits, granularity, num_points


Flags for Intervals, Sets, and Unions

Flag Description Default
ignoreEndpointTypes Do/don't ignore the closed/open status of Interval endpoints when comparing Intervals. When set to 1, two intervals whose endpoints match numerically will be equal, regardless of whether they are open or closed at the endpoints. This is set to 1 automatically for student answers if requireParenMatch is set to 0 in the options to the answer checker. 0
reduceSets Do/don't remove repeated elements from Sets when they are created. For student answers, this is automatically set to the value of studentsMustReduceUnions for the duration of the answer check. 1
reduceSetsForComparison Do/don't reduce Sets (temporarily) before they are compared. For student answers, this is automatically set to the value of showUnionReduceWarnings for the duration of the answer check when studentsMustReduceUnions is set. 1
reduceUnions Do/don't combine overlapping intervals or Sets when Unions are created. For student answers, this is automatically set to the value of studentsMustReduceUnions for the duration of the answer check. 1
reduceUnionsForComparison Do/don't reduce Unions (temporarily) before they are compared. For student answers, this is automatically set to the value of showUnionReduceWarnings for the duration of the answer check when studentsMustReduceUnions is set. 1

Flags for Strings

Flag Description Default
allowEmptyStrings Do/don't allow an empty string to form a String object, even though there is no definition for that. (Useful for if you want to process blank answers.) 1
infiniteWord The word used by the Infinite object to represent infinity (i.e., the string it will output) when displayed. "infinity"

Flags Controlling Formatting

Flag Description Default
formatStudentAnswer Determines how the student's answer is shown in the "Entered" box in the results table when the students submits the answers. When set to "evaluated", it is the final result of the expression. When set to "parsed" it is the Formula entered by the student prior to being evaluated. When set to "reduced", it is the result of calling the reduce() method on the student's answer. "evaluated"
showExtraParens Determines the level to which extra parentheses are inserted to help make the meaning clear. When set to 0, only parentheses required by the operator precedences are inserted. When set to 1, extra parentheses are added to help make the meaning more clear in situations where students tend not to know the precedence rules very well. When set to 2, extra parentheses are added to make the expression painfully unambiguous. 1
ijk Do/don't use [math]ijk[/math] notation for displaying all vectors. When set to 0, angle brackets are used as delimiters to show vectors in coordinate form. 0
ijkAnyDimension Do/don't convert expressions involving [math]ijk[/math] notation to the proper dimension before comparing two vectors (e.g., Vector context could still be used for vectors in the plane). 1

Flags Controlling Warnings

The following are used by contextTypeset.pl to control when warnings are issued.

Flag Description Default
allowBadOperands Do/don't check whether operator operand types are correct; when 0, warnings are issued. 0
allowMissingOperands Do/don't allow operators to have missing operands; when 0, warnings are issued. 0
allowBadFunctionInputs Do/don't check whether function input types are correct; when 0, warnings are issued. 0
allowMissingFunctionInputs Do/don't allow functions to have missing arguments; when 0, warnings are issued. 0
allowWrongArgCount Do/don't allow functions to have too many arguments; when 0, warnings are issued. 0