comp.lang.ada
 help / color / mirror / Atom feed
* [Q] Portability of <= and >= with real operands
@ 1996-11-29  0:00 JP Thornley
  1996-11-29  0:00 ` Robert Dewar
  1996-12-01  0:00 ` Tucker Taft
  0 siblings, 2 replies; 11+ messages in thread
From: JP Thornley @ 1996-11-29  0:00 UTC (permalink / raw)



I'm having difficulty understanding the statements in the Ada 
Quality and Style Guide on the portability of relational expressions 
with real operands:-

Section 5.5.6 - "... the use of <= is more portable than either < or ="

Section 7.2.7 (in the Chapter on Portability) -
   "Strict relational comparisons (<, >, =, /=) are a general problem
    with computations involving real numbers"
and there is an implication (but no direct statement) that the inclusive 
comparisons are not a problem.  (The Ada 83 version did have a statement 
that <= and >= evaluated the same in all implementations but this has 
gone from the Ada 95 version.)

Clearly = and /= are to be avoided, but I can't see why < and > are less 
portable than <= and >=.

My understanding is based on the result being well defined (portable) if 
it is the same no matter which value is taken from the model intervals 
of the operands and undefined (non-portable) if this is not the case.  
But I can't make the quoted statements from the Guide fit with this, so 
what am I missing?

(The reference (in the 7.2.7 rationale) to Sections G.4.1 and G.4.2 of 
the Ada 95 Rationale hasn't helped me much - there isn't any discussion 
of relational expressions in there.)

[BTW, the Guide carefully refers to "real" operands throughout these two 
sections - is there really no difference between floating and fixed?] 

Phil Thornley

-- 
------------------------------------------------------------------------
| JP Thornley    EMail jpt@diphi.demon.co.uk                           |
------------------------------------------------------------------------






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-11-29  0:00 [Q] Portability of <= and >= with real operands JP Thornley
@ 1996-11-29  0:00 ` Robert Dewar
  1996-12-03  0:00   ` Keith Thompson
  1996-12-01  0:00 ` Tucker Taft
  1 sibling, 1 reply; 11+ messages in thread
From: Robert Dewar @ 1996-11-29  0:00 UTC (permalink / raw)



Phil Thornley says

"Section 5.5.6 - "... the use of <= is more portable than either < or ="

Section 7.2.7 (in the Chapter on Portability) -
   "Strict relational comparisons (<, >, =, /=) are a general problem
    with computations involving real numbers"
and there is an implication (but no direct statement) that the inclusive
comparisons are not a problem.  (The Ada 83 version did have a statement
that <= and >= evaluated the same in all implementations but this has
gone from the Ada 95 version.)

Clearly = and /= are to be avoided, but I can't see why < and > are less
portable than <= and >=."


Anmd wonders about the above quotes from AQ&S. To me they are plain
incorrect, as is Phil's conclusion, there is nothing inherently wrong
with using exact comparison on floating-point numbers. The rule is like
using any operator in any situation, you use it only if careful analysis
of your algorithm shows that it has the right semantics for the operatoin
you wish to perform.

The idea that equality testing on fpt numbers is always wrong is a myth
borne of unfamiliarity with floating-point semantics that refuses to die!

The idea that the use of <= is more portable than either < or = is particular
rubbish, I see no possible justification for such a statement, and, unlike
the old rule about avoiding equality, I cannot even guess the thought behind
this misunderstanding.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-11-29  0:00 [Q] Portability of <= and >= with real operands JP Thornley
  1996-11-29  0:00 ` Robert Dewar
@ 1996-12-01  0:00 ` Tucker Taft
  1996-12-02  0:00   ` Norman H. Cohen
  1 sibling, 1 reply; 11+ messages in thread
From: Tucker Taft @ 1996-12-01  0:00 UTC (permalink / raw)



JP Thornley (jpt@diphi.demon.co.uk) wrote:
: I'm having difficulty understanding the statements in the Ada 
: Quality and Style Guide on the portability of relational expressions 
: with real operands:-

: Section 5.5.6 - "... the use of <= is more portable than either < or ="

This is a bug in AQ&S.  Several of the reviewers of AQ&S pointed out
this mistake, but alas, it somehow managed to slip through.  One claim
was that this statement was due to Norman Cohen, and hence indisputable.
However, Norm (or at least NC1, as we used to call his non-alter-ego ;-)
has since disavowed all connection with this statement.

: Phil Thornley
: | JP Thornley    EMail jpt@diphi.demon.co.uk                           |

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-01  0:00 ` Tucker Taft
@ 1996-12-02  0:00   ` Norman H. Cohen
  0 siblings, 0 replies; 11+ messages in thread
From: Norman H. Cohen @ 1996-12-02  0:00 UTC (permalink / raw)



Tucker Taft wrote:
 

> This is a bug in AQ&S.  Several of the reviewers of AQ&S pointed out
> this mistake, but alas, it somehow managed to slip through.  One claim
> was that this statement was due to Norman Cohen, and hence indisputable.

Interesting argument, but I've rarely been able to use it successfully.
;-)

> However, Norm (or at least NC1, as we used to call his non-alter-ego ;-)
> has since disavowed all connection with this statement.

We *ALL* disavow any connection with this statement.

-- 
NC1, NC2, NC3, ...
(Norman H. Cohen)
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-11-29  0:00 ` Robert Dewar
@ 1996-12-03  0:00   ` Keith Thompson
  1996-12-03  0:00     ` Robert Dewar
                       ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Keith Thompson @ 1996-12-03  0:00 UTC (permalink / raw)



In <dewar.849320173@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
[...]
> The idea that the use of <= is more portable than either < or =
> is particular rubbish, I see no possible justification for such a
> statement, and, unlike the old rule about avoiding equality, I cannot
> even guess the thought behind this misunderstanding.

Suppose you've computed two quantities, X and Y, such that X is
mathematically known to be less than Y, but it may be arbitrarily close.
Since floating-point is of finite precision, the representations of X
and Y may be equal.  (For example, X = 0.0, Y = some tiny value which
underflows to 0.0).  Then X <= Y may reflect the relationship more
accurately than X < Y.

Of course, in real life you should analyze the particular case, and you
may well reach the opposite conclusion, but I'd bet that the original
rationale for the statement was something like the above.

-- 
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"SPOON!" -- The Tick




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00   ` Keith Thompson
  1996-12-03  0:00     ` Robert Dewar
  1996-12-03  0:00     ` Thomas Koenig
@ 1996-12-03  0:00     ` Tucker Taft
  1996-12-03  0:00       ` Larry Kilgallen
  1996-12-04  0:00       ` Keith Thompson
  2 siblings, 2 replies; 11+ messages in thread
From: Tucker Taft @ 1996-12-03  0:00 UTC (permalink / raw)



Keith Thompson (kst@aonix.com) wrote:

: In <dewar.849320173@merv> dewar@merv.cs.nyu.edu (Robert Dewar) writes:
: [...]
: > The idea that the use of <= is more portable than either < or =
: > is particular rubbish, I see no possible justification for such a
: > statement, and, unlike the old rule about avoiding equality, I cannot
: > even guess the thought behind this misunderstanding.

: Suppose you've computed two quantities, X and Y, such that X is
: mathematically known to be less than Y, but it may be arbitrarily close.
: Since floating-point is of finite precision, the representations of X
: and Y may be equal.  (For example, X = 0.0, Y = some tiny value which
: underflows to 0.0).  Then X <= Y may reflect the relationship more
: accurately than X < Y.

Are you also saying that X <= Y is somehow "better" than not (X > Y)?
That is truly mysterious, if so.

: Of course, in real life you should analyze the particular case, and you
: may well reach the opposite conclusion, but I'd bet that the original
: rationale for the statement was something like the above.

: Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00   ` Keith Thompson
  1996-12-03  0:00     ` Robert Dewar
@ 1996-12-03  0:00     ` Thomas Koenig
  1996-12-03  0:00     ` Tucker Taft
  2 siblings, 0 replies; 11+ messages in thread
From: Thomas Koenig @ 1996-12-03  0:00 UTC (permalink / raw)



In comp.lang.ada, kst@aonix.com (Keith Thompson) wrote:

>Suppose you've computed two quantities, X and Y, such that X is
>mathematically known to be less than Y, but it may be arbitrarily close.

Just a general note:  Be careful even of this kind of statement unless
you have analyzed your floating point arithmetic and program very
carefully.  Rounding errors can even lead to X>Y.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00     ` Tucker Taft
@ 1996-12-03  0:00       ` Larry Kilgallen
  1996-12-03  0:00         ` Robert Dewar
  1996-12-04  0:00       ` Keith Thompson
  1 sibling, 1 reply; 11+ messages in thread
From: Larry Kilgallen @ 1996-12-03  0:00 UTC (permalink / raw)



In article <E1uEEs.2xJ.0.-s@inmet.camb.inmet.com>, stt@houdini.camb.inmet.com (Tucker Taft) writes:

> Are you also saying that X <= Y is somehow "better" than not (X > Y)?

Depending on the context, one form or the other may be _much_ easier
for a human to scan.  It all depends upon how X and Y have been used
in the surrounding lines, as well as what the real names are (one hopes
that only those doing graphics or genetics actually name variables
X and Y).

Larry Kilgallen




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00       ` Larry Kilgallen
@ 1996-12-03  0:00         ` Robert Dewar
  0 siblings, 0 replies; 11+ messages in thread
From: Robert Dewar @ 1996-12-03  0:00 UTC (permalink / raw)



Larry said, answering Tuck

"> Are you also saying that X <= Y is somehow "better" than not (X > Y)?

Depending on the context, one form or the other may be _much_ easier
for a human to scan.  It all depends upon how X and Y have been used
in the surrounding lines, as well as what the real names are (one hopes
that only those doing graphics or genetics actually name variables
X and Y)."


Sure, of course, we all know this, and it applies to all sorts of contexts,
it is really why NOT is in the language. But this comment has nothing to
do with the issue, which is that to imply one is more portable than the
other, which is also how I read Keith's message also, is very weird.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00   ` Keith Thompson
@ 1996-12-03  0:00     ` Robert Dewar
  1996-12-03  0:00     ` Thomas Koenig
  1996-12-03  0:00     ` Tucker Taft
  2 siblings, 0 replies; 11+ messages in thread
From: Robert Dewar @ 1996-12-03  0:00 UTC (permalink / raw)



Keith says

"Suppose you've computed two quantities, X and Y, such that X is
mathematically known to be less than Y, but it may be arbitrarily close.
Since floating-point is of finite precision, the representations of X
and Y may be equal.  (For example, X = 0.0, Y = some tiny value which
underflows to 0.0).  Then X <= Y may reflect the relationship more
accurately than X < Y.
"

Well first, surely you are not meaning to say that X<=Y is different
from not (X>Y), which you are arguing is somehow less portable than
X>=Y, so this argument is not self consistent!

In fact if your analysis is based on a view of the mathemaytical
proper values of variables, then this argument is almost certainly
bogus, since approximations may lead X > Y to be true, even if
X < Y mathematically.

You cannot substitute rules like this for proper analysis. Both > and
>= have perfectly well defined portable meanings for a given model
of floating-point arithmetic, and you have to analyze your code with
respect to a particular model.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [Q] Portability of <= and >= with real operands
  1996-12-03  0:00     ` Tucker Taft
  1996-12-03  0:00       ` Larry Kilgallen
@ 1996-12-04  0:00       ` Keith Thompson
  1 sibling, 0 replies; 11+ messages in thread
From: Keith Thompson @ 1996-12-04  0:00 UTC (permalink / raw)



In <E1uEEs.2xJ.0.-s@inmet.camb.inmet.com> stt@houdini.camb.inmet.com (Tucker Taft) writes:
> Are you also saying that X <= Y is somehow "better" than not (X > Y)?
> That is truly mysterious, if so.

Of course not.  Ignoring NaNs and readability, X <= Y is identical
to not (X > Y).

The original statement was that AQ&S recommends using "<=" rather than "<"
because it's more portable.  The general consensus (with which I agree)
is that that's absurd as a general statement.  I was merely speculating
on a possible rationale for the original (incorrect) statement by trying
to construct a specific case in which X <= Y might be safer than X < Y,
even if X is mathematically known to be less than Y.  (Even this is not
entirely safe, since roundoff errors could cause X to be greater than Y.)

This is tricky stuff.  I probably know just enough about numerical
analysis to be dangerous.

-- 
Keith Thompson (The_Other_Keith) kst@aonix.com <http://www.aonix.com> <*>
TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706
"SPOON!" -- The Tick




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~1996-12-04  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-29  0:00 [Q] Portability of <= and >= with real operands JP Thornley
1996-11-29  0:00 ` Robert Dewar
1996-12-03  0:00   ` Keith Thompson
1996-12-03  0:00     ` Robert Dewar
1996-12-03  0:00     ` Thomas Koenig
1996-12-03  0:00     ` Tucker Taft
1996-12-03  0:00       ` Larry Kilgallen
1996-12-03  0:00         ` Robert Dewar
1996-12-04  0:00       ` Keith Thompson
1996-12-01  0:00 ` Tucker Taft
1996-12-02  0:00   ` Norman H. Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox