Interval Evaluator

This shows how to use intervals in a problem.

Complete Code

Download file: IntervalEvaluators.pg

PG problem file

Explanation

DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');

Preamble

These standard macros need to be loaded.
Context('Interval');
# to allow open or closed intervals, uncomment
#    the following line.
# Context()->flags->set(ignoreEndpointTypes=>1);

$int = Compute('(1,3)');

Setup

In the problem set-up section of the file, we set the Context to be the Interval context. Note that we can relax checking of endpoints in the Context or in the actual answer checking, as noted below.

Once we’re in the Interval context, we can define intervals as we’d expect: as shown here, or with limits at infinity:

 $int2 = Compute('(-inf,1]');

This would give the interval from negative infinity to 1, including the point at one. Note the Context flag to make endpoint checking “fuzzy.”

BEGIN_PGML
On what interval is the parabola [`y = (1-x)(x-3)`]
above the [`x`]-axis?

For [`x`] in [_____]{$int}
END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.