## Forum archive 2000-2006

### Michael Gage - PG answer evaluators ### Michael Gage - PG answer evaluators

by Arnold Pizer -
Number of replies: 0 PG answer evaluators topic started 4/27/2000; 6:51:25 PMlast post 6/29/2000; 10:32:42 AM Michael Gage - PG answer evaluators 4/27/2000; 6:51:25 PM (reads: 4678, responses: 3)

### How to use them

#### Numerical compare:

• ANS( strict_num_cmp( 3.14159 ) ); The student's answer must be a number in decimal or scientific notation which is within .1 percent of 3.14159. This assumes $numRelPercentTolDefault has been set to .1. • ANS( strict_num_cmp($answer,.01 ) ); The student's answer must be a number within .01 percent of $answer (e.g. 3.14159 if$answer is 3.14159 or $answer is "pi" or$answer is 4*atan(1)).
• ANS( frac_num_cmp( $answer) ) or ANS( frac_num_cmp($answer,.01 )); The student's answer can be a number or fraction, e.g. 2/3.
• ANS( arith_num_cmp( $answer) ) or ANS( arith_num_cmp($answer,.01 )); The student's answer can be an arithmetic expression, e.g. (2+3)/7-2^.5 .
• ANS( std_num_cmp( $answer) ) or ANS( std_num_cmp($answer,.01 )); The student's answer can contain elementary functions, e.g. sin(.3+pi/2)
• You can also specify additional parameters for controling the format of printed answers and for how answers close to zero are handled. Further, there are versions which use a fixed absolute tolerance rather than a relative percent tolerance. Finally, there are versions which will accept a list of answers. Also num_cmp( ) is an alias for std_num_cmp( ). See standard Answer Evaluating Functions.

#### String compare:

All the string comparison operators ignore initial and trailing white space.

• ANS( std_str_cmp( "W. Mozart" ) ); Accepts "W. Mozart", "W. MOZarT" and so forth. Case insensitive. All internal spaces treated as single spaces.
• ANS( std_cs_str_cmp( "Mozart" ) ); Rejects "mozart". Same as std_str_cmp but case sensitive.
• ANS( strict_str_cmp( "W. Mozart" ) ); Accepts only the exact string.
• ANS( unordered_str_cmp( "ABC" ) ); Accepts "a c B", "CBA" and so forth. Unordered, case insensitive, spaces ignored.
• ANS( unordered_cs_str_cmp( "ABC" ) ); Rejects "abc". Same as unordered_str_cmp but case sensitive.
• ANS( ordered_str_cmp( "ABC" ) ); Accepts "a b C", "A B C" and so forth. Ordered, case insensitive, spaces ignored.
• ANS( ordered_cs_str_cmp( "ABC" ) ); Rejects "abc", accepts "A BC" and so forth. Same as ordered_str_cmp but case sensitive.
• There are versions which will accept a list of answers. See standard Answer Evaluating Functions.

• ANS( function_cmp( "cos(x)" ) ); Accepts cos(x), sin(x+pi/2), sin(x)^2 + cos(x) + cos(x)^2 -1, etc. This assumes $functVarDefault has been set to "x". • ANS( function_cmp($answer, "t" ) ); Assuming $answer is "cos(t)", accepts cos(t), etc. • ANS( function_cmp_up_to_constant( "cos(x)" ) ); Accepts any antiderivative of sin(x), e.g. cos(x) + 5. • ANS( function_cmp_up_to_constant( "cos(z)", "z" ) ); Accepts any antiderivative of sin(z), e.g. sin(z+pi/2) + 5. • Further, there are versions which use a fixed absolute tolerance rather than a relative percent tolerance. You can also specify additional parameters. See standard Answer Evaluating Functions. (see also fun_cmp for another syntax) ### What are they? They extend the ability of the instructor to check a student's answer. Instead of just providing a correct answer, they provide a function which evaluates the student's answer to determine if it is correct. In other words the instructor can control both the correct answer and a method for comparing it with the student's answer. Of course for many questions you can use the standard methods listed above. For details on the standard Answer Evaluating Functions see standard Answer Evaluating Functions. For details on writing your own Answer Evaluating Functions see writing your own Answer Evaluating Functions. ### Details on using the standard Answer Evaluating Functions #### Numerical compare: strict_num_cmp($correctAnswer); OR strict_num_cmp($correctAnswer,$relpercentTol); OR strict_num_cmp($correctAnswer,$relpercentTol,$format); OR strict_num_cmp($correctAnswer,$relpercentTol,$format,$zeroLevel); OR strict_num_cmp($correctAnswer,$relpercentTol,$format,$zeroLevel,$zeroLevelTol);

frac_num_cmp($correctAnswer); OR frac_num_cmp($correctAnswer,$relpercentTol); etc. arith_num_cmp($correctAnswer); etc.

function_cmp($correctFunction) OR function_cmp($correctFunction,$var) OR function_cmp($correctFunction,$var,$llimit,$ulimit) OR function_cmp($correctFunction,$var,$llimit,$ulimit,$relpercentTol) OR function_cmp($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints) function_cmp($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints,$zeroLevel) function_cmp($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints,$zeroLevel,$zeroLevelTol) #### Function compare up to constant (e.g. to for antidervatives): function_cmp_up_to_constant($correctFunction) OR function_cmp_up_to_constant($correctFunction,$var) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit,$relpercentTol) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints,$maxConstantOfIntegration) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints,$maxConstantOfIntegration,$zeroLevel) OR function_cmp_up_to_constant($correctFunction,$var,$llimit,$ulimit,$relpercentTol,$numOfPoints,$maxConstantOfIntegration,$zeroLevel,$zeroLevelTol) function_cmp_abs($correctFunction,$var,$llimit,$ulimit,$absTol,$numOfPoints) function_cmp_up_to_constant_abs($correctFunction,$var,$llimit,$ulimit,$absTol,$numOfPoints,,$maxConstantOfIntegration)

$testAnswer = sub { my$in = shift @_;  # get the answer from the student        my $correctQ; # variable will be set to 1 if the answer is # correct. my$PGanswerMessage ="" # message to be printed on screen        if ($in eq "Mozart") {$correctQ =1;                }        else {                $correctQ = 0; } ($correctQ, "Mozart" $in,$PGanswerMessage);        };ANS( $testAnswer );  $testAnswer = sub {        my $in = @_; # get the answer from the student my$correctQ; # variable will be set to 1 if the answer is                # correct.        my $PGanswerMessage ="" # message to be printed on screen if ($in =~ /Mozart/) {                # if the string "Mozart" appears in the answer                $correctQ =1; } else {$correctQ = 0;                }        ($correctQ, "Wolfgang Amadeus Mozart",$in, $PGanswerMessage); };ANS($testAnswer);                  

More examples of evaluation functions

ANS( std_num_cmp(3.456234567) );

Here is the actual code.

 ANS( std_num_cmp( 2 ) ); 

 ANS( std_str_cmp( "Mozart" ) ); 

sub std_cs_str_cmp {       # compare strings case sensitivemy ($correctAnswer) = shift @_; # get the correct answermy$normalizedCorrectAnswer = $correctAnswer;$normalizedCorrectAnswer=~ s/s*$//; # remove trailing whitespace$normalizedCorrectAnswer=~ s/^s*//;     # remove initial spaces$normalizedCorrectAnswer=~ s/s+/ /g; # replace spaces by single space  ANS( std_str_cmp( "Mozart" ) );  <| Post or View Comments |> David Etlinger - Re: PG answer evaluators 6/9/2000; 3:18:58 PM (reads: 3496, responses: 0) docs for std_num_str_cmp and multivar_function_cmp need to be added <| Post or View Comments |> David Etlinger - Re: PG answer evaluators 6/9/2000; 3:30:09 PM (reads: 3471, responses: 0) also, add numerical_compare_with_units <| Post or View Comments |> David Etlinger - Re: PG answer evaluators 6/29/2000; 10:32:42 AM (reads: 3572, responses: 0) Descriptions for a few missing evaluators: ANS( multivar_function_cmp($answer, $var_reference, options ) );$answer = string, represents function of several variables $var_reference = number (of variables), or list reference (e.g. ["var1","var2"] ) Options:$limit_reference = reference to list of lists (e.g. [[1,2],[3,4]]) $relpercentTol = relative percent tolerance in answer$numOfPoints = number of points to sample in for each variable $zeroLevel =$zeroLevelTol = ANS( checkbox_cmp( $answer ) );$answer = a string containing the names of the correct boxes, e.g. "ACD". Note that this means that individual checkbox names can only be one character. ANS( radio_cmp( $answer ) );$answer = a string containing the name of the correct radio button, e.g. "Choice1". ANS( std_num_str_cmp( $answer, options ) ); Options$ra_legalStrings = a reference to an array containing strings which are possible answers, e.g. ["Inf", "Minf", "NaN"] $relPercentTol =$format = $zeroLevel =$zeroLevelTol = ANS( numerical_compare_with_units( $answer, %options ) );$answer = a string which includes both the numerical answer and the units Options (key => value pairs) mode = format = zeroTol = zeroLevelTol = tol = relTol = Notes: --mc_cmp can be eliminated from PGanswermacros.pl (it's commented out near the top, but it makes it confusing to read the file). --Answer evaluators should be consistent in using new AnswerHash() --multivar_function_cmp already has pod documentation. Can we use that for this page, or should we possible add it for the other answer evaluators? --are str_cmp and std_str_cmp functionally equivalent? They are using separate code, but if they are the same they should be made to use the same code. <| Post or View Comments |>