#import "@local/handout:0.1.0": *
#import "@preview/cetz:0.4.2"
#import "../macros.typ": *

= Cycle Notation

#definition("Order")
The _order_ of a permutation $f$ is the smallest positive $n$ where $f^n (x) = x$ for all $x$. \
In other words, if we repeatedly apply a permutation with order $n$, \
we will get back to where we started after $n$ steps. \

#v(2mm)

For example, consider $[2134]$. This permutation has order $2$, as we can see below:

#table(
  columns: (1fr,),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *

    let s = 0.5 // scale
    let del = 0.2 // small line
    let arrow = (
      symbol: ")>",
      scale: s * 2.2,
      fill: oblue,
      stroke: oblue,
    )

    set-style(content: (frame: "rect", stroke: none, fill: white, padding: .1))
    content((0 * s, 3 * s), $1$, name: "1a")
    content((1 * s, 3 * s), $2$, name: "2a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $4$, name: "4a")

    content((0 * s, 0 * s), $2$, name: "2b")
    content((1 * s, 0 * s), $1$, name: "1b")
    content((2 * s, 0 * s), $3$, name: "3b")
    content((3 * s, 0 * s), $4$, name: "4b")

    content((0 * s, -3 * s), $1$, name: "1c")
    content((1 * s, -3 * s), $2$, name: "2c")
    content((2 * s, -3 * s), $3$, name: "3c")
    content((3 * s, -3 * s), $4$, name: "4c")

    markline(s, "1a", "1b")
    markline(s, "2a", "2b")
    markline(s, "3a", "3b")
    markline(s, "4a", "4b")

    markline(s, "1b", "1c")
    markline(s, "2b", "2c")
    markline(s, "3b", "3c")
    markline(s, "4b", "4c")
  })),
)

Swapping the first two elements of a list twice changes nothing. \
Thus, $[2134]$ has an order of two.


#problem()
What is the order of $[2314]$? \
How about $[4321]$? \
#note(type: "Note")[Try to solve this problem without drawing any strings!]

#v(1fr)

#problem()
Find a permutation on five elements with order 4.

#v(1fr)


#problem(label: "finiteorder")
Show that all permutations on a finite set have a well-defined order. \
In other words, show that there must always be an integer $n$ where $f^n (x) = x$.

#v(1fr)
#pagebreak()



#definition("Composition", label: "compdef")
The _composition_ of two permutations $f$ and $g$ is the permutation $h(x) = f(g(x))$. \
We'll denote this by simply writing the permutations we're composing next to each other, like $f g$. \
Note that $g$ is applied _before_ $f$ in $f g$.

#problem()
Show that function composition is associative. \
That is, show that $f(g h) = (f g)h$.

#v(1fr)

#problem()
What is $[1324][4321]$? \
How about $[321][213][231]$? \
Rewrite these compositions as one permutation in square brackets.

#solution([
  - $[1324][4321]$ is $[4321]$
  - $[321][213][231]$ is $[123]$
])


#v(1fr)


As you may have noticed, the square-bracket notation we've been using thus far is a bit unwieldy.
Permutations are verbs---but we've been referring to them using a noun (i.e, their output).

Square-bracket notation fails to capture the structure of the permutation it identifies.

#v(2mm)

Is the permutation $[1234]$ different than the permutation $[12345]$? \
These permutations operate on different sets---but they are both the identity! \
Are $[5342761]$ and $[1342567][5234761]$ similar? What are their orders?


#v(2mm)

Good notation should help us understand the objects we are studying. \
We need something better than square brackets.


#pagebreak()


#remark("Cycles")
Any permutation is composed of a number of _cycles_. \
Reread @finiteorder to convince yourself of this fact.


#example()
Consider the permutation $[2134]$. \
It consists of one two-cycle: $1 arrow.r 2 arrow.r 1$, which we can see in the diagram below. \
#note(
  type: "Note",
)[
  $3 arrow.r 3$ and $4 arrow.r 4$ are also cycles, but we'll ignore them.
  One-cycles aren't interesting.
]

#table(
  columns: (1fr,),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *

    let s = 0.6 // scale
    let del = 0.4 // small line
    let arrow = (
      symbol: ")>",
      scale: s * 2.2,
      fill: oblue,
      stroke: oblue,
    )

    set-style(content: (frame: "rect", stroke: none, fill: white, padding: .1))
    content((0 * s, 3 * s), $1$, name: "1a")
    content((1 * s, 3 * s), $2$, name: "2a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $4$, name: "4a")

    marklinetop(s, "1a", "2a")
    marklinebot(s, "2a", "1a")
  })),
)

#v(4mm)

The permutation $[431265]$ is a bit more interesting---it contains two cycles: \

#table(
  columns: (1fr,),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *

    let s = 0.6 // scale
    let arrow = (
      symbol: ")>",
      scale: s * 2.2,
      fill: oblue,
      stroke: oblue,
    )

    set-style(content: (frame: "rect", stroke: none, fill: white, padding: .1))
    content((0 * s, 3 * s), $1$, name: "1a")
    content((1 * s, 3 * s), $2$, name: "2a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $4$, name: "4a")
    content((4 * s, 3 * s), $5$, name: "5a")
    content((5 * s, 3 * s), $6$, name: "6a")


    marklinetop(s, "3a", "2a", del: 0.8)
    marklinebot(s, "2a", "4a", del: 1.3)
    marklinetop(s, "4a", "1a", del: 1.3)
    marklinebot(s, "1a", "3a", del: 0.8)
    marklinebot(s, "5a", "6a", del: 0.8, c: ogreen)
    marklinetop(s, "6a", "5a", del: 0.8, c: ogreen)
  })),
)

#remark()
Two-cycles may also be called _transpositions_. \
Any permutation that swaps two elements is a transposition.

#problem()
Find all cycles in $[5342761]$.

#solution[
  #table(
    columns: (1fr,),
    align: center,
    stroke: none,
    align(center, cetz.canvas({
      import cetz.draw: *

      let s = 0.5 // scale
      let arrow = (
        symbol: ")>",
        scale: s * 2.2,
        fill: oblue,
        stroke: oblue,
      )

      set-style(content: (
        frame: "rect",
        stroke: none,
        padding: .1,
      ))
      content((0 * s, 3 * s), $1$, name: "1a")
      content((1 * s, 3 * s), $2$, name: "2a")
      content((2 * s, 3 * s), $3$, name: "3a")
      content((3 * s, 3 * s), $4$, name: "4a")
      content((4 * s, 3 * s), $5$, name: "5a")
      content((5 * s, 3 * s), $6$, name: "6a")
      content((6 * s, 3 * s), $7$, name: "7a")


      marklinetop(s, "1a", "7a", del: 1.6)
      marklinebot(s, "7a", "5a", del: 1.2)
      marklinetopswap(s, "5a", "1a", del: 1.2)


      marklinebot(s, "2a", "4a", del: 1.2, c: ogreen)
      marklinetop(s, "4a", "3a", del: 0.8, c: ogreen)
      marklinebotswap(s, "3a", "2a", del: 0.8, c: ogreen)
    })),
  )

  There are two non-trivial cycles:
  - $4 arrow.r 3 arrow.r 2 arrow.r 4$
  - $1 arrow.r 7 arrow.r 5 arrow.r 1$
]



#v(1fr)


#problem()
What permutation on five objects is formed by the cycles $3 arrow.r 5 arrow.r 3$ and $1 arrow.r 2 arrow.r 4 arrow.r 1$? \
Write it in square-bracket notation.

#solution[
  #table(
    columns: (1fr,),
    align: center,
    stroke: none,
    align(center, cetz.canvas({
      import cetz.draw: *

      let s = 0.6 // scale
      let arrow = (
        symbol: ")>",
        scale: s * 2.2,
        fill: oblue,
        stroke: oblue,
      )

      set-style(content: (
        frame: "rect",
        stroke: none,
        padding: .1,
      ))
      content((0 * s, 3 * s), $1$, name: "1a")
      content((1 * s, 3 * s), $2$, name: "2a")
      content((2 * s, 3 * s), $3$, name: "3a")
      content((3 * s, 3 * s), $4$, name: "4a")
      content((4 * s, 3 * s), $5$, name: "5a")

      marklinetop(s, "3a", "5a", del: 0.8, c: ogreen)
      marklinebot(s, "5a", "3a", del: 0.8, c: ogreen)

      marklinebot(s, "1a", "2a", del: 0.8)
      marklinetop(s, "2a", "4a", del: 1.2)

      marklinebotswap(s, "4a", "1a", del: 1.2)
    })),
  )


  This is $[41523]$.
]


#v(1fr)
#pagebreak()


#definition("Cycle Notation")
We can use cycles to develop better notation: \
Instead of identifying permutations using their output, we'll identify them using their _cycles_.

#v(2mm)

For example, we'll write $[2134]$ is $(12)$ in cycle notation, \
since it consists only of the cycle $1 arrow.r 2 arrow.r 1$:

#table(
  columns: (1fr,),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *

    let s = 0.6 // scale
    let arrow = (
      symbol: ")>",
      scale: s * 2.2,
      fill: oblue,
      stroke: oblue,
    )

    set-style(content: (
      frame: "rect",
      stroke: none,
      padding: .1,
    ))
    content((0 * s, 3 * s), $1$, name: "1a")
    content((1 * s, 3 * s), $2$, name: "2a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $4$, name: "4a")

    marklinebot(s, "1a", "2a", del: 0.8)
    marklinetop(s, "2a", "1a", del: 0.8)
  })),
)

#v(2mm)


Permutations that consist of more than one cycle are written as a composition. \
$[2143]$ is written as $(12)(34)$. Applying the permutation $[2143]$ has the same effect as applying $(34)$, then applying $(12)$.

#table(
  columns: (1fr,),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *

    let s = 0.6 // scale
    let arrow = (
      symbol: ")>",
      scale: s * 2.2,
      fill: oblue,
      stroke: oblue,
    )

    set-style(content: (
      frame: "rect",
      stroke: none,
      padding: .1,
    ))
    content((0 * s, 3 * s), $1$, name: "1a")
    content((1 * s, 3 * s), $2$, name: "2a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $4$, name: "4a")

    marklinetop(s, "1a", "2a", del: 0.8)
    marklinebot(s, "2a", "1a", del: 0.8)
    marklinetop(s, "3a", "4a", del: 0.8, c: ogreen)
    marklinebot(s, "4a", "3a", del: 0.8, c: ogreen)
  })),
)



#remark()
According to @finiteorder, any permutation may be written as a composition of disjoint cycles. \
Convince yourself of this fact.

#problem()
Rewrite $[431265]$ in cycle notation.

#solution[
  $[431265]$ is $(1324)(56)$:

  #table(
    columns: (1fr,),
    align: center,
    stroke: none,
    align(center, cetz.canvas({
      import cetz.draw: *

      let s = 0.6 // scale
      let arrow = (
        symbol: ")>",
        scale: s * 2.2,
        fill: oblue,
        stroke: oblue,
      )

      set-style(content: (
        frame: "rect",
        stroke: none,
        padding: .1,
      ))
      content((0 * s, 3 * s), $1$, name: "1a")
      content((1 * s, 3 * s), $2$, name: "2a")
      content((2 * s, 3 * s), $3$, name: "3a")
      content((3 * s, 3 * s), $4$, name: "4a")
      content((4 * s, 3 * s), $5$, name: "5a")
      content((5 * s, 3 * s), $6$, name: "6a")

      marklinetop(s, "1a", "3a", del: 0.8, c: ogreen)
      marklinebot(s, "4a", "1a", del: 1.3, c: ogreen)
      marklinebot(s, "3a", "2a", del: 0.8, c: ogreen)
      marklinetop(s, "2a", "4a", del: 1.3, c: ogreen)

      marklinetop(s, "5a", "6a", del: 0.8)
      marklinebot(s, "6a", "5a", del: 0.8)
    })),
  )
]




#remark()
The identity permutation $f(x) = x$ is written as $()$ in cycle notation.



#problem()
Convince yourself that disjoint cycles commute. \
That is, that $(1324)(56) = (56)(1324) = [431265]$ since $(1324)$ and $(56)$ do not overlap. \


#v(1fr)
#pagebreak()

#problem(label: "insquare")
Write the following in square-bracket notation.

- $(12)$      on a set of 2 elements
- $(12)(435)$   on a set of 5 elements
#v(2mm)
- $(321)$       on a set of 3 elements
- $(321)$       on a set of 6 elements
#v(2mm)
- $(1234)$       on a set of 4 elements
- $(3412)$       on a set of 4 elements

#note[
  Note that $(12)$ refers the "swap first two" permutation on a set of _any_ size. \
  We can use consistent notation for the same action on two different sets! \
]

#v(1fr)



#problem()
Write the following in square-bracket notation.
Pay attention!
- $(13)(243)$  on a set of 4 elements
- $(243)(13)$  on a set of 4 elements

#v(1fr)



#problem()
Consider the last two permutations in @insquare, $(1234)$ and $(3412)$. \
These are _identical_---they are the same cycle written in two different ways. \
List all other ways to write this cycle. \
#hint[There are two more.]

#v(1fr)
#pagebreak()


#definition("Inverse")
The _inverse_ of a permitation $f$ is a permutation $g$ that "un-does" $f$. \
This means that $g(f(x)) = x$ for all $x$.

#problem()
What is the inverse of $(12)$? \
How about $(123)$? And $(4231)$? \
#note[
  Note we do not need to know the size of the set we are operating on. \
  The inverse of $(12)$ is the same in sets of all sizes!
]

#v(1fr)


#problem()
Let $sigma$ be a permutation composed of disjoint cycles $sigma_1sigma_2...sigma_k$. \
Say we know the order of all $sigma_i$. What is the order of $sigma$?

#solution[
  $
    #text[lcm]\(#text[ord]\(sigma_1),#h(0.5em) #text[ord]\(sigma_2),#h(0.5em) ...,#h(0.5em) #text[ord]\(sigma_k))
  $
]


#v(1fr)

#problem(label: "cycletrans")
Show that any cycle $(123...n)$ is equal to the product $(12)(23)...(n-1, n)$.

#solution[
  *Intuition:*\
  $(123...n)$ is a right-shift. Swapping all pairs from right to left achieves the same effect.

  #v(2mm)

  *Complete solution:* \
  Consider $n-1$. After applying $(123...n)$, it takes the position of $n$.

  After applying $(n-1, n)$, $n-1$ moves to the same position _and is never moved again!_ \
  Repeat this argument for all other $n$.
]

#v(1fr)

#problem()
Write $(7126453)$ as a product of transpositions. \

#solution[
  Move elements one at a time, and using the last position as temporary storage.

  We get $(71)(72)(76)(74)(75)(73)$.
  Other solutions are possible. \

  #v(2mm)

  *Bonus:* How can we do this in the fewest number of transpositions?
]

#v(1fr)
#pagebreak()

#problem(label: "simpletrans")
Show that any permutation is a product of transpositions.

#solution[
  Re-use the argument in @cycletrans. \
  Pick an arbitrary "working slot," and re-build all cycles. \
  Use the "not touched again" argument for a proper proof.
]

#v(1fr)


#problem(label: "onetrans")
Show that any permutation is a product of transpositions of the form $(1, k)$. \

#solution[
  Use @simpletrans to rewrite each $(a, b)$ as $(1, a)(1, b)(1, a)$. \
  Showing that $(a, b) = (1, a)(1, b)(1, a)$ is fairly easy.
]

#v(1fr)
#pagebreak()



#problem(label: "oneplustrans")
Show that any transposition $(a, b)$ is equal to the product $(a, a+1)(a+1, b)(a, a+1)$.

#solution[
  This is the same as @onetrans,
  but we use $a + 1$ as a "working slot" instead of $1$.
]

#v(1fr)



#problem()
Show that any permutation is a product of adjacent transpositions. \
An _adjacent transposition_ swaps two adjacent elements, and thus looks like $(n, n+1)$.

#solution[
  As before, we will use @simpletrans and rewrite the transpositions it produces in a convenient fashion.
  To do this, we must show that every transposition $(a, b)$ is a product of adjacent transpositions.

  #v(2mm)

  In the proof below, assume that $a < b$ and perform induction on $b - a$. \

  #v(4mm)


  *Base Case:*\
  If $b - a = 1$, $(a, b)$ is a product of adjacent transpositions. \
  In fact, it _is_ an adjacent transposition.

  #v(4mm)

  *Induction:*\
  Now, say $b - a = n + 1$. \
  Assume that all $(a, b)$ where $b - a <= n$ are products of adjacent transpositions.\
  By @oneplustrans, $(a, b) = (a, a+1)(a+1, b)(a, a+1)$.

  #v(2mm)

  $(a, a+1)$ is an adjacent transposition, and $b - (a+1) = n$. \
  Thus, $(a, b)$ is a product of adjacent transpositions.
]

#v(1fr)
