From: dpvc v. a. <we...@ma...> - 2010-04-01 00:46:35
|
Log Message: ----------- Back out of accidental commit of complex macros Modified Files: -------------- pg/macros: PGcomplexmacros.pl Revision Data ------------- Index: PGcomplexmacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGcomplexmacros.pl,v retrieving revision 1.15 retrieving revision 1.16 diff -Lmacros/PGcomplexmacros.pl -Lmacros/PGcomplexmacros.pl -u -r1.15 -r1.16 --- macros/PGcomplexmacros.pl +++ macros/PGcomplexmacros.pl @@ -90,148 +90,7 @@ =cut -my %cplx_context = ( - 'std' => 'Complex', - 'strict' => 'LimitedComplex-strict', - 'strict_polar' => 'LimitedComplex-polar', - 'strict_cartesian' => 'LimitedComplex-cartesian', - 'strict_num_polar' => 'LimitedComplex-polar-strict', - 'strict_num_cartesian' => 'LimitedComplex-cartesian-strict', -); - sub cplx_cmp { - return original_cplx_cmp(@_) if $main::useOldAnswerMacros; - - my $correctAnswer = shift; - my %cplx_params = @_; - - # - # Get default options - # - assign_option_aliases( \%cplx_params, - 'reltol' => 'relTol', - ); - set_default_options(\%cplx_params, - 'tolType' => (defined($cplx_params{tol}) ) ? 'absolute' : 'relative', - # default mode should be relative, to obtain this tol must not be defined - 'tolerance' => $main::numAbsTolDefault, - 'relTol' => $main::numRelPercentTolDefault, - 'zeroLevel' => $main::numZeroLevelDefault, - 'zeroLevelTol' => $main::numZeroLevelTolDefault, - 'format' => $main::numFormatDefault, - 'debug' => 0, - 'mode' => 'std', - 'strings' => undef, - ); - my $format = $cplx_params{'format'}; - my $mode = $cplx_params{'mode'}; - - if( $cplx_params{tolType} eq 'relative' ) { - $cplx_params{'tolerance'} = .01*$cplx_params{'relTol'}; - } - - my $context = $cplx_context{$mode}; - unless ($context) {$context = "Complex"; warn "Unknown mode '$mode'"} - $context = $Parser::Context::Default::context{$context}->copy; - - # - # Set the format for the context - # - $context->{format}{number} = $cplx_params{'format'} if $cplx_params{'format'}; - - # - # Add the strings to the context - # - if ($cplx_params{strings}) { - foreach my $string (@{$cplx_params{strings}}) { - my %tex = ($string =~ m/(-?)inf(inity)?/i)? (TeX => "$1\\infty"): (); - $context->strings->add(uc($string) => {%tex}) - unless $context->strings->get(uc($string)); - } - } - - # - # Set the tolerances - # - if ($cplx_params{tolType} eq 'absolute') { - $context->flags->set( - tolerance => $cplx_params{tolerance}, - tolType => 'absolute', - ); - } else { - $context->flags->set( - tolerance => .01*$cplx_params{tolerance}, - tolType => 'relative', - ); - } - $context->flags->set( - zeroLevel => $cplx_params{zeroLevel}, - zeroLevelTol => $cplx_params{zeroLevelTol}, - ); - - # - # Get the proper Parser object for the professor's answer - # using the initialized context - # - my $oldContext = Parser::Context->current(\%main::context,$context); my $z; - if (ref($correctAnswer) eq 'Complex') { - $z = Value::Complex->new($correctAnswer->Re,$correctAnswer->Im); - } else { - $z = Value::Formula->new($correctAnswer); - die "The professor's answer can't be a formula" unless $z->isConstant; - $z = $z->eval; $z = new Value::Complex($z) unless Value::class($z) eq 'String'; - } - $z->{correct_ans} = $correctAnswer; - - # - # Get the answer checker from the parser object - # - my $cmp = $z->cmp; - $cmp->install_pre_filter(sub { - my $rh_ans = shift; - $rh_ans->{original_student_ans} = $rh_ans->{student_ans}; - $rh_ans->{original_correct_ans} = $rh_ans->{correct_ans}; - return $rh_ans; - }); - $cmp->install_post_filter(sub { - my $rh_ans = shift; my $z = $rh_ans->{student_value}; - # - # Stringify student answer (use polar form if student did) - # - if (ref($z) && $z->isNumber) { - $z = Value::Complex->new($z); # promote real to complex - if ($rh_ans->{original_student_ans} =~ m/(^|[^a-zA-Z])e\s*(\^|\*\*)/) { - my ($a,$b) = ($z->mod,$z->arg); - unless ($context->flag('strict_numeric')) { - my $rt = (new Complex($z->Re->value,$z->Im->value))->stringify_polar; - ($a,$b) = ($rt =~ m/\[(.*),(.*)\]/); - } - $a = Value::Real->new($a)->string; - $b = Value::Real->new($b)->string if Value::matchNumber($b); - if ($b eq '0') { - $rh_ans->{student_ans} = $a; - } else { - if ($a eq '1') {$a = ''} elsif ($a eq '-1') {$a = '-'} else {$a .= '*'} - if ($b eq '1') {$b = 'i'} elsif ($b eq '-1') {$b = '(-i)'} else {$b = "($b i)"} - $rh_ans->{student_ans} = $a.'e^'.$b; - } - } else { - $rh_ans->{student_ans} = $rh_ans->{student_value}->string; - } - } - return $rh_ans; - }); - $cmp->{debug} = $cplx_params{debug}; - Parser::Context->current(\%main::context,$oldContext); - - return $cmp; -} - -# -# The original version, for backward compatibility -# (can be removed when the Parser-based version is more fully tested.) -# -sub original_cplx_cmp { my $correctAnswer = shift; my %cplx_params = @_; |