From: dpvc v. a. <we...@ma...> - 2008-09-15 15:40:24
|
Log Message: ----------- Fixed problem with inerhiting test points into the adapted formula used for the comparison. In its context, the arbitrary constant is an extra variable, and so extra coordinates have to be added to the test points. This is now handled properly. (It may be a good idea to make $f->removeConstant revert to the original context of the formula rather than the modified one that includes its constants, rather than having to adjust the test points in that case.) Modified Files: -------------- pg/macros: parserFormulaUpToConstant.pl Revision Data ------------- Index: parserFormulaUpToConstant.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFormulaUpToConstant.pl,v retrieving revision 1.15 retrieving revision 1.16 diff -Lmacros/parserFormulaUpToConstant.pl -Lmacros/parserFormulaUpToConstant.pl -u -r1.15 -r1.16 --- macros/parserFormulaUpToConstant.pl +++ macros/parserFormulaUpToConstant.pl @@ -176,9 +176,9 @@ # # Compare with adaptive parameters to see if $l + n0 C = $r for some n0. # - $main::{_cmp_} = sub {return ($l->{adapt}->inherit($l)) == $r}; # a closure to access local variables - my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters - delete $main::{_cmp_}; # remove temprary function + $main::{_cmp_} = sub {return $l->adapt == $r}; # a closure to access local variables + my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters + delete $main::{_cmp_}; # remove temprary function return -1 unless $equal; # # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) @@ -187,6 +187,55 @@ return abs($context->variables->get("n00")->{value}) < $context->flag("zeroLevelTol"); } +# +# Return the {adapt} formula with test points adjusted +# +sub adapt { + my $self = shift; + my $adapt = $self->{adapt}->inherit($self); delete $adapt->{adapt}; + return $self->adjustInherit($self->{adapt}); +} + +# +# Inherit from the main FormulaUpToConstant, but +# adjust the test points to include the constants +# +sub adjustInherit { + my $self = shift; + my $f = shift->inherit($self); + delete $f->{adapt}; delete $f->{constant}; + foreach my $id ('test_points','test_at') { + if (defined $f->{$id}) { + $f->{$id} = $f->{$id}->value if Value::isValue($f->{$id}); + $f->{$id} = [$f->{$id}] unless ref($f->{$id}) eq 'ARRAY'; + $f->{$id} = [map {[$_]} @{$f->{$id}}] unless ref($f->{$id}[0]) eq 'ARRAY'; + $f->{$id} = $self->addConstants($f->{$id}); + } + } + return $f; +} + +# +# Insert dummy values for the constants for the test points +# (These are supposed to be +C, so the value shouldn't matter?) +# +sub addConstants { + my $self = shift; my $points = shift; + my @names = $self->context->variables->variables; + my $variables = $self->context->{variables}; + my $Points = []; + foreach my $p (@{$points}) { + my @P = (.1) x scalar(@names); my $j = 0; + foreach my $i (0..scalar(@names)-1) { + if (!$variables->{$names[$i]}{arbitraryConstant}) { + $P[$i] = $p->[$j] if defined $p->[$j]; $j++; + } + } + push (@{$Points}, \@P); + } + return $Points; +} + ################################################## # # Here we override part of the answer comparison @@ -238,7 +287,7 @@ # sub removeConstant { my $self = shift; - main::Formula($self->substitute($self->{constant}=>0))->reduce->inherit($self); + return $self->adjustInherit(main::Formula($self->substitute($self->{constant}=>0))->reduce); } # |