From: Sam H. v. a. <we...@ma...> - 2007-10-03 19:55:14
|
Log Message: ----------- fixed indentation of verbatim paragraphs: now using hard tabs exclusively. the downside of this is that these get rendered as eight-column tabs. Modified Files: -------------- pg/macros: answerHints.pl answerVariableList.pl contextABCD.pl contextCurrency.pl contextInequalities.pl contextIntegerFunctions.pl contextLimitedComplex.pl contextLimitedNumeric.pl contextLimitedPoint.pl contextLimitedPolynomial.pl contextLimitedPowers.pl contextLimitedVector.pl contextPeriodic.pl contextPiecewiseFunction.pl contextScientificNotation.pl contextString.pl contextTF.pl parserAutoStrings.pl parserCustomization.pl parserDifferenceQuotient.pl parserFormulaUpToConstant.pl parserFormulaWithUnits.pl parserFunction.pl parserImplicitEquation.pl parserImplicitPlane.pl parserMultiAnswer.pl parserNumberWithUnits.pl parserParametricLine.pl parserVectorUtils.pl problemRandomize.pl Revision Data ------------- Index: parserImplicitEquation.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserImplicitEquation.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/parserImplicitEquation.pl -Lmacros/parserImplicitEquation.pl -u -r1.10 -r1.11 --- macros/parserImplicitEquation.pl +++ macros/parserImplicitEquation.pl @@ -61,14 +61,14 @@ Usage examples: - Context("ImplicitEquation"); - $f = ImplicitEquation("x^2 = cos(y)"); - $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]); - $f = ImplicitEquation("x=1/y",tolerance=>.0001); + Context("ImplicitEquation"); + $f = ImplicitEquation("x^2 = cos(y)"); + $f = ImplicitEquation("x^2 - 2y^2 = 5",limits=>[[-3,3],[-2,2]]); + $f = ImplicitEquation("x=1/y",tolerance=>.0001); Then use - ANS($f->cmp); + ANS($f->cmp); to get the answer checker for $f. @@ -150,13 +150,12 @@ For example: - $f = ImplicitEquation("x^2-y^2=0", - solutions => [[0,0],[1,1],[-1,1],[-1,-1],[1,-1]], - tolerance => .001 - ); + $f = ImplicitEquation("x^2-y^2=0", + solutions => [[0,0],[1,1],[-1,1],[-1,-1],[1,-1]], + tolerance => .001 + ); - - $f = ImplicitEquation("xy=5",limits=>[-3,3]); + $f = ImplicitEquation("xy=5",limits=>[-3,3]); The limits value can be set globally within the Context, if you wish, and the others can be controlled by the Context flags discussed Index: parserParametricLine.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserParametricLine.pl,v retrieving revision 1.14 retrieving revision 1.15 diff -Lmacros/parserParametricLine.pl -Lmacros/parserParametricLine.pl -u -r1.14 -r1.15 --- macros/parserParametricLine.pl +++ macros/parserParametricLine.pl @@ -17,18 +17,18 @@ Usage examples: - $L = ParametricLine(Point(3,-1,2),Vector(1,1,3)); - $L = ParametricLine([3,-1,2],[1,1,3]); - $L = ParametricLine("<t,1-t,2t-3>"); + $L = ParametricLine(Point(3,-1,2),Vector(1,1,3)); + $L = ParametricLine([3,-1,2],[1,1,3]); + $L = ParametricLine("<t,1-t,2t-3>"); - $p = Point(3,-1,2); $v = Vector(1,1,3); - $L = ParametricLine($p,$v); + $p = Point(3,-1,2); $v = Vector(1,1,3); + $L = ParametricLine($p,$v); - $t = Formula('t'); $p = Point(3,-1,2); $v = Vector(1,1,3); - $L = ParametricLine($p+$t*$v); + $t = Formula('t'); $p = Point(3,-1,2); $v = Vector(1,1,3); + $L = ParametricLine($p+$t*$v); - Context()->constants->are(a=>1+pi^2); # won't guess this value - $L = ParametricLine("(a,2a,-1) + t <1,a,a^2>"); + Context()->constants->are(a=>1+pi^2); # won't guess this value + $L = ParametricLine("(a,2a,-1) + t <1,a,a^2>"); Then use Index: contextLimitedPoint.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPoint.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/contextLimitedPoint.pl -Lmacros/contextLimitedPoint.pl -u -r1.11 -r1.12 --- macros/contextLimitedPoint.pl +++ macros/contextLimitedPoint.pl @@ -9,7 +9,7 @@ students will be able to perform operations within the coordinates of the points, but not between points. - Context("LimitedPoint") + Context("LimitedPoint") =cut Index: contextString.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextString.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -Lmacros/contextString.pl -Lmacros/contextString.pl -u -r1.12 -r1.13 --- macros/contextString.pl +++ macros/contextString.pl @@ -9,12 +9,12 @@ You can add new strings to the context as needed via the Context()->strings->add() method. E.g., - Context("String")->strings->add(Foo=>{}, Bar=>{alias=>"Foo"}); + Context("String")->strings->add(Foo=>{}, Bar=>{alias=>"Foo"}); Use string_cmp() to produce the answer checker(s) for your correct values. Eg. - ANS(string_cmp("Foo")); + ANS(string_cmp("Foo")); =cut Index: parserCustomization.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserCustomization.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -Lmacros/parserCustomization.pl -Lmacros/parserCustomization.pl -u -r1.5 -r1.6 --- macros/parserCustomization.pl +++ macros/parserCustomization.pl @@ -1,33 +1,35 @@ -sub _parserCustomization_init {} +=head1 NAME + +parserCustomization.pl - Placeholder for site/course-local customization file. + +=head1 DESCRIPTION + +Copy this file to your course templates directory and put any +customization for the Parser that you want for your course +here. For example, you can make vectors display using +ijk notation (and force students to use it for entering +vectors) by uncommenting: -=head1 parserCustomization + $context{Vector} = Parser::Context->getCopy("Vector"); + $context{Vector}->flags->set(ijk=>1); + $context{Vector}->parens->remove('<'); - # - # Copy this file to your course templates directory and put any - # customization for the Parser that you want for your course - # here. For example, you can make vectors display using - # ijk notation (and force students to use it for entering - # vectors) by uncommenting: - # - # $context{Vector} = Parser::Context->getCopy("Vector"); - # $context{Vector}->flags->set(ijk=>1); - # $context{Vector}->parens->remove('<'); - # - # To allow vectors to be entered with parens (and displayed with - # parens) rather than angle-brakets, uncomment - # - # $context{Vector} = Parser::Context->getCopy("Vector"); - # $context{Vector}->{cmpDefaults}{Vector} = {promotePoints => 1}; - # $context{Vector}->lists->set(Vector=>{open=>'(', close=>')'}); - # - # (This actually just turns points into vectors in the answer checker - # for vectors, and displays vectors using parens rather than angle - # brakets. The student is really still entering what the Parser - # thinks is a point, but since points get promoted automatically - # in the Value package, that should work. But if a problem checks - # if a student's value is actually a Vector, that will not be true.) - # +To allow vectors to be entered with parens (and displayed with +parens) rather than angle-brakets, uncomment + + $context{Vector} = Parser::Context->getCopy("Vector"); + $context{Vector}->{cmpDefaults}{Vector} = {promotePoints => 1}; + $context{Vector}->lists->set(Vector=>{open=>'(', close=>')'}); + +(This actually just turns points into vectors in the answer checker +for vectors, and displays vectors using parens rather than angle +brakets. The student is really still entering what the Parser +thinks is a point, but since points get promoted automatically +in the Value package, that should work. But if a problem checks +if a student's value is actually a Vector, that will not be true.) =cut +sub _parserCustomization_init {} + 1; Index: contextLimitedNumeric.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedNumeric.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -Lmacros/contextLimitedNumeric.pl -Lmacros/contextLimitedNumeric.pl -u -r1.8 -r1.9 --- macros/contextLimitedNumeric.pl +++ macros/contextLimitedNumeric.pl @@ -11,8 +11,8 @@ and one for a single number. Select them using one of the following commands: - Context("LimitedNumeric-List"); - Context("LimiteNumeric"); + Context("LimitedNumeric-List"); + Context("LimiteNumeric"); (Now uses Parcer::Legacy::LimitedNumeric to implement these contexts.) Index: parserVectorUtils.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserVectorUtils.pl,v retrieving revision 1.6 retrieving revision 1.7 diff -Lmacros/parserVectorUtils.pl -Lmacros/parserVectorUtils.pl -u -r1.6 -r1.7 --- macros/parserVectorUtils.pl +++ macros/parserVectorUtils.pl @@ -14,7 +14,7 @@ =head2 Overline - Overline($vectorName) + Overline($vectorName) formats a vector name (should be used in math mode) @@ -38,7 +38,7 @@ =head2 BoldMath - BoldMath($vectorName) + BoldMath($vectorName) This gets a bold letter in TeX as well as HTML modes. Although \boldsymbol{} works fine on screen in latex2html mode, @@ -63,11 +63,11 @@ =head2 $GRAD - TEXT($GRAD) + TEXT($GRAD) - BEGIN_TEXT - $GRAD - END_TEXT + BEGIN_TEXT + $GRAD + END_TEXT Grad symbol. @@ -77,7 +77,7 @@ =head2 non_zero_point - non_zero_point($Dim,$L_bound,$U_bound,$step) + non_zero_point($Dim,$L_bound,$U_bound,$step) Create a non-zero point with the given number of coordinates with the given random range (which defaults to (-5,5,1)). @@ -102,11 +102,11 @@ =head2 non_zero_vector, non_zero_vector2D, non_zero_vector3D - non_zero_vector($Dim,$L_bound,$U_bound,$step) + non_zero_vector($Dim,$L_bound,$U_bound,$step) - non_zero_vector2D($L_bound,$U_bound,$step) + non_zero_vector2D($L_bound,$U_bound,$step) - non_zero_vector3D($L_bound,$U_bound,$step) + non_zero_vector3D($L_bound,$U_bound,$step) Functions the same as non_zero_point but for Vectors. non_zero_vector2D and non_zero_vector3D automatically set Dimension to 2 and 3 respectively. @@ -150,7 +150,7 @@ =head2 Plane - Plane($point,$NormalVector) + Plane($point,$NormalVector) Creates a displayable string for a plane given its normal vector and a point on the plane. (Better to use Index: parserDifferenceQuotient.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserDifferenceQuotient.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -Lmacros/parserDifferenceQuotient.pl -Lmacros/parserDifferenceQuotient.pl -u -r1.12 -r1.13 --- macros/parserDifferenceQuotient.pl +++ macros/parserDifferenceQuotient.pl @@ -19,16 +19,16 @@ DifferenceQuotient(). You could use a variable like h instead of dx if you prefer. -Usage examples: +=head1 USAGE - $df = DifferenceQuotient("2x+dx"); - ANS($df->cmp); + $df = DifferenceQuotient("2x+dx"); + ANS($df->cmp); - $df = DifferenceQuotient("2x+h","h"); - ANS($df->cmp); + $df = DifferenceQuotient("2x+h","h"); + ANS($df->cmp); - Context()->variables->are(t=>'Real',a=>'Real'); - ANS(DifferenceQuotient("-a/[t(t+dt)]","dt")->cmp); + Context()->variables->are(t=>'Real',a=>'Real'); + ANS(DifferenceQuotient("-a/[t(t+dt)]","dt")->cmp); =cut Index: parserImplicitPlane.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserImplicitPlane.pl,v retrieving revision 1.17 retrieving revision 1.18 diff -Lmacros/parserImplicitPlane.pl -Lmacros/parserImplicitPlane.pl -u -r1.17 -r1.18 --- macros/parserImplicitPlane.pl +++ macros/parserImplicitPlane.pl @@ -27,19 +27,19 @@ Usage examples: - $P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); # -x+y+3z = 5 - $P = ImplicitPlane([1,0,2],[-1,1,3]); # -x+y+3z = 5 - $P = ImplicitPlane([1,0,2],4); # x+2z = 4 - $P = ImplicitPlane("x+2y-z=5"); - - Context()->variables->are(x=>'Real',y=>'Real',z=>'Real',w=>'Real'); - $P = ImplicitPlane([1,0,2,-1],10); # w+2y-z = 10 (alphabetical order) - $P = ImplicitPlane([3,-1,2,4],5,['x','y','z','w']); # 3x-y+2z+4w = 5 - $P = ImplicitPlane([3,-1,2],5,['y','z','w']); # 3y-z+2w = 5 + $P = ImplicitPlane(Point(1,0,2),Vector(-1,1,3)); # -x+y+3z = 5 + $P = ImplicitPlane([1,0,2],[-1,1,3]); # -x+y+3z = 5 + $P = ImplicitPlane([1,0,2],4); # x+2z = 4 + $P = ImplicitPlane("x+2y-z=5"); + + Context()->variables->are(x=>'Real',y=>'Real',z=>'Real',w=>'Real'); + $P = ImplicitPlane([1,0,2,-1],10); # w+2y-z = 10 (alphabetical order) + $P = ImplicitPlane([3,-1,2,4],5,['x','y','z','w']); # 3x-y+2z+4w = 5 + $P = ImplicitPlane([3,-1,2],5,['y','z','w']); # 3y-z+2w = 5 Then use - ANS($P->cmp); + ANS($P->cmp); to get the answer checker for $P. Index: contextLimitedVector.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedVector.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextLimitedVector.pl -Lmacros/contextLimitedVector.pl -u -r1.10 -r1.11 --- macros/contextLimitedVector.pl +++ macros/contextLimitedVector.pl @@ -20,9 +20,9 @@ You control which format to use by setting the context to one of the following: - Context("LimitedVector-coordinate"); - Context("LimitedVector-ijk"); - Context("LimitedVector"); # either one + Context("LimitedVector-coordinate"); + Context("LimitedVector-ijk"); + Context("LimitedVector"); # either one =cut Index: parserFormulaWithUnits.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFormulaWithUnits.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/parserFormulaWithUnits.pl -Lmacros/parserFormulaWithUnits.pl -u -r1.9 -r1.10 --- macros/parserFormulaWithUnits.pl +++ macros/parserFormulaWithUnits.pl @@ -12,7 +12,7 @@ to generate a FormulaWithUnits object, and then call its cmp() method to get an answer checker for your formula with units. -Usage examples: +=head1 USAGE ANS(FormulaWithUnits("3x+1 ft")->cmp); ANS(FormulaWithUnits("$a*x+1 ft")->cmp); Index: parserNumberWithUnits.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserNumberWithUnits.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/parserNumberWithUnits.pl -Lmacros/parserNumberWithUnits.pl -u -r1.7 -r1.8 --- macros/parserNumberWithUnits.pl +++ macros/parserNumberWithUnits.pl @@ -14,9 +14,9 @@ Usage examples: - ANS(NumberWithUnits("3 ft")->cmp); - ANS(NumberWithUnits("$a*$b ft")->cmp); - ANS(NumberWithUnits($a*$b,"ft")->cmp); + ANS(NumberWithUnits("3 ft")->cmp); + ANS(NumberWithUnits("$a*$b ft")->cmp); + ANS(NumberWithUnits($a*$b,"ft")->cmp); We now call on the Legacy version, which is used by num_cmp to handle numbers with units. Index: answerVariableList.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/answerVariableList.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/answerVariableList.pl -Lmacros/answerVariableList.pl -u -r1.10 -r1.11 --- macros/answerVariableList.pl +++ macros/answerVariableList.pl @@ -3,6 +3,36 @@ answerVariableList.pl - Creates answer checkers that compare the student's answer to a list of variable names. +=head1 MACROS + +=head2 variable_cmp + + ANS(variable_cmp($var_string, %options)) + +This answer checker compares the student answer to a list of +variable names (so, for example, you can ask for what values a +given function depends on). + +Use addVariables() to create the list of variables that from which +the student can choose, and then use variable_cmp() to generate the +answer checker. If the formula passed to variable_cmp contains +parentheses around the list, then the student's answer must as +well. + +You can also include additional parameters to variable_cmp. These +can be any of the flags appropriate for List() answer checker. + +Usage examples: + + addVariables('x','y','z'); + ANS(variable_cmp("(x,y)")); + + addVariables('x','y','z','s','t,); + ANS(variable_cmp("s,t")); + + addVariables('x','y','z'); + ANS(variable_cmp("(x)",showHints=>0,showLengthHints=>0)); + =cut loadMacros('MathObjects.pl'); @@ -30,38 +60,6 @@ main::Context("VariableList"); ### FIXME: probably should require author to set this explicitly. } -=head1 MACROS - -=head2 variable_cmp - - ANS(variable_cmp($var_string, %options)) - -This answer checker compares the student answer to a list of -variable names (so, for example, you can ask for what values a -given function depends on). - -Use addVariables() to create the list of variables that from which -the student can choose, and then use variable_cmp() to generate the -answer checker. If the formula passed to variable_cmp contains -parentheses around the list, then the student's answer must as -well. - -You can also include additional parameters to variable_cmp. These -can be any of the flags appropriate for List() answer checker. - -Usage examples: - - addVariables('x','y','z'); - ANS(variable_cmp("(x,y)")); - - addVariables('x','y','z','s','t,); - ANS(variable_cmp("s,t")); - - addVariables('x','y','z'); - ANS(variable_cmp("(x)",showHints=>0,showLengthHints=>0)); - -=cut - sub variable_cmp { Value->Package("Formula")->new(shift)->cmp( ordered => 1, Index: contextLimitedComplex.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedComplex.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextLimitedComplex.pl -Lmacros/contextLimitedComplex.pl -u -r1.10 -r1.11 --- macros/contextLimitedComplex.pl +++ macros/contextLimitedComplex.pl @@ -9,7 +9,7 @@ be able to perform operations within the real and imaginary parts of the complex numbers, but not between complex numbers. - Context("LimitedComplex") + Context("LimitedComplex") Complex Numbers can still be entered in a+bi or a*e^(bt) form. The e and i are allowed to be entered only once, so we have @@ -20,27 +20,27 @@ You control which format to use by setting the complex_format context flag to 'cartesian', 'polar' or 'either'. E.g., - Context()->flags->set(complex_format => 'polar'); + Context()->flags->set(complex_format => 'polar'); The default is 'either'. There are predefined contexts that already have these values set: - Context("LimitedComplex-cartesian"); - Context("LimitedComplex-polar"); + Context("LimitedComplex-cartesian"); + Context("LimitedComplex-polar"); You can require that the a and b used in these forms be strictly numbers (not expressions) by setting the strict_numeric flag and disabling all the functions: - Context()->flags->set(strict_numeric=>1); - Context()->functions->disable('All'); + Context()->flags->set(strict_numeric=>1); + Context()->functions->disable('All'); There are predefined contexts that already have these values set: - Context("LimitedComplex-cartesian-strict"); - Context("LimitedComplex-polar-strict"); - Context("LimitedComplex-strict"); + Context("LimitedComplex-cartesian-strict"); + Context("LimitedComplex-polar-strict"); + Context("LimitedComplex-strict"); =cut Index: contextPeriodic.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextPeriodic.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextPeriodic.pl -Lmacros/contextPeriodic.pl -u -r1.10 -r1.11 --- macros/contextPeriodic.pl +++ macros/contextPeriodic.pl @@ -10,13 +10,13 @@ =head1 USAGE - Context("Numeric"); - $a = Real("pi/2")->with(period=>pi); - $a->cmp # will match pi/2, 3pi/2 etc. + Context("Numeric"); + $a = Real("pi/2")->with(period=>pi); + $a->cmp # will match pi/2, 3pi/2 etc. - Context("Complex"); - $z0 = Real("i^i")->with(period=>2pi, logPeriodic=>1); - $z0->cmp # will match exp(i*(ln(1) + Arg(pi/2) + 2k pi)) + Context("Complex"); + $z0 = Real("i^i")->with(period=>2pi, logPeriodic=>1); + $z0->cmp # will match exp(i*(ln(1) + Arg(pi/2) + 2k pi)) =cut Index: contextPiecewiseFunction.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextPiecewiseFunction.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -Lmacros/contextPiecewiseFunction.pl -Lmacros/contextPiecewiseFunction.pl -u -r1.5 -r1.6 --- macros/contextPiecewiseFunction.pl +++ macros/contextPiecewiseFunction.pl @@ -7,22 +7,22 @@ This file implements a context in which piecewise-defined functions can be specified by students and problem authors. To use it, add - loadMacros("contextPiecewiseFunction.pl"); + loadMacros("contextPiecewiseFunction.pl"); and then use - Context("PiecewiseFuntion"); + Context("PiecewiseFuntion"); to select the context for piecewise functions. There are several ways to produce a piecewise function. For example: - $f = Compute("x if x >= 0 else -x"); - $f = Compute("x if x >= 0 else -x if x < 0"); - $f = Formula("x+1 if x > 2 else 4 if x = 2 else 1-x"); - $f = PiecewiseFunction("x^2 if 1 < x <= 2 else 2x+1"); - $f = PiecewiseFunction("1 < x <= 2" => "x^2", "2x+1"); - $f = PiecewiseFunction("(1,2]" => "x^2", "2x+1"); - $f = PiecewiseFunction(Interval("(1,2]") => "x^2", "2x+1"); + $f = Compute("x if x >= 0 else -x"); + $f = Compute("x if x >= 0 else -x if x < 0"); + $f = Formula("x+1 if x > 2 else 4 if x = 2 else 1-x"); + $f = PiecewiseFunction("x^2 if 1 < x <= 2 else 2x+1"); + $f = PiecewiseFunction("1 < x <= 2" => "x^2", "2x+1"); + $f = PiecewiseFunction("(1,2]" => "x^2", "2x+1"); + $f = PiecewiseFunction(Interval("(1,2]") => "x^2", "2x+1"); You can use either Compute() or Formula() interchangeably to convert a string containing "if" and "else" to the corresponding @@ -41,18 +41,18 @@ output even if you are not asking a student to enter one. For example: - Context("PiecewiseFunction"); - - $f = Formula("1-x if x > 0 else 4 if x = 0 else 1+x if x < 0"); - $a = random(-2,2,.1); - - Context()->texStrings; - BEGIN_TEXT - Suppose \(f(x)=$f\). Then \(f($a)\) = \{ans_rule(20)\}. - END_TEXT - Context()->normalStrings; - - ANS($f->eval(x=>$a)->cmp); + Context("PiecewiseFunction"); + + $f = Formula("1-x if x > 0 else 4 if x = 0 else 1+x if x < 0"); + $a = random(-2,2,.1); + + Context()->texStrings; + BEGIN_TEXT + Suppose \(f(x)=$f\). Then \(f($a)\) = \{ans_rule(20)\}. + END_TEXT + Context()->normalStrings; + + ANS($f->eval(x=>$a)->cmp); =cut Index: contextInequalities.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextInequalities.pl,v retrieving revision 1.14 retrieving revision 1.15 diff -Lmacros/contextInequalities.pl -Lmacros/contextInequalities.pl -u -r1.14 -r1.15 --- macros/contextInequalities.pl +++ macros/contextInequalities.pl @@ -13,18 +13,18 @@ =head1 USAGE - loadMacros("contextInequalities.pl"); - - Context("Inequalities"); - $S1 = Compute("1 < x <= 4"); - $S2 = Inequality("(1,4]"); # force interval to be inequality - - Context("Inequalities-Only"); - $S1 = Compute("1 < x <= 4"); - $S2 = Inequality("(1,4]"); # generates an error - - $S3 = Compute("x < -2 or x > 2"); # forms a Union - $S4 = Compute("x = 1"); # forms a Set + loadMacros("contextInequalities.pl"); + + Context("Inequalities"); + $S1 = Compute("1 < x <= 4"); + $S2 = Inequality("(1,4]"); # force interval to be inequality + + Context("Inequalities-Only"); + $S1 = Compute("1 < x <= 4"); + $S2 = Inequality("(1,4]"); # generates an error + + $S3 = Compute("x < -2 or x > 2"); # forms a Union + $S4 = Compute("x = 1"); # forms a Set You can set the "noneWord" flag to specify the string to use when the inequalities specify the empty set. By default, @@ -32,9 +32,9 @@ that you use a string that is defined in the Context, however, if you expect the student to be able to enter it. For example - Context("Inequalities"); - Context()->constants->add(EmptySet => Set()); - Context()->flags->set(noneWord=>"EmptySet"); + Context("Inequalities"); + Context()->constants->add(EmptySet => Set()); + Context()->flags->set(noneWord=>"EmptySet"); creates an empty set as a named constant and uses that name. @@ -45,11 +45,11 @@ convert from an Inequality object to one in interval notation. For example: - $I0 = Compute("(1,2]"); # the interval (1,2] - $I1 = Inequality($I); # the inequality 1 < x <= 2 + $I0 = Compute("(1,2]"); # the interval (1,2] + $I1 = Inequality($I); # the inequality 1 < x <= 2 - $I0 = Compute("1 < x <= 2"); # the inequality 1 < x <= 2 - $I1 = Interval($I0); # the interval (1,2] + $I0 = Compute("1 < x <= 2"); # the inequality 1 < x <= 2 + $I1 = Interval($I0); # the interval (1,2] Note that ineqaulities and inervals can be compared and combined regardless of the format, so $I0 == $I1 is true in either example Index: parserMultiAnswer.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserMultiAnswer.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/parserMultiAnswer.pl -Lmacros/parserMultiAnswer.pl -u -r1.7 -r1.8 --- macros/parserMultiAnswer.pl +++ macros/parserMultiAnswer.pl @@ -13,20 +13,20 @@ To create a MultiAnswer pass a list of answers to MultiAnswer() in the order they will appear in the problem. For example: - $mp = MultiAnswer("x^2",-1,1); + $mp = MultiAnswer("x^2",-1,1); or - $mp = MultiAnswer(Vector(1,1,1),Vector(2,2,2))->with(singleResult=>1); + $mp = MultiAnswer(Vector(1,1,1),Vector(2,2,2))->with(singleResult=>1); Then, use $mp->ans_rule to create answer blanks for the various parts just as you would ans_rule. You can pass the width of the blank, which defaults to 20 otherwise. For example: - BEGIN_TEXT - \(f(x)\) = \{$mp->ans_rule(20)\} produces the same value - at \(x\) = \{$mp->ans_rule(10)\} as it does at \(x\) = \{$mp->ans_rule(10)\}. - END_TEXT + BEGIN_TEXT + \(f(x)\) = \{$mp->ans_rule(20)\} produces the same value + at \(x\) = \{$mp->ans_rule(10)\} as it does at \(x\) = \{$mp->ans_rule(10)\}. + END_TEXT Finally, call $mp->cmp to produce the answer checker(s) used in the MultiAnswer. You need to provide a checker routine that will be called to determine if the @@ -43,7 +43,7 @@ to an array of scores, one for each blank. The routine can set error messages via the MultiAnswer's setMessage() method (e.g., - $mp->setMessage(1,"The function can't be the identity"); + $mp->setMessage(1,"The function can't be the identity"); would set the message for the first answer blank of the MultiAnswer), or can call Value::Error() to generate an error and die. @@ -51,29 +51,29 @@ The checker routine can be supplied either when the MultiAnswer is created, or when the cmp() method is called. For example: - $mp = MultiAnswer("x^2",1,-1)->with( - singleResult => 1, - checker => sub { - my ($correct,$student,$self) = @_; # get the parameters - my ($f,$x1,$x2) = @{$student}; # extract the student answers - Value::Error("Function can't be the identity") if ($f == 'x'); - Value::Error("Function can't be constant") if ($f->isConstant); - return $f->eval(x=>$x1) == $f->eval(x=>$x2); - }, - ); - ANS($mp->cmp); + $mp = MultiAnswer("x^2",1,-1)->with( + singleResult => 1, + checker => sub { + my ($correct,$student,$self) = @_; # get the parameters + my ($f,$x1,$x2) = @{$student}; # extract the student answers + Value::Error("Function can't be the identity") if ($f == 'x'); + Value::Error("Function can't be constant") if ($f->isConstant); + return $f->eval(x=>$x1) == $f->eval(x=>$x2); + }, + ); + ANS($mp->cmp); or - $mp = MultiAnswer("x^2",1,-1)->with(singleResult=>1); - sub check { - my ($correct,$student,$self) = @_; # get the parameters - my ($f,$x1,$x2) = @{$student}; # extract the student answers - Value::Error("Function can't be the identity") if ($f == 'x'); - Value::Error("Function can't be constant") if ($f->isConstant); - return $f->eval(x=>$x1) == $f->eval(x=>$x2); - }; - ANS($mp->cmp(checker=>~~&check)); + $mp = MultiAnswer("x^2",1,-1)->with(singleResult=>1); + sub check { + my ($correct,$student,$self) = @_; # get the parameters + my ($f,$x1,$x2) = @{$student}; # extract the student answers + Value::Error("Function can't be the identity") if ($f == 'x'); + Value::Error("Function can't be constant") if ($f->isConstant); + return $f->eval(x=>$x1) == $f->eval(x=>$x2); + }; + ANS($mp->cmp(checker=>~~&check)); =cut Index: contextScientificNotation.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextScientificNotation.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -Lmacros/contextScientificNotation.pl -Lmacros/contextScientificNotation.pl -u -r1.8 -r1.9 --- macros/contextScientificNotation.pl +++ macros/contextScientificNotation.pl @@ -19,38 +19,38 @@ To use this context, add - loadMacros("contextScientificNotation.pl"); + loadMacros("contextScientificNotation.pl"); to the top of your problem file, and then use - Context("ScientificNotation"); + Context("ScientificNotation"); to select the contxt and make it active. You can create values in scientific notation in two ways: - $n1 = Compute("1.23 x 10^3"); + $n1 = Compute("1.23 x 10^3"); or - $n2 = ScientificNotation(1.23 * 10**3); + $n2 = ScientificNotation(1.23 * 10**3); (or even $n2 = ScientificNotation(1230), and it will be converted). You can control how many digits are displayed by setting the snDigits flag in the context. For example, - Context()->flags->set(snDigits=>2); + Context()->flags->set(snDigits=>2); sets the context to display at most 2 digits. The default is 6. By default, trailing zeros are removed, but you can ask that they be retained by issuing the command - Context()->flags->set(snTrimZeros=>0); + Context()->flags->set(snTrimZeros=>0); It is also possible to specify how many decimal digits the student must enter. For example, - Context()->flags->set(snMinDigits=>3); + Context()->flags->set(snMinDigits=>3); would require the student to enter at least 3 digits past the decimal place (for a total of 4 significant digits, @@ -60,7 +60,7 @@ Similarly, - Context()->flags->set(snMaxDigits=>6); + Context()->flags->set(snMaxDigits=>6); sets the maximum number to 6, so the student can't enter more than that. Setting this to 0 means no decimal places @@ -73,12 +73,12 @@ As an example, in order to force a fixed precision of three digits of precision, use - Context()->flags->set( - snDigits => 3, - snTrimZeros => 0, - snMinDigits => 3, - snMaxDigits => 3, - ); + Context()->flags->set( + snDigits => 3, + snTrimZeros => 0, + snMinDigits => 3, + snMaxDigits => 3, + ); Note that if you restrict the number of digits, you may need to adjust the tolerance values since the student Index: contextCurrency.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextCurrency.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/contextCurrency.pl -Lmacros/contextCurrency.pl -u -r1.11 -r1.12 --- macros/contextCurrency.pl +++ macros/contextCurrency.pl @@ -1,6 +1,9 @@ -=head1 Context("Currency"); +=head1 NAME -##################################################################### +contextCurrency.pl - Context for entering numbers with currency symbols and +commas. + +=head1 DESCRIPTION This file implements a context in which students can enter currency values that include a currency symbol and commas every three digits. @@ -9,23 +12,23 @@ To use the context, put - loadMacros("contextCurrency.pl"); + loadMacros("contextCurrency.pl"); at the top of your problem file, and then issue the - Context("Currency"); + Context("Currency"); command to select the context. You can set the currency symbol and the comma or decimal values as in the following examples - Context()->currency->set(symbol=>'#'); - Context()->currency->set(symbol=>'euro'); # accepts '12 euro' - Context()->currency->set(comma=>'.',decimal=>','); # accepts '10.000,00' + Context()->currency->set(symbol=>'#'); + Context()->currency->set(symbol=>'euro'); # accepts '12 euro' + Context()->currency->set(comma=>'.',decimal=>','); # accepts '10.000,00' You can add additional symbols (in case you want to allow more than one way to write the currency). For example: - Context("Currency")->currency->addSymbol("dollars","dollar"); + Context("Currency")->currency->addSymbol("dollars","dollar"); would accept '$12,345.67' or '12.50 dollars' or '1 dollar' as acceptable values. Note that if the symbol cantains any @@ -34,27 +37,27 @@ non-alphabetic characters, it comes before it. You can change this as in these examples: - Context()->currency->setSymbol(euro=>{associativity=>"left"}); - Context()->currency->setSymbol('#'=>{associativity=>"right"}); + Context()->currency->setSymbol(euro=>{associativity=>"left"}); + Context()->currency->setSymbol('#'=>{associativity=>"right"}); You can remove a symbol as follows: - Context()->currency->removeSymbol('dollar'); + Context()->currency->removeSymbol('dollar'); To create a currency value, use - $m = Currency(10.99); + $m = Currency(10.99); or - $m1 = Compute('$10.99'); - $m2 = Compute('$10,000.00'); + $m1 = Compute('$10.99'); + $m2 = Compute('$10,000.00'); and so on. Be careful, however, that you do not put dollar signs inside double quotes, as this refers to variable substitution. For example, - $m = Compute("$10.99"); + $m = Compute("$10.99"); will most likely set $m to the Real value .99 rather than the monitary value of $10.99, since perl thinks $10 is the name of @@ -64,9 +67,9 @@ You can use monitary values within computations, as in - $m1 = Compute('$10.00'); - $m2 = 3*$m1; $m3 = $m2 + .5; - $m4 = Compute('$10.00 + $2.59'); + $m1 = Compute('$10.00'); + $m2 = 3*$m1; $m3 = $m2 + .5; + $m4 = Compute('$10.00 + $2.59'); so that $m2 will be $30.00, $m3 will be $30.50, and $m4 will be $12.59. Students can perform computations within their @@ -77,19 +80,19 @@ to the nearest penny. You can change that on a global basis using - Context()->flags->set(tolerance=>.0001,tolType=>"relative"); + Context()->flags->set(tolerance=>.0001,tolType=>"relative"); for example. You can also change the tolerance on an individual currency value as follows: - $m = Compute('$1,250,000.00')->with(tolerance=>.0001,tolType=>'relative'); + $m = Compute('$1,250,000.00')->with(tolerance=>.0001,tolType=>'relative'); By default, the answer checker for Currency values requires the student to enter the currency symbol, not just a real number. You can relax that condition by including the promoteReals=>1 option to the cmp() method of the Currency value. For example, - ANS(Compute('$150')->cmp(promoteReals=>1)); + ANS(Compute('$150')->cmp(promoteReals=>1)); would allow the student to enter just 150 rather than $150. @@ -97,19 +100,19 @@ force them to supply the commas using forceCommas=>1 in your cmp() call. - ANS(Compute('$10,000.00')->cmp(forceCommas=>1)); + ANS(Compute('$10,000.00')->cmp(forceCommas=>1)); By default, students need not enter decimal digits, so could use $100 or $1,000. as valid entries. You can require that the cents be provided using the forceDecimals=>1 flag. - ANS(Compute('$10.95')->cmp(forceDecimals=>1)); + ANS(Compute('$10.95')->cmp(forceDecimals=>1)); By default, if the monitary value includes decimals digits, it must have exactly two. You can weaken this requirement to all any number of decimals by using noExtraDecimals=>0. - ANS(Compute('$10.23372')->cmp(noExtraDecimals=>0); + ANS(Compute('$10.23372')->cmp(noExtraDecimals=>0); If forceDecimals is set to 1 at the same time, then they must have 2 or more decimals, otherwise any number is OK. Index: contextABCD.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextABCD.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/contextABCD.pl -Lmacros/contextABCD.pl -u -r1.11 -r1.12 --- macros/contextABCD.pl +++ macros/contextABCD.pl @@ -10,8 +10,8 @@ There are two contexts defined here, - Context("ABCD"); - Context("ABCD-List"); + Context("ABCD"); + Context("ABCD-List"); The second allows the students to enter lists of strings, while the first does not. @@ -20,12 +20,12 @@ via the Context()->strings->add() and Context()-strings->remove() methods, eg. - Context("ABCD-List")->strings->add(E=>{},e=>{alias=>"E"}); + Context("ABCD-List")->strings->add(E=>{},e=>{alias=>"E"}); Use string_cmp() to produce the answer checker(s) for your correct values. Eg. - ANS(string_cmp("A","B")); + ANS(string_cmp("A","B")); when there are two answers, the first being "A" and the second being "B". Index: answerHints.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/answerHints.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -Lmacros/answerHints.pl -Lmacros/answerHints.pl -u -r1.4 -r1.5 --- macros/answerHints.pl +++ macros/answerHints.pl @@ -66,25 +66,25 @@ Example: - ANS(Vector(1,2,3)->cmp(showCoordinateHints=>0)->withPostFilter(AnswerHints( - Vector(0,0,0) => "The zero vector is not a valid solution", - "-<1,2,3>" => "Try the opposite direction", - "<1,2,3>" => "Well done!", - ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", - sub { - my ($correct,$student,$ans) = @_; - return $correct . $student == 0; - } => "Your answer is perpendicular to the correct one", - Vector(1,2,3) => [ - "You have the right direction, but not length", - cmp_options => [parallel=>1], - ], - 0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], - sub { - my ($correct,$student,$ans) = @_; - return norm($correct-$student) < .1; - } => ["Close! Keep trying.", score => .25], - ))); + ANS(Vector(1,2,3)->cmp(showCoordinateHints=>0)->withPostFilter(AnswerHints( + Vector(0,0,0) => "The zero vector is not a valid solution", + "-<1,2,3>" => "Try the opposite direction", + "<1,2,3>" => "Well done!", + ["<1,1,1>","<2,2,2>","<3,3,3>"] => "Don't just guess!", + sub { + my ($correct,$student,$ans) = @_; + return $correct . $student == 0; + } => "Your answer is perpendicular to the correct one", + Vector(1,2,3) => [ + "You have the right direction, but not length", + cmp_options => [parallel=>1], + ], + 0 => ["Careful, your answer should be a vector!", checkTypes => 0, replaceMessage => 1], + sub { + my ($correct,$student,$ans) = @_; + return norm($correct-$student) < .1; + } => ["Close! Keep trying.", score => .25], + ))); =cut Index: contextLimitedPowers.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPowers.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/contextLimitedPowers.pl -Lmacros/contextLimitedPowers.pl -u -r1.11 -r1.12 --- macros/contextLimitedPowers.pl +++ macros/contextLimitedPowers.pl @@ -8,17 +8,17 @@ the base or power that is allowed. There are four available restrictions: - No raising e to a power - Only allowing integer powers (positive or negative) - Only allowing positive interger powers - Only allowing positive interger powers (and 0) + No raising e to a power + Only allowing integer powers (positive or negative) + Only allowing positive interger powers + Only allowing positive interger powers (and 0) You install these via one of the commands: - LimitedPowers::NoBaseE(); - LimitedPowers::OnlyIntegers(); - LimitedPowers::OnlyPositiveIntegers(); - LimitedPowers::OnlyNonNegativeIntegers(); + LimitedPowers::NoBaseE(); + LimitedPowers::OnlyIntegers(); + LimitedPowers::OnlyPositiveIntegers(); + LimitedPowers::OnlyNonNegativeIntegers(); Only one of the three can be in effect at a time; setting a second one overrides the first. @@ -26,8 +26,8 @@ These function affect the current context, or you can pass a context reference, as in - $context = Context("Numeric")->copy; - LimitedPowers::OnlyIntegers($context); + $context = Context("Numeric")->copy; + LimitedPowers::OnlyIntegers($context); For the Interger power functions, you can pass additional parameters that control the range of values that are allowed Index: contextTF.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextTF.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -Lmacros/contextTF.pl -Lmacros/contextTF.pl -u -r1.12 -r1.13 --- macros/contextTF.pl +++ macros/contextTF.pl @@ -7,7 +7,7 @@ Implements contexts for string-valued answers especially for matching problems (where you match against T and F). - Context("TF"); + Context("TF"); You can add new strings to the context as needed (or remove old ones) via the Context()->strings->add() and Context()-strings->remove() @@ -15,7 +15,7 @@ Use: - ANS(string_cmp("T","F")); + ANS(string_cmp("T","F")); when there are two answers, the first being "T" and the second being "F". Index: problemRandomize.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/problemRandomize.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/problemRandomize.pl -Lmacros/problemRandomize.pl -u -r1.9 -r1.10 --- macros/problemRandomize.pl +++ macros/problemRandomize.pl @@ -100,11 +100,11 @@ Examples: - ProblemRandomize(); # use all defaults - ProblemRandomize(when=>"Always"); # always can reseed (after due date) + ProblemRandomize(); # use all defaults + ProblemRandomize(when=>"Always"); # always can reseed (after due date) ProblemRandomize(onlyAfterDue=>0); # can reseed whenever correct ProblemRandomize(when=>"always",onlyAfterDue=>0); # always can reseed - ProblemRandomize(style=>"Input"); # use an input box to set the seed + ProblemRandomize(style=>"Input"); # use an input box to set the seed For problems that include "PGcourse.pl" in their loadMacros() calls, you can use that file to provide reseed buttons for ALL problems simply by including Index: parserFunction.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFunction.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/parserFunction.pl -Lmacros/parserFunction.pl -u -r1.10 -r1.11 --- macros/parserFunction.pl +++ macros/parserFunction.pl @@ -13,14 +13,14 @@ students in their answers), use the parserFunction() routine, as in the following examples: - parserFunction(f => "sqrt(x+1)-2"); + parserFunction(f => "sqrt(x+1)-2"); - $x = Formula('x'); - parserFunction(f => sqrt($x+1)-2); + $x = Formula('x'); + parserFunction(f => sqrt($x+1)-2); - parserFunction("f(x)" => "sqrt(x+1)-2"); + parserFunction("f(x)" => "sqrt(x+1)-2"); - parserFunction("f(x,y)" => "sqrt(x*y)"); + parserFunction("f(x,y)" => "sqrt(x*y)"); The first parameter to parserFunction is the name of the function or the name with its argument list. In the first case, the Index: contextIntegerFunctions.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextIntegerFunctions.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/contextIntegerFunctions.pl -Lmacros/contextIntegerFunctions.pl -u -r1.9 -r1.10 --- macros/contextIntegerFunctions.pl +++ macros/contextIntegerFunctions.pl @@ -15,11 +15,11 @@ =head1 USAGE - Context("IntegerFunctions") - - $b = random(2, 5); $a = $b+random(0, 5); - $c = C($a, $b); - ANS(Compute("P($a, $b)")->cmp); + Context("IntegerFunctions") + + $b = random(2, 5); $a = $b+random(0, 5); + $c = C($a, $b); + ANS(Compute("P($a, $b)")->cmp); B<Note:> If the context is set to something else, such as Numeric, it can be set back with Context("IntegerFunctions"). Index: contextLimitedPolynomial.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPolynomial.pl,v retrieving revision 1.15 retrieving revision 1.16 diff -Lmacros/contextLimitedPolynomial.pl -Lmacros/contextLimitedPolynomial.pl -u -r1.15 -r1.16 --- macros/contextLimitedPolynomial.pl +++ macros/contextLimitedPolynomial.pl @@ -9,17 +9,17 @@ Select the context using: - Context("LimitedPolynomial"); + Context("LimitedPolynomial"); If you set the "singlePowers" flag, then only one monomial of each degree can be included in the polynomial: - Context("LimitedPolynomial")->flags->set(singlePowers=>1); + Context("LimitedPolynomial")->flags->set(singlePowers=>1); There is also a strict limited context that does not allow operations even within the coefficients. Select it using: - Context("LimitedPolynomial-Strict"); + Context("LimitedPolynomial-Strict"); In addition to disallowing operations within the coefficients, this context does not reduce constant operations (since they are Index: parserAutoStrings.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserAutoStrings.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -Lmacros/parserAutoStrings.pl -Lmacros/parserAutoStrings.pl -u -r1.2 -r1.3 --- macros/parserAutoStrings.pl +++ macros/parserAutoStrings.pl @@ -10,8 +10,8 @@ To acocmplish this, put the lines - loadMacros("parserAutoStrings.pl"); - AutoStrings(); + loadMacros("parserAutoStrings.pl"); + AutoStrings(); (You can also pass AutoStrings a context pointer if you wish to alter context other than the current one.) @@ -19,8 +19,8 @@ There is also a routine to help making strings easier to predefine. For example: - loadMacros("parserAutoStrings.pl"); - DefineStrings("string1","string2"); + loadMacros("parserAutoStrings.pl"); + DefineStrings("string1","string2"); would define two new strings (string1 and string2). You can pass a context reference as the first argument to add strings to that Index: parserFormulaUpToConstant.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFormulaUpToConstant.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -Lmacros/parserFormulaUpToConstant.pl -Lmacros/parserFormulaUpToConstant.pl -u -r1.8 -r1.9 --- macros/parserFormulaUpToConstant.pl +++ macros/parserFormulaUpToConstant.pl @@ -13,11 +13,11 @@ To use FormulaWithConstat objects, load this macro file at the top of your problem: - loadMacros("parserFormulaUpToConstant.pl"); + loadMacros("parserFormulaUpToConstant.pl"); then create a formula with constant as follows: - $f = FormulaUpToConstant("sin(x)+C"); + $f = FormulaUpToConstant("sin(x)+C"); Note that the C should NOT already be a variable in the Context; the FormulaUpToConstant object will handle adding it in for @@ -28,7 +28,7 @@ The FormulaUpToConstant should work like any normal Formula, and in particular, you use $f->cmp to get its answer checker. - ANS($f->cmp); + ANS($f->cmp); Note that the FormulaUpToConstant object creates its only private copy of the current Context (so that it can add variables without @@ -36,19 +36,19 @@ in general, but if you need to access that context, use $f->{context}. E.g. - Context($f->{context}); + Context($f->{context}); would make the current context the one being used by the FormulaUpToConstant, while - $f->{context}->variables->names + $f->{context}->variables->names would return a list of the variables in the private context. To get the name of the constant in use in the formula, use - $f->constant. + $f->constant. If you combine a FormulaUpToConstant with other formulas, the result will be a new FormulaUpToConstant object, with @@ -58,16 +58,16 @@ then convert back to a FormulaUpToConstant, if necessary. To do this, use the removeConstant() method: - $f = FormulaUpToConstant("sin(x)+C"); - $g = Formula("cos(x)"); - $h = $f->removeConstant + $g; # $h will be "sin(x)+cos(x)" - $h = FormulaUpToConstant($h); # $h will be "sin(x)+cos(x)+C" + $f = FormulaUpToConstant("sin(x)+C"); + $g = Formula("cos(x)"); + $h = $f->removeConstant + $g; # $h will be "sin(x)+cos(x)" + $h = FormulaUpToConstant($h); # $h will be "sin(x)+cos(x)+C" The answer evaluator by default will give "helpful" messages to the student when the "+ C" is left out. You can turn off these messages using the showHints option to the cmp() method: - ANS($f->cmp(showHints => 0)); + ANS($f->cmp(showHints => 0)); One of the hints is about whether the student's answer is linear in the arbitrary constant. This test requires differentiating @@ -75,7 +75,7 @@ problematic, you can disable that test via the showLinearityHints flag. (Note: setting showHints to 0 also disables these hints.) - ANS($f->cmp(showLinearityHints => 0)); + ANS($f->cmp(showLinearityHints => 0)); =cut |