Cocalc 01 Sage Introduction Ipynb
This document aims to give a crash-course to Sage. There are many additional resources for help, including the built-in documentation (discussed below), the official Sage tutorial, and the (highly recommended) open textbook Computational Mathematics with SageMath. Sage is free and open source. Information on running a local installation can be found on the Sage installation guide. Alternatively, Sage can be run "in the cloud" by making a (free) account on the CoCalc website or by uploading a Jupyter notebook to a public git repository and using mybinder.org. This document is written as a Jupyter notebook, the most common (and convenient) way to write and execute Sage code.
A notebook is composed of cells. Most of the cells in this notebook consist of an Input section (containing Sage code) and (potentially) an output section (containing the result of evaluating that Sage code) −-− some code cells simply perform... A few cells (including the current one) consist of formatted text and LaTeX\rm\LaTeXLATEX equations, written using the Markdown markup language. A third type of cell contains plain, unformatted text. To execute a piece of Sage code, click on the Input section of the corresponding code cell and hit Shift + Enter (only hitting Enter simply adds a new line). The reader should execute each statement as they work through the notebook, and is encouraged to modify the code and play around as they go.
Note that skipping a cell may result in errors when later cells are executed (for instance, if one skips a code block defining a variable and later tries to run code calling that variable). To add a new cell, click to the left of any cell and press the "a" key (to insert above) or the "b" key (to insert below). To delete a cell, click to the left of a cell and press the "d" key twice. These (and other) tasks can also be accomplished through the menu bars at the top of the page. This introduction is based off of a worksheet originally written by Steven Melczer. This tutorial should take at most 3-4 hours to fully work through.
You can read it in HTML or PDF versions, or from the Sage notebook click "Help", then click "Tutorial" to interactively work through the tutorial from within Sage. Though much of Sage is implemented using Python, no Python background is needed to read this tutorial. You will want to learn Python (a very fun language!) at some point, and there are many excellent free resources for doing so including [PyT] and [Dive]. If you just want to quickly try out Sage, this tutorial is the place to start. For example: If you do not have Sage installed on a computer and just want to try some commands, use it online at http://sagecell.sagemath.org.
See the Sage Installation Guide in the documentation section of the main Sage webpage [SA] for instructions on installing Sage on your computer. Here we merely make a few comments. The Sage download file comes with “batteries included”. In other words, although Sage uses Python, IPython, PARI, GAP, Singular, Maxima, NTL, GMP, and so on, you do not need to install them separately as they are included with the Sage distribution. However, to use certain Sage features, e.g., Macaulay or KASH, you must install the relevant optional package or at least have the relevant programs installed on your computer already. Macaulay and KASH are Sage packages (for a list of available optional packages, type "sage -optional", or browse the “Download” page on the Sage website).
−12 log(x(t)+1)−12 log(x(t)−1)+log(x(t))=−12i π+t−log(2)−12 log(32)−12 log(12)\displaystyle -\frac{1}{2} \, \log\left(x\left(t\right) + 1\right) - \frac{1}{2} \, \log\left(x\left(t\right) - 1\right) + \log\left(x\left(t\right)\right) = -\frac{1}{2} i \, \pi + t - \log\left(2\right) - \frac{1}{2} \, \log\left(\frac{3}{2}\right) - \frac{1}{2}... [log(x(t))=−12i π+t−12 log(2)−12 log(32)+12 log(x(t)+1)+12 log(x(t)−1)]\displaystyle \left[\log\left(x\left(t\right)\right) = -\frac{1}{2} i \, \pi + t - \frac{1}{2} \, \log\left(2\right) - \frac{1}{2} \, \log\left(\frac{3}{2}\right) + \frac{1}{2} \, \log\left(x\left(t\right) + 1\right) + \frac{1}{2} \, \log\left(x\left(t\right) - 1\right)\right][log(x(t))=−21iπ+t−21log(2)−21log(23)+21log(x(t)+1)+21log(x(t)−1)] −12 (x+1)−12 (x−1)+1x\displaystyle -\frac{1}{2 \, {\left(x + 1\right)}} - \frac{1}{2 \, {\left(x - 1\right)}} + \frac{1}{x}−2(x+1)1−2(x−1)1+x1 −12 log(x+1)−12 log(x−1)+log(x)\displaystyle -\frac{1}{2} \, \log\left(x + 1\right) - \frac{1}{2} \, \log\left(x - 1\right) + \log\left(x\right)−21log(x+1)−21log(x−1)+log(x) −12 log(x+1)−12 log(x−1)+log(x)=c+t\displaystyle -\frac{1}{2} \, \log\left(x + 1\right) - \frac{1}{2} \, \log\left(x - 1\right) + \log\left(x\right) = c + t−21log(x+1)−21log(x−1)+log(x)=c+t This is an introduction to the basic functionality of Python and Sage, with an emphasis on seeing how to handle a worksheet and how to get more detailed help.
We will point out a little bit of the power that Sage has hiding in it, but this is not a full-fledged tutorial. There are two (main) ways to use sage: terminal and browser. Terminal: You can use sagemath from your computer itself. Everything lives on your computer. Uses your computers components, so it'll be faster. On Ubuntu, you can type sage from your computer and it'll open up the terminal.
You can then type whatever code you want and hit enter and you'll get the results. Browser: You can use sagemath from any website. Everything lives on the cloud (good for collaboration/sharing). Uses cocalc servers, so it'll be slower. This file is the browser version. We normally call these "worksheets" and each little box in a worksheet is a "cell".
This is where you write you code on the browser. Once you've written your code, you type shift + enter and you'll get your results. Let's test out that sage works. Try doing 2+7 in sage. In this notebook we will deal mainly with syntax and semantics in Python we explore some basic expressions in Python
we introduce some of the most important control flow statements This is a Jupyter notebook. It is an interface allowing us to combine code (in this case Python) and formatted text in a unified way. The basic unit in a notebook is a cell. You are right now reading the content of a "Markdown" cell, designed to input formatted text. There are also 'Code' cells, designed to input executable code.
CoCalc with Sage combines the capabilities of a word processor and a sophisticated calculator. Read and follow the instructions below to obtain an introduction to CoCalc and Sage and a review of some important mathematical concepts and techniques. You are encouraged to collaborate with other students and to seek assistance from the instructor and others. However, each student must submit their own completed notebook and acknowledge any collaborators, resources used, and assistance received. Note that there are some suggested exercises along the way, but it is only the assignment in the last section that should be submitted for a grade. Notebooks are partitioned into markdown and code cells.
To edit a markdown cell: double-click, type the text you want, and press shift-enter to make it look pretty. Lines starting with one to six hash marks (#) are converted into header font sizes. Text surrounded by single underscores or asterisks are emphasized, and text surrounded by two underscores or asterisks are strongly emphasized. More details about the markdown syntax can be obtained by clicking on 'Help' in the menu bar and then clicking on 'Markdown' in the dropdown menu. Exercise. Insert a new markdown cell below this one and type a random sentence with a word emphasized.
Code cells contain commands to be executed. The following code cell calculates cos(π3)+4(log(e13)−1512)\cos(\frac{\pi}{3})+4\left(\log(e^{13})-\sqrt{\frac{15}{12}}\right)cos(3π)+4(log(e13)−1215). Execute the command by clicking anywhere in the command and pressing shift-enter. Several observations can be made. Commands are typed with standard keyboard characters. The characters +, -, *, and / are used for addition, subtraction, multiplication, and division, respectively.
Functions are represented with standard names: cos for cosine, log for the natural logarithm, and sqrt for the square root. The arguments to functions are enclosed within parentheses. Finally, the output is an exact value: 5\sqrt{5}5 cannot be written as an integer or rational number and so is left as 5\sqrt{5}5, and the rational number 172\frac{17}{2}217 is left as 17/2 rather than... You can ask Sage to output an approximate real number or 'numerical' result by using the n function. Execute the next code cell and observe the output. This worksheet is based on William Stein's JPL09__intro_to_sage.sws worksheet and the Sage days 20.5_demo worksheet and aims to be an interactive introduction to Sage through exercises.
You will learn how to use the notebook and call the help. To evaluate code in the Sage Notebook, type the code into an input cell and press shift-enter or click the evaluate link. Try it now with a simple expression (e.g., 2+32 + 32+3). The first time you evaluate a cell takes longer than subsequent times since a new Sage process is started: Create new input cells by clicking blue line that appears between cells when you move your mouse around. Try it now:
You can go back and edit any cell by clicking in it (or using the keyboard to move up or down). Go back and change your 2+2 above to 3 + 3 and re-evaluate it. \n", " This is an introduction to the basic functionality of Python and Sage, with an emphasis on seeing how to handle a worksheet and how to get more detailed help. We will point out a little bit of the power that Sage has hiding in it, but this is not a full-fledged tutorial.\n", " There are two (main) ways to use sage: terminal and browser. \n", " Terminal: You can use sagemath from your computer itself.
Everything lives on your computer. Uses your computers components, so it'll be faster.\n", " On Ubuntu, you can type sage from your computer and it'll open up the terminal. You can then type whatever code you want and hit enter and you'll get the results.\n", " \n", " Browser: You can use sagemath from any website. Everything lives on the cloud (good for collaboration/sharing). Uses cocalc servers, so it'll be slower.\n", " This file is the browser version.
People Also Search
- CoCalc -- 01-sage-introduction.ipynb
- CoCalc -- introduction.ipynb
- CoCalc -- 01_sage.ipynb
- CoCalc -- Introduction to Python with Sage.ipynb
- CoCalc -- 01_introduction.ipynb
- CoCalc -- 1. Introduction.ipynb
- CoCalc -- A02 CoCalc Introduction.ipynb
- CoCalc -- Chapter One (Introduction).ipynb
- CoCalc -- Tutorial 1 - Using the Sage notebook and navigating the help ...
- embed.cocalc.com
This Document Aims To Give A Crash-course To Sage. There
This document aims to give a crash-course to Sage. There are many additional resources for help, including the built-in documentation (discussed below), the official Sage tutorial, and the (highly recommended) open textbook Computational Mathematics with SageMath. Sage is free and open source. Information on running a local installation can be found on the Sage installation guide. Alternatively, S...
A Notebook Is Composed Of Cells. Most Of The Cells
A notebook is composed of cells. Most of the cells in this notebook consist of an Input section (containing Sage code) and (potentially) an output section (containing the result of evaluating that Sage code) −-− some code cells simply perform... A few cells (including the current one) consist of formatted text and LaTeX\rm\LaTeXLATEX equations, written using the Markdown markup language. A third ...
Note That Skipping A Cell May Result In Errors When
Note that skipping a cell may result in errors when later cells are executed (for instance, if one skips a code block defining a variable and later tries to run code calling that variable). To add a new cell, click to the left of any cell and press the "a" key (to insert above) or the "b" key (to insert below). To delete a cell, click to the left of a cell and press the "d" key twice. These (and o...
You Can Read It In HTML Or PDF Versions, Or
You can read it in HTML or PDF versions, or from the Sage notebook click "Help", then click "Tutorial" to interactively work through the tutorial from within Sage. Though much of Sage is implemented using Python, no Python background is needed to read this tutorial. You will want to learn Python (a very fun language!) at some point, and there are many excellent free resources for doing so includin...
See The Sage Installation Guide In The Documentation Section Of
See the Sage Installation Guide in the documentation section of the main Sage webpage [SA] for instructions on installing Sage on your computer. Here we merely make a few comments. The Sage download file comes with “batteries included”. In other words, although Sage uses Python, IPython, PARI, GAP, Singular, Maxima, NTL, GMP, and so on, you do not need to install them separately as they are includ...