Difference between revisions of "Context flags"
(20 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | ==Context Flags== |
+ | == Using Context Flags == |
− | There are a number of values stored in the context that control things<br />like the tolerance used when comparing numbers, and so on. |
||
− | ==Some Available Contexts== |
||
+ | Each [[Introduction to Contexts|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 |
||
− | * Numeric (variable x, no Complex, Point, etc.)<br /> |
||
− | * Complex (variable z, i = ![math]\sqrt{-1}![/math], no points, etc.)<br /> |
||
− | * Point (another name for Vector context)<br />* Vector (variables x, y, z, angle brakets form vectors,<br />i, j, k are unit coordinate vectors, etc.)<br /> |
||
− | * Vector2D (same as Vector, but with i and j in 2D)<br /> |
||
− | * Matrix (square brakets form matrices)<br />* Interval (parens and brakets form intervals) |
||
− | == Context Flags == |
||
+ | TEXT( pretty_print(Context()->flags->all)); |
||
− | You control the value of these flags with commands such as: |
||
− | $context->flags->set(tolerance=>.00001); |
||
− | For example, |
||
+ | to your PG file. (The interactive [[PGLabs]] page is an easy place to do this.) |
||
− | $context->flags->set(ijk=>1); |
||
+ | You can change the value of one or more Context flags as in the following examples: |
||
− | will cause the output of all vectors to be written in ijk formatrather than <...> format. |
||
+ | Context()->flags->set( |
||
+ | reduceConstants => 0, |
||
+ | reduceConstantFunctions => 0 |
||
+ | ); |
||
+ | |||
+ | Context()->flags->set(formatStudentAnswer => 'parsed'); |
||
+ | |||
+ | Context()->flags->set(limits => [0,1]); |
||
− | == Context Flags List == |
||
+ | Many flags can be applied directly to a MathObject to override the setting in the Context. For example, |
||
− | The following list gives each standard context flag along with a description of its use. |
||
− | There are not currently any context specific flags, but this may change. |
||
− | To find out exactly which flags can be set in a specific context and |
||
− | their current value go to [[HowToListContextFlags]] |
||
− | ;allowBadFunctionInputs |
||
+ | $f = Formula("sqrt(x-5)")->with(limits => [5,7]); |
||
− | :default: 0 |
||
− | ;allowBadOperands |
||
− | :default: 0 |
||
− | ;allowEmptyStrings |
||
− | :default: 1 |
||
− | ;allowMissingFunctionInputs |
||
− | :default: 0 |
||
− | ;allowMissingOperands |
||
− | :default: 0 |
||
− | ;allowWrongArgCount |
||
− | :default: 0 |
||
− | ;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 |
||
− | ;formatStudentAnswer |
||
− | :default: evaluated |
||
− | ;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 |
||
− | ;ignoreEndpointTypes |
||
− | :default: 0 |
||
− | :Usage: $context->flags->set(ignoreEndpointTypes=>1); |
||
− | :Description: If the answer to a question is an interval, the default value of ignoreEndpointTypes is set so that the inclusion or exclusion of endpoints in the students answer needs to match the correct answer to be correct. In our example, if we set ignoreEndpointTypes=>1, a student answer will be correct provided the interval is correct regardless of endpoints. |
||
− | :See also: |
||
− | ;ijk |
||
− | :default: 0 |
||
− | :Usage: $context->flags->set(ijk=>1); |
||
− | :Description: ijk=>1 will cause the output of all vectors to be written in ijk format rather than <...> format. The default setting will output vectors in <...> format. |
||
− | ;infiniteWord |
||
− | :default: infinity |
||
− | ;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 |
||
− | ;reduceConstantFunctions |
||
− | :default: 1 |
||
− | ;reduceConstants |
||
− | :default: 1 |
||
− | :reduceSets |
||
− | :default: 1 |
||
− | ;reduceSetsForComparison |
||
− | :default: 1 |
||
− | ;reduceUnions |
||
− | :default: 1 |
||
− | ;reduceUnionsForComparison |
||
− | :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 |
||
− | ;showExtraParens |
||
− | :default: 1 |
||
− | ;tolType= |
||
− | :default: relative |
||
− | :Usage: $context->flags->set(tolType=>'relative'); |
||
− | :Description: Sets tolerance type as relative or absolute for student answers. The actual result of this depends on the value of tolerance. If tolType is relative, with the default value for tolerance our example would set the answer tolerance to 0.1% of the correct answer. If tolType is absolute, with the default value for tolerance our example would set the answer tolerance to within 0.001 of the absolute value of the correct answer. |
||
− | :See also: tolerance |
||
− | ;tolerance |
||
− | :default: 0.001 |
||
− | :Usage: $context->flags->set(tolerance=>.00001); |
||
− | :Description: Sets tolerance for student answers. The actual result of this depends on the value of tolType. The default value of tolType is relative and under this setting our example would set the answer tolerance to 0.001% of the correct answer. |
||
− | :See also: tolType |
||
− | ;useBaseTenLog |
||
− | :default: 0 |
||
− | ;useFuzzyReals |
||
− | :default: 1 |
||
− | ;zeroLevel:default: 1e-14 |
||
− | :Usage: $context->flags->set(zeroLevel=>.00001); |
||
− | :Description: If the value of an answer is less in absolute value than the zeroLevel, then zeroLevelTol is the absolute tolerance used for student answers. Under this example, any answer whose absolute value is smaller than the 0.00001 is considered correct if it is within the value of zeroLevelTol of the correct answer. |
||
− | :See also: zeroLevelTol, tolerance, tolType |
||
− | ;zeroLevelTol |
||
− | :default: 1e-12 |
||
− | :Usage: $context->flags->set(zeroLevelTol=>.00001); |
||
− | :Description: If an answer is smaller in absolute value than zeroLevel, then this sets the absolute tolerance for the student answer. Under this example, any answer whose absolute value is smaller than zeroLevel is considered correct if it is within 0.00001 of the correct answer. Note that this is overridden by the absolute tolerance if the tolType is set to absolute. |
||
− | :See also: zeroLevel, tolerance, tolType |
||
+ | sets the limits for <code>$f</code> 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. |
||
+ | |||
+ | <div style="font-weight:bold; font-size:125%; margin-top:1em">Further Reading</div> |
||
+ | * [[Introduction to Contexts]] |
||
+ | * [[Common Contexts]] |
||
+ | * [http://webwork.maa.org/pod/pg POD documentation] -- see the files beginning with <code>context</code> |
||
+ | * [[How to list Context flags]] |
||
+ | |||
+ | |||
+ | == Table of Context Flags == |
||
+ | |||
+ | === Flags for Reals === |
||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="useFuzzyReals" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>useFuzzyReals</code> |
||
+ | | style="padding:5px" | Do/don't use <code>[[#tolerance|tolerance]]</code> and <code>[[#tolType|toltype]]</code> to determine when two numbers are equal. When <code>1</code>, the comparisons are "fuzzy" (meaning allowed to be slightly off), when <code>0</code> 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, <code>Real(1) == Real(1.0000001)</code> will be true (in the default Context settings). This lets you perform comparisons in exactly the same way that the answer checkers do. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="tolerance" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>tolerance</code> |
||
+ | | style="padding:5px" | The allowed error when comparing numbers for equality. When <code>[[#tolType|tolType]]</code> is <code>"absolute"</code>, the absolute value of the difference must be less than this; when <code>tolType</code> is <code>"relative"</code>, 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 <code>[[#zeroLevel|zeroLevel]]</code> (if one is closer to zero than that, then the <code>[[#zeroLevelTol|zeroLevelTol]]</code> is used instead as an absolute tolerance). |
||
+ | | style="padding:5px; text-align:center" | <code>.001</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="tolType" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>tolType</code> |
||
+ | | style="padding:5px" | Determines whether checks for equality use absolute or relative tolerances. See <code>[[#tolerance|tolerance]]</code> for details. |
||
+ | | style="padding:5px; text-align:center" | <code>"relative"</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="zeroLevel" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>zeroLevel</code> |
||
+ | | style="padding:5px" | When <code>[[#tolType|tolType]]</code> is <code>"relative"</code>, then numbers smaller than this in absolute value will cause equality checks to switch to absolute comparisons with tolerance given by <code>[[#zeroLevelTol|zeroLevelTol]]</code>. This prevents the relative tolerance computations from blowing up. |
||
+ | | style="padding:5px; text-align:center" | <code>1E-14</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="zeroLevelTol" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>zeroLevelTol</code> |
||
+ | | style="padding:5px" | The tolerance to use when <code>[[#tolType|tolType]]</code> is <code>"relative"</code>, and one of the numbers being compared is smaller than the <code>[[#zeroLevel|zeroLevel]]</code>. See <code>[[#zeroLevelTol|zeroLevelTol]]</code> and <code>[[#tolerance|tolerance]]</code> for details. |
||
+ | | style="padding:5px; text-align:center" | <code>1E-12</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="useBaseTenLog" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>useBaseTenLog</code> |
||
+ | | 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="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> |
||
+ | |||
+ | |} |
||
+ | |||
+ | === Flags for Formulas === |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceConstants" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceConstants</code> |
||
+ | | 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="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> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- 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> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="limits" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>limits</code> |
||
+ | | 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: |
||
+ | |||
+ | : <code>Context()->variables->set(x=>{limits=>[0,1]});</code> |
||
+ | |||
+ | See the [[Introduction to Contexts]] for more details. |
||
+ | |||
+ | | style="padding:5px; text-align:center" | <code>[-2,2]</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="num_points" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>num_points</code> |
||
+ | | 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. |
||
+ | | style="padding:5px; text-align:center" | <code>5</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- 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> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- 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> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="max_adapt" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>max_adapt</code> |
||
+ | | 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. |
||
+ | | 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 === |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="ignoreEndpointTypes" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>ignoreEndpointTypes</code> |
||
+ | | style="padding:5px" | Do/don't ignore the closed/open status of Interval endpoints when comparing Intervals. When set to <code>1</code>, two intervals whose endpoints match numerically will be equal, regardless of whether they are open or closed at the endpoints. This is set to <code>1</code> automatically for student answers if <code>requireParenMatch</code> is set to <code>0</code> in the options to the answer checker. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceSets" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceSets</code> |
||
+ | | style="padding:5px" | Do/don't remove repeated elements from Sets when they are created. For student answers, this is automatically set to the value of <code>[[Answer_Checker_Options_(MathObjects)#studentsMustReduceUnions|studentsMustReduceUnions]]</code> for the duration of the answer check. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceSetsForComparison" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceSetsForComparison</code> |
||
+ | | style="padding:5px" | Do/don't reduce Sets (temporarily) before they are compared. For student answers, this is automatically set to the value of <code>[[Answer_Checker_Options_(MathObjects)#showUnionReduceWarnings|showUnionReduceWarnings]]</code> for the duration of the answer check when <code>[[Answer_Checker_Options_(MathObjects)#studentsMustReduceUnions|studentsMustReduceUnions]]</code> is set. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceUnions" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceUnions</code> |
||
+ | | style="padding:5px" | Do/don't combine overlapping intervals or Sets when Unions are created. For student answers, this is automatically set to the value of <code>[[Answer_Checker_Options_(MathObjects)#studentsMustReduceUnions|studentsMustReduceUnions]]</code> for the duration of the answer check. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="reduceUnionsForComparison" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>reduceUnionsForComparison</code> |
||
+ | | style="padding:5px" | Do/don't reduce Unions (temporarily) before they are compared. For student answers, this is automatically set to the value of <code>[[Answer_Checker_Options_(MathObjects)#showUnionReduceWarnings|showUnionReduceWarnings]]</code> for the duration of the answer check when <code>[[Answer_Checker_Options_(MathObjects)#studentsMustReduceUnions|studentsMustReduceUnions]]</code> is set. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | |} |
||
+ | |||
+ | === Flags for Strings === |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowEmptyStrings" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowEmptyStrings</code> |
||
+ | | style="padding:5px" | 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.) |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="infiniteWord" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>infiniteWord</code> |
||
+ | | style="padding:5px" | The word used by the Infinite object to represent infinity (i.e., the string it will output) when displayed. |
||
+ | | style="padding:5px; text-align:center" | <code>"infinity"</code> |
||
+ | |||
+ | |} |
||
+ | |||
+ | === Flags Controlling Formatting === |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="formatStudentAnswer" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>formatStudentAnswer</code> |
||
+ | | style="padding:5px" | 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 <code>"evaluated"</code>, it is the final result of the expression. When set to <code>"parsed"</code> it is the Formula entered by the student prior to being evaluated. When set to <code>"reduced"</code>, it is the result of calling the <code>reduce()</code> method on the student's answer. |
||
+ | | style="padding:5px; text-align:center" | <code>"evaluated"</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="showExtraParens" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>showExtraParens</code> |
||
+ | | style="padding:5px" | Determines the level to which extra parentheses are inserted to help make the meaning clear. When set to <code>0</code>, only parentheses required by the operator precedences are inserted. When set to <code>1</code>, 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 <code>2</code>, extra parentheses are added to make the expression painfully unambiguous. |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="ijk" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>ijk</code> |
||
+ | | style="padding:5px" | Do/don't use <math>ijk</math> notation for displaying all vectors. When set to <code>0</code>, angle brackets are used as delimiters to show vectors in coordinate form. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="ijkAnyDimension" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>ijkAnyDimension</code> |
||
+ | | style="padding:5px" | Do/don't convert expressions involving <math>ijk</math> notation to the proper dimension before comparing two vectors (e.g., <code>Vector</code> context could still be used for vectors in the plane). |
||
+ | | style="padding:5px; text-align:center" | <code>1</code> |
||
+ | |||
+ | |} |
||
+ | |||
+ | === Flags Controlling Warnings === |
||
+ | |||
+ | The following are used by <code>contextTypeset.pl</code> to control when warnings are issued. |
||
+ | |||
+ | {| class="wikitable" |
||
+ | ! Flag !! Description !! style="padding:5px" | Default |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowBadOperands" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowBadOperands</code> |
||
+ | | style="padding:5px" | Do/don't check whether operator operand types are correct; when <code>0</code>, warnings are issued. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowMissingOperands" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowMissingOperands</code> |
||
+ | | style="padding:5px" | Do/don't allow operators to have missing operands; when <code>0</code>, warnings are issued. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowBadFunctionInputs" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowBadFunctionInputs</code> |
||
+ | | style="padding:5px" | Do/don't check whether function input types are correct; when <code>0</code>, warnings are issued. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowMissingFunctionInputs" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowMissingFunctionInputs</code> |
||
+ | | style="padding:5px" | Do/don't allow functions to have missing arguments; when <code>0</code>, warnings are issued. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | <!-------------------------------------------------------------------------------> |
||
+ | |- style="vertical-align: top" id="allowWrongArgCount" |
||
+ | | style="padding:5px; white-space:nowrap" | <code>allowWrongArgCount</code> |
||
+ | | style="padding:5px" | Do/don't allow functions to have too many arguments; when <code>0</code>, warnings are issued. |
||
+ | | style="padding:5px; text-align:center" | <code>0</code> |
||
+ | |||
+ | |} |
||
Line 124: | 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
|