# Difference between revisions of "SageMath"

m (Arojas moved page Sage-mathematics to SageMath: Program has been renamed) |
(Rename Sage -> SageMath) |
||

Line 7: | Line 7: | ||

{{Related articles end}} | {{Related articles end}} | ||

− | [http://www.sagemath.org Sage | + | [http://www.sagemath.org SageMath] (formerly '''Sage''') is a program for numerical and symbolic mathematical computation that uses [[Python]] as its main language. It is meant to provide an alternative for commercial programs such as Maple, Matlab, and Mathematica. |

− | + | SageMath provides support for the following: | |

* '''Calculus''': using [[Wikipedia:Maxima (software)|Maxima]] and [[Wikipedia:SymPy|SymPy]]. | * '''Calculus''': using [[Wikipedia:Maxima (software)|Maxima]] and [[Wikipedia:SymPy|SymPy]]. | ||

* '''Linear Algebra''': using the [[Wikipedia:GNU Scientific Library|GSL]], [[Wikipedia:SciPy|SciPy]] and [[Wikipedia:NumPy|NumPy]]. | * '''Linear Algebra''': using the [[Wikipedia:GNU Scientific Library|GSL]], [[Wikipedia:SciPy|SciPy]] and [[Wikipedia:NumPy|NumPy]]. | ||

Line 18: | Line 18: | ||

== Installation == | == Installation == | ||

− | + | SageMath can be [[Pacman|installed]] from the [[official repositories]]: | |

* {{Pkg|sagemath}} contains the command-line version; | * {{Pkg|sagemath}} contains the command-line version; | ||

− | * {{Pkg|sagemath-doc}} for documentation from the command line. | + | * {{Pkg|sagemath-doc}} for HTML documentation and inline help from the command line. |

− | * {{Pkg|sage-notebook}} includes the | + | * {{Pkg|sage-notebook}} includes the browser-based notebook interface. |

== Usage == | == Usage == | ||

− | + | SageMath mainly uses Python as a scripting language with a few [http://www.sagemath.org/doc/tutorial/afterword.html#section-mathannoy modifications] to make it better suited for mathematical computations. | |

− | === | + | === SageMath command-line === |

− | + | SageMath can be started from the command-line: | |

$ sage | $ sage | ||

− | For information on the | + | For information on the SageMath command-line see [http://www.sagemath.org/doc/reference/cmd/index.html this page]. |

− | The command-line is based on the IPython shell so you can use all its [http://www.sagemath.org/doc/tutorial/interactive_shell.html tricks] with | + | The command-line is based on the IPython shell so you can use all its [http://www.sagemath.org/doc/tutorial/interactive_shell.html tricks] with SageMath. For an extensive tutorial on IPython see the community maintained [http://wiki.ipython.org/Cookbook IPython Cookbook]. |

Note, however, that it is not very comfortable for some uses such as plotting. When you try to plot something, for example: | Note, however, that it is not very comfortable for some uses such as plotting. When you try to plot something, for example: | ||

sage: plot(sin,(x,0,10)) | sage: plot(sin,(x,0,10)) | ||

− | + | SageMath opens a browser window with the Sage Notebook. | |

=== Sage Notebook === | === Sage Notebook === | ||

− | A better suited interface for advanced usage in | + | A better suited interface for advanced usage in SageMath is the Notebook. |

To start the Notebook server from the command-line, execute: | To start the Notebook server from the command-line, execute: | ||

$ sage -n | $ sage -n | ||

Line 52: | Line 52: | ||

=== Cantor === | === Cantor === | ||

− | [http://edu.kde.org/applications/mathematics/cantor/ Cantor] is an application included in the KDE Edu Project. It acts as a front-end for various mathematical applications such as Maxima, | + | [http://edu.kde.org/applications/mathematics/cantor/ Cantor] is an application included in the KDE Edu Project. It acts as a front-end for various mathematical applications such as Maxima, SageMath, Octave, Scilab, etc. See the [http://wiki.sagemath.org/Cantor Cantor page] on the Sage wiki for more information on how to use it with SageMath. |

− | Cantor can be installed with the {{Pkg| | + | Cantor can be installed with the {{Pkg|cantor}} package or as part of the {{Grp|kde-applications}} or {{Grp|kdeedu}} groups, available in the [[official repositories]]. |

=== Documentation === | === Documentation === | ||

− | For local documentation, one can compile it into multiple formats such as HTML or PDF. To build the whole | + | For local documentation, one can compile it into multiple formats such as HTML or PDF. To build the whole SageMath reference, execute the following command (as root): |

# sage --docbuild reference html | # sage --docbuild reference html | ||

Line 66: | Line 66: | ||

== Optional additions == | == Optional additions == | ||

=== SageTeX === | === SageTeX === | ||

− | If you have installed [[TeX Live]] on your system, you may be interested in [http://www.sagemath.org/doc/tutorial/sagetex.html using SageTeX], a package that makes the inclusion of | + | If you have installed [[TeX Live]] on your system, you may be interested in [http://www.sagemath.org/doc/tutorial/sagetex.html using SageTeX], a package that makes the inclusion of SageMath code in LaTeX files possible. TeX Live is made aware of SageTeX automatically so you can start using it straight away. |

As a simple example, here is how you include a Sage 2D plot in your TEX document (assuming you use {{ic|pdflatex}}): | As a simple example, here is how you include a Sage 2D plot in your TEX document (assuming you use {{ic|pdflatex}}): | ||

Line 132: | Line 132: | ||

== See also == | == See also == | ||

* [http://www.sagemath.org/ Official Website] | * [http://www.sagemath.org/ Official Website] | ||

− | * [http://www.sagemath.org/doc/ | + | * [http://www.sagemath.org/doc/ SageMath Documentation] |

* [http://planet.sagemath.org/ Planet Sage] | * [http://planet.sagemath.org/ Planet Sage] | ||

− | * [http://wiki.sagemath.org/ | + | * [http://wiki.sagemath.org/ SageMath Wiki] |

− | * [http://www.sagemath.org/links-components.html Software Used by | + | * [http://www.sagemath.org/links-components.html Software Used by SageMath] |

## Revision as of 17:26, 25 April 2015

SageMath (formerly **Sage**) is a program for numerical and symbolic mathematical computation that uses Python as its main language. It is meant to provide an alternative for commercial programs such as Maple, Matlab, and Mathematica.

SageMath provides support for the following:

**Calculus**: using Maxima and SymPy.**Linear Algebra**: using the GSL, SciPy and NumPy.**Statistics**: using R (through RPy) and SciPy.**Graphs**: using matplotlib.- An
**interactive shell**using IPython. - Access to
**Python modules**such as PIL, SQLAlchemy, etc.

## Contents

## Installation

SageMath can be installed from the official repositories:

- sagemath contains the command-line version;
- sagemath-doc for HTML documentation and inline help from the command line.
- sage-notebook includes the browser-based notebook interface.

## Usage

SageMath mainly uses Python as a scripting language with a few modifications to make it better suited for mathematical computations.

### SageMath command-line

SageMath can be started from the command-line:

$ sage

For information on the SageMath command-line see this page.

The command-line is based on the IPython shell so you can use all its tricks with SageMath. For an extensive tutorial on IPython see the community maintained IPython Cookbook.

Note, however, that it is not very comfortable for some uses such as plotting. When you try to plot something, for example:

sage: plot(sin,(x,0,10))

SageMath opens a browser window with the Sage Notebook.

### Sage Notebook

A better suited interface for advanced usage in SageMath is the Notebook. To start the Notebook server from the command-line, execute:

$ sage -n

The notebook will be accessible in the browser from http://localhost:8080 and will require you to login.

However, if you only run the server for personal use, and not across the internet, the login will be an annoyance. You can instead start the Notebook without requiring login, and have it automatically pop up in a browser, with the following command:

$ sage -c "notebook(automatic_login=True)"

For a more comprehensive tutorial on the Sage Notebook see the Sage documentation. For more information on the `notebook()`

command see this page.

### Cantor

Cantor is an application included in the KDE Edu Project. It acts as a front-end for various mathematical applications such as Maxima, SageMath, Octave, Scilab, etc. See the Cantor page on the Sage wiki for more information on how to use it with SageMath.

Cantor can be installed with the cantor package or as part of the kde-applications or kdeedu groups, available in the official repositories.

### Documentation

For local documentation, one can compile it into multiple formats such as HTML or PDF. To build the whole SageMath reference, execute the following command (as root):

# sage --docbuild reference html

This builds the HTML documentation for the whole *reference* tree (may take longer than an hour). An option is to build a smaller part of the documentation tree, but you would need to know what it is you want. Until then, you might consider just browsing the online reference.

For a list of documents see `sage --docbuild --documents`

and for a list of supported formats see `sage --docbuild --formats`

.

## Optional additions

### SageTeX

If you have installed TeX Live on your system, you may be interested in using SageTeX, a package that makes the inclusion of SageMath code in LaTeX files possible. TeX Live is made aware of SageTeX automatically so you can start using it straight away.

As a simple example, here is how you include a Sage 2D plot in your TEX document (assuming you use `pdflatex`

):

- include the
`sagetex`

package in the preamble of your document with the usual

\usepackage{sagetex}

- create a
`sagesilent`

environment in which you insert your code:

\begin{sagesilent} dob(x) = sqrt(x^2 - 1) / (x * arctan(sqrt(x^2 - 1))) dpr(x) = sqrt(x^2 - 1) / (x * log( x + sqrt(x^2 - 1))) p1 = plot(dob,(x, 1, 10), color='blue') p2 = plot(dpr,(x, 1, 10), color='red') ptot = p1 + p2 ptot.axes_labels(['$\\xi$','$\\frac{R_h}{\\max(a,b)}$']) \end{sagesilent}

- create the plot, e.g. inside a
`float`

environment:

\begin{figure} \begin{center} \sageplot[width=\linewidth]{ptot} \end{center} \end{figure}

- compile your document with the following procedure:

$ pdflatex <doc.tex> $ sage <doc.sage> $ pdflatex <doc.tex>

- you can have a look at your output document.

The full documentation of SageTeX is available on CTAN.

## Troubleshooting

### TeX Live does not recognize SageTex

If your TeX Live installation does not find the SageTex package, you can try the following procedure (as root or use a local folder):

- Copy the files to the texmf directory:

# cp /opt/sage/local/share/texmf/tex/* /usr/share/texmf/tex/

- Refresh TeX Live:

# texhash /usr/share/texmf/ texhash: Updating /usr/share/texmf/.//ls-R... texhash: Done.

### Starting Sage Notebook Server throws an ImportError

The Sage Notebook Server is in an extra package sage-notebook. So, if you get an ImportError when launching

% sage --notebook ┌────────────────────────────────────────────────────────────────────┐ │ Sage Version 6.4.1, Release Date: 2014-11-23 │ │ Type "notebook()" for the browser-based notebook interface. │ │ Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ Please wait while the Sage Notebook server starts... Traceback (most recent call last): File "/usr/bin/sage-notebook", line 180, in <module> launcher(unknown) File "/usr/bin/sage-notebook", line 58, in __init__ from sagenb.notebook.notebook_object import notebook ImportError: No module named sagenb.notebook.notebook_object

you most likely do not have the package sage-notebook installed.