[system] / trunk / pg / macros / answerComposition.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/answerComposition.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.5372  
changed lines
  Added in v.5373

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9