Symbolic Computation in Theoretical Physics with Python

Part 2: SageMath

SageMath

SageMath (Stein et al. ()) is an open-source system that combines many powerful mathematical software packages into one interface. It provides tools for symbolic computation, numerical analysis, plotting, and more, making it highly useful for both research and education in mathematics, physics, and engineering.

Basics

Fundamental operations, symbolic computation, and core mathematical structures.

Arithmetic operations

Support for basic arithmetic operations:

# Basic arithmetic operations

((3 + 5) / 8) - 2.5 ^ 3
14.6250000000000

Symbolic expressions

Support for symbolic expressions:

# Symbolic variables definition

var('x y')
(x,y)
# Symbolic expressions simplification

expr = (x^2 + x) / x
expr.simplify_full()
x+1

Calculus

SageMath provides tools for symbolic calculus such as differentiation and integration. You can compute derivatives and integrals of functions symbolically:

# Define function

f = x^2 + 3 * x + 2
f
x2+3x+2
# Differentiate with respect to x

diff(f, x)
2x+3
# Integrate with respect to x

integrate(f, x)
13x3+32x2+2x
# Plot of the function

plot(f, (x, -5, 5))

Differential equations

SageMath can solve differential equations symbolically:

# Define a differential equation

y = function('y')(x)
deqn = (diff(y, x) + y == sin(x))
deqn
y(x)+xy(x)=sin(x)
# Solve the differential equation

desolve(deqn, y)
12((cos(x)sin(x))ex2C)e(x)

Linear algebra

SageMath handles matrix operations, such as addition, multiplication, and finding eigenvalues:

# Define matrix A

A = Matrix([[1, 2], [3, 4], [5, 6]])  
A
(123456)
# Define matrix B

B = Matrix([[7, 8, 9], [9, 10, 11],])
B
(78991011)
# Matrix multiplication

A * B
(25283157647189100111)
# Define matrix C

C = Matrix([[1, 0], [0, 2]])  
C
(1002)
# Eigenvalue equation

C.eigenvectors_right()
[(2,[(0,1)],1),(1,[(1,0)],1)]
# Validation of eigenvalue equation

for eigenvalue, (eigenvector, *_), _ in C.eigenvectors_right():
    display((C, eigenvector, eigenvalue, C * eigenvector == eigenvalue * eigenvector))
((1002),(0,1),2,True)
((1002),(1,0),1,True)

Group theory

SageMath includes tools for working with groups:

# Define the symmetric group S3

G = SymmetricGroup(3)
G
(1,2,3),(1,2)
# Get the order of S3

G.order()
6
# List the elements of S3

G.list()
[1,(1,3,2),(1,2,3),(2,3),(1,3),(1,2)]
# Standard representation of S3

[g.matrix() for g in G]
[(100010001),(001100010),(010001100),(100001010),(001010100),(010100001)]

Differentiable manifolds

SageMath allows for computations in differential geometry, including tangent vectors, differential forms, and more:

# Declare the spacetime manifold M

S2 = manifolds.Sphere(2)
S2
S2
# Spherical coordinates

S2.spherical_coordinates()
(A,(θ,ϕ))
# Metric

S2.metric().display()
g=dθdθ+sin(θ)2dϕdϕ

Advanced

Exploring advanced mathematics in SageMath, including group theory, manifolds, Lie groups, and Lie algebras. This section broadly follows ().

Group theory

We begin by exploring finite groups, followed by an introduction to free groups and their presentation. Finally, we examine continuous groups and group actions.

Smallest finite groups

We present the list of all groups of finite order N8.

Order N = 1
# Z1

Z1 = CyclicPermutationGroup(1)
Z1.list()
[1]
Order N = 2
# Z2

Z2 = CyclicPermutationGroup(2)
Z2.list()
[1,(1,2)]
# Z2 Cayley table

print(Z2.cayley_table())
*  a b
 +----
a| a b
b| b a
# S2

S2 = SymmetricGroup(2)
S2.list()
[1,(1,2)]
# S2 Cayley table

print(S2.cayley_table())
*  a b
 +----
a| a b
b| b a
# Z2, S2 isomorphic

assert S2.is_isomorphic(Z2)
Order N = 3
# Z3

Z3 = CyclicPermutationGroup(3)
Z3.list()
[1,(1,2,3),(1,3,2)]
# Z3 Cayley table

print(Z3.cayley_table())
*  a b c
 +------
a| a b c
b| b c a
c| c a b
Order N = 4
# Z4

Z4 = CyclicPermutationGroup(4)
Z4.list()
[1,(1,2,3,4),(1,3)(2,4),(1,4,3,2)]
# Z4 Cayley table

print(Z4.cayley_table())
*  a b c d
 +--------
a| a b c d
b| b c d a
c| c d a b
d| d a b c
# Z4 cyclic

assert Z4.is_cyclic()
# Klein four-group

K4G = direct_product_permgroups([Z2, Z2])
K4G.list()
[1,(1,2),(3,4),(1,2)(3,4)]
# Klein four-group Cayley table

print(K4G.cayley_table())
*  a b c d
 +--------
a| a b c d
b| b a d c
c| c d a b
d| d c b a
# Klein four-group cyclic

assert not K4G.is_cyclic()
Order N = 5
# Z5

Z5 = CyclicPermutationGroup(5)
Z5.list()
[1,(1,2,3,4,5),(1,3,5,2,4),(1,4,2,5,3),(1,5,4,3,2)]
# Z5 Cayley table

print(Z5.cayley_table())
*  a b c d e
 +----------
a| a b c d e
b| b c d e a
c| c d e a b
d| d e a b c
e| e a b c d
Order N = 6
# Z6

Z6 = CyclicPermutationGroup(6)
Z6.list()
[1,(1,2,3,4,5,6),(1,3,5)(2,4,6),(1,4)(2,5)(3,6),(1,5,3)(2,6,4),(1,6,5,4,3,2)]
# Z6 Cayley table

print(Z6.cayley_table())
*  a b c d e f
 +------------
a| a b c d e f
b| b c d e f a
c| c d e f a b
d| d e f a b c
e| e f a b c d
f| f a b c d e
# Z2 x Z3

Z2xZ3 = direct_product_permgroups([Z2, Z3])
Z2xZ3.list()
[1,(1,2),(3,5,4),(1,2)(3,5,4),(3,4,5),(1,2)(3,4,5)]
# Z2 x Z3 Cayley table

print(Z2xZ3.cayley_table())
*  a b c d e f
 +------------
a| a b c d e f
b| b c a e f d
c| c a b f d e
d| d e f a b c
e| e f d b c a
f| f d e c a b
# S3

S3 = SymmetricGroup(3)
S3.list()
[1,(1,3,2),(1,2,3),(2,3),(1,3),(1,2)]
# S3 Cayley table

print(S3.cayley_table())
*  a b c d e f
 +------------
a| a b c d e f
b| b a d c f e
c| c e a f b d
d| d f b e a c
e| e c f a d b
f| f d e b c a
# Z6, Z2 x Z3 isomorphic

assert Z6.is_isomorphic(Z2xZ3)
# S3, Z6 non-isomorphic

assert not S3.is_isomorphic(Z6)
# S3, Z2 x Z3 non-isomorphic

assert not S3.is_isomorphic(Z2xZ3)
# Z6 cyclic

assert Z6.is_cyclic()
# Z2 x Z3 cyclic

assert Z2xZ3.is_cyclic()
# S3 cyclic

assert not S3.is_cyclic()
# Z6 abelian

assert Z6.is_abelian()
# Z2 x Z3 abelian

assert Z2xZ3.is_abelian()
# S3 non-abelian

assert not S3.is_abelian()
Order N = 7
# Z7

Z7 = CyclicPermutationGroup(7)
Z7.list()
[1,(1,2,3,4,5,6,7),(1,3,5,7,2,4,6),(1,4,7,3,6,2,5),(1,5,2,6,3,7,4),(1,6,4,2,7,5,3),(1,7,6,5,4,3,2)]
# Z7 Cayley table

print(Z7.cayley_table())
*  a b c d e f g
 +--------------
a| a b c d e f g
b| b c d e f g a
c| c d e f g a b
d| d e f g a b c
e| e f g a b c d
f| f g a b c d e
g| g a b c d e f
Order N = 8
# Z8

Z8 = CyclicPermutationGroup(8)
Z8.list()
[1,(1,2,3,4,5,6,7,8),(1,3,5,7)(2,4,6,8),(1,4,7,2,5,8,3,6),(1,5)(2,6)(3,7)(4,8),(1,6,3,8,5,2,7,4),(1,7,5,3)(2,8,6,4),(1,8,7,6,5,4,3,2)]
# Z8 Cayley table

print(Z8.cayley_table())
*  a b c d e f g h
 +----------------
a| a b c d e f g h
b| b c d e f g h a
c| c d e f g h a b
d| d e f g h a b c
e| e f g h a b c d
f| f g h a b c d e
g| g h a b c d e f
h| h a b c d e f g
# Z4 x Z2

Z4xZ2 = direct_product_permgroups([Z4, Z2])
Z4xZ2.list()
[1,(1,3)(2,4),(1,4,3,2),(1,2,3,4),(5,6),(1,3)(2,4)(5,6),(1,4,3,2)(5,6),(1,2,3,4)(5,6)]
# Z4xZ2 Cayley table

print(Z4xZ2.cayley_table())
*  a b c d e f g h
 +----------------
a| a b c d e f g h
b| b a d c f e h g
c| c d e f g h a b
d| d c f e h g b a
e| e f g h a b c d
f| f e h g b a d c
g| g h a b c d e f
h| h g b a d c f e
# Z2 x Z2 x Z2

Z2xZ2xZ2 = direct_product_permgroups([Z2, Z2, Z2])
Z2xZ2xZ2.list()
[1,(1,2),(3,4),(1,2)(3,4),(5,6),(1,2)(5,6),(3,4)(5,6),(1,2)(3,4)(5,6)]
# Z2xZ2xZ2 Cayley table

print(Z2xZ2xZ2.cayley_table())
*  a b c d e f g h
 +----------------
a| a b c d e f g h
b| b a d c f e h g
c| c d a b g h e f
d| d c b a h g f e
e| e f g h a b c d
f| f e h g b a d c
g| g h e f c d a b
h| h g f e d c b a
# D4

D4 = DihedralGroup(4)
D4.list()
[1,(1,3)(2,4),(1,4,3,2),(1,2,3,4),(2,4),(1,3),(1,4)(2,3),(1,2)(3,4)]
# D4 Cayley table

print(D4.cayley_table())
*  a b c d e f g h
 +----------------
a| a b c d e f g h
b| b a d c f e h g
c| c g a e d h b f
d| d h b f c g a e
e| e f g h a b c d
f| f e h g b a d c
g| g c e a h d f b
h| h d f b g c e a
# Q

Q = QuaternionGroup()
Q.list()
[1,(1,3)(2,4)(5,7)(6,8),(1,4,3,2)(5,8,7,6),(1,2,3,4)(5,6,7,8),(1,7,3,5)(2,6,4,8),(1,5,3,7)(2,8,4,6),(1,8,3,6)(2,7,4,5),(1,6,3,8)(2,5,4,7)]
# Q Cayley table

print(Q.cayley_table())
*  a b c d e f g h
 +----------------
a| a b c d e f g h
b| b c d a h e f g
c| c d a b g h e f
d| d a b c f g h e
e| e f g h c d a b
f| f g h e b c d a
g| g h e f a b c d
h| h e f g d a b c
# Z8, Z4 x Z2, Z2 x Z2 x Z2, D4, Q  non-isomorphic

from itertools import combinations
groups = [Z8, Z4xZ2, Z2xZ2xZ2, D4, Q]
for group1, group2 in combinations(groups, 2):
    if not group1.is_isomorphic(group2):
        display(f'{group1}, {group2} are not isomorphic.')
Cyclic group of order 8 as a permutation group, Permutation Group with generators [(1,2,3,4), (5,6)] are not isomorphic.
Cyclic group of order 8 as a permutation group, Permutation Group with generators [(1,2), (3,4), (5,6)] are not isomorphic.
Cyclic group of order 8 as a permutation group, Dihedral group of order 8 as a permutation group are not isomorphic.
Cyclic group of order 8 as a permutation group, Quaternion group of order 8 as a permutation group are not isomorphic.
Permutation Group with generators [(1,2,3,4), (5,6)], Permutation Group with generators [(1,2), (3,4), (5,6)] are not isomorphic.
Permutation Group with generators [(1,2,3,4), (5,6)], Dihedral group of order 8 as a permutation group are not isomorphic.
Permutation Group with generators [(1,2,3,4), (5,6)], Quaternion group of order 8 as a permutation group are not isomorphic.
Permutation Group with generators [(1,2), (3,4), (5,6)], Dihedral group of order 8 as a permutation group are not isomorphic.
Permutation Group with generators [(1,2), (3,4), (5,6)], Quaternion group of order 8 as a permutation group are not isomorphic.
Dihedral group of order 8 as a permutation group, Quaternion group of order 8 as a permutation group are not isomorphic.
# Z8 abelian

assert Z8.is_abelian()
# Z4 x Z2 abelian

assert Z4xZ2.is_abelian()
# Z2 x Z2 x Z2 abelian

assert Z2xZ2xZ2.is_abelian()
# D4 non-abelian

assert not D4.is_abelian()
# Q non-abelian

assert not Q.is_abelian()
# Q subgroups

for G in Q.subgroups():
    display(G)
Subgroup 1 of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
Subgroup (1,3)(2,4)(5,7)(6,8) of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
Subgroup (1,3)(2,4)(5,7)(6,8),(1,5,3,7)(2,8,4,6) of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
Subgroup (1,3)(2,4)(5,7)(6,8),(1,2,3,4)(5,6,7,8) of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
Subgroup (1,3)(2,4)(5,7)(6,8),(1,6,3,8)(2,5,4,7) of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
Subgroup (1,3)(2,4)(5,7)(6,8),(1,5,3,7)(2,8,4,6),(1,2,3,4)(5,6,7,8) of (1,2,3,4)(5,6,7,8),(1,5,3,7)(2,8,4,6)
# Q proper subgroups

for G in Q.subgroups():
    if G.order() == 2:
        if G.is_isomorphic(Z2) and G.is_normal():
            display(f'{G} is isomorphic to {Z2} and a normal subgroup of {Q}.')
    elif G.order() == 4:
        if G.is_isomorphic(Z4) and G.is_normal():
            display(f'{G} is isomorphic to {Z4} and a normal subgroup of {Q}.')
Subgroup generated by [(1,3)(2,4)(5,7)(6,8)] of (Quaternion group of order 8 as a permutation group) is isomorphic to Cyclic group of order 2 as a permutation group and a normal subgroup of Quaternion group of order 8 as a permutation group.
Subgroup generated by [(1,3)(2,4)(5,7)(6,8), (1,5,3,7)(2,8,4,6)] of (Quaternion group of order 8 as a permutation group) is isomorphic to Cyclic group of order 4 as a permutation group and a normal subgroup of Quaternion group of order 8 as a permutation group.
Subgroup generated by [(1,3)(2,4)(5,7)(6,8), (1,2,3,4)(5,6,7,8)] of (Quaternion group of order 8 as a permutation group) is isomorphic to Cyclic group of order 4 as a permutation group and a normal subgroup of Quaternion group of order 8 as a permutation group.
Subgroup generated by [(1,3)(2,4)(5,7)(6,8), (1,6,3,8)(2,5,4,7)] of (Quaternion group of order 8 as a permutation group) is isomorphic to Cyclic group of order 4 as a permutation group and a normal subgroup of Quaternion group of order 8 as a permutation group.

Symmetric groups

We present symmetric groups of different orders along with their properties.

Definitions
# S2 elements

S2 = SymmetricGroup(2)
S2.list()
[1,(1,2)]
# S3 elements

S3 = SymmetricGroup(3)
S3.list()
[1,(1,3,2),(1,2,3),(2,3),(1,3),(1,2)]
# S4 elements

S4 = SymmetricGroup(4)
S4.list()
[1,(1,3)(2,4),(1,4)(2,3),(1,2)(3,4),(2,3,4),(1,3,2),(1,4,3),(1,2,4),(2,4,3),(1,3,4),(1,4,2),(1,2,3),(3,4),(1,3,2,4),(1,4,2,3),(1,2),(2,3),(1,3,4,2),(1,4),(1,2,4,3),(2,4),(1,3),(1,4,3,2),(1,2,3,4)]
# S5 elements

S5 = SymmetricGroup(5)
S5.list()
[1,(1,5,4,3,2),(1,2),(1,4,2,5,3),(1,3,5,2,4),(2,5,4,3),(1,5,3)(2,4),(1,2,5,4,3),(1,4)(2,3,5),(1,3,4,5),(2,4)(3,5),(1,5,2,3,4),(1,2,4)(3,5),(1,4,5),(1,3,2),(2,3,4,5),(1,5),(1,2,3,4,5),(1,4,3,2),(1,3)(2,5,4),(3,4),(1,5,4,2),(1,2)(3,4),(1,4)(2,5,3),(1,3)(2,4,5),(2,5,4),(1,5,3,2,4),(1,2,5,4),(1,4,5,2,3),(1,3,5),(2,4,5,3),(1,5,2,3),(1,2,4,5,3),(1,4,3,5),(1,3,4,2),(2,3,5),(1,5)(3,4),(1,2,3,5),(1,4,2),(1,3,2,5,4),(3,5,4),(1,5,3,4,2),(1,2)(3,5,4),(1,4)(2,5),(1,3,2,4,5),(2,5,3,4),(1,5,2,4),(1,2,5,3,4),(1,4,5)(2,3),(1,3),(2,4,5),(1,5)(2,3),(1,2,4,5),(1,4,3),(1,3,5,4,2),(2,3),(1,5,4,3),(1,2,3),(1,4,2)(3,5),(1,3,4)(2,5),(4,5),(1,5,3,2),(1,2)(4,5),(1,4,3)(2,5),(1,3,5)(2,4),(2,5,3),(1,5,2,4,3),(1,2,5,3),(1,4,2,3,5),(1,3,4),(2,4,3,5),(1,5)(2,3,4),(1,2,4,3,5),(1,4),(1,3,2)(4,5),(2,3,4),(1,5,4),(1,2,3,4),(1,4,5,3,2),(1,3)(2,5),(3,4,5),(1,5,2),(1,2)(3,4,5),(1,4,3,2,5),(1,3)(2,4),(2,5),(1,5)(2,4,3),(1,2,5),(1,4,2,3),(1,3,5,4),(2,4,3),(1,5,4,2,3),(1,2,4,3),(1,4)(3,5),(1,3,4,5,2),(2,3,5,4),(1,5,3,4),(1,2,3,5,4),(1,4,5,2),(1,3,2,5),(3,5),(1,5,2)(3,4),(1,2)(3,5),(1,4,2,5),(1,3,2,4),(2,5)(3,4),(1,5)(2,4),(1,2,5)(3,4),(1,4)(2,3),(1,3)(4,5),(2,4),(1,5,4)(2,3),(1,2,4),(1,4,5,3),(1,3,5,2),(2,3)(4,5),(1,5,3),(1,2,3)(4,5),(1,4,3,5,2),(1,3,4,2,5)]
# S6 elements

S6 = SymmetricGroup(6)
S6.list()
[1,(1,6,5,4,3,2),(1,2),(1,5,3)(2,6,4),(1,4)(2,5)(3,6),(1,3,5)(2,4,6),(2,6,5,4,3),(1,6,4,2,5,3),(1,2,6,5,4,3),(1,5,2,4)(3,6),(1,4,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)(2,5,3),(1,2,6)(4,5),(1,5,2,4,3),(1,4,2,3,6,5),(1,3,5,6,4),(2,5,3),(1,6,5,2,4,3),(1,2,5,3),(1,5)(2,3,6,4),(1,4)(3,5,6),(1,3,4,6,2),(2,4,3,6,5),(1,6,4,2,3,5),(1,2,4,3,6,5),(1,5,6,3,4),(1,4,6,2),(1,3,2,6)(4,5),(2,3,5,6,4),(1,6,3,4),(1,2,3,5,6,4),(1,5,4,6,2),(1,4,5,3,2,6),(1,3)(2,5),(3,5,4,6),(1,6,2)(3,4,5),(1,2)(3,5,4,6),(1,5,2,6),(1,4,3,2,5),(1,3)(2,4)(5,6),(2,6)(3,4,5),(1,6)(2,5),(1,2,6)(3,4,5),(1,5)(2,4,3),(1,4,2,3)(5,6),(1,3,6,4),(2,5),(1,6,5)(2,4,3),(1,2,5),(1,5,6,4,2,3),(1,4)(3,6),(1,3,5,4,6,2),(2,4,3)(5,6),(1,6,4,2,3),(1,2,4,3)(5,6),(1,5,4)(3,6),(1,4,6,2)(3,5),(1,3,4,5,2,6),(2,3,6,4),(1,6,3,5,4),(1,2,3,6,4),(1,5,3,4,6,2),(1,4,5,2,6),(1,3,2,5),(3,6)(4,5),(1,6,2)(3,5),(1,2)(3,6)(4,5),(1,5,2,6)(3,4),(1,4,2,5),(1,3,2,4)(5,6),(2,6)(3,5),(1,6)(2,5)(3,4),(1,2,6)(3,5),(1,5)(2,4),(1,4)(2,3)(5,6),(1,3)(4,6),(2,5)(3,4),(1,6,5)(2,4),(1,2,5)(3,4),(1,5,6,4)(2,3),(1,4,6,3),(1,3,6,2)(4,5),(2,4)(5,6),(1,6,4)(2,3),(1,2,4)(5,6),(1,5,4,6,3),(1,4,5,3,6,2),(1,3,5,2,6),(2,3)(4,6),(1,6,3)(4,5),(1,2,3)(4,6),(1,5,3,6,2),(1,4,3,5,2,6),(1,3,4,2,5)]
Multiplication
# S4 elements multiplication

P = S4[5]
Q = S4[12]
print(f'P = {P}, Q = {Q}')
print(f'P * Q = {Q * P}')
P = (1,3,2), Q = (3,4)
P * Q = (1,3,4,2)
Signature
# S4 elements signature

P = S4[16]
Q = S4[2]
print(f'P = {P}, Q = {Q}')
print(f'sgn(P) = {P.sign()}')
print(f'sgn(Q) = {Q.sign()}')
P = (2,3), Q = (1,4)(2,3)
sgn(P) = -1
sgn(Q) = 1
Alternating groups
# A4 elements

A4 = AlternatingGroup(4)
A4.list()
[1,(1,2)(3,4),(1,3)(2,4),(1,4)(2,3),(2,3,4),(1,2,4),(1,3,2),(1,4,3),(2,4,3),(1,2,3),(1,3,4),(1,4,2)]
# A4 subgroup of S4

assert A4.is_subgroup(S4)
# A4 elements signature

assert all(e.sign() == 1 for e in A4)
# A4 order

assert A4.order() == S4.order() / 2
Cayley’s theorem

Every finite group of order N is isomorphic to a subgroup of SN.

# S2 subgroups

assert Z2.is_subgroup(S2)
# S3 subgroups

assert Z3.is_subgroup(S3)
# S4 subgroups

assert Z4.is_subgroup(S4)
assert K4G.is_subgroup(S4)
# S5 subgroups

assert Z5.is_subgroup(S5)
# S6 subgroups

assert Z6.is_subgroup(S6)
assert Z2xZ3.is_subgroup(S6)
assert S3.is_subgroup(S6)

Free groups

A free group G is defined as follows:

  • X={g1,g2,,gn} a subset of G
  • gG{e} can be uniquely written as g=gj1i1gj2i2gjmim with ikZ{0} and gjigji+1

A relation r is a constraint rgj2i1gj2i2gjmim=e.

The presentation of the group G is defined as g1,g2,,gnr1,r2,,rm.

# G = <a>

G.<a> = FreeGroup(1)
G
Free Group on generators {a}
# G = <a, b>

G.<a, b> = FreeGroup(2)
G
Free Group on generators {a, b}
# G = <a|a^n>

n = 3
F.<a> = FreeGroup(1)
G = F / [a^n]
G
aa3
# G, Z3 isomorphism

assert Z3.is_isomorphic(G.as_permutation_group())
# G = <a,b| a*b*a^(-1)*b^(-1)>

F.<a, b> = FreeGroup(2)
G = FreeGroup(['a', 'b']) / [a*b*a^(-1)*b^(-1)]
G
a,baba1b1
# G = <r,f| r^4,f^2,rfrf>

F.<r, f> = FreeGroup(2)
G = F / [r^4, f^2, r*f*r*f]
G
r,fr4,f2,(rf)2
# G, D4 ismoorphism

assert D4.is_isomorphic(G.as_permutation_group())

Lie groups

A Lie group is a continuous group whose group manifold is differentiable. The group GL(n,C) and its subgroups are called matrix Lie groups.

References

Keski-Vakkuri, Esko, Claus Montonen, and Marco Panero. 2022. Mathematical Methods for Physics. Cambridge, England: Cambridge University Press.
Stein, William, David Joyner, David Kohel, John Cremona, and Burçin Eröcal. 2024. “SageMath, Version 10.5.” http://www.sagemath.org.