SageMath in nutshell

Rich and fast scientific calculator

Practically, every important function, a mathematical formula, is already implemented in SageMath. Below are some instructions that can be used in high school:

  • absolute value - abs,

  • factoring - factor,

  • factorial - factorial,

  • Newton’s symbol - binomial,

  • solve the equation - solve,

  • graph a function - plot,

  • next prime number - next_prime,

  • the greatest common divisor gcd

  • the least common multiple: lcm,

  • derivative - diff,

  • integral - integrate.

The first example shows Sage’s capabilites in arithmetics. You can use it to check for calculations by hand, homework assignments by students. If the teacher learns the programming language above, it can create code that will allow you to solve the “step-by-step” calculation.

SageMath is equipped with arbitrary precision arithmetics and, for example, can approximate numbers with any precision. These possibilities we used in our projects, first of all in RSA encryption and in the chapter on approximations of irrational expressions.

Logical expressions

SageMath and also the Python language, allows you to perform oparations on logical expressions. It can turn out to be useful in many areas. For example, consider the puzzle:

Riddles about liars

There are two kinds of people - one always lies and one says truth. Ala and Bolek belong to one of these categories. ala she said: Bolek and me are liars. Who is a liar and who he tells the truth?

By using SageMath we can accept the following interpretations: let \(a\) will be true if Ala is truthful and \(b\) will be true if Bolek is truthful. Then we can write in Sage:

You can see that the only solution is the one where Ala lies and Bolek speaks the truth.

Algebraic expressions

One of the most important possibilities that can be used in the classroom Mathematics, physics and chemistry are operation not only on on numbers, but also on symbolic variables. SageMath is excellent with symbolic calculations, i.e. it can perform calculations, transformations on algebraic expressions. Thus we can modify the form of the formula, express one variable with the help of others, derive general solutions to equations. Below are shown simple examples of shortened multiplication patterns and expressions measurable.

Patterns of shortened multiplication.

Conversion of the form of algebraic expressions

Substitutions in symbolic expressions.

Simplifying expressions containing trigonometric functions requires method .trig_simplify. For example, to use trigonometric identities:

If we want to prove the trigonometric identity better to use bool than trying to simplify expressions.

Solving equations and systems of equations

Many problems in physics and math lead to a equation or a system of equations which has to be solved. Of course no tool should replace the student’s self-solving skills, but can be very useful for exercises, checking the results, or too solving too complex equations. SageMath allows for solving difficult equations and systems of equations with one instruction - solve.

Here are some examples that demonstrate use this functionality in two cases: quadratic eqaution and system of eqautions.

Quadratic equation.

System of two equations

Visualisation

Visualization is a very important aspect of learning especially for the present generation of young people. Sage allows graphing functions in a simple way. So we can quickly present solutions on the plot or draw interesting functions during lessons. Students can modify existing code program and analyze the functions. This can be used not only in mathematics but also in other science subjects.

The following program address a classical problem of calculating zeros of a quadratic function. Short program allows not only for obtaining numerical result but also for its graphical visualization.

The command region_plot it is possible to visualize solution to inequalities.

In SageMath we can algorithmically create a formula of the function. Let us imagine that we want to plot a following expression:

\[f(x) = \sum_{i=0}^{N}\sin(\omega_i x)\]

for large values of of \(N\). It is clear that it it very difficult task without a computer. In SageMath we can easily make use of a loop and construct above sum. In physics, many wave and aoustic phenomema are connecteed with sums of signals of various frequencies and therefore plotting such function is not only an academic excercise. It can serve as an example of e.g. a wave packet.

Another interesting example is a graphical presentation of vector fields. It can have potantial applical for physics lessons. Below, we present a plot of magnetic field of a magnetic dipole. It is possible to draw in 3d, but here we plot a section at \(x=0\):

Interaction

Large educational values have computer programs able to produce animation of a given phenomena and/or allowing for dynamical change some parameters. This class of programms are, most often made in Flash or javascript technologies, are an attractive digital help in teaching. Usually, however, the student is limited to interacting with such a program. SageMath lets you go one step further - it makes it very easy to create these elements. Using relatively simple functions student can create an interactive application that can illustrate a given problem.

We will illustrate the following problem:

Intersections

How many solution has the equation \(x^2=x-a\) as a function of parameter \(a\in(0,\frac{1}{2})\)?

In SageMath we can easily plot as line \(y=x-a\) and parabola \(y=x^2\) and grafically inspect if they have intersections. We can also calculate analytically (using Sage or not) solution and plot them in the same figure. If we then use decorator @interact SageMath will generate us an interactive application:

SageMath = interdisciplinarity

In summary, SageMath gives an excellent tool following operations in a classroom:

  1. Quick and accurate calculations with arbitrarily large numbers.

  2. Manipulate algebraic expressions, Solving equations in complex numbers, solving systems of equations and inequalities.

  3. Visualization of solutions on graphs, drawing graphs of functions.

  4. Calculation of derivatives, integrals, and many other mathematical operations.

Moreover SageMath is a very good and rich programming tool, thanks to which we can combine computer science with mathematics, physics, chemistry.