# Possreps and numeric types

From: Marshall <marshall.spight_at_gmail.com>
Date: 25 Mar 2007 10:30:45 -0700

This is more of me trying to sort out my confusion about possreps.

Lately I have been thinking about numeric types. I find the situation tremendously annoying. On the one hand, one sorely wants to faithfully model as many of the algebraic properties of numbers as possible. On the other hand, the real numbers are only available as an approximation, floating point numbers, and operations on these approximations do *not* possess the vast majority of these algebraic properties. Harumph.

I read a paper recently that was an analysis of the situation in the Scheme programming language. Scheme made some ambitious forays into the so called "Numeric Tower" or the hierarchy of natural, integer, rational, etc.

The paper had some recommendations as to how to do it better still. I found the paper quite convincing.

In the past I've been quite unhappy with the canonical example of possreps, which seems to be the pair
(cartesian, polar) for some type, sometimes Point, or
Bob has suggested Complex. It disturbs me that a cartesian (1,1) is not a value that can be represented in polar coordinates in a computer, because the radius is sqrt(1^2+1^2) = sqrt(2) = a transcendental number. Since transcendentals have an infinite number of nonrepeating digits (think pi) they are not representable as a digit sequence in base 2, base 10, or otherwise.
(There are other ways of representing numbers,
as the solutions to equations, but these are quite complicated and have their own problems.)

So what if we had an internal representation for integer similar to java.math.BigInteger, and an internal representation for rational that was a pair of integers. We can define *exact* operators for these types for basic arithmetic functions. (But not for trigonometric functions, logs, and roots.) The implementation of these operators for integer is likely to be significantly faster than the ones for rational. This starts to sound like possreps to me. (Although I don't think of possreps as being used with subsets.)

Crazier still, the fact that some rationals are integers and some aren't starts to remind me of parsing a string as a number. A possrep for an integer could be a sequence of ascii digit characters. Then constructing (selecting) an integer from a string
(succeeding only if the string represents an integer)
is isomorphic to parsing the string into a number, a la parseInt or atoi or whatever. Integer isn't a subset of String, but the Integer possrep sequence- -digit-chars *is* a subset of the String possrep sequence-of-chars.

Wacky wacky.

Marshall Received on Sun Mar 25 2007 - 19:30:45 CEST

Original text of this message