From: Martin Gregorie on
On Sat, 10 Jul 2010 19:19:59 +0000, Arved Sandstrom wrote:

>
> It's not real numbers and equality that's problematic - it's their
> floating point representation. If I undertook to carry out all my real
> number computations with rational numbers then at any point I'd be able
> to decide in my program whether real number a was equal to real number
> b.
>
Are you including the decimal expansion of rational numbers? If so, how
does this exact comparison deal with the set with terminal repeating
sequences given a fixed and/or limited length representation?

It seems to me that the rationals with terminal repeating sequences are
as problematic to handle as irrationals unless your numeric
representation can recognise and deal with the repeating unit explicitly,
e.g. you'd hold the mantissa as a prefix and a repeating unit.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
From: Arved Sandstrom on
Martin Gregorie wrote:
> On Sat, 10 Jul 2010 19:19:59 +0000, Arved Sandstrom wrote:
>
>> It's not real numbers and equality that's problematic - it's their
>> floating point representation. If I undertook to carry out all my real
>> number computations with rational numbers then at any point I'd be able
>> to decide in my program whether real number a was equal to real number
>> b.
>>
> Are you including the decimal expansion of rational numbers? If so, how
> does this exact comparison deal with the set with terminal repeating
> sequences given a fixed and/or limited length representation?
>
> It seems to me that the rationals with terminal repeating sequences are
> as problematic to handle as irrationals unless your numeric
> representation can recognise and deal with the repeating unit explicitly,
> e.g. you'd hold the mantissa as a prefix and a repeating unit.

No, I was not including the decimal expansion of rational numbers. It's
obvious that any given problem might not, from a practical standpoint,
admit of using rational numbers for all computations, in which case we
descend into the morass of questions such as the ones you just posed. :-)

As you likely gathered my point was rather more simple. You probably
_were_ told way back when that it's not kosher to compare real numbers
for equality; in fact, so was I on more than one occasion. But it's
perfectly OK to compare real numbers for equality; what we can't so
easily do is compare their floating-point representations that way(*),
and so we often end up doing what you mentioned, using a limiting value.
I'm not convinced that all the people who pass this advice on understand
the difference between real numbers and their representations.

Rational numbers happen to be a good example of how we can actually work
with real numbers in computer programs, and not worry about
representation inaccuracies. To the extent, alluded to above, that other
considerations such as performance don't intrude.

AHS

** And I don't doubt that you're perfectly aware of the difference.

--
The warning message we sent the Russians was a calculated ambiguity that
would be clearly understood.
-- Alexander Haig
From: Eric Sosman on
On 7/10/2010 3:19 PM, Arved Sandstrom wrote:
>
> It's not real numbers and equality that's problematic - it's their
> floating point representation. If I undertook to carry out all my real
> number computations with rational numbers then at any point I'd be able
> to decide in my program whether real number a was equal to real number b.

Rational representations can handle all the rational numbers,
yes (up to the point where the numerator and denominator grow too
big for virtual memory). But as I'm sure you're aware, the rational
numbers are an infinitesimal proportion of the real numbers: the log
of almost any number is irrational, and if the log isn't then the
number itself is (with one exception). Square roots, other roots,
trig functions, ... You've calculated the radius of that circle
there with perfect rational precision; what's its area?

Even with rational representations, many calculations will
eventually force you to accept the same kinds of approximations as
you must with floating-point. Rationals do have the advantage that
the precision is (usually) variable, in contrast to the fixed
precision of floating-point, so you can calculate the area of that
circle to a great number of digits if you wish. But it will take
you quite a long time to calculate the area exactly (there was a
Star Trek episode that hinged on essentially this point).

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Arved Sandstrom on
Eric Sosman wrote:
> On 7/10/2010 3:19 PM, Arved Sandstrom wrote:
>>
>> It's not real numbers and equality that's problematic - it's their
>> floating point representation. If I undertook to carry out all my real
>> number computations with rational numbers then at any point I'd be able
>> to decide in my program whether real number a was equal to real number b.
>
> Rational representations can handle all the rational numbers,
> yes (up to the point where the numerator and denominator grow too
> big for virtual memory). But as I'm sure you're aware, the rational
> numbers are an infinitesimal proportion of the real numbers: the log
> of almost any number is irrational, and if the log isn't then the
> number itself is (with one exception). Square roots, other roots,
> trig functions, ... You've calculated the radius of that circle
> there with perfect rational precision; what's its area?
>
> Even with rational representations, many calculations will
> eventually force you to accept the same kinds of approximations as
> you must with floating-point. Rationals do have the advantage that
> the precision is (usually) variable, in contrast to the fixed
> precision of floating-point, so you can calculate the area of that
> circle to a great number of digits if you wish. But it will take
> you quite a long time to calculate the area exactly (there was a
> Star Trek episode that hinged on essentially this point).
>
Absolutely, Eric, no argument from me. I believe that you and I and
Martin are all on the same sheet of music here. I know that Martin was
incorrectly told that real numbers cannot be compared for equality
because I've been told the same thing; using rational numbers is just
one example of how we can use reals in programming and compare for
equality. There's no question that actually using rationals is not
practical in many if not most applications. Although I'd argue that they
could be used more frequently than they currently seem to be.

AHS

--
The warning message we sent the Russians was a calculated ambiguity that
would be clearly understood.
-- Alexander Haig
From: Dr J R Stockton on
In comp.lang.java.programmer message <i1abvu$ig2$1(a)localhost.localdomain
>, Sat, 10 Jul 2010 17:51:58, Martin Gregorie <martin(a)address-in-
sig.invalid> posted:

>
>I'd always assumed that all programmers are taught this much about
==================================================
>dealing with floating point numbers regardless of what the language calls
>the type(s). Am I wrong in this assumption?
=

Yes, since the underlined part seems not to be true in practice.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.