From: Sam H. v. a. <we...@ma...> - 2007-10-02 20:55:52
|
Log Message: ----------- improved formatting for docs -- these were in pod sections but were all formatted as verbatim sections, and i moved them into normal paragraphs, lists, etc. should make things more readable from the web. Modified Files: -------------- pg/macros: answerComposition.pl answerCustom.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 parserDifferenceQuotient.pl parserFormulaUpToConstant.pl parserFormulaWithUnits.pl parserFunction.pl Revision Data ------------- Index: contextLimitedPoint.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPoint.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextLimitedPoint.pl -Lmacros/contextLimitedPoint.pl -u -r1.10 -r1.11 --- macros/contextLimitedPoint.pl +++ macros/contextLimitedPoint.pl @@ -1,20 +1,22 @@ +=head1 NAME -loadMacros("MathObjects.pl"); +contextLimitedPoint.pl - Allow point entry but no point operations. -sub _contextLimitedPoint_init {LimitedPoint::Init()}; # don't load it again +=head1 DESCRIPTION -=head3 Context("LimitedPoint") +Implements a context in which points can be entered, +but no operations are permitted between points. So +students will be able to perform operations within the +coordinates of the points, but not between points. - ########################################################## - # - # Implements a context in which points can be entered, - # but no operations are permitted between points. So - # students will be able to perform operations within the - # coordinates of the points, but not between points. - # + Context("LimitedPoint") =cut +loadMacros("MathObjects.pl"); + +sub _contextLimitedPoint_init {LimitedPoint::Init()}; # don't load it again + ################################################## # # Handle common checking for BOPs Index: contextString.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextString.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/contextString.pl -Lmacros/contextString.pl -u -r1.11 -r1.12 --- macros/contextString.pl +++ macros/contextString.pl @@ -1,26 +1,27 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextString_init {context::String::Init()}; # don't load it again +contextString.pl - Allow string-valued answers. + +=head1 DESCRIPTION + +Implements contexts for string-valued answers. + +You can add new strings to the context as needed +via the Context()->strings->add() method. E.g., -=head3 Context("String") + Context("String")->strings->add(Foo=>{}, Bar=>{alias=>"Foo"}); - ########################################################## - # - # Implements contexts for string-valued answers. - # - # 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"}); - # - # Use string_cmp() to produce the answer checker(s) for your - # correct values. Eg. - # - # ANS(string_cmp("Foo")); - # +Use string_cmp() to produce the answer checker(s) for your +correct values. Eg. + + ANS(string_cmp("Foo")); =cut +loadMacros("MathObjects.pl"); + +sub _contextString_init {context::String::Init()}; # don't load it again + ################################################## package context::String::Variable; Index: contextLimitedNumeric.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedNumeric.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/contextLimitedNumeric.pl -Lmacros/contextLimitedNumeric.pl -u -r1.7 -r1.8 --- macros/contextLimitedNumeric.pl +++ macros/contextLimitedNumeric.pl @@ -1,26 +1,25 @@ +=head1 NAME -loadMacros("MathObjects.pl"); +contextLimitedNumeric.pl - Allows numeric entry but no operations. + +=head1 DESCRIPTION + +Implements a context in which numbers can be entered, +but no operations are permitted between them. -=head3 Context("LimitedNumeric") +There are two versions: one for lists of numbers +and one for a single number. Select them using +one of the following commands: - ########################################################## - # - # Implements a context in which numbers can be entered, - # but no operations are permitted between them. - # - # There are two versions: one for lists of numbers - # and one for a single number. Select them using - # one of the following commands: - # - # Context("LimitedNumeric-list"); - # Context("LimiteNumeric"); - # - # (Now uses Parcer::Legacy::LimitedNumeric to implement - # these contexts.) + Context("LimitedNumeric-List"); + Context("LimiteNumeric"); + +(Now uses Parcer::Legacy::LimitedNumeric to implement +these contexts.) =cut -################################################## +loadMacros("MathObjects.pl"); sub _contextLimitedNumeric_init { Index: parserDifferenceQuotient.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserDifferenceQuotient.pl,v retrieving revision 1.11 retrieving revision 1.12 diff -Lmacros/parserDifferenceQuotient.pl -Lmacros/parserDifferenceQuotient.pl -u -r1.11 -r1.12 --- macros/parserDifferenceQuotient.pl +++ macros/parserDifferenceQuotient.pl @@ -1,41 +1,41 @@ +=head1 NAME -loadMacros('MathObjects.pl'); - -sub _parserDifferenceQuotient_init {DifferenceQuotient::Init()}; # don't reload this file +parserDifferenceQuotient.pl - An answer checker for difference quotients. =head1 DESCRIPTION - ###################################################################### - # - # This is a Parser class that implements an answer checker for - # difference quotients as a subclass of the Formula class. The - # standard ->cmp routine will work for this. The difference quotient - # is just a special type of formula with a special variable - # for 'dx'. The checker will give an error message if the - # student's result contains a dx in the denominator, meaning it - # is not fully reduced. - # - # Use DifferenceQuotient(formula) to create a difference equation - # object. If the context has more than one variable, the last one - # alphabetically is used to form the dx. Otherwise, you can specify - # the variable used for dx as the second argument to - # DifferenceQuotient(). You could use a variable like h instead of - # dx if you prefer. - # - # Usage examples: - # - # $df = DifferenceQuotient("2x+dx"); - # 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); - # +This is a Parser class that implements an answer checker for +difference quotients as a subclass of the Formula class. The +standard ->cmp routine will work for this. The difference quotient +is just a special type of formula with a special variable +for 'dx'. The checker will give an error message if the +student's result contains a dx in the denominator, meaning it +is not fully reduced. + +Use DifferenceQuotient(formula) to create a difference equation +object. If the context has more than one variable, the last one +alphabetically is used to form the dx. Otherwise, you can specify +the variable used for dx as the second argument to +DifferenceQuotient(). You could use a variable like h instead of +dx if you prefer. + +Usage examples: + + $df = DifferenceQuotient("2x+dx"); + 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); =cut +loadMacros('MathObjects.pl'); + +sub _parserDifferenceQuotient_init {DifferenceQuotient::Init()}; # don't reload this file + package DifferenceQuotient; our @ISA = qw(Value::Formula); Index: contextLimitedVector.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedVector.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/contextLimitedVector.pl -Lmacros/contextLimitedVector.pl -u -r1.9 -r1.10 --- macros/contextLimitedVector.pl +++ macros/contextLimitedVector.pl @@ -1,34 +1,35 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextLimitedVector_init {LimitedVector::Init()}; # don't load it again +contextLimitedVector.pl - Allow vector entry but now vector operations. -=head3 Context("LimitedVector") +=head1 DESCRIPTION - ########################################################## - # - # Implements a context in which vectors can be entered, - # but no vector operations are permitted. So students will - # be able to perform operations within the coordinates - # of the vectors, but not between vectors. - # - # Vectors can still be entered either in < , , > or ijk format. - # Most of the complication here is to handle ijk format - # properly. Each coordinate vector is allowed to appear - # only once, so we have to keep track of that, and allow - # SOME vector operations, but only when one term is - # one of the coordinate constants, or one of the formulas - # we've already OKed. - # - # 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 - # +Implements a context in which vectors can be entered, +but no vector operations are permitted. So students will +be able to perform operations within the coordinates +of the vectors, but not between vectors. + +Vectors can still be entered either in < , , > or ijk format. +Most of the complication here is to handle ijk format +properly. Each coordinate vector is allowed to appear +only once, so we have to keep track of that, and allow +SOME vector operations, but only when one term is +one of the coordinate constants, or one of the formulas +we've already OKed. + +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 =cut +loadMacros("MathObjects.pl"); + +sub _contextLimitedVector_init {LimitedVector::Init()}; # don't load it again + ################################################## # # Handle common checking for BOPs Index: parserFormulaWithUnits.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFormulaWithUnits.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/parserFormulaWithUnits.pl -Lmacros/parserFormulaWithUnits.pl -u -r1.7 -r1.8 --- macros/parserFormulaWithUnits.pl +++ macros/parserFormulaWithUnits.pl @@ -1,38 +1,36 @@ +=head1 NAME -loadMacros('MathObjects.pl'); +parserFormulaWithUnits.pl - Implements a formula with units. =head1 DESCRIPTION - ###################################################################### - # - # This is a Parser class that implements a formula with units. - # It is a temporary version until the Parser can handle it - # directly. - # - # Use FormulaWithUnits("num units") or FormulaWithUnits(formula,"units") - # to generate a FormulaWithUnits object, and then call its cmp() method - # to get an answer checker for your formula with units. - # - # Usage examples: - # - # ANS(FormulaWithUnits("3x+1 ft")->cmp); - # ANS(FormulaWithUnits("$a*x+1 ft")->cmp); - # - # $x = Formula("x"); - # ANS(FormulaWithUnits($a*$x+1,"ft")->cmp); - # - ###################################################################### +This is a Parser class that implements a formula with units. +It is a temporary version until the Parser can handle it +directly. + +Use FormulaWithUnits("num units") or FormulaWithUnits(formula,"units") +to generate a FormulaWithUnits object, and then call its cmp() method +to get an answer checker for your formula with units. + +Usage examples: + + ANS(FormulaWithUnits("3x+1 ft")->cmp); + ANS(FormulaWithUnits("$a*x+1 ft")->cmp); + + $x = Formula("x"); + ANS(FormulaWithUnits($a*$x+1,"ft")->cmp); + +=cut + +loadMacros('MathObjects.pl'); # # Now uses the version in Parser::Legacy::NumberWithUnits # to avoid duplication of common code. # -=cut - sub _parserFormulaWithUnits_init { main::PG_restricted_eval('sub FormulaWithUnits {Parser::Legacy::FormulaWithUnits->new(@_)}'); } 1; - Index: answerComposition.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/answerComposition.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -Lmacros/answerComposition.pl -Lmacros/answerComposition.pl -u -r1.4 -r1.5 --- macros/answerComposition.pl +++ macros/answerComposition.pl @@ -1,47 +1,44 @@ +=head1 NAME +answerComposition.pl - An answer checker that determines if two functions +compose to form a given function. =head1 DESCRIPTION - ###################################################################### - # - # An answer checker that determines if two functions compose - # to form a given function. (For use in problems where you ask - # a student to break a given function into a composition of two - # simpler functions, neither of which is allowed to be the identity - # function.) - # +answerComposition.pl provides an answer checker that determines if two functions +compose to form a given function. This can be used in problems where you ask a +student to break a given function into a composition of two simpler functions, +neither of which is allowed to be the identity function. =cut sub _answerComposition_init {}; # don't reload this file -=head3 COMPOSITION_ANS($fn_f,$fn_g) +=head1 MACROS - ###################################################################### - # - # An answer checked to see if f composed with g matches a given function. - # - # Usage: COMPOSITION_ANS(f,g,options) - # - # where f and g are one possible decomposition of the target function - # (these are used to display the "correct" answer, and the composition - # is computed from them) and options are any of the options allowed - # by composition_ans_list() below. - # - # This function actually supplies TWO answer checkers, for the two - # previous answer blanks. So be sure to call it immediately after - # the answer blanks have been supplied. (It may be best to use the - # NAMED_COMPOSITION_ANS checker below, which specifies the answer - # blanks explicitly.) - # - # Example: - # - # BEGIN_TEXT - # \(f\circ g = (1+x)^2\) when - # \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\} - # END_TEXT - # COMPOSITION_ANS("x^2","1+x"); - # +=head2 COMPOSITION_ANS + + COMPOSITION_ANS($f, $g, %options) + +An answer checked to see if $f composed with $g matches a given function,where +$f and $g are one possible decomposition of the target function, and options are +any of the options allowed by composition_ans_list() below. + +$f and $g are used to display the "correct" answer, and the composition is +computed from them. + +This function actually supplies TWO answer checkers, for the two previous answer +blanks. So be sure to call it immediately after the answer blanks have been +supplied. (It may be best to use the NAMED_COMPOSITION_ANS checker below, which +specifies the answer blanks explicitly.) + +Example: + + BEGIN_TEXT + \(f\circ g = (1+x)^2\) when + \(f(x)\) = \{ans_rule(20)\} and \(g(x)\) = \{ans_rule(20)\} + END_TEXT + COMPOSITION_ANS("x^2","1+x"); =cut @@ -53,56 +50,57 @@ ANS($ans{$fID},$ans{$gID}); } -=head3 NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options) +=head2 NAMED_COMPOSITION_ANS + + NAMED_COMPOSITION_ANS($fID=>$f, $gID=>$g, %options) - ###################################################################### - # - # An answer checked to see if f composed with g matches a given function. - # - # Usage: NAMED_COMPOSITION_ANS(fID=>f,gID=>g,options) - # - # where fID and gID are the names of the answer rules for the functions - # f and g, and f and g are the answers for the functions. Options are - # any of the options allowed by composition_ans_list() below. - # - # This routine allows you to put the f and g answer blanks at any - # location in the problem, and in any order. - # - # Example: - # - # BEGIN_TEXT - # \(g\circ f = (1+x)^2\) when - # \(f(x)\) = \{NAMED_ANS('f',20)\} and \(g(x)\) = \{NAMED_ANS('g',20)\} - # END_TEXT - # NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x"); - # +An answer checked to see if $f composed with $g matches a given function, where +$fID and $gID are the names of the answer rules for the functions $f and $g, and +$f and $g are the answers for the functions. %options are any of the options +allowed by composition_ans_list() below. + +This routine allows you to put the answer blanks for $f and $g at any location +in the problem, and in any order. + +Example: + + BEGIN_TEXT + \(g\circ f = (1+x)^2\) when + \(f(x)\) = \{NAMED_ANS('f',20)\} and \(g(x)\) = \{NAMED_ANS('g',20)\} + END_TEXT + NAMED_COMPOSITION_ANS(f => "x^2", g => "1+x"); =cut sub NAMED_COMPOSITION_ANS {NAMED_ANS(composition_ans_list(@_))} -=head3 composition_ans_list(fID=>f,gID=>g,options) +=head2 composition_ans_list + + composition_ans_list($fID=>$f, $gID=>$g, %options) + +This is an internal routine that returns the named answer checkers +used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above. + +$fID and $gID are the names of the answer rules for the functions and $f and $g +are the answers for these functions. %options are from among: - ###################################################################### - # - # This is an internal routine that returns the named answer checkers - # used by COMPOSITION_ANS and NAMED_COMPOSITION_ANS above. - # - # Usage: composition_ans_list(fID=>f,gID=>g,options) - # - # where fID and gID are the names of the answer rules for the functions - # and f and g are the answers for these functions. Options are from - # among: - # - # var => 'x' the name of the variable to use when - # both functions use the same one - # - # vars => ['x','t'] the names of the variables for f and g - # - # showVariableHints => 1 or 0 - # do/don't show errors when the variable - # used by the student is incorrect - # +=over + +=item S<C<< var => 'x' >>> + +the name of the variable to use when +both functions use the same one + +=item S<C<< vars => ['x','t'] >>> + +the names of the variables for $f and $g + +=item S<C<< showVariableHints => 1 or 0 >>> + +do/don't show errors when the variable +used by the student is incorrect + +=back =cut @@ -197,12 +195,16 @@ return (%ans); } -###################################################################### -# -# Evaluator that always returns incorrect, with a given error -# message. Used by COMPOSITION_ANS to produce "dummy" answer -# checkers for the two parts of the composition. -# +=head2 message_cmp + + message_cmp($correct) + +Returns an answer evaluator that always returns incorrect, with a given error +message. Used by COMPOSITION_ANS to produce "dummy" answer checkers for the two +parts of the composition. + +=cut + sub message_cmp { my $correct = shift; my $answerEvaluator = new AnswerEvaluator; @@ -216,3 +218,4 @@ } 1; + Index: answerVariableList.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/answerVariableList.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/answerVariableList.pl -Lmacros/answerVariableList.pl -u -r1.9 -r1.10 --- macros/answerVariableList.pl +++ macros/answerVariableList.pl @@ -1,36 +1,12 @@ -loadMacros('MathObjects.pl'); - -=head1 DESCRIPTION +=head1 NAME - ###################################################################### - # - # 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)); - # +answerVariableList.pl - Creates answer checkers that compare the student's +answer to a list of variable names. =cut +loadMacros('MathObjects.pl'); + sub _answerVariableList_init { # # A new context for variable lists @@ -54,10 +30,38 @@ 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 -# -# A shell that calls Formula()->cmp with the right defaults -# sub variable_cmp { Value->Package("Formula")->new(shift)->cmp( ordered => 1, @@ -68,12 +72,18 @@ ); } -# -# Handy routine to set up variables -# +=head2 addVariables + + addVariables(@vars) + +Adds each string in @vars as a varible to the current context. + +=cut + sub addVariables { my $context = Context(); foreach my $v (@_) {$context->variables->add($v=>'Real')} } 1; + Index: contextLimitedComplex.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedComplex.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -Lmacros/contextLimitedComplex.pl -Lmacros/contextLimitedComplex.pl -u -r1.9 -r1.10 --- macros/contextLimitedComplex.pl +++ macros/contextLimitedComplex.pl @@ -1,51 +1,53 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextLimitedComplex_init {LimitedComplex::Init()}; # don't load it again +contextLimitedComplex.pl - Allow complex numbers but not complex operations. + +=head1 DESCRIPTION + +Implements a context in which complex numbers can be entered, +but no complex operations are permitted. So students will +be able to perform operations within the real and imaginary +parts of the complex numbers, but not between complex numbers. + + 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 +to keep track of that, and allow SOME complex operations, +but only when one term is one of these constants (or an expression +involving it that we've already OKed). + +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'); -=head3 Context("LimitedComplex") +The default is 'either'. There are predefined contexts that +already have these values set: - ########################################################## - # - # Implements a context in which complex numbers can be entered, - # but no complex operations are permitted. So students will - # be able to perform operations within the real and imaginary - # parts of the complex numbers, but not between complex numbers. - # - # - # 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 - # to keep track of that, and allow SOME complex operations, - # but only when one term is one of these constants (or an expression - # involving it that we've already OKed). - # - # 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'); - # - # The default is 'either'. There are predefined contexts that - # already have these values set: - # - # 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'); - # - # There are predefined contexts that already have these values - # set: - # - # Context("LimitedComplex-cartesian-strict"); - # Context("LimitedComplex-polar-strict"); - # Context("LimitedComplex-strict"); - # + 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'); + +There are predefined contexts that already have these values +set: + + Context("LimitedComplex-cartesian-strict"); + Context("LimitedComplex-polar-strict"); + Context("LimitedComplex-strict"); =cut +loadMacros("MathObjects.pl"); + +sub _contextLimitedComplex_init {LimitedComplex::Init()}; # don't load it again + ################################################## # # Handle common checking for BOPs Index: contextPeriodic.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextPeriodic.pl,v retrieving revision 1.8 retrieving revision 1.9 diff -Lmacros/contextPeriodic.pl -Lmacros/contextPeriodic.pl -u -r1.8 -r1.9 --- macros/contextPeriodic.pl +++ macros/contextPeriodic.pl @@ -1,23 +1,23 @@ +=head1 NAME -=head1 contextPeriodic.pl +contextPeriodic.pl - Allow for specifying periodic functions. [DEPRECATED] - ###################################################################### - # - # This file is no longer needed, as these features have been added to the - # Real and Complex MathObject classes. - # - # Usage: - # Context("Numeric"); - # $a = Real("pi/2")->with(period=>pi); - # $a->cmp # will match pi/2, 3pi/2 etc. - # - # Usage: - # Context("Complex"); - # $z0 = Real("i^i")->with(period=>2pi, logPeriodic=>1); - # $z0->cmp # will match exp(i*(ln(1) + Arg(pi/2) + 2k pi)) - # - ###################################################################### +=head1 DESCRIPTION + +This file is no longer needed, as these features have been added to the +Real and Complex MathObject classes. + +=head1 USAGE + + 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)) =cut 1; + Index: contextPiecewiseFunction.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextPiecewiseFunction.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -Lmacros/contextPiecewiseFunction.pl -Lmacros/contextPiecewiseFunction.pl -u -r1.4 -r1.5 --- macros/contextPiecewiseFunction.pl +++ macros/contextPiecewiseFunction.pl @@ -1,66 +1,66 @@ -loadMacros("MathObjects.pl"); -loadMacros("contextInequalities.pl"); +=head1 NAME -sub _contextPiecewiseFunction_init {PiecewiseFunction::Init()} +contextPiecewiseFunction.pl - Allow usage of piecewise functions. -=head1 Context("PiecewiseFunction"); +=head1 DESCRIPTION - ###################################################################### - # - # This file implements a context in which piecewise-defined functions - # can be specified by students and problem authors. To use it, add - # - # loadMacros("contextPiecewieFunction.pl"); - # - # and then use - # - # 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"); - # - # You can use either Compute() or Formula() interchangeably to - # convert a string containing "if" and "else" to the corresponding - # PiecewiseFunction. The PiecewiseFunction() constructor can - # also do this, or you can pass it a list of interval=>formula - # pairs that specify the various branches. If there is an - # unpaired final formula, it represents the "otherwise" portion - # of the function (the formula to use of the input is not in - # any of the given intervals). - # - # Note that you can use Inveral, Set, or Union objects in place of - # the intervals in the specification of a piecewise function. - # - # The PiecewiseFunction object TeXifies using a LaTeX "cases" - # environment, so you can use these objects to produce nice - # 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); - # - ###################################################################### +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"); + +and then use + + 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"); + +You can use either Compute() or Formula() interchangeably to +convert a string containing "if" and "else" to the corresponding +PiecewiseFunction. The PiecewiseFunction() constructor can +also do this, or you can pass it a list of interval=>formula +pairs that specify the various branches. If there is an +unpaired final formula, it represents the "otherwise" portion +of the function (the formula to use of the input is not in +any of the given intervals). + +Note that you can use Inveral, Set, or Union objects in place of +the intervals in the specification of a piecewise function. + +The PiecewiseFunction object TeXifies using a LaTeX "cases" +environment, so you can use these objects to produce nice +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); =cut +loadMacros("MathObjects.pl"); +loadMacros("contextInequalities.pl"); + +sub _contextPiecewiseFunction_init {PiecewiseFunction::Init()} + package PiecewiseFunction; # Index: contextInequalities.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextInequalities.pl,v retrieving revision 1.13 retrieving revision 1.14 diff -Lmacros/contextInequalities.pl -Lmacros/contextInequalities.pl -u -r1.13 -r1.14 --- macros/contextInequalities.pl +++ macros/contextInequalities.pl @@ -1,63 +1,66 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextInequalities_init {Inequalities::Init()} +Context("Inequalities"), Context("Inequalities-Only") - Provides contexts that +allow intervals to be specified as inequalities. -=head1 Context("Inequalities"), Context("Inequalities-Only") +=head1 DESCRIPTION - ######################################################################### - # - # Implements contexts that provides for inequalities that produce - # the cooresponding Interval, Set or Union MathObjects. There are - # two such contexts: Context("Inequalities"), in which both - # intervals and inequalities are defined, and Context("Inequalities-Only"), - # which allows only inequalities as a means of producing intervals. - # - # 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 - # - # You can set the "noneWord" flag to specify the string to - # use when the inequalities specify the empty set. By default, - # it is "NONE", but you can change it to other strings. Be sure - # 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"); - # - # creates an empty set as a named constant and uses that name. - # - # Inequalities and interval notation both can coexist side by - # side, but you may wish to convert from one to the other. - # Use Inequality() to convert from an Interval, Set or Union - # to an Inequality, and use Interval(), Set(), or Union() to - # 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 < 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 - # above. - # - ###################################################################### +Implements contexts that provides for inequalities that produce +the cooresponding Interval, Set or Union MathObjects. There are +two such contexts: Context("Inequalities"), in which both +intervals and inequalities are defined, and Context("Inequalities-Only"), +which allows only inequalities as a means of producing intervals. + +=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 + +You can set the "noneWord" flag to specify the string to +use when the inequalities specify the empty set. By default, +it is "NONE", but you can change it to other strings. Be sure +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"); + +creates an empty set as a named constant and uses that name. + +Inequalities and interval notation both can coexist side by +side, but you may wish to convert from one to the other. +Use Inequality() to convert from an Interval, Set or Union +to an Inequality, and use Interval(), Set(), or Union() to +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 < 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 +above. =cut +loadMacros("MathObjects.pl"); + +sub _contextInequalities_init {Inequalities::Init()} + package Inequalities; # Index: contextScientificNotation.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextScientificNotation.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/contextScientificNotation.pl -Lmacros/contextScientificNotation.pl -u -r1.7 -r1.8 --- macros/contextScientificNotation.pl +++ macros/contextScientificNotation.pl @@ -1,98 +1,99 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextScientificNotation_init {ScientificNotation::Init()} +contextScientificNotation.pl - Allows entry of scientific notation. + +=head1 DESCRIPTION + +This file implements a context in which students can enter +answers in scientific notation. It tries hard to report +useful error messages when the student's answer is not +in the proper format, and it also allows you to control +how many decimal digits they are allowed/required to +enter, and how many the system will display. + +This probably should be called LimitedScientificNotation +since it does not allow any operations other than the ones +needed in Scientific notation. In the future it may be +renamed if we produce a computational scientific notation +context. + +To use this context, add + + loadMacros("contextScientificNotation.pl"); + +to the top of your problem file, and then use + + 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"); + +or + + $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, -=head1 Context("ScientificNotation"); + Context()->flags->set(snDigits=>2); - ######################################################################### - # - # This file implements a context in which students can enter - # answers in scientific notation. It tries hard to report - # useful error messages when the student's answer is not - # in the proper format, and it also allows you to control - # how many decimal digits they are allowed/required to - # enter, and how many the system will display. - # - # This probably should be called LimitedScientificNotation - # since it does not allow any operations other than the ones - # needed in Scientific notation. In the future it may be - # renamed if we produce a computational scientific notation - # context. - # - # To use this context, add - # - # loadMacros("contextScientificNotation.pl"); - # - # to the top of your problem file, and then use - # - # 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"); - # - # or - # - # $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); - # - # 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); - # - # It is also possible to specify how many decimal digits the - # student must enter. For example, - # - # 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, - # including the one to the left of the decimal). The default - # is 1 digit beyond the decimal. A value of 0 means that - # a decimal point and decimal values is optional. - # - # Similarly, - # - # 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 - # are allowed, effectively meaning students can only enter - # the numbers 0 through 9 (times a power of 10). Setting - # this to a negative number means that there is no upper - # limit on the number of digits the student may enter (this - # is the default). - # - # 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, - # ); - # - # Note that if you restrict the number of digits, you may - # need to adjust the tolerance values since the student - # may not be allowed to enter a more precise answer. In - # the example above, it would be appropriate to set the - # tolerance to .0001 and the tolType to "relative" in - # order to require the answers to be correct to the three - # digits that are shown. - # +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); + +It is also possible to specify how many decimal digits the +student must enter. For example, + + 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, +including the one to the left of the decimal). The default +is 1 digit beyond the decimal. A value of 0 means that +a decimal point and decimal values is optional. + +Similarly, + + 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 +are allowed, effectively meaning students can only enter +the numbers 0 through 9 (times a power of 10). Setting +this to a negative number means that there is no upper +limit on the number of digits the student may enter (this +is the default). + +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, + ); + +Note that if you restrict the number of digits, you may +need to adjust the tolerance values since the student +may not be allowed to enter a more precise answer. In +the example above, it would be appropriate to set the +tolerance to .0001 and the tolType to "relative" in +order to require the answers to be correct to the three +digits that are shown. =cut +loadMacros("MathObjects.pl"); + +sub _contextScientificNotation_init {ScientificNotation::Init()} + package ScientificNotation; # Index: contextCurrency.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextCurrency.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextCurrency.pl -Lmacros/contextCurrency.pl -u -r1.10 -r1.11 --- macros/contextCurrency.pl +++ macros/contextCurrency.pl @@ -1,129 +1,126 @@ -loadMacros("MathObjects.pl"); -loadMacros("problemPreserveAnswers.pl"); # needed to preserve $ in answers +=head1 Context("Currency"); -sub _contextCurrency_init {Currency::Init()} +##################################################################### -=head1 Context("Currency"); +This file implements a context in which students can enter currency +values that include a currency symbol and commas every three digits. +You can specify what the currency symbol is, as well as what gets +used for commas and decimals. + +To use the context, put + + loadMacros("contextCurrency.pl"); + +at the top of your problem file, and then issue the + + 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' + +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"); + +would accept '$12,345.67' or '12.50 dollars' or '1 dollar' as +acceptable values. Note that if the symbol cantains any +alphabetic characters, it is expected to come at the end of the +number (as in the examples above) and if the symbol has only +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"}); + +You can remove a symbol as follows: + + Context()->currency->removeSymbol('dollar'); + +To create a currency value, use + + $m = Currency(10.99); + +or + + $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"); - ###################################################################### - # - # This file implements a context in which students can enter currency - # values that include a currency symbol and commas every three digits. - # You can specify what the currency symbol is, as well as what gets - # used for commas and decimals. - # - # To use the context, put - # - # loadMacros("contextCurrency.pl"); - # - # at the top of your problem file, and then issue the - # - # 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' - # - # 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"); - # - # would accept '$12,345.67' or '12.50 dollars' or '1 dollar' as - # acceptable values. Note that if the symbol cantains any - # alphabetic characters, it is expected to come at the end of the - # number (as in the examples above) and if the symbol has only - # 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"}); - # - # You can remove a symbol as follows: - # - # Context()->currency->removeSymbol('dollar'); - # - # To create a currency value, use - # - # $m = Currency(10.99); - # - # or - # - # $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"); - # - # 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 - # a variable, and will substitute that into the string before - # processing it. Since that variable is most likely empty, the - # result will be the same as $m = Compute(".99"); - # - # 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'); - # - # so that $m2 will be $30.00, $m3 will be $30.50, and $m4 will - # be $12.59. Students can perform computations within their - # answers unless you disable the operators and functions as well. - # - # The tolerance for this context is set initially to .005 and the - # tolType to 'absolute' so that monitary values will have to match - # to the nearest penny. You can change that on a global basis - # using - # - # 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'); - # - # 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)); - # - # would allow the student to enter just 150 rather than $150. - # - # By default, the students may omit the commas, but you can - # force them to supply the commas using forceCommas=>1 in - # your cmp() call. - # - # 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)); - # - # 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); - # - # If forceDecimals is set to 1 at the same time, then they must - # have 2 or more decimals, otherwise any number is OK. - # - ###################################################################### +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 +a variable, and will substitute that into the string before +processing it. Since that variable is most likely empty, the +result will be the same as $m = Compute(".99"); + +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'); + +so that $m2 will be $30.00, $m3 will be $30.50, and $m4 will +be $12.59. Students can perform computations within their +answers unless you disable the operators and functions as well. + +The tolerance for this context is set initially to .005 and the +tolType to 'absolute' so that monitary values will have to match +to the nearest penny. You can change that on a global basis +using + + 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'); + +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)); + +would allow the student to enter just 150 rather than $150. + +By default, the students may omit the commas, but you can +force them to supply the commas using forceCommas=>1 in +your cmp() call. + + 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)); + +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); + +If forceDecimals is set to 1 at the same time, then they must +have 2 or more decimals, otherwise any number is OK. =cut +loadMacros("MathObjects.pl"); +loadMacros("problemPreserveAnswers.pl"); # needed to preserve $ in answers + +sub _contextCurrency_init {Currency::Init()} + package Currency; # Index: contextABCD.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextABCD.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextABCD.pl -Lmacros/contextABCD.pl -u -r1.10 -r1.11 --- macros/contextABCD.pl +++ macros/contextABCD.pl @@ -1,37 +1,38 @@ -loadMacros("MathObjects.pl","contextString.pl"); +=head1 NAME + +contextABCD.pl - Contexts for matching problems. =head1 DESCRIPTION - ########################################################## - # - # Implements contexts for string-valued answers especially - # for matching problems (where you match against A, B, C, D, - # and so on). - # - # There are two contexts defined here, - # - # Context("ABCD"); - # Context("ABCD-List"); - # - # The second allows the students to enter lists of strings, - # while the first does not. - # - # You can add new strings to the context as needed (or remove old ones) - # via the Context()->strings->add() and Context()-strings->remove() - # methods, eg. - # - # 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")); - # - # when there are two answers, the first being "A" and the second being "B". - # +Implements contexts for string-valued answers especially +for matching problems (where you match against A, B, C, D, +and so on). + +There are two contexts defined here, + + Context("ABCD"); + Context("ABCD-List"); + +The second allows the students to enter lists of strings, +while the first does not. + +You can add new strings to the context as needed (or remove old ones) +via the Context()->strings->add() and Context()-strings->remove() +methods, eg. + + 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")); + +when there are two answers, the first being "A" and the second being "B". =cut +loadMacros("MathObjects.pl","contextString.pl"); + sub _contextABCD_init { my $context = $main::context{ABCD} = Parser::Context->getCopy("String"); $context->{name} = "ABCD"; Index: contextLimitedPowers.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/contextLimitedPowers.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -Lmacros/contextLimitedPowers.pl -Lmacros/contextLimitedPowers.pl -u -r1.10 -r1.11 --- macros/contextLimitedPowers.pl +++ macros/contextLimitedPowers.pl @@ -1,89 +1,93 @@ -loadMacros("MathObjects.pl"); +=head1 NAME -sub _contextLimitedPowers_init {}; # don't load it again +contextLimitedPowers.pl - Restrict the base or power allowed in exponentials. + +=head1 DESCRIPTION + +Implements subclasses of the "^" operator that restrict +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) + +You install these via one of the commands: + + 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. + +These function affect the current context, or you can pass +a context reference, as in + + $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 +for the powers. The oprtions include: + +=over + +=item S<C<< minPower => m >>> -=head3 LimitedPowers::NoBaseE(); +only integer powers bigger than or equal +to m are allowed. (If m is undef, then +there is no minimum power.) -=head3 LimitedPowers::OnlyIntegers(); +=item S<C<< maxPower => M >>> -=head3 LimitedPowers::OnlyNonNegativeIntegers(); +only integer powers less than or equal +to M are allowed. (If M is undef, then +there is no maximum power.) -=head3 LimitedPowers::OnlyPositiveIntegers(); +=item S<C<< message => "text" >>> -=head3 LimitedPowers::OnlyNonTrivialPositiveIntegers(); - - ########################################################## - # - # Implements subclasses of the "^" operator that restrict - # 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) - # - # You install these via one of the commands: - # - # 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. - # - # These function affect the current context, or you can pass - # a context reference, as in - # - # $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 - # for the powers. The oprtions include: - # - # minPower => m only integer powers bigger than or equal - # to m are allowed. (If m is undef, then - # there is no minimum power.) - # - # maxPower => M only integer powers l... [truncated message content] |