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

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

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

Revision 5440 Revision 5461
120 # 120 #
121 my $n = $f->D($f->{constant}); 121 my $n = $f->D($f->{constant});
122 Value->Error("Your formula isn't linear in the arbitrary constant '%s'",$f->{constant}) 122 Value->Error("Your formula isn't linear in the arbitrary constant '%s'",$f->{constant})
123 unless $n->isConstant; 123 unless $n->isConstant;
124 # 124 #
125 # Make a version with an adaptive parameter for use in the 125 # Make a version with adaptive parameters for use in the
126 # comparison later on. We could like n0*C, but already have $n 126 # comparison later on. We could like n0*C, but already have $n
127 # copies of C, so remove them. That way, n0 will be 0 when there 127 # copies of C, so remove them. That way, n0 will be 0 when there
128 # are no C's in the student answer during the adaptive comparison. 128 # are no C's in the student answer during the adaptive comparison.
129 # (Again, should really check that n0 is not in use already) 129 # (Again, should really check that n0 is not in use already)
130 # 130 #
131 my $n0 = $context->variables->get("n0"); 131 my $n00 = $context->variables->get("n00");
132 $context->variables->add(n0=>'Parameter') unless $n0 and $n0->{parameter}; 132 $context->variables->add(n00=>'Parameter') unless $n00 and $n00->{parameter};
133 my $n01 = $context->variables->get("n01");
134 $context->variables->add(n01=>'Parameter') unless $n01 and $n01->{parameter};
133 $f->{adapt} = $f + "(n0-$n)$f->{constant}"; 135 $f->{adapt} = $f + "(n00-$n)$f->{constant} + n01";
134 return bless $f, $class; 136 return bless $f, $class;
135} 137}
136 138
137################################################## 139##################################################
138# 140#
160 return -1 unless $l->{adapt} == $r; 162 return -1 unless $l->{adapt} == $r;
161 # 163 #
162 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) 164 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer)
163 # (remember: return value of 0 is equal, and non-zero is unequal) 165 # (remember: return value of 0 is equal, and non-zero is unequal)
164 # 166 #
165 return abs($context->variables->get("n0")->{value}) < $context->flag("zeroLevelTol"); 167 return abs($context->variables->get("n00")->{value}) < $context->flag("zeroLevelTol");
166} 168}
167 169
168################################################## 170##################################################
169# 171#
170# Here we override part of the answer comparison 172# Here we override part of the answer comparison
187 return unless $ans->{score} == 0 && !$ans->{isPreview}; 189 return unless $ans->{score} == 0 && !$ans->{isPreview};
188 return if $ans->{ans_message} || !$self->getFlag("showHints"); 190 return if $ans->{ans_message} || !$self->getFlag("showHints");
189 my $student = $ans->{student_value}; 191 my $student = $ans->{student_value};
190 my $result = $ans->{correct_value} <=> $student; # compare encodes the reason in the result 192 my $result = $ans->{correct_value} <=> $student; # compare encodes the reason in the result
191 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3; 193 $self->cmp_Error($ans,"Note: there is always more than one posibility") if $result == 2 || $result == 3;
194 if ($result == 3) {
195 $self->context->flags->set(no_parameters=>0);
196 $result = 1 if $self->removeConstant+"n01+n00x" == $student+"x"; # must use both parameters
197 $self->context->flags->set(no_parameters=>1);
198 }
192 $self->cmp_Error($ans,"Your answer is not the most general solution") 199 $self->cmp_Error($ans,"Your answer is not the most general solution") if $result == 1;
193 if $result == 1 || ($result == 3 && $self->removeConstant == $student);
194 $self->cmp_Error($ans,"Your formula should be linear in the constant '$student->{constant}'") 200 $self->cmp_Error($ans,"Your formula should be linear in the constant '$student->{constant}'")
195 if $result == -1 && $self->getFlag("showLinearityHints") && !$student->D($student->{constant})->isConstant; 201 if $result == -1 && $self->getFlag("showLinearityHints") && !$student->D($student->{constant})->isConstant;
196} 202}
197 203
198################################################## 204##################################################

Legend:
Removed from v.5440  
changed lines
  Added in v.5461

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9