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

= Introduction

#definition()
Informally, a _permutation_ on a collection of $n$ objects is an ordering of these $n$ objects.

For example, a few permutations of `A`, `B`, `C`, and `D` are `ABCD`, `BCDA`, and `DACB`.

#v(2mm)

This, however, isn't the definition we'll use today.
Instead of defining permutations as "ordered lists" \
(like we do above), we'll define them as _functions_ on finite sets. \
Our first goal today is to make sense of this definition.


#definition("Permutations")
Let $Omega$ be a set of $n$ arbitrary objects.

A _permutation_ $f$ on $Omega$ is a map#footnote[The words "function" and "map" are equivalent.]
from $Omega$ to itself that produces a _unique_ output for each input.

#note[This means that if $a$ and $b$ are different, $f(a)$ and $f(b)$ must also be different.]



#v(2mm)

For example, consider ${1, 2, 3}$. \
One permutation on this set can be defined as follows:
- $f(1) = 3$
- $f(2) = 1$
- $f(3) = 2$

If we take the array $123$ and apply $f$, we get $312$.

#problem()
List all permutations on three objects. \
How many permutations of $n$ objects are there?


#v(1fr)

#problem()
What map corresponds to the permutation that produces the array `312` from the array `123`?

#v(1fr)

#problem()
What map corresponds to the "do-nothing" permutation?

Write it as a function and in square-bracket notation.

#note([We will call this the _trivial permutation_])


#v(1fr)
#pagebreak()

We can visualize a permutation using a _string diagram_.
The arrows in this diagram denote \
the output of $f$ for each possible input.
Two examples are below:

#table(
  columns: (1fr, 1fr),
  align: center,
  stroke: none,
  align(center, cetz.canvas({
    import cetz.draw: *
    let s = 0.5 // scale

    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), $1$, name: "1b")
    content((1 * s, 0 * s), $3$, name: "3b")
    content((2 * s, 0 * s), $4$, name: "4b")
    content((3 * s, 0 * s), $2$, name: "2b")

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

  align(center, cetz.canvas({
    import cetz.draw: *
    let s = 0.5 // scale

    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")

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

Note that the elements of the set we are permuting are not ordered. (it is a _set_, after all!) \
For example, consider the diagrams below.
On the left, 1234 are ordered as usual. \
In the middle, they are ordered alphabetically. \
The rightmost diagram uses arbitrary, meaningless labels.

#v(2mm)

#table(
  columns: (1fr, 1fr, 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")

    line(
      "1a.south",
      (v => cetz.vector.add(v, (0, -del)), "1a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "1b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "1b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "1b.north",
      270deg,
      ..arrow,
    )

    line(
      "2a.south",
      (v => cetz.vector.add(v, (0, -del)), "2a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "2b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "2b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "2b.north",
      270deg,
      ..arrow,
    )

    line(
      "3a.south",
      (v => cetz.vector.add(v, (0, -del)), "3a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "3b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "3b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "3b.north",
      270deg,
      ..arrow,
    )

    line(
      "4a.south",
      (v => cetz.vector.add(v, (0, -del)), "4a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "4b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "4b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "4b.north",
      270deg,
      ..arrow,
    )
  })),
  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), $4$, name: "4a")
    content((1 * s, 3 * s), $1$, name: "1a")
    content((2 * s, 3 * s), $3$, name: "3a")
    content((3 * s, 3 * s), $2$, name: "2a")

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

    line(
      "1a.south",
      (v => cetz.vector.add(v, (0, -del)), "1a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "1b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "1b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "1b.north",
      270deg,
      ..arrow,
    )

    line(
      "2a.south",
      (v => cetz.vector.add(v, (0, -del)), "2a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "2b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "2b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "2b.north",
      270deg,
      ..arrow,
    )

    line(
      "3a.south",
      (v => cetz.vector.add(v, (0, -del)), "3a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "3b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "3b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "3b.north",
      270deg,
      ..arrow,
    )

    line(
      "4a.south",
      (v => cetz.vector.add(v, (0, -del)), "4a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "4b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "4b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "4b.north",
      270deg,
      ..arrow,
    )
  })),
  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), $ast.circle$, name: "4a")
    content((1 * s, 3 * s), $hexa.stroked$, name: "1a")
    content((2 * s, 3 * s), $triangle.stroked.b$, name: "3a")
    content((3 * s, 3 * s), $\#$, name: "2a")

    content((0 * s, 0 * s), $hexa.stroked$, name: "1b")
    content((1 * s, 0 * s), $ast.circle$, name: "4b")
    content((2 * s, 0 * s), $triangle.stroked.b$, name: "3b")
    content((3 * s, 0 * s), $\#$, name: "2b")

    line(
      "1a.south",
      (v => cetz.vector.add(v, (0, -del)), "1a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "1b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "1b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "1b.north",
      270deg,
      ..arrow,
    )

    line(
      "2a.south",
      (v => cetz.vector.add(v, (0, -del)), "2a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "2b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "2b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "2b.north",
      270deg,
      ..arrow,
    )

    line(
      "3a.south",
      (v => cetz.vector.add(v, (0, -del)), "3a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "3b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "3b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "3b.north",
      270deg,
      ..arrow,
    )

    line(
      "4a.south",
      (v => cetz.vector.add(v, (0, -del)), "4a.south"),
      (v => cetz.vector.add(v, (0, del + 0.2)), "4b.north"),
      (v => cetz.vector.add(v, (0, 0.2)), "4b.north"),
      stroke: oblue + s * 1mm,
    )
    mark(
      "4b.north",
      270deg,
      ..arrow,
    )
  })),
)

#v(2mm)

It shouldn't be hard to see that despite the different "output" each diagram displays \
($2134$, $1432$, and $hexa.stroked ast.circle triangle.stroked.b \#$), the same permutation ("swap first two") is shown in each.

Observe the following:
- The "names" of the items in our set do not have any meaning. \
  We are interested in sets of $n$ arbitrary things, which we may label however we like.
- Permutations are _verbs_. \
  We do not care about the "output" of a certain permutation. Rather, we care about what it _does_. \
  We could, for example, describe the permutation in the above three diagrams as "swap the first two elements."


#definition("Square Brackets")
However, elements with an implicit order (1, 2, 3, ...) are convenient. \
Such sets let us denote a permutation by writing the array it produces \
after transforming the "reference order" $123...n$.

We will call this _square-bracket notation_. \
$[312]$ denotes the permutation that produces $312$ when applied to $123$.

#problem()
Draw string diagrams for $[4123]$ and $[2341]$.

#v(1fr)
