WeBWorK Problems

parserMultiAnswer and Tests

parserMultiAnswer and Tests

by Justin Sukiennik -
Number of replies: 1
Hi,

We are having problems with students taking a Test on WeBWorK with the parserMultianswer.pl macro. When the students, click the "Preview" button, they get a garble of characters in the second answer, i.e. "B = " answer. For instance, if there are two problems with this parserMultiAnswer.pl in use, they will receive the answers for "B=" combined in each answer blank with "B=". In other words WeBWorK seems to be combining all the denominators into a string and replacing the student's answer with the long string. I have placed two problems from the Test that should suffice for an example.

Sincerely,
Justin

##DESCRIPTION
## Algebra: exponents and radicals
##ENDDESCRIPTION

##KEYWORDS('algebra', 'radicals')

##DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Exponents and Radicals')
## Date('10/27/2009')
## Author('Justin Sukiennik')
## Institution('University of Minnesota')
## TitleText1('Algebra for College Students')
## EditionText1('8')
## AuthorText1('Kaufmann, Schwitters')
## Section1('5.3')
## Problem1('12')

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"parserMultiAnswer.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);


########################################################################

install_problem_grader(~~&std_problem_grader);

$showPartialCorrectAnswers = 0;

TEXT(beginproblem());

########################################################################

Context("Numeric");

$a = random(5,7,2);
$b = list_random(2,4);

$c = Compute("$a-2")->reduce;
$d = Compute("5*$b^2")->reduce;

$numerator = Real("2*$a-2");
$denominator = Real("$a");
$radical = Real("5");

########################################################################

$mp = MultiAnswer($numerator,$denominator)->with(
singleResult => 1,
separator => "/",
tex_separator => "/",
checker => sub {
my ($correct,$student,$self) = @_; # get the parameters

my ( $p1, $p2 ) = @{$correct}; # get the correct num, denom
my ( $p1stu, $p2stu ) = @{$student};# get the student's num, denom

my $isPreview = $main::inputs_ref->{previewAnswers};


$numeratorValid = ( $p1==$p1stu || Compute("-1")*$p1==$p1stu );
$denominatorValid = ( $p2==$p2stu || Compute("-1")*$p2==$p2stu );
$quotientValid = ( $p1/$p2 == Compute($p1stu)/Compute($p2stu) );

if (! $isPreview) { # Don't show messages if previewing....
Value::Error("Your numerator (and maybe more) is incorrect")
unless $numeratorValid;
Value::Error("Your denominator is incorrect")
unless $denominatorValid;
Value::Error("Your fraction has the wrong sign")
unless $quotientValid;
}

return $quotientValid;
},
);


########################################################################

Context()->texStrings;
BEGIN_TEXT
Use the distributive property to help simplify the numerical expression
\[
\frac{$c}{$a}\sqrt{5}+\frac{1}{$b}\sqrt{$d}
\]

into the form \(\frac{A}{B} \sqrt{C}\), where \(A\), \(B\), and \(C\) are all integers.
$PAR
Answer: \(A =\) \{$mp->ans_rule(15)\}, \(B =\) \{$mp->ans_rule(15)\}, and \(C =\) \{ ans_rule(15) \}
$HR
END_TEXT
Context()->normalStrings;

########################################################################

ANS( $mp->cmp );
ANS( $radical->cmp );

ENDDOCUMENT();



##DESCRIPTION
## Algebra: Multiplying rational expressions
##ENDDESCRIPTION

##KEYWORDS('algebra', 'rational expressions', 'multiplying')

##DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Algebraic Expressions')
## Date('10/11/2009')
## Author('Justin Sukiennik')
## Institution('University of Minnesota')
## TitleText1('Algebra for College Students')
## EditionText1('8')
## AuthorText1('Kaufmann, Schwitters')
## Section1('4.2')
## Problem1('30')

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"parserMultiAnswer.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

########################################################################

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

########################################################################

Context("Numeric");
Context()->variables->are(n=>'Real');

$a = random(3,7,2);
$b = random(2,4,2);
$c = random(2,5,1);

$poly1 = Compute("10n^2+(5*$a-2)n-$a") -> reduce;
#(5n-1)(2n+$a)
$poly2 = Compute("$c n^2+ (2*$c+1)n +2") -> reduce;
#(n+2)($c n +1)
$poly3 = Compute("$b n^2+ 2*$b n") -> reduce;
#(n+2)($b n)
$poly4 = Compute("2n^2+($a+2)n+$a") -> reduce;
#(n+1)(2n+$a)

$ans1 = Compute("5*$b n^2 - $b n");
$ans2 = Compute("$c n^2 + (1+$c)n + 1");

########################################################################

$mp = MultiAnswer($ans1,$ans2)->with(
singleResult => 1,
checker => sub {
my ($correct,$student,$self) = @_; # get the parameters

my ( $p1, $p2 ) = @{$correct}; # get the correct num, denom
my ( $p1stu, $p2stu ) = @{$student};# get the student's num, denom

my $isPreview = $main::inputs_ref->{previewAnswers};


$numeratorValid = ( $p1==$p1stu || Compute("-1")*$p1==$p1stu );
$denominatorValid = ( $p2==$p2stu || Compute("-1")*$p2==$p2stu );
$quotientValid = ( $p1/$p2 == Compute($p1stu)/Compute($p2stu) );

if (! $isPreview) { # Don't show messages if previewing....
Value::Error("Your numerator is incorrect")
unless $numeratorValid;
Value::Error("Your denominator is incorrect")
unless $denominatorValid;
Value::Error("One of your answers has the wrong sign")
unless $quotientValid;
}

return $quotientValid;
},
);

########################################################################

Context()->texStrings;
BEGIN_TEXT
Multiply the two rational expressions
\[
\frac{$poly1}{$poly2} \cdot \frac{$poly3}{$poly4}.
\]

Express your answer in simplest form \(\frac{A}{B}\).$PAR
Answer: \(A =\) \{$mp->ans_rule(20)\} and \(B =\) \{$mp->ans_rule(20)\}
END_TEXT
Context()->normalStrings;

########################################################################

ANS( $mp->cmp );

ENDDOCUMENT();
In reply to Justin Sukiennik

Re: parserMultiAnswer and Tests

by Gavin LaRose -
I've had an off-list exchange of e-mails with Jonathan Rogness, who reports that this may be resolved by setting singleResult => 0, instead of singleResult => 1. This suggests that there is something about how the MultiAnswer checker chooses to define its answer blanks that's causing the problem (which makes very good sense).

This is really a work-around rather than a solution, but it's a start!

Gavin