WeBWorK Problems

TeX rendering strangely in College of Idaho Algebra Problem

TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -
Number of replies: 11
I am having trouble with a problem from the College of Idaho.  It appears to be the most up-to-date version and I am on WeBWorK server running version 2.14.

The problem is:
Library/CollegeOfIdaho/setAlgebra_06_02_AddSubRationalExpressions/62IntAlg_19_AddSubRatExp.pg

From the code:
$den2 = Formula("y + $d")->reduce;
$f2 = Formula("($c) / $den2")->reduce->TeX;
When $d = 2, it is rendering the TeX from $f2 as y2 instead of y + 2.
 
The code for the whole problem is below.

Might it be from the bizarroarithmetic?

Any insights?

Thanks!

Paul

##DESCRIPTION
##  Rational Expressions and Functions: Add and Subtract
## 
##ENDDESCRIPTION
## DBsubject(Algebra)
## DBchapter(Rational equations and functions)
## DBsection(Simplifying)
## Institution(The College of Idaho)
## Author(RA Cruz)
## MLT(Add_fractions)
## Level(2)
## TitleText1('Essentials of Intermediate Algebra')
## AuthorText1('Blitzer')
## EditionText1('1')
## Section1('6.2')
## Problem1('')
## KEYWORDS('rational expressions','rational functions')
## Date: 2007/11 updated 2017/10 --rac
DOCUMENT(); # This should be the first executable line in the problem.
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "bizarroArithmetic.pl",
  "PGcourse.pl"
);
TEXT(beginproblem());
######################################
#  Setup
Context("Numeric");
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},
   '*' => {class => 'bizarro::BOP::multiply', isCommand => 1},
   '* ' => {class => 'bizarro::BOP::multiply', isCommand => 1},
   ' *' => {class => 'bizarro::BOP::multiply', isCommand => 1},
   '+' => {class => 'bizarro::BOP::add', isCommand => 1},
   '+ ' => {class => 'bizarro::BOP::add', isCommand => 1},
   ' +' => {class => 'bizarro::BOP::add', isCommand => 1},);
# --- Form: a/(y+b) + c/(y+d) ------------------------------------- 
#  Note: b neq d, and (ad+cb)/(a+c) neq b nor d
#  Answer: ((a+c)y+(ad+cb))/(y+b)(y+d)
Context()->variables->are(y=>'Real');
$a = random(2,5,1);
$b = random(-5,-1,1);
$d = non_zero_random(-7,7,1);
if ($b==$d) {$d = random(1,7,1);}
do {$c = random(1,8,1);}
  until ( gcd(($a*$d+$c*$b),($a+$c)) ==1 );
$den1 = Formula("y + $b")->reduce;
$f1 = Formula("($a) / $den1")->reduce->TeX;
$den2 = Formula("y + $d")->reduce;
$f2 = Formula("($c) / $den2")->reduce->TeX;
# --- For the Solution----------------------------------
$lcd = Formula("(y+$b)(y+$d)")->reduce;
$mult1 = $den2;
$mult2 = $den1;
$num1 = Formula("$a y + ($a*$d)")->reduce;
$num2 = Formula("$c y + ($c*$b) ")->reduce;

######################################
#  Main text
BEGIN_TEXT
Perform the indicated operation.  Note that the denominators 
are different.  Simplify the result, if possible. 
\[ $f1 + $f2 \]
$PAR
Answer:  \{ ans_rule(25) \} 
$BR $BR
\{ 
knowlLink("help(entering your answer)", 
value=>'Enter your answer  '.
'in the form: ${BITALIC}numerator/denominator$EITALIC. '.
'Use parentheses as needed.'.
'$BR Your answer should be in reduced form with integer ' .
'coefficients. For example:'.
'$BR $SPACE $SPACE If the correct, reduced answer is: 3/(2x+4)'.
'$BR $SPACE $SPACE The following will be scored as incorrect: 9/(6x+12) or 1.5/(x+2) or 1/(2/3x+4/3) or (3/2)(1/(x+2))'
) \}
END_TEXT
######################################
#  Answer
$showPartialCorrectAnswers = 1;
$errText = "Your answer is equivalent to the correct answer, but ".
                 "needs to be simplified further or is not in the expected format. $BR".
                 "See ${BBOLD}help(entering your answer)$EBOLD ".
                 "given below for the expected format.";
$answer = Formula("(($a+$c)*y+($a*$d+$c*$b))/((y+$b)*(y+$d))")->reduce;
#--The alternative answer has the factors multiplied out----------
$answerAlt = Formula("(($a+$c)*y+($a*$d+$c*$b))/(y^2+($b+$d)y+($b*$d))")->reduce;
ANS($answer -> cmp(
   checker=>sub{
      my ( $correct, $student, $ansHash ) = @_;
      return 0 if $ansHash->{isPreview} || $correct != $student;
      $student = $ansHash->{student_formula};
      $correct = $correct->{original_formula} if defined $correct->{original_formula};
      $student = Formula("$student"); $correct = Formula("$correct");
      return 0 unless ($correct == $student);
      Context()->flags->set(bizarroDiv=>1,bizarroMul=>1,bizarroAdd=>1);
      delete $correct->{test_values};
      delete $student->{test_values};
      $student = Formula("$student"); $correct = Formula("$correct"); 
      $correctAlt = Formula("$answerAlt");
      my $OK = ($correct == $student || $correctAlt == $student);
      Context()->flags->set(bizarroDiv=>0,bizarroMul=>0,bizarroAdd=>0);
      Value::Error($errText) unless $OK;
      return $OK;
})); 
######################################
#  Solution
Context()->texStrings;
BEGIN_SOLUTION
$BR
The LCD is \($lcd\).
\[
\begin{aligned} 
$f1 + $f2 & = $f1\cdot \frac{$mult1}{$mult1} + $f2 \cdot \frac{$mult2}{$mult2} \\
          & = \frac{$num1}{$lcd} + \frac{$num2}{$lcd} \\
          & = $answer               
\end{aligned}
\]

END_SOLUTION
Context()->normalStrings;
ENDDOCUMENT();

In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -
Correction:

When I said,
"When $d = 2, it is rendering the TeX from $f2 as y2 instead of y + 2."

the fraction does render, but it's actually rendering just the denominator of the fractions incorrectly here without the plus sign. Oddly it does not have trouble with $f1 in this problem which looks to be formatted the same except it has a minus sign for the random seed I am looking at.

The minus sign renders correctly, but NOT the plus sign.

This random seed is 1331.

Thanks!

Paul
In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Alex Jordan -

bizarroArithmetic has nothing to do with how a MathObject is represented as a (TeX or plain text) string.

If:
$d = 2;

And:
$den2 = Formula("y + $d")->reduce;

And
$f2 = Formula("($c) / $den2")->reduce->TeX;

Then $f2 is the same as:
$f2 = Formula("($c) / y + 2")->reduce->TeX;
because you are passing a double quoted string to Formula().

And I would guess you were expecting:
$f2 = Formula("($c) / (y + 2)")->reduce->TeX;

I don't know what this has to do with the "y2" issue, but my first observation is that "$den2" is not actually used as a denominator in the construction for $f2.
In reply to Alex Jordan

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -

Thanks for the attempt, Alex.

But the parentheses did not seem to change the results at all, although it would make more sense to me too.  I even tried it with a direct:

$f2 = Formula("$c / (y + $d)")->reduce->TeX;

As long as $d is positive, the plus sign does not render!  But if it's negative, then the minus sign renders fine!

Note that this is exactly the problem in the OPL.  It's a bug in this problem that I am trying to fix.  It used to work fine.  It was created by Robin Cruz and I see it was modified again by Robin in 2017.

Paul

In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -
Ok, I think I have it working now... and it did somehow have to do with the bizarro arithmetic.

I removed the following lines near the top of the problem and it works as intended.

'+' => {class => 'bizarro::BOP::add', isCommand => 1},
'+ ' => {class => 'bizarro::BOP::add', isCommand => 1},
' +' => {class => 'bizarro::BOP::add', isCommand => 1},);

Any idea why?

I'm not sure why the '+' operation was being bizarroed here anyway. Perhaps this breaks the problem in another way?

Paul
In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -
The previous problem in Robin's problem set
Library/CollegeOfIdaho/setAlgebra_06_02_AddSubRationalExpressions/62IntAlg_18_AddSubRatExp.pg
is very similar and does not seem to have any issues with rendering the plus sign in an almost identical construction.

Could using the variable 'y' cause any issues here?

Paul
In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Alex Jordan -

Hmm, I guess the string method on a Formula like that must include wrap-around parentheses.

I don't see the behavior. Here is the problem with our server, with that seed:
https://webwork.pcc.edu/webwork2/html2xml?&problemSeed=1331&answersSubmitted=0&sourceFilePath=Library/CollegeOfIdaho/setAlgebra_06_02_AddSubRationalExpressions/62IntAlg_19_AddSubRatExp.pg&displayMode=MathJax&courseID=anonymous&userID=anonymous&course_password=open&outputformat=simple

For me it comes out as
3/(y - 4) + 2/(y + 2)

Are you viewing math in "images" mode? It's one thing that might explain it. Sometimes there is a malformed .png image, and it gets cached, and you keep seeing it. Try things like (1) viewing with MathJax (2) adding $refreshCachedImages=1; and (3) going into the server where these images are stored and clearing them (I forget right now exactly where that is). If this is the issue, I don't know what causes it. But these things should fix it. And in any case, I think it's not something other users see because I think the cached image is specific to the user.




In reply to Alex Jordan

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Seeburger -

No, Alex, it was in MathJax mode.

And a number of my students had trouble with it displaying incorrectly.  Basically any of them where $d came out such that the expression was 'y + a number' in the denominator.

Perhaps the problem has been fixed since the version on my server?

Was there anything different in the code of the problem?  The problem used to work fine on my server too, so perhaps it's just something odd about my server.

Paul

In reply to Paul Seeburger

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Alex Jordan -

I'm just shooting in the dark now since I don't see the issue on my server.

(1) If you are seeing the issue in MathJax, what happens when you right-click on the expression and show the LaTeX source for it? If that source looks consistent with what you see when it is rendered, that would help rule out something is wrong with your MathJax version. On the other hand, if the LaTeX source looks right, but it is rendering badly, that seems like a smoking gun for your MathJax needing an upgrade.

(2) If you switch to "images", do you see it?

(3) What do you see if you put TEXT($f2) at the end of the problem?

(4) Similarly, TEXT(Formula("($c) / $den2"), Formula("($c) / $den2")->reduce, Formula("($c) / $den2")->reduce->TeX);

In reply to Alex Jordan

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Paul Vojta -
I'm able to see the issue.
For (1), I don't see how to do that.
(2): Yes.
(3): \frac{2}{2y}
(4): 2/(y*2)2/(2*y)\frac{2}{2y}
In reply to Paul Vojta

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Alex Jordan -
OK, on my server, this problem has been edited from the repository version. I don't recall doing it, but git says I made a commit in February 2018 to this problem file (and many others in that folder) where the diff is:

- '+ ' => {class => 'bizarro::BOP::add', isCommand => 1},
- ' +' => {class => 'bizarro::BOP::add', isCommand => 1},);
+ #'+ ' => {class => 'bizarro::BOP::add', isCommand => 1},
+ #' +' => {class => 'bizarro::BOP::add', isCommand => 1},
+);

and the commit message is "alternate addition operators causing bugs in problems; commented out".

Somehow declaring a class for the operators '+ ' and ' +' leads to problems. It does not appear to be a bizzaroArithmetic thing, because I see the same behavior if I set these operators to have `class => 'Parser::BOP::add'` (the regular non-bizarro addition).

I'm unsure if the long-term solution is to push my commit to the OPL, or if @dpvc should weigh in with a better understanding of why declaring a class for the operators '+ ' and ' +' is an issue in the first place.
In reply to Alex Jordan

Re: TeX rendering strangely in College of Idaho Algebra Problem

by Sean Fitzpatrick -

Definitely a WeBWorK bug and not MathJax. Here's what the solution renders as when you set the display mode to tex commands:


\begin{aligned} 
\frac{4}{y-2} + \frac{7}{2y} & = \frac{4}{y-2}\cdot \frac{y2}{y2} + \frac{7}{2y} \cdot \frac{y-2}{y-2} \\
          & = \frac{4y8}{\left(y-2\right)\!\left(y+2\right)} + \frac{7y-14}{\left(y-2\right)\!\left(y+2\right)} \\
          & = \frac{11y-6}{\left(y-2\right)\!\left(y+2\right)}               
\end{aligned}

The denominator displays (for me) as 2y in the problem. In the solution we can see it start as 2y, then change to y2, and then later to y+2!