Difference between revisions of "DisableFunctions"
(added historical tag and gave updated problem link) |
|||
(11 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Disabling Functions in Student Answers: 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/Trig/DisableFunctions.html a newer version of this problem]</p> |
||
+ | <h2>Disabling Functions and Operators in Student Answers: PG Code Snippet</h2> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
Line 8: | Line 11: | ||
</p> |
</p> |
||
<p style="text-align:center;"> |
<p style="text-align:center;"> |
||
− | [[ |
+ | [[Problem_Techniques|Problem Techniques Index]] |
</p> |
</p> |
||
Line 54: | Line 57: | ||
<li> <code>LimitedNumeric-List</code>, which is similar but for lists; </li> |
<li> <code>LimitedNumeric-List</code>, which is similar but for lists; </li> |
||
<li> <code>LimitedPoint</code>, which allows points to be entered, but no operations between them; </li> |
<li> <code>LimitedPoint</code>, which allows points to be entered, but no operations between them; </li> |
||
− | <li> <code>LimitedPowers</code>, which restricts what constants may be raised to powers. There are several available restrictions, only one of which may be selected: |
||
+ | <li> <code>LimitedVector</code>, which allows vectors to be entered but disallows operations between vectors; there are two variations to this, </li> |
||
+ | <li> <code>LimitedVector-coordinate</code>, which requires that the vectors be entered in coordinate format (<a,b,c>), and </li> |
||
+ | <li> <code>LimitedVector-ijk</code>, which requires ijk-format. </li> |
||
+ | </ul> |
||
+ | <p> |
||
+ | It is possible to restrict what constants may be raised to powers by modifying the <b>current</b> context (such as Numeric, Complex, Vector, etc., as there is no LimitedPowers context) by issuing the following commands after setting the context. There are several available restrictions, and only one of the last three may be selected: |
||
+ | </p> |
||
<ul> |
<ul> |
||
<li> <code>LimitedPowers::NoBaseE()</code>, which doesn't allow ''e'' to be raised to a power, </li> |
<li> <code>LimitedPowers::NoBaseE()</code>, which doesn't allow ''e'' to be raised to a power, </li> |
||
Line 60: | Line 69: | ||
<li> <code>LimitedPowers::OnlyPositiveIntegers()</code>, which only allows positive integers, </li> |
<li> <code>LimitedPowers::OnlyPositiveIntegers()</code>, which only allows positive integers, </li> |
||
<li> <code>LimitedPowers::OnlyNonNegativeIntegers()</code>, which only allows positive integers and zero; </li> |
<li> <code>LimitedPowers::OnlyNonNegativeIntegers()</code>, which only allows positive integers and zero; </li> |
||
− | </ul> |
||
− | <li> <code>LimitedVector</code>, which allows vectors to be entered but disallows operations between vectors; there are two variations to this, </li> |
||
− | <li> <code>LimitedVector-coordinate</code>, which requires that the vectors be entered in coordinate format (<a,b,c>), and </li> |
||
− | <li> <code>LimitedVector-ijk</code>, which requires ijk-format. </li> |
||
</ul> |
</ul> |
||
</td> |
</td> |
||
Line 200: | Line 205: | ||
</table> |
</table> |
||
<p style="text-align:center;"> |
<p style="text-align:center;"> |
||
− | [[ |
+ | [[Problem_Techniques|Problem Techniques Index]] |
</p> |
</p> |
||
[[Category:Problem Techniques]] |
[[Category:Problem Techniques]] |
||
+ | |||
+ | |||
+ | |||
+ | <ul> |
||
+ | <li>POD documentation: [http://webwork.maa.org/pod/pg Look for contextSomeContext.pl]</li> |
||
+ | <li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/ Look for contextSomeContext.pl]</li> |
||
+ | </ul> |
Latest revision as of 08:23, 28 June 2023
This problem has been replaced with a newer version of this problem
Disabling Functions and Operators in Student Answers: PG Code Snippet
This code snippet shows the essential PG code to Disabling Functions in Student Answers. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
In general, this can be done in a number of ways: there are a number of available limited contexts that limit the types of answers that students may enter, or, alternately, it is possible to specifically indicate within the context what functions or operations are not allowed. In the following, we first consider the available contexts, and, below that, show how to specifically disallow some functions.
PG problem file | Explanation |
---|---|
loadMacros("contextLimitedPolynomial.pl"); |
In the initialization section of the file, we need to load the Context that we're using. This will be |
Context("LimitedPolynomial"); # to require that only one monomial of each # degree be included in the polynomial, we # would also set that flag in the Context: # Context()->flags->set(singlePowers=>1); $ans = Compute("x^2 + 3x + 2"); |
There are no additions required in the tagging and description or initialization sections of the problem file. In the problem set-up section, we specify the
There are a number of limited contexts like
It is possible to restrict what constants may be raised to powers by modifying the current context (such as Numeric, Complex, Vector, etc., as there is no LimitedPowers context) by issuing the following commands after setting the context. There are several available restrictions, and only one of the last three may be selected:
|
BEGIN_TEXT Expand the polynomial: $BR \((x+1)(x+2) = \) \{ ans_rule(25) \} END_TEXT |
No changes are required in the text section of the problem file. |
ANS( $ans->cmp() ); |
And in the answer and solution section of the file, we check the answer as usual. |
Alternately, we may find that we need to disable specific functions or operations in student answers. This can be done manually within an existing Context, as shown in the following snippet.
PG problem file | Explanation |
---|---|
Context("Numeric"); ## to disable specific operations in ## student answers, use the undefine ## method for the operations: Context()->operators->undefine("^","**"); ## we can similarly disable specific ## functions with Context()->functions->undefine("sin","cos","tan","sqrt"); $ans = Compute("1/2"); # To disallow absolute value, disable abs(), # sqrt and exponentiation (for sqrt(x^2) and (x^4)^(1/4)), and # the parentheses | |, and give consistent # error messages Context()->functions->disable("abs","sqrt"); Context()->operators->undefine("^","**"); Context()->parens->remove("|"); Context()->{error}{convert} = sub { my $message = shift; $message =~ s/Unexpected character '~~|'/Absolute value is not allowed/; return $message; }; |
No changes are necessary in the documentation and tagging section of the problem, or in the initialization section. In the problem set-up section, we declare a context (here, we've chosen the
We can disable specific operations in the Context: in general, predefined operations are
After disabling the operation, they can be re-enabled with
To disable specific functions in the Context, we similarly
In addition, classes of functions can be disabled with
Alternatively, we could use the following syntax. Parser::Context::Functions::Disable('All'); |
BEGIN_TEXT Find the numerical value: \( sin^2(\pi/4) = \) \{ ans_rule(15) \} END_TEXT |
We don't need to make any changes to the text portion of the problem file. |
ANS( $ans->cmp() ); |
Nor in the answer and solution section. |
- POD documentation: Look for contextSomeContext.pl
- PG macro: Look for contextSomeContext.pl