## WeBWorK Problems

### contextFraction errors in old problem

by Paul Seeburger -
Number of replies: 6
I am using a set of algebra problems based on some from Portland Community College that I have not used since WeBWorK version 2.9 or so, and now I am getting errors.

The first error I am getting is:

------
---- PGML (eval 1336) 1489 ------
==================
Errors parsing PGML:
Error evaluating command: No such package 'Value::Fraction'
==================
__________________________

when I enter my first answer.

Then when I enter the correct answer I get the following error:

### Warning messages

• Processing of this PG problem was not completed. Probably because of a syntax error. The translator died prematurely and no PG warning messages were transmitted. at /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm line 762. Odd number of elements in anonymous hash at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 180. Use of uninitialized value in anonymous hash ({}) at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 180.

### Error messages

Can't use string ("answersSubmitted") as an ARRAY ref while "strict refs" in use at /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm line 202.

### Call stack

The information below can help locate the source of the problem.

• in WeBWorK::Utils::AttemptsTable::_init called at line 190 of /opt/webwork/webwork2/lib/WeBWorK/Utils/AttemptsTable.pm
• in WeBWorK::Utils::AttemptsTable::new called at line 322 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::attemptResults called at line 1868 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::output_summary called at line 155 of /opt/webwork/webwork2/lib/WeBWorK/Template.pm
• in WeBWorK::Template::template called at line 562 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
• in WeBWorK::ContentGenerator::content called at line 363 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator/Problem.pm
• in WeBWorK::ContentGenerator::Problem::content called at line 232 of /opt/webwork/webwork2/lib/WeBWorK/ContentGenerator.pm
• in WeBWorK::ContentGenerator::go called at line 384 of /opt/webwork/webwork2/lib/WeBWorK.pm

The code for the problem is:

# WeBWorK problem written by Carl Yao
# Portland Community College
#
# Solve equations like 5x/4-6x=3/8; answer is a fraction or integer.
#
# Paul Seeburger modified this problem to allow students to enter work
# in a step-by-step manner.
#
# Last edited: Seeburger, 9/9/2014; Kling, 7/18/13; Jordan, 7/10/13; Hughes 7/1/13, Wherry, 6/28/13
# ENDDESCRIPTION

## DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Algebraic Expressions')
## KEYWORDS('solve','linear','equation','fraction')
## DBCCSS('6.EE.7','7.EE.4','8.EE.7')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Alex Jordan, Carl Yao, Chris Hughes, Paul Seeburger')
## Institution('PCC, Monroe Community College')

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

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserAssignment.pl",
"PCCmacros.pl",
"answerHints.pl",
"contextFraction.pl",
"SolveLinearEquationPCC.pl",
"PGcourse.pl",
);

##############################################
Context("Numeric");
$var = RandomVariableName(); Context()->variables->are($var => 'Real');
Context()->noreduce('(-x)-y','(-x)+y');

$den1 = random(2,10,2);$num1 = random(3,9,2);
while (gcd($den1,$num1)!=1) {$num1=random(3,9,2);}$den2 = 2*$den1;$num2 = random(3,9,2);
while (gcd($den2,$num2)!=1) {$num2=random(3,9,2);} #adjust$a's value to make the solution negative
$a=random(5,10,1);$cf1 = 2*$num1;$cf2 = $den2*$a;
$leftL = Formula("$cf1*$var -$cf2*$var"); Context()->operators->undefine("/","/ "," /"); Context()->{error}{msg}{"Can't use '/' in this context"} = "There should no longer be a fraction on this side of the equation.";$ans_eval1 = Compute($den2)->cmp();$ans_eval2 = $leftL->cmp();$ans_eval3 = Compute($num2)->cmp(); Context("Fraction"); Context()->variables->are($var => 'Real');
Context()->noreduce('(-x)-y','(-x)+y');

$ans = Fraction($num2*$den1,$num1*$den2-$a*$den1*$den2)->reduce;
@answ = $ans->value;$ansNum = -$answ[0];$ansDen = $answ[1];$frac2 = Fraction($num2,$den2);
$left = Formula("$num1*$var/$den1-$a*$var");
$rightF = Formula("$frac2");
$right = "\frac{$num2}{$den2}";$rightP = "\frac{[$num2]}{[$den2]}";

@vArray = ($var); @aArray = ($ans);

($ansEqRef,$eqTypesRef) = contextSetup(~~@vArray, ~~@aArray);
##############################################

TEXT(beginproblem());

$tab =$SPACE.$SPACE.$SPACE;

Context()->texStrings;
BEGIN_TEXT
Solve the following equation, showing each required step.
$PAR$tab $tab $$\displaystyle left = right$$$PAR
State the LCD for the fractions in this equation: \{ans_rule \}

END_TEXT
Context()->normalStrings;

ANS($ans_eval1);$ans_hash1 = $ans_eval1->evaluate($inputs_ref->{ANS_NUM_TO_NAME(1)});

if (1 == $ans_hash1->{score}) { Context()->texStrings; BEGIN_TEXT$PAR
Now multiply the LCD into each term on both sides of the equation.
$PAR $$\quad \quad \displaystyle {den2(left) = den2 \cdot right}$$$PAR
\{ans_rule(20)\} $$=$$ \{ans_rule(20)\}

END_TEXT
Context()->normalStrings;

ANS($ans_eval2 );$ans_hash2 = $ans_eval2->evaluate($inputs_ref->{ANS_NUM_TO_NAME(2)});

ANS($ans_eval3 );$ans_hash3 = $ans_eval3->evaluate($inputs_ref->{ANS_NUM_TO_NAME(3)});

if (1 == $ans_hash2->{score} && 1 ==$ans_hash3->{score}) {

$ans_eval4 =$ansEqRef->[0]->cmp();
# [@instructions(~~@vArray)@]**
# [ [$left]=$right ]

BEGIN_PGML
Do the last step(s) and enter the solution of this equation. The answer could be in the form [ [$var] = ] ___ , *no solution*, or *all real numbers*. [_______________________________] END_PGML ############################################## answerCheck($ansEqRef, $eqTypesRef);$ans_hash4 = $ans_eval4->evaluate($inputs_ref->{ANS_NUM_TO_NAME(4)});

if (1 == $ans_hash4->{score}) { BEGIN_TEXT$PAR
Finally enter the $BBOLD solution set$EBOLD : \{ans_rule(10)\}

END_TEXT

$ss = Set("{$ans}");
ANS($ss->cmp()); } } } ##############################################$step1 = $den2*$num1/$den1;$step2 = $a*$den2;
$step3 =$step1-$step2; if ($ansDen!=1) {$ansOutput="-\frac{$ansNum}{$ansDen}";} else {$ansOutput="-$ansNum";} BEGIN_PGML_SOLUTION To clear fractions from an equation, multiply each side of the equation by a common denominator. For this problem, a common denominator is [[$den2]].

[
\begin{aligned}
\frac{[$num1][$var]}{[$den1]} - [$a][$var] &= \frac{[$num2]}{[$den2]} \\ [$den2] \cdot \left(\frac{[$num1][$var]}{[$den1]} - [$a][$var]\right) &= [$den2] \cdot \frac{[$num2]}{[$den2]} \\
[$den2] \cdot \frac{[$num1][$var]}{[$den1]} - [$den2] \cdot [$a][$var] &= [$den2] \cdot \frac{[$num2]}{[$den2]} \\
[$step1][$var] - [$step2][$var] &= [$num2] \\ [$step3][$var] &= [$num2] \\
\frac{[$step3][$var]}{[$step3]} &= \frac{[$num2]}{[$step3]} \\ [$var] &= [ansOutput] \end{aligned} ] [@summary(ansEqRef->[0],$left,$rightF);@]**

END_PGML_SOLUTION

ENDDOCUMENT();

Does anyone have an idea of what may have changed or what I can adjust to make it work now?

Thanks!

Paul
In reply to Paul Seeburger

### Re: contextFraction errors in old problem

by Paul Seeburger -
Ok, it seems that it was all due to a small, but apparently major, error.

Why it worked before I am not sure. But when I changed the very first line of code from

Context("Numeric");

to

Context("Fraction");

it worked fine.

Thanks!

Paul
In reply to Paul Seeburger

### Re: contextFraction errors in old problem

by Alex Jordan -
PCC doesn't use the problems that are in the PCC folder of the OPL. Instead, we have a local "PCC" library set up parallel to the OPL. We do this because it makes it easy for us to immediately edit our problems.

At one point, we added a portion of the PCC library to the OPL (into the Contrib folder). At some point shortly after that, OPL curators added tags and moved them into the PCC folder of the OPL.

We continue to edit our problems, and then roughly once a year, we add it all into the OPL's Contrib collection. However there is no process to carry those edits forward to the actual OPL once the first move was made. And we can't directly add our edits to the main OPL because of the tagging work that the curators made.

I don't see that you posted the file path/name of this file. If I had that, I would run diff to see the differences between .../OpenProblemLibrary/PCC/file and .../Contrib/PCC/file to see if maybe this is something we addressed.

I do see that your name and institution are in the metadata for the file. So I can't assume that this problem code is unedited from the version we put into the OPL in the first place. But if you have the file path, we could look to see.
In reply to Alex Jordan

### Re: contextFraction errors in old problem

by Alex Jordan -
I found this problem file in the Contrib folder:
webwork-open-problem-library/Contrib/PCC/BasicAlgebra/SolveLinearEquations/SolveLinearEquationFraction170.pg

It's the only possible relative the posted code, given the string in the comments:
"Solve equations like 5x/4-6x=3/8; answer is a fraction or integer."

There is no counterpart to this file in the OPL/PCC/ folder, only the Contrib folder.

The code is a lot different from what you posted. So I think you have a problem file that you significantly edited. (Likely, back in 2014 according to the metadata.) In the Contrib file that I can see, the context is Fraction, not Numeric. The commit that brought this file into the OPL is:
0e11583545a0c8970e7e5c4e446b7306e7a7f505
which also shows the file as using "Fraction". So I can only guess that you changed it to Numeric at some point. Or maybe way back when, you were accessing a draft version from the PCC library from even earlier than we had added it to the OPL.
In reply to Alex Jordan

### Re: contextFraction errors in old problem

by Paul Seeburger -
Thanks for your reply, Alex.

Yes, I did edit this problem extensively the last time I taught Intermediate Algebra (in 2014) and this spring I am teaching it again and trying to update/use the same sets of problems (but now on a much newer version of WeBWorK).

I am not sure whether this problem was accidentally changed from Context("Fraction") to Context("Numeric"), but I think it most likely that I had changed it on purpose (for some reason), and it just worked with the Context("Numeric") there on the old version of WeBWorK I was using at that time without giving an error.

It may just have been a case that the code worked at the time and I did not understand that it should have been different.

I will have to download your newer PCC contrib problems to see how they are different, and perhaps to make use of any newer problems you've added!

But I edited most of the PCC problems I used in 2014 fairly extensively to add extra steps, particularly in the word problems. So it may require me to compare the files side-by-side to find aspects that might be good to update.

It would be great to chat with you sometime about it, Alex.

Thanks again!

Paul
In reply to Paul Seeburger

### Re: contextFraction errors in old problem

by Alex Jordan -
Looking more closely at what you wanted here, I would recommend not using the PCC problem as a starting point. At this point in history, some things that were being accomplished by SolveLinearEquationPCC.pl are much easier to do now. Also, the structure of how to use the macros in there is just plain bad. But it was early days for us learning how to code for WeBWorK, and it worked well enough at the time.

Instead for you, I would use scaffold.pl to build the multiple parts of the problem. Then for the solution set, I would use contextFiniteSolutionSets.pl. That one lives in the PCC macros folder of the OPL. I need to make it better, but if you use the following syntax, it will always be OK:

$ans = List(Formula("{$ans}"));

If there is just one solution, and it is 2/3, this allows the student to enter it in many ways and get credit:

{2/3}
2/3
x=2/3

where "x" is the first variable in the context. By default, the latter two give credit but also give a message to suggest that the student use set braces in the future. That message can be turned off with a flag.

If there is more than one solution, the syntax doesn't need the "List" wrapper. And answers can be entered in many ways:

{2/3, 1/2}
2/3, 1/2
2/3 or 1/2
2/3 and 1/2
x = 2/3, 1/2
x = 2/3 or 1/2
x = 2/3, x = 1/2
x = 2/3 or x = 1/2
and more. Again, set braces will be promoted in a feedback message, even when credit is awarded for other things.

Combining this with scaffold.pl is what strikes me as the best way to build the problem you want to build. As of 26 Jan 2020. :)

In reply to Alex Jordan

### Re: contextFraction errors in old problem

by Paul Seeburger -
Wow, thanks for all this, Alex!

But in my case here, I only want to give credit for the solution set (with braces). That's what I asked for, and that's what I am so excited that WeBWorK can help me get students to do! They don't seem to learn this as quickly with paper and pencil assignments and red ink. But when they see that they don't get credit for {x = 2/3} on WeBWorK, they will ask me and learn.

Thanks!

Paul