[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 2732 Revision 4997
1
2
3=head1 DESCRIPTION
4
1###################################################################### 5######################################################################
2# 6#
3# An answer checker that determines if two functions compose 7# An answer checker that determines if two functions compose
4# 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
5# 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
6# simpler functions, neither of which is allowed to be the identity 10# simpler functions, neither of which is allowed to be the identity
7# function.) 11# function.)
8# 12#
9 13
14=cut
15
10sub _answerComposition_init {}; # don't reload this file 16sub _answerComposition_init {}; # don't reload this file
17
18=head3 COMPOSITION_ANS($fn_f,$fn_g)
11 19
12###################################################################### 20######################################################################
13# 21#
14# 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.
15# 23#
32# \(f\circ g = (1+x)^2\) when 40# \(f\circ g = (1+x)^2\) when
33# \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\} 41# \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\}
34# END_TEXT 42# END_TEXT
35# COMPOSITION_ANS("x^2","1+x"); 43# COMPOSITION_ANS("x^2","1+x");
36# 44#
37# 45
46=cut
47
38sub COMPOSITION_ANS { 48sub COMPOSITION_ANS {
39 my $f = shift; my $g = shift; 49 my $f = shift; my $g = shift;
40 my $fID = ANS_NUM_TO_NAME($main::ans_rule_count-1); 50 my $fID = ANS_NUM_TO_NAME($main::ans_rule_count-1);
41 my $gID = ANS_NUM_TO_NAME($main::ans_rule_count); 51 my $gID = ANS_NUM_TO_NAME($main::ans_rule_count);
42 my %ans = composition_ans_list($fID=>$f,$gID=>$g,@_); 52 my %ans = composition_ans_list($fID=>$f,$gID=>$g,@_);
43 ANS($ans{$fID},$ans{$gID}); 53 ANS($ans{$fID},$ans{$gID});
44} 54}
45 55
56=head3 NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options)
46 57
47###################################################################### 58######################################################################
48# 59#
49# 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.
50# 61#
51# Usage: NAMED_COMPOSITION_ANS(fID=>f,gID->g,options) 62# Usage: NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options)
52# 63#
53# 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
54# 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
55# any of the options allowed by composition_ans_list() below. 66# any of the options allowed by composition_ans_list() below.
56# 67#
63# \(g\circ f = (1+x)^2\) when 74# \(g\circ f = (1+x)^2\) when
64# \(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)\}
65# END_TEXT 76# END_TEXT
66# NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x"); 77# NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x");
67# 78#
79
80=cut
81
68sub NAMED_COMPOSITION_ANS {NAMED_ANS(composition_ans_list(@_))} 82sub NAMED_COMPOSITION_ANS {NAMED_ANS(composition_ans_list(@_))}
83
84=head3 composition_ans_list(fID=>f,gID=>g,options)
69 85
70###################################################################### 86######################################################################
71# 87#
72# This is an internal routine that returns the named answer checkers 88# This is an internal routine that returns the named answer checkers
73# used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above. 89# used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above.
79# among: 95# among:
80# 96#
81# var => 'x' the name of the variable to use when 97# var => 'x' the name of the variable to use when
82# both functions use the same one 98# both functions use the same one
83# 99#
84# vars => ['x','t'] the names of the variabless for f and g 100# vars => ['x','t'] the names of the variables for f and g
85# 101#
86# showVariableHints => 1 or 0 102# showVariableHints => 1 or 0
87# do/don't show errors when the variable 103# do/don't show errors when the variable
88# used by the student is incorrect 104# used by the student is incorrect
89# 105#
106
107=cut
90 108
91sub composition_ans_list { 109sub composition_ans_list {
92 my ($fID,$f,$gID,$g,%params) = @_; my @IDs = ($fID,$gID); 110 my ($fID,$f,$gID,$g,%params) = @_; my @IDs = ($fID,$gID);
93 # 111 #
94 # Get options 112 # Get options
166 } 184 }
167 185
168 } 186 }
169 187
170 # 188 #
171 # If no error, nd both answers are given, check if compositions are equal 189 # If no error, and both answers are given, check if compositions are equal
172 # 190 #
173 if (!$error && defined($student{$fID}) && defined($student{$gID})) { 191 if (!$error && defined($student{$fID}) && defined($student{$gID})) {
174 if ($fog == $student{$fID}->substitute($x{$fID}=>$student{$gID})) { 192 if ($fog == $student{$fID}->substitute($x{$fID}=>$student{$gID})) {
175 $ans{$fID}->{rh_ans}{score} = $ans{$gID}->{rh_ans}{score} = 1; 193 $ans{$fID}->{rh_ans}{score} = $ans{$gID}->{rh_ans}{score} = 1;
176 } 194 }

Legend:
Removed from v.2732  
changed lines
  Added in v.4997

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9