Difference between revisions of "InequalityEvaluators"

From WeBWorK_wiki
Jump to navigation Jump to search
(New page: <h2>Inequalities as Answers</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This is the ...)
 
(16 intermediate revisions by one other user not shown)
Line 37: Line 37:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
Include the macro file <code>contextInequalities.pl</code>.
+
Include the macro file <code>contextInequalities.pl</code>, which automatically loads <code>MathObjects.pl</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 47: Line 47:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Inequalities");
+
Context("Inequalities-Only");
 
Context()->variables->add(y=>"Real");
 
Context()->variables->add(y=>"Real");
 
# Context()->constants->add(EmptySet => Set());
 
# Context()->constants->add(EmptySet => Set());
 
# Context()->flags->set(noneWord=>"EmptySet");
 
# Context()->flags->set(noneWord=>"EmptySet");
  +
# Context()->flags->set(ignoreEndpointTypes=>1);
   
 
# f(x) = x^2 - 16 on -1 <= x <= 5
 
# f(x) = x^2 - 16 on -1 <= x <= 5
  +
$f = Formula("x^2 - 16");
   
 
$range = Compute("-16 <= y <= 9");
 
$range = Compute("-16 <= y <= 9");
  +
  +
Context()->variables->remove("x");
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 60: Line 64:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
Using <code>Context("Inequalities")</code>, if the student enters either the inequality <code>-16 <= y <= 9</code> or the interval <code>[-16,9]</code> their answer will be marked correct. As of January 2010, the inequality is not variable-specific, so the answer <code>-16 <= x <= 9</code> would also be marked correct (we could have required students to use the variable y by using
+
Using <code>Context("Inequalities-Only")</code>, if the student enters the inequality <code>-16 <= y <= 9</code> their answer will be marked correct, but the equivalent interval <code>[-16,9]</code> would be incorrect. If we had used <code>Context("Inequalities")</code> instead, both the inequality and the interval would be marked correct.
<code>Context()->variables->are(y=>"Real");</code> which would remove the default variable x from the context). To mark only the inequality correct but not the interval, use <code>Context("Inequalities-Only");</code> instead. For a list of all available options for the interval context, see the <a target="_blank" href="http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/contextInequalities.pl">POD documentation.</a>
+
</p>
  +
<p>
 
Uncommenting the lines containing <code>EmptySet</code> creates an empty set as a named constant and uses that name.
 
Uncommenting the lines containing <code>EmptySet</code> creates an empty set as a named constant and uses that name.
  +
</p>
  +
<p>
  +
Uncommenting <code>Context()->flags->set(ignoreEndpointTypes=>1);</code> would also mark the student answers <code>-16 < y < 9</code> or <code>-16 <= y < 9</code> or <code>-16 < y <= 9</code> correct.
  +
</p>
  +
<p>
  +
As of January 2010, the inequality is not variable-specific. If we had not removed the default variable x from the context using <code>Context()->variables->remove("x");</code>, then the student answer <code>-16 <= x <= 9</code> would also be marked correct. Note that we removed the variable x from the context <i>after</i> we defined the formula <code>$f</code> that uses this variable (otherwise there would be errors and PG file would not work).
 
</p>
 
</p>
 
</td>
 
</td>
Line 72: Line 82:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
  +
Context()->texStrings;
 
BEGIN_TEXT
 
BEGIN_TEXT
 
What is the range of
 
What is the range of
\( y = f(x) = x^2 - 16 \) on the domain \( -1 \leq x \leq 5 \)?
+
\( y = f(x) = $f \) on the domain \( -1 \leq x \leq 5 \)?
Enter your answer using inequalities or intervals.
 
 
$BR
 
$BR
 
$BR
 
$BR
Range: \{ ans_rule(20) \}
+
Range: \{ ans_rule(20) \} Enter your answer using
+
inequalities (not intervals).
 
END_TEXT
 
END_TEXT
  +
Context()->normalStrings;
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
Line 112: Line 124:
   
 
[[Category:Problem Techniques]]
 
[[Category:Problem Techniques]]
  +
  +
  +
  +
  +
<ul>
  +
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/contextInequalities.html contextInequalities.pl]</li>
  +
<li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/contextInequalities.pl?view=log contextInequalities.pl]</li>
  +
</ul>

Revision as of 17:52, 7 April 2021

Inequalities as Answers


This is the essential code for having inequalities as student answers.

Problem Techniques Index

PG problem file Explanation
DOCUMENT();

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

TEXT(beginproblem());

Initialization: Include the macro file contextInequalities.pl, which automatically loads MathObjects.pl.

Context("Inequalities-Only");
Context()->variables->add(y=>"Real");
# Context()->constants->add(EmptySet => Set());
# Context()->flags->set(noneWord=>"EmptySet");
# Context()->flags->set(ignoreEndpointTypes=>1);

# f(x) = x^2 - 16 on -1 <= x <= 5
$f = Formula("x^2 - 16");

$range = Compute("-16 <= y <= 9");

Context()->variables->remove("x");

Setup: Using Context("Inequalities-Only"), if the student enters the inequality -16 <= y <= 9 their answer will be marked correct, but the equivalent interval [-16,9] would be incorrect. If we had used Context("Inequalities") instead, both the inequality and the interval would be marked correct.

Uncommenting the lines containing EmptySet creates an empty set as a named constant and uses that name.

Uncommenting Context()->flags->set(ignoreEndpointTypes=>1); would also mark the student answers -16 < y < 9 or -16 <= y < 9 or -16 < y <= 9 correct.

As of January 2010, the inequality is not variable-specific. If we had not removed the default variable x from the context using Context()->variables->remove("x");, then the student answer -16 <= x <= 9 would also be marked correct. Note that we removed the variable x from the context after we defined the formula $f that uses this variable (otherwise there would be errors and PG file would not work).

Context()->texStrings;
BEGIN_TEXT
What is the range of  
\( y = f(x) = $f \) on the domain \( -1 \leq x \leq 5 \)?
$BR
$BR
Range: \{ ans_rule(20) \} Enter your answer using 
inequalities (not intervals).
END_TEXT
Context()->normalStrings;

Main Text: The problem text section of the file is as we'd expect.

ANS( $range->cmp() );

ENDDOCUMENT();

Answer Evaluation: As is the answer.

Problem Techniques Index