From: Sam H. v. a. <we...@ma...> - 2007-10-25 17:20:13
|
Log Message: ----------- new/improved documentation Modified Files: -------------- pg/macros: IO.pl LinearProgramming.pl MathObjects.pl PG.pl Parser.pl extraAnswerEvaluators.pl Revision Data ------------- Index: Parser.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/Parser.pl,v retrieving revision 1.13 retrieving revision 1.14 diff -Lmacros/Parser.pl -Lmacros/Parser.pl -u -r1.13 -r1.14 --- macros/Parser.pl +++ macros/Parser.pl @@ -1,14 +1,30 @@ +################################################################################ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader$ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. +################################################################################ +=head1 NAME -=head1 DESCRIPTION - - ########################################################################### - ## - ## Set up the functions needed by the Parser. - ## +Parser.pl - Macro-based fronted to the MathObjects system. =cut +########################################################################### +## +## Set up the functions needed by the Parser. +## + if (!$Parser::installed) { die "\n************************************************************\n" . "* This problem requires the Parser.pm package, which doesn't\n". @@ -27,41 +43,39 @@ loadMacros("Value.pl"); loadMacros("PGcommonFunctions.pl"); -=head3 Formula("formula") +=head1 MACROS - # - # The main way to get a MathObject Formula object (an equation - # that depends on one or more variables). - # +=head1 Formula -=cut + Formula("formula"); + +The main way to get a MathObject Formula object (an equation that depends on one +or more variables). +=cut sub Formula {Value->Package("Formula()")->new(@_)} +=head2 Compute + + Compute("formula"[, var=>value, ...]); + +Compute the value of a formula and return a MathObject appropriate to its +value. Set the object so that the correct answer will be shown exatly as in the +given string rather than by its usual stringification. If the value is a +Formula and any var=>value pairs are specified, then the formula will be +evaluated using the given variable values. E.g., + + $x = Compute("x+3",x=>2) + +will produce the equivalent of $x = Real(5). +The original parsed formula will be saved in the object's original_formula +field, and can be obtained by -=head3 Compute("formula"[,var=>value,...]) + $x->{original_formula}; - # - # Compute the value of a formula and return a MathObject appropriate - # to its value. Set the object so that the correct answer will be - # shown exatly as in the given string rather than by its usual - # stringification. If the value is a Formula and any var=>value - # pairs are specified, then the formula will be evaluated using - # the given variable values. E.g., - # - # $x = Compute("x+3",x=>2) - # - # will produce the equivalent of $x = Real(5). - # - # The original parsed formula will be saved in the object's - # original_formula field, and can be obtained by - # - # $x->{original_formula}; - # - # if needed later in the problem. - # +if needed later in the problem. =cut @@ -78,14 +92,16 @@ return $formula; } -=head3 Context(), Context(name) or Context(context) +=head2 Context - # - # Set or get the current context. When a name is given, the context - # with that name is selected as the current context. When a context - # reference is provided, that context is set as the current one. In - # all three cases, the current context (after setting) is returned. - # + Context(); + Context($name); + Context($context); + +Set or get the current context. When a name is given, the context with that +name is selected as the current context. When a context reference is provided, +that context is set as the current one. In all three cases, the current context +(after setting) is returned. =cut Index: IO.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/IO.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/IO.pl -Lmacros/IO.pl -u -r1.7 -r1.8 --- macros/IO.pl +++ macros/IO.pl @@ -1,15 +1,26 @@ - ################################################################################ -# WeBWorK mod-perl (c) 2000-2002 WeBWorK Project -# $Id$ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader$ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. ################################################################################ =head1 NAME -IO.pl - Temporary location for IO functions that need access to the problem -environment. Formerly defined in IO.pm +IO.pl - Input/optput macros that require access to the problem environment. + +=head1 DESCRIPTION -See notes in Translator.pm +See notes in L<WeBWorK::PG::Translator>. =cut @@ -22,6 +33,18 @@ ); } +=head1 MACROS + +=head2 [DEPRECATED] send_mail_to + + send_mail_to($address, subject=>$subject, body=>$body) + +Send an email message with the subject $subject and body $body to the address +$address. This used to be used by mail_answers_to in PGbasicmacros.pl, but it no +longer is. Don't use this, I tell yah! + +=cut + # send_mail_to($user_address,'subject'=>$subject,'body'=>$body) sub send_mail_to { my $user_address = shift; # user must be an instructor @@ -80,29 +103,28 @@ return $out; } -sub getCourseTempDirectory { - return $envir{tempDirectory}; -} +=head2 getCourseTempDirectory -=head2 surePathToTmpFile + $path = getCourseTempDirectory() - surePathToTmpFile($path) - Returns: $path +Returns the path to the current course's temporary directory. -Defined in FILE.pl +=cut -Creates all of the subdirectories between the directory specified -by C<&getCourseTempDirectory> and the address of the path. +sub getCourseTempDirectory { + return $envir{tempDirectory}; +} -Uses +=head2 surePathToTmpFile - &createDirectory($path,$Global::tmp_directory_permission, $Global::numericalGroupID) + $path = surePathToTmpFile($path); -The path may begin with the correct path to the temporary -directory. Any other prefix causes a path relative to the temporary -directory to be created. +Creates all of the intermediate directories between the directory specified by +getCourseTempDirectory() and file specified in $path. -The quality of the error checking could be improved. :-) +If $path begins with the path returned by getCourseTempDirectory(), then the +path is treated as absolute. Otherwise, the path is treated as relative the the +course temp directory. =cut Index: LinearProgramming.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/LinearProgramming.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -Lmacros/LinearProgramming.pl -Lmacros/LinearProgramming.pl -u -r1.1 -r1.2 --- macros/LinearProgramming.pl +++ macros/LinearProgramming.pl @@ -1,62 +1,75 @@ +################################################################################ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader$ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. +################################################################################ =head1 NAME - LinearProgramming.pl +LinearProgramming.pl - Macros for the simplex tableau for linear programming +problems. =head1 SYNPOSIS - Macros related to the simplex method for Linear Programming. +Macros related to the simplex method for Linear Programming. - lp_pivot_element() - find the pivot element from a tableau - lp_solve() - pivot until done - lp_current_value() - given a tableau, find the value of a - requested variable - lp_display() - display a tableau - lp_display_mm() - display a tableau while in math mode - lp_pivot() - perform one pivot on a tableau + lp_pivot_element(...); # find the pivot element from a tableau + lp_solve(...); # pivot until done + lp_current_value(...); # given a tableau, find the value of a requested variable + lp_display(...); # display a tableau + lp_display_mm(...); # display a tableau while in math mode + lp_pivot(...); # perform one pivot on a tableau - Matrix display makes use of macros from PGmatrixmacros.pl, so it - must be included too. +Matrix display makes use of macros from PGmatrixmacros.pl, so it must be +included too. =head1 DESCRIPTION - These are macros for dealing with simplex tableau for linear - programming problems. The tableau is a reference to an array - of arrays, which looks like, [[1,2,3], [4,5,6]]. The entries - can be real numbers or Fractions. - - Tableaus are expected to be legal for the simplex method, such as - - [[0, 3, -4, 5, 1, 0, 0, 28], - [0, 2, 0, 1, 0, 1, 0, 11], - [0, 1, 2, 3, 0, 0, 1, 3], - [1, -1, 2, -3, 0, 0, 0, 0]] +These are macros for dealing with simplex tableau for linear programming +problems. The tableau is a reference to an array of arrays, which looks like, +[[1,2,3], [4,5,6]]. The entries can be real numbers or Fractions. - or something similar which arises after pivoting. +Tableaus are expected to be legal for the simplex method, such as -=cut + [[0, 3, -4, 5, 1, 0, 0, 28], + [0, 2, 0, 1, 0, 1, 0, 11], + [0, 1, 2, 3, 0, 0, 1, 3], + [1, -1, 2, -3, 0, 0, 0, 0]] + +or something similar which arises after pivoting. + +=head1 MACROS =head2 lp_pivot -Take a tableau, the row and column number, and perform one pivot operation. -The tableau can be any matrix in the form reference to array of arrays, such -as [[1,2,3],[4,5,6]]. Row and column numbers start at 0. An optional 4th -argument can be specified to indicate that the matrix has entries of type -Fraction (and then all entries should be of type Fraction). +Take a tableau, the row and column number, and perform one pivot operation. The +tableau can be any matrix in the form reference to array of arrays, such as +[[1,2,3],[4,5,6]]. Row and column numbers start at 0. An optional 4th argument +can be specified to indicate that the matrix has entries of type Fraction (and +then all entries should be of type Fraction). - $m = [[1,2,3],[4,5,6]]; - lp_pivot($m, 0,2); + $m = [[1,2,3],[4,5,6]]; + lp_pivot($m, 0,2); -This function is destructive - it changes the values of its matrix rather -than making a copy, and also returns the matrix, so +This function is destructive - it changes the values of its matrix rather than +making a copy, and also returns the matrix, so - $m = lp_pivot([[1,2,3],[4,5,6]], 0, 2); + $m = lp_pivot([[1,2,3],[4,5,6]], 0, 2); will have the same result as the example above. =cut - # perform a pivot operation # lp_pivot([[1,2,3],...,[4,5,6]], row, col, fractionmode) # row and col indecies start at 0 @@ -96,19 +109,17 @@ =head2 lp_pivot_element -Take a simplex tableau, and determine which element is the next pivot -element based on the algorithm in Mizrahi and Sullivan's Finite -Mathematics, section 4.2. The tableau must represent a point in the -region of feasibility for a LP problem. Otherwise, it can be any -matrix in the form reference to array of arrays, such as -[[1,2,3],[4,5,6]]. An optional 2nd argument can be specified to -indicate that the matrix has entries of type Fraction (and then all -entries should be of type Fraction). - -It returns a pair [row, col], with the count starting at 0. If there -is no legal pivot column (final tableau), it returns [-1,-1]. If -there is a column, but no pivot element (unbounded problem), it returns -[-1, col]. +Take a simplex tableau, and determine which element is the next pivot element +based on the algorithm in Mizrahi and Sullivan's Finite Mathematics, section +4.2. The tableau must represent a point in the region of feasibility for a LP +problem. Otherwise, it can be any matrix in the form reference to array of +arrays, such as [[1,2,3],[4,5,6]]. An optional 2nd argument can be specified to +indicate that the matrix has entries of type Fraction (and then all entries +should be of type Fraction). + +It returns a pair [row, col], with the count starting at 0. If there is no +legal pivot column (final tableau), it returns [-1,-1]. If there is a column, +but no pivot element (unbounded problem), it returns [-1, col]. =cut @@ -154,31 +165,37 @@ =head2 lp_solve -Take a tableau, and perform simplex method pivoting until done. -The tableau can be any matrix in the form reference to array of arrays, such -as [[1,2,3],[4,5,6]], which represents a linear programming tableau at a -feasible point. Options are specified in key/value pairs. - - pivot_limit=> 10 (limit the number of pivots to at most 10 - default is 100) - fraction_mode=> 1 (entries are of type Fraction - defaults to 0, i.e., false) - -This function is destructive - it changes the values of its matrix -rather than making a copy. It returns a triple of the final tableau, -an endcode indicating the type of result, and the number of pivots -used. The endcodes are 1 for success, 0 for unbounded. +Take a tableau, and perform simplex method pivoting until done. The tableau can +be any matrix in the form reference to array of arrays, such as +[[1,2,3],[4,5,6]], which represents a linear programming tableau at a feasible +point. Options are specified in key/value pairs. + +=over + +=item C<S<< pivot_limit => 10 >>> + +limit the number of pivots to at most 10 - default is 100 + +=item C<S<< fraction_mode => 1 >>> + +entries are of type Fraction - defaults to 0, i.e., false + +This function is destructive - it changes the values of its matrix rather than +making a copy. It returns a triple of the final tableau, an endcode indicating +the type of result, and the number of pivots used. The endcodes are 1 for +success, 0 for unbounded. Example: -$m = [[0, 3, -4, 5, 1, 0, 0, 28], - [0, 2, 0, 1, 0, 1, 0, 11], - [0, 1, 2, 3, 0, 0, 1, 3], - [1, -1, 2, -3, 0, 0, 0, 0]]; + $m = [[0, 3, -4, 5, 1, 0, 0, 28], + [0, 2, 0, 1, 0, 1, 0, 11], + [0, 1, 2, 3, 0, 0, 1, 3], + [1, -1, 2, -3, 0, 0, 0, 0]]; -($m, $endcode, $pivcount) = lp_solve($m, pivot_limit=>200); + ($m, $endcode, $pivcount) = lp_solve($m, pivot_limit=>200); =cut - # Solve a linear programming problem # lp_solve([[1,2,3],[4,5,6]]) # It returns a triple of the final tableau, a code to say if we @@ -223,10 +240,10 @@ =head2 lp_current_value Takes a simplex tableau and returns the value of a particular variable. -Variables are associated to column numbers which are indexed starting with -0. So, usually this means that the objective function is 0, x_1 is 1, and -so on. This can be used for slack variables too (assuming you know what -columns they are in). +Variables are associated to column numbers which are indexed starting with 0. +So, usually this means that the objective function is 0, x_1 is 1, and so on. +This can be used for slack variables too (assuming you know what columns they +are in). =cut @@ -267,22 +284,22 @@ Display a simplex tableau while in math mode. -$m = [[0, 3, -4, 5, 1, 0, 0, 28], - [0, 2, 0, 1, 0, 1, 0, 11], - [0, 1, 2, 3, 0, 0, 1, 3], - [1, -1, 2, -3, 0, 0, 0, 0]]; - -\[ \{ lp_display_mm($m) \} \] - -Accepts the same optional arguments as lp_display (see below), and -produces nicer looking results. However, it cannot have answer rules -in the tableau (lp_display can have them for fill in the blank -tableaus). + $m = [[0, 3, -4, 5, 1, 0, 0, 28], + [0, 2, 0, 1, 0, 1, 0, 11], + [0, 1, 2, 3, 0, 0, 1, 3], + [1, -1, 2, -3, 0, 0, 0, 0]]; + + BEGIN_TEXT + \[ \{ lp_display_mm($m) \} \] + END_TEXT + +Accepts the same optional arguments as lp_display (see below), and produces +nicer looking results. However, it cannot have answer rules in the tableau +(lp_display can have them for fill in the blank tableaus). =cut # Display a tableau in math mode - sub lp_display_mm { lp_display(@_, force_tex=>1); } @@ -309,21 +326,21 @@ Display a simplex tableau while not in math mode. -$m = [[0, 3, -4, 5, 1, 0, 0, 28], - [0, 2, 0, 1, 0, 1, 0, 11], - [0, 1, 2, 3, 0, 0, 1, 3], - [1, -1, 2, -3, 0, 0, 0, 0]]; - -\{ lp_display($m)\} - -Takes the same optional arguments as display_matrix. The default -for column alignment as "augmentation line" before the last column. -It also adds a horizontal line before the last row if it is not already -specified. + $m = [[0, 3, -4, 5, 1, 0, 0, 28], + [0, 2, 0, 1, 0, 1, 0, 11], + [0, 1, 2, 3, 0, 0, 1, 3], + [1, -1, 2, -3, 0, 0, 0, 0]]; + + BEGIN_TEXT + \{ lp_display($m)\} + END_TEXT + +Takes the same optional arguments as display_matrix. The default for column +alignment as "augmentation line" before the last column. It also adds a +horizontal line before the last row if it is not already specified. =cut - # Display a tableau sub lp_display { my $a1_ref = shift; @@ -345,5 +362,4 @@ display_matrix($a_ref, %opts); } -# return 1 so that this file can be included with require -1 +1; Index: PG.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PG.pl,v retrieving revision 1.33 retrieving revision 1.34 diff -Lmacros/PG.pl -Lmacros/PG.pl -u -r1.33 -r1.34 --- macros/PG.pl +++ macros/PG.pl @@ -1,13 +1,13 @@ ################################################################################ -# WeBWorK Program Generation Language -# Copyright � 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ # $CVSHeader$ -# +# # This program is free software; you can redistribute it and/or modify it under # the terms of either: (a) the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any later # version, or (b) the "Artistic License" which comes with this package. -# +# # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the @@ -22,23 +22,23 @@ In a PG problem: - DOCUMENT(); # should be the first statment in the problem - - loadMacros(.....); # (optional) load other macro files if needed. - # (loadMacros is defined in F<dangerousMacros.pl>) - - HEADER_TEXT(...); # (optional) used only for inserting javaScript into problems. - - TEXT( # insert text of problems - "Problem text to be", - "displayed. Enter 1 in this blank:", - ANS_RULE(1,30) # ANS_RULE() defines an answer blank 30 characters long. - # It is defined in F<PGbasicmacros.pl> - ); - - ANS(answer_evalutors); # see F<PGanswermacros.pl> for examples of answer evaluatiors. - - ENDDOCUMENT() # must be the last statement in the problem + DOCUMENT(); # should be the first statment in the problem + + loadMacros(.....); # (optional) load other macro files if needed. + # (loadMacros is defined in F<dangerousMacros.pl>) + + HEADER_TEXT(...); # (optional) used only for inserting javaScript into problems. + + TEXT( # insert text of problems + "Problem text to be displayed. ", + "Enter 1 in this blank:", + ANS_RULE(1,30) # ANS_RULE() defines an answer blank 30 characters long. + # It is defined in F<PGbasicmacros.pl> + ); + + ANS(answer_evalutors); # see F<PGanswermacros.pl> for examples of answer evaluatiors. + + ENDDOCUMENT() # must be the last statement in the problem =head1 DESCRIPTION Index: extraAnswerEvaluators.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/extraAnswerEvaluators.pl,v retrieving revision 1.19 retrieving revision 1.20 diff -Lmacros/extraAnswerEvaluators.pl -Lmacros/extraAnswerEvaluators.pl -u -r1.19 -r1.20 --- macros/extraAnswerEvaluators.pl +++ macros/extraAnswerEvaluators.pl @@ -1,32 +1,41 @@ -loadMacros('MathObjects.pl'); +################################################################################ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader$ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. +################################################################################ =head1 NAME - extraAnswerEvaluators.pl - -=head1 SYNPOSIS +extraAnswerEvaluators.pl - Answer evaluators for intervals, lists of numbers, +and lists of points. - Answer Evaluators for intervals, lists of numbers, lists of points, - and equations. +=head1 SYNPOSIS - interval_cmp() -- checks answers which are unions of intervals. - It can also be used for checking an ordered pair or - list of ordered pairs. + interval_cmp() -- checks answers which are unions of intervals. It can also + be used for checking an ordered pair or list of ordered + pairs. number_list_cmp() -- checks a comma separated list of numbers. By use of optional arguments, you can request that order be - important, that complex numbers be allowed, and - specify extra arguments to be sent to num_cmp (or - cplx_cmp) for checking individual entries. - - equation_cmp() -- provides a limited facility for checking equations. - It makes no pretense of checking to see if the real locus - of the student's equation matches the real locus of the - instructor's equation. The student's equation must be - of the same general type as the instructors to get credit. - - -=cut + important, that complex numbers be allowed, and specify + extra arguments to be sent to num_cmp (or cplx_cmp) for + checking individual entries. + + equation_cmp() -- provides a limited facility for checking equations. It + makes no pretense of checking to see if the real locus of + the student's equation matches the real locus of the + instructor's equation. The student's equation must be of + the same general type as the instructors to get credit. =head1 DESCRIPTION @@ -35,6 +44,8 @@ =cut +loadMacros('MathObjects.pl'); + { package Equation_eval; @@ -217,41 +228,45 @@ return($context); } -=head3 interval_cmp () +=head1 MACROS + +=head2 interval_cmp Compares an interval or union of intervals. Typical invocations are - interval_cmp("(2, 3] U(7, 11)") + interval_cmp("(2, 3] U(7, 11)") -The U is used for union symbol. In fact, any garbage (or nothing at all) -can go between intervals. It makes sure open/closed parts of intervals -are correct, unless you don't like that. To have it ignore the difference -between open and closed endpoints, use +The U is used for union symbol. In fact, any garbage (or nothing at all) can go +between intervals. It makes sure open/closed parts of intervals are correct, +unless you don't like that. To have it ignore the difference between open and +closed endpoints, use - interval_cmp("(2, 3] U(7, 11)", sloppy=>'yes') + interval_cmp("(2, 3] U(7, 11)", sloppy=>'yes') -interval_cmp uses num_cmp on the endpoints. You can pass optional -arguments for num_cmp, so to change the tolerance, you can use +interval_cmp uses num_cmp on the endpoints. You can pass optional arguments for +num_cmp, so to change the tolerance, you can use - interval_cmp("(2, 3] U(3+4, 11)", relTol=>3) + interval_cmp("(2, 3] U(3+4, 11)", relTol=>3) The intervals can be listed in any order, unless you want to force a particular order, which is signaled as - interval_cmp("(2, 3] U(3+4, 11)", ordered=>'strict') + interval_cmp("(2, 3] U(3+4, 11)", ordered=>'strict') You can specify infinity as an endpoint. It will do a case-insensitive string match looking for I, Infinity, Infty, or Inf. You can prepend a + or -, as in - interval_cmp("(-inf, 3] U [e^10, infinity)") + interval_cmp("(-inf, 3] U [e^10, infinity)") + or - interval_cmp("(-INF, 3] U [e^10, +I)") + + interval_cmp("(-INF, 3] U [e^10, +I)") If the question might have an empty set as the answer, you can use the strings option to allow for it. So - interval_cmp("$ans", strings=>['empty']) + interval_cmp("$ans", strings=>['empty']) will not generate an error message if the student enters the string empty. Better still, it will mark a student answer of "empty" as correct @@ -261,7 +276,7 @@ Internally, this is just a distinction of whether to put nice union symbols between intervals, or commas. To get commas, use - interval_cmp("(1,2), (2,3), (4,-1)", unions=>'no') + interval_cmp("(1,2), (2,3), (4,-1)", unions=>'no') Note that interval_cmp makes no attempt at simplifying overlapping intervals. This becomes an important feature when you are really checking lists of @@ -272,7 +287,7 @@ showCoordinateHints, showHints, partialCredit, and/or showLengthHints as optional arguments: - interval_cmp("(1,2), (2,3), (4,-1)", unions=>'no', partialCredit=>1) + interval_cmp("(1,2), (2,3), (4,-1)", unions=>'no', partialCredit=>1) Also, set differences and 'R' for all real numbers now work too since they work for Parser Intervals and Unions. @@ -371,24 +386,24 @@ return($ans_eval); } -=head3 number_list_cmp () +=head2 number_list_cmp Checks an answer which is a comma-separated list of numbers. The actual numbers are fed to num_cmp, so all of the flexibilty of num_cmp carries over (values can be expressions to be evaluated). For example, - number_list_cmp("1, -2") + number_list_cmp("1, -2") will accept "1, -2", "-2, 1", or "-1-1,sqrt(1)". - number_list_cmp("1^2 + 1, 2^2 + 1, 3^2 + 1", ordered=>'strict') + number_list_cmp("1^2 + 1, 2^2 + 1, 3^2 + 1", ordered=>'strict') will accept "2, 5, 10", but not "5, 2, 10". If you want to allow complex number entries, complex=>'ok' will cause it to use cplx_cmp instead: - number_list_cmp("2, -2, 2i, -2i", complex=>'ok') + number_list_cmp("2, -2, 2i, -2i", complex=>'ok') In cases where you set complex=>'ok', be sure the problem file loads PGcomplexmacros.pl. @@ -396,23 +411,23 @@ Optional arguements for num_cmp (resp. cplx_cmp) can be used as well, such as - number_list_cmp("cos(3), sqrt(111)", relTol => 3) + number_list_cmp("cos(3), sqrt(111)", relTol => 3) The strings=>['hello'] argument is treated specially. It can be used to replace the entire answer. So - number_list_cmp("cos(3), sqrt(111)", strings=>['none']) + number_list_cmp("cos(3), sqrt(111)", strings=>['none']) will mark "none" wrong, but not generate an error. On the other hand, - number_list_cmp("none", strings=>['none']) + number_list_cmp("none", strings=>['none']) will mark "none" as correct. One can also specify optionnal arguments for Parser's List checker: showHints, partialCredit, and showLengthHints, as in: - number_list_cmp("cos(3), sqrt(111)", partialCredit=>1) + number_list_cmp("cos(3), sqrt(111)", partialCredit=>1) =cut @@ -454,7 +469,7 @@ } -=head3 equation_cmp () +=heads equation_cmp Compares an equation. This really piggy-backs off of fun_cmp. It looks at LHS-RHS of the equations to see if they agree up to constant multiple. @@ -466,11 +481,10 @@ Typical invocation would be: - equation_com("x^2+(y-1)^2 = 11", vars=>['x','y']) + equation_com("x^2+(y-1)^2 = 11", vars=>['x','y']) =cut sub equation_cmp { Equation_eval::equation_cmp(@_); } - Index: MathObjects.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/MathObjects.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -Lmacros/MathObjects.pl -Lmacros/MathObjects.pl -u -r1.7 -r1.8 --- macros/MathObjects.pl +++ macros/MathObjects.pl @@ -1,13 +1,34 @@ -=head1 MathObjects.pl +################################################################################ +# WeBWorK Online Homework Delivery System +# Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader$ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. +################################################################################ + +=head1 NAME + +MathObjects.pl - Macro-based fronted to the MathObjects system. + +=head1 DESCRIPTION + +This file loads Parser.pl which in turn loads Value.pl The purpose of this file +is to encourage the use of the name MathObjects instead of Parser (which is not +as intuitive for those who don't know the history). -=pod +It may later be used for other purposes as well. -This file loads Parser.pl which in turn loads Value.pl -The purpose of this file is to encourage the use of the name MathObjects -instead of Parser (which is not as intuitive for those who don't know -the history). +=head1 SEE ALSO -It may later be used for other purposes as well. +L<Parser.pl>. =cut |