This TypeScript-based calculator computes arithmetic operations over unions of disjoint intervals, addressing a fundamental weakness in standard interval arithmetic: operations that produce discontinuities, like division by an interval containing zero.
Consider dividing 1 by the interval [-1, 2]. In conventional interval arithmetic, this yields [-∞, +∞] or is marked undefined—both useless for practical bounds. The true range excludes [-1, 0.5), covering [-∞, -1] ∪ [0.5, +∞]. Standard methods fail here because they demand a single interval output, forcing massive overestimation of possible values.
This matters in verified computing, where you need tight bounds on numerical errors. Overly wide intervals erode confidence in results, especially in safety-critical fields like aerospace control systems or chemical process modeling. Historical research, from Ramon Moore’s 1966 book Interval Analysis onward, acknowledges this but rarely escapes single-interval constraints.
The Problem in Depth
Interval arithmetic tracks ranges of possible values to certify computations despite rounding errors and uncertainties. Add [1,2] + [3,4] = [4,6]; simple. But non-monotonic functions break it. Division by [a,b] where 0 ∈ [a,b] maps to multiple disconnected components.
Similar issues hit tan(x) near odd multiples of π/2, or sqrt over negative-inclusive intervals. Textbooks sidestep with “undefined” flags, halting expression evaluation. In 2017, Hermann Schichl et al. tackled this in their paper “Interval Unions” (Reliable Computing, vol. 23). They define arithmetic on sets representable as finite unions of closed intervals, preserving closure under basic operations.
Proofs show operations like addition or multiplication yield unions with bounded endpoint counts—typically no more than a handful extra intervals per op. This keeps representations compact for many expressions.
Implementation Details
The project delivers a dependency-free TypeScript library implementing this over IEEE 754 double-precision floats (JavaScript’s number). It uses outward rounding: endpoints round away from zero or toward infinity as needed, ensuring computed unions contain all true values despite float precision loss (about 15 decimal digits).
Here’s a taste via the library API. Represent intervals as [low, high]; unions as arrays thereof, sorted and disjoint:
import { IntervalUnion, add, div } from 'interval-union';
// Single interval
const x = IntervalUnion.from([-1, 2]);
const one = IntervalUnion.from([1, 1]);
// 1 / x
const result = div(one, x);
console.log(result.toString());
// Outputs: "(-∞,-1]U[0.5,+∞]"
The interactive calculator lets you build expressions visually—enter intervals, apply ops like sin, tan, exp—and see results as textual unions or plots. It handles 20+ functions, including transcendentals with branch cuts.
Performance: JS doubles limit precision, but outward rounding compensates. Union sizes grow linearly with discontinuities encountered; a chain of 10 divisions might yield 20 intervals, still manageable. No bigint or multiprecision here—stays lightweight.
Implications and Limitations
This advances practical interval methods. Tighter bounds enable better global optimization (e.g., branch-and-bound solvers exclude infeasible regions precisely) and verified integrations for ODEs in physics sims. In finance, model uncertain parameters—like volatility intervals—for robust VaR estimates without Monte Carlo’s sample variance.
Skeptical take: It’s not revolutionary—similar ideas exist in tools like IBEX (C++) or Gaol (C), with union support. JS limits it to prototyping; production needs C++/Rust for speed. Float outward rounding widens bounds slightly (by up to 0.5 ulp), but that’s standard. Complex expressions with many discontinuities could balloon unions to thousands, demanding pruning heuristics absent here.
Still, fair props: Open-source, browser-tryable, educates on a niche fixing real flaws. If you’re debugging numerical instability or need uncertainty quantification, test it. Push further with contractors or MCP integration for constraint solving. Word count: 612.