The purpose of this script is to show that the bijection f (represented by the matrix bijection below) I constructed, from the dihedral group D_6 to the symmetric group S_3 on 3 letters, is an isomorphism.
I tried to explain the logic behind my script as far as I could with many code comments, so hopefully it is understandable. Apologies if its not clear in some way; feel free to ask me for clarifications.
My problem is that I’m not very sure how to test for the (in)equality of two symbolic expressions. Some things are also perhaps not simplified sufficiently for certain functions (findfirst) to work. More specifically, the two problems I faced is written in detail below, near the bottom of the code block.
# clears the terminal
print("\033c")
using Symbolics
# displayall macro command (for debugging)
# source: https://stackoverflow.com/a/74589689
macro displayall(code)
for i in eachindex(code.args)
typeof(code.args[i]) == LineNumberNode && continue
code.args[i] = quote
display($(esc(code.args[i])));
end
end
return code
end
@displayall begin
function compose_permutations(x::Vector{Int}, y::Vector{Int})
# Check that the vectors x, y each representing a permutation on the set {1, 2, 3} have
# 1. exactly one copy of 1, 2, 3.
# 2. exactly three elements.
for vec in [x, y]
for i = 1:3
copies_of_i = length(findall(==(i), vec))
if copies_of_i != 1
error("The vectors input to compose_permutations have $copies_of_i copies of $i; there should be exactly 1 copy of $i.")
end
end
if length(vec) != 3
error("The vectors input to compose_permutations are not of size 3.")
end
end
# Return the composition of the permutations x, y in vector form.
return [x[y[1]], x[y[2]], x[y[3]]]
end
function reflection_matrix(angle_rad::Real)
P = [-sin(angle_rad) cos(angle_rad)
; cos(angle_rad) sin(angle_rad)]
D = [-1 0
; 0 1]
return P * D * P'
end
function rotation_matrix(angle_rad::Real)
return [cos(angle_rad) -sin(angle_rad)
;sin(angle_rad) cos(angle_rad)]
end
s_1 = reflection_matrix(Num(pi)/2)
s_2 = reflection_matrix(2*Num(pi)/6)
s_3 = reflection_matrix(-Num(pi)/6)
id = [1 0
;0 1]
t_1 = rotation_matrix(2*Num(pi)/3)
t_2 = rotation_matrix(-2*Num(pi)/3)
# The bijection f from D_6 to S_3, which we want to verify is an isomorphism, represented in matrix form:
# The image of the (1, i)th entry under the bijection is the (2, i)th entry.
bijection = [[s_1] [s_2] [s_3] [id] [t_1] [t_2]
;[[1, 3, 2]] [[2, 1, 3]] [[3, 2, 1]] [[1, 2, 3]] [[2, 3, 1]] [[3, 1, 2]]]
# We want to test that f( x*y ) = f( x ) f( y ). We test for all possible combinations of x and y below.
num = size(bijection, 2)
for i = 1 : num, j = 1 : num
# Find the index index_product = [a, b] such that bijection[a, b] = x*y
# x = bijection[1, i]
# y = bijection[1, j]
index_product = findfirst( ==(bijection[1, i] * bijection[1, j]), bijection )
# ^^^ Problem 1: s_1^2 is not simplified to [1 0; 0 1]. So findfirst cannot find anything
# julia> simplify.(s_1^2)
# 2×2 Matrix{Num}:
# 1.0 + 4(cos(1.5708)^2)*(sin(1.5708)^2) 0.0
# 0.0 1.0 + 4(cos(1.5708)^2)*(sin(1.5708)^2)
# Unless f( x*y ) = f( x ) f( y ), issue an error.
# x*y = bijection[1, i] * bijection[1, j]
# f( x ) f( y ) = compose_permutations( bijection[2, i], bijection[2, j] )
# f( x*y ) = bijection[ 2, index_product[2] ]
# x*y = bijection[ index_product ] = bijection[ 1, index_product[2] ] is mapped to f( x*y ) = bijection[ 2, index_product[2] ] under f.
if bijection(2, index_product[2]) != compose_permutations( bijection[2, i], bijection[2, j] )
error("The bijection does not preserve multiplication for i = $i and j = $j.")
end
# ^^^ Problem 2: != does not work for symbolic.jl
# julia> if cos(Num(pi)) != -1
# error("cos(pi) is not equal to -1, which is false; they should be equal.")
# end
# ERROR: TypeError: non-boolean (Num) used in boolean context
# A symbolic expression appeared in a Boolean context. This error arises in situations where Julia expects a Bool, like
# if boolean_condition use ifelse(boolean_condition, then branch, else branch)
# x && y use x & y
# boolean_condition ? a : b use ifelse(boolean_condition, a, b)
# but a symbolic expression appeared instead of a Bool. For help regarding control flow with symbolic variables, see https://docs.sciml.ai/ModelingToolkit/dev/basics/FAQ/#How-do-I-handle-if-statements-in-my-symbolic-forms?
# Stacktrace:
# [1] top-level scope
# @ REPL[9]:1
end