Python/C2/Getting-started-with-sage-notebook/English-timed

From Script | Spoken-Tutorial
Revision as of 12:41, 10 July 2014 by Gaurav (Talk | contribs)

Jump to: navigation, search
Time Narration
00:00 Hello friends and Welcome to this spoken tutorial on "Getting started with Sage and Sage notebook".
00:07 At the end of this tutorial, you will be able to,
  1. Know what Sage and Sage notebook are.
  2. Start a Sage shell or notebook.
  3. Create new worksheets.
  4. Know about the menu options available and the cells in the worksheet.
  5. Evaluate cells, create and delete cells, navigate them.
  6. Make annotations in the worksheet.
  7. Use tab completion.
  8. Use code from other languages in the cells.
  9. Use the offline help available.
00:30 To start with, what is Sage?
00:33 Sage is a free, open-source mathematical software.
00:35 Sage can do a lot of math stuff for you including, but not limited to, algebra, calculus, geometry, cryptography, graph theory among other things.
00:48 It can also be used as an aid in teaching and research in any of the areas that Sage supports.
00:53 So let us start Sage now
00:56 We are assuming that you have Sage installed on your computer now.
01:00 If not please visit the sagemath dot org slash doc slash tutorial slash introduction dot html#installation for the tutorial on how to install Sage.
01:13 Now you can open the terminal
01:17 So, let us now learn how to start Sage.
01:19 So type on the terminal sage and hit enter
01:27 This should start a new Sage shell with the prompt sage.
01:32 So now we can type all the commands that Sage supports here.
01:35 But Sage comes bundled with a much more elegant tool called Sage Notebook.
01:40 So what is Sage Notebook?
01:44 Sage Notebook provides a web based user interface to use Sage.
01:48 So once we have a Sage notebook server up and running, all we want is a browser to access the Sage functionality.
01:56 For example there is an official instance of Sage Notebook server running at http colon double slash sagenb dot org.
02:06 You can visit that page, create an account there and start using Sage!
02:09 So all you need is just a modern browser to use Sage and nothing else!
02:15 The Sage notebook also provides a convenient way of sharing and publishing our work, which is very handy for research and teaching.
02:23 However we can also run our own instances of Sage notebook servers on all the computers, if we have a local installation of Sage to start the notebook server just type notebook and brackets.
02:43 This will start the Sage Notebook server.
02:46 If we are starting the notebook server for the first time, we are prompted to enter the password for the admin.
02:52 Type the password and make a note of it.
02:54 After this Sage automatically starts a browser page for you with the notebook opened.
03:01 If it doesn't automatically start a web page browser , check if the Notebook server started and there were no problems.
03:10 If so, open your browser and in the address bar, type the URL shown in the instructions upon running the notebook command on the sage prompt.
03:20 So you can type http colon double slash localhost colon 8000, in our case it is the point.
03:31 The notebook command gives an instruction telling Open your web browser to localhost colon 8000.
03:40 If you are not logged in yet, it shows the Notebook home page and textboxes to type the username and the password.
03:48 You can use the username 'admin' and the password you gave while starting the notebook server for the first time.
03:54 There are also links that recover forgotten password and to create new accounts.
04:00 Once we are logged in with the admin account we can see the notebook admin page.
04:03 A notebook can contain a collection of Sage Notebook worksheets.
04:09 Worksheet is basically a working area.
04:12 This is where we enter all the Sage commands on the notebook.
04:17 The admin page lists all the worksheets created.
04:21 On the topmost part of this page we have the links to various pages.
04:27 The home link takes us to the admin home page.
04:30 The published link takes us to the page which lists all the published worksheets.
04:34 The log link has the complete log of all the actions we did on the notebook.
04:38 We have the settings link where we can configure our notebook & the notebook server & create and manage accounts.
04:45 We have a link to help upon clicking opens a new window with the complete help of Sage.
04:52 The entire documentation of Sage is supplied with Sage for offline reference and this help link is the way to get into it.
05:01 Then we can report bugs about Sage by clicking on Report a Problem link and there is a link to sign out of the notebook.
05:10 We can create a new worksheet by clicking New Worksheet link
05:13 Sage prompts you for a name for the worksheet.
05:16 Let us name the worksheet as 'nbtutorial'.
05:24 Now we have our first worksheet which is empty.
05:31 Every Sage command must be entered in this cell.
05:34 A cell is equivalent to the prompt on console.
05:37 When we create a new worksheet, to start with we will have one empty cell.
05:43 Let us try out some math here
05:46 So you can type there 2 plus 2
05:52 then 57 point 1 raised to 100
06:00 The cap operator is used for exponentiation.
06:04 If you observed carefully, we typed two commands but the output of only last command was displayed.
06:12 By default each cell displays the result of only the last operation.
06:16 We have to use print statement to display all the results we want to be displayed.
06:22 Now we perform more operations, we want more cells.
06:27 So how do we create a new cell?
06:30 It is very simple.
06:31 As we hover our mouse above or below the existing cells we see a blue line, by clicking on this new line we can create a new cell.
06:46 We have a cell, we have typed some commands in it
06:51 So type matrix then within brackets 1,2,3,4 then charat then again in brackets minus 1.
07:07 but how do we evaluate that cell?
07:09 Pressing Shift along with Enter evaluates the cell.
07:17 Alternatively we can also click on the evaluate link and evaluate the cell given below.
07:22 After we create many cells, we may want to move between the cells.
07:27 To move between the cells use Up and Down arrow keys.
07:31 Also clicking on the cell will let you edit that particular cell.
07:38 To delete a cell, clear the contents of the cell and hit backspace
07:41 If you want to add annotations in the worksheet itself, on the blue line that appears on hovering the mouse around the cell, Hold Shift and click on the line.
07:56 This creates a What You See Is What You Get cell.
08:09 We can type in the editable cell.
08:12 This text contains both the bold text and italicized text.
08:36 Then you can type, it also contain bulleted list.
09:02 Then it also contain enumerated list.
09:29 In the same cell we can display typeset math using the LaTeX like syntax
09:34 So we have to type below that in dollar sign then slash int underscore zero raised to slash infty space e raised to power -x in curly braces then slash then dx then again a dollar symbol.
09:54 We enclose the math to be typeset within dollar and dollar or dollar dollar and dollar dollar as in LaTeX.
10:02 We can also obtain help for a particular Sage command or function within the worksheet itself by using a question mark following the command
10:10 So you can type for example sine question mark and hit enter.
10:24 You have to press shift enter.
10:27 Evaluating this cell gives me the entire help for the sine function inline and the worksheet itself.
10:34 Similarly we can also look at the source code of such command or function using double question mark
10:39 so for ex: you can type matrix question mark question mark then press shift and enter.
10:48 Sage notebook also provides the feature for autocompletion.
10:52 To autocomplete a command type first few unique characters and hit tab key. So you can type plot then tab
11:07 To list all the methods that are available for a certain variable or a datatype, we can use the variable name followed by the dot to access the methods available on it
11:20 So
11:26 you can type
11:28 s=
11:33 within single quotes hello
11:37 then s dot rep then tab
11:51 The output produced by each cell can be one of the three states.
11:55 It can be either the full output, or truncated output or hidden output.
12:00 The output area will display the error, if the Sage code was wrote in the cell did not successfully execute
12:09 So you can type a comma b is equal to 10
12:16 The default output we obtained now is a truncated output.
12:19 Clicking at the left of the output area when the mouse pointer turns to hand gives us the full output
12:30 clicking again makes the output hidden and it cycles.
12:38 Lastly, Sage supports a variety of languages and each cell on the worksheet contain code written in a specific language.
12:45 It is possible to instruct Sage to interpret the code in the language we have written.
12:54 This can be done by putting percentage sign(%) followed by the name of the language.
13:01 For example, to interpret the cell as Python code we put as the first line in the cell percentage symbol then python.
13:14 Similarly we have: %sh for shell scripting,percentage fortran for Fortran, percentage gap for GAP and so on.
13:25 Let us see how this works.
13:26 Say I have an integer.
13:28 The type of the integer in default Sage mode is
13:31 a is equal to 1
13:34 Then type within brackets a.
13:45 Output will be: type 'sage dot rings dot integer dot Integer'>>
13:52 or type within colon int
13:58 We see that Integers are Sage Integers.
14:00 Now let us put percentage python as the first line of the cell and execute the same code snippet
14:09 So you can type there in the cell
14:13 percentage python then a is equal to 1 then type a
14:20 So You can also get the Output colon type 'int'><
14:26 Now we see that the integer is a Python integer.
14:28 Why?
14:29 Because now we instructed Sage to interpret that cell as Python code.
14:36 This brings us to the end of this tutorial.
14:38 In thus tutorial, we have learnt to, Know about Sage and sage notebook.
14:42 Start Sage shell and sage notebook.
14:45 Create accounts and start using the notebook.
14:48 Create new worksheets.
14:49 Access the menus available on the notebook.
14:51 Evaluate cells in the worksheet.
14:54 7. delete the cells. and navigate around the cells.
14:57 8. Make annotations in the worksheet.
14:59 9. Use tab completions.
15:00 10. Embed code of other scripting languages in the cells.
15:05 Here are some self assessment questions for you to solve
15:08 1. Each cell in a sage worksheet displays the result of only the last operation.
15:13 True or False.
15:14 2. How do you evaluate a cell using the keyboard keys?
15:17 Shift key along with enter key
15:19 Control key along with enter key
15:21 Alt key along with enter key
15:23 And the answers,
15:26 1.The answer is True.
15:28 By default each cell displays the result of only the last operation.
15:31 2.We have to press Shift along with Enter evaluates the cell.
15:36 So we hope you have enjoyed This tutorial and found it useful.
15:41 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha