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

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

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

Revision 3512 Revision 3513
156 } 156 }
157} 157}
158 158
159sub mode2context { 159sub mode2context {
160 my $mode = shift; 160 my $mode = shift;
161 my $options = @_; 161 my %options = @_;
162 my $context; 162 my $context;
163 for ($mode) { 163 for ($mode) {
164 /^strict$/i and do { 164 /^strict$/i and do {
165 $context = $Parser::Context::Default::context{LimitedNumeric}->copy; 165 $context = $Parser::Context::Default::context{LimitedNumeric}->copy;
166 $context->operators->redefine(','); 166 $context->operators->redefine(',');
174 /^frac$/i and do { 174 /^frac$/i and do {
175 $context = $Parser::Context::Default::context{'LimitedNumeric-Fraction'}->copy; 175 $context = $Parser::Context::Default::context{'LimitedNumeric-Fraction'}->copy;
176 $context->operators->redefine(','); 176 $context->operators->redefine(',');
177 last; 177 last;
178 }; 178 };
179 if(defined($options{'complex'}) &&
180 ($options{'complex'} =~ /(yes|ok)/i)) {
181 $context = $Parser::Context::Default::context{Complex}->copy;
182 last;
183 }
184 179
185 # default 180 # default
186 $context = $Parser::Context::Default::context{LegacyNumeric}->copy; 181 $context = $Parser::Context::Default::context{LegacyNumeric}->copy;
182 }
183 # If we are using complex numbers, then we ignore the other mode parts
184 if(defined($options{'complex'}) &&
185 ($options{'complex'} =~ /(yes|ok)/i)) {
186 #$context->constants->redefine('i', from=>'Complex');
187 #$context->functions->redefine(['arg','mod','Re','Im','conj', 'sqrt', 'log'], from=>'Complex');
188 #$context->operators->redefine(['^', '**'], from=>'Complex');
189 $context = $Parser::Context::Default::context{'Complex'};
187 } 190 }
188 $options{tolType} = $options{tolType} || 'relative'; 191 $options{tolType} = $options{tolType} || 'relative';
189 $options{tolerance} = $options{tolerance} || $options{tol} || 192 $options{tolerance} = $options{tolerance} || $options{tol} ||
190 $options{reltol} || $options{relTol} || $options{abstol} || 1; 193 $options{reltol} || $options{relTol} || $options{abstol} || 1;
191 $options{zeroLevel} = $options{zeroLevel} || $options{zeroLevelTol} || 194 $options{zeroLevel} = $options{zeroLevel} || $options{zeroLevelTol} ||
298 } else { 301 } else {
299 $context->parens->redefine('(', from=>'Interval'); 302 $context->parens->redefine('(', from=>'Interval');
300 $context->parens->redefine('[', from=>'Interval'); 303 $context->parens->redefine('[', from=>'Interval');
301 $context->parens->redefine('{', from=>'Interval'); 304 $context->parens->redefine('{', from=>'Interval');
302 305
303 #$context->constants->redefine('R',from=>'Interval'); 306 $context->constants->redefine('R',from=>'Interval');
304 my $infinity = Value::Infinity->new();
305 $context->constants->add(
306 R => Value::Interval->new('(',-$infinity,$infinity,')'),
307 );
308 $context->operators->redefine('U',from=>"Interval"); 307 $context->operators->redefine('U',from=>"Interval");
309 $context->operators->redefine('u',from=>"Interval",using=>"U"); 308 $context->operators->redefine('u',from=>"Interval",using=>"U");
310 $ans_type = 'Union'; 309 $ans_type = 'Union';
311 } 310 }
312 # Take optional arguments intended for List, or Union 311 # Take optional arguments intended for List, or Union
313 for my $o qw( showCoordinateHints showHints partialCredit showLengthHints ) { 312 for my $o qw( showCoordinateHints showHints partialCredit showLengthHints ) {
314 $options{$o} = $opts{$o} || 0; 313 $options{$o} = $opts{$o} || 0;
315 } 314 }
316 $options{ordered} = 1 if(defined($opts{ordered}) and $opts{ordered});
317 $options{showUnionReduceWarnings}= $opts{showUnionReduceWarnings} || 1; 315 $options{showUnionReduceWarnings} = $opts{showUnionReduceWarnings};
318 $options{studentsMustReduceUnions} = $opts{studentsMustReduceUnions} || 0; 316 $options{studentsMustReduceUnions} = $opts{studentsMustReduceUnions};
317 if(defined($opts{ordered}) and $opts{ordered}) {
318 $options{ordered} = 1;
319 # Force this option if the the union must be ordered
320 $options{studentsMustReduceUnions} = 1;
321 }
319 if (defined($opts{'sloppy'}) && $opts{'sloppy'} eq 'yes') { 322 if (defined($opts{'sloppy'}) && $opts{'sloppy'} eq 'yes') {
320 $options{requireParenMatch} = 0; 323 $options{requireParenMatch} = 0;
321 } 324 }
322 # historically we allow more infinities 325 # historically we allow more infinities
323 $context->strings->add( 326 $context->strings->add(
325 'infty' => {alias=>'infinity'}, 328 'infty' => {alias=>'infinity'},
326 'minfinity' => {infinite=>1, negative=>1}, 329 'minfinity' => {infinite=>1, negative=>1},
327 'minfty' => {alias=>'minfinity'}, 330 'minfty' => {alias=>'minfinity'},
328 'minf' => {alias=>'minfinity'}, 331 'minf' => {alias=>'minfinity'},
329 'mi' => {alias=>'minfinity'}, 332 'mi' => {alias=>'minfinity'},
330 ); 333 );
331 # Add any strings 334 # Add any strings
332 if ($opts{strings}) { 335 if ($opts{strings}) {
333 foreach my $string (@{$opts{strings}}) { 336 foreach my $string (@{$opts{strings}}) {
334 $string = uc($string); 337 $string = uc($string);
335 $context->strings->add($string) unless 338 $context->strings->add($string) unless

Legend:
Removed from v.3512  
changed lines
  Added in v.3513

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9