Professional Documents
Culture Documents
Sage Trucos
Sage Trucos
Sage Trucos
trucos Pgina 1 de 4
Constantes
----------
http://doc.sagemath.org/html/en/reference/constants/sage/symbolic/constants.html
sage: pi
pi
sage: e # base of the natural logarithm
e
sage: NaN # Not a number
NaN
sage: golden_ratio
golden_ratio
sage: log2 # natural logarithm of the real number 2
log2
sage: euler_gamma # Euler's gamma constant
euler_gamma
sage: catalan # the Catalan constant
catalan
sage: khinchin # Khinchin's constant
khinchin
sage: twinprime
twinprime
sage: mertens
mertens
sage: a = pi + e*4/5; a
pi + 4/5*e
Interpolacin
-------------
http://sage.unex.es/home/pub/61/
http://www.highschoolmathandchess.com/2014/11/13/sagetex-tables-with-a-random-number-of-columnsrows/
https://github.com/mikecroucher/SMC_tutorial
This document describes the different ways to use Sage in console mode (i.e without the notebook
option).
Execute a Sage script from Sage
The easiest way is to write a Sage script to run it using Sage itself. A Sage script has the file
extension .sage. If you want, for example, evaluate the following script:
"""
simple.sage
this is a simple sage script
"""
f(x) = x**2
Archivo: /home/jgarcia/Dropbox/sage/sage.trucos Pgina 2 de 4
print f(2)
def solve_square(n):
""" returns the value of f(x) in
f(x) = x**2
"""
return f(n)
You can simply use the sage sesion to load the script and have all the available functions in your
shell.
>>> sage
sage: load("simple.sage")
sage: solve_square(2)
sage: 4
we can use the attach command to link the file to our Sage session. In that way, we do not need to
reload the file every time we make a change in the file.
sage: attach(simple.sage)
This is if we want to use Sage scripts in the Python shell. For that we need:
Now, everytime that you edit the file simply.py, the changes will be updated without loading againg.
Install tornado
Now you can execute Sage with the IPython notebook option
Salir de sage
-------------
http://doc.sagemath.org/html/en/tutorial/interactive_shell.html
When using the interactive shell, any UNIX shell command can be executed from Sage by prefacing it by
an exclamation point !. For example,
sage: !ls
auto example.sage glossary.tex t tmp tut.log tut.tex
The command save_session(sessionname) saves all the variables youve defined in the current session as
a dictionary in the given sessionname. (In the rare case when a variable does not support saving, it
is simply not saved to the dictionary.) The resulting file is an .sobj file and can be loaded just
like any other object that was saved. When you load the objects saved in a session, you get a
dictionary whose keys are the variables names and whose values are the objects.
You can use the load_session(sessionname) command to load the variables defined in sessionname into
the current session. Note that this does not wipe out variables youve already defined in your current
session; instead, the two sessions are merged.
sage: E = EllipticCurve('11a')
sage: M = ModularSymbols(37)
sage: a = 389
sage: t = M.T(2003).matrix(); t.charpoly().factor()
_4 = (x - 2004) * (x - 12)^2 * (x + 54)^2
Next we save our session, which saves each of the above variables into a file. Then we view the file,
which is about 3K in size.
sage: save_session('misc')
Saving a
Saving M
Saving t
Saving E
sage: quit
was@form:~/tmp$ ls -l misc.sobj
-rw-r--r-- 1 was was 2979 2006-01-28 19:47 misc.sobj
Finally we restart Sage, define an extra variable, and load our saved session.
sage: b = 19
sage: load_session('misc')
Loading a
Loading M
Loading E
Loading t
Each saved variable is again available. Moreover, the variable b was not overwritten.
sage: M
Full Modular Symbols space for Gamma_0(37) of weight 2 with sign 0
Archivo: /home/jgarcia/Dropbox/sage/sage.trucos Pgina 4 de 4
Resultado numerico
------------------
s=pi/2+4
s
1/2*pi + 4
s.n()
5.57079632679490
s.n(digits=4)
5.571