## PREP 2014 Question Authoring - Archived

### Inconsistent error messages for single vs unions of intervals

by Mary Cameron -
Number of replies: 3

If you run the code below, and supply similarly incorrect intervals (0,4) and (0,8),  the message for the first is “The type of interval is incorrect”, but no similar message appears for the second interval, even though it is likewise incorrect.  Is there some way this message can be made to appear?

As you can see in the code below, the first interval was defined in a single Interval statement (0,4], whereas the second interval is a result of a ‘reduced’ union of (0,4)U[4,8].  In the latter case, entering (0,4)U[4,8) as an answer leads to the message “Your union can be simplified by combining intervals”, but entering (0,8) does not produce the (desired) message “The type of interval is incorrect”.

Thanks,

Mary

######################### Initialization
DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
);
TEXT(beginproblem());

#########################  Setup
Context("Interval");

$d[0] = Interval ( "(0, 4] ");$d[1] = Interval ( "(4, 8] ");

Context()->flags->set(reduceUnions => 1);
$d2 = Union($d[0], $d[1]); Context()->flags->set(reduceUnions => 0);$dlong = Union ( $d[0],$d[1] );
Context()->flags->set(reduceUnions => 1);

######################### Main Text
Context()->texStrings;
BEGIN_TEXT
Enter the following intervals:
defined as one interval $$d[0]$$ =  \{ ans_rule(30) \}  $defined as a union of two intervals $$d2$$ = \{ ans_rule(30) \} END_TEXT Context()->normalStrings; ########################## Evaluate Context("Interval"); ANS($d[0] -> cmp   (showEndTypeHints => 1, showEndpointHints => 1)   );
ANS(  $d2 -> cmp (showEndTypeHints => 1, showEndpointHints => 1) ); ########################## Solution Context()->texStrings; BEGIN_SOLUTION The domain is $$dlong$$ which simplifies to $$d2$$$BR
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version');
ENDDOCUMENT();

### Re: Inconsistent error messages for single vs unions of intervals

by Paul Pearson -
Hi Mary,

#####  begin code
$d[0] = Interval("(0,4]");$d[1] = Interval("(4,8]");
Context()->flags->set(reduceUnions => 1);
$d2 = Union($d[0], $d[1]); ##### end code will not generate an error message when (0,8) is entered, but if the definition of$d2 is replaced by

$d2 = Interval("(0,8]"); then the appropriate error message is generated. I'm not sure why$d2 does not generate an error message when constructed as a Union.

My suggestion would be to go low-tech by precomputing $d2 = Interval("(0,8]"); rather than using MathObjects as a computer algebra system via$d2 = Union( $d[0],$d[1]);.  MathObjects are designed to be useful for writing problems and checking answers.  That some MathObjects can do some computer algebra stuff is very useful and a blessing.

Best regards,

Paul Pearson

### Re: Inconsistent error messages for single vs unions of intervals

by Davide Cervone -
As Paul pointed out, the reason for the difference is the distinction between intervals and unions. A union is a list of intervals, and so you are having the same distinctions as I pointed out on Monday between a list and a single element. MathObjects can give more detailed messages about individual elements than it does about lists, because it doesn't know which element of a list the student's answer is supposed to be when it is not a perfect match. it is true that singleton lists could be handled as thought they were the single element, but then that would lead to inconsistent messages and the ability of students to use that to determine whether the correct answer is one element or more than one.

In your case, even though the union turns out to be a single interval, you have used Union() explicitly, so have forces MathObjects to generate a union from your single interval. Had you done

    $d2 = Compute("$d[0] U $d[1]");  or better $d2 = $d[0] +$d[1];

then \$d2 would have been an Interval, and you would get the messages you wanted. But because you specifically asked for a Union(), MathObjects obliged and you ended up with a union of one interval.