DigitsTolType: Difference between revisions
(format code) |
(added historical tag and gave updated problem link) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ | {{historical}} | ||
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/problem-techniques/DigitsTolType.html a newer version of this problem]</p> | |||
<h2>Digits TolType</h2> | <h2>Digits TolType</h2> | ||
Line 48: | Line 49: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> | <td style="background-color:#ffffdd;border:black 1px dashed;"> | ||
<pre> | <pre> | ||
Context("Numeric") | Context("Numeric"); | ||
Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 1); | Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 1); | ||
$answer = Real("pi"); | $answer = Real("pi"); | ||
Line 73: | Line 74: | ||
<p> | <p> | ||
<b>Warning:</b> this tolerance type also applies to formula comparisons. For example if the answer is 2^x and a student enters e^(0.69x), this will probably not be accepted. Random test values will be used for x to make that comparison. For example if one of the test values is x=2, the correct output is 4 and the student's output would be 3.9749... and this would be declared as not a match, since the first three digits to not agree. | <b>Warning:</b> this tolerance type also applies to formula comparisons. For example if the answer is 2^x and a student enters e^(0.69x), this will probably not be accepted. Random test values will be used for x to make that comparison. For example if one of the test values is x=2, the correct output is 4 and the student's output would be 3.9749... and this would be declared as not a match, since the first three digits to not agree. | ||
</p> | |||
<p> | |||
<b>Warning:</b> this article is about using this tolerance type for comparison of correct answers to student answers. But if this tolerance type is activated for a context, it also applies to comparisons you might make in problem setup code. It may be important to understand that it is not symmetric. For example, under default conditions, <code>Real(4) == Real(3.995)</code> is false, while <code>Real(3.995) == Real(4)</code> is true. The left operand is viewed as the "correct" value. With <code>Real(4) == Real(3.995)</code>, that "5" violates the <code>tolExtraDigits</code> checking. But with <code>Real(3.995) == Real(4)</code>, it is as if the student entered 4.00 and has the first 3 digits correct accounting for rounding. (Note that the default tolerance type <code>relative</code> is similarly asymmetric, but the effect is more subtle. You can see it with <code>Real(4) == Real(3.996001)</code> versus <code>Real(3.996001) == Real(4)</code>.) | |||
</p> | </p> | ||
Line 119: | Line 123: | ||
<pre> | <pre> | ||
BEGIN_PGML | BEGIN_PGML | ||
This section is with [|tolTruncation|] set to false (0). The exact answer is [`\pi`]. Enter 3.14 | This section is with [|tolTruncation|] set to false (0). The exact answer is [`\pi`]. Enter 3.14, 3.141, 3.142 to see if it accepts the answer. | ||
[`\pi=`][_]{$answer2} | [`\pi=`][_]{$answer2} | ||
Line 137: | Line 141: | ||
<pre> | <pre> | ||
Context("Numeric"); | Context("Numeric"); | ||
Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0,tolExtraDigits => 2); | Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0, tolExtraDigits => 2); | ||
$answer3 = Real("3.14"); | $answer3 = Real("3.14"); | ||
</pre> | </pre> |
Latest revision as of 13:21, 28 June 2023
This problem has been replaced with a newer version of this problem
Digits TolType
This describes an alternative way for determining the tolerance type based on the number of digits.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGML.pl" ); TEXT(beginproblem()); |
Initialization: The tolType of type digits is built-in to MathObjects. |
Context("Numeric"); Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 1); $answer = Real("pi"); |
Setup:
The goal is that the student must enter at least the first
If the student enters additional digits, the first additional Warning: this tolerance type also applies to formula comparisons. For example if the answer is 2^x and a student enters e^(0.69x), this will probably not be accepted. Random test values will be used for x to make that comparison. For example if one of the test values is x=2, the correct output is 4 and the student's output would be 3.9749... and this would be declared as not a match, since the first three digits to not agree.
Warning: this article is about using this tolerance type for comparison of correct answers to student answers. But if this tolerance type is activated for a context, it also applies to comparisons you might make in problem setup code. It may be important to understand that it is not symmetric. For example, under default conditions, |
BEGIN_PGML This section is with [|tolTruncation|] set to true (1). The exact answer is [`\pi`]. Enter 3.14, 3.15, 3.141, 3.142 to see if it accepts the answer. [`\pi=`][_]{$answer} END_PGML |
First Section: This tests the default conditions for this tolerance type. It should accept 3.14, 3.141 and 3.142 as correct, but not 3.15. |
Context("Numeric"); Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0); $answer2 = Real("pi"); |
Second block explanation: First, reset the context with |
BEGIN_PGML This section is with [|tolTruncation|] set to false (0). The exact answer is [`\pi`]. Enter 3.14, 3.141, 3.142 to see if it accepts the answer. [`\pi=`][_]{$answer2} END_PGML |
Second Section: This tests when |
Context("Numeric"); Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0, tolExtraDigits => 2); $answer3 = Real("3.14"); |
Second block explanation: First, reset the context with |
BEGIN_PGML This section is with [|tolTruncation|] set to false (0) and [|tolExtraDigits|] set to 2. Enter 3.1415, 3.1416, 3.1417, 3.14888, 3.14, and 3.1415888 to see if it accepts the answer. [`\pi=`][_]{$answer3} END_PGML |
Third Section: This additionally tests when |