Difference between revisions of "DigitsTolType"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with "<h2>Digits TolType</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This describ...")
 
m (added ;)
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  +
{{UnderConstruction}}
  +
 
<h2>Digits TolType</h2>
 
<h2>Digits TolType</h2>
   
Line 32: Line 34:
 
</pre>
 
</pre>
 
</td>
 
</td>
  +
 
<td style="background-color:#ccffcc;padding:7px;">
 
<td style="background-color:#ccffcc;padding:7px;">
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
This is built-in to MathObjects.
+
The <tt>tolType</tt> of type </tt>digits</tt> is built-in to MathObjects.
 
</p>
 
</p>
 
</td>
 
</td>
Line 45: Line 48:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Numeric")->flags->set(tolType=>'digits',tolerateTruncation=>0);
+
Context("Numeric");
  +
Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 1);
  +
$answer = Real("pi");
  +
 
</pre>
 
</pre>
 
</td>
 
</td>
  +
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
 
<ul>
 
<ul>
<li>The <pre>tolType=>'digits'</pre> switch to the digits tolerance. </li>
+
<li>The <code>tolType => 'digits'</code> switches from the default 'relative' tolerance type to the 'digits' tolerance type.</li>
  +
<li>The <code>tolerance => 3</code> sets the number of digits to check to 3. The default value is acutally the default for other tolerance types, 0.001, but any tolerance that is between 0 and 1 is converted via log10 and rounding to an integer (in this case, to 3).</li>
  +
<li>The <code>tolTruncation</code> parameter is either 1 (true) or 0 (false). Its default is 1. Details are explained below.</li>
  +
<li>The <code>tolExtraDigits</code> parameter sets the number of extra digits to examine beyond the first <code>tolerance</code> digits. Its default value is 1. This is explained below.</li>
 
</ul>
 
</ul>
 
</p>
 
</p>
  +
<p>
  +
The goal is that the student must enter at least the first <code>tolerance</code> digits correctly. The last digits that they enter might be rounded (always accepted) or truncated (only accepted if <code>tolTruncation</code> is true). For example, if the correct answer is e=2.7182818... and <code>tolerance</code> is 3, the student can answer with 2.72. Or they can answer with 2.71 if <code>tolTruncation</code> is true. But for example 2.7 and 2.73 are not accepted.
  +
</p>
  +
<p>
  +
If the student enters additional digits, the first additional <code>tolExtraDigits</code> digits are examined in the same manner. For example, if the correct answer is pi=3.1415926... and default flag values are used, the student can answer with 3.14, 3.141, 3.142, 3.1415, and even 3.1418 since that 8 is beyond the extra digits checking. But for example 3.143 is not accepted, since the first extra digit is not right. (And if <code>tolTruncation</code> is false, 3.141 would not be accepted either.)
  +
</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.
  +
</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>
  +
 
</td>
 
</td>
 
</tr>
 
</tr>
   
<!-- Question text section -->
+
<!-- First Block text section -->
   
 
<tr valign="top">
 
<tr valign="top">
Line 64: Line 81:
 
<pre>
 
<pre>
 
BEGIN_PGML
 
BEGIN_PGML
Graph the circle given by the following equation.
 
   
[`[$circle_eq_lhs] = [$r ** 2]`]
 
  +
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.
   
[_]{$gt}
+
[`\pi=`][_]{$answer}
END_PGML
+
</pre>
+
END_PGML</pre>
  +
</td>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Main Text:</b>
 
  +
<b>First Section:</b> 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.
This asks to graph the circle given by the equation. And the code:
 
  +
</p>
  +
</td>
  +
</tr>
  +
  +
<!-- Setup 2nd block -->
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
[_]{$gt}
 
  +
  +
Context("Numeric");
  +
Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0);
  +
$answer2 = Real("pi");
  +
 
</pre>
 
</pre>
inserts the GraphTool.
 
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Second block explanation: </b> First, reset the context with <code>Context("Numeric")</code> and then the same flags are set as before except for <code>tolTruncation => 0</code>.
  +
</td>
  +
  +
<!-- Second Block text section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ffdddd;border:black 1px dashed;">
  +
<pre>
  +
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
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffcccc;padding:7px;">
  +
<p>
  +
<b>Second Section:</b> This tests when <code>tolTruncation</code> is false. It should accept 3.14, 3.142 as correct, but not 3.141.
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
   
<!-- Solution section -->
+
<!-- Setup 3rd block -->
  +
<td style="background-color:#ffffdd;border:black 1px dashed;">
  +
<pre>
  +
Context("Numeric");
  +
Context()->flags->set(tolType => 'digits', tolerance => 3, tolTruncation => 0, tolExtraDigits => 2);
  +
$answer3 = Real("3.14");
  +
</pre>
  +
</td>
  +
<td style="background-color:#ffffcc;padding:7px;">
  +
<p>
  +
<b>Second block explanation: </b> First, reset the context with <code>Context("Numeric")</code> and then the same flags are set except
  +
for <code>tolTruncation => 0</code> as well as the <code>tolExtraDigits => 2</code>.
  +
</td>
  +
  +
<!-- Third Block text section -->
   
 
<tr valign="top">
 
<tr valign="top">
<td style="background-color:#eeddff;border:black 1px dashed;">
+
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_PGML_SOLUTION
 
  +
BEGIN_PGML
The equation of the circle of the form:
 
   
[`[$circle_eq_lhs] = [$r ** 2]`]
 
  +
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.
   
has a center at [`([$h],[$k])`] and radius [$r]. To enter the graph, click the circle tool, then click the center at [`([$h],[$k])`] and then click a second point that is [$r] units from the center. This is easist going left, right, up or down from the center.
 
  +
[`\pi=`][_]{$answer3}
END_PGML_SOLUTION
 
  +
  +
END_PGML
   
ENDDOCUMENT();
 
 
</pre>
 
</pre>
<td style="background-color:#eeccff;padding:7px;">
 
  +
</td>
  +
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
This is the solution.
 
  +
<b>Third Section:</b> This additionally tests when <code>tolExtraDigits</code> is larger than its default. It should accept 3.1416, 3.14, and 3.1415888. It should reject 3.1415 because <code>tolTruncation</code> is false. It should reject 3.1417 and 3.14888 because the student chose to use extra digits and the first two of those are not correct.
 
</p>
 
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
  +
  +
  +
 
</table>
 
</table>
   
Line 111: Line 160:
   
 
[[Category:Problem Techniques]]
 
[[Category:Problem Techniques]]
 
 
<ul>
 
<li>POD documentation: [https://webwork.maa.org/pod/pg/macros/parserGraphTool.html]</li>
 
</ul>
 

Revision as of 07:30, 21 July 2021

Construction.png This article is under construction. Use the information herein with caution until this message is removed.

Digits TolType


This describes an alternative way for determining the tolerance type based on the number of digits.

Problem Techniques Index

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 tolType => 'digits' switches from the default 'relative' tolerance type to the 'digits' tolerance type.
  • The tolerance => 3 sets the number of digits to check to 3. The default value is acutally the default for other tolerance types, 0.001, but any tolerance that is between 0 and 1 is converted via log10 and rounding to an integer (in this case, to 3).
  • The tolTruncation parameter is either 1 (true) or 0 (false). Its default is 1. Details are explained below.
  • The tolExtraDigits parameter sets the number of extra digits to examine beyond the first tolerance digits. Its default value is 1. This is explained below.

The goal is that the student must enter at least the first tolerance digits correctly. The last digits that they enter might be rounded (always accepted) or truncated (only accepted if tolTruncation is true). For example, if the correct answer is e=2.7182818... and tolerance is 3, the student can answer with 2.72. Or they can answer with 2.71 if tolTruncation is true. But for example 2.7 and 2.73 are not accepted.

If the student enters additional digits, the first additional tolExtraDigits digits are examined in the same manner. For example, if the correct answer is pi=3.1415926... and default flag values are used, the student can answer with 3.14, 3.141, 3.142, 3.1415, and even 3.1418 since that 8 is beyond the extra digits checking. But for example 3.143 is not accepted, since the first extra digit is not right. (And if tolTruncation is false, 3.141 would not be accepted either.)

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, Real(4) == Real(3.995) is false, while Real(3.995) == Real(4) is true. The left operand is viewed as the "correct" value. With Real(4) == Real(3.995), that "5" violates the tolExtraDigits checking. But with Real(3.995) == Real(4), 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 relative is similarly asymmetric, but the effect is more subtle. You can see it with Real(4) == Real(3.996001) versus Real(3.996001) == Real(4).)

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 Context("Numeric") and then the same flags are set as before except for tolTruncation => 0.

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 tolTruncation is false. It should accept 3.14, 3.142 as correct, but not 3.141.

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 Context("Numeric") and then the same flags are set except for tolTruncation => 0 as well as the tolExtraDigits => 2.

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 tolExtraDigits is larger than its default. It should accept 3.1416, 3.14, and 3.1415888. It should reject 3.1415 because tolTruncation is false. It should reject 3.1417 and 3.14888 because the student chose to use extra digits and the first two of those are not correct.

Problem Techniques Index