Difference between revisions of "DisableFunctions"
m |
|||
Line 15: | Line 15: | ||
<th> PG problem file </th> |
<th> PG problem file </th> |
||
<th> Explanation </th> |
<th> Explanation </th> |
||
+ | </tr> |
||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ddffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | loadMacros("contextLimitedPolynomial.pl"); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ccffcc;padding:7px;"> |
||
+ | <p> |
||
+ | In the initialization section of the file, we need to load the Context that we're using. This will be <code>context<i>ContextName</i>.pl</code>, where <code><i>ContextName</i></code> is the name of the context used in the problem set-up section of the problem. |
||
+ | </p> |
||
+ | </td> |
||
</tr> |
</tr> |
||
<tr valign="top"> |
<tr valign="top"> |
Revision as of 14:47, 12 February 2008
Disabling Functions 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
|
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"); |
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
|
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. |