Ask Your Question

Revision history [back]

The computation of 3**10000000 is itself much faster in Sage than Python 3. This is because, when you type 3 in Sage, you do not get a Python int but a Sage integer, that relies on the GMP library (which is optimized for such computations):

sage: type(3)
<class 'sage.rings.integer.Integer'>
sage: parent(3)
Integer Ring

If you look at, the source code for the exponentitiation of such an object:

sage: a = 3
sage: a.__pow__??

you see that it will call a._pow_ (with a single underscore), and if you look at that source code:

you see that it calls the _pow_long method which is not available to introspection, but you can get its source code at https://git.sagemath.org/sage.git/tree/src/sage/rings/integer.pyx#n2242 which is written in the Cython language. Everytime you see mpz..., it means that the GMP library is used.