Context flags
Contents
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( reduceConstants => 0, reduceConstantFunctions => 0 ); Context()>flags>set(formatStudentAnswer => '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(x5)")>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(formatStudentAnswer => '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.
 Introduction to Contexts
 Common Contexts
 POD documentation  see the files beginning with
context
 How to list Context flags
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.

1E14

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.

1E12

useBaseTenLog

Do/don't use base 10 when computing log() . When 0 , use base [math]e[/math].

0

NumberCheck

A code reference to a subroutine used to check the format of numbers when a student answer is parsed. It is passed the Parser::Number object to be checked, and can use its {value} or {value_string} properties during the check, and its Error() method to report errors. See the NoDecimals implementation in pg/lib/Parser/Number.pm for an example.

undef

Flags for Formulas
Flag  Description  Default 

reduceConstants

Do/don't combine constants when the operands of an operator are constant. E.g., Formula("2 * 3") will become Formula("6") automatically when this is set to 1 , but will remain unchanged when it is set to 0 .

1

reduceConstantFunctions

Do/don't compute functions when their arguments are all constants. E.g., Formula("sqrt(2)") will become Formula("1.4142135623731") when this is set to 1 , but will remain unchanged when it is set to 0 .

1

checkUndefinedPoints

Do/don't allow test points where a Formula is undefined. This can be useful if you want to make sure a student's answer is undefined at the same locations as the correct answer. E.g., you want to distinguish between ln(x) and ln(x) . It often helps to use test_at in this case, and you may want to increase num_points so that sufficient test points are located where the Formula is defined.

0

limits

The range of values to use for variables in determining the test points for Formula comparisons. This the the default used for all variables; the limits for individual variables can be set using Context variables object, as in this example:
See the Introduction to Contexts for more details. 
[2,2]

num_points

The number of random test points to use during function comparisons. This is in addition to any test_at points, but if test_points are given, no random points are given.

5

granularity

This gives the minimum distance between possible test points used to compare two Formulas. The distance is determined by dividing the length of the interval specified by limits by the granularity . For example, with limits=>[0,5] and granularity=>5 , the test points will be integers, while with granularity=>20, the test points will be multiples of 1/4.

1000

resolution

An alternative to granularity , this value specifies the spacing between possible test points for Formula comparisons. For example, with limits=>[0,5] and resolution=>1 , the test points will be integers, while resolution=>1/4 would mean the test points are multiples of 1/4. If set, this takes precedence over granularity .

undef

max_adapt

This is the largest value allowed for an adaptive parameter. If an adaptive parameter exceeds this limit, a warning will be issued.  1E8

max_undefined

When checkUndefinedPoints is set, this gives the maximum number of test points that can be at locations where the Formula is undefined. If undef , there is no limit, but it may be best to set a limit so that some points where the function actually is defined will guaranteed to be used.

undef

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
