[system] / trunk / pg / macros / answerComposition.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww Revision 5373 Revision 5551
1 2
4compose to form a given function.
2 5
4 7
5 ###################################################################### 8answerComposition.pl provides an answer checker that determines if two functions
6 #
7 # An answer checker that determines if two functions compose
8 # to form a given function. (For use in problems where you ask 9compose to form a given function. This can be used in problems where you ask a
9 # a student to break a given function into a composition of two 10student to break a given function into a composition of two simpler functions,
10 # simpler functions, neither of which is allowed to be the identity 11neither of which is allowed to be the identity function.
11 # function.)
12 #
13 12
14=cut 13=cut
15 14
17 16
19 18
21 # 20
21 COMPOSITION_ANS(\$f, \$g, %options)
22
22 # An answer checked to see if f composed with g matches a given function. 23An answer checked to see if \$f composed with \$g matches a given function,where
23 #
24 # Usage: COMPOSITION_ANS(f,g,options)
25 #
26 # where f and g are one possible decomposition of the target function 24\$f and \$g are one possible decomposition of the target function, and options are
25any of the options allowed by composition_ans_list() below.
26
27 # (these are used to display the "correct" answer, and the composition 27\$f and \$g are used to display the "correct" answer, and the composition is
28 # is computed from them) and options are any of the options allowed 28computed from them.
29 # by composition_ans_list() below. 29
30 #
31 # This function actually supplies TWO answer checkers, for the two 30This function actually supplies TWO answer checkers, for the two previous answer
32 # previous answer blanks. So be sure to call it immediately after 31blanks. So be sure to call it immediately after the answer blanks have been
33 # the answer blanks have been supplied. (It may be best to use the 32supplied. (It may be best to use the NAMED_COMPOSITION_ANS checker below, which
34 # NAMED_COMPOSITION_ANS checker below, which specifies the answer 33specifies the answer blanks explicitly.)
35 # blanks explicitly.) 34
36 #
37 # Example: 35Example:
38 # 36
39 # BEGIN_TEXT 37 BEGIN_TEXT
40 # \(f\circ g = (1+x)^2\) when 38 \(f\circ g = (1+x)^2\) when
41 # \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\} 39 \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\}
42 # END_TEXT 40 END_TEXT
43 # COMPOSITION_ANS("x^2","1+x"); 41 COMPOSITION_ANS("x^2","1+x");
44 #
45 42
46=cut 43=cut
47 44
48sub COMPOSITION_ANS { 45sub COMPOSITION_ANS {
49 my \$f = shift; my \$g = shift; 46 my \$f = shift; my \$g = shift;
51 my \$gID = ANS_NUM_TO_NAME(\$main::ans_rule_count); 48 my \$gID = ANS_NUM_TO_NAME(\$main::ans_rule_count);
52 my %ans = composition_ans_list(\$fID=>\$f,\$gID=>\$g,@_); 49 my %ans = composition_ans_list(\$fID=>\$f,\$gID=>\$g,@_);
53 ANS(\$ans{\$fID},\$ans{\$gID}); 50 ANS(\$ans{\$fID},\$ans{\$gID});
54} 51}
55 52
54
56=head3 NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options) 55 NAMED_COMPOSITION_ANS(\$fID=>\$f, \$gID=>\$g, %options)
57 56
58 ######################################################################
59 #
60 # An answer checked to see if f composed with g matches a given function. 57An answer checked to see if \$f composed with \$g matches a given function, where
61 #
62 # Usage: NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options)
63 #
64 # where fID and gID are the names of the answer rules for the functions 58\$fID and \$gID are the names of the answer rules for the functions \$f and \$g, and
65 # f and g, and f and g are the answers for the functions. Options are 59\$f and \$g are the answers for the functions. %options are any of the options
66 # any of the options allowed by composition_ans_list() below. 60allowed by composition_ans_list() below.
67 # 61
68 # This routine allows you to put the f and g answer blanks at any 62This routine allows you to put the answer blanks for \$f and \$g at any location
69 # location in the problem, and in any order. 63in the problem, and in any order.
70 # 64
71 # Example: 65Example:
72 # 66
73 # BEGIN_TEXT 67 BEGIN_TEXT
74 # \(g\circ f = (1+x)^2\) when 68 \(g\circ f = (1+x)^2\) when
75 # \(f(x)\) = \{NAMED_ANS('f',20)\} and \(g(x)\) = \{NAMED_ANS('g',20)\} 69 \(f(x)\) = \{NAMED_ANS('f',20)\} and \(g(x)\) = \{NAMED_ANS('g',20)\}
76 # END_TEXT 70 END_TEXT
77 # NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x"); 71 NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x");
78 #
79 72
80=cut 73=cut
81 74
82sub NAMED_COMPOSITION_ANS {NAMED_ANS(composition_ans_list(@_))} 75sub NAMED_COMPOSITION_ANS {NAMED_ANS(composition_ans_list(@_))}
83 76
78
84=head3 composition_ans_list(fID=>f,gID=>g,options) 79 composition_ans_list(\$fID=>\$f, \$gID=>\$g, %options)
85 80
86 ######################################################################
87 #
88 # This is an internal routine that returns the named answer checkers 81This is an internal routine that returns the named answer checkers
89 # used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above. 82used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above.
90 # 83
91 # Usage: composition_ans_list(fID=>f,gID=>g,options)
92 #
93 # where fID and gID are the names of the answer rules for the functions 84\$fID and \$gID are the names of the answer rules for the functions and \$f and \$g
94 # and f and g are the answers for these functions. Options are from 85are the answers for these functions. %options are from among:
95 # among: 86
96 # 87=over
97 # var => 'x' the name of the variable to use when 88
98 # both functions use the same one 89=item S<C<< var => 'x' >>>
99 # 90
100 # vars => ['x','t'] the names of the variables for f and g 91the name of the variable to use when
101 # 92both functions use the same one
102 # showVariableHints => 1 or 0 93
103 # do/don't show errors when the variable 94=item S<C<< vars => ['x','t'] >>>
104 # used by the student is incorrect 95
105 # 96the names of the variables for \$f and \$g
97
98=item S<C<< showVariableHints => 1 or 0 >>>
99
100do/don't show errors when the variable
101used by the student is incorrect
102
103=back
106 104
107=cut 105=cut
108 106
109sub composition_ans_list { 107sub composition_ans_list {
110 my (\$fID,\$f,\$gID,\$g,%params) = @_; my @IDs = (\$fID,\$gID); 108 my (\$fID,\$f,\$gID,\$g,%params) = @_; my @IDs = (\$fID,\$gID);
195 } 193 }
196 194
197 return (%ans); 195 return (%ans);
198} 196}
199 197
201# 199
200 message_cmp(\$correct)
201
202# Evaluator that always returns incorrect, with a given error 202Returns an answer evaluator that always returns incorrect, with a given error
203# message. Used by COMPOSITION_ANS to produce "dummy" answer 203message. Used by COMPOSITION_ANS to produce "dummy" answer checkers for the two
204# checkers for the two parts of the composition. 204parts of the composition.
205# 205
206=cut
207
206sub message_cmp { 208sub message_cmp {
207 my \$correct = shift; 209 my \$correct = shift;