getting-started-sagenotebook.rst
changeset 169 0b0620ae8f4d
parent 168 13280334ca2b
equal deleted inserted replaced
168:13280334ca2b 169:0b0620ae8f4d
    46 create an account there and start using Sage! So all you need is just
    46 create an account there and start using Sage! So all you need is just
    47 a browser, a modern browser 
    47 a browser, a modern browser 
    48 
    48 
    49 {{{ Intentional *cough* *cough* }}}
    49 {{{ Intentional *cough* *cough* }}}
    50 
    50 
    51 to use Sage and nothing else!
    51 to use Sage and nothing else! The Sage notebook also provides a
       
    52 convenient way of sharing and publishing our work which is very handy
       
    53 when we use Sage for research or for teaching.
    52 
    54 
    53 However we can also run our own instances of Sage notebook servers on
    55 However we can also run our own instances of Sage notebook servers on
    54 all the computers we have a local installation of Sage. To start the
    56 all the computers we have a local installation of Sage. To start the
    55 notebook server just type::
    57 notebook server just type::
    56 
    58 
    57   notebook()
    59   notebook()
    58 
    60 
    59 on the Sage prompt. This will start the Sage Notebook server.
    61 on the Sage prompt. This will start the Sage Notebook server. If we
    60 If we are starting the notebook server for the first time, we are
    62 are starting the notebook server for the first time, we are prompted
    61 prompted to enter the password for the admin. Type the password and
    63 to enter the password for the admin. Type the password and make a note
    62 make a note of it. After this Sage automatically starts a browser page
    64 of it. After this Sage automatically starts a browser page for you
    63 for you with the notebook opened.
    65 with the notebook opened.
    64 
    66 
    65 If it doesn't automatically start a browser page check if the Notebook
    67 If it doesn't automatically start a browser page check if the Notebook
    66 server started and there were no problems. If so open your browser and
    68 server started and there were no problems. If so open your browser and
    67 in the address bar type the URL shown in the instructions upon running
    69 in the address bar type the URL shown in the instructions upon running
    68 the notebook command on the sage prompt.
    70 the notebook command on the sage prompt.
    87 admin page. A notebook can contain a collection of Sage Notebook
    89 admin page. A notebook can contain a collection of Sage Notebook
    88 worksheets. Worksheets are basically the working area. This is where
    90 worksheets. Worksheets are basically the working area. This is where
    89 we enter all the Sage commands on the notebook.
    91 we enter all the Sage commands on the notebook.
    90 
    92 
    91 The admin page lists all the worksheets created. On the topmost part
    93 The admin page lists all the worksheets created. On the topmost part
    92 of this page we have the links to various pages. The home link takes
    94 of this page we have the links to various pages. 
    93 to the admin home page. The published link takes us the page which
    95 
    94 lists all the published worksheets.
    96 {{{ Whenever you talk on an individual link point your mouse towards
    95 
    97 the link. For each of the link go to the page and explain as below }}}
    96 
    98 
    97 
    99 The home link takes us to the admin home page. The published link
    98 
   100 takes us to the page which lists all the published worksheets. The log
    99 This brings us to the end of the session on using Sage notebook. In
   101 link has the complete log of all the actions we did on the
   100 this tutorial session we learnt
   102 notebook. We have the settings link where can configure our notebook,
   101 
   103 the notebook server, we can create and mangage accounts. We have a
   102   *
   104 link to help upon clicking opens a new window with the complete help
       
   105 of Sage. The entire documentation of Sage is supplied with Sage for
       
   106 offline reference and this help link is the way to get into it. Then
       
   107 we can report bugs about Sage by clicking on Report a Problem link and
       
   108 there is a link to sign out of the notebook.
       
   109 
       
   110 We can create a new worksheet by clicking New Worksheet link
       
   111 
       
   112 {{{ Click on the link }}}
       
   113 
       
   114 Sage prompts you for a name for the worksheet. Let us name the
       
   115 worksheet as nbtutorial. Now we have our first worksheet which is
       
   116 empty.
       
   117 
       
   118 A worksheet will contain a collection of cells. Every Sage command
       
   119 must be entered in this cell. Cell is equivalent to the prompt on
       
   120 console. When we create a new worksheet, to start with we will have
       
   121 one empty cell. Let us try out some math here::
       
   122 
       
   123   2 + 2
       
   124   57.1 ^ 100
       
   125 
       
   126 The cap operator is used for exponentiation. If you observed carefully
       
   127 we typed two commands but the output of only last command was
       
   128 displayed. By default each cell displays the result of only the last
       
   129 operation. We have to use print statement to display all the results
       
   130 we want to be displayed.
       
   131 
       
   132 {{{ Demonstrate creating a new cell }}}
       
   133 
       
   134 Now to perform more operations we want more cells. So how do we create
       
   135 a new cell? It is very simple. As we hover our mouse above or below
       
   136 the existing cells we see a blue line, by clicking on this new line we
       
   137 can create a new cell. 
       
   138 
       
   139 We have a cell, we have typed some commands in it, but how do we
       
   140 evaluate that cell? Pressing Shift along with Enter evaluates the
       
   141 cell. Alternatively we can also click on the evaluate link to evaluate
       
   142 the cell
       
   143 
       
   144 {{{ Evaluate the cell and demonstrate for both methods separately
       
   145 }}}::
       
   146 
       
   147   matrix([[1,2], [3,4]])^(-1)
       
   148 
       
   149 After we create many cells, we may want to move between the cells. To
       
   150 move between the cells use Up and Down arrow keys. Also clicking on
       
   151 the cell will let you edit that particular cell.
       
   152 
       
   153 {{{ Move between two cells created }}}
       
   154 
       
   155 To delete a cell, clear the contents of the cell and hit backspace
       
   156 
       
   157 {{{ Clear and demonstrate deleting the cell }}}::
       
   158 
       
   159   Makes no sense
       
   160 
       
   161 If you want to add annotations in the worksheet itself on the blue
       
   162 line that appears on hovering the mouse around the cell, Hold Shift
       
   163 and click on the line. This creates a What You See Is What You Get
       
   164 cell.
       
   165 
       
   166 {{{ Create a HTML editable cell }}}
       
   167 
       
   168 We can make our text here rich text. We can make it bold, Italics, we
       
   169 can create bulleted and enumerated lists in this area::
       
   170 
       
   171   This text contains both the **bold** text and also *italicised*
       
   172   text.
       
   173   It also contains bulleted list:
       
   174   * Item 1
       
   175   * Item 2
       
   176   It also contains enumerate list:
       
   177   1. Item 1
       
   178   2. Item 2
       
   179 
       
   180 In the same cell we can display typeset math using the LaTeX like
       
   181 syntax::
       
   182 
       
   183   $\int_0^\infty e^{-x} \, dx$
       
   184 
       
   185 We enclose the math to be typeset within $ and $ or $$ and $$ as in
       
   186 LaTeX.
       
   187 
       
   188 We can also obtain help for a particular Sage command or function
       
   189 within the worksheet itself by using a question mark following the
       
   190 command::
       
   191 
       
   192   sin?
       
   193 
       
   194 Evaluating this cell gives me the entire help for the sin function
       
   195 inline on the worksheet itself. Similarly we can also look at the
       
   196 source code of each command or function using double question mark::
       
   197 
       
   198   matrix??
       
   199 
       
   200 Sage notebook also provides the feature for autocompletion. To
       
   201 autocomplete a command type first few unique characters and hit tab
       
   202 key::
       
   203 
       
   204   sudo<tab>
       
   205 
       
   206 To see all the commands starting with a specific name type those
       
   207 characters and hit tab::
       
   208 
       
   209   plo<tab>
       
   210 
       
   211 To list all the methods that are available for a certain variable or
       
   212 a datatype we can use the variable name followed by the dot to access
       
   213 the methods available on it and then hit tab::
       
   214 
       
   215   s = 'Hello'
       
   216   s.rep<tab>
       
   217 
       
   218 The output produced by each cell can be one of the three states. It
       
   219 can be either the full output, or truncated output or hidden output.
       
   220 The output area will display the error if the Sage code we wrote in
       
   221 the cell did not successfully execute::
       
   222 
       
   223   a, b = 10
       
   224 
       
   225 {{{ Show the three states }}}
       
   226 
       
   227 The default output we obtained now is a truncated output. Clicking at
       
   228 the left of the output area when the mouse pointer turns to hand gives
       
   229 us the full output, clicking again makes the output hidden and it
       
   230 cycles.
       
   231 
       
   232 Lastly, Sage supports a variety of languages and each cell on the
       
   233 worksheet can contain code written in a specific language. It is
       
   234 possible to instruct Sage to interpret the code in the language we
       
   235 have written. This can be done by putting percentage sign(%) followed
       
   236 by the name of the language. For example, to interpret the cell as
       
   237 Python code we put::
       
   238 
       
   239   %python
       
   240 
       
   241 as the first line in the cell. Similarly we have: %sh for shell
       
   242 scripting, %fortran for Fortran, %gap for GAP and so on. Let us see
       
   243 how this works. Say I have an integer. The type of the integer in
       
   244 default Sage mode is
       
   245 {{{ Read the output }}}::
       
   246 
       
   247   a = 1
       
   248   type(a)
       
   249 
       
   250   Output: <type 'sage.rings.integer.Integer'>
       
   251 
       
   252 We see that Integers are Sage Integers. Now let us put %python as the
       
   253 first line of the cell and execute the same code snippet::
       
   254 
       
   255   %python
       
   256   a = 1
       
   257   type(a)
       
   258 
       
   259   Output: <type 'int'>
       
   260 
       
   261 Now we see that the integer is a Python integer. Why? Because now we
       
   262 instructed Sage to interpret that cell as Python code.
       
   263 
       
   264 This brings us to the end of the tutorial on using Sage. We learnt
       
   265 quite a lot about using the Notebook User Interface of Sage. We are
       
   266 now confident that we can comfortably use the notebook to learn more
       
   267 about Sage in the following tutorials. Let us summarize what we
       
   268 learnt. In this session we learnt
       
   269 
       
   270   * What is Sage
       
   271   * How to start Sage shell
       
   272   * What is Sage notebook
       
   273   * How to start the Sage notebook
       
   274   * How to create accounts and start using the notebook
       
   275   * How to create new worksheets
       
   276   * The menus available on the notebook
       
   277   * About cells in the worksheet
       
   278   * Methods to evaluate the cell, create new cells, delete the cells
       
   279     and navigate around the cells
       
   280   * To make annotations in the worksheet
       
   281   * Tab completions
       
   282   * And embedding code of other scripting languages in the cells
   103 
   283 
   104 {{{ Show the "sponsored by FOSSEE" slide }}}
   284 {{{ Show the "sponsored by FOSSEE" slide }}}
   105 
   285 
   106 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   286 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   107 
   287