WeBWorK Problems

Retrieving students' un-evaluated constant expressions from MultiAns

Retrieving students' un-evaluated constant expressions from MultiAns

by Andrew Parker -
Number of replies: 1
So, the idea here is to require students to re-write a (non-algebraic) logarithmic expression in exponential form.

e.g. convert log_5(25) = 2 into 5^2 = 25

I've set up the problem as two answer blanks separated by an equal sign, with the two answers joined under parserMultiAns.

I'm using bizarroArithmetic to check for proper formatting with a custom MultiAns checker to allow for mirrored responses.

However, in the answer checker, I am having trouble pulling the un-evaluated student answers from $ansHash. Using @{$student} of course gives me the evaluated (Real-valued) form of the student expression, and @{$ansHash->{student_formula}} comes up blank (as does @{$ansHash->{original_student_ans}}). Using reduceConstants=>0 ensures that the preview answer string is exactly what I want, but I can't seem to figure out how to pull it from the $ansHash or $student.
In reply to Andrew Parker

Re: Retrieving students' un-evaluated constant expressions from MultiAns

by Andrew Parker -
Thanks to Geoff for helping me figure this out - I'll leave the fixed result for anyone else who might run into a similar problem:

$ans = MultiAnswer(Formula("$base^($exp)"),Formula("$result"))->with(
   singleResult => 1,
   separator => " = ",
   tex_separator => " = ",
   checker => sub {
      my ($correct,$student,$self) = @_;  # get the parameters
      my ($ansHash1, $ansHash2) = @{$self->{ans}};
      my $lhs = $ansHash1->{student_formula};
      my $rhs = $ansHash2->{student_formula};
      my ($exp,$res) = @{$correct};
      $lhs = Formula("$lhs"); $rhs = Formula("$rhs"); $exp = Formula("$exp");
      return 0 unless (($lhs == $exp) && ($rhs == $res));
      Context()->flags->set(bizarroDiv=>1, bizarroMul=>1, bizarroAdd=>1, bizarroSub=>1, bizarroPow=>1 );
      Value::Error("Your equation is not in exponential form.") unless ((($lhs == $exp || $exp == $lhs) && ($rhs == $res || $res == $rhs)) || (($lhs == $res || $res == $lhs) && ($rhs == $exp || $exp == $rhs)));
      Context()->flags->set(bizarroDiv=>0, bizarroMul=>0, bizarroAdd=>0, bizarroSub=>0, bizarroPow=>0 );
      return 1;
       },
  );

BEGIN_PGML

Rewrite the logarithmic equation in exponential form.

>> [`` \log_[$base]([$result]) = [$exp] ``] <<

[________]{$ans} = [________]{$ans}

END_PGML

ENDDOCUMENT();