WeBWorK Problems

Uninitialized value $a in division (/) in contextFraction.pl

Uninitialized value $a in division (/) in contextFraction.pl

by Paul Seeburger -
Number of replies: 8
I am using a problem developed by authors at PCC to have students enter the solution set, {4}, along with their solved solution to equations, in the form, "x = 4".

Somehow it works without errors when the correct answer is entered in my second answer blank (asking for the solution set), but if the incorrect fraction is entered in the solution set answer blank, the following warning is displayed.  Interestingly, if the student enters an integer in braces, this error is not shown.

WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

Warning messages

  • Use of uninitialized value $a in division (/) at line 680 of [PG]/macros/contextFraction.pl

Request information

TimeThu Sep 11 12:28:30 2014
MethodPOST
URI/webwork2/MTH_104_Intermediate_Algebra/HW4-SolvingLinearEquations/3/


Here is the code for the problem, but note that it is using a macro from PCC (found in the OPL macro folder under PCC) named SolveLinearEquationPCC.pl.

# WeBWorK problem written by Carl Yao
# Portland Community College
#
# Solve equations like ax + b= cx + d; the solution is a fraction.
# Last updated: Kling 7/21/13; Jordan 7/20/13; Hughes 7/2/13 Yao, 6/27/13
# ENDDESCRIPTION

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

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

DOCUMENT();

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

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

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

do {
$a = random(2,10,1);
$b = random(2,10,1);
$c = random(2,10,1);
$d = random(2,10,1);
} until (abs($c-$a)>1 and $b != $d and ($d-$b)/($c-$a) != int(($d-$b)/($c-$a)) );


$ans = Fraction($d-$b,$a-$c);

$left = Formula("$a $var + $b");
$right = Formula("$c $var + $d");


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


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

TEXT(beginproblem());

BEGIN_PGML

[@instructions(~~@vArray)@]**

    [`` [$left]=[$right]  ``]  

    [_______________________________] 

Note that you should enter your answers using reduced fraction form, where needed.
END_PGML

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

answerCheck($ansEqRef, $eqTypesRef);

##############################################
BEGIN_TEXT
$PAR
Enter the $BBOLD solution set$EBOLD: \{ans_rule(10)\}
END_TEXT

$ss = Set("{$ans}");
ANS($ss->cmp());


BEGIN_PGML_SOLUTION

To solve this equation, use addition and subtraction to move variable terms to one side and constant terms to the other. Then divide.
    [``
\begin{aligned}
  [$left] &= [$right]\\
  [$left] \mathbf{{}-[$b]}&= [$right]\mathbf{{}-[$b]}\\
  [$a][$var] &= [$c][$var]+[$d-$b]\\
  [$a][$var] \mathbf{{}-[$c][$var]}&= [$c][$var]+[$d-$b]\mathbf{{}-[$c][$var]}\\
  [$a-$c][$var] &= [$d-$b]\\
  \frac{[$a-$c][$var]}{[$a-$c]} &= \frac{[$d-$b]}{[$a-$c]}\\
  [$var] &= [$ans]
\end{aligned}
    ``]

[@summary($ansEqRef->[0],$left,$right);@]**

END_PGML_SOLUTION




ENDDOCUMENT();

In reply to Paul Seeburger

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Alex Jordan -
Are you saying that the "x = 4" part of the problem is functioning, but the part that asks for "{4}" is not? And are you saying that entering something like "{8/2}" is causing the error?

I'll investigate this soon. Can you tell me what versions of PG and WeBWorK you are using in case it ends up mattering?

It's nice to see that our problems are being used elsewhere. I recently pushed revisions up the the Contrib folder of the OPL, if you haven't pulled from there recently. I don't think it affects these problems, but it may affect others that you are using.
In reply to Alex Jordan

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Paul Seeburger -
Hi, Alex!

Thanks for sharing these problems!  It has made my job of creating problem sets for my Intermediate Algebra course a lot easier to get started on.

I did just download them this past week, so I expect I have the latest version.

Yes, the "x=4" part is functioning just fine, and if the student gets the second part with the solution set "{4}" correct, then it functions fine too.

In fact, the only time the error comes up is when the student enters an incorrect fractional answer in the braces.  If the answer is fractional and they enter the correct fraction, no error is shown, but if they enter the incorrect fraction, it is shown.

I am using theme: math4 | ww_version: 2.8 | pg_version: 2.8.1

Thanks!
In reply to Paul Seeburger

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Paul Seeburger -
Another odd issue here is that when an unreduced version of the correct answer is entered as a fraction, no error is shown, and the student is given full credit for the problem.

Is there a way to force the answer to be treated as a Fraction that needs to be reduced while it is within a Set (with braces)?

I want {5} to be accepted, but not {30/6} for example.  I had a student who got credit for the {30/6} form.
In reply to Paul Seeburger

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Alex Jordan -
I believe this was an earlier problem that we wrote in summer 2013 before we had fully developed some macro tools that make everything cleaner. Specifically, I think I can change this block of problems to use bizarroArithmetic.pl in the solution set part. It would be great if a Set object could contain Fraction objects, but as far as I know it's not something that can be done at the moment.

A bizarroArithmetic solution to the issue will have one less-than-ideal thing about it. If the answer is actually "{5}", but a student enters something like "{20/5}" (an incorrect, unreduced fraction) they will be told their answer is incorrect. They will not be told that their answer is unreduced, as would happen with contextFraction. I don't think this is a big deal, and to some, it might be preferable.

I can't act on this until tomorrow. I'll post again here once the issues are resolved and I have submitted a pull request to the OPL. Even then, it may be a day or so before the pull request is accepted.
In reply to Paul Seeburger

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Alex Jordan -
I think I found this problem in our library. Is it SolveLinearEquationFraction320.pg?

Asking for the solution set style answer like this is not part of our version of these problems. At least I cannot find the string "
Enter the $BBOLD solution set$EBOLD" in our library. Somewhere between when we released these problems and you started using them, someone inserted the part:

BEGIN_TEXT
$PAR
Enter the $BBOLD solution set$EBOLD: \{ans_rule(10)\}
END_TEXT

$ss = Set("{$ans}");
ANS($ss->cmp());

Or it is possible that we had that block in there at some earlier stage of development and now it has been removed. But this would be strange since we are in the practice of always using PGML whenever possible.

Still, I think that this can be made to work by adding bizarroArithmetic.pl to the macros load. This seems to work, but I have not done thorough testing. Replace the snippet above with this:

Context("Interval");
Parser::Number::NoDecimals();
Context()->operators->set(
'/' => {class => 'bizarro::BOP::divide', isCommand => 1},
'//' => {class => 'bizarro::BOP::divide', isCommand => 1},
' /' => {class => 'bizarro::BOP::divide', isCommand => 1},
'/ ' => {class => 'bizarro::BOP::divide', isCommand => 1},
);

Context()->flags->set(formatStudentAnswer => 'parsed');

BEGIN_PGML
[$PAR]*
Enter the *solution set*: [___________]

END_PGML

$ss = Compute("{$ans}");
ANS($ss -> cmp(
checker=>sub{
my ( $correct, $student, $ansHash ) = @_;
return 0 if $ansHash->{isPreview};
$student = $ansHash->{student_formula};
$correct = $ansHash->{correct_ans};
$student = Formula("$student"); $correct = Formula("$correct");
return 0 unless ($correct == $student);
Context()->flags->set(bizarroDiv=>1);
delete $correct->{test_values}, $student->{test_values};
my $OK = (($correct == $student) or ($student == $correct)) ;
Context()->flags->set(bizarroDiv=>0);
Value::Error("Your answer is correct, but please simplify it further") unless $OK;
return $OK;
}));

Context("Fraction"); #needed for @summary to work in the solution


In reply to Alex Jordan

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Paul Seeburger -
Thanks so much, Alex!

I will give this solution a try.  It sounds like it may address both my issues (the error and the non-reduced correct answers being allowed).

I am the one who had added this new code to the problem trying to get my students to give the solution set as well to reinforce the habit I am trying to get them to form for the course.

I had never used PGML before, so I used the normal code I am used to.  I am not sure of the benefits of PGML yet, but I will have to investigate it further.

As I said before, the problems from PCC have been a great starting point for my problems.

I have also adapted a number of the fractional equation problems so that the student is asked for the LCD first, then shown both sides of the equation multiplied by the LCD they provided and asked for the cleared fraction form of each side of the equation.  Finally they are asked to solve the equation, using your "x = 8" form and then asked for the solution set, "{8}".

It seems to be really helping my students to practice this technique of clearing the fractions first to solve these equations, which was my goal.

Thanks again for making these problems available.

Paul
In reply to Paul Seeburger

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Alex Jordan -
Your improvements sound great. If you apply them and submit a pull request to https://github.com/Alex-Jordan/PCC, I'd bring them into the fold. Feel free to add your name to the list of authors.

Periodically I submit pull requests to the OPL after copying subfolders at https://github.com/Alex-Jordan/PCC into openwebwork/webwork-open-problem-library/Contrib/PCC.

I don't know how long it will be until these problems are in the actual OPL. There is a lot of them, and a lot of checking to do with tagging. Plus I'd really like to see them tagged with Common Core numbering. But until then, this would be the best way to share any improvements. After that, I'm not sure if it would be better to submit to the OPL itself.

Regarding PGML, mainly I think that it is makes for more more human readable code. Also, there are some things that you can do with less effort, like bold text, italicized text, indenting, and centering.
In reply to Alex Jordan

Re: Uninitialized value $a in division (/) in contextFraction.pl

by Paul Seeburger -
Yes, Alex, this code seems to be working great!  Thanks so much!

I'll be glad to share them with you, once I get them working correctly.  As I posted in another question in the forum, I am still trying to adjust the scoring of the parts.  It gets thrown off because of the hidden parts, and it would probably make sense to have somewhat smaller percentage of the 100% go to finding the LCD than to rewriting the equation, for example.

I am also still trying to get more comfortable using the pull request stuff on github.  I did it once with Paul Pearson sitting next to me, but I will have to take some time to try it again sometime.  I would really love to be able to share more of my problems with the OPL.

Paul