Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Lean/Mathlib/Mathlib/Order/UpperLower/     Datei vom 15.10.2026 mit Größe 7 kB image not shown  

Quelle  Basic.lean   Sprache: Lean

 

/-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Yury Kudryashov
-/

module

public import Mathlib.Algebra.BigOperators.Group.List.Defs
public import Mathlib.Algebra.Group.Action.Defs
public import Mathlib.Algebra.Group.Basic
public import Mathlib.Algebra.Group.Equiv.Defs
public import Mathlib.Algebra.Group.Nat.Defs
public import Mathlib.Algebra.Group.Units.Defs
public import Mathlib.Data.List.Basic
public import Mathlib.Util.CompileInductive

/-!
# Free monoid over a given alphabet

## Main definitions

* `FreeMonoid α`: free monoid over alphabet `α`; defined as a one-field structure around `List α`
  with multiplication given by `(++)`.
* `FreeMonoid.of`: embedding `α → FreeMonoid α` sending each element `x` to `[x]`;
* `FreeMonoid.lift`: natural equivalence between `α → M` and `FreeMonoid α →* M`
* `FreeMonoid.map`: embedding of `α → β` into `FreeMonoid α →* FreeMonoid β` given by `List.map`.
-/


@[expose] public section


variable {α : Type*} {β : Type*} {γ : Type*} {M : Type*} [Monoid M] {N : Type*} [Monoid N]

/--
If `α` is a type, then `FreeMonoid α` is the free monoid generated by `α`.
This is a monoid equipped with a function `FreeMonoid.of : α → FreeMonoid α` which has
the following universal property: if `M` is any monoid, and `f : α → M` is any function,
then this function is the composite of `FreeMonoid.of` and a unique monoid homomorphism
`FreeMonoid.lift f : FreeMonoid α →* M`.

A typical element of `FreeMonoid α` is a formal product of elements of `α`.
For example if `x` and `y` are terms of type `α` then `x * y * y * x` is a
"typical" element of `FreeMonoid α`. In particular if `α` is empty
then `FreeMonoid α` is isomorphic to the trivial monoid, and if `α` has one term
then `FreeMonoid α` is isomorphic to `Multiplicative ℕ`.
If `α` has two or more terms then `FreeMonoid α` is not commutative.
One can think of `FreeMonoid α` as the type of lists of `α`, with multiplication
given by concatenation.
-/

@[ext]
structure FreeMonoid (α : Type*) where
  /-- Convert a `List α` to a `FreeMonoid α`. -/
  ofList ::
  /-- The underlying list -/
  toList : List α

/-- If `α` is a type, then `FreeAddMonoid α` is the free additive monoid generated by `α`.
This is a monoid equipped with a function `FreeAddMonoid.of : α → FreeAddMonoid α` which has
the following universal property: if `M` is any monoid, and `f : α → M` is any function,
then this function is the composite of `FreeAddMonoid.of` and a unique monoid homomorphism
`FreeAddMonoid.lift f : FreeAddMonoid α →+ M`.

A typical element of `FreeAddMonoid α` is a formal sum of elements of `α`.
For example if `x` and `y` are terms of type `α` then `x + y + y + x` is a
"typical" element of `FreeAddMonoid α`. In particular if `α` is empty
then `FreeAddMonoid α` is isomorphic to the trivial monoid, and if `α` has one term
then `FreeAddMonoid α` is isomorphic to `ℕ`.
If `α` has two or more terms then `FreeAddMonoid α` is not commutative.
One can think of `FreeAddMonoid α` as the type of lists of `α`, with addition
given by concatenation. -/

@[ext]
structure FreeAddMonoid (α : Type*) where
  /-- Convert a `List α` to a `FreeAddMonoid α`. -/
  ofList ::
  /-- The underlying list -/
  toList : List α

attribute [to_additive existing] FreeMonoid

namespace FreeMonoid

@[to_additive (attr := simp)]
theorem toList_ofList (l : List α) : toList (ofList l) = l := rfl

@[to_additive (attr := simp)]
theorem ofList_toList (xs : FreeMonoid α) : ofList (toList xs) = xs := rfl

@[to_additive, deprecated (since := "2026-10-23")] alias toList_symm := ofList_toList
@[to_additive, deprecated (since := "2026-10-23")] alias ofList_symm := toList_ofList

@[to_additive (attr := simp)]
theorem toList_comp_ofList : @toList α ∘ ofList = id := rfl

@[to_additive (attr := simp)]
theorem ofList_comp_toList : @ofList α ∘ toList = id := rfl

@[to_additive]
instance : CancelMonoid (FreeMonoid α) where
  one := ofList []
  mul x y := ofList (toList x ++ toList y)
  mul_one x := by ext1; exact List.append_nil _
  one_mul x := by ext1; exact List.nil_append _
  mul_assoc x y z := by ext1; exact List.append_assoc ..
  mul_left_cancel _ _ _ e := by rw [FreeMonoid.ext_iff] at *; exact List.append_cancel_left e
  mul_right_cancel _ _ _ e := by rw [FreeMonoid.ext_iff] at *; exact List.append_cancel_right e

@[to_additive]
instance : Inhabited (FreeMonoid α) := ⟨1⟩

@[to_additive]
instance [IsEmpty α] : Unique (FreeMonoid α) where
  uniq a := by ext1; exact List.uniqueOfIsEmpty.uniq a.toList

@[to_additive (attr := simp)]
theorem toList_one : toList (1 : FreeMonoid α) = [] := rfl

@[to_additive (attr := simp)]
theorem ofList_nil : ofList ([] : List α) = 1 := rfl

@[to_additive (attr := simp)]
theorem toList_mul (xs ys : FreeMonoid α) : toList (xs * ys) = toList xs ++ toList ys := rfl

@[to_additive (attr := simp)]
theorem ofList_append (xs ys : List α) : ofList (xs ++ ys) = ofList xs * ofList ys := rfl

@[to_additive (attr := simp)]
theorem toList_prod (xs : List (FreeMonoid α)) : toList xs.prod = (xs.map toList).flatten := by
  induction xs <;> simp [*]

@[to_additive (attr := simp)]
theorem ofList_flatten (xs : List (List α)) : ofList xs.flatten = (xs.map ofList).prod := by
  ext1; simp

/-- Embeds an element of `α` into `FreeMonoid α` as a singleton list. -/
@[to_additive /-- Embeds an element of `α` into `FreeAddMonoid α` as a singleton list. -/]
def of (x : α) : FreeMonoid α := ofList [x]

@[to_additive (attr := simp)]
theorem toList_of (x : α) : toList (of x) = [x] := rfl

@[to_additive]
theorem ofList_singleton (x : α) : ofList [x] = of x := rfl

@[to_additive (attr := simp)]
theorem ofList_cons (x : α) (xs : List α) : ofList (x :: xs) = of x * ofList xs := rfl

@[to_additive]
theorem toList_of_mul (x : α) (xs : FreeMonoid α) : toList (of x * xs) = x :: toList xs := rfl

@[to_additive]
theorem of_injective : Function.Injective (@of α) := fun x y e ↦ by
  rwa [FreeMonoid.ext_iff, toList_of, toList_of, List.singleton_inj] at e

@[to_additive]
lemma «forall» {p : FreeMonoid α → Prop} : (∀ x, p x) ↔ ∀ l, p (ofList l) :=
  ⟨fun h l ↦ h ⟨l⟩, fun a x ↦ a x.toList⟩

@[to_additive]
lemma «exists» {p : FreeMonoid α → Prop} : (∃ x, p x) ↔ ∃ l, p (ofList l) :=
  ⟨fun h ↦ h.imp' _ fun _ ↦ id, fun h ↦ h.imp' _ fun _ ↦ id⟩

/-- The natural equivalence between `FreeMonoid α` and `List α`. -/
@[to_additive /-- The natural equivalence between `FreeAddMonoid α` and `List α`. -/]
def toListEquiv : FreeMonoid α ≃ List α where
  toFun := toList
  invFun := ofList

/-! ### Length -/

section Length
variable {a : FreeMonoid α}

/-- The length of a free monoid element: 1.length = 0 and (a * b).length = a.length + b.length -/
@[to_additive (attr := deprecated "use `a.toList.length` instead" (since := "2026-10-23"))
/-- The length of a free additive monoid element: 0.length = 0 and
(a + b).length = a.length + b.length -/
]
def length (a : FreeMonoid α) : ℕ := a.toList.length

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_nil (since := "2026-10-23"))]
theorem length_one : length (1 : FreeMonoid α) = 0 := rfl

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_eq_zero_iff (since := "2026-10-23"))]
theorem length_eq_zero : length a = 0 ↔ a = 1 := by
  simp only [FreeMonoid.ext_iff]; exact List.length_eq_zero_iff

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_singleton (since := "2026-10-23"))]
theorem length_of (m : α) : length (of m) = 1 := rfl

set_option linter.deprecated false in
@[to_additive (attr := deprecated "no replacement" (since := "2026-10-23"))]
theorem length_surjective [Nonempty α] : (@length α).Surjective :=
  ‹Nonempty α›.elim fun a n => ⟨FreeMonoid.ofList (List.replicate n a), by simp [length]⟩

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_eq_one_iff (since := "2026-10-23"))
FreeAddMonoid.length_eq_one]
theorem length_eq_one : length a = 1 ↔ ∃ m, a = of m := by
  simp only [FreeMonoid.ext_iff]; exact List.length_eq_one_iff

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_eq_two (since := "2026-10-23"))]
theorem length_eq_two {v : FreeMonoid α} : v.length = 2 ↔ ∃ a b, v = of a * of b := by
  simp only [FreeMonoid.ext_iff]; exact List.length_eq_two

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_eq_three (since := "2026-10-23"))]
theorem length_eq_three {v : FreeMonoid α} :
    v.length = 3 ↔ ∃ (a b c : α), v = of a * of b * of c := by
  simp only [FreeMonoid.ext_iff]; exact List.length_eq_three

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_eq_four (since := "2026-10-23"))]
theorem length_eq_four {v : FreeMonoid α} :
    v.length = 4 ↔ ∃ (a b c d : α), v = of a * of b * of c * of d := by
  simp only [FreeMonoid.ext_iff]; exact List.length_eq_four

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_append (since := "2026-10-23"))]
theorem length_mul (a b : FreeMonoid α) : (a * b).length = a.length + b.length :=
  List.length_append

@[to_additive (attr := simp)]
theorem of_ne_one (a : α) : of a ≠ 1 := fun h ↦ by simpa using congr(($h).toList.length)

@[to_additive (attr := simp)]
theorem one_ne_of (a : α) : 1 ≠ of a := of_ne_one _ |>.symm

end Length

section Mem
variable {m : α}

/-- Membership in a free monoid element -/
@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))
/-- Membership in a free additive monoid element -/]
def mem (a : FreeMonoid α) (m : α) := m ∈ toList a

@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))]
instance : Membership α (FreeMonoid α) := ⟨fun a m ↦ m ∈ a.toList⟩

@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))]
theorem notMem_one : m ∉ (1 : FreeMonoid α) := List.not_mem_nil

@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))]
theorem mem_of {n : α} : m ∈ of n ↔ m = n := List.mem_singleton

@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))]
theorem mem_of_self : m ∈ of m := List.mem_singleton_self _

@[to_additive (attr := deprecated "use `m ∈ a.toList` instead" (since := "2026-10-23"))]
theorem mem_mul {a b : FreeMonoid α} : m ∈ a * b ↔ m ∈ a ∨ m ∈ b := List.mem_append

end Mem

/-- Recursor for `FreeMonoid` using `1` and `FreeMonoid.of x * xs`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator)
/-- Recursor for `FreeAddMonoid` using `0` and `FreeAddMonoid.of x + xs`. -/]
def mulRecOn {motive : FreeMonoid α → Sort*} (xs : FreeMonoid α) (one : motive 1)
    (of_mul : ∀ x xs, motive xs → motive (of x * xs)) : motive xs := by
  cases xs with | _ xs => exact List.recOn xs one fun x xs ↦ of_mul x ⟨xs⟩

@[to_additive (attr := simp)]
theorem mulRecOn_one {motive : FreeMonoid α → Sort*} (one : motive 1)
    (of_mul : ∀ x xs, motive xs → motive (of x * xs)) :
    @mulRecOn α motive 1 one of_mul = one := rfl

@[to_additive (attr := simp)]
theorem mulRecOn_of_mul {motive : FreeMonoid α → Sort*} (x : α) (xs : FreeMonoid α) (one : motive 1)
    (of_mul : ∀ x xs, motive xs → motive (of x * xs)) :
    @mulRecOn α motive (of x * xs) one of_mul = of_mul x xs (mulRecOn xs one of_mul) := rfl

@[to_additive, deprecated (since := "2026-10-23")] alias recOn_one := mulRecOn_one
@[to_additive, deprecated (since := "2026-10-23")] alias recOn_of_mul := mulRecOn_of_mul

/-! ### Induction -/

section InductionPrinciples

/-- An induction principle on free monoids, with cases for `1`, `FreeMonoid.of` and `*`. -/
@[to_additive (attr := elab_as_elim, induction_eliminator) /-- An induction principle on
free additive monoids, with cases for `0`, `FreeAddMonoid.of` and `+`. -/
]
protected theorem inductionOn {motive : FreeMonoid α → Prop} (z : FreeMonoid α) (one : motive 1)
    (of : ∀ (x : α), motive (FreeMonoid.of x))
    (mul : ∀ (x y : FreeMonoid α), motive x → motive y → motive (x * y)) :
    motive z :=
  mulRecOn z one fun x xs ih => mul (.of x) xs (of x) ih

/-- An induction principle for free monoids which mirrors induction on lists, with cases analogous
to the empty list and cons. -/

@[to_additive (attr := elab_as_elim) /-- An induction principle for free additive monoids which
mirrors induction on lists, with cases analogous to the empty list and cons. -/
]
protected theorem inductionOn' {motive : FreeMonoid α → Prop} (a : FreeMonoid α)
    (one : motive (1 : FreeMonoid α)) (of_mul : ∀ b a, motive a → motive (of b * a)) : motive a :=
  mulRecOn a one of_mul

end InductionPrinciples

/-- A version of `List.casesOn` for `FreeMonoid` using `1` and `FreeMonoid.of x * xs` instead of
`[]` and `x :: xs`. -/

@[to_additive (attr := elab_as_elim, cases_eliminator)
/-- A version of `List.casesOn` for `FreeAddMonoid` using `0` and `FreeAddMonoid.of x + xs`
instead of `[]` and `x :: xs`. -/
]
def mulCasesOn {motive : FreeMonoid α → Sort*} (xs : FreeMonoid α) (one : motive 1)
    (of_mul : ∀ x xs, motive (of x * xs)) : motive xs :=
  mulRecOn xs one fun x xs _ ↦ of_mul x xs

@[to_additive (attr := simp)]
theorem mulCasesOn_one {motive : FreeMonoid α → Sort*} (one : motive 1)
    (of_mul : ∀ x xs, motive (of x * xs)) :
    @mulCasesOn α motive 1 one of_mul = one := by simp [mulCasesOn]

@[to_additive (attr := simp)]
theorem mulCasesOn_of_mul {motive : FreeMonoid α → Sort*} (x : α) (xs : FreeMonoid α)
    (one : motive 1) (of_mul : ∀ x xs, motive (of x * xs)) :
    @mulCasesOn α motive (of x * xs) one of_mul = of_mul x xs := by simp [mulCasesOn]

@[to_additive, deprecated (since := "2026-10-23")] alias casesOn_one := mulCasesOn_one
@[to_additive, deprecated (since := "2026-10-23")] alias casesOn_of_mul := mulCasesOn_of_mul

@[to_additive (attr := ext)]
theorem hom_eq ⦃f g : FreeMonoid α →* M⦄ (h : ∀ x, f (of x) = g (of x)) : f = g :=
  MonoidHom.ext fun l ↦ mulRecOn l (f.map_one.trans g.map_one.symm)
    (fun x xs hxs ↦ by simp only [h, hxs, map_mul])

/-- A variant of `List.prod` that has `[x].prod = x` true definitionally.
The purpose is to make `FreeMonoid.lift_eval_of` true by `rfl`. -/

@[to_additive /-- A variant of `List.sum` that has `[x].sum = x` true definitionally.
The purpose is to make `FreeAddMonoid.lift_eval_of` true by `rfl`. -/
]
def prodAux {M} [Monoid M] : List M → M
  | [] => 1
  | (x :: xs) => List.foldl (· * ·) x xs

@[to_additive]
lemma prodAux_eq : ∀ l : List M, FreeMonoid.prodAux l = l.prod
  | [] => rfl
  | (_ :: xs) => by simp [prodAux, List.prod_eq_foldl]

/-- Equivalence between maps `α → M` and monoid homomorphisms `FreeMonoid α →* M`. -/
@[to_additive /-- Equivalence between maps `α → A` and additive monoid homomorphisms
`FreeAddMonoid α →+ A`. -/
]
def lift : (α → M) ≃ (FreeMonoid α →* M) where
  toFun f :=
  { toFun := fun l ↦ prodAux ((toList l).map f)
    map_one' := rfl
    map_mul' := fun _ _ ↦ by simp only [prodAux_eq, toList_mul, List.map_append, List.prod_append] }
  invFun f x := f (of x)

@[to_additive (attr := simp)]
theorem lift_ofList (f : α → M) (l : List α) : lift f (ofList l) = (l.map f).prod :=
  prodAux_eq _

@[to_additive (attr := simp)]
theorem lift_symm_apply (f : FreeMonoid α →* M) : lift.symm f = f ∘ of := rfl

@[to_additive]
theorem lift_apply (f : α → M) (l : FreeMonoid α) : lift f l = ((toList l).map f).prod :=
  prodAux_eq _

@[to_additive]
theorem lift_comp_of (f : α → M) : lift f ∘ of = f := rfl

@[to_additive (attr := simp)]
theorem lift_eval_of (f : α → M) (x : α) : lift f (of x) = f x := rfl

@[to_additive (attr := simp)]
theorem lift_restrict (f : FreeMonoid α →* M) : lift (f ∘ of) = f := lift.apply_symm_apply f

@[to_additive]
theorem comp_lift (g : M →* N) (f : α → M) : g.comp (lift f) = lift (g ∘ f) := by
  ext
  simp

@[to_additive]
theorem hom_map_lift (g : M →* N) (f : α → M) (x : FreeMonoid α) : g (lift f x) = lift (g ∘ f) x :=
  DFunLike.ext_iff.1 (comp_lift g f) x

/-- Define a multiplicative action of `FreeMonoid α` on `β`. -/
@[to_additive (attr := instance_reducible)
/-- Define an additive action of `FreeAddMonoid α` on `β`. -/]
def mkMulAction (f : α → β → β) : MulAction (FreeMonoid α) β where
  smul l b := l.toList.foldr f b
  one_smul _ := rfl
  mul_smul _ _ _ := List.foldr_append

@[to_additive]
theorem smul_def (f : α → β → β) (l : FreeMonoid α) (b : β) :
    haveI := mkMulAction f
    l • b = l.toList.foldr f b := rfl

@[to_additive]
theorem ofList_smul (f : α → β → β) (l : List α) (b : β) :
    haveI := mkMulAction f
    ofList l • b = l.foldr f b := rfl

@[to_additive (attr := simp)]
theorem of_smul (f : α → β → β) (x : α) (y : β) :
    (haveI := mkMulAction f
    of x • y) = f x y := rfl

/-! ### map -/

section Map
variable {f : α → β} {a b : FreeMonoid α}
/-- The unique monoid homomorphism `FreeMonoid α →* FreeMonoid β` that sends
each `of x` to `of (f x)`. -/

@[to_additive /-- The unique additive monoid homomorphism `FreeAddMonoid α →+ FreeAddMonoid β`
that sends each `of x` to `of (f x)`. -/
]
def map (f : α → β) : FreeMonoid α →* FreeMonoid β where
  toFun l := ofList <| l.toList.map f
  map_one' := rfl
  map_mul' _ _ := by ext1; exact List.map_append

@[to_additive (attr := simp)]
theorem map_of (f : α → β) (x : α) : map f (of x) = of (f x) := rfl

@[to_additive]
theorem mem_map {m : β} : m ∈ map f a ↔ ∃ n ∈ a, f n = m := List.mem_map

@[to_additive]
theorem map_map {α₁ : Type*} {g : α₁ → α} {x : FreeMonoid α₁} :
    map f (map g x) = map (f ∘ g) x := by
  unfold map
  simp only [MonoidHom.coe_mk, OneHom.coe_mk, List.map_map]

@[to_additive (attr := simp)]
theorem toList_map (f : α → β) (xs : FreeMonoid α) : toList (map f xs) = xs.toList.map f := rfl

@[to_additive]
theorem ofList_map (f : α → β) (xs : List α) : ofList (xs.map f) = map f (ofList xs) := rfl

@[to_additive]
theorem lift_of_comp_eq_map (f : α → β) : (lift fun x ↦ of (f x)) = map f := hom_eq fun _ ↦ rfl

@[to_additive]
theorem map_comp (g : β → γ) (f : α → β) : map (g ∘ f) = (map g).comp (map f) := hom_eq fun _ ↦ rfl

@[to_additive (attr := simp)]
theorem map_id : map (@id α) = MonoidHom.id (FreeMonoid α) := hom_eq fun _ ↦ rfl

@[to_additive (attr := simp)]
theorem map_symm_apply_map_eq {x : FreeMonoid α} (e : α ≃ β) :
    (map ⇑e.symm) ((map ⇑e) x) = x := by simp [map_map]

@[to_additive (attr := simp)]
theorem map_apply_map_symm_eq {x : FreeMonoid β} (e : α ≃ β) :
    (map ⇑e) ((map ⇑e.symm) x) = x := by simp [map_map]

/-- The only invertible element of the free monoid is 1; this instance enables `units_eq_one`. -/
@[to_additive]
instance : Unique (FreeMonoid α)ˣ where
  uniq u := Units.ext <| FreeMonoid.ext <|
    have : toList u.val ++ toList u.inv = [] := congr(toList $u.val_inv)
    (List.append_eq_nil_iff.mp this).1

@[to_additive (attr := simp)]
theorem map_surjective {f : α → β} : Function.Surjective (map f) ↔ Function.Surjective f := by
  constructor <;> intro fs d
  · rcases fs (of d) with ⟨b, hb⟩
    induction b using FreeMonoid.inductionOn' with
    | one => simpa using congr(($hb).toList.length)
    | of_mul head x hx =>
      simp only [show x = 1 by
        simpa [← toList_one, ← FreeMonoid.ext_iff] using congr(($hb).toList.length)] at hb
      exact ⟨head, of_injective hb⟩
  induction d using FreeMonoid.inductionOn' with
  | one => use 1; rfl
  | of_mul head tail ih =>
    obtain ⟨a, rfl⟩:= fs head
    obtain ⟨b, rfl⟩ := ih
    exact ⟨of a * b, rfl⟩

end Map

/-! ### reverse -/

section Reverse
/-- Reverse the symbols in a `FreeMonoid α`. -/
@[to_additive (attr := deprecated "use `star` in `Mathlib.Algebra.Star.Free` instead"
(since := "2026-10-23"))
/-- Reverses the symbols in a `FreeAddMonoid α`. -/]
def reverse (x : FreeMonoid α) : FreeMonoid α := ⟨x.toList.reverse⟩

set_option linter.deprecated false in
@[to_additive (attr := deprecated "use `star_of` in `Mathlib.Algebra.Star.Free` instead"
(since := "2026-10-23"))]
theorem reverse_of (a : α) : reverse (of a) = of a := rfl

set_option linter.deprecated false in
@[to_additive (attr := deprecated "use `star_mul` instead" (since := "2026-10-23"))]
theorem reverse_mul {a b : FreeMonoid α} : reverse (a * b) = reverse b * reverse a := by
  ext1; exact List.reverse_append

set_option linter.deprecated false in
@[to_additive (attr := deprecated "use `star_star` instead" (since := "2026-10-23"))]
theorem reverse_reverse {a : FreeMonoid α} : reverse (reverse a) = a := by
  ext1; apply List.reverse_reverse

set_option linter.deprecated false in
@[to_additive (attr := deprecated List.length_reverse (since := "2026-10-23"))]
theorem length_reverse {a : FreeMonoid α} : a.reverse.length = a.length :=
  List.length_reverse

end Reverse

section IsomorphicTypes

variable {α β : Type*}

/-- Free monoids over isomorphic types are isomorphic. -/
@[to_additive /-- Free additive monoids over isomorphic types are isomorphic. -/]
def freeMonoidCongr (e : α ≃ β) : FreeMonoid α ≃* FreeMonoid β where
  toFun := FreeMonoid.map ⇑e
  invFun := FreeMonoid.map ⇑e.symm
  left_inv _ := map_symm_apply_map_eq e
  right_inv _ := map_apply_map_symm_eq e
  map_mul' := by simp [map_mul]

@[to_additive (attr := simp)]
theorem freeMonoidCongr_of (e : α ≃ β) (a : α) : freeMonoidCongr e (of a) = of (e a) := rfl

@[to_additive (attr := simp)]
lemma symm_freeMonoidCongr (e : α ≃ β) : (freeMonoidCongr e).symm = freeMonoidCongr e.symm := rfl

@[to_additive (attr := deprecated freeMonoidCongr_of +typeChanged (since := "2026-10-21"))]
theorem freeMonoidCongr_symm_of (e : α ≃ β) (b : β) :
    freeMonoidCongr e.symm (of b) = of (e.symm b) := by simp

end IsomorphicTypes

end FreeMonoid

Messung
CHZG
9110010096

¤ Dauer der Verarbeitung: 0.76 Sekunden  ¤

*© Formatika GbR, Deutschland