Re: [Chicken-users] Possible numbers bug

2011-05-28 Thread Matt Welland
What was the final word on this? Is it a real issue on some platforms?

Anyhow, I found this whole exercise pretty interesting and played with
it a bit more and observed a couple curious things:

1. Performance (see below) of guile was better than the compiled
chicken-4.6.5 for my code. It looked like it might be due to string
operations based on profile (I wasn't exactly trying to be efficient).

2. Taking the inverse exponent (i.e. result^(1/n) ) runs into trouble
at n=144. Anyone care to explain why that is and is there a numerical
methods trick to work around it?

3. Why do guile, scm and STk put out +inf.0 and chicken puts out +inf
(gauche gives #i1/0)? My hazy understanding is that +inf.0 is not the
same as +inf.

The code I used is below.
==
Chicken 3.4:

csi (load test.scm)
; loading test.scm ...
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf
==
Chicken 4.6.5:

Note: re-importing already imported identifier: magnitude
; loading 
/nfs/ch/disks/ch_umg_disk0003/mrwellan/tools/4/lib/chicken/6/numbers.so
...
; loading /nfs/ch/disks/ch_umg_disk0003/mrwellan/tools/4/lib/chicken/6/regex.so
...
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf
==
STk (load test.scm)
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is inf.0
==
guile -s test.scm
   ~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf.0
==
scm -f test.scm
  ~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is +inf.0
==
gosh -b -q test.scm
  ~
1000368...(2987 hidden digits)...0846700
Inverse of 144th expt is #i1/0
==
Speed (on Atom n550)

Chicken 4.6.5, compiled:   0.46s
Chicken 3.4, compiled: 37s
stk -f test.scm  2.9s
guile -s test.scm:  0.16s
scm -f test.scm:   1.49s
gosh  -b -q test.scm: 0.46s
==

;(use numbers)

(define vals #f)

(define (print . strs)
  (map display strs)
  (display \n))

(define (sum-of-exponents n lim)
  (if ( n lim) 0 (+ (expt n n)
 (sum-of-exponents (+ n 1) lim
(define (pp-bignum num)
  (let* ((str (number-string num))
 (len (string-length str)))
(if ( len 45)
(string-append (substring str 0 7) ...( (number-string (- len 14))
 hidden digits)... (substring str (- len 7) len))
str)))

(define (cmpit lim)
  (set! vals (make-vector (+ 2 lim)))
  (let loop ((n   1)
 (sum 0))
(vector-set! vals n (expt n n))
(if ( n lim)
(print (pp-bignum sum))
(loop (+ n 1)(+ sum (vector-ref vals n)
  (let loop ((n 1))
(let ((invexpt (expt (vector-ref vals n)(/ 1.0 n
  (if ( (abs (- invexpt n)) 0.0001)
  (print Inverse of  n th expt is  (pp-bignum invexpt))
  (if ( n lim)
  (print Done)
  (loop (+ n 1)))

;; (print (message-digest-string (md5-primitive) (number-string
(sum-of-exponents 1 1000'

(cmpit 1000)
(exit)

On Fri, May 27, 2011 at 2:00 PM, David N Murray dmur...@jsbsystems.com wrote:
 On May 27, Kon Lovett scribed:


 Chicken x86:
 520cbadfbf1e95567b1b49bd543fa8ab

 sauron:chicken-4.7.0 dnm$ csi -v

 CHICKEN
 (c)2008-2011 The Chicken Team
 (c)2000-2007 Felix L. Winkelmann
 Version 4.7.0
 macosx-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
 compiled 2011-05-26 on sauron.local (Darwin)

 sauron:chicken-4.7.0 dnm$ csi -b -n -q -e '(use md5 message-digest
 numbers) (define (sum-of-exponents n lim) (if ( n lim) 0 (+ (expt n n)
 (sum-of-exponents (+ n 1) lim (print (message-digest-string
 (md5-primitive) (number-string (sum-of-exponents 1 1000'
 89f880d1887706b3d1a2263b177f3352

 Yup, that doesn't match.  I have a debug build of x64-64 (macosx)
 available if someone wants to give me an idea on where to look.

 Dave

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Possible numbers bug

2011-05-28 Thread Peter Bex
On Sat, May 28, 2011 at 11:03:41AM -0700, Matt Welland wrote:
 What was the final word on this? Is it a real issue on some platforms?

Probably. I will look into it when time allows.

 Anyhow, I found this whole exercise pretty interesting and played with
 it a bit more and observed a couple curious things:
 
 2. Taking the inverse exponent (i.e. result^(1/n) ) runs into trouble
 at n=144. Anyone care to explain why that is and is there a numerical
 methods trick to work around it?

You divide the inexact 1.0 by the number.  Try doing an exact division
like (/ 1 n) or just (/ n). This will produce a rational number which
is exact and not limited in any way.

 3. Why do guile, scm and STk put out +inf.0 and chicken puts out +inf
 (gauche gives #i1/0)? My hazy understanding is that +inf.0 is not the
 same as +inf.

I think it's the same.  Only flonums can be +inf and hence the .0 is
superfluous.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Possible numbers bug

2011-05-28 Thread Matt Welland
On Sat, May 28, 2011 at 11:11 AM, Peter Bex peter@xs4all.nl wrote:
 On Sat, May 28, 2011 at 11:03:41AM -0700, Matt Welland wrote:

 2. Taking the inverse exponent (i.e. result^(1/n) ) runs into trouble
 at n=144. Anyone care to explain why that is and is there a numerical
 methods trick to work around it?

 You divide the inexact 1.0 by the number.  Try doing an exact division
 like (/ 1 n) or just (/ n). This will produce a rational number which
 is exact and not limited in any way.

Ah, yeah, I forgot to mention that I tried both 1.0 and 1 and got the
same result.

Matt
-=-

 Cheers,
 Peter
 --
 http://sjamaan.ath.cx
 --
 The process of preparing programs for a digital computer
  is especially attractive, not only because it can be economically
  and scientifically rewarding, but also because it can be an aesthetic
  experience much like composing poetry or music.
                                                        -- Donald Knuth

 ___
 Chicken-users mailing list
 Chicken-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/chicken-users


___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Non-finite number I/O (was: Possible numbers bug)

2011-05-28 Thread John Cowan
Peter Bex scripsit:

 I think it's the same.  Only flonums can be +inf and hence the .0 is
 superfluous.

Superfluous, maybe, but now standard.  R6RS prescribes it (for systems
supporting IEEE floats) and so will R7RS-small, despite being much more
like R5RS in most ways.

Existing implementations use either +inf.0 or something specific to
that implementation.  Specifically: Racket, Gauche, Guile, Kawa, Chibi,
SCM, Ikarus, Larceny, IronScheme, Ypsilon, Mosh, and STklos all use
+inf.0.  Bigloo uses +Infinity.  Scheme48/scsh uses #{Inf}.  SISC uses
infinity.0, which is not even rereadable.  MIT Scheme and Scheme 9 do
not have non-finite values; they always report floating overflow or
divide by zero errors.  (Scheme 9 is non-IEEE; it handles flonums up to
10^10^10 - 1.)

What is more, Chicken is not even consistent: on Linux it prints +inf,
but on Cygwin, which uses Newlib instead of GNU libc, it prints +inf.0.

My recommendations:

Use wrapper logic in number-string to print +inf.0, -inf.0, and +nan.0
in the appropriate circumstances, and make sure that string-number
always accepts them.

Remove the divide-by-zero exception when dividing by inexact 0, which
does not represent a mathematical 0, but any number between the smallest
positive flonum and the largest negative flonum.

-- 
We do, doodley do, doodley do, doodley do,John Cowan co...@ccil.org
What we must, muddily must, muddily must, muddily must; 
Muddily do, muddily do, muddily do, muddily do,http://www.ccil.org/~cowan
Until we bust, bodily bust, bodily bust, bodily bust.  --Bokonon

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users