[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 5905 Revision 5907
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.13 2008/09/11 17:26:57 dpvc Exp $ 4# $CVSHeader: pg/macros/parserFormulaUpToConstant.pl,v 1.14 2008/09/12 21:31:43 dpvc Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
147 my $n00 = $context->variables->get("n00"); 147 my $n00 = $context->variables->get("n00");
148 $context->variables->add(n00=>'Parameter') unless $n00 and $n00->{parameter}; 148 $context->variables->add(n00=>'Parameter') unless $n00 and $n00->{parameter};
149 my $n01 = $context->variables->get("n01"); 149 my $n01 = $context->variables->get("n01");
150 $context->variables->add(n01=>'Parameter') unless $n01 and $n01->{parameter}; 150 $context->variables->add(n01=>'Parameter') unless $n01 and $n01->{parameter};
151 $f->{adapt} = $f + "(n00-$n)$f->{constant} + n01"; 151 $f->{adapt} = $f + "(n00-$n)$f->{constant} + n01";
152
152 return bless $f, $class; 153 return bless $f, $class;
153} 154}
154 155
155################################################## 156##################################################
156# 157#
173 # 174 #
174 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant}; 175 $r = $r->substitute($r->{constant}=>$l->{constant}) unless $r->{constant} eq $l->{constant};
175 # 176 #
176 # Compare with adaptive parameters to see if $l + n0 C = $r for some n0. 177 # Compare with adaptive parameters to see if $l + n0 C = $r for some n0.
177 # 178 #
178 $main::{_cmp_} = sub {return $l->{adapt} == $r}; # a closure to access local variables 179 $main::{_cmp_} = sub {return ($l->{adapt}->inherit($l)) == $r}; # a closure to access local variables
179 my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters 180 my $equal = main::PG_restricted_eval('&{$main::{_cmp_}}'); # prevents errors with large adaptive parameters
180 delete $main::{_cmp_}; # remove temprary function 181 delete $main::{_cmp_}; # remove temprary function
181 return -1 unless $equal; 182 return -1 unless $equal;
182 # 183 #
183 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer) 184 # Check that n0 is non-zero (i.e., there is a multiple of C in the student answer)
184 # (remember: return value of 0 is equal, and non-zero is unequal) 185 # (remember: return value of 0 is equal, and non-zero is unequal)
185 # 186 #
235# 236#
236# Remove the constant and return a Formula object 237# Remove the constant and return a Formula object
237# 238#
238sub removeConstant { 239sub removeConstant {
239 my $self = shift; 240 my $self = shift;
240 main::Formula($self->substitute($self->{constant}=>0))->reduce; 241 main::Formula($self->substitute($self->{constant}=>0))->reduce->inherit($self);
241} 242}
242 243
243# 244#
244# Override the differentiation so that we always return 245# Override the differentiation so that we always return
245# a Formula, not a FormulaUpToConstant (we don't want to 246# a Formula, not a FormulaUpToConstant (we don't want to

Legend:
Removed from v.5905  
changed lines
  Added in v.5907

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9