caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-08 16:25 Harrison, John R
  0 siblings, 0 replies; 15+ messages in thread
From: Harrison, John R @ 2004-10-08 16:25 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

| But if x is the result of any computation (with rounding error), and x

| is huge, sin x may be any value between -1 and 1. So the best value
from 
| sin x is either 0 (your possible error is minimum) or nan.

The job of the library function should be to solve the simple
mathematical
task of returning an accurate sin, not indulge in a speculative critique
of
the user's error analysis.

Sure, the input is most likely either a previously rounded result or
some
inexact physical measurement. But it *might* be a precise value. Or the
result may be used in such a way that the error will not be an issue,
e.g.
if one subsequently does something like "1 + sin(x)/x". Returning NaN
would
force the user to indulge in many tedious checks instead of simply using
the straightforward algorithm.

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-09 18:10 Harrison, John R
  0 siblings, 0 replies; 15+ messages in thread
From: Harrison, John R @ 2004-10-09 18:10 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

| As I said in an earlier post, you can do
| 
|   let (=?) x y = (Pervasives.compare x y = 0)
| 
| and use =? instead of = in places where you need the "early stop"
| behaviour.

OK. I wanted to be sure this was a recommended solution, not just
something that happens to work at the moment.

| Of course, if the speed of equality is critical, you can also define
| your own comparison functions for the types of interest, or even (as
| Damien suggested) implement hash-consing.

In fact, the key function is an alpha-conversion test on
name-carrying lambda-terms. Since it's almost always expected to
succeed with full equality after a shallow comparison, I now do an
equality test first to get the early-out behaviour. I can just
change it to put an "==" into the main recursion when it hasn't
gone through any lambdas.

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-09 17:56 Harrison, John R
  0 siblings, 0 replies; 15+ messages in thread
From: Harrison, John R @ 2004-10-09 17:56 UTC (permalink / raw)
  To: Damien Doligez, caml-list

| What I did in my soon-to-be-released automatic prover, following
| advice from Pierre Weis, was to hash-cons all the terms used by the
| program.  Now I only need to use pointer equality: if the pointers
| are not the same then I know the terms are not the same.  The speedup
| was a factor of 100 because my program does lots of comparisons and
| hashing of terms.

Yes, it might well be worth looking at that again. I tried it once
in CAML Light and the results were disappointing. But one reason was
that something like weak pointers either didn't exist or I didn't
know about them, so my hash tables rendered some ephemeral stuff 
non-collectible.

I'll look forward to the release of your prover!

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-08 16:35 Harrison, John R
  2004-10-08 17:34 ` Damien Doligez
  2004-10-09  8:58 ` Xavier Leroy
  0 siblings, 2 replies; 15+ messages in thread
From: Harrison, John R @ 2004-10-08 16:35 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

| > I was assuming two things about equal:
| > - scan of block from left to right
| > - a test on adress equality on pointer before follwing the pointer 
| > (which is now wrong in 3.08).
| 
| That was true of the old implementation, but has never been
guaranteed.

For LCF-style theorem provers, I think it's quite important that when
comparing terms (or similar tree structures) for equality, there should
be a quick "yes" when two high-level subgraphs are pointer eq. For
example,

  Constr(small_1,big) = Constr(small_2,big)

(where small_1 = small_2) should return "true" without recursing down
"big". This often comes up when generic theorems are instantiated and
one then checks that the instantiation does make certain terms match
up.

I guess like Christophe Raffalli I had just assumed this would be
the case based on long experience with ML-family languages, rather than
through any explicit discussion in the documentation. Can you clarify
what we need to do in order to guarantee this behaviour?

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 15+ messages in thread
* RE: [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-08  2:54 Harrison, John R
  2004-10-08  5:49 ` Christophe Raffalli
  0 siblings, 1 reply; 15+ messages in thread
From: Harrison, John R @ 2004-10-08  2:54 UTC (permalink / raw)
  To: Christophe Raffalli, caml-list

| I spend one complete day to adapt Phox (my theorem prover) to 3.08
| because the new = does not check first physical equality.

If that's true, it would probably be bad news for the efficiency of my
theorem prover (HOL Light) as well, though I haven't run any actual
comparisons. (I have it running under 3.06, 3.07 and 3.08 on different
machines --- only the camlp4 part was different each time.)

| sin x with x > 10e100 gives a value which is certainly wrong since you

| can not compute the modulo 2 pi for such a big number.
| sin x should give nan when |x| is too big.

You can perfectly well compute it, and the general consensus among the
floating-point community is that trig functions should do the best they
reasonably can even on huge arguments. Techniques for doing this kind
of reduction reasonably efficiently have been known for at least 20
years, e.g.

@ARTICLE{payne-hanek,                                               
        author          = "M. Payne and R. Hanek",
        title           = "Radian Reduction for Trigonometric
Functions",
        journal         = "SIGNUM Newsletter",   
        year            = 1983,              
        volume          = 18,                     
        number          = 1,          
        pages           = "19--24"}               

Taking the sin of large numbers may indeed indicate bad code, but so may
lots of other eccentric uses of library functions.

John.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 15+ messages in thread
* [Caml-list] Are you sure the new "=" of 3.08 is good ?
@ 2004-10-07 21:14 Christophe Raffalli
  2004-10-08  7:38 ` Jean-Christophe Filliatre
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Christophe Raffalli @ 2004-10-07 21:14 UTC (permalink / raw)
  To: caml-list


I spend one complete day to adapt Phox (my theorem prover) to 3.08
because the new = does not check first physical equality. Hopefully, the 
backtracking ocamldebugger let me pin point the many "=" which were 
looping, otherwise I would have spend a month !!!

I was assuming two things about equal:
- scan of block from left to right
- a test on adress equality on pointer before follwing the pointer 
(which is now wrong in 3.08).

Then in a data type with some structure starting with an identifier 
filed like

type symbol = structh { id : int; ... },

if you have the property that two structures with the same id are always 
physically equal, the old "=" would never scan the structure itself.

The new "=" can dramatically change the complexity of a program using 
such a structure. It can even loop if your data type are cyclic but all 
cycle need to traverse a structure with the above property (in this case 
the old "=" did not loop).

I imagine there are other examples where the old "=" can be much faster 
than the new one.

So the comparison between both "=" gives

old "=":
- can have much better complexity of some specific data structure
- nan = nan => true

new "="
- can have a small linear speedup on some specific data structure
- nan = nan => false

Clearly for most ocaml programmer the old "=" was better.

Moreover, code relying on, nan = nan to give false are very suspicious 
to me !!! If you need to debug, you have better to insert assertion 
about your floats.

Finally, the IEEE norm about floating point arithmetic is not perfect 
yet. For instance it makes nothing about transcendentals function (see 
below) so I really do not think this norm is so good that OCaml MUST 
respect it for polymorphic equality (a new better norm may appear one day).

--
Here are two small problems with the actual implementation of float:

asin 1.000001 gives nan while some floating point expression which you 
can mathematically prove to be in [-1, 1] gets computed as 1 + epsilon !
so asin x should be equal to asin 1 if x > 1 (idem for -1) otherwise all 
call to asin shoud do a comparison with 1 and -1

sin x with x > 10e100 gives a value which is certainly wrong since you 
can not compute the modulo 2 pi for such a big number.
sin x should give nan when |x| is too big.

-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature
---------------------------------------------

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2004-10-09 18:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-08 16:25 [Caml-list] Are you sure the new "=" of 3.08 is good ? Harrison, John R
  -- strict thread matches above, loose matches on Subject: below --
2004-10-09 18:10 Harrison, John R
2004-10-09 17:56 Harrison, John R
2004-10-08 16:35 Harrison, John R
2004-10-08 17:34 ` Damien Doligez
2004-10-09  8:58 ` Xavier Leroy
2004-10-08  2:54 Harrison, John R
2004-10-08  5:49 ` Christophe Raffalli
2004-10-08  6:54   ` David Brown
2004-10-07 21:14 Christophe Raffalli
2004-10-08  7:38 ` Jean-Christophe Filliatre
2004-10-08  8:31   ` Christophe Raffalli
2004-10-08 15:10     ` Damien Doligez
2004-10-08  9:37 ` Sébastien Furic
2004-10-08 15:54 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).