WeBWorK Problems

Scaffolding with LimitedFactor context

Scaffolding with LimitedFactor context

by Paul Seeburger -
Number of replies: 7
Hello,

I have successfully created my first problem using the new scaffold.pl form of scaffolding.

In my second problem I am having trouble, however.

It seems that when I use the LimitedFactor context developed by Alex Jordan in the problem, the correct answers are marked incorrect when I check them, but oddly the section header is turned green and the second section opens up, so the answers are registering as correct in some form.

And though, the bar for Section 1 turns green, and Section 2 is opened, the score does not reflect correct answers for the first part even after finishing the problem.

Here is my code so far:

DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"answerHints.pl",
"scaffold.pl",
"parserAssignment.pl",
"contextLimitedFactor.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

###########################################
#  The scaffold
Scaffold::Begin(
      can_open => "when_previous_correct",
      is_open  => "correct_or_first_incorrect"
    );
Section::Begin("Part 1: Separate the variables.");

Context("Numeric");
$a = random(2,9,1);
do { $b = random(2,5,1); } until ($b != $a);

$ab = $a * $b;

Context("LimitedFactor");
Context()->variables->add(y=>"Real");
Context()->noreduce('(-x)-y','(-x)+y');
$ans = Formula("(x+$b)*(y+$a)")->reduce;
$factor = Compute("y+$a"); $factor2 = Compute("y+$a");

BEGIN_PGML
Find the general solution to 
[` \displaystyle \frac{dy}{dx} = xy + [$a] x + [$b] y + [$ab]`], showing all requested steps.

Use C as a arbitrary constant, if needed.

First, factor the right side of the differential equation.

[` \displaystyle \frac{dy}{dx} = xy + [$a] x + [$b] y + [$ab] = x(`][______]{$factor}[`) + [$b](`][______]{$factor2}[`)  =`][______________]{$ans}
END_PGML

Section::End();

Section::Begin("Part 2: Separate the variables.");

Context("Numeric")->variables->add(
y=>"Real", C=>"Real");
$C=2.356;

parser::Assignment->Allow;

$answer = Compute("y = C * e^(x^2/2 + $b x) - $a");

$ls = Compute("1/($factor)");  $rs = Compute("x + $b");

BEGIN_PGML
Now, separate the variables.

[`\int`][_____]{$ls} [`dy  = \int`][_____]{$rs} [`dx`]
END_PGML

BEGIN_PGML_SOLUTION

END_PGML_SOLUTION
Section::End();

Scaffold::End();
COMMENT("MathObject version.");

ENDDOCUMENT();

Clearly something is not working correctly.

Thanks!

Paul
In reply to Paul Seeburger

Re: Scaffolding with LimitedFactor context

by Alex Jordan -
Hi Paul,

That's curious. At first glance, I think this may be a question for someone who knows more about scaffold.pl. Scaffold.pl is somehow marking the correct answers as correct as evidenced by giving you access to the second part of the problem. And yet the feedback table is not receiving that information. Maybe it is something about the strangeness of the answer checker in LimitedFactor context.

The answer checker used by LimitedFactor (https://github.com/openwebwork/pg/blob/master/macros/contextLimitedFactor.pl) relies on bizarroArithmetic.pl, and is given by:

$context->{cmpDefaults}{Formula}{checker} = sub {
my ($correct,$student,$ans) = @_;
return 0 if $ans->{isPreview} || $correct != $student;
$student = $ans->{student_formula};
$correct = $correct->{original_formula} if defined $correct->{original_formula};
# check for equivalence when bizarro arithmetic is enforced
Context()->flags->set(bizarroSub=> 1,bizarroAdd=> 1, bizarroDiv=> 1);
delete $correct->{test_values}, $student->{test_values};
my $OK = ($correct == $student);
Context()->flags->set(bizarroSub=> 0,bizarroAdd=> 0, bizarroDiv=> 0);
my $factorableObject = Context()->flag("factorableObject");
Value::Error("Your answer is equivalent to the $factorableObject in the correct answer, but not completely factored or simplified") unless $OK;
return $OK;
};

If I could look at this together with someone who knows more about scaffold.pl, perhaps we could figure it out.


In reply to Alex Jordan

Re: Scaffolding with LimitedFactor context

by Paul Pearson -
Hi Paul,

Try the code below and report if it works.  If it does not work, try commenting out "contextLimitedFactor.pl" and replacing Context("LimitedFactor"); by Context("Numeric");  I was able to get it working with Context("Numeric"); and I do not have contextLimitedFactor.pl installed on the server I used to test this.

Best regards,

Paul Pearson

###################################
DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"answerHints.pl",
"scaffold.pl",
"parserAssignment.pl",
"contextLimitedFactor.pl",
"PGcourse.pl",
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;


$a = random(2,9,1);
do { $b = random(2,5,1); } until ($b != $a);

$ab = $a * $b;

Context("LimitedFactor");
#Context("Numeric");
Context()->variables->add(y=>"Real");
Context()->noreduce('(-x)-y','(-x)+y');
$ans = Formula("(x+$b)*(y+$a)")->reduce;
$factor = Compute("y+$a"); $factor2 = Compute("y+$a");

###########################################
#  The scaffold
Scaffold::Begin(
      can_open => "when_previous_correct",
      is_open  => "correct_or_first_incorrect"
    );
Section::Begin("Part 1: Separate the variables.");
BEGIN_PGML
Find the general solution to 
[` \displaystyle \frac{dy}{dx} = xy + [$a] x + [$b] y + [$ab]`], showing all requested steps.

Use C as a arbitrary constant, if needed.

First, factor the right side of the differential equation.

[` \displaystyle \frac{dy}{dx} = xy + [$a] x + [$b] y + [$ab] = x(`][______]{$factor}[`) + [$b](`][______]{$factor2}[`)  =`][______________]{$ans}
END_PGML
Section::End();


Context("Numeric")->variables->add(
y=>"Real", C=>"Real");
$C=2.356;
parser::Assignment->Allow;
$answer = Compute("y = C * e^(x^2/2 + $b x) - $a");
$ls = Compute("1/($factor)");  $rs = Compute("x + $b");

Section::Begin("Part 2: Separate the variables.");
BEGIN_PGML
Now, separate the variables.

[`\int`][_____]{$ls} [`dy  = \int`][_____]{$rs} [`dx`]
END_PGML
Section::End();

Scaffold::End();

ENDDOCUMENT();

In reply to Alex Jordan

Re: Scaffolding with LimitedFactor context

by Davide Cervone -
I have been looking into it myself, and there is something funny about the LimitedFactor context. If you ask a formula to check itself against a correct student answer twice, the first time it marks it correct but the second time it marks it false. For example
loadMacros("contextLimitedFactor.pl");
Context("LimitedFactor");
$f = Compute("x+7");
TEXT(
  $f->cmp->evaluate("x+7")->{score},
  " ",
  $f->cmp->evaluate("x+7")->{score}
);
shows "1 0", so the first one is marked correct and the second marked incorrect. I haven't yet tracked down why, but I have seen other custom checkers in the past that were not consistent in this way. I'll look into it further. The reason that this makes a difference is that the scaffolding macros call the evaluate() method in order to decide whether the next section needs to be opened. This happens outside of the normal grading process, so when WeBWorK goes to grade the problem, it calls evaluate() again. Usually, these both return the same answer, but for LimitedFactor, that doesn't seem to be the case. So the scaffold thinks the answer is right, and WeBWorK thinks it is not. Not sure exactly what is causing the inconsistency, but that is what I know at the moment.
In reply to Alex Jordan

Re: Scaffolding with LimitedFactor context

by Davide Cervone -
OK, found it. The problem is that after the bizzaro check, the student answer is left with the bizzaro values in its test_values property, and on the second time through, the comparison $correct != $student in the second line of the checker compares the correct answers with the bizzaro student values, which aren't equal, and so the score is zero.

I recommend adding

delete $correct->{test_values}, $student->{test_values};
after
my $OK = ($correct == $student);
so that the bizzaro values are removed from both equations after the bizzaro check. That allows the checker to be called twice without problems.
In reply to Davide Cervone

Re: Scaffolding with LimitedFactor context

by Paul Seeburger -
Thanks, Davide!

This seems to work perfectly now, as far as I can tell!

It requires the form of the answer to be factored from the LimitedFactor context and is marked correctly for both the scaffolding and scoring.

This will be good for anyone else who wishes to evaluate factoring in a scaffolded approach too!

Paul
In reply to Davide Cervone

Re: Scaffolding with LimitedFactor context

by Alex Jordan -
Thanks Davide, that makes sense but I never would have found it in a million years.

I can add this to LimitedFactor.pl and submit a pull request. But not for a few days owing to the awkward setup of our development server here, which I can't reliably access from home. I'd also add a note about this issue in the documentation for bizarroArithmetic.pl, and change the example there to do the same. (If anyone wants to beat me to any of this, please feel free.)

Paul, if you are needing something sooner, you could copy LimitedFactor.pl into local macros, and add the line that Davide suggests.
In reply to Alex Jordan

Re: Scaffolding with LimitedFactor context

by Paul Seeburger -
I've already updated my local copy of your contextLimitedFactor.pl, Alex, and it is working well, it seems.

Thanks!