HP Forums

Full Version: Interval Arithmetic
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The arithmetic functions for intervals are defined as:

[a, b] + [c, d] = [a + c, b + d]
[a, b] - [c, d] = [a - d, b - c]
[a, b] × [c, d] = [min(a × c, a × d, b × c, b × d), max(a × c, a × d, b × c, b × d)]
[a, b] ÷ [c, d] = [min(a/c, a/d, b/c, b/d), max(a/c, a/d, b/c, b/d)]

INTERVALHELP: help screen for interval arithmetic functions
INTERVALSUB: subtracting two intervals
INTERVALMUL: multiply two intervals
INTERVALDIV: divide two intervals

In the Home mode, use the curly brackets (used for lists { }), to type the intervals. For example, the interval [ 81.8, 82.2 ] would be typed {81.8,82.2}.

Code:
```EXPORT INTERVALHELP() BEGIN // 2022-12-22 EWS PRINT(); PRINT("Interval Arithmetic"); PRINT("Use curly brackets {}"); PRINT(""); PRINT("INTERVALADD({a,b},{c,d})"); PRINT("add intervals"); PRINT(""); PRINT("INTERVALSUB({a,b},{c,d}"); PRINT("subtract intervals"); PRINT(""); PRINT("INTERVALMUL({a,b},{c,d})"); PRINT("multiply intervals"); PRINT(""); PRINT("INTERVALDIV({a,b},{c,d})"); PRINT("divide intervals"); END;```

Code:
```EXPORT INTERVALADD(v1,v2) BEGIN RETURN v1+v2; END;```

Code:
```EXPORT INTERVALSUB(v1,v2) BEGIN RETURN v1-REVERSE(v2); END;```

Code:
```EXPORT INTERVALMUL(v1,v2) BEGIN LOCAL v3; v3:=CONCAT(v1*v2,v1*REVERSE(v2)); RETURN {MIN(v3),MAX(v3)}; END;```

Code:
```EXPORT INTERVALDIV(v1,v2) BEGIN INTERVALMUL(v1,1/REVERSE(v2)); END;```

Example

Interval 1 = {13, 29}
Interval 2 = {10, 14}