bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug


From: Bill Schelter
Subject: bug
Date: Thu, 3 May 2001 00:04:12 -0500

I am incorporating gmp into GCL (gnu common lisp) to use
with Maxima (free computer algebra system)
http://www.ma.utexas.edu/maxima.html
It gives MUCH better performance for bignums than the old pari
code which I had used before.    A few problems I found in testing
it, now that it is in:

bug/comment 1):
Unfortunately I will not be able to count on distributed libraries
with various Linux distributions, since sometimes they are compiled
on things like a K6, and that exits on an illegal instruction when
I use things like mpz_popcount.   There ought to be a run time flag
somewhere in the library, that gets set at first initting, that
chooses the right code.   Almost all software we have has such run
time checking OR no specific K6/K7 code.    It is a real pain on 
networks with hundreds of machines to have to have two versions.

bug 2) I found there is a bug in mpz_sizeinbase (compiled with gcc 2.95.2
gmp 3.1.1).   It gives some bogus very large number in some cases.
I think this may arise since 
  count_leading_zeros (cnt, x->_mp_d[size - 1]);
is called and in the case in question x->_mp_d[size - 1]
is 0.  Indeed there are about 5 extra trailing 0's.   I am not
sure why that is.   I just computed factorial 10000, so the
bug may somehow be in the multiplying routines.    Dont know.  

(gdb) p *x
$4 = {_mp_alloc = 3702, _mp_size = 3701, _mp_d = 0x834b05c}
(gdb) p x->address@hidden
$5 = {227330331, 574010, 0, 0, 0, 0, 0, 0, 0, 0}

the computation of 10000 factorial is a bit bizarre in that i
first produce 20 numbers a_i which the products of the numbers <=10000
and congruent to i.  then i form a_1 *a_2 ...
Each time a bignum is produced, there is a new call to init a new
bignum.   Not very good to do I know but without doing some special
compiler hacks to detect unaliased variables in lisp, i cant really
do better.    As it is the computation is pretty reasonable, .08 seconds
on a pentium 800mhz.  

(defun factorial (n &aux (ans 1)  )
  (let* ((vec (make-array (if (< n 100) 1 20) :initial-element 1))
         (m (length vec))
         (j 0))
  (sloop for i from 1 to n
         do (setq j (mod i m))
         (setf (aref vec j) (* (aref vec j) i)))
  (sloop for v in-array vec
         do (setq ans (* ans v)))
  ans))






reply via email to

[Prev in Thread] Current Thread [Next in Thread]