Re: [Maxima-discuss] Should Maxima use GMP ? (Answer: YES!)

Camm Maguire <[email protected]>
Newsgroups gmane.lisp.gcl.devel,gmane.comp.mathematics.maxima.general
Message-ID <[email protected]>
Greetings!  Just ran across this thread.  Am traveling this week, but
will get back with a substantive reply.  In short, a much more developed
GMP interface is basically in place in the master branch, which still
has a bit of work before it is ready.  The interface could be moved over
relatively easily.

Take care,

Henry Baker <[email protected]> writes:

> Here's some *very interesting* timing results on the SBCL and GCL 'gcd' function using my
>
> relatively new 64-bit laptop running under WSL2 (Windows Subsystem for Linux).
>
>  
>
> If I simply fire up SBCL 2.1.1, I can do ~188,679 gcd's of random 256bit numbers per second.
>
>  
>
> If I then do (require :sb-gmp) *without restarting* SBCL, I can now do 909,091 gcd's of random
>
> 256bit numbers per second -- i.e., 4.8X faster !!
>
>  
>
> In other words, SBCL will use GMP for 'gcd' *if it's loaded*, but otherwise not !
>
>  
>
> SBCL's utilization of GMP has a cost, however.
>
>  
>
> I can do 10,395,010 32bit gcd's per second if I call sb-gmp:mpz-gcd directly, but
>
> only 4,878,049 gcd's per second if I call Lisp's 'gcd' function; i.e., the cost of
>
> checking for GMP costs more than the cost of doing the 32bit gcd !!
>
>  
>
> Note that when SBCL uses GMP on 32bit gcd's, it is *slower* than using GMP
>
> on 64bit gcd's (on my 64-bit laptop).
>
>  
>
> Bottom line: *always incorporate "(require :sb-gmp)" into your SBCL Maxima builds*,
>
> whether you plan to call any sb-gmp functions directly yourself or not.
>
>  
>
> ---
>
> Now for gcd's on GCL 2.6.12 on the same 64bit laptop.
>
>  
>
> On 32-bit gcd's, GCL is slightly faster than SBCL/GMP, but slightly slower than calling GMP directly.
>
> On 64-bit gcd's, GCL is twice as slow as SBCL/GMP.
>
> On 128-bit gcd's, GCL is 12X slower than SBCL/GMP.
>
> On 256-bit gcd's, GCL is 10X slower than SBCL/GMP.
>
> On 512-bit gcd's, GCL is 12.5X slower than SBCL/GMP.
>
> On 1024-bit gcd's, GCL is 11X slower than SBCL/GMP.
>
> On 4096-bit gcd's, GCL is 21.5X slower than SBCL/GMP.
>
>  
>
> I'm dumb-founded as to why GCL would incorporate GMP, and then not use it for the 'gcd' function !!
>
>  
>
> It's time for GCL to use GMP as much as possible.
>
>  
>
> Case closed.
>
>  
>
> -----Original Message-----
> From: Richard Fateman <[email protected]>
> Sent: Apr 21, 2023 6:00 PM
> To: Stavros Macrakis <[email protected]>, <[email protected]> <[email protected]>
> Subject: Re: [Maxima-discuss] Does any maxima package implement the 'primorial' function ?
>
>  
>
> If you assume GMP,  you can possibly remove big floats and bignums. Thoughts?
> Richard
>
> On Fri, Apr 21, 2023, 6:19 PM Stavros Macrakis <[email protected]> wrote:
>
>  Given that we have a nice and reasonably fast Maxima function which works on all Lisps, I'm not sure I see the value of an implementation-specific implementation, especially since primordial is of rather specialized interest. But I would be curious to know how
>  fast the GMP primordial function is on 3*10^6. Surprisingly, perhaps, generating the primes in Maxima takes about 40% of the time and the other 60% are the multiplications and overhead.
>
>  On Fri, Apr 21, 2023 at 6:00 PM Henry Baker <[email protected]> wrote:
>
>  I downloaded the sources for GCL, it it appears that GCL incorporates its own
>
>  version of GMP (i.e., GCL doesn't seem to use the standard libgmp dynamic
>
>  library).
>
>   
>
>  The 'primorial' function appears in the source code, as the '.c' file for it exists.
>
>  However, I can't tell if this .c file appears in the final GCL binary.
>
>   
>
>  Given the close relationship of GCL and GMP, I would imagine that providing
>
>  a Lisp-level 'primorial' function would be pretty easy (if it doesn't already
>
>  exist).
>
>   
>
>  I did search the GCL symbol tables and couldn't find any hint of Lisp-level
>
>  functions for the GMP 'mpz' functions.
>
>   
>
>  -----Original Message-----
>  From: Henry Baker <[email protected]>
>  Sent: Apr 21, 2023 7:39 AM
>  To: Raymond Toy <[email protected]>, <[email protected]>
>  Subject: Re: [Maxima-discuss] Does any maxima package implement the 'primorial' function ?
>
>   
>
>  GMP already works in SBCL as an FFI package:
>
>   
>
>  sbcl
>  This is SBCL 2.1.11.debian, an implementation of ANSI Common Lisp.
>  More information about SBCL is available at <http://www.sbcl.org/>.
>
>  SBCL is free software, provided as is, with absolutely no warranty.
>  It is mostly in the public domain; some portions are provided under
>  BSD-style licenses.  See the CREDITS and COPYING files in the
>  distribution for more information.
>  * (require :sb-gmp)
>  ("SB-GMP")
>  * (defun primorial (n) (sb-gmp:mpz-primorial n))
>  PRIMORIAL
>  * (primorial 255)
>  64266330917908644872330635228106713310880186591609208114244758680898150367880703152525200743234420230
>  *
>
>   
>
>  It will be interesting to see if SBCL Maxima takes advantage of
>
>  the non-CL-standard functions from GMP.
>
>   
>
>  -----Original Message-----
>  From: Raymond Toy <[email protected]>
>  Sent: Apr 21, 2023 7:28 AM
>  To: <[email protected]>
>  Subject: Re: [Maxima-discuss] Does any maxima package implement the 'primorial' function ?
>
>   
>
>   
>
>  On 4/21/23 07:10, Henry Baker wrote:
>
>  I just notice that Gnu GMP *already* provides a 'primorial' function:
>
>   
>
>  https://gmplib.org/manual/Number-Theoretic-Functions
>
>   
>
>  "Function: void mpz_primorial_ui (mpz_t rop, unsigned long int n)
>
>  Set rop to the primorial of n, i.e. the product of all positive prime numbers <=n."
>
>   
>
>  So any Lisp/Maxima which utilizes GMP already has 'primorial' code loaded;
>
>  I don't know if any of these Lisp's provide access to this code via Lisp or
>
>  Maxima.  (I just tested GCL, ECL, SBCL; none have a 'primorial' function.)
>
>   
>
>  Perhaps it is time that Common Lisp (and Maxima) have an 'unofficial'
>
>  upgrade of the CL standard to include all of the standard GMP number
>
>  I doubt that's going to happen.  There's probably no desire to update the official CL standard.  I think that requires a lot of work and time to make happen.
>
>  theoretic functions, since adding these functions to one of these Lisps
>
>  should be only about a day's work for a knowledgeable person, once
>
>  the function name & arguments have been agreed upon.
>
>   
>
>  primep(n), next_prime(n), inverse_mod(m,n), jacobi(m,n), legendre(a,p),
>
>  kronecker(a,b), factorial(n), binomial(n,k), fibonacci(n), lucas(n), etc.
>
>  But getting lisps to support this is probably easiest if someone created a lisp library that implemented these and made it available via quicklisp.
>
>   
>
>   
>
>  _______________________________________________
>  Maxima-discuss mailing list
>  [email protected]
>  https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
>  _______________________________________________
>  Maxima-discuss mailing list
>  [email protected]
>  https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
> _______________________________________________
> Maxima-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>

-- 
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.