Chapter 1. Getting Started

Table of Contents

Getting Information
Basics
Fiddling with Vertices and Edges
Graph()
Vertices

Getting Information

The Sage tutorial at http://www.sagemath.org/doc/tutorial/index.html is the best starting point, and is very easy to read. The "constructions" manual is of very little use for graphs. The Sage reference manual at http://www.sagemath.org/doc/reference/index.html is vast. You will eventually need to read the sections on graphs, matrices, vector spaces, finite fields, power series and commutative rings.

If you are not up to speed with python, the first four or five chapters of "Dive into Python" (http://diveintopython.org/) could be useful and are available on line. (I do not think you will get much out the later chapters dealing with XML and HTML.) I also recommend the Python Tutorial (http://docs.python.org/tutorial/). You need to become comfortable with lists, dictionaries and list comprehensions. You can get quite a ways in Sage without knowing anything much about objects and classes, but you will need some familiarity with Python.

There are two basic ways of running Sage. One is to start Sage in a terminal window and then type notebook(). This starts up a web browser and you work from there.

The alternative, which I use, is to start Sage in a terminal window and then open up an editor. Set the working directory in Sage to the directory where your files are. (Sage recognizes ls, cd and pwd)---so don't use ls as the name of a list!) Write your code in the editor, save it as stuff.sage (say), then type load stuff.sage in your terminal window. Now you can run your code in Sage. You can load as many files as you like, and if you edit a file, load it again.

You can load a file with the command attach stuff.sage and then Sage will automatically reload your file each time you save it. A disadvantage of this approach is that certain syntax errors in your file can confuse Sage considerably. In this case you may have to hit control-C (and perhaps wait a bit) to unlock things. I have found it more convenient just to use the load command, as above.

You can save data to a file:

some_list = ['A', 356, x^2]
save( some_list, 'smlst')

and reload it with:

renamed_list = load('smlst')
renamed_list
['A', 356, x^2]

(The output to save is not human readable.) When you're working in Sage, on-line help can be obtained using help() and the tab key. Thus typing tab after graphs? or graphs?? gives information about the command graphs(). You will find situations where this does not work. Tab completion can sometimes save you typing in the full name for some command, but you will also find there are many contexts where it does not.

Do not forget that the command you are trying to understand may be a Python command; reasonably enough these are not explained in the Sage docs.