doc-next-gen

Mathlib.Data.Sym.Basic

Module docstring

{"# Symmetric powers

This file defines symmetric powers of a type. The nth symmetric power consists of homogeneous n-tuples modulo permutations by the symmetric group.

The special case of 2-tuples is called the symmetric square, which is addressed in more detail in Data.Sym.Sym2.

TODO: This was created as supporting material for Sym2; it needs a fleshed-out interface.

Tags

symmetric powers

","### Combinatorial equivalences "}

Sym definition
(α : Type*) (n : ℕ)
Full source
/-- The nth symmetric power is n-tuples up to permutation.  We define it
as a subtype of `Multiset` since these are well developed in the
library.  We also give a definition `Sym.sym'` in terms of vectors, and we
show these are equivalent in `Sym.symEquivSym'`.
-/
def Sym (α : Type*) (n : ) :=
  { s : Multiset α // Multiset.card s = n }
Symmetric power of a type
Informal description
The $n$-th symmetric power of a type $\alpha$ is the set of equivalence classes of $n$-tuples of elements of $\alpha$ modulo permutations by the symmetric group. It is defined as the subtype of multisets of $\alpha$ with exactly $n$ elements.
Sym.toMultiset definition
{α : Type*} {n : ℕ} (s : Sym α n) : Multiset α
Full source
/-- The canonical map to `Multiset α` that forgets that `s` has length `n` -/
@[coe] def Sym.toMultiset {α : Type*} {n : } (s : Sym α n) : Multiset α :=
  s.1
Forgetful map from symmetric power to multiset
Informal description
The function maps an element $s$ of the $n$-th symmetric power of a type $\alpha$ to its underlying multiset in $\text{Multiset} \alpha$, forgetting the length constraint $n$.
Sym.hasCoe instance
(α : Type*) (n : ℕ) : CoeOut (Sym α n) (Multiset α)
Full source
instance Sym.hasCoe (α : Type*) (n : ) : CoeOut (Sym α n) (Multiset α) :=
  ⟨Sym.toMultiset⟩
Symmetric Power as Multiset
Informal description
For any type $\alpha$ and natural number $n$, there is a canonical way to view an element of the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ as a multiset over $\alpha$.
instDecidableEqSym instance
{α : Type*} {n : ℕ} [DecidableEq α] : DecidableEq (Sym α n)
Full source
instance {α : Type*} {n : } [DecidableEq α] : DecidableEq (Sym α n) :=
  inferInstanceAs <| DecidableEq <| Subtype _
Decidable Equality for Symmetric Powers
Informal description
For any type $\alpha$ with decidable equality and any natural number $n$, the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ has decidable equality.
List.Vector.Perm.isSetoid abbrev
(α : Type*) (n : ℕ) : Setoid (Vector α n)
Full source
/-- This is the `List.Perm` setoid lifted to `Vector`.

See note [reducible non-instances].
-/
abbrev List.Vector.Perm.isSetoid (α : Type*) (n : ) : Setoid (Vector α n) :=
  (List.isSetoid α).comap Subtype.val
Setoid Structure Induced by Vector Permutations
Informal description
For any type $\alpha$ and natural number $n$, the equivalence relation `List.Vector.Perm` (permutation of vectors) induces a setoid structure on the type `Vector α n$ of length-$n$ vectors over $\alpha$.
instDecidableRelVectorEquivOfDecidableEq instance
{α : Type*} {n : ℕ} [DecidableEq α] : DecidableRel (· ≈ · : List.Vector α n → List.Vector α n → Prop)
Full source
instance {α : Type*} {n : } [DecidableEq α] :
    DecidableRel (· ≈ · : List.Vector α n → List.Vector α n → Prop) :=
  fun _ _ => List.decidablePerm _ _
Decidability of Vector Permutation Equivalence
Informal description
For any type $\alpha$ with decidable equality and any natural number $n$, the equivalence relation $\approx$ on length-$n$ vectors over $\alpha$ (given by permutation of vector elements) is decidable.
Sym.coe_injective theorem
: Injective ((↑) : Sym α n → Multiset α)
Full source
theorem coe_injective : Injective ((↑) : Sym α n → Multiset α) :=
  Subtype.coe_injective
Injectivity of the Symmetric Power to Multiset Canonical Map
Informal description
The canonical map from the $n$-th symmetric power $\text{Sym}(\alpha, n)$ to the multiset $\text{Multiset}(\alpha)$ is injective. In other words, if two elements of $\text{Sym}(\alpha, n)$ have the same underlying multiset, then they are equal.
Sym.coe_inj theorem
{s₁ s₂ : Sym α n} : (s₁ : Multiset α) = s₂ ↔ s₁ = s₂
Full source
@[simp, norm_cast]
theorem coe_inj {s₁ s₂ : Sym α n} : (s₁ : Multiset α) = s₂ ↔ s₁ = s₂ :=
  coe_injective.eq_iff
Equality Criterion for Symmetric Power Elements via Multiset Equality
Informal description
For any two elements $s_1, s_2$ in the $n$-th symmetric power of a type $\alpha$, the underlying multisets of $s_1$ and $s_2$ are equal if and only if $s_1 = s_2$.
Sym.ext theorem
{s₁ s₂ : Sym α n} (h : (s₁ : Multiset α) = ↑s₂) : s₁ = s₂
Full source
@[ext] theorem ext {s₁ s₂ : Sym α n} (h : (s₁ : Multiset α) = ↑s₂) : s₁ = s₂ :=
  coe_injective h
Extensionality for Symmetric Power Elements via Multiset Equality
Informal description
For any two elements $s_1, s_2$ in the $n$-th symmetric power of a type $\alpha$, if their underlying multisets (obtained via the canonical map to $\text{Multiset} \alpha$) are equal, then $s_1 = s_2$.
Sym.val_eq_coe theorem
(s : Sym α n) : s.1 = ↑s
Full source
@[simp]
theorem val_eq_coe (s : Sym α n) : s.1 = ↑s :=
  rfl
Equality of Projection and Coercion for Symmetric Power Elements
Informal description
For any element $s$ of the $n$-th symmetric power of a type $\alpha$, the underlying multiset of $s$ (accessed via the projection `.1`) is equal to the image of $s$ under the forgetful map to $\text{Multiset} \alpha$.
Sym.mk abbrev
(m : Multiset α) (h : Multiset.card m = n) : Sym α n
Full source
/-- Construct an element of the `n`th symmetric power from a multiset of cardinality `n`.
-/
@[match_pattern]
abbrev mk (m : Multiset α) (h : Multiset.card m = n) : Sym α n :=
  ⟨m, h⟩
Construction of Symmetric Power Element from Multiset
Informal description
Given a multiset $m$ of elements of type $\alpha$ with cardinality $n$, the function constructs an element of the $n$-th symmetric power of $\alpha$.
Sym.nil definition
: Sym α 0
Full source
/-- The unique element in `Sym α 0`. -/
@[match_pattern]
def nil : Sym α 0 :=
  ⟨0, Multiset.card_zero⟩
Empty symmetric power element
Informal description
The unique element in the zeroth symmetric power of a type $\alpha$, represented as the empty multiset with cardinality $0$.
Sym.coe_nil theorem
: ↑(@Sym.nil α) = (0 : Multiset α)
Full source
@[simp]
theorem coe_nil : ↑(@Sym.nil α) = (0 : Multiset α) :=
  rfl
Empty Symmetric Power Maps to Zero Multiset
Informal description
The image of the empty symmetric power element `Sym.nil` under the forgetful map `Sym.toMultiset` is the zero multiset, i.e., $\text{toMultiset}(\text{nil}) = 0$.
Sym.cons definition
(a : α) (s : Sym α n) : Sym α n.succ
Full source
/-- Inserts an element into the term of `Sym α n`, increasing the length by one.
-/
@[match_pattern]
def cons (a : α) (s : Sym α n) : Sym α n.succ :=
  ⟨a ::ₘ s.1, by rw [Multiset.card_cons, s.2]⟩
Insertion into symmetric power
Informal description
Given an element \( a \) of type \( \alpha \) and an element \( s \) of the \( n \)-th symmetric power \( \text{Sym} \alpha n \), the operation \( \text{cons}(a, s) \) returns an element of the \( (n+1) \)-th symmetric power \( \text{Sym} \alpha (n+1) \) obtained by inserting \( a \) into the multiset underlying \( s \).
Sym.term_::ₛ_ definition
: Lean.TrailingParserDescr✝
Full source
@[inherit_doc]
infixr:67 " ::ₛ " => cons
Cons notation for symmetric powers
Informal description
The infix notation `::ₛ` is used to denote the `cons` operation on symmetric powers, which prepends an element `a` of type `α` to a symmetric power `s` of type `Sym α n`, resulting in a symmetric power of type `Sym α (n + 1)`.
Sym.cons_inj_right theorem
(a : α) (s s' : Sym α n) : a ::ₛ s = a ::ₛ s' ↔ s = s'
Full source
@[simp]
theorem cons_inj_right (a : α) (s s' : Sym α n) : a ::ₛ sa ::ₛ s = a ::ₛ s' ↔ s = s' :=
  Subtype.ext_iff.trans <| (Multiset.cons_inj_right _).trans Subtype.ext_iff.symm
Right Injectivity of Symmetric Power Insertion: $a \mathbin{::ₛ} s = a \mathbin{::ₛ} s' \leftrightarrow s = s'$
Informal description
For any element $a$ of type $\alpha$ and any elements $s, s'$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the equality $a \mathbin{::ₛ} s = a \mathbin{::ₛ} s'$ holds if and only if $s = s'$.
Sym.cons_inj_left theorem
(a a' : α) (s : Sym α n) : a ::ₛ s = a' ::ₛ s ↔ a = a'
Full source
@[simp]
theorem cons_inj_left (a a' : α) (s : Sym α n) : a ::ₛ sa ::ₛ s = a' ::ₛ s ↔ a = a' :=
  Subtype.ext_iff.trans <| Multiset.cons_inj_left _
Left Injectivity of Symmetric Power Insertion: $a \mathbin{::ₛ} s = a' \mathbin{::ₛ} s \leftrightarrow a = a'$
Informal description
For any elements $a$ and $a'$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the equality $a \mathbin{::ₛ} s = a' \mathbin{::ₛ} s$ holds if and only if $a = a'$.
Sym.cons_swap theorem
(a b : α) (s : Sym α n) : a ::ₛ b ::ₛ s = b ::ₛ a ::ₛ s
Full source
theorem cons_swap (a b : α) (s : Sym α n) : a ::ₛ b ::ₛ s = b ::ₛ a ::ₛ s :=
  Subtype.ext <| Multiset.cons_swap a b s.1
Commutativity of Insertion in Symmetric Power: $a \mathbin{::ₛ} b \mathbin{::ₛ} s = b \mathbin{::ₛ} a \mathbin{::ₛ} s$
Informal description
For any elements $a$ and $b$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the equality $a \mathbin{::ₛ} (b \mathbin{::ₛ} s) = b \mathbin{::ₛ} (a \mathbin{::ₛ} s)$ holds. In other words, the order of inserting two distinct elements into a symmetric power does not affect the resulting element.
Sym.coe_cons theorem
(s : Sym α n) (a : α) : (a ::ₛ s : Multiset α) = a ::ₘ s
Full source
theorem coe_cons (s : Sym α n) (a : α) : (a ::ₛ s : Multiset α) = a ::ₘ s :=
  rfl
Multiset Representation of Insertion in Symmetric Power: $(a \mathbin{::ₛ} s) = a \mathbin{::ₘ} s$
Informal description
For any element $a$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the underlying multiset of $a \mathbin{::ₛ} s$ is equal to $a$ inserted into the underlying multiset of $s$, i.e., $(a \mathbin{::ₛ} s : \text{Multiset} \alpha) = a \mathbin{::ₘ} s$.
Sym.ofVector definition
: List.Vector α n → Sym α n
Full source
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
def ofVector : List.Vector α n → Sym α n :=
  fun x => ⟨↑x.val, (Multiset.coe_card _).trans x.2⟩
Symmetric power construction from vector
Informal description
The function maps a vector (list with fixed length $n$) of elements of type $\alpha$ to its equivalence class in the $n$-th symmetric power of $\alpha$, where elements are considered up to permutation. More precisely, given a vector $v$ of length $n$, the function returns the multiset formed by the elements of $v$, which is an element of the symmetric power $\text{Sym}^n \alpha$.
Sym.instCoeVector instance
: Coe (List.Vector α n) (Sym α n)
Full source
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
instance : Coe (List.Vector α n) (Sym α n) where coe x := ofVector x
Canonical Map from Vectors to Symmetric Powers
Informal description
For any type $\alpha$ and natural number $n$, there is a canonical map from the type of vectors (lists of fixed length $n$) over $\alpha$ to the $n$-th symmetric power of $\alpha$, which sends a vector to its equivalence class under permutations.
Sym.ofVector_nil theorem
: ↑(Vector.nil : List.Vector α 0) = (Sym.nil : Sym α 0)
Full source
@[simp]
theorem ofVector_nil : ↑(Vector.nil : List.Vector α 0) = (Sym.nil : Sym α 0) :=
  rfl
Empty Vector Maps to Nil in Zeroth Symmetric Power
Informal description
The equivalence class of the empty vector in the zeroth symmetric power of a type $\alpha$ is equal to the unique element $\text{Sym.nil}$ of $\text{Sym}(\alpha, 0)$. In symbols, $\text{ofVector}(\text{Vector.nil}) = \text{Sym.nil}$.
Sym.ofVector_cons theorem
(a : α) (v : List.Vector α n) : ↑(Vector.cons a v) = a ::ₛ (↑v : Sym α n)
Full source
@[simp]
theorem ofVector_cons (a : α) (v : List.Vector α n) :
    ↑(Vector.cons a v) = a ::ₛ (↑v : Sym α n) := by
  cases v
  rfl
Compatibility of Vector Construction with Symmetric Power Insertion
Informal description
For any element $a$ of type $\alpha$ and any vector $v$ of length $n$ over $\alpha$, the equivalence class of the vector obtained by prepending $a$ to $v$ is equal to the symmetric power element obtained by inserting $a$ into the equivalence class of $v$. In symbols, $\text{ofVector}(\text{cons}(a, v)) = a ::ₛ \text{ofVector}(v)$.
Sym.card_coe theorem
: Multiset.card (s : Multiset α) = n
Full source
@[simp]
theorem card_coe : Multiset.card (s : Multiset α) = n := s.prop
Cardinality of Symmetric Power Elements: $|\text{toMultiset}(s)| = n$
Informal description
For any element $s$ in the $n$-th symmetric power of a type $\alpha$, the cardinality of the underlying multiset (obtained via the forgetful map $\text{Sym.toMultiset}$) is equal to $n$. In other words, if $s \in \text{Sym}(\alpha, n)$, then $|\text{toMultiset}(s)| = n$.
Sym.instMembership instance
: Membership α (Sym α n)
Full source
/-- `α ∈ s` means that `a` appears as one of the factors in `s`.
-/
instance : Membership α (Sym α n) :=
  ⟨fun s a => a ∈ s.1⟩
Membership in Symmetric Powers
Informal description
For any type $\alpha$ and natural number $n$, we say an element $a \in \alpha$ is a member of the $n$-th symmetric power $s$ (denoted $a \in s$) if $a$ appears as one of the elements in the multiset representing $s$.
Sym.decidableMem instance
[DecidableEq α] (a : α) (s : Sym α n) : Decidable (a ∈ s)
Full source
instance decidableMem [DecidableEq α] (a : α) (s : Sym α n) : Decidable (a ∈ s) :=
  s.1.decidableMem _
Decidability of Membership in Symmetric Powers
Informal description
For any type $\alpha$ with decidable equality, given an element $a \in \alpha$ and an $n$-th symmetric power $s$ of $\alpha$, it is decidable whether $a$ is a member of $s$.
Sym.coe_mk theorem
(s : Multiset α) (h : Multiset.card s = n) : mk s h = s
Full source
@[simp, norm_cast] lemma coe_mk (s : Multiset α) (h : Multiset.card s = n) : mk s h = s := rfl
Equality of Symmetric Power Construction with Underlying Multiset
Informal description
For any multiset $s$ of elements of type $\alpha$ with cardinality $n$, the element of the $n$-th symmetric power constructed from $s$ is equal to $s$ when viewed as a multiset.
Sym.mem_mk theorem
(a : α) (s : Multiset α) (h : Multiset.card s = n) : a ∈ mk s h ↔ a ∈ s
Full source
@[simp]
theorem mem_mk (a : α) (s : Multiset α) (h : Multiset.card s = n) : a ∈ mk s ha ∈ mk s h ↔ a ∈ s :=
  Iff.rfl
Membership in Constructed Symmetric Power Element
Informal description
For any element $a$ of type $\alpha$, any multiset $s$ of elements of $\alpha$ with cardinality $n$, and any proof $h$ that $\text{card}(s) = n$, we have that $a$ is a member of the symmetric power element $\text{mk}(s, h)$ if and only if $a$ is a member of the multiset $s$.
Sym.forall theorem
{p : Sym α n → Prop} : (∀ s : Sym α n, p s) ↔ ∀ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs)
Full source
lemma «forall» {p : Sym α n → Prop} :
    (∀ s : Sym α n, p s) ↔ ∀ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
  simp [Sym]
Universal Quantification Characterization for Symmetric Power Elements
Informal description
For any predicate $p$ on the $n$-th symmetric power of a type $\alpha$, the universal quantification over all elements of $\text{Sym}(\alpha, n)$ is equivalent to the universal quantification over all multisets $s$ of $\alpha$ with cardinality $n$, applied to the symmetric power element constructed from $s$. In other words, a property holds for all elements of $\text{Sym}(\alpha, n)$ if and only if it holds for all elements constructed from multisets of $\alpha$ with exactly $n$ elements.
Sym.exists theorem
{p : Sym α n → Prop} : (∃ s : Sym α n, p s) ↔ ∃ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs)
Full source
lemma «exists» {p : Sym α n → Prop} :
    (∃ s : Sym α n, p s) ↔ ∃ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
  simp [Sym]
Existence in Symmetric Power via Multisets
Informal description
For any predicate $p$ on the $n$-th symmetric power $\text{Sym}(\alpha, n)$, there exists an element $s$ in $\text{Sym}(\alpha, n)$ satisfying $p(s)$ if and only if there exists a multiset $s$ of elements of $\alpha$ with cardinality $n$ such that $p$ holds for the symmetric power element constructed from $s$.
Sym.not_mem_nil theorem
(a : α) : ¬a ∈ (nil : Sym α 0)
Full source
@[simp]
theorem not_mem_nil (a : α) : ¬ a ∈ (nil : Sym α 0) :=
  Multiset.not_mem_zero a
No Element in Empty Symmetric Power: $a \notin \text{Sym}(\alpha, 0)$
Informal description
For any element $a$ of type $\alpha$, $a$ is not a member of the empty symmetric power $\text{Sym}(\alpha, 0)$.
Sym.mem_cons theorem
: a ∈ b ::ₛ s ↔ a = b ∨ a ∈ s
Full source
@[simp]
theorem mem_cons : a ∈ b ::ₛ sa ∈ b ::ₛ s ↔ a = b ∨ a ∈ s :=
  Multiset.mem_cons
Membership in Symmetric Power After Insertion: $a \in b ::ₛ s \leftrightarrow a = b \lor a \in s$
Informal description
For any elements $a, b$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power of $\alpha$, the element $a$ belongs to the symmetric power obtained by inserting $b$ into $s$ (denoted $b ::ₛ s$) if and only if either $a = b$ or $a$ belongs to $s$.
Sym.mem_coe theorem
: a ∈ (s : Multiset α) ↔ a ∈ s
Full source
@[simp]
theorem mem_coe : a ∈ (s : Multiset α)a ∈ (s : Multiset α) ↔ a ∈ s :=
  Iff.rfl
Membership in Symmetric Power is Equivalent to Membership in Underlying Multiset
Informal description
For any element $a$ of type $\alpha$ and any $n$-th symmetric power $s$ of $\alpha$, the element $a$ belongs to the underlying multiset of $s$ if and only if $a$ belongs to $s$ as a symmetric power element.
Sym.mem_cons_of_mem theorem
(h : a ∈ s) : a ∈ b ::ₛ s
Full source
theorem mem_cons_of_mem (h : a ∈ s) : a ∈ b ::ₛ s :=
  Multiset.mem_cons_of_mem h
Membership Preservation in Symmetric Power Insertion: $a \in s \Rightarrow a \in b ::ₛ s$
Informal description
For any elements $a, b$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power of $\alpha$, if $a$ belongs to $s$, then $a$ also belongs to the symmetric power obtained by inserting $b$ into $s$ (denoted $b ::ₛ s$).
Sym.mem_cons_self theorem
(a : α) (s : Sym α n) : a ∈ a ::ₛ s
Full source
theorem mem_cons_self (a : α) (s : Sym α n) : a ∈ a ::ₛ s :=
  Multiset.mem_cons_self a s.1
Self-Membership in Symmetric Power Insertion: $a \in a ::ₛ s$
Informal description
For any element $a$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the element $a$ belongs to the symmetric power obtained by inserting $a$ into $s$, i.e., $a \in a ::ₛ s$.
Sym.cons_of_coe_eq theorem
(a : α) (v : List.Vector α n) : a ::ₛ (↑v : Sym α n) = ↑(a ::ᵥ v)
Full source
theorem cons_of_coe_eq (a : α) (v : List.Vector α n) : a ::ₛ (↑v : Sym α n) = ↑(a ::ᵥ v) :=
  Subtype.ext <| by
    cases v
    rfl
Compatibility of Insertion with Symmetric Power Construction from Vector
Informal description
For any element $a$ of type $\alpha$ and any vector $v$ of length $n$ over $\alpha$, the insertion of $a$ into the symmetric power corresponding to $v$ is equal to the symmetric power corresponding to the vector obtained by prepending $a$ to $v$. In symbols, $a ::ₛ (\text{Sym.ofVector}(v)) = \text{Sym.ofVector}(a ::ᵥ v)$.
Sym.sound theorem
{a b : List.Vector α n} (h : a.val ~ b.val) : (↑a : Sym α n) = ↑b
Full source
theorem sound {a b : List.Vector α n} (h : a.val ~ b.val) : (↑a : Sym α n) = ↑b :=
  Subtype.ext <| Quotient.sound h
Permutation of Vectors Implies Equality in Symmetric Power
Informal description
For any two vectors $a$ and $b$ of length $n$ over a type $\alpha$, if their underlying lists are permutations of each other (i.e., $a.\text{val} \sim b.\text{val}$), then their images under the canonical map to the $n$-th symmetric power of $\alpha$ are equal, i.e., $\text{Sym.ofVector}(a) = \text{Sym.ofVector}(b)$.
Sym.erase definition
[DecidableEq α] (s : Sym α (n + 1)) (a : α) (h : a ∈ s) : Sym α n
Full source
/-- `erase s a h` is the sym that subtracts 1 from the
  multiplicity of `a` if a is present in the sym. -/
def erase [DecidableEq α] (s : Sym α (n + 1)) (a : α) (h : a ∈ s) : Sym α n :=
  ⟨s.val.erase a, (Multiset.card_erase_of_mem h).trans <| s.property.symm ▸ n.pred_succ⟩
Element erasure in symmetric powers
Informal description
For a type $\alpha$ with decidable equality and a symmetric power $s \in \text{Sym}(\alpha, n+1)$, the operation $\text{erase}(s, a, h)$ returns a new symmetric power in $\text{Sym}(\alpha, n)$ where the multiplicity of $a$ is decreased by one, given a proof $h$ that $a$ is present in $s$. More precisely, if $s$ is represented by a multiset $m$ with $n+1$ elements, then $\text{erase}(s, a, h)$ is represented by the multiset $m \setminus \{a\}$ (which has $n$ elements).
Sym.erase_mk theorem
[DecidableEq α] (m : Multiset α) (hc : Multiset.card m = n + 1) (a : α) (h : a ∈ m) : (mk m hc).erase a h = mk (m.erase a) (by rw [Multiset.card_erase_of_mem h, hc, Nat.add_one, Nat.pred_succ])
Full source
@[simp]
theorem erase_mk [DecidableEq α] (m : Multiset α)
    (hc : Multiset.card m = n + 1) (a : α) (h : a ∈ m) :
    (mk m hc).erase a h =mk (m.erase a)
        (by rw [Multiset.card_erase_of_mem h, hc, Nat.add_one, Nat.pred_succ]) :=
  rfl
Erasure in Symmetric Power Construction: $\text{erase}(\text{mk}(m), a) = \text{mk}(m \setminus \{a\})$
Informal description
Let $\alpha$ be a type with decidable equality, $m$ be a multiset of elements of $\alpha$ with cardinality $n+1$, and $a \in m$. Then the erasure of $a$ from the symmetric power element constructed from $m$ is equal to the symmetric power element constructed from the multiset obtained by erasing one occurrence of $a$ from $m$. In other words, if $s = \text{mk}(m, hc)$ where $hc$ proves $|m| = n+1$, then $\text{erase}(s, a, h) = \text{mk}(m \setminus \{a\}, h')$ where $h'$ proves $|m \setminus \{a\}| = n$.
Sym.coe_erase theorem
[DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : (s.erase a h : Multiset α) = Multiset.erase s a
Full source
@[simp]
theorem coe_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) :
    (s.erase a h : Multiset α) = Multiset.erase s a :=
  rfl
Multiset Erasure Commutes with Symmetric Power Erasure
Informal description
Let $\alpha$ be a type with decidable equality, $s$ be an element of the $(n+1)$-th symmetric power of $\alpha$, and $a \in s$. Then the underlying multiset of $\text{erase}(s, a, h)$ is equal to the multiset obtained by erasing one occurrence of $a$ from the multiset representation of $s$, i.e., $(s \setminus \{a\}) = \text{erase}(s, a, h)$ as multisets.
Sym.cons_erase theorem
[DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : a ::ₛ s.erase a h = s
Full source
@[simp]
theorem cons_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : a ::ₛ s.erase a h = s :=
  coe_injective <| Multiset.cons_erase h
Reconstruction of Symmetric Power via Insertion and Erasure: $a \text{ ::ₛ } \text{erase}(s, a, h) = s$
Informal description
Let $\alpha$ be a type with decidable equality, and let $s$ be an element of the $(n+1)$-th symmetric power of $\alpha$. For any element $a \in s$, the operation of inserting $a$ into the symmetric power obtained by erasing one occurrence of $a$ from $s$ yields the original symmetric power $s$. In other words, $a \text{ ::ₛ } \text{erase}(s, a, h) = s$.
Sym.Sym' definition
(α : Type*) (n : ℕ)
Full source
/-- Another definition of the nth symmetric power, using vectors modulo permutations. (See `Sym`.)
-/
def Sym' (α : Type*) (n : ) :=
  Quotient (Vector.Perm.isSetoid α n)
Symmetric power of a type (vector quotient definition)
Informal description
The $n$-th symmetric power of a type $\alpha$, denoted $\text{Sym}' \alpha n$, is defined as the quotient of the type of length-$n$ vectors over $\alpha$ by the equivalence relation of permutation of vector components. In other words, it consists of equivalence classes of $n$-tuples where two tuples are considered equivalent if one can be obtained from the other by rearranging its elements.
Sym.cons' definition
{α : Type*} {n : ℕ} : α → Sym' α n → Sym' α (Nat.succ n)
Full source
/-- This is `cons` but for the alternative `Sym'` definition.
-/
def cons' {α : Type*} {n : } : α → Sym' α n → Sym' α (Nat.succ n) := fun a =>
  Quotient.map (Vector.cons a) fun ⟨_, _⟩ ⟨_, _⟩ h => List.Perm.cons _ h
Cons operation for symmetric powers
Informal description
The function `Sym.cons'` takes an element $a$ of type $\alpha$ and an element of the $n$-th symmetric power $\text{Sym}' \alpha n$, and returns an element of the $(n+1)$-th symmetric power $\text{Sym}' \alpha (n+1)$. It is constructed by mapping the vector cons operation through the quotient that defines the symmetric power, ensuring that the result respects the permutation equivalence relation.
Sym.term_::_ definition
: Lean.TrailingParserDescr✝
Full source
@[inherit_doc]
scoped notation a " :: " b => cons' a b
Cons notation for symmetric powers
Informal description
The notation `a :: b` represents the operation of constructing an element of the symmetric power `Sym' α (n+1)` from an element `a : α` and an element `b : Sym' α n`. This is the symmetric power analog of the cons operation for lists.
Sym.symEquivSym' definition
{α : Type*} {n : ℕ} : Sym α n ≃ Sym' α n
Full source
/-- Multisets of cardinality n are equivalent to length-n vectors up to permutations.
-/
def symEquivSym' {α : Type*} {n : } : SymSym α n ≃ Sym' α n :=
  Equiv.subtypeQuotientEquivQuotientSubtype _ _ (fun _ => by rfl) fun _ _ => by rfl
Equivalence between multiset and vector-quotient definitions of symmetric power
Informal description
For any type $\alpha$ and natural number $n$, there is a natural equivalence between the $n$-th symmetric power of $\alpha$ defined via multisets ($\text{Sym}\,\alpha\,n$) and the $n$-th symmetric power defined via quotient of vectors modulo permutations ($\text{Sym}'\,\alpha\,n$). This equivalence maps a multiset with exactly $n$ elements to the equivalence class of any $n$-tuple that contains the same elements with the same multiplicities (up to permutation), and vice versa.
Sym.cons_equiv_eq_equiv_cons theorem
(α : Type*) (n : ℕ) (a : α) (s : Sym α n) : (a :: symEquivSym' s) = symEquivSym' (a ::ₛ s)
Full source
theorem cons_equiv_eq_equiv_cons (α : Type*) (n : ) (a : α) (s : Sym α n) :
    (a::symEquivSym' s) = symEquivSym' (a ::ₛ s) := by
  rcases s with ⟨⟨l⟩, _⟩
  rfl
Commutativity of Symmetric Power Equivalence with Cons Operation
Informal description
For any type $\alpha$, natural number $n$, element $a \in \alpha$, and element $s$ of the $n$-th symmetric power $\text{Sym}\,\alpha\,n$, the equivalence $\text{symEquivSym}'$ commutes with the cons operation. That is, the equivalence class of $a$ cons'd with $\text{symEquivSym}'(s)$ equals $\text{symEquivSym}'$ applied to $a$ cons'd with $s$ in the multiset definition. Symbolically: $$(a :: \text{symEquivSym}'(s)) = \text{symEquivSym}'(a ::ₛ s)$$
Sym.instZeroSym instance
: Zero (Sym α 0)
Full source
instance instZeroSym : Zero (Sym α 0) :=
  ⟨⟨0, rfl⟩⟩
Zero Element in the Zeroth Symmetric Power
Informal description
The $0$-th symmetric power of a type $\alpha$ has a zero element, which is the equivalence class of the empty multiset.
Sym.toMultiset_zero theorem
: toMultiset (0 : Sym α 0) = 0
Full source
@[simp] theorem toMultiset_zero : toMultiset (0 : Sym α 0) = 0 := rfl
Forgetful Map Preserves Zero in Zeroth Symmetric Power
Informal description
The forgetful map from the zeroth symmetric power of a type $\alpha$ to multisets sends the zero element $0 \in \text{Sym}(\alpha, 0)$ to the empty multiset $0 \in \text{Multiset}(\alpha)$. In other words, $\text{toMultiset}(0) = 0$.
Sym.instEmptyCollectionOfNatNat instance
: EmptyCollection (Sym α 0)
Full source
instance : EmptyCollection (Sym α 0) :=
  ⟨0⟩
Empty Collection in the Zeroth Symmetric Power
Informal description
The zeroth symmetric power of a type $\alpha$ has an empty collection, which is the equivalence class of the empty multiset.
Sym.uniqueZero instance
: Unique (Sym α 0)
Full source
instance uniqueZero : Unique (Sym α 0) :=
  ⟨⟨nil⟩, eq_nil_of_card_zero⟩
Uniqueness of the Zeroth Symmetric Power
Informal description
The zeroth symmetric power $\text{Sym}(\alpha, 0)$ of any type $\alpha$ has a unique element, which is the equivalence class of the empty multiset.
Sym.replicate definition
(n : ℕ) (a : α) : Sym α n
Full source
/-- `replicate n a` is the sym containing only `a` with multiplicity `n`. -/
def replicate (n : ) (a : α) : Sym α n :=
  ⟨Multiset.replicate n a, Multiset.card_replicate _ _⟩
Replicated element in symmetric power
Informal description
For a type $\alpha$ and natural number $n$, the function `replicate n a` constructs the symmetric power element consisting of the element $a$ repeated $n$ times. This is represented as a multiset with exactly $n$ copies of $a$.
Sym.replicate_succ theorem
{a : α} {n : ℕ} : replicate n.succ a = a ::ₛ replicate n a
Full source
theorem replicate_succ {a : α} {n : } : replicate n.succ a = a ::ₛ replicate n a :=
  rfl
Recursive construction of replicated elements in symmetric power
Informal description
For any element $a$ of type $\alpha$ and any natural number $n$, the $(n+1)$-fold replication of $a$ in the symmetric power is equal to the insertion of $a$ into the $n$-fold replication of $a$. That is, $\text{replicate}(n+1, a) = a \text{::ₛ} \text{replicate}(n, a)$.
Sym.coe_replicate theorem
: (replicate n a : Multiset α) = Multiset.replicate n a
Full source
theorem coe_replicate : (replicate n a : Multiset α) = Multiset.replicate n a :=
  rfl
Multiset Representation of Replicated Symmetric Power: $\text{replicate}(n, a) = \text{Multiset.replicate}(n, a)$
Informal description
For any type $\alpha$, natural number $n$, and element $a \in \alpha$, the underlying multiset of the symmetric power element $\text{replicate}(n, a)$ is equal to the multiset $\text{Multiset.replicate}(n, a)$ (the multiset consisting of $n$ copies of $a$).
Sym.val_replicate theorem
: (replicate n a).val = Multiset.replicate n a
Full source
theorem val_replicate : (replicate n a).val = Multiset.replicate n a := by
  rw [val_eq_coe, coe_replicate]
Underlying Multiset of Replicated Symmetric Power Equals Replicated Multiset
Informal description
For any type $\alpha$, natural number $n$, and element $a \in \alpha$, the underlying multiset value of the symmetric power element $\text{replicate}(n, a)$ is equal to the multiset $\text{Multiset.replicate}(n, a)$ (the multiset consisting of $n$ copies of $a$).
Sym.mem_replicate theorem
: b ∈ replicate n a ↔ n ≠ 0 ∧ b = a
Full source
@[simp]
theorem mem_replicate : b ∈ replicate n ab ∈ replicate n a ↔ n ≠ 0 ∧ b = a :=
  Multiset.mem_replicate
Membership in Replicated Symmetric Power: $b \in \text{replicate}(n, a) \leftrightarrow n \neq 0 \land b = a$
Informal description
For any element $b$ of type $\alpha$ and natural number $n$, $b$ is a member of the symmetric power `replicate n a` if and only if $n$ is non-zero and $b$ equals $a$. In other words, $b \in \text{replicate}(n, a) \leftrightarrow n \neq 0 \land b = a$.
Sym.exists_mem theorem
(s : Sym α n.succ) : ∃ a, a ∈ s
Full source
theorem exists_mem (s : Sym α n.succ) : ∃ a, a ∈ s :=
  Multiset.card_pos_iff_exists_mem.1 <| s.2.symm ▸ n.succ_pos
Existence of Member in Non-Empty Symmetric Power
Informal description
For any non-empty symmetric power $s$ of type $\alpha$ (i.e., $s \in \text{Sym}(\alpha, n+1)$), there exists an element $a \in \alpha$ such that $a$ is a member of $s$.
Sym.exists_cons_of_mem theorem
{s : Sym α (n + 1)} {a : α} (h : a ∈ s) : ∃ t, s = a ::ₛ t
Full source
theorem exists_cons_of_mem {s : Sym α (n + 1)} {a : α} (h : a ∈ s) : ∃ t, s = a ::ₛ t := by
  obtain ⟨m, h⟩ := Multiset.exists_cons_of_mem h
  have : Multiset.card m = n := by
    apply_fun Multiset.card at h
    rw [s.2, Multiset.card_cons, add_left_inj] at h
    exact h.symm
  use ⟨m, this⟩
  apply Subtype.ext
  exact h
Decomposition of Symmetric Power Membership: $a \in s \implies \exists t, s = a ::ₛ t$
Informal description
For any element $a$ in the type $\alpha$ and any symmetric power $s \in \text{Sym}(\alpha, n+1)$, if $a$ is a member of $s$, then there exists a symmetric power $t \in \text{Sym}(\alpha, n)$ such that $s$ can be expressed as the insertion of $a$ into $t$, i.e., $s = a ::ₛ t$.
Sym.exists_eq_cons_of_succ theorem
(s : Sym α n.succ) : ∃ (a : α) (s' : Sym α n), s = a ::ₛ s'
Full source
theorem exists_eq_cons_of_succ (s : Sym α n.succ) : ∃ (a : α) (s' : Sym α n), s = a ::ₛ s' := by
  obtain ⟨a, ha⟩ := exists_mem s
  classical exact ⟨a, s.erase a ha, (cons_erase ha).symm⟩
Decomposition of Non-Empty Symmetric Power via Insertion
Informal description
For any non-empty symmetric power $s \in \text{Sym}(\alpha, n+1)$, there exists an element $a \in \alpha$ and a symmetric power $s' \in \text{Sym}(\alpha, n)$ such that $s$ can be expressed as the insertion of $a$ into $s'$, i.e., $s = a ::ₛ s'$.
Sym.instSubsingleton instance
[Subsingleton α] (n : ℕ) : Subsingleton (Sym α n)
Full source
instance [Subsingleton α] (n : ) : Subsingleton (Sym α n) :=
  ⟨by
    cases n
    · simp [eq_iff_true_of_subsingleton]
    · intro s s'
      obtain ⟨b, -⟩ := exists_mem s
      rw [eq_replicate_of_subsingleton b s', eq_replicate_of_subsingleton b s]⟩
Subsingleton Property of Symmetric Powers for Subsingleton Types
Informal description
For any type $\alpha$ that is a subsingleton (i.e., has at most one element) and any natural number $n$, the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ is also a subsingleton.
Sym.inhabitedSym instance
[Inhabited α] (n : ℕ) : Inhabited (Sym α n)
Full source
instance inhabitedSym [Inhabited α] (n : ) : Inhabited (Sym α n) :=
  ⟨replicate n default⟩
Inhabited Symmetric Powers of Inhabited Types
Informal description
For any inhabited type $\alpha$ and natural number $n$, the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ is also inhabited.
Sym.instUnique instance
(n : ℕ) [Unique α] : Unique (Sym α n)
Full source
instance (n : ) [Unique α] : Unique (Sym α n) :=
  Unique.mk' _
Unique Elements in Symmetric Powers of Unique Types
Informal description
For any natural number $n$ and any type $\alpha$ with a unique element, the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ also has a unique element.
Sym.replicate_right_inj theorem
{a b : α} {n : ℕ} (h : n ≠ 0) : replicate n a = replicate n b ↔ a = b
Full source
theorem replicate_right_inj {a b : α} {n : } (h : n ≠ 0) : replicatereplicate n a = replicate n b ↔ a = b :=
  Subtype.ext_iff.trans (Multiset.replicate_right_inj h)
Injectivity of Replicated Symmetric Power Elements for Nonzero $n$
Informal description
For any elements $a, b$ of a type $\alpha$ and any nonzero natural number $n$, the replicated symmetric power elements $\mathrm{replicate}\,n\,a$ and $\mathrm{replicate}\,n\,b$ are equal if and only if $a = b$.
Sym.replicate_right_injective theorem
{n : ℕ} (h : n ≠ 0) : Function.Injective (replicate n : α → Sym α n)
Full source
theorem replicate_right_injective {n : } (h : n ≠ 0) :
    Function.Injective (replicate n : α → Sym α n) := fun _ _ => (replicate_right_inj h).1
Injectivity of Replication in Symmetric Powers for Nonzero $n$
Informal description
For any nonzero natural number $n$, the function that maps an element $a$ of a type $\alpha$ to its $n$-fold replication in the $n$-th symmetric power $\mathrm{Sym}(\alpha, n)$ is injective. In other words, if $\mathrm{replicate}\,n\,a = \mathrm{replicate}\,n\,b$, then $a = b$.
Sym.instNontrivialHAddNatOfNat instance
(n : ℕ) [Nontrivial α] : Nontrivial (Sym α (n + 1))
Full source
instance (n : ) [Nontrivial α] : Nontrivial (Sym α (n + 1)) :=
  (replicate_right_injective n.succ_ne_zero).nontrivial
Nontriviality of Higher Symmetric Powers
Informal description
For any natural number $n$ and any nontrivial type $\alpha$, the $(n+1)$-th symmetric power $\mathrm{Sym}(\alpha, n+1)$ is also a nontrivial type.
Sym.map definition
{n : ℕ} (f : α → β) (x : Sym α n) : Sym β n
Full source
/-- A function `α → β` induces a function `Sym α n → Sym β n` by applying it to every element of
the underlying `n`-tuple. -/
def map {n : } (f : α → β) (x : Sym α n) : Sym β n :=
  ⟨x.val.map f, by simp⟩
Image of symmetric power under a function
Informal description
Given a function $f : \alpha \to \beta$ and an element $x$ of the $n$-th symmetric power of $\alpha$, the function `Sym.map` applies $f$ to each element of the underlying $n$-tuple of $x$ to produce an element of the $n$-th symmetric power of $\beta$.
Sym.mem_map theorem
{n : ℕ} {f : α → β} {b : β} {l : Sym α n} : b ∈ Sym.map f l ↔ ∃ a, a ∈ l ∧ f a = b
Full source
@[simp]
theorem mem_map {n : } {f : α → β} {b : β} {l : Sym α n} :
    b ∈ Sym.map f lb ∈ Sym.map f l ↔ ∃ a, a ∈ l ∧ f a = b :=
  Multiset.mem_map
Characterization of Membership in Mapped Symmetric Power
Informal description
For any natural number $n$, function $f : \alpha \to \beta$, element $b \in \beta$, and symmetric power $l \in \Sym(\alpha, n)$, we have $b \in \Sym.\map(f, l)$ if and only if there exists $a \in \alpha$ such that $a \in l$ and $f(a) = b$.
Sym.map_id' theorem
{α : Type*} {n : ℕ} (s : Sym α n) : Sym.map (fun x : α => x) s = s
Full source
/-- Note: `Sym.map_id` is not simp-normal, as simp ends up unfolding `id` with `Sym.map_congr` -/
@[simp]
theorem map_id' {α : Type*} {n : } (s : Sym α n) : Sym.map (fun x : α => x) s = s := by
  ext; simp only [map, Multiset.map_id', ← val_eq_coe]
Identity Map Preserves Symmetric Power Elements: $\text{id}_*(s) = s$
Informal description
For any type $\alpha$, natural number $n$, and element $s$ in the $n$-th symmetric power of $\alpha$, the image of $s$ under the identity map (i.e., $\text{Sym.map}(\text{id}, s)$) is equal to $s$ itself.
Sym.map_id theorem
{α : Type*} {n : ℕ} (s : Sym α n) : Sym.map id s = s
Full source
theorem map_id {α : Type*} {n : } (s : Sym α n) : Sym.map id s = s := by
  ext; simp only [map, id_eq, Multiset.map_id', ← val_eq_coe]
Identity Map Preserves Symmetric Power Elements: $\text{id}_*(s) = s$
Informal description
For any type $\alpha$, natural number $n$, and element $s$ in the $n$-th symmetric power of $\alpha$, the image of $s$ under the identity map is equal to $s$ itself, i.e., $\text{Sym.map}(\text{id}, s) = s$.
Sym.map_map theorem
{α β γ : Type*} {n : ℕ} (g : β → γ) (f : α → β) (s : Sym α n) : Sym.map g (Sym.map f s) = Sym.map (g ∘ f) s
Full source
@[simp]
theorem map_map {α β γ : Type*} {n : } (g : β → γ) (f : α → β) (s : Sym α n) :
    Sym.map g (Sym.map f s) = Sym.map (g ∘ f) s :=
  Subtype.ext <| by dsimp only [Sym.map]; simp
Composition Law for Symmetric Power Maps: $(g \circ f)_* = g_* \circ f_*$
Informal description
For any types $\alpha$, $\beta$, $\gamma$, natural number $n$, and functions $f : \alpha \to \beta$ and $g : \beta \to \gamma$, the composition of the symmetric power maps satisfies $(g \circ f)_*(s) = g_*(f_*(s))$ for any $s$ in the $n$-th symmetric power of $\alpha$.
Sym.map_zero theorem
(f : α → β) : Sym.map f (0 : Sym α 0) = (0 : Sym β 0)
Full source
@[simp]
theorem map_zero (f : α → β) : Sym.map f (0 : Sym α 0) = (0 : Sym β 0) :=
  rfl
Preservation of Zero Element under Symmetric Power Mapping
Informal description
For any function $f : \alpha \to \beta$, the image of the zero element in the zeroth symmetric power of $\alpha$ under the map $f$ is the zero element in the zeroth symmetric power of $\beta$, i.e., $f_*(0) = 0$.
Sym.map_cons theorem
{n : ℕ} (f : α → β) (a : α) (s : Sym α n) : (a ::ₛ s).map f = f a ::ₛ s.map f
Full source
@[simp]
theorem map_cons {n : } (f : α → β) (a : α) (s : Sym α n) : (a ::ₛ s).map f = f a ::ₛ s.map f :=
  ext <| Multiset.map_cons _ _ _
Naturality of symmetric power map with respect to insertion: $f_*(a ::ₛ s) = f(a) ::ₛ f_*(s)$
Informal description
For any natural number $n$, function $f : \alpha \to \beta$, element $a \in \alpha$, and symmetric power element $s \in \text{Sym} \alpha n$, the image of the cons operation under $f$ satisfies: \[ \text{map}\, f\, (a ::ₛ s) = f(a) ::ₛ \text{map}\, f\, s \] where $::ₛ$ denotes the insertion operation in symmetric powers.
Sym.map_congr theorem
{f g : α → β} {s : Sym α n} (h : ∀ x ∈ s, f x = g x) : map f s = map g s
Full source
@[congr]
theorem map_congr {f g : α → β} {s : Sym α n} (h : ∀ x ∈ s, f x = g x) : map f s = map g s :=
  Subtype.ext <| Multiset.map_congr rfl h
Congruence Property of Symmetric Power Mapping
Informal description
Let $\alpha$ and $\beta$ be types, $n$ a natural number, and $f, g : \alpha \to \beta$ functions. For any element $s$ in the $n$-th symmetric power of $\alpha$, if $f(x) = g(x)$ for all $x \in s$, then the images of $s$ under $f$ and $g$ are equal, i.e., $\text{map}\, f\, s = \text{map}\, g\, s$.
Sym.map_mk theorem
{f : α → β} {m : Multiset α} {hc : Multiset.card m = n} : map f (mk m hc) = mk (m.map f) (by simp [hc])
Full source
@[simp]
theorem map_mk {f : α → β} {m : Multiset α} {hc : Multiset.card m = n} :
    map f (mk m hc) = mk (m.map f) (by simp [hc]) :=
  rfl
Image of Symmetric Power Construction under Function Application
Informal description
For any function $f : \alpha \to \beta$ and multiset $m$ of elements of $\alpha$ with cardinality $n$, the image of the symmetric power element constructed from $m$ under $f$ is equal to the symmetric power element constructed from the image multiset $f(m)$, i.e., \[ \text{map}\, f\, (\text{mk}\, m\, hc) = \text{mk}\, (m.\text{map}\, f)\, (hc') \] where $hc$ is a proof that $m$ has cardinality $n$ and $hc'$ is the corresponding proof for $f(m)$.
Sym.coe_map theorem
(s : Sym α n) (f : α → β) : ↑(s.map f) = Multiset.map f s
Full source
@[simp]
theorem coe_map (s : Sym α n) (f : α → β) : ↑(s.map f) = Multiset.map f s :=
  rfl
Compatibility of Symmetric Power Map with Multiset Map
Informal description
For any element $s$ in the $n$-th symmetric power of a type $\alpha$ and any function $f : \alpha \to \beta$, the underlying multiset of the image of $s$ under the symmetric power map $f$ is equal to the image of the underlying multiset of $s$ under $f$. That is, \[ \text{toMultiset}\, (\text{map}\, f\, s) = \text{Multiset.map}\, f\, (\text{toMultiset}\, s). \]
Sym.map_injective theorem
{f : α → β} (hf : Injective f) (n : ℕ) : Injective (map f : Sym α n → Sym β n)
Full source
theorem map_injective {f : α → β} (hf : Injective f) (n : ) :
    Injective (map f : Sym α n → Sym β n) := fun _ _ h =>
  coe_injective <| Multiset.map_injective hf <| coe_inj.2 h
Injectivity of Symmetric Power Map Induced by Injective Function
Informal description
For any injective function $f : \alpha \to \beta$ and any natural number $n$, the induced map $\text{Sym}(\alpha, n) \to \text{Sym}(\beta, n)$ is also injective.
Sym.equivCongr definition
(e : α ≃ β) : Sym α n ≃ Sym β n
Full source
/-- Mapping an equivalence `α ≃ β` using `Sym.map` gives an equivalence between `Sym α n` and
`Sym β n`. -/
@[simps]
def equivCongr (e : α ≃ β) : SymSym α n ≃ Sym β n where
  toFun := map e
  invFun := map e.symm
  left_inv x := by rw [map_map, Equiv.symm_comp_self, map_id]
  right_inv x := by rw [map_map, Equiv.self_comp_symm, map_id]
Equivalence of symmetric powers induced by type equivalence
Informal description
Given an equivalence $e : \alpha \simeq \beta$ between types $\alpha$ and $\beta$, the function `Sym.equivCongr` constructs an equivalence between the $n$-th symmetric powers $\text{Sym}\,\alpha\,n$ and $\text{Sym}\,\beta\,n$. This is done by applying the function $e$ to each element of the symmetric power via `Sym.map`, with the inverse constructed similarly using the inverse equivalence $e^{-1}$. The construction ensures that applying $e$ followed by $e^{-1}$ (or vice versa) returns the original symmetric power element.
Sym.attach definition
(s : Sym α n) : Sym { x // x ∈ s } n
Full source
/-- "Attach" a proof that `a ∈ s` to each element `a` in `s` to produce
an element of the symmetric power on `{x // x ∈ s}`. -/
def attach (s : Sym α n) : Sym { x // x ∈ s } n :=
  ⟨s.val.attach, by (conv_rhs => rw [← s.2, ← Multiset.card_attach])⟩
Attaching membership proofs to symmetric power elements
Informal description
Given an element $s$ of the $n$-th symmetric power of a type $\alpha$, the function `Sym.attach` produces an element of the symmetric power on the subtype $\{x \mid x \in s\}$ by attaching to each element in $s$ a proof that it belongs to $s$.
Sym.attach_mk theorem
{m : Multiset α} {hc : Multiset.card m = n} : attach (mk m hc) = mk m.attach (Multiset.card_attach.trans hc)
Full source
@[simp]
theorem attach_mk {m : Multiset α} {hc : Multiset.card m = n} :
    attach (mk m hc) = mk m.attach (Multiset.card_attach.trans hc) :=
  rfl
Equality of Attached Symmetric Power Construction and Construction of Attached Multiset
Informal description
For any multiset $m$ of elements of type $\alpha$ with cardinality $n$, the attached symmetric power element constructed from $m$ is equal to the symmetric power element constructed from the attached multiset $m.\text{attach}$ (where the cardinality condition is preserved via the natural bijection between $m$ and its attached version).
Sym.coe_attach theorem
(s : Sym α n) : (s.attach : Multiset { a // a ∈ s }) = Multiset.attach (s : Multiset α)
Full source
@[simp]
theorem coe_attach (s : Sym α n) : (s.attach : Multiset { a // a ∈ s }) =
    Multiset.attach (s : Multiset α) :=
  rfl
Equality of Attached Symmetric Power and Multiset Attachment
Informal description
For any element $s$ of the $n$-th symmetric power of a type $\alpha$, the underlying multiset of the attached symmetric power $s.\text{attach}$ is equal to the multiset obtained by attaching membership proofs to the elements of the underlying multiset of $s$.
Sym.attach_map_coe theorem
(s : Sym α n) : s.attach.map (↑) = s
Full source
theorem attach_map_coe (s : Sym α n) : s.attach.map (↑) = s :=
  coe_injective <| Multiset.attach_map_val _
Canonical Map of Attached Symmetric Power Preserves Original Element
Informal description
For any element $s$ of the $n$-th symmetric power of a type $\alpha$, the map obtained by applying the canonical inclusion to each element of the attached symmetric power $s.\text{attach}$ is equal to $s$ itself. In other words, $(\text{map} \, \uparrow) \, s.\text{attach} = s$.
Sym.mem_attach theorem
(s : Sym α n) (x : { x // x ∈ s }) : x ∈ s.attach
Full source
@[simp]
theorem mem_attach (s : Sym α n) (x : { x // x ∈ s }) : x ∈ s.attach :=
  Multiset.mem_attach _ _
Membership in Attached Symmetric Power
Informal description
For any element $x$ in the subtype $\{x \mid x \in s\}$ where $s$ is an element of the $n$-th symmetric power of a type $\alpha$, the element $x$ belongs to the attached symmetric power $s.\text{attach}$.
Sym.attach_nil theorem
: (nil : Sym α 0).attach = nil
Full source
@[simp]
theorem attach_nil : (nil : Sym α 0).attach = nil :=
  rfl
Attached Symmetric Power of Empty Element is Empty
Informal description
For the empty symmetric power element $\text{nil} : \text{Sym}(\alpha, 0)$, the attached symmetric power $\text{nil}.\text{attach}$ is equal to $\text{nil}$ itself.
Sym.attach_cons theorem
(x : α) (s : Sym α n) : (cons x s).attach = cons ⟨x, mem_cons_self _ _⟩ (s.attach.map fun x => ⟨x, mem_cons_of_mem x.prop⟩)
Full source
@[simp]
theorem attach_cons (x : α) (s : Sym α n) :
    (cons x s).attach =
      cons ⟨x, mem_cons_self _ _⟩ (s.attach.map fun x => ⟨x, mem_cons_of_mem x.prop⟩) :=
  coe_injective <| Multiset.attach_cons _ _
Attached Symmetric Power of Insertion Equals Insertion of Attached Elements
Informal description
For any element $x$ of type $\alpha$ and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the attached symmetric power of the insertion $x ::ₛ s$ is equal to the insertion of $\langle x, \text{mem\_cons\_self}\ x\ s\rangle$ into the image of $s.\text{attach}$ under the function mapping each element $\langle y, h\rangle$ to $\langle y, \text{mem\_cons\_of\_mem}\ h\rangle$.
Sym.cast definition
{n m : ℕ} (h : n = m) : Sym α n ≃ Sym α m
Full source
/-- Change the length of a `Sym` using an equality.
The simp-normal form is for the `cast` to be pushed outward. -/
protected def cast {n m : } (h : n = m) : SymSym α n ≃ Sym α m where
  toFun s := ⟨s.val, s.2.trans h⟩
  invFun s := ⟨s.val, s.2.trans h.symm⟩
  left_inv _ := Subtype.ext rfl
  right_inv _ := Subtype.ext rfl
Equivalence of symmetric powers via natural number equality
Informal description
Given a natural number equality $h : n = m$, the function `Sym.cast h` defines an equivalence between the $n$-th symmetric power of a type $\alpha$ and the $m$-th symmetric power of $\alpha$, by transporting the cardinality condition along the equality $h$.
Sym.cast_rfl theorem
: Sym.cast rfl s = s
Full source
@[simp]
theorem cast_rfl : Sym.cast rfl s = s :=
  Subtype.ext rfl
Reflexivity of Symmetric Power Cast: $\text{Sym.cast}\, \text{rfl}\, s = s$
Informal description
For any symmetric power $\text{Sym}(\alpha, n)$ and any element $s \in \text{Sym}(\alpha, n)$, the equivalence $\text{Sym.cast}$ applied to the reflexivity proof $\text{rfl} : n = n$ maps $s$ to itself, i.e., $\text{Sym.cast}\, \text{rfl}\, s = s$.
Sym.cast_cast theorem
{n'' : ℕ} (h : n = n') (h' : n' = n'') : Sym.cast h' (Sym.cast h s) = Sym.cast (h.trans h') s
Full source
@[simp]
theorem cast_cast {n'' : } (h : n = n') (h' : n' = n'') :
    Sym.cast h' (Sym.cast h s) = Sym.cast (h.trans h') s :=
  rfl
Composition of Symmetric Power Casts via Transitivity of Equality
Informal description
For any natural numbers $n$, $n'$, and $n''$, given equalities $h : n = n'$ and $h' : n' = n''$, the composition of the symmetric power equivalences $\text{Sym.cast}\, h' \circ \text{Sym.cast}\, h$ is equal to the equivalence $\text{Sym.cast}\, (h \trans h')$ applied to $s$.
Sym.coe_cast theorem
(h : n = m) : (Sym.cast h s : Multiset α) = s
Full source
@[simp]
theorem coe_cast (h : n = m) : (Sym.cast h s : Multiset α) = s :=
  rfl
Underlying Multiset Preservation under Symmetric Power Cast
Informal description
For any natural numbers $n$ and $m$ with an equality $h : n = m$, and any element $s$ of the $n$-th symmetric power $\text{Sym}(\alpha, n)$, the underlying multiset of $\text{Sym.cast}\, h\, s$ is equal to $s$.
Sym.mem_cast theorem
(h : n = m) : a ∈ Sym.cast h s ↔ a ∈ s
Full source
@[simp]
theorem mem_cast (h : n = m) : a ∈ Sym.cast h sa ∈ Sym.cast h s ↔ a ∈ s :=
  Iff.rfl
Membership Preservation under Symmetric Power Cast
Informal description
For any natural numbers $n$ and $m$ with $h : n = m$, and any element $a$ of type $\alpha$, the element $a$ belongs to the symmetric power $\text{Sym.cast}\, h\, s$ if and only if $a$ belongs to $s$.
Sym.append definition
(s : Sym α n) (s' : Sym α n') : Sym α (n + n')
Full source
/-- Append a pair of `Sym` terms. -/
def append (s : Sym α n) (s' : Sym α n') : Sym α (n + n') :=
  ⟨s.1 + s'.1, by rw [Multiset.card_add, s.2, s'.2]⟩
Append operation for symmetric powers
Informal description
Given two symmetric powers \( s \in \text{Sym}^n(\alpha) \) and \( s' \in \text{Sym}^{n'}(\alpha) \), the operation \( \text{Sym.append} \) combines them into a symmetric power \( \text{Sym}^{n+n'}(\alpha) \) by taking the multiset union of their underlying multisets.
Sym.append_inj_right theorem
(s : Sym α n) {t t' : Sym α n'} : s.append t = s.append t' ↔ t = t'
Full source
@[simp]
theorem append_inj_right (s : Sym α n) {t t' : Sym α n'} : s.append t = s.append t' ↔ t = t' :=
  Subtype.ext_iff.trans <| (add_right_inj _).trans Subtype.ext_iff.symm
Right Injectivity of Symmetric Power Append Operation
Informal description
For any symmetric power $s \in \text{Sym}^n(\alpha)$ and any two symmetric powers $t, t' \in \text{Sym}^{n'}(\alpha)$, the equality $s \cdot t = s \cdot t'$ holds if and only if $t = t'$, where $\cdot$ denotes the append operation on symmetric powers.
Sym.append_inj_left theorem
{s s' : Sym α n} (t : Sym α n') : s.append t = s'.append t ↔ s = s'
Full source
@[simp]
theorem append_inj_left {s s' : Sym α n} (t : Sym α n') : s.append t = s'.append t ↔ s = s' :=
  Subtype.ext_iff.trans <| (add_left_inj _).trans Subtype.ext_iff.symm
Left Injectivity of Symmetric Power Append Operation
Informal description
For any two symmetric powers $s, s' \in \text{Sym}^n(\alpha)$ and any symmetric power $t \in \text{Sym}^{n'}(\alpha)$, the equality $s \cdot t = s' \cdot t$ holds if and only if $s = s'$, where $\cdot$ denotes the append operation on symmetric powers.
Sym.append_comm theorem
(s : Sym α n') (s' : Sym α n') : s.append s' = Sym.cast (add_comm _ _) (s'.append s)
Full source
theorem append_comm (s : Sym α n') (s' : Sym α n') :
    s.append s' = Sym.cast (add_comm _ _) (s'.append s) := by
  ext
  simp [append, add_comm]
Commutativity of Symmetric Power Append via Addition Commutativity
Informal description
For any symmetric powers $s \in \text{Sym}^n(\alpha)$ and $s' \in \text{Sym}^n(\alpha)$, the append operation $s \cdot s'$ is equal to $s' \cdot s$ under the equivalence induced by the commutativity of addition on natural numbers, i.e., $s \cdot s' = \text{Sym.cast}(n + n' = n' + n)(s' \cdot s)$.
Sym.coe_append theorem
(s : Sym α n) (s' : Sym α n') : (s.append s' : Multiset α) = s + s'
Full source
@[simp, norm_cast]
theorem coe_append (s : Sym α n) (s' : Sym α n') : (s.append s' : Multiset α) = s + s' :=
  rfl
Multiset Representation of Symmetric Power Append Operation
Informal description
For any symmetric powers $s \in \text{Sym}^n(\alpha)$ and $s' \in \text{Sym}^{n'}(\alpha)$, the underlying multiset of their append operation $\text{Sym.append}(s, s')$ is equal to the sum of their underlying multisets, i.e., $(s \text{.append } s' : \text{Multiset } \alpha) = s + s'$.
Sym.mem_append_iff theorem
{s' : Sym α m} : a ∈ s.append s' ↔ a ∈ s ∨ a ∈ s'
Full source
theorem mem_append_iff {s' : Sym α m} : a ∈ s.append s'a ∈ s.append s' ↔ a ∈ s ∨ a ∈ s' :=
  Multiset.mem_add
Membership in Append of Symmetric Powers is Union of Memberships
Informal description
For any element $a$ of type $\alpha$, symmetric powers $s \in \text{Sym}^n(\alpha)$ and $s' \in \text{Sym}^m(\alpha)$, the element $a$ belongs to the append operation $\text{Sym.append}(s, s')$ if and only if $a$ belongs to $s$ or $a$ belongs to $s'$.
Sym.oneEquiv definition
: α ≃ Sym α 1
Full source
/-- `a ↦ {a}` as an equivalence between `α` and `Sym α 1`. -/
@[simps apply]
def oneEquiv : α ≃ Sym α 1 where
  toFun a := ⟨{a}, by simp⟩
  invFun s := (Equiv.subtypeQuotientEquivQuotientSubtype
      (·.length = 1) _ (fun _ ↦ Iff.rfl) (fun l l' ↦ by rfl) s).liftOn
    (fun l ↦ l.1.head <| List.length_pos_iff.mp <| by simp)
    fun ⟨_, _⟩ ⟨_, h⟩ ↦ fun perm ↦ by
      obtain ⟨a, rfl⟩ := List.length_eq_one_iff.mp h
      exact List.eq_of_mem_singleton (perm.mem_iff.mp <| List.head_mem _)
  left_inv a := by rfl
  right_inv := by rintro ⟨⟨l⟩, h⟩; obtain ⟨a, rfl⟩ := List.length_eq_one_iff.mp h; rfl
Equivalence between a type and its first symmetric power
Informal description
The equivalence between a type $\alpha$ and its first symmetric power $\text{Sym}(\alpha, 1)$, which maps each element $a \in \alpha$ to the singleton multiset $\{a\}$.
Sym.fill definition
(a : α) (i : Fin (n + 1)) (m : Sym α (n - i)) : Sym α n
Full source
/-- Fill a term `m : Sym α (n - i)` with `i` copies of `a` to obtain a term of `Sym α n`.
This is a convenience wrapper for `m.append (replicate i a)` that adjusts the term using
`Sym.cast`. -/
def fill (a : α) (i : Fin (n + 1)) (m : Sym α (n - i)) : Sym α n :=
  Sym.cast (Nat.sub_add_cancel i.is_le) (m.append (replicate i a))
Filling a symmetric power with repeated elements
Informal description
Given an element $a$ of type $\alpha$, an index $i$ in $\text{Fin}(n+1)$, and a symmetric power element $m \in \text{Sym}(\alpha, n-i)$, the operation $\text{Sym.fill}$ constructs a symmetric power element in $\text{Sym}(\alpha, n)$ by appending $i$ copies of $a$ to $m$ and adjusting the result using the natural number equality $n - i + i = n$. More precisely, $\text{Sym.fill}$ is defined as the composition of $\text{Sym.append}$ with $\text{Sym.cast}$, where $\text{Sym.append}$ combines $m$ with the replicated element $\text{replicate}(i, a)$, and $\text{Sym.cast}$ ensures the result has the correct cardinality $n$ via the identity $n - i + i = n$.
Sym.coe_fill theorem
{a : α} {i : Fin (n + 1)} {m : Sym α (n - i)} : (fill a i m : Multiset α) = m + replicate i a
Full source
theorem coe_fill {a : α} {i : Fin (n + 1)} {m : Sym α (n - i)} :
    (fill a i m : Multiset α) = m + replicate i a :=
  rfl
Multiset Representation of Filled Symmetric Power
Informal description
For any element $a$ of type $\alpha$, index $i \in \text{Fin}(n+1)$, and symmetric power element $m \in \text{Sym}(\alpha, n-i)$, the underlying multiset of $\text{Sym.fill}(a, i, m)$ is equal to the sum of the multiset associated with $m$ and the multiset consisting of $i$ copies of $a$. That is, $$ \text{toMultiset}(\text{fill}(a, i, m)) = \text{toMultiset}(m) + \text{replicate}(i, a). $$
Sym.mem_fill_iff theorem
{a b : α} {i : Fin (n + 1)} {s : Sym α (n - i)} : a ∈ Sym.fill b i s ↔ (i : ℕ) ≠ 0 ∧ a = b ∨ a ∈ s
Full source
theorem mem_fill_iff {a b : α} {i : Fin (n + 1)} {s : Sym α (n - i)} :
    a ∈ Sym.fill b i sa ∈ Sym.fill b i s ↔ (i : ℕ) ≠ 0 ∧ a = b ∨ a ∈ s := by
  rw [fill, mem_cast, mem_append_iff, or_comm, mem_replicate]
Membership Condition for Filled Symmetric Power: $a \in \text{fill}(b,i,s) \leftrightarrow (i \neq 0 \land a = b) \lor a \in s$
Informal description
For any elements $a, b$ of type $\alpha$, index $i \in \text{Fin}(n+1)$, and symmetric power element $s \in \text{Sym}(\alpha, n-i)$, the element $a$ belongs to the filled symmetric power $\text{Sym.fill}\, b\, i\, s$ if and only if either: 1. $i \neq 0$ and $a = b$, or 2. $a$ belongs to $s$.
Sym.filterNe definition
[DecidableEq α] (a : α) (m : Sym α n) : Σ i : Fin (n + 1), Sym α (n - i)
Full source
/-- Remove every `a` from a given `Sym α n`.
Yields the number of copies `i` and a term of `Sym α (n - i)`. -/
def filterNe [DecidableEq α] (a : α) (m : Sym α n) : Σ i : Fin (n + 1), Sym α (n - i) :=
  ⟨⟨m.1.count a, (count_le_card _ _).trans_lt <| by rw [m.2, Nat.lt_succ_iff]⟩,
    m.1.filter (a ≠ ·),
    Nat.eq_sub_of_add_eq <|
      Eq.trans
        (by
          rw [← countP_eq_card_filter, add_comm]
          simp only [eq_comm, Ne, count]
          rw [← card_eq_countP_add_countP _ _])
        m.2⟩
Filtering non-equal elements from symmetric power
Informal description
Given a decidable equality on type $\alpha$, an element $a \in \alpha$, and a symmetric power $m \in \text{Sym}(\alpha, n)$, the function $\text{filterNe}$ returns a pair $(i, s')$ where: - $i$ is the multiplicity of $a$ in $m$ (a natural number between $0$ and $n$) - $s'$ is the symmetric power obtained by removing all occurrences of $a$ from $m$, which lies in $\text{Sym}(\alpha, n - i)$ In other words, $\text{filterNe}$ partitions $m$ into the part consisting of $a$ (with multiplicity $i$) and the part consisting of all other elements (forming $s'$).
Sym.sigma_sub_ext theorem
{m₁ m₂ : Σ i : Fin (n + 1), Sym α (n - i)} (h : (m₁.2 : Multiset α) = m₂.2) : m₁ = m₂
Full source
theorem sigma_sub_ext {m₁ m₂ : Σ i : Fin (n + 1), Sym α (n - i)} (h : (m₁.2 : Multiset α) = m₂.2) :
    m₁ = m₂ :=
  Sigma.subtype_ext
    (Fin.ext <| by
      rw [← Nat.sub_sub_self (Nat.le_of_lt_succ m₁.1.is_lt), ← m₁.2.2, val_eq_coe, h,
        ← val_eq_coe, m₂.2.2, Nat.sub_sub_self (Nat.le_of_lt_succ m₂.1.is_lt)])
    h
Extensionality for Filtered Symmetric Powers
Informal description
Let $\alpha$ be a type and $n$ a natural number. For any two pairs $(i_1, s_1)$ and $(i_2, s_2)$ in the sigma type $\Sigma (i : \text{Fin}(n+1)), \text{Sym}(\alpha, n-i)$, if the underlying multisets of $s_1$ and $s_2$ are equal (i.e., $s_1 = s_2$ as multisets), then the pairs are equal: $(i_1, s_1) = (i_2, s_2)$.
Sym.fill_filterNe theorem
[DecidableEq α] (a : α) (m : Sym α n) : (m.filterNe a).2.fill a (m.filterNe a).1 = m
Full source
theorem fill_filterNe [DecidableEq α] (a : α) (m : Sym α n) :
    (m.filterNe a).2.fill a (m.filterNe a).1 = m :=
  Sym.ext
    (by
      rw [coe_fill, filterNe, ← val_eq_coe, Subtype.coe_mk, Fin.val_mk]
      ext b; dsimp
      rw [count_add, count_filter, Sym.coe_replicate, count_replicate]
      obtain rfl | h := eq_or_ne a b
      · rw [if_pos rfl, if_neg (not_not.2 rfl), zero_add]
      · rw [if_pos h, if_neg h, add_zero])
Reconstruction of Symmetric Power via Fill and Filter
Informal description
Let $\alpha$ be a type with decidable equality, $a \in \alpha$, and $m \in \text{Sym}(\alpha, n)$. If $(i, s')$ is the result of filtering out all occurrences of $a$ from $m$ (where $i$ is the multiplicity of $a$ in $m$ and $s' \in \text{Sym}(\alpha, n-i)$), then filling $s'$ with $i$ copies of $a$ reconstructs the original symmetric power element $m$. That is, \[ \text{fill}(a, i, s') = m. \]
Sym.filter_ne_fill theorem
[DecidableEq α] (a : α) (m : Σ i : Fin (n + 1), Sym α (n - i)) (h : a ∉ m.2) : (m.2.fill a m.1).filterNe a = m
Full source
theorem filter_ne_fill
    [DecidableEq α] (a : α) (m : Σ i : Fin (n + 1), Sym α (n - i)) (h : a ∉ m.2) :
    (m.2.fill a m.1).filterNe a = m :=
  sigma_sub_ext
    (by
      rw [filterNe, ← val_eq_coe, Subtype.coe_mk, val_eq_coe, coe_fill]
      rw [filter_add, filter_eq_self.2, add_eq_left, eq_zero_iff_forall_not_mem]
      · intro b hb
        rw [mem_filter, Sym.mem_coe, mem_replicate] at hb
        exact hb.2 hb.1.2.symm
      · exact fun a ha ha' => h <| ha'.symm ▸ ha)
Inverse Property of Fill and Filter for Symmetric Powers: $\text{filterNe}(a, \text{fill}(a, i, s)) = (i, s)$ when $a \notin s$
Informal description
Let $\alpha$ be a type with decidable equality, $a \in \alpha$, and $m = (i, s)$ where $i \in \text{Fin}(n+1)$ and $s \in \text{Sym}(\alpha, n-i)$. If $a$ is not a member of $s$, then applying the operations $\text{fill}(a, i, s)$ followed by $\text{filterNe}(a)$ recovers the original pair $m$, i.e., \[ \text{filterNe}(a, \text{fill}(a, i, s)) = (i, s). \]
Sym.count_coe_fill_self_of_not_mem theorem
[DecidableEq α] {a : α} {i : Fin (n + 1)} {s : Sym α (n - i)} (hx : a ∉ s) : count a (fill a i s : Multiset α) = i
Full source
theorem count_coe_fill_self_of_not_mem [DecidableEq α] {a : α} {i : Fin (n + 1)} {s : Sym α (n - i)}
    (hx : a ∉ s) :
    count a (fill a i s : Multiset α) = i := by
  simp [coe_fill, coe_replicate, hx]
Multiplicity of Filled Element in Symmetric Power When Not Originally Present
Informal description
Let $\alpha$ be a type with decidable equality, $a \in \alpha$, $i \in \text{Fin}(n+1)$, and $s \in \text{Sym}(\alpha, n-i)$. If $a$ is not a member of $s$, then the multiplicity of $a$ in the multiset corresponding to $\text{fill}(a, i, s)$ is equal to $i$, i.e., \[ \text{count}(a, \text{fill}(a, i, s)) = i. \]
Sym.count_coe_fill_of_ne theorem
[DecidableEq α] {a x : α} {i : Fin (n + 1)} {s : Sym α (n - i)} (hx : x ≠ a) : count x (fill a i s : Multiset α) = count x s
Full source
theorem count_coe_fill_of_ne [DecidableEq α] {a x : α} {i : Fin (n + 1)} {s : Sym α (n - i)}
    (hx : x ≠ a) :
    count x (fill a i s : Multiset α) = count x s := by
  suffices x ∉ Multiset.replicate i a by simp [coe_fill, coe_replicate, this]
  simp [Multiset.mem_replicate, hx]
Multiplicity Preservation in Symmetric Power Filling for Distinct Elements: $\text{count}(x, \text{fill}(a, i, s)) = \text{count}(x, s)$ when $x \neq a$
Informal description
Let $\alpha$ be a type with decidable equality, and let $a, x \in \alpha$ be distinct elements (i.e., $x \neq a$). For any index $i \in \text{Fin}(n+1)$ and any symmetric power element $s \in \text{Sym}(\alpha, n-i)$, the multiplicity of $x$ in the multiset obtained by filling $s$ with $i$ copies of $a$ is equal to the multiplicity of $x$ in $s$. In symbols: \[ \text{count}(x, \text{fill}(a, i, s)) = \text{count}(x, s). \]
SymOptionSuccEquiv.encode definition
[DecidableEq α] (s : Sym (Option α) n.succ) : Sym (Option α) n ⊕ Sym α n.succ
Full source
/-- Function from the symmetric product over `Option` splitting on whether or not
it contains a `none`. -/
def encode [DecidableEq α] (s : Sym (Option α) n.succ) : SymSym (Option α) n ⊕ Sym α n.succ :=
  if h : none ∈ s then Sum.inl (s.erase none h)
  else
    Sum.inr
      (s.attach.map fun o =>
        o.1.get <| Option.ne_none_iff_isSome.1 <| ne_of_mem_of_not_mem o.2 h)
Encoding for symmetric powers over $\text{Option } \alpha$
Informal description
The function `SymOptionSuccEquiv.encode` maps an element $s$ of the $(n+1)$-th symmetric power of $\text{Option } \alpha$ to either: 1. An element of the $n$-th symmetric power of $\text{Option } \alpha$ if $\text{none} \in s$, obtained by erasing one occurrence of $\text{none}$ from $s$. 2. An element of the $(n+1)$-th symmetric power of $\alpha$ if $\text{none} \notin s$, obtained by extracting the values from the $\text{some}$ constructors in $s$.
SymOptionSuccEquiv.encode_of_none_mem theorem
[DecidableEq α] (s : Sym (Option α) n.succ) (h : none ∈ s) : encode s = Sum.inl (s.erase none h)
Full source
@[simp]
theorem encode_of_none_mem [DecidableEq α] (s : Sym (Option α) n.succ) (h : nonenone ∈ s) :
    encode s = Sum.inl (s.erase none h) :=
  dif_pos h
Encoding of $\operatorname{none}$-containing symmetric powers via erasure
Informal description
For a type $\alpha$ with decidable equality and an element $s$ of the $(n+1)$-th symmetric power of $\operatorname{Option} \alpha$, if $\operatorname{none}$ is a member of $s$, then the encoding of $s$ is equal to the left inclusion of the symmetric power obtained by erasing one occurrence of $\operatorname{none}$ from $s$. In symbols: $$\text{encode}(s) = \operatorname{Sum.inl}(\operatorname{erase}(s, \operatorname{none}, h))$$
SymOptionSuccEquiv.encode_of_not_none_mem theorem
[DecidableEq α] (s : Sym (Option α) n.succ) (h : ¬none ∈ s) : encode s = Sum.inr (s.attach.map fun o => o.1.get <| Option.ne_none_iff_isSome.1 <| ne_of_mem_of_not_mem o.2 h)
Full source
@[simp]
theorem encode_of_not_none_mem [DecidableEq α] (s : Sym (Option α) n.succ) (h : ¬none ∈ s) :
    encode s =
      Sum.inr
        (s.attach.map fun o =>
          o.1.get <| Option.ne_none_iff_isSome.1 <| ne_of_mem_of_not_mem o.2 h) :=
  dif_neg h
Encoding of $\operatorname{none}$-free symmetric powers via $\operatorname{some}$ extraction
Informal description
For a type $\alpha$ with decidable equality and an element $s$ of the $(n+1)$-th symmetric power of $\operatorname{Option} \alpha$, if $\operatorname{none}$ is not a member of $s$, then the encoding of $s$ is equal to the right inclusion of the symmetric power obtained by: 1. Attaching membership proofs to each element of $s$ (creating elements of $\{x \mid x \in s\}$), 2. Mapping each such element $o$ to the value inside its $\operatorname{some}$ constructor (since $o \neq \operatorname{none}$ by assumption), 3. Producing an element of $\operatorname{Sym} \alpha (n+1)$. In symbols: $$\text{encode}(s) = \operatorname{Sum.inr}\left(\operatorname{map}\left(\lambda o, \operatorname{get}(o.1)\right) (\operatorname{attach}(s))\right)$$ where the $\operatorname{get}$ operation is valid because $o.1$ must be of the form $\operatorname{some} a$ (since $o.1 \neq \operatorname{none}$).
SymOptionSuccEquiv.decode definition
: Sym (Option α) n ⊕ Sym α n.succ → Sym (Option α) n.succ
Full source
/-- Inverse of `Sym_option_succ_equiv.decode`. -/
def decode : SymSym (Option α) n ⊕ Sym α n.succSym (Option α) n.succ
  | Sum.inl s => none ::ₛ s
  | Sum.inr s => s.map Embedding.some
Decoding function for symmetric powers of Option types
Informal description
The function takes a sum type consisting of either an element of the $n$-th symmetric power of $\operatorname{Option} \alpha$ or an element of the $(n+1)$-th symmetric power of $\alpha$, and returns an element of the $(n+1)$-th symmetric power of $\operatorname{Option} \alpha$. Specifically: - If the input is $\operatorname{Sum.inl} s$ where $s \in \operatorname{Sym} (\operatorname{Option} \alpha) n$, the result is obtained by inserting $\operatorname{none}$ into $s$. - If the input is $\operatorname{Sum.inr} s$ where $s \in \operatorname{Sym} \alpha (n+1)$, the result is obtained by applying the embedding $\operatorname{some}$ to each element of $s$.
SymOptionSuccEquiv.decode_inl theorem
(s : Sym (Option α) n) : decode (Sum.inl s) = none ::ₛ s
Full source
@[simp]
theorem decode_inl (s : Sym (Option α) n) : decode (Sum.inl s) = nonenone ::ₛ s :=
  rfl
Decoding of Left Inclusion in Symmetric Power Equals Insertion of None
Informal description
For any element $s$ of the $n$-th symmetric power of $\operatorname{Option} \alpha$, the decoding function applied to $\operatorname{Sum.inl} s$ (the left inclusion of $s$) equals the insertion of $\operatorname{none}$ into $s$, denoted as $\operatorname{none} ::ₛ s$.
SymOptionSuccEquiv.decode_inr theorem
(s : Sym α n.succ) : decode (Sum.inr s) = s.map Embedding.some
Full source
@[simp]
theorem decode_inr (s : Sym α n.succ) : decode (Sum.inr s) = s.map Embedding.some :=
  rfl
Decoding of Right Inclusion in Symmetric Power Equals Image under Some Embedding
Informal description
For any element $s$ in the $(n+1)$-th symmetric power of $\alpha$, the decoding function applied to the right inclusion $\operatorname{Sum.inr} s$ equals the image of $s$ under the map induced by the embedding $\operatorname{some} : \alpha \hookrightarrow \operatorname{Option} \alpha$. That is, $\operatorname{decode}(\operatorname{Sum.inr} s) = \operatorname{Sym.map} \operatorname{some} s$.
SymOptionSuccEquiv.decode_encode theorem
[DecidableEq α] (s : Sym (Option α) n.succ) : decode (encode s) = s
Full source
@[simp]
theorem decode_encode [DecidableEq α] (s : Sym (Option α) n.succ) : decode (encode s) = s := by
  by_cases h : none ∈ s
  · simp [h]
  · simp only [decode, h, not_false_iff, encode_of_not_none_mem, Embedding.some_apply, map_map,
      comp_apply, Option.some_get]
    convert s.attach_map_coe
Bijectivity of Symmetric Power Encoding/Decoding: $\operatorname{decode} \circ \operatorname{encode} = \operatorname{id}$
Informal description
For a type $\alpha$ with decidable equality and any element $s$ in the $(n+1)$-th symmetric power of $\operatorname{Option} \alpha$, the composition of the encoding and decoding functions returns $s$ unchanged, i.e., $\operatorname{decode}(\operatorname{encode}(s)) = s$.
SymOptionSuccEquiv.encode_decode theorem
[DecidableEq α] (s : Sym (Option α) n ⊕ Sym α n.succ) : encode (decode s) = s
Full source
@[simp]
theorem encode_decode [DecidableEq α] (s : SymSym (Option α) n ⊕ Sym α n.succ) :
    encode (decode s) = s := by
  obtain s | s := s
  · simp
  · unfold SymOptionSuccEquiv.encode
    split_ifs with h
    · obtain ⟨a, _, ha⟩ := Multiset.mem_map.mp h
      exact Option.some_ne_none _ ha
    · refine congr_arg Sum.inr ?_
      refine map_injective (Option.some_injective _) _ ?_
      refine Eq.trans ?_ (.trans (SymOptionSuccEquiv.decode (Sum.inr s)).attach_map_coe ?_) <;> simp
Encoding-Decoding Identity for Symmetric Powers of Option Types
Informal description
For any type $\alpha$ with decidable equality and any natural number $n$, the composition of the encoding and decoding functions for symmetric powers of $\operatorname{Option} \alpha$ is the identity. That is, for any element $s$ in the sum type $\operatorname{Sym} (\operatorname{Option} \alpha) n \oplus \operatorname{Sym} \alpha (n+1)$, we have $\operatorname{encode}(\operatorname{decode}(s)) = s$.
symOptionSuccEquiv definition
[DecidableEq α] : Sym (Option α) n.succ ≃ Sym (Option α) n ⊕ Sym α n.succ
Full source
/-- The symmetric product over `Option` is a disjoint union over simpler symmetric products. -/
--@[simps]
def symOptionSuccEquiv [DecidableEq α] :
    SymSym (Option α) n.succ ≃ Sym (Option α) n ⊕ Sym α n.succ where
  toFun := SymOptionSuccEquiv.encode
  invFun := SymOptionSuccEquiv.decode
  left_inv := SymOptionSuccEquiv.decode_encode
  right_inv := SymOptionSuccEquiv.encode_decode
Bijection between symmetric powers of $\operatorname{Option} \alpha$ and their disjoint union
Informal description
For a type $\alpha$ with decidable equality and a natural number $n$, there is a bijection between the $(n+1)$-th symmetric power of $\operatorname{Option} \alpha$ and the disjoint union of the $n$-th symmetric power of $\operatorname{Option} \alpha$ and the $(n+1)$-th symmetric power of $\alpha$. The bijection is constructed as follows: - The forward map $\operatorname{encode}$ splits an element of $\operatorname{Sym} (\operatorname{Option} \alpha) (n+1)$ into either: - An element of $\operatorname{Sym} (\operatorname{Option} \alpha) n$ if $\operatorname{none}$ is present (by removing one $\operatorname{none}$), or - An element of $\operatorname{Sym} \alpha (n+1)$ if $\operatorname{none}$ is absent (by extracting values from $\operatorname{some}$). - The inverse map $\operatorname{decode}$ combines these back by either inserting $\operatorname{none}$ or applying $\operatorname{some}$ to each element.