interval arithmetic
SICP §2.1.4: a quantity given as a range [lower, upper] instead of a single
number. Addition, subtraction, multiplication and division act on ranges. An
interval result always encloses every value the expression can take, but it
overestimates the range whenever a variable appears more than once, because
each occurrence is treated as an independent interval.
Drag a variable's endpoints (or its bar) to change A, B, or C, type an
expression over + − × ÷ and parentheses, and step through the trace one
operation at a time. Two toggles let you replay two of the book's own
exercises: 4 corner products vs sign cases (ex. 2.11) for multiplication,
and signal an error vs return a bogus interval (ex. 2.10) when a divisor
spans zero. A third toggle shows intervals as [lower, upper] or as
center ± percent (ex. 2.12). With sampling on, 2,000 seeded random points
plus every corner combination of A, B, C are evaluated pointwise
(ordinary floats, not intervals) as a ground truth to compare against.
The parallel-resistors preset (ex. 2.14) is the load-bearing example: A×B/(A+B)
and 1/(1/A + 1/B) are equal as real-valued functions — sample both and their
true ranges coincide — but interval arithmetic gives them different bounds,
because the first formula repeats A and B while the second uses each once.
The pure part is wal-sh.tools.interval-arithmetic.core (host-neutral
.cljc: the parser, the five interval primitives, the trace/event log, and
Monte-Carlo sampling, tested on the JVM with test.check — sign-case
multiplication always agrees with the 4-corner method, and every computed
interval encloses its own sampled range). The browser adapter is
wal-sh.tools.interval-arithmetic.browser. Build: gmake tools-cljs; debug
in isolation: gmake dev-tool TOOL=interval-arithmetic.