Difference between revisions of "IntervalEvaluators"

From WeBWorK_wiki
Jump to navigation Jump to search
(added historical tag and gave updated problem link)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<h2>Interval Answer Checkers: PG Code Snippet</h2>
 
  +
{{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/IntervalEvaluators.html a newer version of this problem]</p>
  +
<h2>Interval Answer Checkers</h2>
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em>This code snippet shows the essential PG code to check intervals as student answers. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
 
  +
<em>This code shows how to check answers that are intervals.
  +
<br />
  +
<br />
  +
For answers that are inequalities (or intervals), see [http://webwork.maa.org/wiki/InequalityEvaluators InequalityEvaluators]
  +
</em>
 
</p>
 
</p>
 
<p style="text-align:center;">
 
<p style="text-align:center;">
Line 13: Line 20:
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
  +
  +
<!-- Load specialized macro files section -->
  +
  +
<tr valign="top">
  +
<td style="background-color:#ddffdd;border:black 1px dashed;">
  +
<pre>
  +
DOCUMENT();
  +
  +
loadMacros(
  +
"PGstandard.pl",
  +
"MathObjects.pl",
  +
"PGcourse.pl",
  +
);
  +
  +
TEXT(beginproblem());
  +
</pre>
  +
</td>
  +
<td style="background-color:#ccffcc;padding:7px;">
  +
<p>
  +
<b>Initialization:</b>
  +
Load the usual suspects. The interval context and interval answer checker are part of <code>MathObjects.pl</code>.
  +
</p>
  +
</td>
  +
</tr>
  +
 
<tr valign="top">
 
<tr valign="top">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Interval");
+
Context("Interval");
# to allow open or closed intervals, uncomment
+
# to allow open or closed intervals, uncomment
# the following line.
+
# the following line.
# Context()-&gt;flags-&gt;set(ignoreEndpointTypes=>1);
+
# Context()-&gt;flags-&gt;set(ignoreEndpointTypes=>1);
   
$int = Compute("(1,3)");
+
$int = Compute("(1,3)");
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
No changes are necessary in the tagging and description and initialization sections of the question file. In the problem set-up section of the file, we set the Context to be the Interval Context.
 
  +
<b>Setup:</b>
  +
No changes are necessary in the tagging and description and initialization sections of the question file. In the problem set-up section of the file, we set the Context to be the Interval Context. Note that we can relax checking of endpoints in the Context or in the actual answer checking, as noted below.
 
</p>
 
</p>
 
<p>
 
<p>
Line 32: Line 65:
 
</p>
 
</p>
 
<pre>
 
<pre>
$int2 = Compute("(-inf,1]");
+
$int2 = Compute("(-inf,1]");
 
</pre>
 
</pre>
 
<p>
 
<p>
Line 42: Line 75:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
BEGIN_TEXT
+
BEGIN_TEXT
On what interval is the parabola
+
On what interval is the parabola
\( y = (1-x)(x-3) \)
+
\( y = (1-x)(x-3) \)
above the \(x\)-axis?
+
above the \(x\)-axis?
$BR
+
$BR
For \(x\) in \{ ans_rule(15) \}
+
For \(x\) in \{ ans_rule(15) \}
END_TEXT
+
END_TEXT
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
  +
<b>Main Text:</b>
 
In the text section of the file, we ask the question as usual.
 
In the text section of the file, we ask the question as usual.
 
</p>
 
</p>
Line 59: Line 93:
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
<pre>
ANS( $int->cmp() );
+
ANS( $int->cmp() );
  +
  +
ENDDOCUMENT();
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
And in the answer and solution section of the file, we can check the answer using our interval MathObject.
 
  +
<b>Answer Evaluation:</b>
  +
We check the answer using our interval MathObject. To allow either open or closed intervals, we can specify a flag for the cmp() call: <code>$int-&gt;cmp( requireParenMatch =&gt; 0 )</code>. (Alternately, we can specify this for all intervals in the Context, as noted above.)
 
</p>
 
</p>
 
</td>
 
</td>

Latest revision as of 09:55, 28 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem

Interval Answer Checkers

This code shows how to check answers that are intervals.

For answers that are inequalities (or intervals), see InequalityEvaluators

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

Initialization: Load the usual suspects. The interval context and interval answer checker are part of MathObjects.pl.

Context("Interval");
# to allow open or closed intervals, uncomment
#    the following line.
# Context()->flags->set(ignoreEndpointTypes=>1);

$int = Compute("(1,3)");

Setup: No changes are necessary in the tagging and description and initialization sections of the question file. In the problem set-up section of the file, we set the Context to be the Interval Context. Note that we can relax checking of endpoints in the Context or in the actual answer checking, as noted below.

Once we're in the Interval context, we can define intervals as we'd expect: as shown here, or with limits at infinity:

$int2 = Compute("(-inf,1]");

Would give the interval from negative infinity to 1, including the point at one. Note the Context flag to make endpoint checking "fuzzy."

BEGIN_TEXT
On what interval is the parabola
\( y = (1-x)(x-3) \)
above the \(x\)-axis?
$BR
For \(x\) in \{ ans_rule(15) \}
END_TEXT

Main Text: In the text section of the file, we ask the question as usual.

ANS( $int->cmp() );

ENDDOCUMENT();

Answer Evaluation: We check the answer using our interval MathObject. To allow either open or closed intervals, we can specify a flag for the cmp() call: $int->cmp( requireParenMatch => 0 ). (Alternately, we can specify this for all intervals in the Context, as noted above.)

Problem Techniques Index