Department of Mathematics-ITS

These SageMath Cells and Jupyter Notebooks serve as dedicated teaching aids for the mathematics department at the Sepuluh Nopember Institute of Technology (ITS). They provide a platform to showcase how ITS mathematics students can bridge the gap between theoretical knowledge and practical applications. By performing calculations based on mathematical reasoning, students can simultaneously verify their understanding of mathematical concepts.

Furthermore, students can validate the mathematical ideas they have studied by utilizing their programming skills in languages like **Sage, Gap, GP**, and **Maxima**, all of which are specifically designed for symbolic mathematics. Numerical validation can also be facilitated by languages like **R** and **Python**.. All resources and computations are conveniently cloud-based.

Whoever follows the road of knowledge-seeking,اللهwill facilitate his journey toجَنَّة.

A free and open-source mathematical software package with an emphasis on computer algebra is called SageMath. "Embedded SageMath Cell" refers to SageMath programme cells that can be put into other programmes because SageMath can be embedded in other programmes.

Sagemath is useful for a variety of mathematical problems, such as:

- Symbolic and numerical computation
- Algebra
- Calculus
- Differential equations
- Numerical analysis
- Statistics
- Optimization
- Graphing
- Programming
- SageMath Features

Among the many characteristics of Sagemath are the following:

- A powerful and flexible syntax
- A large library of mathematical functions
- An extensive documentation
- A vibrant community of users and developers
- SageMath Applications

SageMath has several uses, some of which are as follows:

- Mathematical research
- Education
- Engineering
- Science
- Finance
- Business

A SageMath feature called "Embedded SageMath Cell" enables users to embed SageMath code in other documents, such Jupyter notebooks. This saves users from having to launch Sagemath (an interactive application) and use it as a calculator by enabling them to run SageMath code directly within the text. Furthermore, we can execute **python** code in SageMath Cell, including **sympy** (symbolic python), **numpy** (numerical python), **scipy** (scientific python), and so on.

**SageMath** is introduced in this section. "System for Algebra and Geometry Experimentation" was the original name of SAGE. Currently using SageMath. Its goal is to be a strong free open source substitute for open source **MAPLE**, **MATHEMATICA**, and **MATLAB**. It is free software, licenced under the **GPL**. SageMath is constructed upon numerous open source packages that already exist: The URL **NumPy**, **SciPy**, **matplotlib**, **Sympy**, ** Maxima**, **GAP**, **FLINT**, **R** and many others. Through an interface or wrapper, or directly through a common Python-based language, you can access their combined strength.

SageMath includes a large number of excellent open-source mathematical software programmes. Calculus, number theory (beginning to advanced), cryptography, commutative algebra, group theory, graph theory, exact and numerical linear algebra, and many more mathematical topics can all be discussed using the open-source SageMath programme. Furthermore, SageMath features interactive programmes that are simple to comprehend and, consequently, to construct, as well as graphical animations and capabilities. As a result, it will be highly beneficial for learning, particularly for maths. SageMath 10.2 is the most recent version, and it was released on December 3, 2023.

Python is the programming language utilised in SageMath. It was initially introduced by mathematician **William Stein** of the University of Washington, Seattle, who oversaw the development of SageMath.

**History and Development of SageMath**

The original intention behind the publication of SageMath's first edition, which was free and open-source software released under the GNU General Public Licence version 3, was to provide a "open source alternative to Magma, Maple, Mathematica, and MATLAB". Mathematical problems in algebra, number theory, geometry, and combinatorics can be resolved with the Magma computer algebra system. The programme, which is called after the algebraic structure magma, is compatible with both Windows and Unix-like operating systems. [Magma] is closed source software even if it is not non-commercial software (cost recovery, non-commercial proprietary). University of Washington mathematician William Stein is the creator and director of the SageMath project.

When creating SageMath, William Stein discovered that a number of open-source mathematical software packages—written in **C, C ++, Common Lisp, Fortran**, and **Python**—had already been developed in other languages.

Instead of creating the wheel, SageMath (primarily developed in Python and Cython) unifies a variety of specialised mathematical software products into a single interface that requires no programming knowledge beyond Python. Nevertheless, the hundreds of thousands of lines of original code that make up SageMath bring new functionality and provide the interface between its parts.

Professionals and students alike work on developing **SageMath**. Grants and volunteer labour are used to fund the development of SageMath. Still, the first full-time SageMath developer wasn't hired until 2016 (thanks to an EU grant). The same year, Stein expressed his dissatisfaction with the dearth of university financing and certification programmes for software development, stating this as the rationale behind his choice to resign from his academic post and devote all of his time to the project at a recently established business, SageMath, Inc. Sagemath's official website, [SageMath], and [WikiSageMath] provide comprehensive material and can be used as a resource.

SageMath is a powerful software programme for studying a wide range of mathematical topics, including calculus, number theory (from elementary to advanced), cryptography, commutative algebra, group theory, graph theory, and both precise and numerical linear algebra. It can also generate user-friendly visualizations like images, animations, and interactive programs. This makes SageMath a valuable tool for learning mathematics, especially for visual learners. The SageMath Cell Server provides access to the latest version of SageMath. You can check the specific version by typing the command `version()`

within a cell. For more information on SageMath development, please refer to [SageMath Development]. Based on the knowledge we given here, we took the initiative to construct the **SageMath-ITS Cell**. Computations can be done using **Sage, Gap, GP, HTML, Maxima, Octave, Python**, and **R** programming languages.

The Sage command line has a sage prompt in the input cell. If you are using a Sage notebook (the available input box), type, for example, `5+21`

in the input box cell, and click the Evaluate button to calculate the corresponding output.

To calculate the power of a number, type the following in the input cell: `123**1245`

, which calculates \(123^{1245}\). Please try it by typing the input on line 2 and then clicking the Evaluate button. To find out the version of SageMath you are currently using, type `version()`

on line \(3\) of the input, and then click the Evaluate button. Then copy and paste the following command on the next input line:

```
%display latex
```

A=matrix([[1,2], [3,4]])

print("A = ")

A

to display a matrix \(A=\left(\begin{array}{rr}
1 & 2 \\
3 & 4
\end{array}\right)\) of size \(2\times 2\). To determine the inverse of \(A\), which is \(B=A^{-1}=\left(\begin{array}{rr}
-2 & 1 \\
\frac{3}{2} & -\frac{1}{2}
\end{array}\right)\) copy and paste the following command:

```
print("B =")
```

A^-1

Copy and paste the following commands one by one:

```
print("AB = ")
```

A*A^-1

and

```
print("BA =")
```

A^-1*A

It can be seen that matrix \(A=\left(\begin{array}{rr}
1 & 2 \\
3 & 4
\end{array}\right)\) has invers \(B=\left(\begin{array}{rr}
-2 & 1 \\
\frac{3}{2} & -\frac{1}{2}
\end{array}\right)\).

The following integral is calculated: $$ \int\sqrt{x+1}\sqrt{x}\;dx $$ using the following command:

```
%display latex
```

x = var('x')

f=sqrt(x)*sqrt(1+x)

print("f(x) = ")

f

and

```
g=integrate(f, x)
```

print("The integral of f(x) with respect to x is: ", g)

Next, we test the anti-derivative of \(f(x)\), which is \(F(x)\). We can verify this by differentiating \(F(x)\) and checking if it equals \(f(x)\). Do this with the following command:

```
%display latex
```

h=diff(g,x)

h.canonicalize_radical()

If you want to know information about the commands you have typed in the input cell box, type the following in the input cell box, for example:

```
diff?
```

or

```
integrate?
```

If you place the command `%time`

at the beginning of an input line, the time it takes to execute the command will be displayed after the output. For example, we can compare the running times for certain exponential operations in a few ways. The timings below will likely be different on your computer, or even between different versions of SageMath. Try typing the following commands in the input cell box:

```
%time a = int(1938)^int(99484); print("a = ",a)
```

Sage provides extensive 2D plotting functionality. The underlying rendering is done using the **matplotlib Python library**. To get information on 2D plots, type `plot?`

. From this information, you can try drawing graphs from the existing examples.

plot?

Sage also provides extensive 3D plotting functionality. The underlying rendering is done using the matplotlib Python library. To get information on 3D plots, type `plot3d?`

, from this information you can try drawing graphs from the existing examples. Click the left mouse button and move around. By doing this, you can see the image from different angles.

Given any 3D graphics object M one can compute a raytraced representation by typing `M.show(viewer='tachyon')`

. For example, we draw two translucent spheres that contain a red tube, and render the result using Tachyon.
SageMath's 3D graphics capabilities are truly remarkable, as evidenced by the various examples provided here. Readers can learn from the 3D graphics code presented here and experiment by modifying the commands to suit their needs.

In addition to the 3D graphics presented here, you can interact with the Three.js JavaScript WebGL Renderer. A web-based interactive viewer using the Three.js JavaScript library maintained by https://threejs.org.

The viewer is invoked by adding the keyword argument `viewer='threejs'`

to the command `show()`

or any three-dimensional graphic. The scene is rendered and displayed in the users’s web browser. Interactivity includes

- Zooming in or out with the mouse wheel or pinching on a touch pad
- Rotation by clicking and dragging with the mouse or swiping on a touch pad
- Panning by right-clicking and dragging with the mouse or swiping with three fingers on a touch pad

The generated HTML file contains all data for the scene apart from the `JavaScript`

library and can be saved to disk for sharing or embedding in a web page. The option online can be set to `true`

to provide links to the required files in an online content delivery network. Alternately the required files can be downloaded from the Three.js GitHub repository and linked directly from the web server.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Generate data
x = np.linspace(-5, 5, 100)
y = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, y)
z = np.sin(np.sqrt(x**2 + y**2))
# Plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, cmap='viridis')
# Set labels and title
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('3D Surface Plot')
plt.show()

plot3d?

x,y = var('x,y')
plot3d(sin(x - y)*y*cos(x), (x, -3, 3), (y, -3, 3),mesh=True)

x, y = var('x y')
W = plot3d(sin(pi*((x)^2 + (y)^2))/2, (x, -1, 1), (y, -1, 1),frame=False, color='purple', opacity=0.8)
S = sphere((0, 0, 0), size=0.3, color='red', aspect_ratio=[1,1,1])
show(W + S, figsize=8)

def f(x,y):
return math.sin(y^2 + x^2)/math.sqrt(x^2 + y^2 + 0.0001)
P = plot3d(f, (-3, 3),(-3, 3), adaptive=True,color=rainbow(60, 'rgbtuple'), max_bend=.1, max_depth=15)
P.show()

def f(x,y):
return math.exp(x/5)*math.sin(y)
P = plot3d(f, (-5, 5), (-5, 5), adaptive=True, color=['red', 'yellow'])
from sage.plot.plot3d.plot3d import axes
S = P + axes(6, color='black')
S.show()

x, y = var('x y')
cm = colormaps.hsv
def c(x, y): return float((x + y + x*y)/15) % 1
plot3d(x*x + y*y, (x, -4, 4), (y, -4, 4), color=(c, cm))

T = Cylindrical('height', ['radius', 'azimuth'])
r, theta, z = var('r theta z')
T.transform(radius=r, azimuth=theta, height=z)
plot3d(9-r^2, (r, 0, 3), (theta, 0, pi), transformation=T)

S = Cylindrical('radius', ['azimuth', 'height'])
theta, z = var('theta, z')
plot3d(3, (theta, 0, 2*pi), (z, -2, 2), transformation=S)

T = Spherical('radius', ['azimuth', 'inclination'])
r, phi, theta = var('r phi theta')
T.transform(radius=r, azimuth=theta, inclination=phi)
plot3d(phi * theta, (theta, 0, pi), (phi, 0, 1), transformation=T)

S = Spherical('inclination', ['radius', 'azimuth'])
r, theta = var('r,theta')
plot3d(10, (r,0,5), (theta, 0, 2*pi), transformation=S)

SE = SphericalElevation('elevation', ['radius', 'azimuth'])
r, theta = var('r,theta')
plot3d(10, (r, 0, 5), (theta, 0, 2*pi), transformation=SE)

SE = SphericalElevation('elevation', ['radius', 'azimuth'])
r, theta = var('r,theta')
P1 = plot3d((pi/12)*sin(8*theta), (r,0.99,1), (theta, 0, 2*pi),transformation=SE, plot_points=(10,200))
P2 = sphere(center=(0,0,0), size=1, color='red', opacity=0.3)
P1 + P2

r, phi, theta = var('r phi theta')
SE = SphericalElevation('elevation', ['radius', 'azimuth'])
angles = [pi/18, pi/12, pi/6]
P1 = [plot3d(a, (r,0,3), (theta, 0, 2*pi), transformation=SE,
opacity=0.85, color='blue')
for a in angles]
S = Spherical('inclination', ['radius', 'azimuth'])
P2 = [plot3d(a, (r,0,3), (theta, 0, 2*pi), transformation=S,
opacity=0.85, color='red')
for a in angles]
show(sum(P1+P2), aspect_ratio=1)

r, u, v = var('r,u,v')
f = u*v; urange = (u, 0, pi); vrange = (v, 0, pi)
T = (r*cos(u), r*sin(u), v, [u, v])
plot3d(f, urange, vrange, transformation=T)

theta, z = var('theta,z')
cylindrical_plot3d(2, (theta, 0, 3*pi/2), (z, -2, 2))

theta, z = var('theta,z')
cylindrical_plot3d(cosh(z), (theta, 0, 2*pi), (z, -2, 2))

theta, z = var('theta,z')
cylindrical_plot3d(e^(-z^2)*(cos(4*theta) + 2) + 1, (theta, 0, 2*pi), (z, -2, 2), plot_points=[80, 80]).show(aspect_ratio=(1, 1, 1))

plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2))

plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True)

plot3d(lambda x, y: x^2 + y^2, (-2,2), (-2,2), adaptive=True, initial_depth=5)

var('x,y')
plot3d(x^2 + y^2, (x,-2,2), (y,-2,2))

var('x,y')
plot3d(sin(x*y), (x, -pi, pi), (y, -pi, pi))

var('x,y')
plot3d(sin(x^2 + y^2), (x,-5,5), (y,-5,5), plot_points=200)

var('x,y')
plot3d(sin(x^2 + y^2), (x, -5, 5), (y, -5, 5), plot_points=[10, 100])

var('x,y')
plot3d(sin(x - y)*y*cos(x), (x, -3, 3), (y, -3, 3), mesh=True)

var('x,y')
plot3d(sin(x - y)*y*cos(x), (x, -3, 3), (y, -3, 3), mesh=True,
thickness=2, viewer='threejs')

x,y = var('x,y')
P = plot3d(x + y + sin(x*y), (x, -10, 10), (y, -10, 10),
opacity=0.87, color='blue')
Q = plot3d(x - 2*y - cos(x*y),(x, -10, 10), (y, -10, 10),
opacity=0.3, color='red')
P + Q

x,y = var('x,y')
L = plot3d(lambda x,y: 0, (-5,5), (-5,5), color="lightblue", opacity=0.8)
P = plot3d(lambda x,y: 4 - x^3 - y^2, (-2,2), (-2,2), color='green')
Q = plot3d(lambda x,y: x^3 + y^2 - 4, (-2,2), (-2,2), color='orange')
L + P + Q

x, y = var('x y')
plot3d(sin(pi*(x^2 + y^2))/2, (x, -1, 1), (y, -1, 1))

x, y = var('x y')
plot3d(4*x*exp(-x^2 - y^2), (x, -2, 2), (y, -2, 2))

r, phi, z = var('r phi z')
trans = (r*cos(phi), r*sin(phi), z)
plot3d(cos(r), (r, 0, 17*pi/2), (phi, 0, 2*pi), transformation=trans, opacity=0.87).show(aspect_ratio=(1,1,2), frame=False)

phi, theta = var('phi, theta')
Y = spherical_harmonic(2, 1, theta, phi)
rea = spherical_plot3d(abs(real(Y)), (phi, 0, 2*pi), (theta, 0, pi), color='blue', opacity=0.6)
ima = spherical_plot3d(abs(imag(Y)), (phi, 0, 2*pi), (theta, 0, pi), color='red', opacity=0.6)
(rea + ima).show(aspect_ratio=1)

x,y = var('x,y')
spherical_plot3d((2 + cos(2*x))*(y + 1), (x, 0, 2*pi), (y, 0, pi), rgbcolor=(1, .1, .1))

x,y = var('x,y')
spherical_plot3d(1 + sin(5*x)/5, (x, 0, 2*pi), (y, 0, pi), rgbcolor=(1, 0.5, 0), plot_points=(80, 80), opacity=0.7)

x, y = var('x,y')
spherical_plot3d(1 + 2*cos(2*y), (x, 0, 3*pi/2), (y, 0, pi)).show(aspect_ratio=(1, 1, 1))

S = sphere(opacity=0.8, aspect_ratio=[1,1,1])
L = line3d([(0,0,0),(2,0,0)], thickness=10, color='red')
M = S + S.translate((2,0,0)) + L
M.show(viewer='tachyon')

t = Tachyon(xres=500, yres=500, camera_position=(2,0,0))
t.light((4,3,2), 0.2, (1,1,1))
t.texture('t2', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(1,0,0))
t.texture('t3', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,1,0))
t.texture('t4', ambient=0.1, diffuse=0.9, specular=0.5, opacity=1.0, color=(0,0,1))
t.sphere((0,0.5,0), 0.2, 't2')
t.sphere((0.5,0,0), 0.2, 't3')
t.sphere((0,0,0.5), 0.2, 't4')
t.show()

t = Tachyon(camera_position=(0,-4,1), xres=800, yres=600, raydepth=12,
aspectratio=.75, antialiasing=4)
t.light((0.02,0.012,0.001), 0.01, (1,0,0))
t.light((0,0,10), 0.01, (0,0,1))
t.texture('s', color=(.8,1,1), opacity=.9, specular=.95, diffuse=.3, ambient=0.05)
t.texture('p', color=(0,0,1), opacity=1, specular=.2)
t.sphere((-1,-.57735,-0.7071),1,'s')
t.sphere((1,-.57735,-0.7071),1,'s')
t.sphere((0,1.15465,-0.7071),1,'s')
t.sphere((0,0,0.9259),1,'s')
t.plane((0,0,-1.9259),(0,0,1),'p')
t.show()

cedges = [[[1, 1, 1], [-1, 1, 1]], [[1, 1, 1], [1, -1, 1]],
[[1, 1, 1], [1, 1, -1]], [[-1, 1, 1], [-1, -1, 1]], [[-1, 1, 1],
[-1, 1, -1]], [[1, -1, 1], [-1, -1, 1]], [[1, -1, 1], [1, -1, -1]],
[[-1, -1, 1], [-1, -1, -1]], [[1, 1, -1], [-1, 1, -1]],
[[1, 1, -1], [1, -1, -1]], [[-1, 1, -1], [-1, -1, -1]],
[[1, -1, -1], [-1, -1, -1]]]
t = Tachyon(xres=800, yres=600, camera_position=(-1.5,0.0,0.0), zoom=.2)
t.texture('t1', color=(0,0,1))
for ed in cedges:
t.fcylinder(ed[0], ed[1], .05, 't1')
t.light((-4,-4,4), .1, (1,1,1))
t.show()

cedges = [[[1, 1, 1], [-1, 1, 1]], [[1, 1, 1], [1, -1, 1]],
[[1, 1, 1], [1, 1, -1]], [[-1, 1, 1], [-1, -1, 1]], [[-1, 1, 1],
[-1, 1, -1]], [[1, -1, 1], [-1, -1, 1]], [[1, -1, 1], [1, -1, -1]],
[[-1, -1, 1], [-1, -1, -1]], [[1, 1, -1], [-1, 1, -1]],
[[1, 1, -1], [1, -1, -1]], [[-1, 1, -1], [-1, -1, -1]],
[[1, -1, -1], [-1, -1, -1]]]
t = Tachyon(xres=800, yres=600, camera_position=(-1.5,0.0,0.0),
projection='fisheye', frustum=(-1.2, 1.2, -1.2, 1.2))
t.texture('t1', color=(0,0,1))
for ed in cedges:
t.fcylinder(ed[0], ed[1], .05, 't1')
t.light((-4,-4,4), .1, (1,1,1))
t.show()

T = Tachyon(xres=800, antialiasing=4, raydepth=10,
projection='perspective_dof', focallength='1.0', aperture='.0025')
T.light((0,5,7), 1.0, (1,1,1))
T.texture('t1', opacity=1, specular=.3)
T.texture('t2', opacity=1, specular=.3, color=(0,0,1))
T.texture('t3', opacity=1, specular=1, color=(1,.8,1), diffuse=0.2)
T.plane((0,0,-1), (0,0,1), 't3')
ttlist = ['t1', 't2']
tt = 't1'
T.cylinder((0,0,.1), (1,1/3,0), .05, 't3')
for q in srange(-3, 100, .15):
if tt == 't1':
tt = 't2';
else:
tt = 't1'
T.sphere((q, q/3+.3*sin(3*q), .1+.3*cos(3*q)), .1, tt)
T.show()

p1 = sphere(color='red', opacity='.5')
p2 = sphere((-1,-1,1), color='cyan', opacity='.3')
p3 = sphere((1,-1,-1), color='yellow', opacity='.7')
show(p1 + p2 + p3, viewer='threejs')

def build_frame(t):
e = parametric_plot3d([sin(x-t), 0, x], (x, 0, 2*pi), color='red')
m = parametric_plot3d([0, -sin(x-t), x], (x, 0, 2*pi), color='green')
return e + m
frames = [build_frame(t) for t in (0, pi/32, pi/16, .., 2*pi)]
plot = animate(frames).interactive()
show(plot, delay=5, auto_play=False, projection='orthographic')

We present examples of animations created with the Three.js JavaScript WebGL Renderer.

# This Sagemath cell is provided for practice!

# This Sagemath cell is provided for practice!

# This Sagemath cell is provided for practice!

**Data structures** A data organization, and storage format that is usually chosen for efficient access to data. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data, i.e., it is an algebraic structure about data. [Source] are fundamental building blocks in **computer science** Computer science is the study of computation, information, and automation. Computer science spans theoretical disciplines (such as algorithms, theory of computation, and information theory) to applied disciplines (including the design and implementation of hardware and software). [Source]. They organize and store data efficiently, enabling easy access, modification, and retrieval. These structures are crucial for writing efficient algorithms and managing large **datasets** A data set (or dataset) is a collection of data. In the case of tabular data, a data set corresponds to one or more database tables, where every column of a table represents a particular variable, and each row corresponds to a given record of the data set in question. The data set lists values for each of the variables, such as for example height and weight of an object, for each member of the data set. Data sets can also consist of a collection of documents or files. [Source] in software development.

Here are some common data structures:

**Arrays**: A collection of elements stored in contiguous memory locations. Arrays offer constant-time access to elements but may have limitations when resizing.**Linked Lists**: A sequence of elements where each element points to the next one in the sequence. Linked lists allow for efficient insertion and deletion but may have slower access times compared to arrays.**Stacks**: A Last-In-First-Out (LIFO) data structure. Elements are added and removed from the same end, called the top. Common operations include push (add) and pop (remove).**Queues**: A First-In-First-Out (FIFO) data structure. Elements are added at the rear and removed from the front. Common operations include enqueue (add) and dequeue (remove).**Trees**: Hierarchical data structures composed of nodes. Trees have a root node, parent nodes, and child nodes. Examples include binary trees, binary search trees, and AVL trees.**Graphs**: A collection of nodes (vertices) connected by edges. Graphs can be directed or undirected and may have weighted edges.**Hash Tables**: Data structures that store key-value pairs. They use a hash function to compute an index into an array of buckets or slots, where the value can be stored or retrieved with an associated key.

These are just some of the foundational data structures, and there are many variations and combinations used in different scenarios depending on the requirements of the problem at hand. Understanding data structures and their properties is essential for designing efficient algorithms and building robust software systems.

The **greedy algorithm**A greedy algorithm is any algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage. In many problems, a greedy strategy does not produce an optimal solution, but a greedy heuristic can yield locally optimal solutions that approximate a globally optimal solution in a reasonable amount of time. [Source] can be used to determine the minimum number of bills to give when making a refund in a cash transaction. Here's how it works in practice: Imagine you need to return change for an amount like 678, using only bills of denominations 500, 100, 50, 20, 10, 5, and 1. How many bills would you need to minimize the total number given?

Let us understand this with the help of an example: If you have 1,000 and needs to return 678. We will start with 500 (the highest denomination) and find the number of bills of this denomination required by dividing the amount to be returned by the denomination (and then taking the floor), which is 678/500, which is 1. Now, the remaining balance can be found by subtracting from 678, which gives 178. This is followed by repeating the process with the next highest denomination. That is, for finding the number of denominations of 100, divide the remaining, i.e., 178 by 100 (and then take the floor), which gives 1. The remaining amount in the next step will be 78. Likewise, the number of notes of 50, 20, 10, 5, and 1 will be 1, 1, 0, 1, and 3. That is, the number of bills required for change are [1, 1, 1, 1, 0, 1, 3].

Here is the Python code to solve the problem mentioned before.

NumPy is not imported into sage initially. To use NumPy, you first need to import it. The basic object of computation in NumPy is an array. It is simple to create an array.

NumPy arrays can store any type of python object. However, for speed, numeric types are automatically converted to native hardware types (i.e., `int, float`

, etc.) when possible. If the value or precision of a number cannot be handled by a native hardware type, then an array of Sage objects will be created. You can do calculations on these arrays, but they may be slower than using native types. When the numpy array contains Sage or python objects, then the data type is explicitly printed as object. If no data type is explicitly shown when NumPy prints the array, the type is either a hardware float or int.

The `dtype`

attribute of an array tells you the type of the array. For fast numerical computations, you generally want this to be some sort of float. If the data type is float, then the array is stored as an array of machine floats, which takes up much less space and which can be operated on much faster.

You can create an array of a specific type by specifying the dtype parameter. If you want to make sure that you are dealing with machine floats, it is good to specify `dtype=float`

when creating an array.

You can access elements of a NumPy array just like any list, as well as take slices

You can do basic arithmetic operations

Note that `l*l`

will multiply the elements of `l`

componentwise. To get a dot product, use `numpy.dot()`

.

We can also create two dimensional arrays

This is basically equivalent to the following

The difference is that with `np.array(), m`

is treated as just an array of data. In particular `m*m`

will multiply componentwise, however with `np.matrix(), m*m`

will do matrix multiplication. We can also do matrix vector multiplication, and matrix addition.

If `n`

was created with `numpy.array()`

, then to do matrix vector multiplication, you would use `numpy.dot(n,v)`

.

All NumPy arrays have a shape attribute. This is a useful attribute to manipulate

This changes the one-dimensional array into a $5\times 5$ array.

NumPy arrays can be sliced as well

It is important to note that the sliced matrices are references to the original.

You will note that the original matrix changed. This may or may not be what you want. If you want to change the sliced matrix without changing the original you should make a copy.

Some particularly useful commands are

You can see that `numpy.arange()`

creates an array of floats increasing by `0.1`

from `0`

to `2`

. There is a useful command `numpy.r_()`

that is best explained by example.

`numpy.r_()`

provides a shorthand for constructing NumPy arrays efficiently. Note in the above `0.0:5.0`

was shorthand for `0.0, 1.0, 2.0, 3.0, 4.0`

. Suppose we want to divide the interval from `0`

to `5`

into `10`

intervals. We can do this as follows

The notation `0.0:5.0:11*j`

expands to a list of `11`

equally space points between `0`

and `5`

including both endpoints. Note that `j`

is the NumPy imaginary number, but it has this special syntax for creating arrays. We can combine all of these techniques.

Another useful command is `numpy.meshgrid()`

, it produces meshed grids. As an example suppose you want to evaluate $f(x,y)=x^2+y^2$ on a an equally spaced grid with $\Delta x=\Delta y = 0.25$ for $0\leq x,y\leq 1$. You can do that as follows

You can see that `numpy.meshgrid()`

produces a pair of matrices, here denoted $xx$ and $yy$, such that
$(xx[i,j],yy[x,j])$ has coordinates $(x[i],y[j])$. This is useful because to evaluate $f$ over a grid, we only need to evaluate it on each pair of entries in $xx, yy$. Since NumPy automatically performs arithmetic operations on arrays componentwise, it is very easy to evaluate functions over a grid with very little code.

A useful module is the `numpy.linalg`

module. If you want to solve an equation $Ax=b$ do

This creates a random $5\times 5$ matrix $A$, and solves $Ax=b$ where $b=[1.0,2.0,3.0,4.0,5.0]$. There are many other routines in the `numpy.linalg`

module that are mostly self-explanatory. For example there are `qr`

and `lu`

routines for doing **QR** and **LU** decompositions. There is also a command `eigs`

for computing **eigenvalues** of a matrix. You can always do

to get the documentation which is quite good for these routines.

Hopefully this gives you a sense of what NumPy is like. You should explore the package as there is quite a bit more functionality.

Click the "**Enable**" button below to calculate indefinite integrals. To perform the computation, click the "**Update**" button. Please type other functions in the available box to perform indefinite integration of the functions you want.

You can also perform indefinite integral computations using **Geogebra** as follows. Try observing and comparing the computation results in the **SageMath** Cell with the results in **Geogebra**.

We provide some problems, you can try solving them with SageMath.

- Find the integral: \(\operatorname{\Large\int} \dfrac{\sqrt{3}}{\sqrt{3x^2-2}}\; dx\).

**Solution: Click to display/hide!**To solve this problem, we need a geometric diagram of the following right triangle:

If \(a=u\) and \(b=1\), then \(c=\sqrt{u^{2} - 1}\). This leads to \(\sec(\theta)=u\) and \(\tan(\theta)=\sqrt{u^{2} - 1}\). We will also be utilizing the following trigonometric identities: \begin{equation} \fbox{\(\tan^2(\theta)=\sec^{2} - 1\)}.\label{eqn1}\tag{1} \end{equation} and (

**the reader is encouraged to verify**) the equation: \begin{equation} \fbox{\(\int\; \sec(\theta)\;d\theta=\ln|\sec(\theta)+\tan(\theta)|+k\)}.\label{eqn2}\tag{2} \end{equation} Now, we are ready to calculate the requested integral. \begin{eqnarray*} \operatorname{\Large\int} \dfrac{\sqrt{3}}{\sqrt{3x^2-2}}\; dx &=& \operatorname{\Large\int} \dfrac{\sqrt{3}}{\sqrt{2(\frac{3}{2}x^2-1)}}\; dx\\ &=& \operatorname{\huge\int} \dfrac{\sqrt{3}}{\sqrt{2}}\dfrac{1}{\sqrt{\left(\frac{\sqrt{3}}{\sqrt{2}}x\right)^2-1)}}\; dx,\\ && \qquad{\rm{let,}}\ u=\frac{\sqrt{3}}{\sqrt{2}}x\Rightarrow du=\frac{\sqrt{3}}{\sqrt{2}}dx\\ &=& \operatorname{\Large\int} \dfrac{1}{\sqrt{u^2-1}}\; du. \end{eqnarray*} To calculate the last integral that appears here, we substitute \(u=\sec(\theta)\). We discussed the reason for this substitution when we discussed the trigonometric diagram. This gives us \(du=\sec(\theta)\tan(\theta)d\theta\). Using Equation (\ref{eqn1}) and Equation (\ref{eqn2}), we have \[ \begin{eqnarray*} \operatorname{\Large\int} \dfrac{1}{\sqrt{u^2-1}}\; du &=& \operatorname{\Large\int} \dfrac{\sec(\theta)\tan(\theta)}{\sqrt{\sec^2(\theta)-1}}\; d\theta\\ &=& \operatorname{\Large\int} \dfrac{\sec(\theta)\tan(\theta)}{\sqrt{\tan^2(\theta)}}\; d\theta\\ &=& \operatorname{\Large\int} \dfrac{\sec(\theta)\tan(\theta)}{\tan(\theta)}\; d\theta\\ &=& \int\; \sec(\theta)\;d\theta\\ &=& \ln|\sec(\theta)+\tan(\theta)|+k\\ &=& \ln|u + \sqrt{u^{2} - 1}|+k\\ &=& \ln\left| \frac{\sqrt{3}}{\sqrt{2}}x +\sqrt{\frac{3}{2}x^2 -1} \right| + k\\ &=& \ln\left| \frac{6}{2\sqrt{6}}x +\frac{1}{\sqrt{2}}\sqrt{3x^2 -2} \right| + k\\ &=& \ln\left| \frac{6}{2\sqrt{6}}x +\frac{2\sqrt{3}}{2\sqrt{6}}\sqrt{3x^2 -2} \right| + k\\ &=& \ln\left|\frac{1}{2\sqrt{6}} \left(6x +2\sqrt{3}\sqrt{3x^2 -2}\right) \right| + k\\ &=& \ln\left|6x +2\sqrt{3}\sqrt{3x^2 -2}\right| + \ln\left(\frac{1}{2\sqrt{6}}\right)+k,\\ &&\qquad\qquad \ c=\ln\left(\frac{1}{2\sqrt{6}}\right)+k \\ &=& \ln\left|6x +2\sqrt{3}\sqrt{3x^2 -2}\right| + c. \end{eqnarray*} \] The reader is invited to verify this result using SageMath computation, noting that \(\ln\) in SageMath is represented as \(\log\).\(\qquad\bigstar\)

- Compute \(\operatorname{\Large\int} \dfrac{1}{2+x^2}\; dx\).

**Solution: Click to display/hide!**\[ \begin{eqnarray*} \operatorname{\Large\int} \dfrac{1}{2+x^2}\; dx &=& \operatorname{\huge\int} \dfrac{1}{2\left(1+\left(\frac{x}{\sqrt{2}}\right)^{2}\right)}\; dx,\\ &&\qquad {\rm{suppose}}\ \tan(\theta)=\frac{x}{\sqrt{2}}\Rightarrow \sqrt{2}\sec^{2}(\theta)d\theta=dx\\ &=& \operatorname{\Large\int} \dfrac{\sqrt{2}\sec^{2}(\theta)}{2(1+\tan^2(\theta)}\; d\theta\\ &=&\frac{\sqrt{2}}{2}\int \frac{\sec^2(\theta)}{\sec^2(\theta)}\;d\theta\\ &=& \frac{\sqrt{2}}{2}\int d\theta\\ &=& \frac{\sqrt{2}}{2}\theta +c\\ &=& \frac{\sqrt{2}}{2}\arctan\left(\frac{1}{2}\sqrt{2}x\right)+c.\quad\bigstar \end{eqnarray*} \]

- Compute \(\operatorname{\Large\int} \dfrac{e^{x}}{\sqrt{1-e^{2x}}}\;dx\).

**Solution: Click to display/hide!**\[ \begin{eqnarray*} \operatorname{\Large\int} \dfrac{e^{x}}{\sqrt{1-e^{2x}}}\;dx &=& \operatorname{\Large\int} \dfrac{e^{x}}{\sqrt{1-(e^{x})^2}}\;dx\\ &&\qquad {\rm{suppose}}\ \sin(\theta)=e^{x}\Rightarrow \cos(\theta)d\theta=e^{x}dx\\ &=& \operatorname{\Large\int} \dfrac{\cos(\theta)}{\sqrt{1-\sin^2(\theta)}}\;d\theta\\ &=& \operatorname{\Large\int} \dfrac{\cos(\theta)}{\sqrt{\cos^2(\theta)}}\;d\theta\\ &=& \operatorname{\Large\int} \dfrac{\cos(\theta)}{\cos(\theta)}\;d\theta\\ &=& \int d\theta\\ &=& \theta + c\\ &=& \arcsin(e^x)+c.\quad\bigstar \end{eqnarray*} \]

- Compute \(\operatorname{\Large\int}\dfrac{x}{4x^2+12x+13}\,dx\).

**Solution: Click to display/hide!**From

**Exercise 2**, we can conclude that \(\fbox{\(\int\frac{1}{1+u^2}\;du=\arctan(u)+c\)}\). We use this result: \begin{eqnarray*} \operatorname{\Large\int}\dfrac{x}{4x^2+12x+13}\;dx &=& \frac{1}{4}\operatorname{\Large\int}\dfrac{x}{x^2+3x+\frac{9}{4}+1}\;dx\\ &=& \frac{1}{4}\operatorname{\Large\int}\dfrac{x}{\left(x+\frac{3}{2}\right)^2+1}\;dx,\\ &&\qquad {\rm{suppose}}\ u=x+\frac{3}{2}\Rightarrow du=dx, x=u-\frac{3}{2}\\ &=& \frac{1}{4}\operatorname{\Large\int}\dfrac{u-\frac{3}{2}}{u^2+1}\;du\\ &=& \frac{1}{4}\operatorname{\Large\int}\dfrac{u}{u^2+1}\;du-\frac{3}{8}\operatorname{\Large\int}\dfrac{1}{u^2+1}\;du\\ &=&\frac{1}{4}\operatorname{\Large\int}\dfrac{u}{u^2+1}\;du-\frac{3}{8}\arctan(u)+k\\ &=&\frac{1}{4}\operatorname{\Large\int}\dfrac{u}{u^2+1}\;du-\frac{3}{8}\operatorname{\Large\int}\dfrac{1}{u^2+1}\;du\\ &=&\frac{1}{4}\operatorname{\Large\int}\dfrac{u}{u^2+1}\;du-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=&\frac{1}{8}\operatorname{\Large\int}\dfrac{2udu}{u^2+1}-\frac{3}{8}\arctan(x+\frac{3}{2})+k,\\ &&\qquad {\rm{suppose}}\; v=u^2+1\Rightarrow dv=2udu\\ &=& \frac{1}{8}\operatorname{\Large\int}\dfrac{dv}{v}-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=& \frac{1}{8}\ln(v)-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=& \frac{1}{8}\ln(u^2+1)-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=& \frac{1}{8}\ln(x^2+3x+\frac{13}{4})-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=& \frac{1}{8}\ln\left(\frac{1}{4}(4x^2+12x+13)\right)-\frac{3}{8}\arctan(x+\frac{3}{2})+k\\ &=& \frac{1}{8}\ln(4x^2+12x+13)-\frac{3}{8}\arctan(x+\frac{3}{2})+\frac{1}{8}\ln(\frac{1}{4})+k\\ &=& \frac{1}{8}\ln(4x^2+12x+13)-\frac{3}{8}\arctan(x+\frac{3}{2})+c,\\ &&\qquad\text{where}\ c=\frac{1}{8}\ln(\frac{1}{4})+k.\ \qquad\bigstar \end{eqnarray*}

This computational tool calculates definite integrals of the form: \(\mathop{\int}\limits_{a}^{b}f(x)dx\) where \(f(x)\) is defined on the closed interval \([a,b]\). The tool requires two conditions:

- \(f(x)\) must be Riemann integrable on the interval \([a,b]\).
- The antiderivative of \(f(x)\), denoted by \(F(x)\), must satisfy the equation \(F'(x) = f(x)\) for all \(x\)-values within the interval.

If these conditions are not met, an "integral divergence error message" will appear.

To use the tool:

- Click the "
**Enable**" button below to calculate a definite integral. - Click the "
**Update**" button to change the integration limits \(a\) and \(b\) using the provided boxes. - Enter your desired function in the designated box.
- Specify the desired integration limits \(a\) and \(b\) in the corresponding boxes.

**Geogebra** can also be used to perform definite integral computations. Readers can then compare the results obtained with **Geogebra** to those produced by **SageMath**.

To solve the non-homogeneous system of equations \(Ax=b\):

- Click the "
**Enable**" button. - Enter the respective values of \(A\) and \(b\) in the provided boxes.
- Click the "
**Update**" button to perform the computation.

You can convert the system to a homogeneous system of equations by setting \(b=0\). To demonstrate the role of pivots, try changing the value of \(a_{1,1}\) to \(0\). This will result in row swapping. Enjoy!

Click the "**Enable**" button below to see the cycloid motion animation. Please try it!

**Cycloid Animation using Geogebra**

Perform SageMath Computations Independently. Follow the commands provided below:

- Click "
**Evaluate**" to see the results. - Feel free to replace the commands with other SageMath commands that you are familiar with.

**Surface Area of a Revolved Solid**
Given a curve \(y=f(x)\) and \(x\in [a,b]\). If the object is bounded by \(f(x)\) and \(x=a, x=b\) and rotated about the \(x\)-axis, then the surface area of the revolved solid is \(A\) with \(dA=2\pi\ y\ ds\) so that we get:
$$
A=2\pi\mathop{\int}\limits_{a}^{b}f(x)\sqrt{1+\left(f'(x)\right)^2}dx.
$$
**Example**

Given the curve \(y=f(x)=x\) and \(x\in [-1,1]\). If the object is bounded by \(f(x)\) and \(x=-1, x=1\) and rotated about the \(x\)-axis, then the surface area of the revolved solid is \(A\) with \(dA=2\pi\ y\ ds\) so that we get:
\[
A=2\pi\int_{-1}^{1}f(x)\sqrt{1+\left(f'(x)\right)^2}dx.
\]
Note: You can replace \(y=f(x)\) and the domain interval \([a,b]\) as desired!

The computational result is given in the SageMath cell as follows:

The following SageMath cell can be used to practice drawing various types of functions, including implicit functions. For example: \(y^3-3x^2+2x+5 = 0,\ -4\leq x\leq 4,\ -4\leq y \leq 4\).
About **plotting**, we recommend that our readers see more details at [plotting].

Let's give an example to calculate the value:
$$
\int \sqrt{x}\;\sqrt{1+x}\;dx.
$$
To get an exact result, we use the `canonicalize_radical()`

command as follows:

SageMath can be used to simulate dynamical systems, such as the predator-prey system or the Lotka-Volterra model. Here is an example of a simulation of a predator-prey system:

Let's delve deeper into the Lotka-Volterra equations, previously mentioned. These equations, also known as the Lotka-Volterra predator-prey model, are a pair of first-order, nonlinear differential equations. They're frequently used to describe the dynamics of biological systems where two species interact: one as a predator and the other as prey. Population changes over time according to the following equation: \begin{eqnarray*} \frac{dx}{dt} &=& \alpha x - \beta xy\\ \frac{dy}{dt} &=& \delta xy - \gamma y \end{eqnarray*} where

- the variable \(x\) represents the population density of the prey (e.g., the number of rabbits per square kilometer);
- the variable \(y\) represents the population density of a predator (e.g., the number of foxes per square kilometer);
- \(\frac{dx}{dt}\) and \(\frac{dy}{dt}\) represent the instantaneous rates of change of the two populations;
- \(t\) represents time.
- The prey model considers two factors affecting prey populations; \(\alpha\) represents the maximum rate at which prey can reproduce per individual \(\beta\), on the other hand, reflects the increased mortality rate of prey due to the presence of predators.
- The predator model also relies on two key parameters, \(γ\) and \(δ\); \(γ\) represents the per capita death rate of the predator, while \(δ\) captures the impact of prey presence on the predator's growth rate.
- All parameters are positive and real.

The solution to the differential equation is deterministic and continuous. This, in turn, implies that the generations of predators and prey continuously overlap.

The Lotka–Volterra equation system is an example of a Kolmogorov model, which is a more general framework that can model the dynamics of ecological systems with predator-prey interactions, competition, disease, and mutualism.

We simulate Lotka-Volterra Population Dynamics in a SageMath Cell. With the following code:

SageMath can be used to model differential equations, both ordinary differential equations (ODEs) and partial differential equations (PDEs): Here is an example of modeling an ODE and solving it exactly if there is a solution.

Now, let's consider the following ODE (Ordinary Differential Equation): $$ \frac{dy}{dx} + y - 1 = 0, $$ We'll solve it in a SageMath cell as shown below

The following is a second-order linear ODE: $$ \frac{d^2 y}{dx^2}+2\frac{dy}{dx} + y -\cos(x)=0,\ y(0)=3,\ y^{\prime}(0)=1. $$ Here's the solution code in a SageMath cell:

Next, we consider a higher-order linear ODE, in this case:
$$
-2 \, x^{4} + x^{3} \frac{d^{3}}{(d x)^{3}}y\left(x\right) + x^{2} \frac{d^{2}}{(d x)^{2}}y\left(x\right) - 2 \, x \frac{d}{d x}y\left(x\right) + 2 \, y\left(x\right) = 0.
$$
The solution is given in a SageMath cell using **sympy** as follows:

SageMath can be used to fit data to a mathematical model. Here is an example of fitting data to a linear regression model:

SageMath can be used to solve optimization problems, such as finding the maximum or minimum value of a function. Here is an example of finding the maximum value of the function \(f(x) = x^2 - 4x + 3\):

SageMath can be used to visualize mathematical objects, such as curves, surfaces, and graphs. Here is an example of visualizing a curve:

A square matrix is provided. We will analyze its behavior in a SageMath cell as follows:

We provide the Taylor Series Expansion of the function:
$$
f(x) = e^{-x}\sin(x).
$$
Please click the **Enable** box and move the slider to the desired order.

To calculate the integral
$$
\int_{0}^{\infty}e^{-x^2} dx
$$
we need the SciPy module `scipy.integrate`

, which contains several integration routines such as the Trapezoidal and Simpson's Rules. The workhorse for numerical integration in Python is the quad function (for quadrature, the traditional term for numerical integration). The quad function itself is not a single method but a collection of routines that work together to achieve an accurate answer efficiently. The algorithm behind quad was originally written in Fortran in a package called QUADPACK. Here is the basic syntax for the quad function:

Next, we calculate the exact value of $$ \int_{0}^{\infty}e^{-x^2} dx $$ as well as its numerical value using SageMath as follows:

Compute and plot the partial sum of the Taylor series for:
$$
\ln(1 + x)
$$
At what value of \(x\) does the Taylor series converge?

Recall that the Taylor series for a continuous differentiable function \(f\) expanded about \(x = 0\) (also known as the Maclaurin series) is given by:
\begin{equation}
f(x) = f(0) + f'(0)x + \frac{f''(0)}{2!}x^2 + \frac{f'''(0)}{3!} x^3 + \cdots = \sum_{n=0}^{\infty}\frac{f^{(n)}}{n!}x^n.
\tag{1}
\end{equation}
For the given function, we obtain:
$$
\ln(1 + x) = \sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n}x^n.\tag{2}
$$
Plotting the graph of \(y=\ln(1 + x)\) together with the partial sums of the Taylor series up to the term \(x^{20}\) is given in the SageMath cell below. Because of the large number of lines, it may be helpful to start plotting only the partial sums up to the \(5\)th and so on. The first few partial sums do not tell you much more than the fact that they are poor approximations.

Systematically coloring the different curves can also be helpful. In our plot, we gradually adjust the values of `(r, g, b)`

to make the curves 'bluer' as the number of terms increases (i.e., by increasing the value of `b`

from `0`

to `1`

and keeping `r = g = 0`

).

The `(r, g, b)`

values are the red, green, and blue components of the color, respectively. By increasing the value of b from \(0\) to \(1\), we are making the curves bluer. Keeping \(r = g = 0\) means that the curves will have no red or green components.

From the graph (and further experimentation with the number of terms in the partial sum), we can make the following observations:

The Taylor series for \(\ln(1+x)\) appears to converge to \(\ln(1+x)\) for \(x\in(−1,1)\), possibly also at \(x=1\).
However, for \(x > 1\), the graphs with a large number of terms \(n\) show divergence (i.e., the \(y\) values become very large around \(x=1\) from the right).

**Explanation:**

The Taylor series for \(\ln(1+x)\) is given by:
$$
\ln(1 + x) = \sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} x^n
$$
This series converges for all values of \(x\) in the interval \((−1,1]\). However, it diverges for all values of \(x\) outside of this interval.

The graphs in the SageMath cell above show the partial sums of the Taylor series for \(\ln(1+x)\) up to the term-\(x^{20}\). As you can see, the partial sums converge to \(\ln(1+x)\) for \(x\in(−1,1)\). However, they diverge for \(x > 1\).

This is because the Taylor series for \(\ln(1+x)\) is an alternating series. Alternating series are known to converge if the terms decrease in absolute value and approach zero. However, the terms of the Taylor series for \(\ln(1+x)\) do not decrease in absolute value for \(x > 1\). This is why the series diverges for \(x > 1\).

**Conclusion:**

The Taylor series for \(\ln(1+x)\) converges to \(\ln(1+x)\) for \(x\in(−1,1]\). However, it diverges for \(x > 1\).

We perform computations with SageMath to determine the Taylor series of the previously discussed function as follows:

Next, we show the graph of the function \(f(x) = \ln(x+1)\) and the graph of \(g(x)\) which is the result of the Taylor series of \(f(x)\):

SageMath has a great ability to display a surface in 3D. This is very useful for analyzing the behavior of 3D surfaces, especially those related to Differential Geometry. To see the image from different angles, click the left cursor and move it!

These are two different Schlegel projections. The first is projected onto an icosahedron. The SageMath code is below the diagram.

A common situation in science and engineering: you have collected a bunch of data and you want to fit a function to it. SageMath trivializes this procedure.

First, we will create some data that has some inherent variance using list comprehension and the `normalvariate()`

function and store it in the array `data`

; then we will propose a model with some adjustable parameters, and find the parameter values that fit best. Finally, we will plug those parameter values back into the model and plot it alongside the data.

A natural source of graphs, known as **Cayley graphs**, In mathematics, a Cayley graph, also known as a Cayley color graph, Cayley diagram, group diagram, or color group, is a graph that encodes the abstract structure of a group. Its definition is suggested by Cayley's theorem (named after Arthur Cayley), and uses a specified set of generators for the group. It is a central tool in combinatorial and geometric group theory. The structure and symmetry of Cayley graphs makes them particularly good candidates for constructing expander graphs. [Source] comes from group theory. **Representation theory** Representation theory is a branch of mathematics that studies abstract algebraic structures by representing their elements as linear transformations of vector spaces, and studies modules over these abstract algebraic structures. In essence, a representation makes an abstract algebraic object more concrete by describing its elements by matrices and their algebraic operations (for example, matrix addition, matrix multiplication). The theory of matrices and linear operators is well-understood, so representations of more abstract objects in terms of familiar linear algebra objects helps glean properties and sometimes simplify calculations on more abstract theories. [Source] motivates us to analyze the eigenvalues of Cayley graphs at least for Abelian groups.

**Definition**

Let \(G\) be a **finite group.** In abstract algebra, a finite group is a group whose underlying set is finite. Finite groups often arise when considering symmetry of mathematical or physical objects, when those objects admit just a finite number of structure-preserving transformations. Important examples of finite groups include cyclic groups and permutation groups. The study of finite groups has been an integral part of group theory since it arose in the 19th century. One major area of study has been classification: the classification of finite simple groups (those with no nontrivial normal subgroup) was completed in 2004. [Source] A symmetric subset of \(G\) is a subset \(S\subseteq G\) that satisfies the following conditions:

- The identity element \(1\) is not in \(S\).
- If \(s\) is in \(S\), then the inverse \(s^{-1}\) is also in \(S\).

If \(S\) is a symmetric subset of \(G\), then the graph of \(G\) associated with \(S\) is the graph with vertex set \(G\) and with an edge \(\{g,h\}\) connecting \(g\) to \(h\) if and only if \(gh^{-1}\in S\) or equivalently \(hg^{-1}\in S\).

In other words, the graph of \(G\) associated with \(S\) is the graph that has a vertex for each element of \(G\) and an edge between two vertices \(g\) and \(h\) if and only if \(gh^{-1}\in S\) or \(hg^{-1}\in S\).

This graph is called the **Cayley graph** of G with respect to \(S\). It is a useful tool for studying the properties of \(G\). For example, the diameter of the Cayley graph is equal to the length of the longest word in \(G\).

**Note**: In the definition, \(S\) can be the empty set. In this case, the Cayley graph has no edges. Also, as is known, any finite group \(G\) is isomorphic to a permutation group \(G_p\). Therefore, to determine the graph of a group \(G\), we do it through the
**permutation group** In mathematics, a permutation group is a group \(G\) whose elements are permutations of a given set \(M\) and whose group operation is the composition of permutations in \(G\) (which are thought of as bijective functions from the set \(M\) to itself). The group of all permutations of a set \(M\) is the symmetric group of \(M\), often written as Sym(\(M\)). The term permutation group thus means a subgroup of the symmetric group. If \(M = \{1, 2,\ldots, n\}\) then Sym(\(M\)) is usually denoted by \(S_n\), and may be called the symmetric group on \(n\) letters. By Cayley's theorem, every group is **isomorphic** to some permutation group. The way in which the elements of a permutation group permute the elements of the set is called its group action. Group actions have applications in the study of symmetries, combinatorics and many other branches of mathematics, physics and chemistry. [Source] \(G_p\).

We can verify that the Cayley graph is connected (every two vertices are connected by a path) if and only if \(S\) **generates** \(G\).

**Example**

Let \(G=\mathbb{Z}/ 4\mathbb{Z}\) and \(S=\{\pm [1]_4\}\). To obtain the Cayley graph associated with \(S\); in SageMath cell, do the following:

1. Create the Abelian group \(G=\mathbb{Z}/ 4\mathbb{Z}\).

2. Construct the permutation group \(G_p\) from the Abelian group \(G\).

3. Determine the generators of the group \(G_p\).

4. From the available generators, create the symmetric set \(S\).

5. Associated with the group \(G_p\), create the adjacency matrix \(A\) with the generator \(S\).

6. From the adjacency matrix \(A\), create the Cayley graph.

The SageMath commands for generating a **Cayley graph** can be a bit tricky. We want to make sure to select the "simple" option and to choose a symmetric generating set, as shown in the two examples below of Cayley graphs of the Abelian group \(\mathbb{Z}/6\mathbb{Z}\) for the symmetric sets \(S_1=\{\pm 1,\pm 2\}\) and \(S_2=\{\pm 1,\pm 3\}\):

Next, we discuss the Cayley graph \(\Gamma\) of \(\mathbb{Z}/4\mathbb{Z}\times\mathbb{Z}/4\mathbb{Z}\), with the generator set \(S=\{±(0,1),±(1,0),±(1,1)\}\). We implement this in SageMath as follows:

Here is the SageMath code that implements the Cayley graph \(\Gamma\):

The following shows the Cayley graph of the group \(\mathbb{Z}/24\mathbb{Z}\) with the symmetry set \(S=\{[8]_{24},[16]_{24},[3]_{24},[21]_{24}\}\).

The following shows the Cayley graph of the group \(\mathbb{Z}/24\mathbb{Z}\) with the symmetry set $$ S_1=\{\pm [2]_{24},\pm [4]_{24},\pm [6]_{24},\pm [8]_{24},\pm [10]_{24}\}. $$

The following shows the Cayley graph of the group \(\mathbb{Z}/24\mathbb{Z}\) with the symmetry set $$ S_2=\{\pm [2]_{24},\pm [4]_{24},\pm [6]_{24},\pm [8]_{24},\pm [10]_{24},\pm [12]_{24}\}. $$

At first glance, graphs \(\Gamma_1\) and \(\Gamma_2\) appear to be the same. However, they are actually different, as evidenced by their distinct characteristic polynomials. Furthermore, it can be demonstrated that graphs \(\Gamma_1\) and \(\Gamma_2\) are not isomorphic, and thus \(\Gamma_1\) and \(\Gamma_2\) are indeed different. We will show this as follows:

To get complete information about a graph in SageMath Cell, use the command `Graph?`

.

Before we conclude our discussion of Cayley graphs, let us introduce a different topic from before: Cayley graphs generated from a non-commutative group. For example, if G is a group and \(C\subseteq G\) (i.e., a list of some elements of \(G\)), then we can generate the Cayley graph \(X(G,C)\) as follows:

The output is a directed graph, even if \(C\) is closed under inversion; in the latter case we can turn \(G\) into a graph as follows:

Note that C is not required to construct G. There are a number of keywords for this command (e.g., side and simple).

Also, note that the command `_Graph()`

makes it easy to create your own Cayley graphs. For example, the cube-like graph is the Cayley graph for \(GF(2)^d\). We can construct it using the command `_Graph()`

. In the following example, `_vector_list_`

is a list of \(01\)-vectors of length \(d\).

For a general group, we can use the following construction to create an undirected Cayley graph.

We can also use a **free group** In mathematics, the free group \(F_S\) over a given set \(S\) consists of all words that can be built from members of \(S\), considering two words to be different unless their equality follows from the group axioms (e.g. \(st = suu^{-1}t\) but \(s\neq t^{-1}\) for \(s,t,u\in S\)). The members of \(S\) are called generators of \(F_S\), and the number of generators is the rank of the free group. An arbitrary group \(G\) is called free if it is isomorphic to \(F_S\) for some subset \(S\) of \(G\), that is, if there is a subset \(S\) of \(G\) such that every element of \(G\) can be written in exactly one way as a product of finitely many elements of \(S\) and their inverses (disregarding trivial variations such as \(st = suu^{-1}t\)). [Source] \(G\) generated by elements through a set of relations to construct a Cayley graph. Here is an example:

We will next illustrate the concept of a **total graph** The total graph \(T = T(G)\) of a graph G is a graph such that (i) the vertex set of \(T\) corresponds to the vertices and edges of \(G\) and (ii) two vertices are adjacent in \(T\) if and only if their corresponding elements are either adjacent or incident in \(G\). [Source] for a ring. Here's an example for the ring of integers modulo \(R\), along with the corresponding SageMath code.

We provide ten SageMath Cells that you can use as practice toverify mathematical theorieslearned in lectures!

**JupyterLab** is a next-generation web-based user interface for Project Jupyter. It enables you to work with documents and activities such as Jupyter notebooks, text editors, terminals, and custom components in a flexible, integrated, and extensible manner. It is the interface that you're looking at right now.

**Jupyter Notebooks** are a community standard for communicating and performing interactive computing. They are a document that blends computations, outputs, explanatory text, mathematics, images, and rich media representations of objects

To start a Jupyter notebook, click the **File** menu, then select **New** and **Notebook**.

To carry out activities in Jupyter Notebook, click **Code** and choose one option: **Code**, **Markdown**, or **Raw**.

In Jupyter Notebook, cells containing code are called **code cells**. These cells are where you write and execute programming instructions. The default kernel in Jupyter Notebook typically runs **Python** code, but you can use other languages depending on the chosen kernel. Here are some key points about code cells:

- They allow multiline text input with syntax highlighting for easier code readability.
- You can run the code in a cell by using the "Run" button, keyboard shortcuts (like Shift+Enter), or selecting the option from the "Cell" menu.
- The output from the code execution, such as text, plots, or tables, is displayed below the code cell.

Jupyter Notebook also offers other cell types for different purposes:

**Markdown cells**: Used for formatted text explanations, notes, or documentation within the notebook using Markdown syntax.**Raw cells**: Intended for arbitrary content that isn't evaluated by the kernel. They are useful for including things like system commands or notes that you don't want to execute.

If you need help with Jupyter Notebook, click **Help** and select the information you need.

This section provides access to computing facilities through a Jupyter notebook. To deepen your understanding of Jupyter notebooks' role in mathematics, particularly mathematical modeling, we've included the "**On-Jupyter-Maths.ipynb**" file. Click on this file to launch it in the Jupyter Notebook environment and explore the concepts discussed.