I'm working on implementing interval arithmetic in Frink. Interval
arithmetic is cool--instead of a number being a single value, an
interval can contain a range of (real) values.
For example, a baseball is allowed to have a circumference between 9
and 9 1/4 inches, and a mass between 5 and 5 1/4 ounces. This will be
able to be directly expressed in Frink:
circumference = [9 inches, (9 + 1/4) inches]
mass = [5 ounces, (5 + 1/4) ounces]
You can then write the rest of your calculations normally:
radius = circumference / (2 pi)
volume = 4/3 pi radius^3
density = mass / volume
And Frink will track the range of possible values through all
calculations. The final density will itself be an interval.
It'll be very cool. You can write many programs in the normal way,
and just "feed" them with interval values, and Frink will automagically
calculate your error bounds for you.
Many old programs will just magically start to work with intervals.
They won't all work -- the problem is that some operators and functions
aren't always meaningful when applied to intervals.
For instance,
2 < [3,4] is true. 2 is smaller than the lower bound.
3.5 < [3,4] is indeterminate. (How to handle?)
5 < [3,4] is false?? Indeterminate? I dunno.
Not to mention the issues when you compare intervals to intervals.
The problem is that square brackets will be indistinguishable from an
array. So we have to come up with a different way to specify that
something's an interval. One could of course do:
a = new Interval[2,3]
But that's slightly cumbersome. So, what notation can we use for
intervals that's:
1.) Possible to type on an ordinary keyboard
2.) Uses only ASCII characters
3.) Unambiguous
4.) Doesn't force change of existing syntax.
5.) Quick to type
6.) Not too visually noisy
7.) Visually distinguishable from other constructs
8.) It should still kinda look like [2, 3]
We could use combinations of characters. _[2, 3] would work, I think.
We could use a special operator to indicate that something's an
interval. [3 interval 6]
We could use a function to create intervals.
i[2,3]
I like this one a lot, but it will prevent us from ever implicitly
multiplying a scalar and an array, because it's indistinguishable from
multiplying the complex unit "i" by an array. Not really a big deal.
In that case we'd just write i * [2,3]. However, a function call will
always be slower than something that's evaluated at compile time.
Something like [[ ]] doesn't work... it would be indistinguishable
from a 2-d array.
Also, there may be an interval triplet indicating a lower and upper
bound, and a best "center" value: [1, 1.5, 2]
So, who can come up with the best way to write intervals concisely?
Sun is working on a new language called "Fortress" (
http://research.sun.com/projects/plrg/fortress0618.pdf )
that plans on having intervals. They've decided to use some wacky
Unicode brackets from the 298x range,
http://www.unicode.org/charts/PDF/U2980.pdf , which is fine for display
in Java 1.5 and later, but bad if you're writing command-line programs
in an old dumb shell, or targeting older Java releases (in which AWT
GUIs were broken, and you weren't guaranteed to have a working font on
any given machine.)
--
Alan Eliasen | "It is not enough to do your best;
eliasen@... | you must know what to do and THEN
http://futureboy.homeip.net/ | do your best." -- W. Edwards Deming