## WeBWorK Problems

### Inequality intersection bug ### Inequality intersection bug

by Olivia Henders -
Number of replies: 3
I've been running into problems with the intersect function with a couple of inequalities. Basically, here's the code:
##############################
# Initialization

DOCUMENT();

# Contains a comma-separated list of macro filename strings.
# Each file contains functionality necessary for the mathematical
# functions being used in the problem.
# REQUIRED: Used for basic question and answer operations.
"PGstandard.pl",
# REQUIRED: Used for expression parsing.
"MathObjects.pl",
# Provides greater control over the layout of the problem.
"PGML.pl",
# Used to provide contextual help for how to type answers.
"contextInequalities.pl"
);

# Sets up basic problem information.
TEXT(beginproblem());

#############################
# Setup

Context("Inequalities-Only")->variables->are(x=>"Real");
$xBetween = Compute("2 <= x <= 5");$xNotEqual = Compute("x != 7/2");
$answer =$xBetween->intersect($xNotEqual); ############################# # Problem Text #-ULETH-# BEGIN_PGML i. Intersection What is [[$xBetween] \cap [$xNotEqual]]? [____________________][@ AnswerFormatHelp("inequalities") @]* *Correct Answer(s):* [|2 <= x <= 5 and x != 3.5|] *or* [|5 >= x >= 2 and 3.5 != x|] *Displayed Answer (after the due date):* [[$answer]]
END_PGML

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

# Setting this to 1 means that students will receive feedback on whether their
$showPartialCorrectAnswers = 1; ANS($answer->cmp());

#############################
# Solution

# Can be used to show the student the solution to the problem.

# Similar to BEGIN_PGML, marks the start of the solution text.
BEGIN_PGML_SOLUTION

# Solution explanation goes here. Layout as you would with the problem text.

# Marks the end of the solution text.
END_PGML_SOLUTION

# Marks the end of the problem document.
ENDDOCUMENT();



In theory, this should be giving the answer as 2 <= x <= 5 and x != 3.5. However, the answer that is actually being shown is 2 <= x < 5 and x != 3.5. We're speculating that this is either a problem with the display of the answer or something in the intersect function. Does anyone have any insight on this? ### Re: Inequality intersection bug

by Davide Cervone -
This turns out to be a bug in the output produced by the Inequalities context. The internal representation is correct, but the output is wrong. The problem is in trying to turn the internal form (equivalent to 2 <= x < 3.5 and 3.5 < x <= 5) back into the "and" format, where it is getting the closing inequality incorrect.

You could set the showNotEquals to 0 to prevent the conversion back to the "and" format, via

Context()->flags->set(showNotEquals => 0);

or you can modify pg/macros/contextInequalities.pl to include the line
          $interval->{close} =$x->{close};

between lines 698 and 699, to get
          $interval->{data} =$x->{data};
$interval->{close} =$x->{close};
$interval->{rightInfinite} = 1 if$x->{rightInfinite};

at that location. You can create copy of the macro file and put it in your courses templates/macros file if you don't have access to edit the copy in pg/macros.

I've made a pull request that includes the fix. You can get a copy of the updated file from there.  