Difference between revisions of "DisableFunctions1"

From WeBWorK_wiki
Jump to navigation Jump to search
(PGML example link)
(Removes the AnswerFormatHelp macro and some other cleanup.)
Line 16: Line 16:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 40%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 43: Line 43:
   
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
'PGstandard.pl',
"MathObjects.pl",
+
'MathObjects.pl',
"AnswerFormatHelp.pl",
+
'contextFraction.pl',
"contextFraction.pl",
+
'PGML.pl',
  +
'PGcourse.pl'
 
);
 
);
 
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 55: Line 54:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
  +
  +
* The <code>contextFraction.pl</code> is loaded since we used the <code>Fraction-NoDecimals</text> context.
 
</p>
 
</p>
 
</td>
 
</td>
Line 65: Line 66:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("Fraction-NoDecimals");
+
Context('Fraction-NoDecimals');
   
 
# Prevent pi from becoming 3.1415... and cos(pi) from
 
# Prevent pi from becoming 3.1415... and cos(pi) from
 
# becoming -1.
 
# becoming -1.
Context()->constants->set(pi => {keepName => 1});
+
Context()->constants->set(pi => {keepName => 1});
   
$f1 = Formula("cos(pi)");
 
  +
# The next context changes are not necessary to
$f2 = Formula("sin(pi/3)");
 
  +
# prevent cos(pi) from becoming -1, but they cannot hurt.
  +
Context()->flags->set(
  +
reduceConstants=>0,
  +
reduceConstantFunctions=>0
  +
);
   
Context()->functions->disable("All");
 
  +
$f1 = Formula('cos(pi)');
Context()->functions->enable("sqrt");
 
  +
$f2 = Formula('sin(pi/3)');
   
$answer1 = Compute("-1");
 
  +
Context()->functions->disable('All');
$answer2 = Compute("sqrt(3)/2");
 
  +
Context()->functions->enable('sqrt');
  +
  +
$answer1 = Compute('-1');
  +
$answer2 = Compute('sqrt(3)/2');
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 97: Line 105:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
 
Enter your answers as simplified fractions.
 
Enter your answers as simplified fractions.
$BR
 
$BR
 
\( $f1 = \)
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("fractions") \}
 
$BR
 
$BR
 
\( $f2 = \)
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("fractions") \}
 
END_TEXT
 
Context()->normalStrings;
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<b>Main Text:</b>
 
</p>
 
</td>
 
</tr>
 
   
<!-- Answer evaluation section -->
 
  +
+ [` [$f1] = `] [_____________]{$answer1}
   
<tr valign="top">
 
  +
+ [` [$f2] = `] [_____________]{$answer2}
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers = 1;
 
   
ANS( $answer1->cmp() );
 
  +
[@ helpLink('fractions') @]*
 
  +
END_PGML
ANS( $answer2->cmp() );
 
 
</pre>
 
</pre>
<td style="background-color:#eeccff;padding:7px;">
+
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
<b>Answer Evaluation:</b>
+
<b>Main Text:</b>
 
</p>
 
</p>
 
</td>
 
</td>
Line 143: Line 127:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
  +
The cosine of an angle is zero when
${PAR}SOLUTION:${PAR}
 
  +
the angle is an integer multiple of \( \pi \).
Solution explanation goes here.
 
  +
END_PGML_SOLUTION
END_SOLUTION
 
Context()->normalStrings;
 
 
COMMENT('MathObject version.');
 
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();

Revision as of 13:42, 10 March 2023

Disabling Functions so Students Must Simplify Answers

Click to enlarge

This PG code shows how to disable all functions and restrict student answers to fractions.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
  'PGstandard.pl',
  'MathObjects.pl',
  'contextFraction.pl',
  'PGML.pl',
  'PGcourse.pl'
);
TEXT(beginproblem());

Initialization:

  • The contextFraction.pl is loaded since we used the Fraction-NoDecimals</text> context.

Context('Fraction-NoDecimals');

# Prevent pi from becoming 3.1415... and cos(pi) from
# becoming -1.
Context()->constants->set(pi => {keepName => 1});

# The next context changes are not necessary to
# prevent cos(pi) from becoming -1, but they cannot hurt.
Context()->flags->set(
  reduceConstants=>0,
  reduceConstantFunctions=>0
);

$f1 = Formula('cos(pi)');
$f2 = Formula('sin(pi/3)');

Context()->functions->disable('All');
Context()->functions->enable('sqrt');

$answer1 = Compute('-1');
$answer2 = Compute('sqrt(3)/2');

Setup: We choose a context that requires fractions as answers and does not allow decimals. After constructing the formulas involving trig functions, we disable all functions and re-enable the sqrt() function. This means that students are allowed to type in fractions and square roots, but not much else (e.g., they'll get an error message if they type in a trig function).

Note that $f1 and $f2 are MathObject Formulas, which do not get reduced since pi is set to keep its name. If $f1 and $f2 used Compute instead, then the results would be -1 and 0.866... instead of cos(\pi) and sin(\pi/3) as desired.

BEGIN_PGML
Enter your answers as simplified fractions.

+ [` [$f1] = `] [_____________]{$answer1}

+ [` [$f2] = `] [_____________]{$answer2}

[@ helpLink('fractions') @]*
END_PGML

Main Text:

BEGIN_PGML_SOLUTION
The cosine of an angle is zero when
the angle is an integer multiple of \( \pi \).
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area