2009/8/15 rjf <fate...@gmail.com>:
>
> wow, I post one place and it comes out in two places...
>
> Here is an amplification about the comments on GMP and GMPY.
>
> From the perspective of Sage and python, I just took a look at the
> current gmpy.
> The documentation,  which has not apparently been updated since 2003,
> says
>
> "Early tests have shown that supporting Python 2's "in-place
> operation" functionality (by making MPZ, MPF and MPQ Python objects
> mutable) would offer a substantial performance boost.
>
> Despite this, widespread feeling among Python cognoscenti appears to
> be against exposing such "mutable numbers". .... "
>
> ................
>
> So my comment about the unsophisticated python wrappers for gmpy are
> still correct for now, at least if the documentation is up to date.
>
>
> If that is true, Sage, using this gmpy, imposes a significant
> limitation to persons attempting
> to use gmp in its most efficient manner, using mutable numbers.

Sage does not use gmpy.  Sage also doesn't use GMP -- it uses a fork
of GMP called MPIR, and has its own direct wrapping of the MPIR
library (http://mpir.org/). This does support in place operations for
speed reasons, though you have to explicitly call an "underscore
method" to access them:

sage: n = 15
sage: n._iadd_(5)
20
sage: n
20

They should be used only when people know what they are doing, since
one can do stupid things like the following:

sage: V = QQ^4; V
Vector space of dimension 4 over Rational Field
sage: a = V.dimension()
sage: a._iadd_(5)
9
sage: V.dimension()
9


One can also just directly use the MPIR C api through Cython, and
there is a lot of support for this.  This is in fact how a substantial
amount of Sage itself is written.   It provides exactly the same
performance as programming MPIR in C.   To get a sense of how much
this is used in Sage, note that there are nearly 5000 lines of code in
Sage that contain mpz_ or mpq_:

wst...@sage:~$ sage -grep mpz_ |wc -l
4021
wst...@sage:~$ sage -grep mpq_ |wc -l
888



> Some lisps that use gmp directly, may also avoid the parts that do
> mutation, since that causes problems with the functional model that
> prevails with the simplest viewpoint of lisp arithmetic.  That does
> NOT mean that lisp cannot use GMP and mutation.
>
> For examples of how I used gmp from Allegro Common Lisp,  a lisp that
> does not natively use GMP, see
> http://www.cs.berkeley.edu/~fateman/generic
> and especially...
> http://www.cs.berkeley.edu/~fateman/generic/gmp.lisp
>
> I initially tried loading the python-packaged gmp library into lisp --
> it worked fine, but was limited. So I load the gmp library directly.
>
>
> There are also comments in that file that give comparisons for
> different hardware and different versions of gmp.
> If you use the "generic pentium" gmp instead of the specific version
> for pentium3 or pentium4 [depending on what
> you are using!] then you suffer a penalty of 3X in speed.  Or did so
> when I ran those tests.
>
> I don't know if Sage is set up to provide linkages to the "most
> appropriate" GMP for each architecture, but
> there are substantial efficiency differences.

Sage includes MPIR, and a large amount of work goes into making sure that
MPIR is built optimally on each platform Sage supports.

> To the extent that you find it acceptable to set up the foreign-
> function interface, probably anything you can
> import into python, you can import into lisp, though not uniformly for
> all lisp implementations.  And the
> foreign-function interface is somewhat diddly, which is why there are
> some utilities that will read a *.h file and generate
> most of it automatically.  I didn't use one myself, since I used only
> a few entry points to start, and added
> only those that I thought I needed.
>
>
>
>
>
>
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to