Sage Quick Tips And Gotchas

**Gotchas and Tips for using Sage**

Sage or SageMath here refers to the Notebook interface.

Sage is easy enough to grab an empty worksheet and go, but sometimes that is frustrating. At least try looking at a sample worksheet to get the general idea. An reading a tutorial while you are learning ( suggest one ) may be a time saver in the long run.

- Use the help button on the top of each worksheet to get some useful tips, they are not, in general, repeated here.

- Formulas code etc. are entered in the rectangles ( called cells ) on the worksheet. End a line with a carriage return ( the enter key ) The response area is just below the cell. When Sage evaluates the cell the response area will contain… wait for it… the response. You may expect a response but not get it. Sage will usually print out something from the last line in a cell, but to be sure use print ( for numbers and symbols ) and show() for plots and formulas where you want to be sure to get output. You can use them as many times in a cell as you want.

- A green bar at the left side of the response area indicates that Sage is working on the response, and when complete the bar will disappear, this can be a little subtle and easy to miss. If there is no green bar and you want to start evaluation of the cell click on the test “evaluate”.

- Try printing 2 * pi and you expect to get something around 6.3, but instead you get 2 * pi, which is actually the right answer, but may not be what you want to push sage towards number use print n (2 * pi ). Same applies if x = 2 * pi, print n( x )

- Sometimes Sage gets stuck evaluating a cell, it will never finish. If you think this is the case then press the evaluate button again and wait a bit. If you are still stuck use the interrupt button and/or the restart button under the [actions ] drop down.

- The values from one cell are carried from one cell to the other in the order the cells are evaluated, normally from top to bottom. At the top of the work sheet is a drop down labeled [actions ]that will reevaluate all the cells on the worksheet. This may be useful to make sure all cells are evaluated from top to bottom or to recalculate some value that has been messed up by you.

- Values are carried from cell to cell but not from worksheet to worksheet. If you have multiple worksheets open the values are completely separate. Reset worksheet seems to reset all values.

- You can fairly easily mess up by redefining a symbol that you should not. For example if you use a variable like n = 6.022e23 then the function n() which tries to make a value numeric will no longer work.

- Add a cell: you normally get a new cell at the bottom of the sheet, to insert a new cell in the body of the worksheet go to the bottom of the cell and press control enter.

- Delete a cell: delete all its contents, plus one more backspace and the cell will go away.

- Sage is caps sensitive, so different capitalization s of symbols stand for different things. S may or may not be equal to s.

- Sage is math oriented so beware: by default most trig is based on radians, logs based on e. Do conversions if necessary.

- As in algebra a letter ( or several like hBar ) can have a numerical value, but a symbol can also be other things, a variable – no specific vale, a vector, a matrix, or a plot. The function type( ) will tell you what kind of thing a symbol stands for or will if you print it like “print type( hBar ) and show( hBar ) will print some representation of it. If a symbol has a numerical value then the function n() will left you print its value ( ie: printn(hBar) ).

- Sometimes the notebook facility used by show will stop showing formulas and expressions nicely, I do not understand quite what is going on, but I deal with it by saving the worksheet and reloading the page.

- Sometimes the entire contents of cell is not visible on the worksheet, clicking into the cell seems to force the entire cell to show. This is not an issue when printing a worksheet, all cells show in full.

- In all programming cut and paste is a good strategy. Find something that worked ( even from another worksheet), grab the material you need and then carefully edit it if necessary for its new context.

Sage Backing up and Moving Worksheets

A Sage Wiki home page

page revision: 6, last edited: 27 Feb 2014 02:14