People who do research mathematics and use Python often run into a few problems:
** versus ^. In Python, ^ means
``xor'', not exponentiation, so in Python we have
>>> 2^8 10 >>> 3^2 1 >>> 3**2 9
This might be easy for some people to get used to, but for a person
used to typing LaTeX this appears odd; it is also inefficient for
pure math research, since exclusive or is rarely used. For
convenience, Sage pre-parses all command lines before passing them to
Python, replacing instances of ^ that are not in strings with
**:
sage: 2^8 256 sage: 3^2 9 sage: "3^2" '3^2'
2/3 has much different
behavior in Python than
in any standard math system. In Python, if 2/3 returns the floating point number 0.6666..., and
making 2//3 return 0
.
We deal with this in the Sage interpreter, by wrapping integer
literals in ZZ( ) and making division a constructor for
rational numbers. For example:
sage: 2/3 2/3 sage: 2//3 0 sage: int(2)/int(3) 0
L at
the end to distinguish them from int's (and this won't change
any time soon). Sage also implements
arbitrary precision integers, using the GMP C-library, and these
print without an L.
Rather than modifying the Python interpreter (as I've heard some people have done for internal projects), we use the Python language exactly as is, and write a pre-parser for IPython so that the command line behavior of IPython is what a mathematician expects. This means any existing Python code can be used in Sage. However, one must still obey the standard Python rules when writing packages that will be imported into Sage.
Note:
To install a random Python library that you find on the internet,
follow the directions, but run sage -python instead of python.
Very often this means typing sage -python setup.py install.
See About this document... for information on suggesting changes.