Difference between revisions of "Context flags"
(Finished Intervals, Unions, Sets section -- only Formulas left) |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 10: | Line 10: | ||
Context()->flags->set( |
Context()->flags->set( |
||
− | + | reduceConstants => 0, |
|
reduceConstantFunctions => 0 |
reduceConstantFunctions => 0 |
||
); |
); |
||
− | Context()->flags->set( |
+ | Context()->flags->set(formatStudentAnswer => 'parsed'); |
Context()->flags->set(limits => [0,1]); |
Context()->flags->set(limits => [0,1]); |
||
Line 26: | Line 26: | ||
Similarly, some flags can be overridden in the answer checker's option list: |
Similarly, some flags can be overridden in the answer checker's option list: |
||
− | ANS($f->cmp( |
+ | ANS($f->cmp(formatStudentAnswer => 'parsed')); |
ANS($r->cmp(tolerance => .05, tolType => 'absolute')); |
ANS($r->cmp(tolerance => .05, tolType => 'absolute')); |
||
Line 34: | Line 34: | ||
* [[Introduction to Contexts]] |
* [[Introduction to Contexts]] |
||
* [[Common Contexts]] |
* [[Common Contexts]] |
||
− | * [http://webwork.maa.org/pod/ |
+ | * [http://webwork.maa.org/pod/pg POD documentation] -- see the files beginning with <code>context</code> |
* [[How to list Context flags]] |
* [[How to list Context flags]] |
||
Line 79: | Line 79: | ||
| style="padding:5px" | Do/don't use base 10 when computing <code>log()</code>. When <code>0</code>, use base <math>e</math>. |
| style="padding:5px" | Do/don't use base 10 when computing <code>log()</code>. When <code>0</code>, use base <math>e</math>. |
||
| style="padding:5px; text-align:center" | <code>0</code> |
| style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="NumberCheck" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>NumberCheck</code> |
||
+ | | style="padding:5px" | A code reference to a subroutine used to check the format of numbers when a student answer is parsed. It is passed the <code>Parser::Number</code> object to be checked, and can use its <code>{value}</code> or <code>{value_string}</code> properties during the check, and its <code>Error()</code> method to report errors. See the <code>NoDecimals</code> implementation in <code>[https://github.com/openwebwork/pg/blob/master/lib/Parser/Number.pm#L81 pg/lib/Parser/Number.pm]</code> for an example. |
||
+ | | style="padding:5px; text-align:center" | <code>undef</code> |
||
|} |
|} |
||
Line 88: | Line 94: | ||
<!-------------------------------------------------------------------------------> |
<!-------------------------------------------------------------------------------> |
||
− | |- style="vertical-align: top" id="" |
+ | |- style="vertical-align: top" id="reduceConstants" |
− | | style="padding:5px; white-space:nowrap" | <code></code> |
+ | | style="padding:5px; white-space:nowrap" | <code>reduceConstants</code> |
− | | style="padding:5px" | |
+ | | style="padding:5px" | Do/don't combine constants when the operands of an operator are constant. E.g., <code>Formula("2 * 3")</code> will become <code>Formula("6")</code> automatically when this is set to <code>1</code>, but will remain unchanged when it is set to <code>0</code>. |
| style="padding:5px; text-align:center" | <code>1</code> |
| style="padding:5px; text-align:center" | <code>1</code> |
||
− | |} |
||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceConstantFunctions" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceConstantFunctions</code> |
||
+ | | style="padding:5px" | Do/don't compute functions when their arguments are all constants. E.g., <code>Formula("sqrt(2)")</code> will become <code>Formula("1.4142135623731")</code> when this is set to <code>1</code>, but will remain unchanged when it is set to <code>0</code>. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
− | ;checkUndefinedPoints |
||
+ | <!-------------------------------------------------------------------------------> |
||
− | :default: 0 |
||
+ | |- style="vertical-align: top" id="checkUndefinedPoints" |
||
− | : |
+ | | style="padding:5px; white-space:nowrap" | <code>checkUndefinedPoints</code> |
− | + | | style="padding:5px" | 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 <code>ln(x)</code> and <code>ln(|x|)</code>. It often helps to use <code>[[Formula (MathObject Class)#test_at|test_at]]</code> in this case, and you may want to increase <code>[[#num_points|num_points]]</code> so that sufficient test points are located where the Formula is defined. |
|
− | + | | style="padding:5px; text-align:center" | <code>0</code> |
|
− | ;limits |
||
+ | <!-------------------------------------------------------------------------------> |
||
− | :default: [-2 , 2] |
||
+ | |- style="vertical-align: top" id="limits" |
||
− | : Usage: <code>$context->flags->set(x=>{limits=>[-1,1]});</code> |
||
+ | | style="padding:5px; white-space:nowrap" | <code>limits</code> |
||
− | :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. |
||
+ | | style="padding:5px" | 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 <code>variables</code> object, as in this example: |
||
− | :See also: resolution, granularity, num_points |
||
− | ;max_adapt |
||
+ | : <code>Context()->variables->set(x=>{limits=>[0,1]});</code> |
||
− | :default: 100000000 |
||
− | ;max_undefined |
||
+ | See the [[Introduction to Contexts]] for more details. |
||
− | :default: |
||
− | : Usage: <code>$context->flags->set(max_undefined=>1);</code> |
||
− | :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 |
||
+ | | style="padding:5px; text-align:center" | <code>[-2,2]</code> |
||
− | :default: 5 |
||
− | : Usage: <code>$context->flags->set(num_points=>5);</code> |
||
− | :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 |
||
+ | |- style="vertical-align: top" id="num_points" |
||
− | : Usage: <code>$context->flags->set(granularity=>5000);</code> |
||
+ | | style="padding:5px; white-space:nowrap" | <code>num_points</code> |
||
− | :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. |
||
+ | | style="padding:5px" | The number of random test points to use during function comparisons. This is in addition to any <code>[[Formula (MathObject Class)#test_at|test_at]]</code> points, but if <code>[[Formula (MathObject Class)#test_points|test_points]]</code> are given, no random points are given. |
||
− | :See also: limits, num_points, resolution |
||
+ | | style="padding:5px; text-align:center" | <code>5</code> |
||
− | ;reduceConstantFunctions |
||
+ | <!-------------------------------------------------------------------------------> |
||
− | :default: 1 |
||
+ | |- style="vertical-align: top" id="granularity" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>granularity</code> |
||
+ | | style="padding:5px" | 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 <code>[[#limits|limits]]</code> by the <code>granularity</code>. For example, with <code>limits=>[0,5]</code> and <code>granularity=>5</code>, the test points will be integers, while with granularity=>20</code>, the test points will be multiples of 1/4. |
||
+ | | style="padding:5px; text-align:center" | <code>1000</code> |
||
− | ;reduceConstants |
||
+ | <!-------------------------------------------------------------------------------> |
||
− | :default: 1 |
||
+ | |- style="vertical-align: top" id="resolution" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>resolution</code> |
||
+ | | style="padding:5px" | An alternative to <code>[[#granularity|granularity]]</code>, this value specifies the spacing between possible test points for Formula comparisons. For example, with <code>limits=>[0,5]</code> and <code>resolution=>1</code>, the test points will be integers, while <code>resolution=>1/4</code> would mean the test points are multiples of 1/4. If set, this takes precedence over <code>granularity</code>. |
||
+ | | style="padding:5px; text-align:center" | <code>undef</code> |
||
− | ;resolution |
||
+ | <!-------------------------------------------------------------------------------> |
||
− | :default: |
||
+ | |- style="vertical-align: top" id="max_adapt" |
||
− | : Usage: <code>$context->flags->set(resolution=>1/2);</code> |
||
+ | | style="padding:5px; white-space:nowrap" | <code>max_adapt</code> |
||
− | :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. |
||
+ | | style="padding:5px" | This is the largest value allowed for an adaptive parameter. If an adaptive parameter exceeds this limit, a warning will be issued. |
||
− | :See also: limits, granularity, num_points |
||
+ | | style="padding:5px; text-align:center" | <code>1E8</code> |
||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="max_undefined" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>max_undefined</code> |
||
+ | | style="padding:5px" | When <code>[[#checkUndefinedPoints|checkUndefinedPoints]]</code> is set, this gives the maximum number of test points that can be at locations where the Formula is undefined. If <code>undef</code>, 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. |
||
+ | | style="padding:5px; text-align:center" | <code>undef</code> |
||
+ | |||
+ | |} |
||
=== Flags for Intervals, Sets, and Unions === |
=== Flags for Intervals, Sets, and Unions === |
||
Line 271: | Line 284: | ||
[[Category:Contexts]] |
[[Category:Contexts]] |
||
[[Category:MathObjects]] |
[[Category:MathObjects]] |
||
+ | [[Category:Reference Tables]] |
||
[[Category:AIMWeBWorK Working Groups]] |
[[Category:AIMWeBWorK Working Groups]] |
Latest revision as of 16:18, 7 April 2021
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(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(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.
|
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
|
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
|