Sage in Research

Numbers

sage: a = RR(sqrt(2)); a
1.41421356237310
sage: b = sqrt(RealField(100)(2)); b     
1.4142135623730950488016887242
sage: (a-b).parent()
Real Field with 53 bits of precision
sage: b.parent()
Real Field with 100 bits of precision
sage: c = RealField(100)(a); c
1.4142135623730951454746218587
sage: b-c
-9.6672933134529652200516048587e-17
There are different types of numbers available. There are three major groups for floating point arithmetic:
  • Python: float, complex, decimal
  • Sage specific: RDF, CDF, RQDF, CC, RR, RIF, CIF
  • included Systems: pari, maxima
Most important are the Sage specific types. They use specific libraries and have more functionality. Important are RR and CC, because their behavior is independent of the underlying system and architecture using the MPFR library. RDF and CDF use the GSL library and are very fast and compatible with the Sage framework.
The example on the left shows how to construct different types of floating point numbers and interactions between them.

Algebra

sage: M = IntegerModRing(7)
sage: M(2) + M(8)
3
sage: M.list()
[0, 1, 2, 3, 4, 5, 6]

sage: A.<a,b,c> = AbelianGroup([2,2,3]); A
Multiplicative Abelian Group isomorphic to C2 x C2 x C3
sage: A.order()
12
sage: A.list()
[1, c, c^2, b, b*c, b*c^2, a, a*c, a*c^2,
                        a*b, a*b*c, a*b*c^2]
sage: c^5*b*a^4*c
b

Sage is built above an object oriented programming language. It uses this feature to describe categories of mathematical objects. A good example are algebraic objects like groups, rings and fields.
On the left side you can see some examples how to construct and use them. The first one picks two integers out of the ring of integers modulo 7. The list() method lists all elements of that ring. Similar, the second example constructs an abelian group and assigns its generators to the letters a, b and c.

Parallel Distributed Computing

sage: dsage.setup()
[...]
Configuration finished.

sage: D = dsage.start_all()
[...]
Spawned python $SAGE/local/bin/dsage_worker.py ...
[...]

sage: j = D('factor(18152631827)')

sage: j.wait()

sage: j
11 * 37 * 44601061
A part of Sage called "dsage" deals with coarse distributed computations. It is a framework for distributed computing using functions for calling evaluations in other Sage instances on other machines, catching up on those calls and synchronizing them and controlling the network. There is also a web-interface to monitor and control the working clients.
The commands on the left show a basic example how the framework can be used. dsage.setup() initializes the server with default parameters, sage: D = dsage.start_all() starts the default clients (two of them) and stores a communication and control interface in D. The following commands call the factorization command on the remote machine, the wait() method catches up when the execution has finished and finally, the object j holds the result of the calculation.
Further information can be found in the reference manual.

Embedding Sage into LaTeX

\section{SageTex Examples}

This is a small calculation:
The sum of $1+2+\sqrt{3} = \sage{1+2+sqrt(3)}$.

Here you can see a $sin()$-Function:
\sageplot{plot(sin(x), x, 0, 2*pi)}
     
It is possible to call Sage commands from inside a LaTeX document. The SageTex package provides special LaTeX commands, that translate Sage code into a Python file. Then, this file is evaluated by Sage and the results of each calculation are written back into the LaTeX file. This even works for graphics, source-code and saved objects.
The example on the left shows, how you can embed a formula like $$1+2+\sqrt{3}$$ and a plot in a LaTeX document.
This package is part of the Sage distribution in the /examples/latex_embed sub-directory together with the documentation. You can also obtain it online: CTAN: SageTex Package