Author here. Outward rounding to combat precision issues is what interval arithmetic is most known for (try 0.1+0.2 with "full precision mode" enabled), but that's really a shame in my opinion. Outward rounding is cool, but the "inclusion property", as it's known in research papers, works at every scale! This is what enables things like:
50 * (10 + [-1, 1])
[450, 550]
which is lovely, I think. Adding the union layer to it enables even cooler things, like the true inverse of the square function. Did you know it's not sqrt? Try 'sqinv(64)'.
I made interval calculator actually mostly as a way to test my implementation of interval union arithmetic [0], which I needed for another project: a backwards updating spreadsheet [1][2].
Very nice, thanks for sharing!
Maybe show which upper or lower values are included in the intervals?
A notation I am familiar with uses outward facing brackets if the value is not included in the interval. That always applies to infinity.
Applied to the cases here:
]-∞, -1] U [0.5, +∞[
The excluded interval in between becomes ]-1, 0.5[ then.
That’s how min (and analogously max) works, right?
min(A, B) = [lo(A,B), lo (hi(A), hi(B))].
Edit: idea: copy a formula from the results section to the input field if the user clicks/taps on it.
From reading the linked paper[0], It explains closed interval only. "An interval union is a set of closed and disjoint intervals where the bounds of the extreme interval can be ±∞".
It's possible to support that but it makes the code very very much more complicated. I've decided early on to not support it. Would be a cool addition though!
I just read up on interval arithmetic. I understand its desirable properties. Where in practice have you applied it? What’s a real world application for interval arithmetic?
It’s astonishing how nobody hasn’t mentioned abstract interpretation yet. Under classical static analysis, if you can “prove” that a variable does not have values in some unsound zones, you can e.g. “prove” soundness or apply further optimizations.
The interval abstract domain works under interval analysis with an algebra that’s the same of this calculator. It’s funny to implement something like that on source/binary level :)
Excellent!! I love interval arithmetic and also wrote a TS implementation for a graphing calculator project. Agree that it's very underrated, and I wish that directed rounding was exposed in more languages.
Yeah it's super interesting. Like you said, I learned that the IEEE 754 spec actually requires that complete implementations of floating point numbers expose a way to programmatically choose the rounding mode. As far as I know only C allows you to do that, and even then it depends on hardware support. For JS I had to use ugly typedarray casts. Which kinda only accidentally work due to endianess. But technically there should be an API for it!
There's other unused stuff in IEEE 754 like that: the inexact bit or signaling NaNs!
You could add a feature where it will compute the global optimum of any function of a small number of variables. Branch and bound with interval arithmetic works well for a small number of variables.
Disjoint unions of intervals seems like a nice thing to have
I made interval calculator actually mostly as a way to test my implementation of interval union arithmetic [0], which I needed for another project: a backwards updating spreadsheet [1][2].
[0] https://github.com/victorpoughon/not-so-float
[1] https://victorpoughon.github.io/bidicalc/
[2] https://news.ycombinator.com/item?id=46234734
https://youtu.be/UxGxsGnbyJ4?si=Oo6Lmc4ACaSr5Dk6&t=1006
https://memalign.github.io/m/formulagraph/index.html
Some detail on how this works, including links to the relevant interval math code:
https://memalign.github.io/p/formulagraph.html
Applied to the cases here:
]-∞, -1] U [0.5, +∞[
The excluded interval in between becomes ]-1, 0.5[ then.
That’s how min (and analogously max) works, right? min(A, B) = [lo(A,B), lo (hi(A), hi(B))].
Edit: idea: copy a formula from the results section to the input field if the user clicks/taps on it.
[0]: https://www.ime.usp.br/~montanhe/unions.pdf
Though you are inherently losing precision: there are values in the output interval which don't have a corresponding input that causes this output.
The interval abstract domain works under interval analysis with an algebra that’s the same of this calculator. It’s funny to implement something like that on source/binary level :)
There's other unused stuff in IEEE 754 like that: the inexact bit or signaling NaNs!
Disjoint unions of intervals seems like a nice thing to have