Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Field.Defs import Mathlib.Algebra.GroupWithZero.Invertible import Mathlib.Data.Sigma.Basic import Mathlib.Algebra.Ring.Nat import Mathlib.Data.Int.Cast.Basic import Qq.MetaM /-! ## The `Result` type for `norm_num` We set up predicates `IsNat`, `IsInt`, and `IsRat`, stating that an element of a ring is equal to the "normal form" of a natural number, integer, or rational number coerced into that ring. We then define `Result e`, which contains a proof that a typed expression `e : Q($Ξ±)` is equal to the coercion of an explicit natural number, integer, or rational number, or is either `true` or `false`. -/ universe u variable {Ξ± : Type u} open Lean open Lean.Meta Qq Lean.Elab Term namespace Mathlib namespace Meta.NormNum variable {u : Level} /-- A shortcut (non)instance for `AddMonoidWithOne β„•` to shrink generated proofs. -/ def instAddMonoidWithOneNat : AddMonoidWithOne β„• := inferInstance /-- A shortcut (non)instance for `AddMonoidWithOne Ξ±` from `Ring Ξ±` to shrink generated proofs. -/ def instAddMonoidWithOne {Ξ± : Type u} [Ring Ξ±] : AddMonoidWithOne Ξ± := inferInstance /-- Helper function to synthesize a typed `AddMonoidWithOne Ξ±` expression. -/ def inferAddMonoidWithOne (Ξ± : Q(Type u)) : MetaM Q(AddMonoidWithOne $Ξ±) := return ← synthInstanceQ q(AddMonoidWithOne $Ξ±) <|> throwError "not an AddMonoidWithOne" /-- Helper function to synthesize a typed `Semiring Ξ±` expression. -/ def inferSemiring (Ξ± : Q(Type u)) : MetaM Q(Semiring $Ξ±) := return ← synthInstanceQ q(Semiring $Ξ±) <|> throwError "not a semiring" /-- Helper function to synthesize a typed `Ring Ξ±` expression. -/ def inferRing (Ξ± : Q(Type u)) : MetaM Q(Ring $Ξ±) := return ← synthInstanceQ q(Ring $Ξ±) <|> throwError "not a ring" /-- Represent an integer as a "raw" typed expression. This uses `.lit (.natVal n)` internally to represent a natural number, rather than the preferred `OfNat.ofNat` form. We use this internally to avoid unnecessary typeclass searches. This function is the inverse of `Expr.intLit!`. -/ def mkRawIntLit (n : β„€) : Q(β„€) := let lit : Q(β„•) := mkRawNatLit n.natAbs if 0 ≀ n then q(.ofNat $lit) else q(.negOfNat $lit) /-- Represent an integer as a "raw" typed expression. This `.lit (.natVal n)` internally to represent a natural number, rather than the preferred `OfNat.ofNat` form. We use this internally to avoid unnecessary typeclass searches. -/ def mkRawRatLit (q : β„š) : Q(β„š) := let nlit : Q(β„€) := mkRawIntLit q.num let dlit : Q(β„•) := mkRawNatLit q.den q(mkRat $nlit $dlit) /-- Extract the raw natlit representing the absolute value of a raw integer literal (of the type produced by `Mathlib.Meta.NormNum.mkRawIntLit`) along with an equality proof. -/ def rawIntLitNatAbs (n : Q(β„€)) : (m : Q(β„•)) Γ— Q(Int.natAbs $n = $m) := if n.isAppOfArity ``Int.ofNat 1 then have m : Q(β„•) := n.appArg! ⟨m, show Q(Int.natAbs (Int.ofNat $m) = $m) from q(Int.natAbs_natCast $m)⟩ else if n.isAppOfArity ``Int.negOfNat 1 then have m : Q(β„•) := n.appArg! ⟨m, show Q(Int.natAbs (Int.negOfNat $m) = $m) from q(Int.natAbs_neg $m)⟩ else panic! "not a raw integer literal" /-- Constructs an `ofNat` application `a'` with the canonical instance, together with a proof that the instance is equal to the result of `Nat.cast` on the given `AddMonoidWithOne` instance. This function is performance-critical, as many higher level tactics have to construct numerals. So rather than using typeclass search we hardcode the (relatively small) set of solutions to the typeclass problem. -/ def mkOfNat (Ξ± : Q(Type u)) (_sΞ± : Q(AddMonoidWithOne $Ξ±)) (lit : Q(β„•)) : MetaM ((a' : Q($Ξ±)) Γ— Q($lit = $a')) := do if Ξ±.isConstOf ``Nat then let a' : Q(β„•) := q(OfNat.ofNat $lit : β„•) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else if Ξ±.isConstOf ``Int then let a' : Q(β„€) := q(OfNat.ofNat $lit : β„€) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else if Ξ±.isConstOf ``Rat then let a' : Q(β„š) := q(OfNat.ofNat $lit : β„š) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ else let some n := lit.rawNatLit? | failure match n with | 0 => pure ⟨q(0 : $Ξ±), (q(Nat.cast_zero (R := $Ξ±)) : Expr)⟩ | 1 => pure ⟨q(1 : $Ξ±), (q(Nat.cast_one (R := $Ξ±)) : Expr)⟩ | k+2 => let k : Q(β„•) := mkRawNatLit k let _x : Q(Nat.AtLeastTwo $lit) := (q(instNatAtLeastTwo (n := $k)) : Expr) let a' : Q($Ξ±) := q(OfNat.ofNat $lit) pure ⟨a', (q(Eq.refl $a') : Expr)⟩ /-- Assert that an element of a semiring is equal to the coercion of some natural number. -/ structure IsNat {Ξ± : Type u} [AddMonoidWithOne Ξ±] (a : Ξ±) (n : β„•) : Prop where /-- The element is equal to the coercion of the natural number. -/ out : a = n theorem IsNat.raw_refl (n : β„•) : IsNat n n := ⟨rfl⟩ /-- A "raw nat cast" is an expression of the form `(Nat.rawCast lit : Ξ±)` where `lit` is a raw natural number literal. These expressions are used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `Ξ±`. -/ @[simp] def _root_.Nat.rawCast {Ξ± : Type u} [AddMonoidWithOne Ξ±] (n : β„•) : Ξ± := n theorem IsNat.to_eq {Ξ± : Type u} [AddMonoidWithOne Ξ±] {n} : {a a' : Ξ±} β†’ IsNat a n β†’ n = a' β†’ a = a' | _, _, ⟨rfl⟩, rfl => rfl theorem IsNat.to_raw_eq {a : Ξ±} {n : β„•} [AddMonoidWithOne Ξ±] : IsNat (a : Ξ±) n β†’ a = n.rawCast | ⟨e⟩ => e theorem IsNat.of_raw (Ξ±) [AddMonoidWithOne Ξ±] (n : β„•) : IsNat (n.rawCast : Ξ±) n := ⟨rfl⟩ @[elab_as_elim] theorem isNat.natElim {p : β„• β†’ Prop} : {n : β„•} β†’ {n' : β„•} β†’ IsNat n n' β†’ p n' β†’ p n | _, _, ⟨rfl⟩, h => h /-- Assert that an element of a ring is equal to the coercion of some integer. -/ structure IsInt [Ring Ξ±] (a : Ξ±) (n : β„€) : Prop where /-- The element is equal to the coercion of the integer. -/ out : a = n /-- A "raw int cast" is an expression of the form: * `(Nat.rawCast lit : Ξ±)` where `lit` is a raw natural number literal * `(Int.rawCast (Int.negOfNat lit) : Ξ±)` where `lit` is a nonzero raw natural number literal (That is, we only actually use this function for negative integers.) This representation is used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `Ξ±`. -/ @[simp] def _root_.Int.rawCast [Ring Ξ±] (n : β„€) : Ξ± := n theorem IsInt.to_isNat {Ξ±} [Ring Ξ±] : βˆ€ {a : Ξ±} {n}, IsInt a (.ofNat n) β†’ IsNat a n | _, _, ⟨rfl⟩ => ⟨by simp⟩ theorem IsNat.to_isInt {Ξ±} [Ring Ξ±] : βˆ€ {a : Ξ±} {n}, IsNat a n β†’ IsInt a (.ofNat n) | _, _, ⟨rfl⟩ => ⟨by simp⟩ theorem IsInt.to_raw_eq {a : Ξ±} {n : β„€} [Ring Ξ±] : IsInt (a : Ξ±) n β†’ a = n.rawCast | ⟨e⟩ => e theorem IsInt.of_raw (Ξ±) [Ring Ξ±] (n : β„€) : IsInt (n.rawCast : Ξ±) n := ⟨rfl⟩ theorem IsInt.neg_to_eq {Ξ±} [Ring Ξ±] {n} : {a a' : Ξ±} β†’ IsInt a (.negOfNat n) β†’ n = a' β†’ a = -a' | _, _, ⟨rfl⟩, rfl => by simp [Int.negOfNat_eq, Int.cast_neg] theorem IsInt.nonneg_to_eq {Ξ±} [Ring Ξ±] {n} {a a' : Ξ±} (h : IsInt a (.ofNat n)) (e : n = a') : a = a' := h.to_isNat.to_eq e /-- Assert that an element of a ring is equal to `num / denom` (and `denom` is invertible so that this makes sense). We will usually also have `num` and `denom` coprime, although this is not part of the definition. -/ inductive IsRat [Ring Ξ±] (a : Ξ±) (num : β„€) (denom : β„•) : Prop | mk (inv : Invertible (denom : Ξ±)) (eq : a = num * β…Ÿ(denom : Ξ±)) /-- A "raw rat cast" is an expression of the form: * `(Nat.rawCast lit : Ξ±)` where `lit` is a raw natural number literal * `(Int.rawCast (Int.negOfNat lit) : Ξ±)` where `lit` is a nonzero raw natural number literal * `(Rat.rawCast n d : Ξ±)` where `n` is a raw int literal, `d` is a raw nat literal, and `d` is not `1` or `0`. (where a raw int literal is of the form `Int.ofNat lit` or `Int.negOfNat nzlit` where `lit` is a raw nat literal) This representation is used by tactics like `ring` to decrease the number of typeclass arguments required in each use of a number literal at type `Ξ±`. -/ @[simp] def _root_.Rat.rawCast [DivisionRing Ξ±] (n : β„€) (d : β„•) : Ξ± := n / d theorem IsRat.to_isNat {Ξ±} [Ring Ξ±] : βˆ€ {a : Ξ±} {n}, IsRat a (.ofNat n) (nat_lit 1) β†’ IsNat a n
| _, _, ⟨inv, rfl⟩ => have := @invertibleOne α _; ⟨by simp⟩
Mathlib/Tactic/NormNum/Result.lean
212
213
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Group.Submonoid.BigOperators import Mathlib.GroupTheory.Subsemigroup.Center import Mathlib.RingTheory.NonUnitalSubring.Defs import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # `NonUnitalSubring`s Let `R` be a non-unital ring. We prove that non-unital subrings are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set R` to `NonUnitalSubring R`, sending a subset of `R` to the non-unital subring it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(R : Type u) [NonUnitalRing R] (S : Type u) [NonUnitalRing S] (f g : R β†’β‚™+* S)` `(A : NonUnitalSubring R) (B : NonUnitalSubring S) (s : Set R)` * `instance : CompleteLattice (NonUnitalSubring R)` : the complete lattice structure on the non-unital subrings. * `NonUnitalSubring.center` : the center of a non-unital ring `R`. * `NonUnitalSubring.closure` : non-unital subring closure of a set, i.e., the smallest non-unital subring that includes the set. * `NonUnitalSubring.gi` : `closure : Set M β†’ NonUnitalSubring M` and coercion `coe : NonUnitalSubring M β†’ Set M` form a `GaloisInsertion`. * `comap f B : NonUnitalSubring A` : the preimage of a non-unital subring `B` along the non-unital ring homomorphism `f` * `map f A : NonUnitalSubring B` : the image of a non-unital subring `A` along the non-unital ring homomorphism `f`. * `Prod A B : NonUnitalSubring (R Γ— S)` : the product of non-unital subrings * `f.range : NonUnitalSubring B` : the range of the non-unital ring homomorphism `f`. * `eq_locus f g : NonUnitalSubring R` : given non-unital ring homomorphisms `f g : R β†’β‚™+* S`, the non-unital subring of `R` where `f x = g x` ## Implementation notes A non-unital subring is implemented as a `NonUnitalSubsemiring` which is also an additive subgroup. Lattice inclusion (e.g. `≀` and `βŠ“`) is used rather than set notation (`βŠ†` and `∩`), although `∈` is defined as membership of a non-unital subring's underlying set. ## Tags non-unital subring -/ universe u v w section Basic variable {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] namespace NonUnitalSubring variable (s : NonUnitalSubring R) /-- Sum of a list of elements in a non-unital subring is in the non-unital subring. -/ protected theorem list_sum_mem {l : List R} : (βˆ€ x ∈ l, x ∈ s) β†’ l.sum ∈ s := list_sum_mem /-- Sum of a multiset of elements in a `NonUnitalSubring` of a `NonUnitalRing` is in the `NonUnitalSubring`. -/ protected theorem multiset_sum_mem {R} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) (m : Multiset R) : (βˆ€ a ∈ m, a ∈ s) β†’ m.sum ∈ s := multiset_sum_mem _ /-- Sum of elements in a `NonUnitalSubring` of a `NonUnitalRing` indexed by a `Finset` is in the `NonUnitalSubring`. -/ protected theorem sum_mem {R : Type*} [NonUnitalNonAssocRing R] (s : NonUnitalSubring R) {ΞΉ : Type*} {t : Finset ΞΉ} {f : ΞΉ β†’ R} (h : βˆ€ c ∈ t, f c ∈ s) : (βˆ‘ i ∈ t, f i) ∈ s := sum_mem h /-! ## top -/ /-- The non-unital subring `R` of the ring `R`. -/ instance : Top (NonUnitalSubring R) := ⟨{ (⊀ : Subsemigroup R), (⊀ : AddSubgroup R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊀ : NonUnitalSubring R) := Set.mem_univ x @[simp] theorem coe_top : ((⊀ : NonUnitalSubring R) : Set R) = Set.univ := rfl /-- The ring equiv between the top element of `NonUnitalSubring R` and `R`. -/ @[simps!] def topEquiv : (⊀ : NonUnitalSubring R) ≃+* R := NonUnitalSubsemiring.topEquiv end NonUnitalSubring end Basic section Hom namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] [FunLike F R S] [NonUnitalRingHomClass F R S] (s : NonUnitalSubring R) /-! ## comap -/ /-- The preimage of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def comap {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring S) : NonUnitalSubring R := { s.toSubsemigroup.comap (f : R β†’β‚™* S), s.toAddSubgroup.comap (f : R β†’+ S) with carrier := f ⁻¹' s.carrier } @[simp] theorem coe_comap (s : NonUnitalSubring S) (f : F) : (s.comap f : Set R) = f ⁻¹' s := rfl @[simp] theorem mem_comap {s : NonUnitalSubring S} {f : F} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl theorem comap_comap (s : NonUnitalSubring T) (g : S β†’β‚™+* T) (f : R β†’β‚™+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl /-! ## map -/ /-- The image of a `NonUnitalSubring` along a ring homomorphism is a `NonUnitalSubring`. -/ def map {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] (f : F) (s : NonUnitalSubring R) : NonUnitalSubring S := { s.toSubsemigroup.map (f : R β†’β‚™* S), s.toAddSubgroup.map (f : R β†’+ S) with carrier := f '' s.carrier } @[simp] theorem coe_map (f : F) (s : NonUnitalSubring R) : (s.map f : Set S) = f '' s := rfl @[simp] theorem mem_map {f : F} {s : NonUnitalSubring R} {y : S} : y ∈ s.map f ↔ βˆƒ x ∈ s, f x = y := Set.mem_image _ _ _ @[simp] theorem map_id : s.map (NonUnitalRingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ theorem map_map (g : S β†’β‚™+* T) (f : R β†’β‚™+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ theorem map_le_iff_le_comap {f : F} {s : NonUnitalSubring R} {t : NonUnitalSubring S} : s.map f ≀ t ↔ s ≀ t.comap f := Set.image_subset_iff theorem gc_map_comap (f : F) : GaloisConnection (map f : NonUnitalSubring R β†’ NonUnitalSubring S) (comap f) := fun _S _T => map_le_iff_le_comap /-- A `NonUnitalSubring` is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : F) (hf : Function.Injective (f : R β†’ S)) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (map_mul f _ _) map_add' := fun _ _ => Subtype.ext (map_add f _ _) } @[simp] theorem coe_equivMapOfInjective_apply (f : F) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl end NonUnitalSubring namespace NonUnitalRingHom variable {R : Type u} {S : Type v} {T : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [NonUnitalNonAssocRing T] (g : S β†’β‚™+* T) (f : R β†’β‚™+* S) /-! ## range -/ /-- The range of a ring homomorphism, as a `NonUnitalSubring` of the target. See Note [range copy pattern]. -/ def range {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] (f : R β†’β‚™+* S) : NonUnitalSubring S := ((⊀ : NonUnitalSubring R).map f).copy (Set.range f) Set.image_univ.symm @[simp] theorem coe_range : (f.range : Set S) = Set.range f := rfl @[simp] theorem mem_range {f : R β†’β‚™+* S} {y : S} : y ∈ f.range ↔ βˆƒ x, f x = y := Iff.rfl theorem range_eq_map (f : R β†’β‚™+* S) : f.range = NonUnitalSubring.map f ⊀ := by ext; simp theorem mem_range_self (f : R β†’β‚™+* S) (x : R) : f x ∈ f.range := mem_range.mpr ⟨x, rfl⟩ theorem map_range : f.range.map g = (g.comp f).range := by simpa only [range_eq_map] using (⊀ : NonUnitalSubring R).map_map g f /-- The range of a ring homomorphism is a fintype, if the domain is a fintype. Note: this instance can form a diamond with `Subtype.fintype` in the presence of `Fintype S`. -/ instance fintypeRange [Fintype R] [DecidableEq S] (f : R β†’β‚™+* S) : Fintype (range f) := Set.fintypeRange f end NonUnitalRingHom namespace NonUnitalSubring section Order variable {R : Type u} [NonUnitalNonAssocRing R] /-! ## bot -/ instance : Bot (NonUnitalSubring R) := ⟨(0 : R β†’β‚™+* R).range⟩ instance : Inhabited (NonUnitalSubring R) := ⟨βŠ₯⟩ theorem coe_bot : ((βŠ₯ : NonUnitalSubring R) : Set R) = {0} := (NonUnitalRingHom.coe_range (0 : R β†’β‚™+* R)).trans (@Set.range_const R R _ 0) theorem mem_bot {x : R} : x ∈ (βŠ₯ : NonUnitalSubring R) ↔ x = 0 := show x ∈ ((βŠ₯ : NonUnitalSubring R) : Set R) ↔ x = 0 by rw [coe_bot, Set.mem_singleton_iff] /-! ## inf -/ /-- The inf of two `NonUnitalSubring`s is their intersection. -/ instance : Min (NonUnitalSubring R) := ⟨fun s t => { s.toSubsemigroup βŠ“ t.toSubsemigroup, s.toAddSubgroup βŠ“ t.toAddSubgroup with carrier := s ∩ t }⟩ @[simp] theorem coe_inf (p p' : NonUnitalSubring R) : ((p βŠ“ p' : NonUnitalSubring R) : Set R) = (p : Set R) ∩ p' := rfl @[simp] theorem mem_inf {p p' : NonUnitalSubring R} {x : R} : x ∈ p βŠ“ p' ↔ x ∈ p ∧ x ∈ p' := Iff.rfl instance : InfSet (NonUnitalSubring R) := ⟨fun s => NonUnitalSubring.mk' (β‹‚ t ∈ s, ↑t) (β¨… t ∈ s, NonUnitalSubring.toSubsemigroup t) (β¨… t ∈ s, NonUnitalSubring.toAddSubgroup t) (by simp) (by simp)⟩ @[simp, norm_cast] theorem coe_sInf (S : Set (NonUnitalSubring R)) : ((sInf S : NonUnitalSubring R) : Set R) = β‹‚ s ∈ S, ↑s := rfl theorem mem_sInf {S : Set (NonUnitalSubring R)} {x : R} : x ∈ sInf S ↔ βˆ€ p ∈ S, x ∈ p := Set.mem_iInterβ‚‚ @[simp, norm_cast] theorem coe_iInf {ΞΉ : Sort*} {S : ΞΉ β†’ NonUnitalSubring R} : (↑(β¨… i, S i) : Set R) = β‹‚ i, S i := by simp only [iInf, coe_sInf, Set.biInter_range] theorem mem_iInf {ΞΉ : Sort*} {S : ΞΉ β†’ NonUnitalSubring R} {x : R} : (x ∈ β¨… i, S i) ↔ βˆ€ i, x ∈ S i := by simp only [iInf, mem_sInf, Set.forall_mem_range] @[simp] theorem sInf_toSubsemigroup (s : Set (NonUnitalSubring R)) : (sInf s).toSubsemigroup = β¨… t ∈ s, NonUnitalSubring.toSubsemigroup t := mk'_toSubsemigroup _ _ @[simp] theorem sInf_toAddSubgroup (s : Set (NonUnitalSubring R)) : (sInf s).toAddSubgroup = β¨… t ∈ s, NonUnitalSubring.toAddSubgroup t := mk'_toAddSubgroup _ _ /-- `NonUnitalSubring`s of a ring form a complete lattice. -/ instance : CompleteLattice (NonUnitalSubring R) := { completeLatticeOfInf (NonUnitalSubring R) fun _s => IsGLB.of_image (@fun _ _ : NonUnitalSubring R => SetLike.coe_subset_coe) isGLB_biInf with bot := βŠ₯ bot_le := fun s _x hx => (mem_bot.mp hx).symm β–Έ zero_mem s top := ⊀ le_top := fun _ _ _ => trivial inf := (Β· βŠ“ Β·) inf_le_left := fun _ _ _ => And.left inf_le_right := fun _ _ _ => And.right le_inf := fun _s _t₁ _tβ‚‚ h₁ hβ‚‚ _x hx => ⟨h₁ hx, hβ‚‚ hx⟩ } theorem eq_top_iff' (A : NonUnitalSubring R) : A = ⊀ ↔ βˆ€ x : R, x ∈ A := eq_top_iff.trans ⟨fun h m => h <| mem_top m, fun h m _ => h m⟩ end Order /-! ## Center of a ring -/ section Center variable {R : Type u} section NonUnitalNonAssocRing variable (R) [NonUnitalNonAssocRing R] /-- The center of a ring `R` is the set of elements that commute with everything in `R` -/ def center : NonUnitalSubring R := { NonUnitalSubsemiring.center R with neg_mem' := Set.neg_mem_center } theorem coe_center : ↑(center R) = Set.center R := rfl @[simp] theorem center_toNonUnitalSubsemiring : (center R).toNonUnitalSubsemiring = NonUnitalSubsemiring.center R := rfl /-- The center is commutative and associative. -/ instance center.instNonUnitalCommRing : NonUnitalCommRing (center R) := { NonUnitalSubsemiring.center.instNonUnitalCommSemiring R, inferInstanceAs <| NonUnitalNonAssocRing (center R) with } variable {R} /-- The center of isomorphic (not necessarily unital or associative) rings are isomorphic. -/ @[simps!] def centerCongr {S} [NonUnitalNonAssocRing S] (e : R ≃+* S) : center R ≃+* center S := NonUnitalSubsemiring.centerCongr e /-- The center of a (not necessarily uintal or associative) ring is isomorphic to the center of its opposite. -/ @[simps!] def centerToMulOpposite : center R ≃+* center Rᡐᡒᡖ := NonUnitalSubsemiring.centerToMulOpposite end NonUnitalNonAssocRing section NonUnitalRing variable [NonUnitalRing R] -- no instance diamond, unlike the unital version example : (center.instNonUnitalCommRing _).toNonUnitalRing = NonUnitalSubringClass.toNonUnitalRing (center R) := by with_reducible_and_instances rfl theorem mem_center_iff {z : R} : z ∈ center R ↔ βˆ€ g, g * z = z * g := Subsemigroup.mem_center_iff instance decidableMemCenter [DecidableEq R] [Fintype R] : DecidablePred (Β· ∈ center R) := fun _ => decidable_of_iff' _ mem_center_iff @[simp] theorem center_eq_top (R) [NonUnitalCommRing R] : center R = ⊀ := SetLike.coe_injective (Set.center_eq_univ R) end NonUnitalRing end Center /-! ## `NonUnitalSubring` closure of a subset -/ variable {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] /-- The `NonUnitalSubring` generated by a set. -/ def closure (s : Set R) : NonUnitalSubring R := sInf {S | s βŠ† S} theorem mem_closure {x : R} {s : Set R} : x ∈ closure s ↔ βˆ€ S : NonUnitalSubring R, s βŠ† S β†’ x ∈ S := mem_sInf /-- The `NonUnitalSubring` generated by a set includes the set. -/ @[simp, aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_closure {s : Set R} : s βŠ† closure s := fun _x hx => mem_closure.2 fun _S hS => hS hx theorem not_mem_of_not_mem_closure {s : Set R} {P : R} (hP : P βˆ‰ closure s) : P βˆ‰ s := fun h => hP (subset_closure h) /-- A `NonUnitalSubring` `t` includes `closure s` if and only if it includes `s`. -/ @[simp] theorem closure_le {s : Set R} {t : NonUnitalSubring R} : closure s ≀ t ↔ s βŠ† t := ⟨Set.Subset.trans subset_closure, fun h => sInf_le h⟩ /-- `NonUnitalSubring` closure of a set is monotone in its argument: if `s βŠ† t`, then `closure s ≀ closure t`. -/ @[gcongr] theorem closure_mono ⦃s t : Set R⦄ (h : s βŠ† t) : closure s ≀ closure t := closure_le.2 <| Set.Subset.trans h subset_closure theorem closure_eq_of_le {s : Set R} {t : NonUnitalSubring R} (h₁ : s βŠ† t) (hβ‚‚ : t ≀ closure s) : closure s = t := le_antisymm (closure_le.2 h₁) hβ‚‚ /-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements of `s`, and is preserved under addition, negation, and multiplication, then `p` holds for all elements of the closure of `s`. -/ @[elab_as_elim] theorem closure_induction {s : Set R} {p : (x : R) β†’ x ∈ closure s β†’ Prop} (mem : βˆ€ (x) (hx : x ∈ s), p x (subset_closure hx)) (zero : p 0 (zero_mem _)) (add : βˆ€ x y hx hy, p x hx β†’ p y hy β†’ p (x + y) (add_mem hx hy)) (neg : βˆ€ x hx, p x hx β†’ p (-x) (neg_mem hx)) (mul : βˆ€ x y hx hy, p x hx β†’ p y hy β†’ p (x * y) (mul_mem hx hy)) {x} (hx : x ∈ closure s) : p x hx := let K : NonUnitalSubring R := { carrier := { x | βˆƒ hx, p x hx } mul_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, mul _ _ _ _ hpx hpy⟩ add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩ neg_mem' := fun ⟨_, hpx⟩ ↦ ⟨_, neg _ _ hpx⟩ zero_mem' := ⟨_, zero⟩ } closure_le (t := K) |>.mpr (fun y hy ↦ ⟨subset_closure hy, mem y hy⟩) hx |>.elim fun _ ↦ id /-- An induction principle for closure membership, for predicates with two arguments. -/ @[elab_as_elim] theorem closure_inductionβ‚‚ {s : Set R} {p : (x y : R) β†’ x ∈ closure s β†’ y ∈ closure s β†’ Prop} (mem_mem : βˆ€ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_closure hx) (subset_closure hy)) (zero_left : βˆ€ x hx, p 0 x (zero_mem _) hx) (zero_right : βˆ€ x hx, p x 0 hx (zero_mem _)) (neg_left : βˆ€ x y hx hy, p x y hx hy β†’ p (-x) y (neg_mem hx) hy) (neg_right : βˆ€ x y hx hy, p x y hx hy β†’ p x (-y) hx (neg_mem hy)) (add_left : βˆ€ x y z hx hy hz, p x z hx hz β†’ p y z hy hz β†’ p (x + y) z (add_mem hx hy) hz) (add_right : βˆ€ x y z hx hy hz, p x y hx hy β†’ p x z hx hz β†’ p x (y + z) hx (add_mem hy hz)) (mul_left : βˆ€ x y z hx hy hz, p x z hx hz β†’ p y z hy hz β†’ p (x * y) z (mul_mem hx hy) hz) (mul_right : βˆ€ x y z hx hy hz, p x y hx hy β†’ p x z hx hz β†’ p x (y * z) hx (mul_mem hy hz)) {x y : R} (hx : x ∈ closure s) (hy : y ∈ closure s) : p x y hx hy := by induction hy using closure_induction with | mem z hz => induction hx using closure_induction with | mem _ h => exact mem_mem _ _ h hz | zero => exact zero_left _ _ | mul _ _ _ _ h₁ hβ‚‚ => exact mul_left _ _ _ _ _ _ h₁ hβ‚‚ | add _ _ _ _ h₁ hβ‚‚ => exact add_left _ _ _ _ _ _ h₁ hβ‚‚ | neg _ _ h => exact neg_left _ _ _ _ h | zero => exact zero_right x hx | mul _ _ _ _ h₁ hβ‚‚ => exact mul_right _ _ _ _ _ _ h₁ hβ‚‚ | add _ _ _ _ h₁ hβ‚‚ => exact add_right _ _ _ _ _ _ h₁ hβ‚‚ | neg _ _ h => exact neg_right _ _ _ _ h theorem mem_closure_iff {s : Set R} {x} : x ∈ closure s ↔ x ∈ AddSubgroup.closure (Subsemigroup.closure s : Set R) := ⟨fun h => by induction h using closure_induction with | mem _ hx => exact AddSubgroup.subset_closure (Subsemigroup.subset_closure hx) | zero => exact zero_mem _ | add _ _ _ _ hx hy => exact add_mem hx hy | neg x _ hx => exact neg_mem hx | mul _ _ _hx _hy hx hy => clear _hx _hy induction hx, hy using AddSubgroup.closure_inductionβ‚‚ with | mem _ _ hx hy => exact AddSubgroup.subset_closure (mul_mem hx hy) | one_left => simpa using zero_mem _ | one_right => simpa using zero_mem _ | mul_left _ _ _ _ _ _ h₁ hβ‚‚ => simpa [add_mul] using add_mem h₁ hβ‚‚ | mul_right _ _ _ _ _ _ h₁ hβ‚‚ => simpa [mul_add] using add_mem h₁ hβ‚‚ | inv_left _ _ _ _ h => simpa [neg_mul] using neg_mem h | inv_right _ _ _ _ h => simpa [mul_neg] using neg_mem h, fun h => by induction h using AddSubgroup.closure_induction with | mem _ hx => induction hx using Subsemigroup.closure_induction with | mem _ h => exact subset_closure h | mul _ _ _ _ h₁ hβ‚‚ => exact mul_mem h₁ hβ‚‚ | one => exact zero_mem _ | mul _ _ _ _ h₁ hβ‚‚ => exact add_mem h₁ hβ‚‚ | inv _ _ h => exact neg_mem h⟩ /-- If all elements of `s : Set A` commute pairwise, then `closure s` is a commutative ring. -/ def closureNonUnitalCommRingOfComm {R : Type u} [NonUnitalRing R] {s : Set R} (hcomm : βˆ€ a ∈ s, βˆ€ b ∈ s, a * b = b * a) : NonUnitalCommRing (closure s) := { (closure s).toNonUnitalRing with mul_comm := fun ⟨x, hx⟩ ⟨y, hy⟩ => by ext simp only [MulMemClass.mk_mul_mk] induction hx, hy using closure_inductionβ‚‚ with | mem_mem x y hx hy => exact hcomm x hx y hy | zero_left x _ => exact Commute.zero_left x | zero_right x _ => exact Commute.zero_right x | mul_left _ _ _ _ _ _ h₁ hβ‚‚ => exact Commute.mul_left h₁ hβ‚‚ | mul_right _ _ _ _ _ _ h₁ hβ‚‚ => exact Commute.mul_right h₁ hβ‚‚ | add_left _ _ _ _ _ _ h₁ hβ‚‚ => exact Commute.add_left h₁ hβ‚‚ | add_right _ _ _ _ _ _ h₁ hβ‚‚ => exact Commute.add_right h₁ hβ‚‚ | neg_left _ _ _ _ h => exact Commute.neg_left h | neg_right _ _ _ _ h => exact Commute.neg_right h } variable (R) in /-- `closure` forms a Galois insertion with the coercion to set. -/ protected def gi : GaloisInsertion (@closure R _) SetLike.coe where choice s _ := closure s gc _s _t := closure_le le_l_u _s := subset_closure choice_eq _s _h := rfl /-- Closure of a `NonUnitalSubring` `S` equals `S`. -/ @[simp] theorem closure_eq (s : NonUnitalSubring R) : closure (s : Set R) = s := (NonUnitalSubring.gi R).l_u_eq s @[simp] theorem closure_empty : closure (βˆ… : Set R) = βŠ₯ := (NonUnitalSubring.gi R).gc.l_bot @[simp] theorem closure_univ : closure (Set.univ : Set R) = ⊀ := @coe_top R _ β–Έ closure_eq ⊀ theorem closure_union (s t : Set R) : closure (s βˆͺ t) = closure s βŠ” closure t := (NonUnitalSubring.gi R).gc.l_sup theorem closure_iUnion {ΞΉ} (s : ΞΉ β†’ Set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (NonUnitalSubring.gi R).gc.l_iSup theorem closure_sUnion (s : Set (Set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t := (NonUnitalSubring.gi R).gc.l_sSup theorem map_sup (s t : NonUnitalSubring R) (f : F) : (s βŠ” t).map f = s.map f βŠ” t.map f := (gc_map_comap f).l_sup theorem map_iSup {ΞΉ : Sort*} (f : F) (s : ΞΉ β†’ NonUnitalSubring R) : (iSup s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_iSup theorem map_inf (s t : NonUnitalSubring R) (f : F) (hf : Function.Injective f) : (s βŠ“ t).map f = s.map f βŠ“ t.map f := SetLike.coe_injective (Set.image_inter hf) theorem map_iInf {ΞΉ : Sort*} [Nonempty ΞΉ] (f : F) (hf : Function.Injective f) (s : ΞΉ β†’ NonUnitalSubring R) : (iInf s).map f = β¨… i, (s i).map f := by apply SetLike.coe_injective simpa using (Set.injOn_of_injective hf).image_iInter_eq (s := SetLike.coe ∘ s) theorem comap_inf (s t : NonUnitalSubring S) (f : F) : (s βŠ“ t).comap f = s.comap f βŠ“ t.comap f := (gc_map_comap f).u_inf theorem comap_iInf {ΞΉ : Sort*} (f : F) (s : ΞΉ β†’ NonUnitalSubring S) : (iInf s).comap f = β¨… i, (s i).comap f := (gc_map_comap f).u_iInf @[simp] theorem map_bot (f : R β†’β‚™+* S) : (βŠ₯ : NonUnitalSubring R).map f = βŠ₯ := (gc_map_comap f).l_bot @[simp] theorem comap_top (f : R β†’β‚™+* S) : (⊀ : NonUnitalSubring S).comap f = ⊀ := (gc_map_comap f).u_top /-- Given `NonUnitalSubring`s `s`, `t` of rings `R`, `S` respectively, `s.prod t` is `s Γ—Λ’ t` as a `NonUnitalSubring` of `R Γ— S`. -/ def prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : NonUnitalSubring (R Γ— S) := { s.toSubsemigroup.prod t.toSubsemigroup, s.toAddSubgroup.prod t.toAddSubgroup with carrier := s Γ—Λ’ t } @[norm_cast] theorem coe_prod (s : NonUnitalSubring R) (t : NonUnitalSubring S) : (s.prod t : Set (R Γ— S)) = (s : Set R) Γ—Λ’ t := rfl theorem mem_prod {s : NonUnitalSubring R} {t : NonUnitalSubring S} {p : R Γ— S} : p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := Iff.rfl @[mono] theorem prod_mono ⦃s₁ sβ‚‚ : NonUnitalSubring R⦄ (hs : s₁ ≀ sβ‚‚) ⦃t₁ tβ‚‚ : NonUnitalSubring S⦄ (ht : t₁ ≀ tβ‚‚) : s₁.prod t₁ ≀ sβ‚‚.prod tβ‚‚ := Set.prod_mono hs ht theorem prod_mono_right (s : NonUnitalSubring R) : Monotone fun t : NonUnitalSubring S => s.prod t := prod_mono (le_refl s) theorem prod_mono_left (t : NonUnitalSubring S) : Monotone fun s : NonUnitalSubring R => s.prod t := fun _s₁ _sβ‚‚ hs => prod_mono hs (le_refl t) theorem prod_top (s : NonUnitalSubring R) : s.prod (⊀ : NonUnitalSubring S) = s.comap (NonUnitalRingHom.fst R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] theorem top_prod (s : NonUnitalSubring S) : (⊀ : NonUnitalSubring R).prod s = s.comap (NonUnitalRingHom.snd R S) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[simp] theorem top_prod_top : (⊀ : NonUnitalSubring R).prod (⊀ : NonUnitalSubring S) = ⊀ := (top_prod _).trans <| comap_top _ /-- Product of `NonUnitalSubring`s is isomorphic to their product as rings. -/ def prodEquiv (s : NonUnitalSubring R) (t : NonUnitalSubring S) : s.prod t ≃+* s Γ— t := { Equiv.Set.prod (s : Set R) (t : Set S) with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- The underlying set of a non-empty directed Sup of `NonUnitalSubring`s is just a union of the `NonUnitalSubring`s. Note that this fails without the directedness assumption (the union of two `NonUnitalSubring`s is typically not a `NonUnitalSubring`) -/ theorem mem_iSup_of_directed {ΞΉ} [hΞΉ : Nonempty ΞΉ] {S : ΞΉ β†’ NonUnitalSubring R} (hS : Directed (Β· ≀ Β·) S) {x : R} : (x ∈ ⨆ i, S i) ↔ βˆƒ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ let U : NonUnitalSubring R := NonUnitalSubring.mk' (⋃ i, (S i : Set R)) (⨆ i, (S i).toSubsemigroup) (⨆ i, (S i).toAddSubgroup) (Subsemigroup.coe_iSup_of_directed hS) (AddSubgroup.coe_iSup_of_directed hS) suffices ⨆ i, S i ≀ U by simpa [U] using @this x exact iSup_le fun i x hx ↦ Set.mem_iUnion.2 ⟨i, hx⟩ theorem coe_iSup_of_directed {ΞΉ} [Nonempty ΞΉ] {S : ΞΉ β†’ NonUnitalSubring R} (hS : Directed (Β· ≀ Β·) S) : ((⨆ i, S i : NonUnitalSubring R) : Set R) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] theorem mem_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty) (hS : DirectedOn (Β· ≀ Β·) S) {x : R} : x ∈ sSup S ↔ βˆƒ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp only [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk, exists_prop] theorem coe_sSup_of_directedOn {S : Set (NonUnitalSubring R)} (Sne : S.Nonempty) (hS : DirectedOn (Β· ≀ Β·) S) : (↑(sSup S) : Set R) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] theorem mem_map_equiv {f : R ≃+* S} {K : NonUnitalSubring R} {x : S} : x ∈ K.map (f : R β†’β‚™+* S) ↔ f.symm x ∈ K := @Set.mem_image_equiv _ _ (K : Set R) f.toEquiv x theorem map_equiv_eq_comap_symm (f : R ≃+* S) (K : NonUnitalSubring R) : K.map (f : R β†’β‚™+* S) = K.comap f.symm := SetLike.coe_injective (f.toEquiv.image_eq_preimage K) theorem comap_equiv_eq_map_symm (f : R ≃+* S) (K : NonUnitalSubring S) : K.comap (f : R β†’β‚™+* S) = K.map f.symm := (map_equiv_eq_comap_symm f.symm K).symm end NonUnitalSubring namespace NonUnitalRingHom variable {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] open NonUnitalSubring /-- Restriction of a ring homomorphism to its range interpreted as a `NonUnitalSubring`. This is the bundled version of `Set.rangeFactorization`. -/ def rangeRestrict (f : R β†’β‚™+* S) : R β†’β‚™+* f.range := NonUnitalRingHom.codRestrict f f.range fun x => ⟨x, rfl⟩ @[simp] theorem coe_rangeRestrict (f : R β†’β‚™+* S) (x : R) : (f.rangeRestrict x : S) = f x := rfl theorem rangeRestrict_surjective (f : R β†’β‚™+* S) : Function.Surjective f.rangeRestrict := fun ⟨_y, hy⟩ => let ⟨x, hx⟩ := mem_range.mp hy ⟨x, Subtype.ext hx⟩ theorem range_eq_top {f : R β†’β‚™+* S} : f.range = (⊀ : NonUnitalSubring S) ↔ Function.Surjective f := SetLike.ext'_iff.trans <| Iff.trans (by rw [coe_range, coe_top]) Set.range_eq_univ @[deprecated (since := "2024-11-11")] alias range_top_iff_surjective := range_eq_top /-- The range of a surjective ring homomorphism is the whole of the codomain. -/ @[simp] theorem range_eq_top_of_surjective (f : R β†’β‚™+* S) (hf : Function.Surjective f) : f.range = (⊀ : NonUnitalSubring S) := range_eq_top.2 hf @[deprecated (since := "2024-11-11")] alias range_top_of_surjective := range_eq_top_of_surjective /-- The `NonUnitalSubring` of elements `x : R` such that `f x = g x`, i.e., the equalizer of f and g as a `NonUnitalSubring` of R -/ def eqLocus (f g : R β†’β‚™+* S) : NonUnitalSubring R := { (f : R β†’β‚™* S).eqLocus g, (f : R β†’+ S).eqLocus g with carrier := {x | f x = g x} } @[simp] theorem eqLocus_same (f : R β†’β‚™+* S) : f.eqLocus f = ⊀ := SetLike.ext fun _ => eq_self_iff_true _ /-- If two ring homomorphisms are equal on a set, then they are equal on its `NonUnitalSubring` closure. -/ theorem eqOn_set_closure {f g : R β†’β‚™+* S} {s : Set R} (h : Set.EqOn f g s) : Set.EqOn f g (closure s) := show closure s ≀ f.eqLocus g from closure_le.2 h theorem eq_of_eqOn_set_top {f g : R β†’β‚™+* S} (h : Set.EqOn f g (⊀ : NonUnitalSubring R)) : f = g := ext fun _x => h trivial theorem eq_of_eqOn_set_dense {s : Set R} (hs : closure s = ⊀) {f g : R β†’β‚™+* S} (h : s.EqOn f g) : f = g := eq_of_eqOn_set_top <| hs β–Έ eqOn_set_closure h theorem closure_preimage_le (f : R β†’β‚™+* S) (s : Set S) : closure (f ⁻¹' s) ≀ (closure s).comap f := closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx /-- The image under a ring homomorphism of the `NonUnitalSubring` generated by a set equals the `NonUnitalSubring` generated by the image of the set. -/ theorem map_closure (f : R β†’β‚™+* S) (s : Set R) : (closure s).map f = closure (f '' s) := Set.image_preimage.l_comm_of_u_comm (gc_map_comap f) (NonUnitalSubring.gi S).gc (NonUnitalSubring.gi R).gc fun _ ↦ rfl end NonUnitalRingHom namespace NonUnitalSubring variable {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] open NonUnitalRingHom @[simp] theorem range_subtype (s : NonUnitalSubring R) : (NonUnitalSubringClass.subtype s).range = s := SetLike.coe_injective <| (coe_srange _).trans Subtype.range_coe theorem range_fst : NonUnitalRingHom.srange (fst R S) = ⊀ := NonUnitalSubsemiring.range_fst theorem range_snd : NonUnitalRingHom.srange (snd R S) = ⊀ := NonUnitalSubsemiring.range_snd end NonUnitalSubring namespace RingEquiv variable {R : Type u} {S : Type v} [NonUnitalRing R] [NonUnitalRing S] {s t : NonUnitalSubring R} /-- Makes the identity isomorphism from a proof two `NonUnitalSubring`s of a multiplicative monoid are equal. -/ def nonUnitalSubringCongr (h : s = t) : s ≃+* t := { Equiv.setCongr <| congr_arg _ h with map_mul' := fun _ _ => rfl map_add' := fun _ _ => rfl } /-- Restrict a ring homomorphism with a left inverse to a ring isomorphism to its `RingHom.range`. -/ def ofLeftInverse' {g : S β†’ R} {f : R β†’β‚™+* S} (h : Function.LeftInverse g f) : R ≃+* f.range := { f.rangeRestrict with toFun := fun x => f.rangeRestrict x invFun := fun x => (g ∘ NonUnitalSubringClass.subtype f.range) x left_inv := h right_inv := fun x => Subtype.ext <| let ⟨x', hx'⟩ := NonUnitalRingHom.mem_range.mp x.prop show f (g x) = x by rw [← hx', h x'] } @[simp] theorem ofLeftInverse'_apply {g : S β†’ R} {f : R β†’β‚™+* S} (h : Function.LeftInverse g f) (x : R) : ↑(ofLeftInverse' h x) = f x := rfl @[simp] theorem ofLeftInverse'_symm_apply {g : S β†’ R} {f : R β†’β‚™+* S} (h : Function.LeftInverse g f) (x : f.range) : (ofLeftInverse' h).symm x = g x := rfl end RingEquiv namespace NonUnitalSubring variable {F : Type w} {R : Type u} {S : Type v} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S] [FunLike F R S] [NonUnitalRingHomClass F R S] theorem closure_preimage_le (f : F) (s : Set S) : closure ((f : R β†’ S) ⁻¹' s) ≀ (closure s).comap f := closure_le.2 fun _x hx => SetLike.mem_coe.2 <| mem_comap.2 <| subset_closure hx end NonUnitalSubring end Hom
Mathlib/RingTheory/NonUnitalSubring/Basic.lean
866
873
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.InnerProductSpace.Subspace import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse /-! # Angles between vectors This file defines unoriented angles in real inner product spaces. ## Main definitions * `InnerProductGeometry.angle` is the undirected angle between two vectors. ## TODO Prove the triangle inequality for the angle. -/ assert_not_exists HasFDerivAt ConformalAt noncomputable section open Real Set open Real open RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] {x y : V} /-- The undirected angle between two vectors. If either vector is 0, this is Ο€/2. See `Orientation.oangle` for the corresponding oriented angle definition. -/ def angle (x y : V) : ℝ := Real.arccos (βŸͺx, y⟫ / (β€–xβ€– * β€–yβ€–)) theorem continuousAt_angle {x : V Γ— V} (hx1 : x.1 β‰  0) (hx2 : x.2 β‰  0) : ContinuousAt (fun y : V Γ— V => angle y.1 y.2) x := by unfold angle fun_prop (disch := simp [*]) theorem angle_smul_smul {c : ℝ} (hc : c β‰  0) (x y : V) : angle (c β€’ x) (c β€’ y) = angle x y := by have : c * c β‰  0 := mul_ne_zero hc hc rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs, mul_mul_mul_comm _ β€–xβ€–, abs_mul_abs_self, ← mul_assoc c c, mul_div_mul_left _ _ this] @[simp] theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F] [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] (f : E β†’β‚—α΅’[ℝ] F) (u v : E) : angle (f u) (f v) = angle u v := by rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map] @[simp, norm_cast] theorem _root_.Submodule.angle_coe {s : Submodule ℝ V} (x y : s) : angle (x : V) (y : V) = angle x y := s.subtypeβ‚—α΅’.angle_map x y /-- The cosine of the angle between two vectors. -/ theorem cos_angle (x y : V) : Real.cos (angle x y) = βŸͺx, y⟫ / (β€–xβ€– * β€–yβ€–) := Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1 (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2 /-- The angle between two vectors does not depend on their order. -/ theorem angle_comm (x y : V) : angle x y = angle y x := by unfold angle rw [real_inner_comm, mul_comm] /-- The angle between the negation of two vectors. -/ @[simp] theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by unfold angle rw [inner_neg_neg, norm_neg, norm_neg] /-- The angle between two vectors is nonnegative. -/ theorem angle_nonneg (x y : V) : 0 ≀ angle x y := Real.arccos_nonneg _ /-- The angle between two vectors is at most Ο€. -/ theorem angle_le_pi (x y : V) : angle x y ≀ Ο€ := Real.arccos_le_pi _ /-- The sine of the angle between two vectors is nonnegative. -/ theorem sin_angle_nonneg (x y : V) : 0 ≀ sin (angle x y) := sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y) /-- The angle between a vector and the negation of another vector. -/ theorem angle_neg_right (x y : V) : angle x (-y) = Ο€ - angle x y := by unfold angle rw [← Real.arccos_neg, norm_neg, inner_neg_right, neg_div] /-- The angle between the negation of a vector and another vector. -/ theorem angle_neg_left (x y : V) : angle (-x) y = Ο€ - angle x y := by rw [← angle_neg_neg, neg_neg, angle_neg_right] proof_wanted angle_triangle (x y z : V) : angle x z ≀ angle x y + angle y z /-- The angle between the zero vector and a vector. -/ @[simp] theorem angle_zero_left (x : V) : angle 0 x = Ο€ / 2 := by unfold angle rw [inner_zero_left, zero_div, Real.arccos_zero] /-- The angle between a vector and the zero vector. -/ @[simp] theorem angle_zero_right (x : V) : angle x 0 = Ο€ / 2 := by unfold angle rw [inner_zero_right, zero_div, Real.arccos_zero] /-- The angle between a nonzero vector and itself. -/ @[simp] theorem angle_self {x : V} (hx : x β‰  0) : angle x x = 0 := by unfold angle rw [← real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : βŸͺx, x⟫ β‰  0), Real.arccos_one] /-- The angle between a nonzero vector and its negation. -/ @[simp] theorem angle_self_neg_of_nonzero {x : V} (hx : x β‰  0) : angle x (-x) = Ο€ := by rw [angle_neg_right, angle_self hx, sub_zero] /-- The angle between the negation of a nonzero vector and that vector. -/ @[simp] theorem angle_neg_self_of_nonzero {x : V} (hx : x β‰  0) : angle (-x) x = Ο€ := by rw [angle_comm, angle_self_neg_of_nonzero hx] /-- The angle between a vector and a positive multiple of a vector. -/ @[simp] theorem angle_smul_right_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle x (r β€’ y) = angle x y := by unfold angle rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), ← mul_assoc, mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)] /-- The angle between a positive multiple of a vector and a vector. -/
@[simp] theorem angle_smul_left_of_pos (x y : V) {r : ℝ} (hr : 0 < r) : angle (r β€’ x) y = angle x y := by
Mathlib/Geometry/Euclidean/Angle/Unoriented/Basic.lean
142
143
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Topology.Order.IsLUB /-! # Order topology on a densely ordered set -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {Ξ± Ξ² : Type*} section DenselyOrdered variable [TopologicalSpace Ξ±] [LinearOrder Ξ±] [OrderTopology Ξ±] [DenselyOrdered Ξ±] {a b : Ξ±} {s : Set Ξ±} /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ theorem closure_Ioi' {a : Ξ±} (h : (Ioi a).Nonempty) : closure (Ioi a) = Ici a := by apply Subset.antisymm Β· exact closure_minimal Ioi_subset_Ici_self isClosed_Ici Β· rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff] exact isGLB_Ioi.mem_closure h /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] theorem closure_Ioi (a : Ξ±) [NoMaxOrder Ξ±] : closure (Ioi a) = Ici a := closure_Ioi' nonempty_Ioi /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ theorem closure_Iio' (h : (Iio a).Nonempty) : closure (Iio a) = Iic a := closure_Ioi' (Ξ± := Ξ±α΅’α΅ˆ) h /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] theorem closure_Iio (a : Ξ±) [NoMinOrder Ξ±] : closure (Iio a) = Iic a := closure_Iio' nonempty_Iio /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioo {a b : Ξ±} (hab : a β‰  b) : closure (Ioo a b) = Icc a b := by apply Subset.antisymm Β· exact closure_minimal Ioo_subset_Icc_self isClosed_Icc Β· rcases hab.lt_or_lt with hab | hab
Β· rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le] have hab' : (Ioo a b).Nonempty := nonempty_Ioo.2 hab simp only [insert_subset_iff, singleton_subset_iff] exact ⟨(isGLB_Ioo hab).mem_closure hab', (isLUB_Ioo hab).mem_closure hab'⟩ Β· rw [Icc_eq_empty_of_lt hab] exact empty_subset _ /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] theorem closure_Ioc {a b : Ξ±} (hab : a β‰  b) : closure (Ioc a b) = Icc a b := by
Mathlib/Topology/Order/DenselyOrdered.lean
52
61
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov, SΓ©bastien GouΓ«zel, Chris Hughes -/ import Mathlib.Data.Fin.Rev import Mathlib.Data.Nat.Find /-! # Operation on tuples We interpret maps `βˆ€ i : Fin n, Ξ± i` as `n`-tuples of elements of possibly varying type `Ξ± i`, `(Ξ± 0, …, Ξ± (n-1))`. A particular case is `Fin n β†’ Ξ±` of elements with all the same type. In this case when `Ξ± i` is a constant map, then tuples are isomorphic (but not definitionally equal) to `Vector`s. ## Main declarations There are three (main) ways to consider `Fin n` as a subtype of `Fin (n + 1)`, hence three (main) ways to move between tuples of length `n` and of length `n + 1` by adding/removing an entry. ### Adding at the start * `Fin.succ`: Send `i : Fin n` to `i + 1 : Fin (n + 1)`. This is defined in Core. * `Fin.cases`: Induction/recursion principle for `Fin`: To prove a property/define a function for all `Fin (n + 1)`, it is enough to prove/define it for `0` and for `i.succ` for all `i : Fin n`. This is defined in Core. * `Fin.cons`: Turn a tuple `f : Fin n β†’ Ξ±` and an entry `a : Ξ±` into a tuple `Fin.cons a f : Fin (n + 1) β†’ Ξ±` by adding `a` at the start. In general, tuples can be dependent functions, in which case `f : βˆ€ i : Fin n, Ξ± i.succ` and `a : Ξ± 0`. This is a special case of `Fin.cases`. * `Fin.tail`: Turn a tuple `f : Fin (n + 1) β†’ Ξ±` into a tuple `Fin.tail f : Fin n β†’ Ξ±` by forgetting the start. In general, tuples can be dependent functions, in which case `Fin.tail f : βˆ€ i : Fin n, Ξ± i.succ`. ### Adding at the end * `Fin.castSucc`: Send `i : Fin n` to `i : Fin (n + 1)`. This is defined in Core. * `Fin.lastCases`: Induction/recursion principle for `Fin`: To prove a property/define a function for all `Fin (n + 1)`, it is enough to prove/define it for `last n` and for `i.castSucc` for all `i : Fin n`. This is defined in Core. * `Fin.snoc`: Turn a tuple `f : Fin n β†’ Ξ±` and an entry `a : Ξ±` into a tuple `Fin.snoc f a : Fin (n + 1) β†’ Ξ±` by adding `a` at the end. In general, tuples can be dependent functions, in which case `f : βˆ€ i : Fin n, Ξ± i.castSucc` and `a : Ξ± (last n)`. This is a special case of `Fin.lastCases`. * `Fin.init`: Turn a tuple `f : Fin (n + 1) β†’ Ξ±` into a tuple `Fin.init f : Fin n β†’ Ξ±` by forgetting the start. In general, tuples can be dependent functions, in which case `Fin.init f : βˆ€ i : Fin n, Ξ± i.castSucc`. ### Adding in the middle For a **pivot** `p : Fin (n + 1)`, * `Fin.succAbove`: Send `i : Fin n` to * `i : Fin (n + 1)` if `i < p`, * `i + 1 : Fin (n + 1)` if `p ≀ i`. * `Fin.succAboveCases`: Induction/recursion principle for `Fin`: To prove a property/define a function for all `Fin (n + 1)`, it is enough to prove/define it for `p` and for `p.succAbove i` for all `i : Fin n`. * `Fin.insertNth`: Turn a tuple `f : Fin n β†’ Ξ±` and an entry `a : Ξ±` into a tuple `Fin.insertNth f a : Fin (n + 1) β†’ Ξ±` by adding `a` in position `p`. In general, tuples can be dependent functions, in which case `f : βˆ€ i : Fin n, Ξ± (p.succAbove i)` and `a : Ξ± p`. This is a special case of `Fin.succAboveCases`. * `Fin.removeNth`: Turn a tuple `f : Fin (n + 1) β†’ Ξ±` into a tuple `Fin.removeNth p f : Fin n β†’ Ξ±` by forgetting the `p`-th value. In general, tuples can be dependent functions, in which case `Fin.removeNth f : βˆ€ i : Fin n, Ξ± (succAbove p i)`. `p = 0` means we add at the start. `p = last n` means we add at the end. ### Miscellaneous * `Fin.find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never satisfied. * `Fin.append a b` : append two tuples. * `Fin.repeat n a` : repeat a tuple `n` times. -/ assert_not_exists Monoid universe u v namespace Fin variable {m n : β„•} open Function section Tuple /-- There is exactly one tuple of size zero. -/ example (Ξ± : Fin 0 β†’ Sort u) : Unique (βˆ€ i : Fin 0, Ξ± i) := by infer_instance theorem tuple0_le {Ξ± : Fin 0 β†’ Type*} [βˆ€ i, Preorder (Ξ± i)] (f g : βˆ€ i, Ξ± i) : f ≀ g := finZeroElim variable {Ξ± : Fin (n + 1) β†’ Sort u} (x : Ξ± 0) (q : βˆ€ i, Ξ± i) (p : βˆ€ i : Fin n, Ξ± i.succ) (i : Fin n) (y : Ξ± i.succ) (z : Ξ± 0) /-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/ def tail (q : βˆ€ i, Ξ± i) : βˆ€ i : Fin n, Ξ± i.succ := fun i ↦ q i.succ theorem tail_def {n : β„•} {Ξ± : Fin (n + 1) β†’ Sort*} {q : βˆ€ i, Ξ± i} : (tail fun k : Fin (n + 1) ↦ q k) = fun k : Fin n ↦ q k.succ := rfl /-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/ def cons (x : Ξ± 0) (p : βˆ€ i : Fin n, Ξ± i.succ) : βˆ€ i, Ξ± i := fun j ↦ Fin.cases x p j @[simp] theorem tail_cons : tail (cons x p) = p := by simp +unfoldPartialApp [tail, cons] @[simp] theorem cons_succ : cons x p i.succ = p i := by simp [cons] @[simp] theorem cons_zero : cons x p 0 = x := by simp [cons] @[simp] theorem cons_one {Ξ± : Fin (n + 2) β†’ Sort*} (x : Ξ± 0) (p : βˆ€ i : Fin n.succ, Ξ± i.succ) : cons x p 1 = p 0 := by rw [← cons_succ x p]; rfl /-- Updating a tuple and adding an element at the beginning commute. -/ @[simp] theorem cons_update : cons x (update p i y) = update (cons x p) i.succ y := by ext j by_cases h : j = 0 Β· rw [h] simp [Ne.symm (succ_ne_zero i)] Β· let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ] by_cases h' : j' = i Β· rw [h'] simp Β· have : j'.succ β‰  i.succ := by rwa [Ne, succ_inj] rw [update_of_ne h', update_of_ne this, cons_succ] /-- As a binary function, `Fin.cons` is injective. -/ theorem cons_injective2 : Function.Injective2 (@cons n Ξ±) := fun xβ‚€ yβ‚€ x y h ↦ ⟨congr_fun h 0, funext fun i ↦ by simpa using congr_fun h (Fin.succ i)⟩ @[simp] theorem cons_inj {xβ‚€ yβ‚€ : Ξ± 0} {x y : βˆ€ i : Fin n, Ξ± i.succ} : cons xβ‚€ x = cons yβ‚€ y ↔ xβ‚€ = yβ‚€ ∧ x = y := cons_injective2.eq_iff theorem cons_left_injective (x : βˆ€ i : Fin n, Ξ± i.succ) : Function.Injective fun xβ‚€ ↦ cons xβ‚€ x := cons_injective2.left _ theorem cons_right_injective (xβ‚€ : Ξ± 0) : Function.Injective (cons xβ‚€) := cons_injective2.right _ /-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/ theorem update_cons_zero : update (cons x p) 0 z = cons z p := by ext j by_cases h : j = 0 Β· rw [h] simp Β· simp only [h, update_of_ne, Ne, not_false_iff] let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this, cons_succ, cons_succ] /-- Concatenating the first element of a tuple with its tail gives back the original tuple -/ @[simp] theorem cons_self_tail : cons (q 0) (tail q) = q := by ext j by_cases h : j = 0 Β· rw [h] simp Β· let j' := pred j h have : j'.succ = j := succ_pred j h rw [← this] unfold tail rw [cons_succ] /-- Equivalence between tuples of length `n + 1` and pairs of an element and a tuple of length `n` given by separating out the first element of the tuple. This is `Fin.cons` as an `Equiv`. -/ @[simps] def consEquiv (Ξ± : Fin (n + 1) β†’ Type*) : Ξ± 0 Γ— (βˆ€ i, Ξ± (succ i)) ≃ βˆ€ i, Ξ± i where toFun f := cons f.1 f.2 invFun f := (f 0, tail f) left_inv f := by simp right_inv f := by simp /-- Recurse on an `n+1`-tuple by splitting it into a single element and an `n`-tuple. -/ @[elab_as_elim] def consCases {P : (βˆ€ i : Fin n.succ, Ξ± i) β†’ Sort v} (h : βˆ€ xβ‚€ x, P (Fin.cons xβ‚€ x)) (x : βˆ€ i : Fin n.succ, Ξ± i) : P x := _root_.cast (by rw [cons_self_tail]) <| h (x 0) (tail x) @[simp] theorem consCases_cons {P : (βˆ€ i : Fin n.succ, Ξ± i) β†’ Sort v} (h : βˆ€ xβ‚€ x, P (Fin.cons xβ‚€ x)) (xβ‚€ : Ξ± 0) (x : βˆ€ i : Fin n, Ξ± i.succ) : @consCases _ _ _ h (cons xβ‚€ x) = h xβ‚€ x := by rw [consCases, cast_eq] congr /-- Recurse on a tuple by splitting into `Fin.elim0` and `Fin.cons`. -/ @[elab_as_elim] def consInduction {Ξ± : Sort*} {P : βˆ€ {n : β„•}, (Fin n β†’ Ξ±) β†’ Sort v} (h0 : P Fin.elim0) (h : βˆ€ {n} (xβ‚€) (x : Fin n β†’ Ξ±), P x β†’ P (Fin.cons xβ‚€ x)) : βˆ€ {n : β„•} (x : Fin n β†’ Ξ±), P x | 0, x => by convert h0 | _ + 1, x => consCases (fun _ _ ↦ h _ _ <| consInduction h0 h _) x theorem cons_injective_of_injective {Ξ±} {xβ‚€ : Ξ±} {x : Fin n β†’ Ξ±} (hxβ‚€ : xβ‚€ βˆ‰ Set.range x) (hx : Function.Injective x) : Function.Injective (cons xβ‚€ x : Fin n.succ β†’ Ξ±) := by refine Fin.cases ?_ ?_ Β· refine Fin.cases ?_ ?_ Β· intro rfl Β· intro j h rw [cons_zero, cons_succ] at h exact hxβ‚€.elim ⟨_, h.symm⟩ Β· intro i refine Fin.cases ?_ ?_ Β· intro h rw [cons_zero, cons_succ] at h exact hxβ‚€.elim ⟨_, h⟩ Β· intro j h rw [cons_succ, cons_succ] at h exact congr_arg _ (hx h) theorem cons_injective_iff {Ξ±} {xβ‚€ : Ξ±} {x : Fin n β†’ Ξ±} : Function.Injective (cons xβ‚€ x : Fin n.succ β†’ Ξ±) ↔ xβ‚€ βˆ‰ Set.range x ∧ Function.Injective x := by refine ⟨fun h ↦ ⟨?_, ?_⟩, fun h ↦ cons_injective_of_injective h.1 h.2⟩ Β· rintro ⟨i, hi⟩ replace h := @h i.succ 0 simp [hi] at h Β· simpa [Function.comp] using h.comp (Fin.succ_injective _) @[simp] theorem forall_fin_zero_pi {Ξ± : Fin 0 β†’ Sort*} {P : (βˆ€ i, Ξ± i) β†’ Prop} : (βˆ€ x, P x) ↔ P finZeroElim := ⟨fun h ↦ h _, fun h x ↦ Subsingleton.elim finZeroElim x β–Έ h⟩ @[simp] theorem exists_fin_zero_pi {Ξ± : Fin 0 β†’ Sort*} {P : (βˆ€ i, Ξ± i) β†’ Prop} : (βˆƒ x, P x) ↔ P finZeroElim := ⟨fun ⟨x, h⟩ ↦ Subsingleton.elim x finZeroElim β–Έ h, fun h ↦ ⟨_, h⟩⟩ theorem forall_fin_succ_pi {P : (βˆ€ i, Ξ± i) β†’ Prop} : (βˆ€ x, P x) ↔ βˆ€ a v, P (Fin.cons a v) := ⟨fun h a v ↦ h (Fin.cons a v), consCases⟩ theorem exists_fin_succ_pi {P : (βˆ€ i, Ξ± i) β†’ Prop} : (βˆƒ x, P x) ↔ βˆƒ a v, P (Fin.cons a v) := ⟨fun ⟨x, h⟩ ↦ ⟨x 0, tail x, (cons_self_tail x).symm β–Έ h⟩, fun ⟨_, _, h⟩ ↦ ⟨_, h⟩⟩ /-- Updating the first element of a tuple does not change the tail. -/ @[simp] theorem tail_update_zero : tail (update q 0 z) = tail q := by ext j simp [tail] /-- Updating a nonzero element and taking the tail commute. -/ @[simp] theorem tail_update_succ : tail (update q i.succ y) = update (tail q) i y := by ext j by_cases h : j = i Β· rw [h] simp [tail] Β· simp [tail, (Fin.succ_injective n).ne h, h] theorem comp_cons {Ξ± : Sort*} {Ξ² : Sort*} (g : Ξ± β†’ Ξ²) (y : Ξ±) (q : Fin n β†’ Ξ±) : g ∘ cons y q = cons (g y) (g ∘ q) := by
ext j by_cases h : j = 0 Β· rw [h]
Mathlib/Data/Fin/Tuple/Basic.lean
270
272
/- Copyright (c) 2023 JoΓ«l Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: JoΓ«l Riou -/ import Mathlib.CategoryTheory.Shift.CommShift /-! # Shift induced from a category to another In this file, we introduce a sufficient condition on a functor `F : C β₯€ D` so that a shift on `C` by a monoid `A` induces a shift on `D`. More precisely, when the functor `(D β₯€ D) β₯€ C β₯€ D` given by the precomposition with `F` is fully faithful, and that all the shift functors on `C` can be lifted to functors `D β₯€ D` (i.e. we have functors `s a : D β₯€ D` for all `a : A`, and isomorphisms `F β‹™ s a β‰… shiftFunctor C a β‹™ F`), then these functors `s a` are the shift functors of a term of type `HasShift D A`. As this condition on the functor `F` is satisfied for quotient and localization functors, the main construction `HasShift.induced` in this file shall be used for both quotient and localized shifts. -/ namespace CategoryTheory variable {C D : Type _} [Category C] [Category D] (F : C β₯€ D) {A : Type _} [AddMonoid A] [HasShift C A] (s : A β†’ D β₯€ D) (i : βˆ€ a, F β‹™ s a β‰… shiftFunctor C a β‹™ F) [((whiskeringLeft C D D).obj F).Full] [((whiskeringLeft C D D).obj F).Faithful] namespace HasShift namespace Induced /-- The `zero` field of the `ShiftMkCore` structure for the induced shift. -/ noncomputable def zero : s 0 β‰… 𝟭 D := ((whiskeringLeft C D D).obj F).preimageIso ((i 0) β‰ͺ≫ isoWhiskerRight (shiftFunctorZero C A) F β‰ͺ≫ F.leftUnitor β‰ͺ≫ F.rightUnitor.symm) /-- The `add` field of the `ShiftMkCore` structure for the induced shift. -/ noncomputable def add (a b : A) : s (a + b) β‰… s a β‹™ s b := ((whiskeringLeft C D D).obj F).preimageIso (i (a + b) β‰ͺ≫ isoWhiskerRight (shiftFunctorAdd C a b) F β‰ͺ≫ Functor.associator _ _ _ β‰ͺ≫ isoWhiskerLeft _ (i b).symm β‰ͺ≫ (Functor.associator _ _ _).symm β‰ͺ≫ isoWhiskerRight (i a).symm _ β‰ͺ≫ Functor.associator _ _ _) @[simp] lemma zero_hom_app_obj (X : C) : (zero F s i).hom.app (F.obj X) = (i 0).hom.app X ≫ F.map ((shiftFunctorZero C A).hom.app X) := by have h : whiskerLeft F (zero F s i).hom = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma zero_inv_app_obj (X : C) : (zero F s i).inv.app (F.obj X) = F.map ((shiftFunctorZero C A).inv.app X) ≫ (i 0).inv.app X := by have h : whiskerLeft F (zero F s i).inv = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma add_hom_app_obj (a b : A) (X : C) : (add F s i a b).hom.app (F.obj X) = (i (a + b)).hom.app X ≫ F.map ((shiftFunctorAdd C a b).hom.app X) ≫ (i b).inv.app ((shiftFunctor C a).obj X) ≫ (s b).map ((i a).inv.app X) := by have h : whiskerLeft F (add F s i a b).hom = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) @[simp] lemma add_inv_app_obj (a b : A) (X : C) : (add F s i a b).inv.app (F.obj X) = (s b).map ((i a).hom.app X) ≫ (i b).hom.app ((shiftFunctor C a).obj X) ≫ F.map ((shiftFunctorAdd C a b).inv.app X) ≫ (i (a + b)).inv.app X := by have h : whiskerLeft F (add F s i a b).inv = _ := ((whiskeringLeft C D D).obj F).map_preimage _ exact (NatTrans.congr_app h X).trans (by simp) end Induced variable (A) /-- When `F : C β₯€ D` is a functor satisfying suitable technical assumptions, this is the induced term of type `HasShift D A` deduced from `[HasShift C A]`. -/ noncomputable def induced : HasShift D A := hasShiftMk D A { F := s zero := Induced.zero F s i add := Induced.add F s i zero_add_hom_app := fun n => by suffices (Induced.add F s i 0 n).hom = eqToHom (by rw [zero_add]; rfl) ≫ whiskerRight (Induced.zero F s i ).inv (s n) by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X have eq := dcongr_arg (fun a => (i a).hom.app X) (zero_add n) dsimp simp only [Induced.add_hom_app_obj, eq, shiftFunctorAdd_zero_add_hom_app, Functor.map_comp, eqToHom_map, Category.assoc, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, eqToHom_app, Induced.zero_inv_app_obj] erw [← NatTrans.naturality_assoc, Iso.hom_inv_id_app_assoc] rfl add_zero_hom_app := fun n => by suffices (Induced.add F s i n 0).hom = eqToHom (by rw [add_zero]; rfl) ≫ whiskerLeft (s n) (Induced.zero F s i).inv by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X dsimp erw [Induced.add_hom_app_obj, dcongr_arg (fun a => (i a).hom.app X) (add_zero n), ← cancel_mono ((s 0).map ((i n).hom.app X)), Category.assoc, Category.assoc, Category.assoc, Category.assoc, Category.assoc, Category.assoc, ← (s 0).map_comp, Iso.inv_hom_id_app, Functor.map_id, Category.comp_id, ← NatTrans.naturality, Induced.zero_inv_app_obj, shiftFunctorAdd_add_zero_hom_app] simp [eqToHom_map, eqToHom_app] assoc_hom_app := fun m₁ mβ‚‚ m₃ => by suffices (Induced.add F s i (m₁ + mβ‚‚) m₃).hom ≫ whiskerRight (Induced.add F s i m₁ mβ‚‚).hom (s m₃) = eqToHom (by rw [add_assoc]) ≫ (Induced.add F s i m₁ (mβ‚‚ + m₃)).hom ≫ whiskerLeft (s m₁) (Induced.add F s i mβ‚‚ m₃).hom by intro X simpa using NatTrans.congr_app this X apply ((whiskeringLeft C D D).obj F).map_injective ext X dsimp have eq := F.congr_map (shiftFunctorAdd'_assoc_hom_app m₁ mβ‚‚ m₃ _ _ (m₁+mβ‚‚+m₃) rfl rfl rfl X) simp only [shiftFunctorAdd'_eq_shiftFunctorAdd] at eq simp only [Functor.comp_obj, Functor.map_comp, shiftFunctorAdd', Iso.trans_hom, eqToIso.hom, NatTrans.comp_app, eqToHom_app, Category.assoc] at eq rw [← cancel_mono ((s m₃).map ((s mβ‚‚).map ((i m₁).hom.app X)))] simp only [Induced.add_hom_app_obj, Category.assoc, Functor.map_comp] slice_lhs 4 5 => erw [← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id] erw [Category.id_comp] slice_lhs 6 7 => erw [← Functor.map_comp, ← Functor.map_comp, Iso.inv_hom_id_app, (s mβ‚‚).map_id, (s m₃).map_id] erw [Category.comp_id, ← NatTrans.naturality_assoc, reassoc_of% eq, dcongr_arg (fun a => (i a).hom.app X) (add_assoc m₁ mβ‚‚ m₃).symm] simp only [Functor.comp_obj, eqToHom_map, eqToHom_app, NatTrans.naturality_assoc, Induced.add_hom_app_obj, Functor.comp_map, Category.assoc, Iso.inv_hom_id_app_assoc, eqToHom_trans_assoc, eqToHom_refl, Category.id_comp, Category.comp_id, ← Functor.map_comp, Iso.inv_hom_id_app, Functor.map_id] } end HasShift lemma shiftFunctor_of_induced (a : A) : letI := HasShift.induced F A s i shiftFunctor D a = s a := by rfl variable (A) @[simp]
lemma shiftFunctorZero_hom_app_obj_of_induced (X : C) : letI := HasShift.induced F A s i (shiftFunctorZero D A).hom.app (F.obj X) = (i 0).hom.app X ≫ F.map ((shiftFunctorZero C A).hom.app X) := by letI := HasShift.induced F A s i simp only [ShiftMkCore.shiftFunctorZero_eq, HasShift.Induced.zero_hom_app_obj]
Mathlib/CategoryTheory/Shift/Induced.lean
165
171
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n β‰₯ 2` * The computation of `∫ x in 0..Ο€, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : β„•) namespace intervalIntegral open MeasureTheory variable {f : ℝ β†’ ℝ} {ΞΌ : Measure ℝ} [IsLocallyFiniteMeasure ΞΌ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : β„€} (h : 0 ≀ n ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) ΞΌ a b := (continuousOn_id.zpowβ‚€ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≀ r ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) ΞΌ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : βˆ€ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 field_simp [(by linarith : r + 1 β‰  0)] apply integrableOn_deriv_of_nonneg _ hderiv Β· intro x hx; apply rpow_nonneg hx.1.le Β· refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * Ο€)) rw [intervalIntegrable_iff] at m ⊒ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≀ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_rpow' h (a := 0) (b := t)⟩ contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : β„‚} (h : 0 ≀ r.re ∨ (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) ΞΌ a b := by by_cases h2 : (0 : ℝ) βˆ‰ [[a, b]] Β· -- Easy case #1: 0 βˆ‰ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') Β· -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ Β· refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices βˆ€ c : ℝ, IntervalIntegrable (fun x : ℝ => β€–(x : β„‚) ^ rβ€–) ΞΌ 0 c from (this a).symm.trans (this b) intro c rcases le_or_lt 0 c with (hc | hc) Β· -- case `0 ≀ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ β†’ ℝ) ΞΌ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊒ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] Β· -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r β‰  0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor Β· refine integrableOn_singleton_iff.mpr (Or.inr ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton Β· have : βˆ€ x : ℝ, x ∈ Ioo c 0 β†’ β€–Complex.exp (↑π * Complex.I * r)β€– = β€–(x : β„‚) ^ rβ€– := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const] refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : β„‚} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : β„‚) ^ r) volume a b := by suffices βˆ€ c : ℝ, IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : βˆ€ c : ℝ, 0 ≀ c β†’ IntervalIntegrable (fun x => (x : β„‚) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] Β· rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun Β· rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h Β· intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] Β· exact measurableSet_uIoc Β· refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) Β· exact this c hc Β· rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (Ο€ * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≀ -c)] at m ⊒ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≀ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : β„‚} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : β„‚) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_cpow' h (a := 0) (b := t)⟩ have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) ΞΌ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) ΞΌ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) ΞΌ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) ΞΌ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp ΞΌ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : βˆ€ x : ℝ, x ∈ [[a, b]] β†’ f x β‰  0) : IntervalIntegrable (fun x => log (f x)) ΞΌ a b := (ContinuousOn.log hf h).intervalIntegrable /-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) βˆ‰ [[a, b]]) : IntervalIntegrable log ΞΌ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log Β· |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) Β· -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) Β· exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg Β· intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) Β· intro s ⟨hs₁, hsβ‚‚βŸ© norm_num at * exact (log_nonpos_iff hs₁.le).mpr hsβ‚‚.le Β· -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.not_mem_uIcc_of_lt zero_lt_one at hx simpa @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin ΞΌ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos ΞΌ a b := continuous_cos.intervalIntegrable a b theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) ΞΌ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b Β· fun_prop Β· nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) ΞΌ a b := by field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : β„‚} (h : -1 < r.re ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : (∫ x : ℝ in a..b, (x : β„‚) ^ r) = ((b : β„‚) ^ (r + 1) - (a : β„‚) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 β‰  0 := by rcases h with h | h Β· apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' Β· rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) βˆ‰ [[a, b]] Β· apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices βˆ€ c : ℝ, (∫ x : ℝ in (0)..c, (x : β„‚) ^ r) = (c : β„‚) ^ (r + 1) / (r + 1) - (0 : β„‚) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right Β· refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] Β· refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt Β· rcases le_total c 0 with (hc | hc) Β· rw [max_eq_left hc] at hx; exact hx.2.ne Β· rw [min_eq_left hc] at hx; exact hx.1.ne' Β· contrapose! hr; rw [hr]; ring Β· exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : β„‚).re ∨ (r : β„‚) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := by cases h Β· left; rwa [Complex.ofReal_re] Β· right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : β„‚) ^ (r : β„‚)) = ((b : β„‚) ^ (r + 1 : β„‚) - (a : β„‚) ^ (r + 1 : β„‚)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this Β· simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' Β· exact intervalIntegrable_cpow' h' Β· exact intervalIntegrable_cpow (Or.inr h'.2) Β· rw [(by push_cast; rfl : (r : β„‚) + 1 = ((r + 1 : ℝ) : β„‚))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : β„€} (h : 0 ≀ n ∨ n β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) β‰  -1 ∧ (0 : ℝ) βˆ‰ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ξ™ a b`. This integral appears in the proof of the Picard-LindelΓΆf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ξ™ a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_lt a b with hab | hab Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in (0)..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] Β· calc ∫ x in Ξ™ a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_argβ‚‚ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) βˆ‰ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_invβ‚€.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) :=
integral_inv <| not_mem_uIcc_of_lt ha hb
Mathlib/Analysis/SpecialFunctions/Integrals.lean
448
449
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, YaΓ«l Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≀` and `<` are the transitive closures of, respectively, `β©Ώ` and `β‹–`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≀` is the transitive closure of `β©Ώ` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `β‹–` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : β„•`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ΞΉ Ξ± : Type*} {a a₁ aβ‚‚ b b₁ bβ‚‚ c x : Ξ±} namespace Finset section Preorder variable [Preorder Ξ±] section LocallyFiniteOrder variable [LocallyFiniteOrder Ξ±] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≀ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered Ξ±] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = βˆ… ↔ Β¬a ≀ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered Ξ±] : Ioo a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : Β¬a < b) : Ioo a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = βˆ… := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≀ a) : Ico a b = βˆ… := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≀ a) : Ioc a b = βˆ… := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≀ a) : Ioo a b = βˆ… := Ioo_eq_empty h.not_lt theorem left_mem_Icc : a ∈ Icc a b ↔ a ≀ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≀ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a βˆ‰ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a βˆ‰ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b βˆ‰ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b βˆ‰ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ico a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ioc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ioo a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≀ aβ‚‚) : Icc aβ‚‚ b βŠ† Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≀ aβ‚‚) : Ico aβ‚‚ b βŠ† Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≀ aβ‚‚) : Ioc aβ‚‚ b βŠ† Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≀ aβ‚‚) : Ioo aβ‚‚ b βŠ† Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≀ bβ‚‚) : Icc a b₁ βŠ† Icc a bβ‚‚ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≀ bβ‚‚) : Ico a b₁ βŠ† Ico a bβ‚‚ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≀ bβ‚‚) : Ioc a b₁ βŠ† Ioc a bβ‚‚ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≀ bβ‚‚) : Ioo a b₁ βŠ† Ioo a bβ‚‚ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < aβ‚‚) : Ico aβ‚‚ b βŠ† Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < bβ‚‚) : Ioc a b₁ βŠ† Ioo a bβ‚‚ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < bβ‚‚) : Icc a b₁ βŠ† Ico a bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b βŠ† Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b βŠ† Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b βŠ† Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b βŠ† Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b βŠ† Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ ≀ bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ < bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ < bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ ≀ bβ‚‚ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ < a₁) (hb : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ ≀ a₁) (hb : b₁ < bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : Ξ±} (hbc : b ≀ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = βˆ… := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = βˆ… := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = βˆ… := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set Ξ±} [DecidablePred (Β· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (Β· < c)] (hca : c ≀ a) : {x ∈ Ico a b | x < c} = βˆ… := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (Β· < c)] (hbc : b ≀ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (Β· < c)] (hcb : c ≀ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : Ξ±} [DecidablePred (c ≀ Β·)] (hca : c ≀ a) : {x ∈ Ico a b | c ≀ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : Ξ±} [DecidablePred (b ≀ Β·)] : {x ∈ Ico a b | b ≀ x} = βˆ… := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : Ξ±} [DecidablePred (c ≀ Β·)] (hac : a ≀ c) : {x ∈ Ico a b | c ≀ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {Ξ±} [Preorder Ξ±] [LocallyFiniteOrderBot Ξ±] {a c : Ξ±} [DecidablePred (Β· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype Ξ±] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≀ b] : ({j | a < j ∧ j ≀ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≀ j ∧ j < b] : ({j | a ≀ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≀ j ∧ j ≀ b] : ({j | a ≀ j ∧ j ≀ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop Ξ±] @[simp] theorem Ioi_eq_empty : Ioi a = βˆ… ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ Β¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop Ξ±] : Ioi (⊀ : Ξ±) = βˆ… := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot Ξ±] [Fintype Ξ±] : Ici (βŠ₯ : Ξ±) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ Β¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a βŠ† Ici b ↔ b ≀ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a βŠ‚ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≀ b) : Ioi b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b βŠ‚ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder Ξ±] theorem Icc_subset_Ici_self : Icc a b βŠ† Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b βŠ† Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b βŠ† Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b βŠ† Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot Ξ±] @[simp] theorem Iio_eq_empty : Iio a = βˆ… ↔ IsMin a := Ioi_eq_empty (Ξ± := Ξ±α΅’α΅ˆ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ Β¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot Ξ±] : Iio (βŠ₯ : Ξ±) = βˆ… := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop Ξ±] [Fintype Ξ±] : Iic (⊀ : Ξ±) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ Β¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a βŠ† Iic b ↔ a ≀ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a βŠ‚ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≀ b) : Iio a βŠ† Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a βŠ‚ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder Ξ±] theorem Icc_subset_Iic_self : Icc a b βŠ† Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b βŠ† Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b βŠ† Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b βŠ† Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b βŠ† Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b βŠ† Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≀ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : Ξ±) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a β–Έ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop Ξ±] {a : Ξ±} theorem Ioi_subset_Ici_self : Ioi a βŠ† Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set Ξ±} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set Ξ±} : s.Infinite β†’ Β¬BddBelow s := mt BddBelow.finite variable [Fintype Ξ±] theorem filter_lt_eq_Ioi [DecidablePred (a < Β·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≀ Β·)] : ({x | a ≀ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot Ξ±] {a : Ξ±} theorem Iio_subset_Iic_self : Iio a βŠ† Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set Ξ±} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set Ξ±} : s.Infinite β†’ Β¬BddAbove s := mt BddAbove.finite variable [Fintype Ξ±] theorem filter_gt_eq_Iio [DecidablePred (Β· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (Β· ≀ a)] : ({x | x ≀ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder Ξ±] @[simp] theorem Icc_bot [OrderBot Ξ±] : Icc (βŠ₯ : Ξ±) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop Ξ±] : Icc a (⊀ : Ξ±) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot Ξ±] : Ico (βŠ₯ : Ξ±) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop Ξ±] : Ioc a (⊀ : Ξ±) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder Ξ±] [Fintype Ξ±] : Icc (βŠ₯ : Ξ±) (⊀ : Ξ±) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop Ξ±] [LocallyFiniteOrderBot Ξ±] theorem disjoint_Ioi_Iio (a : Ξ±) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder Ξ±] [LocallyFiniteOrder Ξ±] {a b c : Ξ±} @[simp] theorem Icc_self (a : Ξ±) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : Ξ±) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop Ξ±] : Ici (⊀ : Ξ±) = {⊀} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot Ξ±] : Iic (βŠ₯ : Ξ±) = {βŠ₯} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq Ξ±] @[simp] theorem Icc_erase_left (a b : Ξ±) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : Ξ±) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : Ξ±) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] @[simp] theorem Ioc_erase_right (a b : Ξ±) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] @[simp] theorem Icc_diff_both (a b : Ξ±) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] @[simp] theorem Ico_insert_right (h : a ≀ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≀ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] @[simp] theorem Icc_diff_Ico_self (h : a ≀ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioc_self (h : a ≀ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioo_self (h : a ≀ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h]
Mathlib/Order/Interval/Finset/Basic.lean
608
608
/- Copyright (c) 2023 Scott Carnahan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Carnahan -/ import Mathlib.Algebra.Ring.Int.Defs import Mathlib.Data.Nat.Cast.Basic import Mathlib.Algebra.Group.Prod /-! # Typeclasses for power-associative structures In this file we define power-associativity for algebraic structures with a multiplication operation. The class is a Prop-valued mixin named `NatPowAssoc`. ## Results - `npow_add` a defining property: `x ^ (k + n) = x ^ k * x ^ n` - `npow_one` a defining property: `x ^ 1 = x` - `npow_assoc` strictly positive powers of an element have associative multiplication. - `npow_comm` `x ^ m * x ^ n = x ^ n * x ^ m` for strictly positive `m` and `n`. - `npow_mul` `x ^ (m * n) = (x ^ m) ^ n` for strictly positive `m` and `n`. - `npow_eq_pow` monoid exponentiation coincides with semigroup exponentiation. ## Instances We also produce the following instances: - `NatPowAssoc` for Monoids, Pi types and products. ## TODO * to_additive? -/ assert_not_exists DenselyOrdered variable {M : Type*} /-- A mixin for power-associative multiplication. -/ class NatPowAssoc (M : Type*) [MulOneClass M] [Pow M β„•] : Prop where /-- Multiplication is power-associative. -/ protected npow_add : βˆ€ (k n : β„•) (x : M), x ^ (k + n) = x ^ k * x ^ n /-- Exponent zero is one. -/ protected npow_zero : βˆ€ (x : M), x ^ 0 = 1 /-- Exponent one is identity. -/ protected npow_one : βˆ€ (x : M), x ^ 1 = x section MulOneClass variable [MulOneClass M] [Pow M β„•] [NatPowAssoc M] theorem npow_add (k n : β„•) (x : M) : x ^ (k + n) = x ^ k * x ^ n := NatPowAssoc.npow_add k n x @[simp] theorem npow_zero (x : M) : x ^ 0 = 1 := NatPowAssoc.npow_zero x @[simp] theorem npow_one (x : M) : x ^ 1 = x := NatPowAssoc.npow_one x theorem npow_mul_assoc (k m n : β„•) (x : M) : (x ^ k * x ^ m) * x ^ n = x ^ k * (x ^ m * x ^ n) := by simp only [← npow_add, add_assoc] theorem npow_mul_comm (m n : β„•) (x : M) : x ^ m * x ^ n = x ^ n * x ^ m := by simp only [← npow_add, add_comm] theorem npow_mul (x : M) (m n : β„•) : x ^ (m * n) = (x ^ m) ^ n := by induction n with | zero => rw [npow_zero, Nat.mul_zero, npow_zero] | succ n ih => rw [mul_add, npow_add, ih, mul_one, npow_add, npow_one] theorem npow_mul' (x : M) (m n : β„•) : x ^ (m * n) = (x ^ n) ^ m := by rw [mul_comm] exact npow_mul x n m end MulOneClass section Neg theorem neg_npow_assoc {R : Type*} [NonAssocRing R] [Pow R β„•] [NatPowAssoc R] (a b : R) (k : β„•) : (-1)^k * a * b = (-1)^k * (a * b) := by induction k with | zero => simp only [npow_zero, one_mul] | succ k ih => rw [npow_add, npow_one, ← neg_mul_comm, mul_one] simp only [neg_mul, ih] end Neg instance Pi.instNatPowAssoc {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} [βˆ€ i, MulOneClass <| Ξ± i] [βˆ€ i, Pow (Ξ± i) β„•] [βˆ€ i, NatPowAssoc <| Ξ± i] : NatPowAssoc (βˆ€ i, Ξ± i) where npow_add _ _ _ := by ext; simp [npow_add] npow_zero _ := by ext; simp npow_one _ := by ext; simp instance Prod.instNatPowAssoc {N : Type*} [MulOneClass M] [Pow M β„•] [NatPowAssoc M] [MulOneClass N] [Pow N β„•] [NatPowAssoc N] : NatPowAssoc (M Γ— N) where npow_add _ _ _ := by ext <;> simp [npow_add] npow_zero _ := by ext <;> simp npow_one _ := by ext <;> simp section Monoid variable [Monoid M] instance Monoid.PowAssoc : NatPowAssoc M where npow_add _ _ _ := pow_add _ _ _ npow_zero _ := pow_zero _ npow_one _ := pow_one _ @[simp, norm_cast]
theorem Nat.cast_npow (R : Type*) [NonAssocSemiring R] [Pow R β„•] [NatPowAssoc R] (n m : β„•) : (↑(n ^ m) : R) = (↑n : R) ^ m := by induction m with | zero => simp only [pow_zero, Nat.cast_one, npow_zero] | succ m ih => rw [npow_add, npow_add, Nat.cast_mul, ih, npow_one, npow_one]
Mathlib/Algebra/Group/NatPowAssoc.lean
117
121
/- Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FormalMultilinearSeries import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Tactic.Bound.Attribute import Mathlib.Topology.Algebra.InfiniteSum.Module /-! # Analytic functions A function is analytic in one dimension around `0` if it can be written as a converging power series `Ξ£ pβ‚™ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by requiring that `pβ‚™` is a continuous `n`-multilinear map. In general, `pβ‚™` is not unique (in two dimensions, taking `pβ‚‚ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pβ‚™`, but this is not always possible in nonzero characteristic (in characteristic 2, the previous example has no symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition, and we only require the existence of a converging series. The general framework is important to say that the exponential map on bounded operators on a Banach space is analytic, as well as the inverse on invertible operators. ## Main definitions Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n` for `n : β„•`. * `p.radius`: the largest `r : ℝβ‰₯0∞` such that `β€–p nβ€– * r^n` grows subexponentially. * `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_isBigO`: if `β€–p nβ€– * r ^ n` is bounded above, then `r ≀ p.radius`; * `p.isLittleO_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.isLittleO_one_of_lt_radius`, `p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then `β€–p nβ€– * r ^ n` tends to zero exponentially; * `p.lt_radius_of_isBigO`: if `r β‰  0` and `β€–p nβ€– * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then `r < p.radius`; * `p.partialSum n x`: the sum `βˆ‘_{i = 0}^{n-1} pα΅’ xⁱ`. * `p.sum x`: the sum `βˆ‘'_{i = 0}^{∞} pα΅’ xⁱ`. Additionally, let `f` be a function from `E` to `F`. * `HasFPowerSeriesOnBall f p x r`: on the ball of center `x` with radius `r`, `f (x + y) = βˆ‘'_n pβ‚™ yⁿ`. * `HasFPowerSeriesAt f p x`: on some ball of center `x` with positive radius, holds `HasFPowerSeriesOnBall f p x r`. * `AnalyticAt π•œ f x`: there exists a power series `p` such that holds `HasFPowerSeriesAt f p x`. * `AnalyticOnNhd π•œ f s`: the function `f` is analytic at every point of `s`. We also define versions of `HasFPowerSeriesOnBall`, `AnalyticAt`, and `AnalyticOnNhd` restricted to a set, similar to `ContinuousWithinAt`. See `Mathlib.Analysis.Analytic.Within` for basic properties. * `AnalyticWithinAt π•œ f s x` means a power series at `x` converges to `f` on `𝓝[s βˆͺ {x}] x`. * `AnalyticOn π•œ f s t` means `βˆ€ x ∈ t, AnalyticWithinAt π•œ f s x`. We develop the basic properties of these notions, notably: * If a function admits a power series, it is continuous (see `HasFPowerSeriesOnBall.continuousOn` and `HasFPowerSeriesAt.continuousAt` and `AnalyticAt.continuousAt`). * In a complete space, the sum of a formal power series with positive radius is well defined on the disk of convergence, see `FormalMultilinearSeries.hasFPowerSeriesOnBall`. ## Implementation details We only introduce the radius of convergence of a power series, as `p.radius`. For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent) notion, describing the polydisk of convergence. This notion is more specific, and not necessary to build the general theory. We do not define it here. -/ noncomputable section variable {π•œ E F G : Type*} open Topology NNReal Filter ENNReal Set Asymptotics namespace FormalMultilinearSeries variable [Semiring π•œ] [AddCommMonoid E] [AddCommMonoid F] [Module π•œ E] [Module π•œ F] variable [TopologicalSpace E] [TopologicalSpace F] variable [ContinuousAdd E] [ContinuousAdd F] variable [ContinuousConstSMul π•œ E] [ContinuousConstSMul π•œ F] /-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Ξ£ pβ‚™ xⁿ`. A priori, it only behaves well when `β€–xβ€– < p.radius`. -/ protected def sum (p : FormalMultilinearSeries π•œ E F) (x : E) : F := βˆ‘' n : β„•, p n fun _ => x /-- Given a formal multilinear series `p` and a vector `x`, then `p.partialSum n x` is the sum `Ξ£ pβ‚– xᡏ` for `k ∈ {0,..., n-1}`. -/ def partialSum (p : FormalMultilinearSeries π•œ E F) (n : β„•) (x : E) : F := βˆ‘ k ∈ Finset.range n, p k fun _ : Fin k => x /-- The partial sums of a formal multilinear series are continuous. -/ theorem partialSum_continuous (p : FormalMultilinearSeries π•œ E F) (n : β„•) : Continuous (p.partialSum n) := by unfold partialSum fun_prop end FormalMultilinearSeries /-! ### The radius of a formal multilinear series -/ variable [NontriviallyNormedField π•œ] [NormedAddCommGroup E] [NormedSpace π•œ E] [NormedAddCommGroup F] [NormedSpace π•œ F] [NormedAddCommGroup G] [NormedSpace π•œ G] namespace FormalMultilinearSeries variable (p : FormalMultilinearSeries π•œ E F) {r : ℝβ‰₯0} /-- The radius of a formal multilinear series is the largest `r` such that the sum `Ξ£ β€–pβ‚™β€– β€–y‖ⁿ` converges for all `β€–yβ€– < r`. This implies that `Ξ£ pβ‚™ yⁿ` converges for all `β€–yβ€– < r`, but these definitions are *not* equivalent in general. -/ def radius (p : FormalMultilinearSeries π•œ E F) : ℝβ‰₯0∞ := ⨆ (r : ℝβ‰₯0) (C : ℝ) (_ : βˆ€ n, β€–p nβ€– * (r : ℝ) ^ n ≀ C), (r : ℝβ‰₯0∞) /-- If `β€–pβ‚™β€– rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound (C : ℝ) {r : ℝβ‰₯0} (h : βˆ€ n : β„•, β€–p nβ€– * (r : ℝ) ^ n ≀ C) : (r : ℝβ‰₯0∞) ≀ p.radius := le_iSup_of_le r <| le_iSup_of_le C <| le_iSup (fun _ => (r : ℝβ‰₯0∞)) h /-- If `β€–pβ‚™β€– rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_bound_nnreal (C : ℝβ‰₯0) {r : ℝβ‰₯0} (h : βˆ€ n : β„•, β€–p nβ€–β‚Š * r ^ n ≀ C) : (r : ℝβ‰₯0∞) ≀ p.radius := p.le_radius_of_bound C fun n => mod_cast h n /-- If `β€–pβ‚™β€– rⁿ = O(1)`, as `n β†’ ∞`, then the radius of `p` is at least `r`. -/ theorem le_radius_of_isBigO (h : (fun n => β€–p nβ€– * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : ↑r ≀ p.radius := Exists.elim (isBigO_one_nat_atTop_iff.1 h) fun C hC => p.le_radius_of_bound C fun n => (le_abs_self _).trans (hC n) theorem le_radius_of_eventually_le (C) (h : βˆ€αΆ  n in atTop, β€–p nβ€– * (r : ℝ) ^ n ≀ C) : ↑r ≀ p.radius := p.le_radius_of_isBigO <| IsBigO.of_bound C <| h.mono fun n hn => by simpa theorem le_radius_of_summable_nnnorm (h : Summable fun n => β€–p nβ€–β‚Š * r ^ n) : ↑r ≀ p.radius := p.le_radius_of_bound_nnreal (βˆ‘' n, β€–p nβ€–β‚Š * r ^ n) fun _ => h.le_tsum' _ theorem le_radius_of_summable (h : Summable fun n => β€–p nβ€– * (r : ℝ) ^ n) : ↑r ≀ p.radius := p.le_radius_of_summable_nnnorm <| by simp only [← coe_nnnorm] at h exact mod_cast h
theorem radius_eq_top_of_forall_nnreal_isBigO (h : βˆ€ r : ℝβ‰₯0, (fun n => β€–p nβ€– * (r : ℝ) ^ n) =O[atTop] fun _ => (1 : ℝ)) : p.radius = ∞ :=
Mathlib/Analysis/Analytic/Basic.lean
147
149
/- Copyright (c) 2022 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Additive Haar measure constructed from a basis Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue measure, which gives measure `1` to the parallelepiped spanned by the basis. ## Main definitions * `parallelepiped v` is the parallelepiped spanned by a finite family of vectors. * `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with nonempty interior. * `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the corresponding parallelepiped. In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space, by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent of the basis). -/ open Set TopologicalSpace MeasureTheory MeasureTheory.Measure Module open scoped Pointwise noncomputable section variable {ΞΉ ΞΉ' E F : Type*} section Fintype variable [Fintype ΞΉ] [Fintype ΞΉ'] section AddCommGroup variable [AddCommGroup E] [Module ℝ E] [AddCommGroup F] [Module ℝ F] /-- The closed parallelepiped spanned by a finite family of vectors. -/ def parallelepiped (v : ΞΉ β†’ E) : Set E := (fun t : ΞΉ β†’ ℝ => βˆ‘ i, t i β€’ v i) '' Icc 0 1 theorem mem_parallelepiped_iff (v : ΞΉ β†’ E) (x : E) : x ∈ parallelepiped v ↔ βˆƒ t ∈ Icc (0 : ΞΉ β†’ ℝ) 1, x = βˆ‘ i, t i β€’ v i := by simp [parallelepiped, eq_comm] theorem parallelepiped_basis_eq (b : Basis ΞΉ ℝ E) : parallelepiped b = {x | βˆ€ i, b.repr x i ∈ Set.Icc 0 1} := by classical ext x simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum, map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc, Pi.le_def, Pi.zero_apply, Pi.one_apply, ← forall_and] aesop theorem image_parallelepiped (f : E β†’β‚—[ℝ] F) (v : ΞΉ β†’ E) : f '' parallelepiped v = parallelepiped (f ∘ v) := by simp only [parallelepiped, ← image_comp] congr 1 with t simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulβ‚›β‚—, RingHom.id_apply] /-- Reindexing a family of vectors does not change their parallelepiped. -/ @[simp] theorem parallelepiped_comp_equiv (v : ΞΉ β†’ E) (e : ΞΉ' ≃ ΞΉ) : parallelepiped (v ∘ e) = parallelepiped v := by simp only [parallelepiped] let K : (ΞΉ' β†’ ℝ) ≃ (ΞΉ β†’ ℝ) := Equiv.piCongrLeft' (fun _a : ΞΉ' => ℝ) e have : Icc (0 : ΞΉ β†’ ℝ) 1 = K '' Icc (0 : ΞΉ' β†’ ℝ) 1 := by rw [← Equiv.preimage_eq_iff_eq_image] ext x simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply, Pi.one_apply] refine ⟨fun h => ⟨fun i => ?_, fun i => ?_⟩, fun h => ⟨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)⟩⟩ Β· simpa only [Equiv.symm_apply_apply] using h.1 (e i) Β· simpa only [Equiv.symm_apply_apply] using h.2 (e i) rw [this, ← image_comp] congr 1 with x have := fun z : ΞΉ' β†’ ℝ => e.symm.sum_comp fun i => z i β€’ v (e i) simp_rw [Equiv.apply_symm_apply] at this simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this] -- The parallelepiped associated to an orthonormal basis of `ℝ` is either `[0, 1]` or `[-1, 0]`. theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ΞΉ ℝ ℝ) : parallelepiped b = Icc 0 1 ∨ parallelepiped b = Icc (-1) 0 := by have e : ΞΉ ≃ Fin 1 := by apply Fintype.equivFinOfCardEq simp only [← finrank_eq_card_basis b.toBasis, finrank_self] have B : parallelepiped (b.reindex e) = parallelepiped b := by convert parallelepiped_comp_equiv b e.symm ext i simp only [OrthonormalBasis.coe_reindex] rw [← B] let F : ℝ β†’ Fin 1 β†’ ℝ := fun t => fun _i => t have A : Icc (0 : Fin 1 β†’ ℝ) 1 = F '' Icc (0 : ℝ) 1 := by apply Subset.antisymm Β· intro x hx refine ⟨x 0, ⟨hx.1 0, hx.2 0⟩, ?_⟩ ext j simp only [F, Subsingleton.elim j 0] Β· rintro x ⟨y, hy, rfl⟩ exact ⟨fun _j => hy.1, fun _j => hy.2⟩ rcases orthonormalBasis_one_dim (b.reindex e) with (H | H) Β· left simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one] simp only [F, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, ← image_comp, Function.comp_apply, image_id'] Β· right simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A] simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib, Finset.sum_singleton, ← image_comp, Function.comp, image_neg_eq_neg, neg_Icc, neg_zero] theorem parallelepiped_eq_sum_segment (v : ΞΉ β†’ E) : parallelepiped v = βˆ‘ i, segment ℝ 0 (v i) := by ext simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left, segment_eq_image, smul_zero, zero_add, ← Set.pi_univ_Icc, Set.mem_univ_pi] constructor Β· rintro ⟨t, ht, rfl⟩ exact ⟨t β€’ v, fun {i} => ⟨t i, ht _, by simp⟩, rfl⟩ rintro ⟨g, hg, rfl⟩ choose t ht hg using @hg refine ⟨@t, @ht, ?_⟩ simp_rw [hg] theorem convex_parallelepiped (v : ΞΉ β†’ E) : Convex ℝ (parallelepiped v) := by rw [parallelepiped_eq_sum_segment] exact convex_sum _ fun _i _hi => convex_segment _ _ /-- A `parallelepiped` is the convex hull of its vertices -/ theorem parallelepiped_eq_convexHull (v : ΞΉ β†’ E) : parallelepiped v = convexHull ℝ (βˆ‘ i, {(0 : E), v i}) := by simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment] /-- The axis aligned parallelepiped over `ΞΉ β†’ ℝ` is a cuboid. -/ theorem parallelepiped_single [DecidableEq ΞΉ] (a : ΞΉ β†’ ℝ) : (parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by ext x simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, ← forall_and, Pi.inf_apply, Pi.sup_apply, ← Pi.single_smul', Pi.one_apply, Pi.zero_apply, ← Pi.smul_apply', Finset.univ_sum_single (_ : ΞΉ β†’ ℝ)] constructor Β· rintro ⟨t, ht, rfl⟩ i specialize ht i simp_rw [smul_eq_mul, Pi.mul_apply]
rcases le_total (a i) 0 with hai | hai Β· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] exact ⟨le_mul_of_le_one_left hai ht.2, mul_nonpos_of_nonneg_of_nonpos ht.1 hai⟩ Β· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] exact ⟨mul_nonneg ht.1 hai, mul_le_of_le_one_left hai ht.2⟩ Β· intro h refine ⟨fun i => x i / a i, fun i => ?_, funext fun i => ?_⟩ Β· specialize h i rcases le_total (a i) 0 with hai | hai Β· rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] at h exact ⟨div_nonneg_of_nonpos h.2 hai, div_le_one_of_ge h.1 hai⟩ Β· rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] at h exact ⟨div_nonneg h.1 hai, div_le_one_of_leβ‚€ h.2 hai⟩ Β· specialize h i simp only [smul_eq_mul, Pi.mul_apply] rcases eq_or_ne (a i) 0 with hai | hai Β· rw [hai, inf_idem, sup_idem, ← le_antisymm_iff] at h rw [hai, ← h, zero_div, zero_mul] Β· rw [div_mul_cancelβ‚€ _ hai] end AddCommGroup section NormedSpace variable [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] /-- The parallelepiped spanned by a basis, as a compact set with nonempty interior. -/ def Basis.parallelepiped (b : Basis ΞΉ ℝ E) : PositiveCompacts E where carrier := _root_.parallelepiped b
Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean
153
181
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Order.Archimedean.IndicatorCard import Mathlib.Probability.Martingale.Centering import Mathlib.Probability.Martingale.Convergence import Mathlib.Probability.Martingale.OptionalStopping /-! # Generalized Borel-Cantelli lemma This file proves LΓ©vy's generalized Borel-Cantelli lemma which is a generalization of the Borel-Cantelli lemmas. With this generalization, one can easily deduce the Borel-Cantelli lemmas by choosing appropriate filtrations. This file also contains the one sided martingale bound which is required to prove the generalized Borel-Cantelli. **Note**: the usual Borel-Cantelli lemmas are not in this file. See `MeasureTheory.measure_limsup_atTop_eq_zero` for the first (which does not depend on the results here), and `ProbabilityTheory.measure_limsup_eq_one` for the second (which does). ## Main results - `MeasureTheory.Submartingale.bddAbove_iff_exists_tendsto`: the one sided martingale bound: given a submartingale `f` with uniformly bounded differences, the set for which `f` converges is almost everywhere equal to the set for which it is bounded. - `MeasureTheory.ae_mem_limsup_atTop_iff`: LΓ©vy's generalized Borel-Cantelli: given a filtration `β„±` and a sequence of sets `s` such that `s n ∈ β„± n` for all `n`, `limsup atTop s` is almost everywhere equal to the set for which `βˆ‘ β„™[s (n + 1)βˆ£β„± n] = ∞`. -/ open Filter open scoped NNReal ENNReal MeasureTheory ProbabilityTheory Topology namespace MeasureTheory variable {Ξ© : Type*} {m0 : MeasurableSpace Ξ©} {ΞΌ : Measure Ξ©} {β„± : Filtration β„• m0} {f : β„• β†’ Ξ© β†’ ℝ} /-! ### One sided martingale bound -/ -- TODO: `leastGE` should be defined taking values in `WithTop β„•` once the `stoppedProcess` -- refactor is complete /-- `leastGE f r n` is the stopping time corresponding to the first time `f β‰₯ r`. -/ noncomputable def leastGE (f : β„• β†’ Ξ© β†’ ℝ) (r : ℝ) (n : β„•) := hitting f (Set.Ici r) 0 n theorem Adapted.isStoppingTime_leastGE (r : ℝ) (n : β„•) (hf : Adapted β„± f) : IsStoppingTime β„± (leastGE f r n) := hitting_isStoppingTime hf measurableSet_Ici theorem leastGE_le {i : β„•} {r : ℝ} (Ο‰ : Ξ©) : leastGE f r i Ο‰ ≀ i := hitting_le Ο‰ -- The following four lemmas shows `leastGE` behaves like a stopped process. Ideally we should -- define `leastGE` as a stopping time and take its stopped process. However, we can't do that -- with our current definition since a stopping time takes only finite indices. An upcoming -- refactor should hopefully make it possible to have stopping times taking infinity as a value theorem leastGE_mono {n m : β„•} (hnm : n ≀ m) (r : ℝ) (Ο‰ : Ξ©) : leastGE f r n Ο‰ ≀ leastGE f r m Ο‰ := hitting_mono hnm theorem leastGE_eq_min (Ο€ : Ξ© β†’ β„•) (r : ℝ) (Ο‰ : Ξ©) {n : β„•} (hΟ€n : βˆ€ Ο‰, Ο€ Ο‰ ≀ n) : leastGE f r (Ο€ Ο‰) Ο‰ = min (Ο€ Ο‰) (leastGE f r n Ο‰) := by classical refine le_antisymm (le_min (leastGE_le _) (leastGE_mono (hΟ€n Ο‰) r Ο‰)) ?_ by_cases hle : Ο€ Ο‰ ≀ leastGE f r n Ο‰ Β· rw [min_eq_left hle, leastGE] by_cases h : βˆƒ j ∈ Set.Icc 0 (Ο€ Ο‰), f j Ο‰ ∈ Set.Ici r Β· refine hle.trans (Eq.le ?_) rw [leastGE, ← hitting_eq_hitting_of_exists (hΟ€n Ο‰) h] Β· simp only [hitting, if_neg h, le_rfl] Β· rw [min_eq_right (not_le.1 hle).le, leastGE, leastGE, ← hitting_eq_hitting_of_exists (hΟ€n Ο‰) _] rw [not_le, leastGE, hitting_lt_iff _ (hΟ€n Ο‰)] at hle exact let ⟨j, hj₁, hjβ‚‚βŸ© := hle ⟨j, ⟨hj₁.1, hj₁.2.le⟩, hjβ‚‚βŸ© theorem stoppedValue_stoppedValue_leastGE (f : β„• β†’ Ξ© β†’ ℝ) (Ο€ : Ξ© β†’ β„•) (r : ℝ) {n : β„•} (hΟ€n : βˆ€ Ο‰, Ο€ Ο‰ ≀ n) : stoppedValue (fun i => stoppedValue f (leastGE f r i)) Ο€ = stoppedValue (stoppedProcess f (leastGE f r n)) Ο€ := by ext1 Ο‰ simp +unfoldPartialApp only [stoppedProcess, stoppedValue] rw [leastGE_eq_min _ _ _ hΟ€n] theorem Submartingale.stoppedValue_leastGE [IsFiniteMeasure ΞΌ] (hf : Submartingale f β„± ΞΌ) (r : ℝ) : Submartingale (fun i => stoppedValue f (leastGE f r i)) β„± ΞΌ := by rw [submartingale_iff_expected_stoppedValue_mono] Β· intro Οƒ Ο€ hΟƒ hΟ€ hΟƒ_le_Ο€ hΟ€_bdd obtain ⟨n, hΟ€_le_n⟩ := hΟ€_bdd simp_rw [stoppedValue_stoppedValue_leastGE f Οƒ r fun i => (hΟƒ_le_Ο€ i).trans (hΟ€_le_n i)] simp_rw [stoppedValue_stoppedValue_leastGE f Ο€ r hΟ€_le_n] refine hf.expected_stoppedValue_mono ?_ ?_ ?_ fun Ο‰ => (min_le_left _ _).trans (hΟ€_le_n Ο‰) Β· exact hΟƒ.min (hf.adapted.isStoppingTime_leastGE _ _) Β· exact hΟ€.min (hf.adapted.isStoppingTime_leastGE _ _) Β· exact fun Ο‰ => min_le_min (hΟƒ_le_Ο€ Ο‰) le_rfl Β· exact fun i => stronglyMeasurable_stoppedValue_of_le hf.adapted.progMeasurable_of_discrete (hf.adapted.isStoppingTime_leastGE _ _) leastGE_le Β· exact fun i => integrable_stoppedValue _ (hf.adapted.isStoppingTime_leastGE _ _) hf.integrable leastGE_le variable {r : ℝ} {R : ℝβ‰₯0} theorem norm_stoppedValue_leastGE_le (hr : 0 ≀ r) (hf0 : f 0 = 0) (hbdd : βˆ€α΅ Ο‰ βˆ‚ΞΌ, βˆ€ i, |f (i + 1) Ο‰ - f i Ο‰| ≀ R) (i : β„•) : βˆ€α΅ Ο‰ βˆ‚ΞΌ, stoppedValue f (leastGE f r i) Ο‰ ≀ r + R := by filter_upwards [hbdd] with Ο‰ hbddΟ‰ change f (leastGE f r i Ο‰) Ο‰ ≀ r + R by_cases heq : leastGE f r i Ο‰ = 0 Β· rw [heq, hf0, Pi.zero_apply] exact add_nonneg hr R.coe_nonneg Β· obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero heq
rw [hk, add_comm, ← sub_le_iff_le_add] have := not_mem_of_lt_hitting (hk.symm β–Έ k.lt_succ_self : k < leastGE f r i Ο‰) (zero_le _) simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ici, not_or, not_le] at this exact (sub_lt_sub_left this _).le.trans ((le_abs_self _).trans (hbddΟ‰ _)) theorem Submartingale.stoppedValue_leastGE_eLpNorm_le [IsFiniteMeasure ΞΌ] (hf : Submartingale f β„± ΞΌ) (hr : 0 ≀ r) (hf0 : f 0 = 0) (hbdd : βˆ€α΅ Ο‰ βˆ‚ΞΌ, βˆ€ i, |f (i + 1) Ο‰ - f i Ο‰| ≀ R) (i : β„•) : eLpNorm (stoppedValue f (leastGE f r i)) 1 ΞΌ ≀ 2 * ΞΌ Set.univ * ENNReal.ofReal (r + R) := by refine eLpNorm_one_le_of_le' ((hf.stoppedValue_leastGE r).integrable _) ?_ (norm_stoppedValue_leastGE_le hr hf0 hbdd i) rw [← setIntegral_univ] refine le_trans ?_ ((hf.stoppedValue_leastGE r).setIntegral_le (zero_le _) MeasurableSet.univ) simp_rw [stoppedValue, leastGE, hitting_of_le le_rfl, hf0, integral_zero', le_rfl]
Mathlib/Probability/Martingale/BorelCantelli.lean
120
132
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne -/ import Mathlib.Analysis.Convex.Jensen import Mathlib.Analysis.Convex.Mul import Mathlib.Analysis.Convex.SpecificFunctions.Basic import Mathlib.Analysis.SpecialFunctions.Pow.NNReal /-! # Mean value inequalities In this file we prove several mean inequalities for finite sums. Versions for integrals of some of these inequalities are available in `MeasureTheory.MeanInequalities`. ## Main theorems: generalized mean inequality The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$ and $p ≀ q$ we have $$ \sqrt[p]{\sum_{i\in s} w_i z_i^p} ≀ \sqrt[q]{\sum_{i\in s} w_i z_i^q}. $$ Currently we only prove this inequality for $p=1$. As in the rest of `Mathlib`, we provide different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents (`zpow_arith_mean_le_arith_mean_zpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and `arith_mean_le_rpow_mean`). In the first two cases we prove $$ \left(\sum_{i\in s} w_i z_i\right)^n ≀ \sum_{i\in s} w_i z_i^n $$ in order to avoid using real exponents. For real exponents we prove both this and standard versions. ## TODO - each inequality `A ≀ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `StrictConvexOn` functions. - generalized mean inequality with any `p ≀ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. -/ universe u v open Finset NNReal ENNReal noncomputable section variable {ΞΉ : Type u} (s : Finset ΞΉ) namespace Real theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) (n : β„•) : (βˆ‘ i ∈ s, w i * z i) ^ n ≀ βˆ‘ i ∈ s, w i * z i ^ n := (convexOn_pow n).map_sum_le hw hw' hz theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) {n : β„•} (hn : Even n) : (βˆ‘ i ∈ s, w i * z i) ^ n ≀ βˆ‘ i ∈ s, w i * z i ^ n := hn.convexOn_pow.map_sum_le hw hw' fun _ _ => Set.mem_univ _ theorem zpow_arith_mean_le_arith_mean_zpow (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 < z i) (m : β„€) : (βˆ‘ i ∈ s, w i * z i) ^ m ≀ βˆ‘ i ∈ s, w i * z i ^ m := (convexOn_zpow m).map_sum_le hw hw' hz theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) {p : ℝ} (hp : 1 ≀ p) : (βˆ‘ i ∈ s, w i * z i) ^ p ≀ βˆ‘ i ∈ s, w i * z i ^ p := (convexOn_rpow hp).map_sum_le hw hw' hz theorem arith_mean_le_rpow_mean (w z : ΞΉ β†’ ℝ) (hw : βˆ€ i ∈ s, 0 ≀ w i) (hw' : βˆ‘ i ∈ s, w i = 1) (hz : βˆ€ i ∈ s, 0 ≀ z i) {p : ℝ} (hp : 1 ≀ p) : βˆ‘ i ∈ s, w i * z i ≀ (βˆ‘ i ∈ s, w i * z i ^ p) ^ (1 / p) := by have : 0 < p := by positivity rw [← rpow_le_rpow_iff _ _ this, ← rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one] Β· exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp all_goals apply_rules [sum_nonneg, rpow_nonneg] intro i hi apply_rules [mul_nonneg, rpow_nonneg, hw i hi, hz i hi] end Real namespace NNReal /-- Weighted generalized mean inequality, version sums over finite sets, with `ℝβ‰₯0`-valued functions and natural exponent. -/ theorem pow_arith_mean_le_arith_mean_pow (w z : ΞΉ β†’ ℝβ‰₯0) (hw' : βˆ‘ i ∈ s, w i = 1) (n : β„•) : (βˆ‘ i ∈ s, w i * z i) ^ n ≀ βˆ‘ i ∈ s, w i * z i ^ n := mod_cast Real.pow_arith_mean_le_arith_mean_pow s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) n /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝβ‰₯0`-valued functions and real exponents. -/ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β†’ ℝβ‰₯0) (hw' : βˆ‘ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≀ p) : (βˆ‘ i ∈ s, w i * z i) ^ p ≀ βˆ‘ i ∈ s, w i * z i ^ p := mod_cast Real.rpow_arith_mean_le_arith_mean_rpow s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) hp /-- Weighted generalized mean inequality, version for two elements of `ℝβ‰₯0` and real exponents. -/ theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ wβ‚‚ z₁ zβ‚‚ : ℝβ‰₯0) (hw' : w₁ + wβ‚‚ = 1) {p : ℝ} (hp : 1 ≀ p) : (w₁ * z₁ + wβ‚‚ * zβ‚‚) ^ p ≀ w₁ * z₁ ^ p + wβ‚‚ * zβ‚‚ ^ p := by have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, wβ‚‚] ![z₁, zβ‚‚] ?_ hp Β· simpa [Fin.sum_univ_succ] using h Β· simp [hw', Fin.sum_univ_succ] /-- Unweighted mean inequality, version for two elements of `ℝβ‰₯0` and real exponents. -/ theorem rpow_add_le_mul_rpow_add_rpow (z₁ zβ‚‚ : ℝβ‰₯0) {p : ℝ} (hp : 1 ≀ p) : (z₁ + zβ‚‚) ^ p ≀ (2 : ℝβ‰₯0) ^ (p - 1) * (z₁ ^ p + zβ‚‚ ^ p) := by rcases eq_or_lt_of_le hp with (rfl | h'p) Β· simp only [rpow_one, sub_self, rpow_zero, one_mul]; rfl convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * zβ‚‚) (add_halves 1) hp using 1 Β· simp only [one_div, inv_mul_cancel_leftβ‚€, Ne, mul_eq_zero, two_ne_zero, one_ne_zero, not_false_iff] Β· have A : p - 1 β‰  0 := ne_of_gt (sub_pos.2 h'p) simp only [mul_rpow, rpow_sub' A, div_eq_inv_mul, rpow_one, mul_one] ring /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝβ‰₯0`-valued functions and real exponents. -/ theorem arith_mean_le_rpow_mean (w z : ΞΉ β†’ ℝβ‰₯0) (hw' : βˆ‘ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≀ p) : βˆ‘ i ∈ s, w i * z i ≀ (βˆ‘ i ∈ s, w i * z i ^ p) ^ (1 / p) := mod_cast Real.arith_mean_le_rpow_mean s _ _ (fun i _ => (w i).coe_nonneg) (mod_cast hw') (fun i _ => (z i).coe_nonneg) hp private theorem add_rpow_le_one_of_add_le_one {p : ℝ} (a b : ℝβ‰₯0) (hab : a + b ≀ 1) (hp1 : 1 ≀ p) : a ^ p + b ^ p ≀ 1 := by have h_le_one : βˆ€ x : ℝβ‰₯0, x ≀ 1 β†’ x ^ p ≀ x := fun x hx => rpow_le_self_of_le_one hx hp1 have ha : a ≀ 1 := (self_le_add_right a b).trans hab have hb : b ≀ 1 := (self_le_add_left b a).trans hab exact (add_le_add (h_le_one a ha) (h_le_one b hb)).trans hab theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝβ‰₯0) (hp1 : 1 ≀ p) : a ^ p + b ^ p ≀ (a + b) ^ p := by have hp_pos : 0 < p := by positivity by_cases h_zero : a + b = 0 Β· simp [add_eq_zero.mp h_zero, hp_pos.ne'] have h_nonzero : Β¬(a = 0 ∧ b = 0) := by rwa [add_eq_zero] at h_zero have h_add : a / (a + b) + b / (a + b) = 1 := by rw [div_add_div_same, div_self h_zero] have h := add_rpow_le_one_of_add_le_one (a / (a + b)) (b / (a + b)) h_add.le hp1 rw [div_rpow a (a + b), div_rpow b (a + b)] at h have hab_0 : (a + b) ^ p β‰  0 := by simp [hp_pos, h_nonzero] have hab_0' : 0 < (a + b) ^ p := zero_lt_iff.mpr hab_0 have h_mul : (a + b) ^ p * (a ^ p / (a + b) ^ p + b ^ p / (a + b) ^ p) ≀ (a + b) ^ p := by nth_rw 4 [← mul_one ((a + b) ^ p)] exact (mul_le_mul_left hab_0').mpr h rwa [div_eq_mul_inv, div_eq_mul_inv, mul_add, mul_comm (a ^ p), mul_comm (b ^ p), ← mul_assoc, ← mul_assoc, mul_inv_cancelβ‚€ hab_0, one_mul, one_mul] at h_mul theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝβ‰₯0) (hp1 : 1 ≀ p) : (a ^ p + b ^ p) ^ (1 / p) ≀ a + b := by rw [one_div] rw [← @NNReal.le_rpow_inv_iff _ _ p⁻¹ (by simp [lt_of_lt_of_le zero_lt_one hp1])] rw [inv_inv] exact add_rpow_le_rpow_add _ _ hp1 theorem rpow_add_rpow_le {p q : ℝ} (a b : ℝβ‰₯0) (hp_pos : 0 < p) (hpq : p ≀ q) : (a ^ q + b ^ q) ^ (1 / q) ≀ (a ^ p + b ^ p) ^ (1 / p) := by have h_rpow : βˆ€ a : ℝβ‰₯0, a ^ q = (a ^ p) ^ (q / p) := fun a => by rw [← NNReal.rpow_mul, div_eq_inv_mul, ← mul_assoc, mul_inv_cancelβ‚€ hp_pos.ne.symm, one_mul] have h_rpow_add_rpow_le_add : ((a ^ p) ^ (q / p) + (b ^ p) ^ (q / p)) ^ (1 / (q / p)) ≀ a ^ p + b ^ p := by refine rpow_add_rpow_le_add (a ^ p) (b ^ p) ?_ rwa [one_le_div hp_pos] rw [h_rpow a, h_rpow b, one_div p, NNReal.le_rpow_inv_iff hp_pos, ← NNReal.rpow_mul, mul_comm, mul_one_div] rwa [one_div_div] at h_rpow_add_rpow_le_add theorem rpow_add_le_add_rpow {p : ℝ} (a b : ℝβ‰₯0) (hp : 0 ≀ p) (hp1 : p ≀ 1) : (a + b) ^ p ≀ a ^ p + b ^ p := by rcases hp.eq_or_lt with (rfl | hp_pos) Β· simp have h := rpow_add_rpow_le a b hp_pos hp1 rw [one_div_one, one_div] at h repeat' rw [NNReal.rpow_one] at h exact (NNReal.le_rpow_inv_iff hp_pos).mp h end NNReal namespace Real lemma add_rpow_le_rpow_add {p : ℝ} {a b : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (hp1 : 1 ≀ p) : a ^ p + b ^ p ≀ (a + b) ^ p := by lift a to NNReal using ha lift b to NNReal using hb exact_mod_cast NNReal.add_rpow_le_rpow_add a b hp1 lemma rpow_add_rpow_le_add {p : ℝ} {a b : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (hp1 : 1 ≀ p) : (a ^ p + b ^ p) ^ (1 / p) ≀ a + b := by lift a to NNReal using ha lift b to NNReal using hb exact_mod_cast NNReal.rpow_add_rpow_le_add a b hp1 lemma rpow_add_rpow_le {p q : ℝ} {a b : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (hp_pos : 0 < p) (hpq : p ≀ q) : (a ^ q + b ^ q) ^ (1 / q) ≀ (a ^ p + b ^ p) ^ (1 / p) := by lift a to NNReal using ha lift b to NNReal using hb exact_mod_cast NNReal.rpow_add_rpow_le a b hp_pos hpq lemma rpow_add_le_add_rpow {p : ℝ} {a b : ℝ} (ha : 0 ≀ a) (hb : 0 ≀ b) (hp : 0 ≀ p) (hp1 : p ≀ 1) : (a + b) ^ p ≀ a ^ p + b ^ p := by lift a to NNReal using ha lift b to NNReal using hb exact_mod_cast NNReal.rpow_add_le_add_rpow a b hp hp1 end Real namespace ENNReal /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝβ‰₯0∞`-valued functions and real exponents. -/ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ΞΉ β†’ ℝβ‰₯0∞) (hw' : βˆ‘ i ∈ s, w i = 1) {p : ℝ} (hp : 1 ≀ p) : (βˆ‘ i ∈ s, w i * z i) ^ p ≀ βˆ‘ i ∈ s, w i * z i ^ p := by have hp_pos : 0 < p := by positivity have hp_nonneg : 0 ≀ p := by positivity have hp_not_neg : Β¬p < 0 := by simp [hp_nonneg] have h_top_iff_rpow_top : βˆ€ (i : ΞΉ), i ∈ s β†’ (w i * z i = ⊀ ↔ w i * z i ^ p = ⊀) := by simp [ENNReal.mul_eq_top, hp_pos, hp_nonneg, hp_not_neg] refine le_of_top_imp_top_of_toNNReal_le ?_ ?_ Β· -- first, prove `(βˆ‘ i ∈ s, w i * z i) ^ p = ⊀ β†’ βˆ‘ i ∈ s, (w i * z i ^ p) = ⊀` rw [rpow_eq_top_iff, sum_eq_top, sum_eq_top] intro h simp only [and_false, hp_not_neg, false_or] at h rcases h.left with ⟨a, H, ha⟩ use a, H rwa [← h_top_iff_rpow_top a H] Β· -- second, suppose both `(βˆ‘ i ∈ s, w i * z i) ^ p β‰  ⊀` and `βˆ‘ i ∈ s, (w i * z i ^ p) β‰  ⊀`, -- and prove `((βˆ‘ i ∈ s, w i * z i) ^ p).toNNReal ≀ (βˆ‘ i ∈ s, (w i * z i ^ p)).toNNReal`, -- by using `NNReal.rpow_arith_mean_le_arith_mean_rpow`. intro h_top_rpow_sum _ -- show hypotheses needed to put the `.toNNReal` inside the sums. have h_top : βˆ€ a : ΞΉ, a ∈ s β†’ w a * z a β‰  ⊀ := haveI h_top_sum : βˆ‘ i ∈ s, w i * z i β‰  ⊀ := by intro h rw [h, top_rpow_of_pos hp_pos] at h_top_rpow_sum exact h_top_rpow_sum rfl fun a ha => (lt_top_of_sum_ne_top h_top_sum ha).ne have h_top_rpow : βˆ€ a : ΞΉ, a ∈ s β†’ w a * z a ^ p β‰  ⊀ := by intro i hi specialize h_top i hi rwa [Ne, ← h_top_iff_rpow_top i hi] -- put the `.toNNReal` inside the sums. simp_rw [toNNReal_sum h_top_rpow, toNNReal_rpow, toNNReal_sum h_top, toNNReal_mul, toNNReal_rpow] -- use corresponding nnreal result refine NNReal.rpow_arith_mean_le_arith_mean_rpow s (fun i => (w i).toNNReal) (fun i => (z i).toNNReal) ?_ hp -- verify the hypothesis `βˆ‘ i ∈ s, (w i).toNNReal = 1`, using `βˆ‘ i ∈ s, w i = 1` . have h_sum_nnreal : βˆ‘ i ∈ s, w i = ↑(βˆ‘ i ∈ s, (w i).toNNReal) := by rw [coe_finset_sum] refine sum_congr rfl fun i hi => (coe_toNNReal ?_).symm refine (lt_top_of_sum_ne_top ?_ hi).ne exact hw'.symm β–Έ ENNReal.one_ne_top rwa [← coe_inj, ← h_sum_nnreal] /-- Weighted generalized mean inequality, version for two elements of `ℝβ‰₯0∞` and real exponents. -/ theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ wβ‚‚ z₁ zβ‚‚ : ℝβ‰₯0∞) (hw' : w₁ + wβ‚‚ = 1) {p : ℝ} (hp : 1 ≀ p) : (w₁ * z₁ + wβ‚‚ * zβ‚‚) ^ p ≀ w₁ * z₁ ^ p + wβ‚‚ * zβ‚‚ ^ p := by have h := rpow_arith_mean_le_arith_mean_rpow univ ![w₁, wβ‚‚] ![z₁, zβ‚‚] ?_ hp Β· simpa [Fin.sum_univ_succ] using h Β· simp [hw', Fin.sum_univ_succ] /-- Unweighted mean inequality, version for two elements of `ℝβ‰₯0∞` and real exponents. -/ theorem rpow_add_le_mul_rpow_add_rpow (z₁ zβ‚‚ : ℝβ‰₯0∞) {p : ℝ} (hp : 1 ≀ p) : (z₁ + zβ‚‚) ^ p ≀ (2 : ℝβ‰₯0∞) ^ (p - 1) * (z₁ ^ p + zβ‚‚ ^ p) := by convert rpow_arith_mean_le_arith_mean2_rpow (1 / 2) (1 / 2) (2 * z₁) (2 * zβ‚‚) (ENNReal.add_halves 1) hp using 1 Β· simp [← mul_assoc, ENNReal.inv_mul_cancel two_ne_zero ofNat_ne_top] Β· simp only [mul_rpow_of_nonneg _ _ (zero_le_one.trans hp), rpow_sub _ _ two_ne_zero ofNat_ne_top, ENNReal.div_eq_inv_mul, rpow_one, mul_one] ring theorem add_rpow_le_rpow_add {p : ℝ} (a b : ℝβ‰₯0∞) (hp1 : 1 ≀ p) : a ^ p + b ^ p ≀ (a + b) ^ p := by have hp_pos : 0 < p := by positivity by_cases h_top : a + b = ⊀ Β· rw [← @ENNReal.rpow_eq_top_iff_of_pos (a + b) p hp_pos] at h_top rw [h_top]
exact le_top obtain ⟨ha_top, hb_top⟩ := add_ne_top.mp h_top lift a to ℝβ‰₯0 using ha_top lift b to ℝβ‰₯0 using hb_top simpa [ENNReal.coe_rpow_of_nonneg _ hp_pos.le] using ENNReal.coe_le_coe.2 (NNReal.add_rpow_le_rpow_add a b hp1) theorem rpow_add_rpow_le_add {p : ℝ} (a b : ℝβ‰₯0∞) (hp1 : 1 ≀ p) :
Mathlib/Analysis/MeanInequalitiesPow.lean
289
296
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Order.BigOperators.Ring.Finset import Mathlib.Analysis.Convex.Hull import Mathlib.LinearAlgebra.AffineSpace.Basis /-! # Convex combinations This file defines convex combinations of points in a vector space. ## Main declarations * `Finset.centerMass`: Center of mass of a finite family of points. ## Implementation notes We divide by the sum of the weights in the definition of `Finset.centerMass` because of the way mathematical arguments go: one doesn't change weights, but merely adds some. This also makes a few lemmas unconditional on the sum of the weights being `1`. -/ open Set Function Pointwise universe u u' section variable {R R' E F ΞΉ ΞΉ' Ξ± : Type*} [Field R] [Field R'] [AddCommGroup E] [AddCommGroup F] [AddCommGroup Ξ±] [LinearOrder Ξ±] [Module R E] [Module R F] [Module R Ξ±] {s : Set E} /-- Center of mass of a finite collection of points with prescribed weights. Note that we require neither `0 ≀ w i` nor `βˆ‘ w = 1`. -/ def Finset.centerMass (t : Finset ΞΉ) (w : ΞΉ β†’ R) (z : ΞΉ β†’ E) : E := (βˆ‘ i ∈ t, w i)⁻¹ β€’ βˆ‘ i ∈ t, w i β€’ z i variable (i j : ΞΉ) (c : R) (t : Finset ΞΉ) (w : ΞΉ β†’ R) (z : ΞΉ β†’ E) open Finset theorem Finset.centerMass_empty : (βˆ… : Finset ΞΉ).centerMass w z = 0 := by simp only [centerMass, sum_empty, smul_zero] theorem Finset.centerMass_pair [DecidableEq ΞΉ] (hne : i β‰  j) : ({i, j} : Finset ΞΉ).centerMass w z = (w i / (w i + w j)) β€’ z i + (w j / (w i + w j)) β€’ z j := by simp only [centerMass, sum_pair hne] module variable {w} theorem Finset.centerMass_insert [DecidableEq ΞΉ] (ha : i βˆ‰ t) (hw : βˆ‘ j ∈ t, w j β‰  0) : (insert i t).centerMass w z = (w i / (w i + βˆ‘ j ∈ t, w j)) β€’ z i + ((βˆ‘ j ∈ t, w j) / (w i + βˆ‘ j ∈ t, w j)) β€’ t.centerMass w z := by simp only [centerMass, sum_insert ha, smul_add, (mul_smul _ _ _).symm, ← div_eq_inv_mul] congr 2 rw [div_mul_eq_mul_div, mul_inv_cancelβ‚€ hw, one_div] theorem Finset.centerMass_singleton (hw : w i β‰  0) : ({i} : Finset ΞΉ).centerMass w z = z i := by rw [centerMass, sum_singleton, sum_singleton] match_scalars field_simp @[simp] lemma Finset.centerMass_neg_left : t.centerMass (-w) z = t.centerMass w z := by simp [centerMass, inv_neg] lemma Finset.centerMass_smul_left {c : R'} [Module R' R] [Module R' E] [SMulCommClass R' R R] [IsScalarTower R' R R] [SMulCommClass R R' E] [IsScalarTower R' R E] (hc : c β‰  0) : t.centerMass (c β€’ w) z = t.centerMass w z := by simp [centerMass, -smul_assoc, smul_assoc c, ← smul_sum, smul_invβ‚€, smul_smul_smul_comm, hc] theorem Finset.centerMass_eq_of_sum_1 (hw : βˆ‘ i ∈ t, w i = 1) : t.centerMass w z = βˆ‘ i ∈ t, w i β€’ z i := by simp only [Finset.centerMass, hw, inv_one, one_smul] theorem Finset.centerMass_smul : (t.centerMass w fun i => c β€’ z i) = c β€’ t.centerMass w z := by simp only [Finset.centerMass, Finset.smul_sum, (mul_smul _ _ _).symm, mul_comm c, mul_assoc] /-- A convex combination of two centers of mass is a center of mass as well. This version deals with two different index types. -/ theorem Finset.centerMass_segment' (s : Finset ΞΉ) (t : Finset ΞΉ') (ws : ΞΉ β†’ R) (zs : ΞΉ β†’ E) (wt : ΞΉ' β†’ R) (zt : ΞΉ' β†’ E) (hws : βˆ‘ i ∈ s, ws i = 1) (hwt : βˆ‘ i ∈ t, wt i = 1) (a b : R) (hab : a + b = 1) : a β€’ s.centerMass ws zs + b β€’ t.centerMass wt zt = (s.disjSum t).centerMass (Sum.elim (fun i => a * ws i) fun j => b * wt j) (Sum.elim zs zt) := by rw [s.centerMass_eq_of_sum_1 _ hws, t.centerMass_eq_of_sum_1 _ hwt, smul_sum, smul_sum, ← Finset.sum_sumElim, Finset.centerMass_eq_of_sum_1] Β· congr with ⟨⟩ <;> simp only [Sum.elim_inl, Sum.elim_inr, mul_smul] Β· rw [sum_sumElim, ← mul_sum, ← mul_sum, hws, hwt, mul_one, mul_one, hab] /-- A convex combination of two centers of mass is a center of mass as well. This version works if two centers of mass share the set of original points. -/ theorem Finset.centerMass_segment (s : Finset ΞΉ) (w₁ wβ‚‚ : ΞΉ β†’ R) (z : ΞΉ β†’ E) (hw₁ : βˆ‘ i ∈ s, w₁ i = 1) (hwβ‚‚ : βˆ‘ i ∈ s, wβ‚‚ i = 1) (a b : R) (hab : a + b = 1) : a β€’ s.centerMass w₁ z + b β€’ s.centerMass wβ‚‚ z = s.centerMass (fun i => a * w₁ i + b * wβ‚‚ i) z := by have hw : (βˆ‘ i ∈ s, (a * w₁ i + b * wβ‚‚ i)) = 1 := by simp only [← mul_sum, sum_add_distrib, mul_one, *] simp only [Finset.centerMass_eq_of_sum_1, Finset.centerMass_eq_of_sum_1 _ _ hw, smul_sum, sum_add_distrib, add_smul, mul_smul, *] theorem Finset.centerMass_ite_eq [DecidableEq ΞΉ] (hi : i ∈ t) : t.centerMass (fun j => if i = j then (1 : R) else 0) z = z i := by rw [Finset.centerMass_eq_of_sum_1] Β· trans βˆ‘ j ∈ t, if i = j then z i else 0 Β· congr with i split_ifs with h exacts [h β–Έ one_smul _ _, zero_smul _ _] Β· rw [sum_ite_eq, if_pos hi] Β· rw [sum_ite_eq, if_pos hi] variable {t} theorem Finset.centerMass_subset {t' : Finset ΞΉ} (ht : t βŠ† t') (h : βˆ€ i ∈ t', i βˆ‰ t β†’ w i = 0) : t.centerMass w z = t'.centerMass w z := by rw [centerMass, sum_subset ht h, smul_sum, centerMass, smul_sum] apply sum_subset ht intro i hit' hit rw [h i hit' hit, zero_smul, smul_zero] theorem Finset.centerMass_filter_ne_zero [βˆ€ i, Decidable (w i β‰  0)] : {i ∈ t | w i β‰  0}.centerMass w z = t.centerMass w z := Finset.centerMass_subset z (filter_subset _ _) fun i hit hit' => by simpa only [hit, mem_filter, true_and, Ne, Classical.not_not] using hit' namespace Finset variable [LinearOrder R] [IsStrictOrderedRing R] [IsOrderedAddMonoid Ξ±] [OrderedSMul R Ξ±] theorem centerMass_le_sup {s : Finset ΞΉ} {f : ΞΉ β†’ Ξ±} {w : ΞΉ β†’ R} (hwβ‚€ : βˆ€ i ∈ s, 0 ≀ w i) (hw₁ : 0 < βˆ‘ i ∈ s, w i) : s.centerMass w f ≀ s.sup' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f := by rw [centerMass, inv_smul_le_iff_of_pos hw₁, sum_smul] exact sum_le_sum fun i hi => smul_le_smul_of_nonneg_left (le_sup' _ hi) <| hwβ‚€ i hi theorem inf_le_centerMass {s : Finset ΞΉ} {f : ΞΉ β†’ Ξ±} {w : ΞΉ β†’ R} (hwβ‚€ : βˆ€ i ∈ s, 0 ≀ w i) (hw₁ : 0 < βˆ‘ i ∈ s, w i) : s.inf' (nonempty_of_ne_empty <| by rintro rfl; simp at hw₁) f ≀ s.centerMass w f := centerMass_le_sup (Ξ± := Ξ±α΅’α΅ˆ) hwβ‚€ hw₁ end Finset
variable {z} lemma Finset.centerMass_of_sum_add_sum_eq_zero {s t : Finset ΞΉ} (hw : βˆ‘ i ∈ s, w i + βˆ‘ i ∈ t, w i = 0) (hz : βˆ‘ i ∈ s, w i β€’ z i + βˆ‘ i ∈ t, w i β€’ z i = 0) :
Mathlib/Analysis/Convex/Combination.lean
144
148
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers import Mathlib.CategoryTheory.Abelian.Images import Mathlib.CategoryTheory.Preadditive.Basic /-! # Every NonPreadditiveAbelian category is preadditive In mathlib, we define an abelian category as a preadditive category with a zero object, kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is normal. While virtually every interesting abelian category has a natural preadditive structure (which is why it is included in the definition), preadditivity is not actually needed: Every category that has all of the other properties appearing in the definition of an abelian category admits a preadditive structure. This is the construction we carry out in this file. The proof proceeds in roughly five steps: 1. Prove some results (for example that all equalizers exist) that would be trivial if we already had the preadditive structure but are a bit of work without it. 2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel. The results of the first two steps are also useful for the "normal" development of abelian categories, and will be used there. 3. For every object `A`, define a "subtraction" morphism `Οƒ : A β¨― A ⟢ A` and use it to define subtraction on morphisms as `f - g := prod.lift f g ≫ Οƒ`. 4. Prove a small number of identities about this subtraction from the definition of `Οƒ`. 5. From these identities, prove a large number of other identities that imply that defining `f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition is bilinear. The construction is non-trivial and it is quite remarkable that this abelian group structure can be constructed purely from the existence of a few limits and colimits. Even more remarkably, since abelian categories admit exactly one preadditive structure (see `subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly reconstruct any natural preadditive structure the category may have. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory section universe v u variable (C : Type u) [Category.{v} C] /-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary products and coproducts, and every monomorphism and every epimorphism is normal. -/ class NonPreadditiveAbelian extends HasZeroMorphisms C, IsNormalMonoCategory C, IsNormalEpiCategory C where [has_zero_object : HasZeroObject C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] [has_finite_products : HasFiniteProducts C] [has_finite_coproducts : HasFiniteCoproducts C] attribute [instance] NonPreadditiveAbelian.has_zero_object attribute [instance] NonPreadditiveAbelian.has_kernels attribute [instance] NonPreadditiveAbelian.has_cokernels attribute [instance] NonPreadditiveAbelian.has_finite_products attribute [instance] NonPreadditiveAbelian.has_finite_coproducts end end CategoryTheory open CategoryTheory universe v u variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C] namespace CategoryTheory.NonPreadditiveAbelian section Factor variable {P Q : C} (f : P ⟢ Q) /-- The map `p : P ⟢ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := let I := Abelian.image f let p := Abelian.factorThruImage f let i := kernel.ΞΉ (cokernel.Ο€ f) -- It will suffice to consider some g : I ⟢ R such that p ≫ g = 0 and show that g = 0. NormalMonoCategory.epi_of_zero_cancel _ fun R (g : I ⟢ R) (hpg : p ≫ g = 0) => by -- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h. let u := kernel.ΞΉ g ≫ i haveI hu := normalMonoOfMono u let h := hu.g -- By hypothesis, p factors through the kernel of g via some t. obtain ⟨t, ht⟩ := kernel.lift' g p hpg have fh : f ≫ h = 0 := calc f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm β–Έ rfl _ = ((t ≫ kernel.ΞΉ g) ≫ i) ≫ h := ht β–Έ rfl _ = t ≫ u ≫ h := by simp only [u, Category.assoc] _ = t ≫ 0 := hu.w β–Έ rfl _ = 0 := HasZeroMorphisms.comp_zero _ _ -- h factors through the cokernel of f via some l. obtain ⟨l, hl⟩ := cokernel.desc' f h fh have hih : i ≫ h = 0 := calc i ≫ h = i ≫ cokernel.Ο€ f ≫ l := hl β–Έ rfl _ = 0 ≫ l := by rw [← Category.assoc, kernel.condition] _ = 0 := zero_comp -- i factors through u = ker h via some s. obtain ⟨s, hs⟩ := NormalMono.lift' u i hih have hs' : (s ≫ kernel.ΞΉ g) ≫ i = πŸ™ I ≫ i := by rw [Category.assoc, hs, Category.id_comp] haveI : Epi (kernel.ΞΉ g) := epi_of_epi_fac ((cancel_mono _).1 hs') -- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required. exact zero_of_epi_comp _ (kernel.condition g) instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := isIso_of_mono_of_epi <| Abelian.factorThruImage f /-- The canonical morphism `i : coimage f ⟢ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := let I := Abelian.coimage f let i := Abelian.factorThruCoimage f let p := cokernel.Ο€ (kernel.ΞΉ f) NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟢ I) (hgi : g ≫ i = 0) => by -- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h. let u := p ≫ cokernel.Ο€ g haveI hu := normalEpiOfEpi u let h := hu.g -- By hypothesis, i factors through the cokernel of g via some t. obtain ⟨t, ht⟩ := cokernel.desc' g i hgi have hf : h ≫ f = 0 := calc h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm β–Έ rfl _ = h ≫ p ≫ cokernel.Ο€ g ≫ t := ht β–Έ rfl _ = h ≫ u ≫ t := by simp only [u, Category.assoc] _ = 0 ≫ t := by rw [← Category.assoc, hu.w] _ = 0 := zero_comp -- h factors through the kernel of f via some l. obtain ⟨l, hl⟩ := kernel.lift' f h hf have hhp : h ≫ p = 0 := calc h ≫ p = (l ≫ kernel.ΞΉ f) ≫ p := hl β–Έ rfl _ = l ≫ 0 := by rw [Category.assoc, cokernel.condition] _ = 0 := comp_zero -- p factors through u = coker h via some s. obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp have hs' : p ≫ cokernel.Ο€ g ≫ s = p ≫ πŸ™ I := by rw [← Category.assoc, hs, Category.comp_id] haveI : Mono (cokernel.Ο€ g) := mono_of_mono_fac ((cancel_epi _).1 hs') -- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required. exact zero_of_comp_mono _ (cokernel.condition g) instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := isIso_of_mono_of_epi _ end Factor section CokernelOfKernel variable {X Y : C} {f : X ⟢ Y} /-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `Fork.ΞΉ s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofΟ€ f (KernelFork.condition s)) := IsCokernel.cokernelIso _ _ (cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h) (ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _)) (asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f) /-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `Cofork.Ο€ s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofΞΉ f (CokernelCofork.condition s)) := IsKernel.isoKernel _ _ (kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _)) (CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _)) (asIso <| Abelian.factorThruImage f) (Abelian.image.fac f) end CokernelOfKernel section /-- The composite `A ⟢ A β¨― A ⟢ cokernel (Ξ” A)`, where the first map is `(πŸ™ A, 0)` and the second map is the canonical projection into the cokernel. -/ abbrev r (A : C) : A ⟢ cokernel (diag A) := prod.lift (πŸ™ A) 0 ≫ cokernel.Ο€ (diag A) instance mono_Ξ” {A : C} : Mono (diag A) := mono_of_mono_fac <| prod.lift_fst _ _ instance mono_r {A : C} : Mono (r A) := by let hl : IsLimit (KernelFork.ofΞΉ (diag A) (cokernel.condition (diag A))) := monoIsKernelOfCokernel _ (colimit.isColimit _) apply NormalEpiCategory.mono_of_cancel_zero intro Z x hx have hxx : (x ≫ prod.lift (πŸ™ A) (0 : A ⟢ A)) ≫ cokernel.Ο€ (diag A) = 0 := by rw [Category.assoc, hx] obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx rw [KernelFork.ΞΉ_ofΞΉ] at hy have hyy : y = 0 := by erw [← Category.comp_id y, ← Limits.prod.lift_snd (πŸ™ A) (πŸ™ A), ← Category.assoc, hy, Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero] haveI : Mono (prod.lift (πŸ™ A) (0 : A ⟢ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (πŸ™ A) (0 : A ⟢ A))).1 rw [← hy, hyy, zero_comp, zero_comp] instance epi_r {A : C} : Epi (r A) := by have hlp : prod.lift (πŸ™ A) (0 : A ⟢ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _ let hp1 : IsLimit (KernelFork.ofΞΉ (prod.lift (πŸ™ A) (0 : A ⟢ A)) hlp) := by refine Fork.IsLimit.mk _ (fun s => Fork.ΞΉ s ≫ Limits.prod.fst) ?_ ?_ Β· intro s apply Limits.prod.hom_ext <;> simp Β· intro s m h haveI : Mono (prod.lift (πŸ™ A) (0 : A ⟢ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (πŸ™ A) (0 : A ⟢ A))).1 convert h apply Limits.prod.hom_ext <;> simp let hp2 : IsColimit (CokernelCofork.ofΟ€ (Limits.prod.snd : A β¨― A ⟢ A) hlp) := epiIsCokernelOfKernel _ hp1 apply NormalMonoCategory.epi_of_zero_cancel intro Z z hz have h : prod.lift (πŸ™ A) (0 : A ⟢ A) ≫ cokernel.Ο€ (diag A) ≫ z = 0 := by rw [← Category.assoc, hz] obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h rw [CokernelCofork.Ο€_ofΟ€] at ht have htt : t = 0 := by rw [← Category.id_comp t] change πŸ™ A ≫ t = 0 rw [← Limits.prod.lift_snd (πŸ™ A) (πŸ™ A), Category.assoc, ht, ← Category.assoc, cokernel.condition, zero_comp] apply (cancel_epi (cokernel.Ο€ (diag A))).1 rw [← ht, htt, comp_zero, comp_zero] instance isIso_r {A : C} : IsIso (r A) := isIso_of_mono_of_epi _ /-- The composite `A β¨― A ⟢ cokernel (diag A) ⟢ A` given by the natural projection into the cokernel followed by the inverse of `r`. In the category of modules, using the normal kernels and cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `Οƒ` for "subtraction". -/ abbrev Οƒ {A : C} : A β¨― A ⟢ A := cokernel.Ο€ (diag A) ≫ inv (r A) end @[reassoc] theorem diag_Οƒ {X : C} : diag X ≫ Οƒ = 0 := by rw [cokernel.condition_assoc, zero_comp] @[reassoc (attr := simp)] theorem lift_Οƒ {X : C} : prod.lift (πŸ™ X) 0 ≫ Οƒ = πŸ™ X := by rw [← Category.assoc, IsIso.hom_inv_id] @[reassoc] theorem lift_map {X Y : C} (f : X ⟢ Y) : prod.lift (πŸ™ X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (πŸ™ Y) 0 := by simp /-- Οƒ is a cokernel of Ξ” X. -/ def isColimitΟƒ {X : C} : IsColimit (CokernelCofork.ofΟ€ (Οƒ : X β¨― X ⟢ X) diag_Οƒ) := cokernel.cokernelIso _ Οƒ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv]) /-- This is the key identity satisfied by `Οƒ`. -/ theorem Οƒ_comp {X Y : C} (f : X ⟢ Y) : Οƒ ≫ f = Limits.prod.map f f ≫ Οƒ := by obtain ⟨g, hg⟩ := CokernelCofork.IsColimit.desc' isColimitΟƒ (Limits.prod.map f f ≫ Οƒ) (by rw [prod.diag_map_assoc, diag_Οƒ, comp_zero]) suffices hfg : f = g by rw [← hg, Cofork.Ο€_ofΟ€, hfg] calc f = f ≫ prod.lift (πŸ™ Y) 0 ≫ Οƒ := by rw [lift_Οƒ, Category.comp_id] _ = prod.lift (πŸ™ X) 0 ≫ Limits.prod.map f f ≫ Οƒ := by rw [lift_map_assoc] _ = prod.lift (πŸ™ X) 0 ≫ Οƒ ≫ g := by rw [← hg, CokernelCofork.Ο€_ofΟ€] _ = g := by rw [← Category.assoc, lift_Οƒ, Category.id_comp] section -- We write `f - g` for `prod.lift f g ≫ Οƒ`. /-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/ def hasSub {X Y : C} : Sub (X ⟢ Y) := ⟨fun f g => prod.lift f g ≫ ΟƒβŸ© attribute [local instance] hasSub -- We write `-f` for `0 - f`. /-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/ def hasNeg {X Y : C} : Neg (X ⟢ Y) where neg := fun f => 0 - f attribute [local instance] hasNeg -- We write `f + g` for `f - (-g)`. /-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/ def hasAdd {X Y : C} : Add (X ⟢ Y) := ⟨fun f g => f - -g⟩ attribute [local instance] hasAdd theorem sub_def {X Y : C} (a b : X ⟢ Y) : a - b = prod.lift a b ≫ Οƒ := rfl theorem add_def {X Y : C} (a b : X ⟢ Y) : a + b = a - -b := rfl theorem neg_def {X Y : C} (a : X ⟢ Y) : -a = 0 - a := rfl theorem sub_zero {X Y : C} (a : X ⟢ Y) : a - 0 = a := by rw [sub_def] conv_lhs => congr; congr; rw [← Category.comp_id a] case a.g => rw [show 0 = a ≫ (0 : Y ⟢ Y) by simp] rw [← prod.comp_lift, Category.assoc, lift_Οƒ, Category.comp_id] theorem sub_self {X Y : C} (a : X ⟢ Y) : a - a = 0 := by rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_Οƒ, comp_zero] theorem lift_sub_lift {X Y : C} (a b c d : X ⟢ Y) : prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by simp only [sub_def] ext Β· rw [Category.assoc, Οƒ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst] Β· rw [Category.assoc, Οƒ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd] theorem sub_sub_sub {X Y : C} (a b c d : X ⟢ Y) : a - c - (b - d) = a - b - (c - d) := by rw [sub_def, ← lift_sub_lift, sub_def, Category.assoc, Οƒ_comp, prod.lift_map_assoc]; rfl theorem neg_sub {X Y : C} (a b : X ⟢ Y) : -a - b = -b - a := by conv_lhs => rw [neg_def, ← sub_zero b, sub_sub_sub, sub_zero, ← neg_def] theorem neg_neg {X Y : C} (a : X ⟢ Y) : - -a = a := by rw [neg_def, neg_def] conv_lhs => congr; rw [← sub_self a] rw [sub_sub_sub, sub_zero, sub_self, sub_zero] theorem add_comm {X Y : C} (a b : X ⟢ Y) : a + b = b + a := by rw [add_def] conv_lhs => rw [← neg_neg a] rw [neg_def, neg_def, neg_def, sub_sub_sub] conv_lhs => congr next => skip rw [← neg_def, neg_sub] rw [sub_sub_sub, add_def, ← neg_def, neg_neg b, neg_def] theorem add_neg {X Y : C} (a b : X ⟢ Y) : a + -b = a - b := by rw [add_def, neg_neg] theorem add_neg_cancel {X Y : C} (a : X ⟢ Y) : a + -a = 0 := by rw [add_neg, sub_self] theorem neg_add_cancel {X Y : C} (a : X ⟢ Y) : -a + a = 0 := by rw [add_comm, add_neg_cancel] theorem neg_sub' {X Y : C} (a b : X ⟢ Y) : -(a - b) = -a + b := by rw [neg_def, neg_def] conv_lhs => rw [← sub_self (0 : X ⟢ Y)] rw [sub_sub_sub, add_def, neg_def] theorem neg_add {X Y : C} (a b : X ⟢ Y) : -(a + b) = -a - b := by rw [add_def, neg_sub', add_neg] theorem sub_add {X Y : C} (a b c : X ⟢ Y) : a - b + c = a - (b - c) := by rw [add_def, neg_def, sub_sub_sub, sub_zero] theorem add_assoc {X Y : C} (a b c : X ⟢ Y) : a + b + c = a + (b + c) := by conv_lhs => congr; rw [add_def] rw [sub_add, ← add_neg, neg_sub', neg_neg] theorem add_zero {X Y : C} (a : X ⟢ Y) : a + 0 = a := by rw [add_def, neg_def, sub_self, sub_zero] theorem comp_sub {X Y Z : C} (f : X ⟢ Y) (g h : Y ⟢ Z) : f ≫ (g - h) = f ≫ g - f ≫ h := by rw [sub_def, ← Category.assoc, prod.comp_lift, sub_def] theorem sub_comp {X Y Z : C} (f g : X ⟢ Y) (h : Y ⟢ Z) : (f - g) ≫ h = f ≫ h - g ≫ h := by rw [sub_def, Category.assoc, Οƒ_comp, ← Category.assoc, prod.lift_map, sub_def] theorem comp_add (X Y Z : C) (f : X ⟢ Y) (g h : Y ⟢ Z) : f ≫ (g + h) = f ≫ g + f ≫ h := by rw [add_def, comp_sub, neg_def, comp_sub, comp_zero, add_def, neg_def] theorem add_comp (X Y Z : C) (f g : X ⟢ Y) (h : Y ⟢ Z) : (f + g) ≫ h = f ≫ h + g ≫ h := by rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def] /-- Every `NonPreadditiveAbelian` category is preadditive. -/ def preadditive : Preadditive C where homGroup X Y := { add := (Β· + Β·) add_assoc := add_assoc zero := 0 zero_add := neg_neg add_zero := add_zero neg := fun f => -f neg_add_cancel := neg_add_cancel sub_eq_add_neg := fun f g => (add_neg f g).symm -- Porting note: autoParam failed add_comm := add_comm nsmul := nsmulRec zsmul := zsmulRec }
add_comp := add_comp
Mathlib/CategoryTheory/Abelian/NonPreadditive.lean
411
411
/- Copyright (c) 2021 Lu-Ming Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Lu-Ming Zhang -/ import Mathlib.Algebra.Group.Fin.Basic import Mathlib.LinearAlgebra.Matrix.Symmetric import Mathlib.Tactic.Abel /-! # Circulant matrices This file contains the definition and basic results about circulant matrices. Given a vector `v : n β†’ Ξ±` indexed by a type that is endowed with subtraction, `Matrix.circulant v` is the matrix whose `(i, j)`th entry is `v (i - j)`. ## Main results - `Matrix.circulant`: the circulant matrix generated by a given vector `v : n β†’ Ξ±`. - `Matrix.circulant_mul`: the product of two circulant matrices `circulant v` and `circulant w` is the circulant matrix generated by `circulant v *α΅₯ w`. - `Matrix.circulant_mul_comm`: multiplication of circulant matrices commutes when the elements do. ## Implementation notes `Matrix.Fin.foo` is the `Fin n` version of `Matrix.foo`. Namely, the index type of the circulant matrices in discussion is `Fin n`. ## Tags circulant, matrix -/ variable {Ξ± Ξ² n R : Type*} namespace Matrix open Function open Matrix /-- Given the condition `[Sub n]` and a vector `v : n β†’ Ξ±`, we define `circulant v` to be the circulant matrix generated by `v` of type `Matrix n n Ξ±`. The `(i,j)`th entry is defined to be `v (i - j)`. -/ def circulant [Sub n] (v : n β†’ Ξ±) : Matrix n n Ξ± := of fun i j => v (i - j) -- TODO: set as an equation lemma for `circulant`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem circulant_apply [Sub n] (v : n β†’ Ξ±) (i j) : circulant v i j = v (i - j) := rfl theorem circulant_col_zero_eq [SubtractionMonoid n] (v : n β†’ Ξ±) (i : n) : circulant v i 0 = v i := congr_arg v (sub_zero _) theorem circulant_injective [SubtractionMonoid n] : Injective (circulant : (n β†’ Ξ±) β†’ Matrix n n Ξ±) := by intro v w h ext k rw [← circulant_col_zero_eq v, ← circulant_col_zero_eq w, h] theorem Fin.circulant_injective : βˆ€ n, Injective fun v : Fin n β†’ Ξ± => circulant v | 0 => by simp [Injective] | _ + 1 => Matrix.circulant_injective @[simp] theorem circulant_inj [SubtractionMonoid n] {v w : n β†’ Ξ±} : circulant v = circulant w ↔ v = w := circulant_injective.eq_iff @[simp] theorem Fin.circulant_inj {n} {v w : Fin n β†’ Ξ±} : circulant v = circulant w ↔ v = w := (Fin.circulant_injective n).eq_iff theorem transpose_circulant [SubtractionMonoid n] (v : n β†’ Ξ±) : (circulant v)α΅€ = circulant fun i => v (-i) := by ext; simp theorem conjTranspose_circulant [Star Ξ±] [SubtractionMonoid n] (v : n β†’ Ξ±) : (circulant v)α΄΄ = circulant (star fun i => v (-i)) := by ext; simp theorem Fin.transpose_circulant : βˆ€ {n} (v : Fin n β†’ Ξ±), (circulant v)α΅€ = circulant fun i => v (-i) | 0 => by simp [Injective, eq_iff_true_of_subsingleton] | _ + 1 => Matrix.transpose_circulant theorem Fin.conjTranspose_circulant [Star Ξ±] : βˆ€ {n} (v : Fin n β†’ Ξ±), (circulant v)α΄΄ = circulant (star fun i => v (-i))
| 0 => by simp [Injective, eq_iff_true_of_subsingleton] | _ + 1 => Matrix.conjTranspose_circulant
Mathlib/LinearAlgebra/Matrix/Circulant.lean
86
87
/- Copyright (c) 2024 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Constructions import Mathlib.Data.Set.Notation /-! # Maps between matroids This file defines maps and comaps, which move a matroid on one type to a matroid on another using a function between the types. The constructions are (up to isomorphism) just combinations of restrictions and parallel extensions, so are not mathematically difficult. Because a matroid `M : Matroid Ξ±` is defined with am embedded ground set `M.E : Set Ξ±` which contains all the structure of `M`, there are several types of map and comap one could reasonably ask for; for instance, we could map `M : Matroid Ξ±` to a `Matroid Ξ²` using either a function `f : Ξ± β†’ Ξ²`, a function `f : ↑M.E β†’ Ξ²` or indeed a function `f : ↑M.E β†’ ↑E` for some `E : Set Ξ²`. We attempt to give definitions that capture most reasonable use cases. `Matroid.map` and `Matroid.comap` are defined in terms of bare functions rather than functions defined on subtypes, so are often easier to work in practice than the subtype variants. In fact, the statement that `N = Matroid.map M f _` for some `f : Ξ± β†’ Ξ²` is equivalent to the existence of an isomorphism from `M` to `N`, except in the trivial degenerate case where `M` is an empty matroid on a nonempty type and `N` is an empty matroid on an empty type. This can be simpler to use than an actual formal isomorphism, which requires subtypes. ## Main definitions In the definitions below, `M` and `N` are matroids on `Ξ±` and `Ξ²` respectively. * For `f : Ξ± β†’ Ξ²`, `Matroid.comap N f` is the matroid on `Ξ±` with ground set `f ⁻¹' N.E` in which each `I` is independent if and only if `f` is injective on `I` and `f '' I` is independent in `N`. (For each nonloop `x` of `N`, the set `f ⁻¹' {x}` is a parallel class of `N.comap f`) * `Matroid.comapOn N f E` is the restriction of `N.comap f` to `E` for some `E : Set Ξ±`. * For an embedding `f : M.E β†ͺ Ξ²` defined on the subtype `↑M.E`, `Matroid.mapSetEmbedding M f` is the matroid on `Ξ²` with ground set `range f` whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`. * For a function `f : Ξ± β†’ Ξ²` and a proof `hf` that `f` is injective on `M.E`, `Matroid.map f hf` is the matroid on `Ξ²` with ground set `f '' M.E` whose independent sets are the images of those in `M`. This matroid is isomorphic to `M`, and does not depend on the values `f` takes outside `M.E`. * `Matroid.mapEmbedding f` is a version of `Matroid.map` where `f : Ξ± β†ͺ Ξ²` is a bundled embedding. It is defined separately because the global injectivity of `f` gives some nicer `simp` lemmas. * `Matroid.mapEquiv f` is a version of `Matroid.map` where `f : Ξ± ≃ Ξ²` is a bundled equivalence. It is defined separately because we get even nicer `simp` lemmas. * `Matroid.mapSetEquiv f` is a version of `Matroid.map` where `f : M.E ≃ E` is an equivalence on subtypes. It gives a matroid on `Ξ²` with ground set `E`. * For `X : Set Ξ±`, `Matroid.restrictSubtype M X` is the `Matroid β†₯X` with ground set `univ : Set β†₯X`. This matroid is isomorphic to `M β†Ύ X`. ## Implementation details The definition of `comap` is the only place where we need to actually define a matroid from scratch. After `comap` is defined, we can define `map` and its variants indirectly in terms of `comap`. If `f : Ξ± β†’ Ξ²` is injective on `M.E`, the independent sets of `M.map f hf` are the images of the independent set of `M`; i.e. `(M.map f hf).Indep I ↔ βˆƒ Iβ‚€, M.Indep Iβ‚€ ∧ I = f '' Iβ‚€`. But if `f` is globally injective, we can phrase this more directly; indeed, `(M.map f _).Indep I ↔ M.Indep (f ⁻¹' I) ∧ I βŠ† range f`. If `f` is an equivalence we have `(M.map f _).Indep I ↔ M.Indep (f.symm '' I)`. In order that these stronger statements can be `@[simp]`, we define `mapEmbedding` and `mapEquiv` separately from `map`. ## Notes For finite matroids, both maps and comaps are a special case of a construction of Perfect [perfect1969matroid] in which a matroid structure can be transported across an arbitrary bipartite graph that may not correspond to a function at all (See [oxley2011], Theorem 11.2.12). It would have been nice to use this more general construction as a basis for the definition of both `Matroid.map` and `Matroid.comap`. Unfortunately, we can't do this, because the construction doesn't extend to infinite matroids. Specifically, if `M₁` and `Mβ‚‚` are matroids on the same type `Ξ±`, and `f` is the natural function from `Ξ± βŠ• Ξ±` to `Ξ±`, then the images under `f` of the independent sets of the direct sum `M₁ βŠ• Mβ‚‚` are the independent sets of a matroid if and only if the union of `M₁` and `Mβ‚‚` is a matroid, and unions do not exist for some pairs of infinite matroids: see [aignerhorev2012infinite]. For this reason, `Matroid.map` requires injectivity to be well-defined in general. ## TODO * Bundled matroid isomorphisms. * Maps of finite matroids across bipartite graphs. ## References * [E. Aigner-Horev, J. Carmesin, J. FrΓΆhlic, Infinite Matroid Union][aignerhorev2012infinite] * [H. Perfect, Independence Spaces and Combinatorial Problems][perfect1969matroid] * [J. Oxley, Matroid Theory][oxley2011] -/ assert_not_exists Field open Set Function Set.Notation namespace Matroid variable {Ξ± Ξ² : Type*} {f : Ξ± β†’ Ξ²} {E I : Set Ξ±} {M : Matroid Ξ±} {N : Matroid Ξ²} section comap /-- The pullback of a matroid on `Ξ²` by a function `f : Ξ± β†’ Ξ²` to a matroid on `Ξ±`. Elements with the same (nonloop) image are parallel and the ground set is `f ⁻¹' M.E`. The matroids `M.comap f` and `M β†Ύ range f` have isomorphic simplifications; the preimage of each nonloop of `M β†Ύ range f` is a parallel class. -/ def comap (N : Matroid Ξ²) (f : Ξ± β†’ Ξ²) : Matroid Ξ± := IndepMatroid.matroid <| { E := f ⁻¹' N.E Indep := fun I ↦ N.Indep (f '' I) ∧ InjOn f I indep_empty := by simp indep_subset := fun _ _ h hIJ ↦ ⟨h.1.subset (image_subset _ hIJ), InjOn.mono hIJ h.2⟩ indep_aug := by rintro I B ⟨hI, hIinj⟩ hImax hBmax obtain ⟨I', hII', hI', hI'inj⟩ := (not_maximal_subset_iff ⟨hI, hIinj⟩).1 hImax have h₁ : Β¬(N β†Ύ range f).IsBase (f '' I) := by refine fun hB ↦ hII'.ne ?_ have h_im := hB.eq_of_subset_indep (by simpa) (image_subset _ hII'.subset) rwa [hI'inj.image_eq_image_iff hII'.subset Subset.rfl] at h_im have hβ‚‚ : (N β†Ύ range f).IsBase (f '' B) := by refine Indep.isBase_of_forall_insert (by simpa using hBmax.1.1) ?_ rintro _ ⟨⟨e, heB, rfl⟩, hfe⟩ hi rw [restrict_indep_iff, ← image_insert_eq] at hi have hinj : InjOn f (insert e B) := by rw [injOn_insert (fun heB ↦ hfe (mem_image_of_mem f heB))] exact ⟨hBmax.1.2, hfe⟩ refine hBmax.not_prop_of_ssuperset (t := insert e B) (ssubset_insert ?_) ⟨hi.1, hinj⟩ exact fun heB ↦ hfe <| mem_image_of_mem f heB obtain ⟨_, ⟨⟨e, he, rfl⟩, he'⟩, hei⟩ := Indep.exists_insert_of_not_isBase (by simpa) h₁ hβ‚‚ have heI : e βˆ‰ I := fun heI ↦ he' (mem_image_of_mem f heI) rw [← image_insert_eq, restrict_indep_iff] at hei exact ⟨e, ⟨he, heI⟩, hei.1, (injOn_insert heI).2 ⟨hIinj, he'⟩⟩ indep_maximal := by rintro X - I ⟨hI, hIinj⟩ hIX obtain ⟨J, hJ⟩ := (N β†Ύ range f).existsMaximalSubsetProperty_indep (f '' X) (by simp) (f '' I) (by simpa) (image_subset _ hIX) simp only [restrict_indep_iff, image_subset_iff, maximal_subset_iff, mem_setOf_eq, and_imp, and_assoc] at hJ ⊒ obtain ⟨hIJ, hJ, hJf, hJX, hJmax⟩ := hJ obtain ⟨Jβ‚€, hIJβ‚€, hJβ‚€X, hbj⟩ := hIinj.bijOn_image.exists_extend_of_subset hIX (image_subset f hIJ) (image_subset_iff.2 <| preimage_mono hJX) obtain rfl : f '' Jβ‚€ = J := by rw [← image_preimage_eq_of_subset hJf, hbj.image_eq] refine ⟨Jβ‚€, hIJβ‚€, hJ, hbj.injOn, hJβ‚€X, fun K hK hKinj hKX hJβ‚€K ↦ ?_⟩ rw [← hKinj.image_eq_image_iff hJβ‚€K Subset.rfl, hJmax hK (image_subset_range _ _) (image_subset f hKX) (image_subset f hJβ‚€K)] subset_ground := fun _ hI e heI ↦ hI.1.subset_ground ⟨e, heI, rfl⟩ } @[simp] lemma comap_indep_iff : (N.comap f).Indep I ↔ N.Indep (f '' I) ∧ InjOn f I := Iff.rfl @[simp] lemma comap_ground_eq (N : Matroid Ξ²) (f : Ξ± β†’ Ξ²) : (N.comap f).E = f ⁻¹' N.E := rfl @[simp] lemma comap_dep_iff : (N.comap f).Dep I ↔ N.Dep (f '' I) ∨ (N.Indep (f '' I) ∧ Β¬ InjOn f I) := by rw [Dep, comap_indep_iff, not_and, comap_ground_eq, Dep, image_subset_iff] refine ⟨fun ⟨hi, h⟩ ↦ ?_, ?_⟩ Β· rw [and_iff_left h, ← imp_iff_not_or] exact fun hI ↦ ⟨hI, hi hI⟩ rintro (⟨hI, hIE⟩ | hI) Β· exact ⟨fun h ↦ (hI h).elim, hIE⟩ rw [iff_true_intro hI.1, iff_true_intro hI.2, implies_true, true_and] simpa using hI.1.subset_ground @[simp] lemma comap_id (N : Matroid Ξ²) : N.comap id = N := ext_indep rfl <| by simp [injective_id.injOn] lemma comap_indep_iff_of_injOn (hf : InjOn f (f ⁻¹' N.E)) : (N.comap f).Indep I ↔ N.Indep (f '' I) := by rw [comap_indep_iff, and_iff_left_iff_imp] refine fun hi ↦ hf.mono <| subset_trans ?_ (preimage_mono hi.subset_ground) apply subset_preimage_image @[simp] lemma comap_emptyOn (f : Ξ± β†’ Ξ²) : comap (emptyOn Ξ²) f = emptyOn Ξ± := by simp [← ground_eq_empty_iff] @[simp] lemma comap_loopyOn (f : Ξ± β†’ Ξ²) (E : Set Ξ²) : comap (loopyOn E) f = loopyOn (f ⁻¹' E) := by rw [eq_loopyOn_iff]; aesop @[simp] lemma comap_isBasis_iff {I X : Set Ξ±} : (N.comap f).IsBasis I X ↔ N.IsBasis (f '' I) (f '' X) ∧ I.InjOn f ∧ I βŠ† X := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· obtain ⟨hI, hinj⟩ := comap_indep_iff.1 h.indep refine ⟨hI.isBasis_of_forall_insert (image_subset f h.subset) fun e he ↦ ?_, hinj, h.subset⟩ simp only [mem_diff, mem_image, not_exists, not_and, and_imp, forall_exists_index, forall_apply_eq_imp_iffβ‚‚] at he obtain ⟨⟨e, heX, rfl⟩, he⟩ := he have heI : e βˆ‰ I := fun heI ↦ (he e heI rfl) replace h := h.insert_dep ⟨heX, heI⟩ simp only [comap_dep_iff, image_insert_eq, or_iff_not_imp_right, injOn_insert heI, hinj, mem_image, not_exists, not_and, true_and, not_forall, Classical.not_imp, not_not] at h exact h (fun _ ↦ he) refine Indep.isBasis_of_forall_insert ?_ h.2.2 fun e ⟨heX, heI⟩ ↦ ?_ Β· simp [comap_indep_iff, h.1.indep, h.2] have hIE : insert e I βŠ† (N.comap f).E := by simp_rw [comap_ground_eq, ← image_subset_iff] exact (image_subset _ (insert_subset heX h.2.2)).trans h.1.subset_ground suffices N.Indep (insert (f e) (f '' I)) β†’ βˆƒ x ∈ I, f x = f e by simpa [← not_indep_iff hIE, injOn_insert heI, h.2.1, image_insert_eq] exact h.1.mem_of_insert_indep (mem_image_of_mem f heX) @[simp] lemma comap_isBase_iff {B : Set Ξ±} : (N.comap f).IsBase B ↔ N.IsBasis (f '' B) (f '' (f ⁻¹' N.E)) ∧ B.InjOn f ∧ B βŠ† f ⁻¹' N.E := by rw [← isBasis_ground_iff, comap_isBasis_iff]; rfl @[simp] lemma comap_isBasis'_iff {I X : Set Ξ±} : (N.comap f).IsBasis' I X ↔ N.IsBasis' (f '' I) (f '' X) ∧ I.InjOn f ∧ I βŠ† X := by simp only [isBasis'_iff_isBasis_inter_ground, comap_ground_eq, comap_isBasis_iff, image_inter_preimage, subset_inter_iff, ← and_assoc, and_congr_left_iff, and_iff_left_iff_imp, and_imp] exact fun h _ _ ↦ (image_subset_iff.1 h.indep.subset_ground) instance comap_finitary (N : Matroid Ξ²) [N.Finitary] (f : Ξ± β†’ Ξ²) : (N.comap f).Finitary := by refine ⟨fun I hI ↦ ?_⟩ rw [comap_indep_iff, indep_iff_forall_finite_subset_indep] simp only [forall_subset_image_iff] refine ⟨fun J hJ hfin ↦ ?_, fun x hx y hy ↦ (hI _ (pair_subset hx hy) (by simp)).2 (by simp) (by simp)⟩ obtain ⟨J', hJ'J, hJ'⟩ := (surjOn_image f J).exists_bijOn_subset rw [← hJ'.image_eq] at hfin ⊒ exact (hI J' (hJ'J.trans hJ) (hfin.of_finite_image hJ'.injOn)).1 instance comap_rankFinite (N : Matroid Ξ²) [N.RankFinite] (f : Ξ± β†’ Ξ²) : (N.comap f).RankFinite := by obtain ⟨B, hB⟩ := (N.comap f).exists_isBase refine hB.rankFinite_of_finite ?_ simp only [comap_isBase_iff] at hB exact (hB.1.indep.finite.of_finite_image hB.2.1) end comap section comapOn variable {E B I : Set Ξ±} /-- The pullback of a matroid on `Ξ²` by a function `f : Ξ± β†’ Ξ²` to a matroid on `Ξ±`, restricted to a ground set `E`. The matroids `M.comapOn f E` and `M β†Ύ (f '' E)` have isomorphic simplifications; elements with the same nonloop image are parallel. -/ def comapOn (N : Matroid Ξ²) (E : Set Ξ±) (f : Ξ± β†’ Ξ²) : Matroid Ξ± := (N.comap f) β†Ύ E lemma comapOn_preimage_eq (N : Matroid Ξ²) (f : Ξ± β†’ Ξ²) : N.comapOn (f ⁻¹' N.E) f = N.comap f := by rw [comapOn, restrict_eq_self_iff]; rfl @[simp] lemma comapOn_indep_iff : (N.comapOn E f).Indep I ↔ (N.Indep (f '' I) ∧ InjOn f I ∧ I βŠ† E) := by simp [comapOn, and_assoc] @[simp] lemma comapOn_ground_eq : (N.comapOn E f).E = E := rfl lemma comapOn_isBase_iff : (N.comapOn E f).IsBase B ↔ N.IsBasis' (f '' B) (f '' E) ∧ B.InjOn f ∧ B βŠ† E := by rw [comapOn, isBase_restrict_iff', comap_isBasis'_iff] lemma comapOn_isBase_iff_of_surjOn (h : SurjOn f E N.E) : (N.comapOn E f).IsBase B ↔ (N.IsBase (f '' B) ∧ InjOn f B ∧ B βŠ† E) := by simp_rw [comapOn_isBase_iff, and_congr_left_iff, and_imp, isBasis'_iff_isBasis_inter_ground, inter_eq_self_of_subset_right h, isBasis_ground_iff, implies_true] lemma comapOn_isBase_iff_of_bijOn (h : BijOn f E N.E) : (N.comapOn E f).IsBase B ↔ N.IsBase (f '' B) ∧ B βŠ† E := by rw [← and_iff_left_of_imp (IsBase.subset_ground (M := N.comapOn E f) (B := B)), comapOn_ground_eq, and_congr_left_iff] suffices h' : B βŠ† E β†’ InjOn f B from fun hB ↦ by simp [hB, comapOn_isBase_iff_of_surjOn h.surjOn, h'] exact fun hBE ↦ h.injOn.mono hBE lemma comapOn_dual_eq_of_bijOn (h : BijOn f E N.E) : (N.comapOn E f)✢ = N✢.comapOn E f := by refine ext_isBase (by simp) (fun B hB ↦ ?_) rw [comapOn_isBase_iff_of_bijOn (by simpa), dual_isBase_iff, comapOn_isBase_iff_of_bijOn h, dual_isBase_iff _, comapOn_ground_eq, and_iff_left diff_subset, and_iff_left (by simpa), h.injOn.image_diff_subset (by simpa), h.image_eq] exact (h.mapsTo.mono_left (show B βŠ† E by simpa)).image_subset instance comapOn_finitary [N.Finitary] : (N.comapOn E f).Finitary := by rw [comapOn]; infer_instance instance comapOn_rankFinite [N.RankFinite] : (N.comapOn E f).RankFinite := by rw [comapOn]; infer_instance end comapOn section mapSetEmbedding /-- Map a matroid `M` to an isomorphic copy in `Ξ²` using an embedding `M.E β†ͺ Ξ²`. -/ def mapSetEmbedding (M : Matroid Ξ±) (f : M.E β†ͺ Ξ²) : Matroid Ξ² := Matroid.ofExistsMatroid (E := range f) (Indep := fun I ↦ M.Indep ↑(f ⁻¹' I) ∧ I βŠ† range f) (hM := by classical obtain (rfl | ⟨⟨e,he⟩⟩) := eq_emptyOn_or_nonempty M Β· refine ⟨emptyOn Ξ², ?_⟩ simp only [emptyOn_ground] at f simp [range_eq_empty f, subset_empty_iff] have _ : Nonempty M.E := ⟨⟨e,he⟩⟩ have _ : Nonempty Ξ± := ⟨e⟩ refine ⟨M.comapOn (range f) (fun x ↦ ↑(invFunOn f univ x)), rfl, ?_⟩ simp_rw [comapOn_indep_iff, ← and_assoc, and_congr_left_iff, subset_range_iff_exists_image_eq] rintro _ ⟨I, rfl⟩ rw [← image_image, InjOn.invFunOn_image f.injective.injOn (subset_univ _), preimage_image_eq _ f.injective, and_iff_left_iff_imp] rintro - x hx y hy simp only [EmbeddingLike.apply_eq_iff_eq, Subtype.val_inj] exact (invFunOn_injOn_image f univ) (image_subset f (subset_univ I) hx) (image_subset f (subset_univ I) hy) ) @[simp] lemma mapSetEmbedding_ground (M : Matroid Ξ±) (f : M.E β†ͺ Ξ²) : (M.mapSetEmbedding f).E = range f := rfl @[simp] lemma mapSetEmbedding_indep_iff {f : M.E β†ͺ Ξ²} {I : Set Ξ²} : (M.mapSetEmbedding f).Indep I ↔ M.Indep ↑(f ⁻¹' I) ∧ I βŠ† range f := Iff.rfl lemma Indep.exists_eq_image_of_mapSetEmbedding {f : M.E β†ͺ Ξ²} {I : Set Ξ²} (hI : (M.mapSetEmbedding f).Indep I) : βˆƒ (Iβ‚€ : Set M.E), M.Indep Iβ‚€ ∧ I = f '' Iβ‚€ := ⟨f ⁻¹' I, hI.1, Eq.symm <| image_preimage_eq_of_subset hI.2⟩ lemma mapSetEmbedding_indep_iff' {f : M.E β†ͺ Ξ²} {I : Set Ξ²} : (M.mapSetEmbedding f).Indep I ↔ βˆƒ (Iβ‚€ : Set M.E), M.Indep ↑Iβ‚€ ∧ I = f '' Iβ‚€ := by simp only [mapSetEmbedding_indep_iff, subset_range_iff_exists_image_eq] constructor Β· rintro ⟨hI, I, rfl⟩ exact ⟨I, by rwa [preimage_image_eq _ f.injective] at hI, rfl⟩ rintro ⟨I, hI, rfl⟩ rw [preimage_image_eq _ f.injective] exact ⟨hI, _, rfl⟩ end mapSetEmbedding section map /-- Given a function `f` that is injective on `M.E`, the copy of `M` in `Ξ²` whose independent sets are the images of those in `M`. If `Ξ²` is a nonempty type, then `N : Matroid Ξ²` is a map of `M` if and only if `M` and `N` are isomorphic. -/ def map (M : Matroid Ξ±) (f : Ξ± β†’ Ξ²) (hf : InjOn f M.E) : Matroid Ξ² := Matroid.ofExistsMatroid (E := f '' M.E) (Indep := fun I ↦ βˆƒ Iβ‚€, M.Indep Iβ‚€ ∧ I = f '' Iβ‚€) (hM := by refine ⟨M.mapSetEmbedding ⟨_, hf.injective⟩, by simp, fun I ↦ ?_⟩ simp_rw [mapSetEmbedding_indep_iff', Embedding.coeFn_mk, restrict_apply, ← image_image f Subtype.val, Subtype.exists_set_subtype (p := fun J ↦ M.Indep J ∧ I = f '' J)] exact ⟨fun ⟨Iβ‚€, _, hIβ‚€βŸ© ↦ ⟨Iβ‚€, hIβ‚€βŸ©, fun ⟨Iβ‚€, hIβ‚€βŸ© ↦ ⟨Iβ‚€, hIβ‚€.1.subset_ground, hIβ‚€βŸ©βŸ©) @[simp] lemma map_ground (M : Matroid Ξ±) (f : Ξ± β†’ Ξ²) (hf) : (M.map f hf).E = f '' M.E := rfl @[simp] lemma map_indep_iff {hf} {I : Set Ξ²} : (M.map f hf).Indep I ↔ βˆƒ Iβ‚€, M.Indep Iβ‚€ ∧ I = f '' Iβ‚€ := Iff.rfl lemma Indep.map (hI : M.Indep I) (f : Ξ± β†’ Ξ²) (hf) : (M.map f hf).Indep (f '' I) := map_indep_iff.2 ⟨I, hI, rfl⟩ lemma Indep.exists_bijOn_of_map {I : Set Ξ²} (hf) (hI : (M.map f hf).Indep I) : βˆƒ Iβ‚€, M.Indep Iβ‚€ ∧ BijOn f Iβ‚€ I := by obtain ⟨Iβ‚€, hIβ‚€, rfl⟩ := hI exact ⟨Iβ‚€, hIβ‚€, (hf.mono hIβ‚€.subset_ground).bijOn_image⟩ lemma map_image_indep_iff {hf} {I : Set Ξ±} (hI : I βŠ† M.E) : (M.map f hf).Indep (f '' I) ↔ M.Indep I := by rw [map_indep_iff] refine ⟨fun ⟨J, hJ, hIJ⟩ ↦ ?_, fun h ↦ ⟨I, h, rfl⟩⟩ rw [hf.image_eq_image_iff hI hJ.subset_ground] at hIJ; rwa [hIJ]
@[simp] lemma map_isBase_iff (M : Matroid Ξ±) (f : Ξ± β†’ Ξ²) (hf) {B : Set Ξ²} : (M.map f hf).IsBase B ↔ βˆƒ Bβ‚€, M.IsBase Bβ‚€ ∧ B = f '' Bβ‚€ := by rw [isBase_iff_maximal_indep] refine ⟨fun h ↦ ?_, ?_⟩ Β· obtain ⟨Bβ‚€, hBβ‚€, hbij⟩ := h.prop.exists_bijOn_of_map refine ⟨Bβ‚€, hBβ‚€.isBase_of_maximal fun J hJ hBβ‚€J ↦ ?_, hbij.image_eq.symm⟩ rw [← hf.image_eq_image_iff hBβ‚€.subset_ground hJ.subset_ground, hbij.image_eq] exact h.eq_of_subset (hJ.map f hf) (hbij.image_eq β–Έ image_subset f hBβ‚€J) rintro ⟨B, hB, rfl⟩ rw [maximal_subset_iff] refine ⟨hB.indep.map f hf, fun I hI hBI ↦ ?_⟩ obtain ⟨Iβ‚€, hIβ‚€, hbij⟩ := hI.exists_bijOn_of_map rw [← hbij.image_eq, hf.image_subset_image_iff hB.subset_ground hIβ‚€.subset_ground] at hBI
Mathlib/Data/Matroid/Map.lean
374
386
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.GroupTheory.GroupAction.SubMulAction import Mathlib.Algebra.Group.Pointwise.Set.Basic /-! # Pointwise monoid structures on SubMulAction This file provides `SubMulAction.Monoid` and weaker typeclasses, which show that `SubMulAction`s inherit the same pointwise multiplications as sets. To match `Submodule.idemSemiring`, we do not put these in the `Pointwise` locale. -/ open Pointwise variable {R M : Type*} namespace SubMulAction section One variable [Monoid R] [MulAction R M] [One M] instance : One (SubMulAction R M) where one := { carrier := Set.range fun r : R => r β€’ (1 : M) smul_mem' := fun r _ ⟨r', hr'⟩ => hr' β–Έ ⟨r * r', mul_smul _ _ _⟩ } theorem coe_one : ↑(1 : SubMulAction R M) = Set.range fun r : R => r β€’ (1 : M) := rfl @[simp] theorem mem_one {x : M} : x ∈ (1 : SubMulAction R M) ↔ βˆƒ r : R, r β€’ (1 : M) = x := Iff.rfl theorem subset_coe_one : (1 : Set M) βŠ† (1 : SubMulAction R M) := fun _ hx => ⟨1, (one_smul _ _).trans hx.symm⟩ end One section Mul variable [Monoid R] [MulAction R M] [Mul M] [IsScalarTower R M M] instance : Mul (SubMulAction R M) where mul p q := { carrier := Set.image2 (Β· * Β·) p q smul_mem' := fun r _ ⟨m₁, hm₁, mβ‚‚, hmβ‚‚, h⟩ => h β–Έ smul_mul_assoc r m₁ mβ‚‚ β–Έ Set.mul_mem_mul (p.smul_mem _ hm₁) hmβ‚‚ } @[norm_cast] theorem coe_mul (p q : SubMulAction R M) : ↑(p * q) = (p * q : Set M) := rfl theorem mem_mul {p q : SubMulAction R M} {x : M} : x ∈ p * q ↔ βˆƒ y ∈ p, βˆƒ z ∈ q, y * z = x := Set.mem_mul end Mul section MulOneClass variable [Monoid R] [MulAction R M] [MulOneClass M] [IsScalarTower R M M] [SMulCommClass R M M] -- Porting note: giving the instance the name `mulOneClass` instance mulOneClass : MulOneClass (SubMulAction R M) where mul := (Β· * Β·) one := 1 mul_one a := by ext x simp only [mem_mul, mem_one, mul_smul_comm, exists_exists_eq_and, mul_one] constructor Β· rintro ⟨y, hy, r, rfl⟩ exact smul_mem _ _ hy Β· intro hx exact ⟨x, hx, 1, one_smul _ _⟩ one_mul a := by ext x simp only [mem_mul, mem_one, smul_mul_assoc, exists_exists_eq_and, one_mul] refine ⟨?_, fun hx => ⟨1, x, hx, one_smul _ _⟩⟩ rintro ⟨r, y, hy, rfl⟩ exact smul_mem _ _ hy end MulOneClass section Semigroup variable [Monoid R] [MulAction R M] [Semigroup M] [IsScalarTower R M M] -- Porting note: giving the instance the name `semiGroup` instance semiGroup : Semigroup (SubMulAction R M) where mul := (Β· * Β·) mul_assoc _ _ _ := SetLike.coe_injective (mul_assoc (_ : Set _) _ _) end Semigroup section Monoid variable [Monoid R] [MulAction R M] [Monoid M] [IsScalarTower R M M] [SMulCommClass R M M] instance : Monoid (SubMulAction R M) := { SubMulAction.semiGroup, SubMulAction.mulOneClass with } theorem coe_pow (p : SubMulAction R M) : βˆ€ {n : β„•} (_ : n β‰  0), ↑(p ^ n) = (p : Set M) ^ n | 0, hn => (hn rfl).elim | 1, _ => by rw [pow_one, pow_one] | n + 2, _ => by rw [pow_succ _ (n + 1), pow_succ _ (n + 1), coe_mul, coe_pow _ n.succ_ne_zero]
theorem subset_coe_pow (p : SubMulAction R M) : βˆ€ {n : β„•}, (p : Set M) ^ n βŠ† ↑(p ^ n) | 0 => by rw [pow_zero, pow_zero] exact subset_coe_one | n + 1 => by rw [← Nat.succ_eq_add_one, coe_pow _ n.succ_ne_zero]
Mathlib/GroupTheory/GroupAction/SubMulAction/Pointwise.lean
116
120
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes HΓΆlzl, Kim Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Data.Set.Finite.Lemmas import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Localization.FractionRing import Mathlib.SetTheory.Cardinal.Order /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ assert_not_exists Ideal open Multiset Finset noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β„•} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) := by rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl theorem card_roots (hp0 : p β‰  0) : (Multiset.card (roots p) : WithBot β„•) ≀ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 theorem card_roots' (p : R[X]) : Multiset.card p.roots ≀ natDegree p := by by_cases hp0 : p = 0 Β· simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree p := calc (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm β–Έ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≀ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 Β· simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a @[simp] theorem mem_roots' : a ∈ p.roots ↔ p β‰  0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] theorem mem_roots (hp : p β‰  0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p β‰  0 := (mem_roots'.1 h).1 theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β†’+* R} (hf : Function.Injective f) {x : R} (hp : p β‰  0) : x ∈ (p.map f).roots ↔ p.evalβ‚‚ f x = 0 := by rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map] lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β‰  0) : x ∈ roots p ↔ aeval x p = 0 := by rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w, Algebra.id.map_eq_id, map_id] theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val βŠ† p.roots) : #Z ≀ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) theorem finite_setOf_isRoot {p : R[X]} (hp : p β‰  0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ x ≀ xβ‚€ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ xβ‚€ ≀ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] theorem roots_mul {p q : R[X]} (hpq : p * q β‰  0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] theorem roots.le_of_dvd (h : q β‰  0) : p ∣ q β†’ roots p ≀ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p β‰  C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm β–Έ degree_C_le @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] @[simp] theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r) @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) @[simp] theorem roots_one : (1 : R[X]).roots = βˆ… := roots_C 1 @[simp] theorem roots_C_mul (p : R[X]) (ha : a β‰  0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a β‰  0) : (a β€’ p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] @[simp] theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots = {a⁻¹ * b} := by rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul, Units.inv_mul, C_1, one_mul] exact roots_X_sub_C (a⁻¹ * b) @[simp] theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots = {-(a⁻¹ * b)} := by rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) βˆ‰ L β†’ L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) βˆ‰ m β†’ m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β†’ R[X]) (s : Finset ΞΉ) : s.prod f β‰  0 β†’ (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) @[simp] theorem roots_pow (p : R[X]) (n : β„•) : (p ^ n).roots = n β€’ p.roots := by induction n with | zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero] | succ n ihn => rcases eq_or_ne p 0 with (rfl | hp) Β· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] Β· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] theorem roots_X_pow (n : β„•) : (X ^ n : R[X]).roots = n β€’ ({0} : Multiset R) := by rw [roots_pow, roots_X] theorem roots_C_mul_X_pow (ha : a β‰  0) (n : β„•) : Polynomial.roots (C a * X ^ n) = n β€’ ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] @[simp] theorem roots_monomial (ha : a β‰  0) (n : β„•) : (monomial n a).roots = n β€’ ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h theorem card_roots_X_pow_sub_C {n : β„•} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≀ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot β„•) ≀ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/ def nthRoots (n : β„•) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) @[simp] theorem mem_nthRoots {n : β„•} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : β„•) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : β„•) (a : R) : Multiset.card (nthRoots n a) ≀ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (Ξ± := WithBot β„•)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ Β¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] /-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be `nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/ def nthRootsFinset (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n a) lemma nthRootsFinset_def (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : β„•} (h : 0 < n) (a : R) {x : R} : x ∈ nthRootsFinset n a ↔ x ^ (n : β„•) = a := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] @[simp] theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = βˆ… := by classical simp [nthRootsFinset_def] theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) : f x ∈ nthRootsFinset n (f a) := by by_cases hn : n = 0 Β· simp [hn] at hx Β· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset (Nat.pos_of_ne_zero hn) a).1 hx] theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) : f x ∈ nthRootsFinset n 1 := by rw [← (map_one f)] exact map_mem_nthRootsFinset hx _ theorem mul_mem_nthRootsFinset {η₁ Ξ·β‚‚ : R} {a₁ aβ‚‚ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hΞ·β‚‚ : Ξ·β‚‚ ∈ nthRootsFinset n aβ‚‚) : η₁ * Ξ·β‚‚ ∈ nthRootsFinset n (a₁ * aβ‚‚) := by cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hΞ·β‚‚ ⊒ rw [mul_pow, hη₁, hΞ·β‚‚] theorem ne_zero_of_mem_nthRootsFinset {Ξ· : R} {a : R} (ha : a β‰  0) (hΞ· : Ξ· ∈ nthRootsFinset n a) : Ξ· β‰  0 := by nontriviality R rintro rfl cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hΞ· | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hΞ· exact ha hΞ·.symm theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : βˆ€ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ theorem funext [Infinite R] {p q : R[X]} (ext : βˆ€ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) β‰  0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← evalβ‚‚_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p β‰  0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact FaithfulSMul.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q β‰  0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q β‰  0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp] theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1 @[simp] theorem aroots_neg [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) : (-p).aroots S = p.aroots S := by rw [aroots, Polynomial.map_neg, roots_neg] @[simp] theorem aroots_C_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β‰  0) : (C a * p).aroots S = p.aroots S := by rw [aroots_def, Polynomial.map_mul, map_C, roots_C_mul] rwa [map_ne_zero_iff] exact FaithfulSMul.algebraMap_injective T S @[simp] theorem aroots_smul_nonzero [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (p : T[X]) (ha : a β‰  0) : (a β€’ p).aroots S = p.aroots S := by rw [smul_eq_C_mul, aroots_C_mul _ ha] @[simp] theorem aroots_pow [CommRing S] [IsDomain S] [Algebra T S] (p : T[X]) (n : β„•) : (p ^ n).aroots S = n β€’ p.aroots S := by rw [aroots_def, Polynomial.map_pow, roots_pow] theorem aroots_X_pow [CommRing S] [IsDomain S] [Algebra T S] (n : β„•) : (X ^ n : T[X]).aroots S = n β€’ ({0} : Multiset S) := by rw [aroots_pow, aroots_X] theorem aroots_C_mul_X_pow [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a β‰  0) (n : β„•) : (C a * X ^ n : T[X]).aroots S = n β€’ ({0} : Multiset S) := by rw [aroots_C_mul _ ha, aroots_X_pow] @[simp] theorem aroots_monomial [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : T} (ha : a β‰  0) (n : β„•) : (monomial n a).aroots S = n β€’ ({0} : Multiset S) := by rw [← C_mul_X_pow_eq_monomial, aroots_C_mul_X_pow ha] variable (R S) in @[simp] theorem aroots_map (p : T[X]) [CommRing S] [Algebra T S] [Algebra S R] [Algebra T R] [IsScalarTower T S R] : (p.map (algebraMap T S)).aroots R = p.aroots R := by rw [aroots_def, aroots_def, map_map, IsScalarTower.algebraMap_eq T S R] /-- The set of distinct roots of `p` in `S`. If you have a non-separable polynomial, use `Polynomial.aroots` for the multiset where multiple roots have the appropriate multiplicity. -/ def rootSet (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Set S := haveI := Classical.decEq S (p.aroots S).toFinset theorem rootSet_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] [DecidableEq S] : p.rootSet S = (p.aroots S).toFinset := by rw [rootSet] convert rfl @[simp] theorem rootSet_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).rootSet S = βˆ… := by classical rw [rootSet_def, aroots_C, Multiset.toFinset_zero, Finset.coe_empty] @[simp] theorem rootSet_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).rootSet S = βˆ… := by rw [← C_0, rootSet_C] @[simp] theorem rootSet_one (S) [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).rootSet S = βˆ… := by rw [← C_1, rootSet_C] @[simp] theorem rootSet_neg (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : (-p).rootSet S = p.rootSet S := by rw [rootSet, aroots_neg, rootSet] instance rootSetFintype (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : Fintype (p.rootSet S) := FinsetCoe.fintype _ theorem rootSet_finite (p : T[X]) (S : Type*) [CommRing S] [IsDomain S] [Algebra T S] : (p.rootSet S).Finite := Set.toFinite _ /-- The set of roots of all polynomials of bounded degree and having coefficients in a finite set is finite. -/ theorem bUnion_roots_finite {R S : Type*} [Semiring R] [CommRing S] [IsDomain S] [DecidableEq S] (m : R β†’+* S) (d : β„•) {U : Set R} (h : U.Finite) : (⋃ (f : R[X]) (_ : f.natDegree ≀ d ∧ βˆ€ i, f.coeff i ∈ U), ((f.map m).roots.toFinset.toSet : Set S)).Finite := Set.Finite.biUnion (by -- We prove that the set of polynomials under consideration is finite because its -- image by the injective map `Ο€` is finite let Ο€ : R[X] β†’ Fin (d + 1) β†’ R := fun f i => f.coeff i refine ((Set.Finite.pi fun _ => h).subset <| ?_).of_finite_image (?_ : Set.InjOn Ο€ _) Β· exact Set.image_subset_iff.2 fun f hf i _ => hf.2 i Β· refine fun x hx y hy hxy => (ext_iff_natDegree_le hx.1 hy.1).2 fun i hi => ?_ exact id congr_fun hxy ⟨i, Nat.lt_succ_of_le hi⟩) fun _ _ => Finset.finite_toSet _ theorem mem_rootSet' {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] {a : S} : a ∈ p.rootSet S ↔ p.map (algebraMap T S) β‰  0 ∧ aeval a p = 0 := by classical rw [rootSet_def, Finset.mem_coe, mem_toFinset, mem_aroots'] theorem mem_rootSet {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {a : S} : a ∈ p.rootSet S ↔ p β‰  0 ∧ aeval a p = 0 := by rw [mem_rootSet', Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)] theorem mem_rootSet_of_ne {p : T[X]} {S : Type*} [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] (hp : p β‰  0) {a : S} : a ∈ p.rootSet S ↔ aeval a p = 0 := mem_rootSet.trans <| and_iff_right hp theorem rootSet_maps_to' {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] (hp : p.map (algebraMap T S') = 0 β†’ p.map (algebraMap T S) = 0) (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := fun x hx => by rw [mem_rootSet'] at hx ⊒ rw [aeval_algHom, AlgHom.comp_apply, hx.2, _root_.map_zero] exact ⟨mt hp hx.1, rfl⟩ theorem ne_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (h : a ∈ p.rootSet S) : p β‰  0 := fun hf => by rwa [hf, rootSet_zero] at h theorem aeval_eq_zero_of_mem_rootSet {p : T[X]} [CommRing S] [IsDomain S] [Algebra T S] {a : S} (hx : a ∈ p.rootSet S) : aeval a p = 0 := (mem_rootSet'.1 hx).2 theorem rootSet_mapsTo {p : T[X]} {S S'} [CommRing S] [IsDomain S] [Algebra T S] [CommRing S'] [IsDomain S'] [Algebra T S'] [NoZeroSMulDivisors T S'] (f : S →ₐ[T] S') : (p.rootSet S).MapsTo f (p.rootSet S') := by refine rootSet_maps_to' (fun hβ‚€ => ?_) f obtain rfl : p = 0 := map_injective _ (FaithfulSMul.algebraMap_injective T S') (by rwa [Polynomial.map_zero]) exact Polynomial.map_zero _ theorem mem_rootSet_of_injective [CommRing S] {p : S[X]} [Algebra S R] (h : Function.Injective (algebraMap S R)) {x : R} (hp : p β‰  0) : x ∈ p.rootSet R ↔ aeval x p = 0 := by classical exact Multiset.mem_toFinset.trans (mem_roots_map_of_injective h hp) end Roots lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero {R} [CommRing R] [IsDomain R] (p : R[X]) {ΞΉ} [Fintype ΞΉ] {f : ΞΉ β†’ R} (hf : Function.Injective f) (heval : βˆ€ i, p.eval (f i) = 0) (hcard : natDegree p < Fintype.card ΞΉ) : p = 0 := by classical by_contra hp refine lt_irrefl #p.roots.toFinset ?_ calc #p.roots.toFinset ≀ Multiset.card p.roots := Multiset.toFinset_card_le _ _ ≀ natDegree p := Polynomial.card_roots' p _ < Fintype.card ΞΉ := hcard _ = Fintype.card (Set.range f) := (Set.card_range_of_injective hf).symm _ = #(Finset.univ.image f) := by rw [← Set.toFinset_card, Set.toFinset_range] _ ≀ #p.roots.toFinset := Finset.card_mono ?_ intro _ simp only [Finset.mem_image, Finset.mem_univ, true_and, Multiset.mem_toFinset, mem_roots', ne_eq, IsRoot.def, forall_exists_index, hp, not_false_eq_true] rintro x rfl exact heval _ lemma eq_zero_of_natDegree_lt_card_of_eval_eq_zero' {R} [CommRing R] [IsDomain R] (p : R[X]) (s : Finset R) (heval : βˆ€ i ∈ s, p.eval i = 0) (hcard : natDegree p < #s) : p = 0 := eq_zero_of_natDegree_lt_card_of_eval_eq_zero p Subtype.val_injective (fun i : s ↦ heval i i.prop) (hcard.trans_eq (Fintype.card_coe s).symm) open Cardinal in lemma eq_zero_of_forall_eval_zero_of_natDegree_lt_card (f : R[X]) (hf : βˆ€ r, f.eval r = 0) (hfR : f.natDegree < #R) : f = 0 := by obtain hR|hR := finite_or_infinite R Β· have := Fintype.ofFinite R apply eq_zero_of_natDegree_lt_card_of_eval_eq_zero f Function.injective_id hf simpa only [mk_fintype, Nat.cast_lt] using hfR Β· exact zero_of_eval_zero _ hf open Cardinal in lemma exists_eval_ne_zero_of_natDegree_lt_card (f : R[X]) (hf : f β‰  0) (hfR : f.natDegree < #R) : βˆƒ r, f.eval r β‰  0 := by contrapose! hf exact eq_zero_of_forall_eval_zero_of_natDegree_lt_card f hf hfR section omit [IsDomain R] theorem monic_multisetProd_X_sub_C (s : Multiset R) : Monic (s.map fun a => X - C a).prod := monic_multiset_prod_of_monic _ _ fun a _ => monic_X_sub_C a theorem monic_prod_X_sub_C {Ξ± : Type*} (b : Ξ± β†’ R) (s : Finset Ξ±) : Monic (∏ a ∈ s, (X - C (b a))) := monic_prod_of_monic _ _ fun a _ => monic_X_sub_C (b a) theorem monic_finprod_X_sub_C {Ξ± : Type*} (b : Ξ± β†’ R) : Monic (∏ᢠ k, (X - C (b k))) := monic_finprod_of_monic _ _ fun a _ => monic_X_sub_C (b a) end theorem prod_multiset_root_eq_finset_root [DecidableEq R] : (p.roots.map fun a => X - C a).prod = p.roots.toFinset.prod fun a => (X - C a) ^ rootMultiplicity a p := by simp only [count_roots, Finset.prod_multiset_map_count] /-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/ theorem prod_multiset_X_sub_C_dvd (p : R[X]) : (p.roots.map fun a => X - C a).prod ∣ p := by classical rw [← map_dvd_map _ (IsFractionRing.injective R <| FractionRing R) (monic_multisetProd_X_sub_C p.roots)] rw [prod_multiset_root_eq_finset_root, Polynomial.map_prod] refine Finset.prod_dvd_of_coprime (fun a _ b _ h => ?_) fun a _ => ?_ Β· simp_rw [Polynomial.map_pow, Polynomial.map_sub, map_C, map_X] exact (pairwise_coprime_X_sub_C (IsFractionRing.injective R <| FractionRing R) h).pow Β· exact Polynomial.map_dvd _ (pow_rootMultiplicity_dvd p a) /-- A Galois connection. -/ theorem _root_.Multiset.prod_X_sub_C_dvd_iff_le_roots {p : R[X]} (hp : p β‰  0) (s : Multiset R) : (s.map fun a => X - C a).prod ∣ p ↔ s ≀ p.roots := by classical exact ⟨fun h => Multiset.le_iff_count.2 fun r => by rw [count_roots, le_rootMultiplicity_iff hp, ← Multiset.prod_replicate, ← Multiset.map_replicate fun a => X - C a, ← Multiset.filter_eq] exact (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| s.filter_le _).trans h, fun h => (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map h).trans p.prod_multiset_X_sub_C_dvd⟩ theorem exists_prod_multiset_X_sub_C_mul (p : R[X]) : βˆƒ q, (p.roots.map fun a => X - C a).prod * q = p ∧ Multiset.card p.roots + q.natDegree = p.natDegree ∧ q.roots = 0 := by obtain ⟨q, he⟩ := p.prod_multiset_X_sub_C_dvd use q, he.symm obtain rfl | hq := eq_or_ne q 0 Β· rw [mul_zero] at he subst he simp constructor Β· conv_rhs => rw [he] rw [(monic_multisetProd_X_sub_C p.roots).natDegree_mul' hq, natDegree_multiset_prod_X_sub_C_eq_card] Β· replace he := congr_arg roots he.symm rw [roots_mul, roots_multiset_prod_X_sub_C] at he exacts [add_eq_left.1 he, mul_ne_zero (monic_multisetProd_X_sub_C p.roots).ne_zero hq] /-- A polynomial `p` that has as many roots as its degree can be written `p = p.leadingCoeff * ∏(X - a)`, for `a` in `p.roots`. -/ theorem C_leadingCoeff_mul_prod_multiset_X_sub_C (hroots : Multiset.card p.roots = p.natDegree) : C p.leadingCoeff * (p.roots.map fun a => X - C a).prod = p := (eq_leadingCoeff_mul_of_monic_of_dvd_of_natDegree_le (monic_multisetProd_X_sub_C p.roots) p.prod_multiset_X_sub_C_dvd ((natDegree_multiset_prod_X_sub_C_eq_card _).trans hroots).ge).symm /-- A monic polynomial `p` that has as many roots as its degree can be written `p = ∏(X - a)`, for `a` in `p.roots`. -/ theorem prod_multiset_X_sub_C_of_monic_of_roots_card_eq (hp : p.Monic) (hroots : Multiset.card p.roots = p.natDegree) : (p.roots.map fun a => X - C a).prod = p := by convert C_leadingCoeff_mul_prod_multiset_X_sub_C hroots rw [hp.leadingCoeff, C_1, one_mul] theorem Monic.isUnit_leadingCoeff_of_dvd {a p : R[X]} (hp : Monic p) (hap : a ∣ p) : IsUnit a.leadingCoeff := isUnit_of_dvd_one (by simpa only [hp.leadingCoeff] using leadingCoeff_dvd_leadingCoeff hap) /-- To check a monic polynomial is irreducible, it suffices to check only for divisors that have smaller degree. See also: `Polynomial.Monic.irreducible_iff_natDegree`. -/ theorem Monic.irreducible_iff_degree_lt {p : R[X]} (p_monic : Monic p) (p_1 : p β‰  1) : Irreducible p ↔ βˆ€ q, degree q ≀ ↑(p.natDegree / 2) β†’ q ∣ p β†’ IsUnit q := by simp only [p_monic.irreducible_iff_lt_natDegree_lt p_1, Finset.mem_Ioc, and_imp, natDegree_pos_iff_degree_pos, natDegree_le_iff_degree_le] constructor Β· rintro h q deg_le dvd by_contra q_unit have := degree_pos_of_not_isUnit_of_dvd_monic p_monic q_unit dvd have hu := p_monic.isUnit_leadingCoeff_of_dvd dvd refine (h _ (monic_of_isUnit_leadingCoeff_inv_smul hu) ?_ ?_ (dvd_trans ?_ dvd)).elim Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)] Β· rwa [degree_smul_of_smul_regular _ (isSMulRegular_of_group _)] Β· rw [Units.smul_def, Polynomial.smul_eq_C_mul, (isUnit_C.mpr (Units.isUnit _)).mul_left_dvd] Β· rintro h q _ deg_pos deg_le dvd exact deg_pos.ne' <| degree_eq_zero_of_isUnit (h q deg_le dvd) end CommRing section variable {A B : Type*} [CommRing A] [CommRing B] theorem le_rootMultiplicity_map {p : A[X]} {f : A β†’+* B} (hmap : map f p β‰  0) (a : A) : rootMultiplicity a p ≀ rootMultiplicity (f a) (p.map f) := by rw [le_rootMultiplicity_iff hmap] refine _root_.trans ?_ ((mapRingHom f).map_dvd (pow_rootMultiplicity_dvd p a)) rw [map_pow, map_sub, coe_mapRingHom, map_X, map_C] theorem eq_rootMultiplicity_map {p : A[X]} {f : A β†’+* B} (hf : Function.Injective f) (a : A) : rootMultiplicity a p = rootMultiplicity (f a) (p.map f) := by by_cases hp0 : p = 0; Β· simp only [hp0, rootMultiplicity_zero, Polynomial.map_zero] apply le_antisymm (le_rootMultiplicity_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) a) rw [le_rootMultiplicity_iff hp0, ← map_dvd_map f hf ((monic_X_sub_C a).pow _), Polynomial.map_pow, Polynomial.map_sub, map_X, map_C] apply pow_rootMultiplicity_dvd theorem count_map_roots [IsDomain A] [DecidableEq B] {p : A[X]} {f : A β†’+* B} (hmap : map f p β‰  0) (b : B) : (p.roots.map f).count b ≀ rootMultiplicity b (p.map f) := by rw [le_rootMultiplicity_iff hmap, ← Multiset.prod_replicate, ← Multiset.map_replicate fun a => X - C a] rw [← Multiset.filter_eq] refine (Multiset.prod_dvd_prod_of_le <| Multiset.map_le_map <| Multiset.filter_le (Eq b) _).trans ?_ convert Polynomial.map_dvd f p.prod_multiset_X_sub_C_dvd simp only [Polynomial.map_multiset_prod, Multiset.map_map] congr; ext1 simp only [Function.comp_apply, Polynomial.map_sub, map_X, map_C] theorem count_map_roots_of_injective [IsDomain A] [DecidableEq B] (p : A[X]) {f : A β†’+* B} (hf : Function.Injective f) (b : B) : (p.roots.map f).count b ≀ rootMultiplicity b (p.map f) := by by_cases hp0 : p = 0 Β· simp only [hp0, roots_zero, Multiset.map_zero, Multiset.count_zero, Polynomial.map_zero, rootMultiplicity_zero, le_refl] Β· exact count_map_roots ((Polynomial.map_ne_zero_iff hf).mpr hp0) b theorem map_roots_le [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (h : p.map f β‰  0) : p.roots.map f ≀ (p.map f).roots := by classical exact Multiset.le_iff_count.2 fun b => by rw [count_roots] apply count_map_roots h theorem map_roots_le_of_injective [IsDomain A] [IsDomain B] (p : A[X]) {f : A β†’+* B} (hf : Function.Injective f) : p.roots.map f ≀ (p.map f).roots := by by_cases hp0 : p = 0 Β· simp only [hp0, roots_zero, Multiset.map_zero, Polynomial.map_zero, le_rfl] exact map_roots_le ((Polynomial.map_ne_zero_iff hf).mpr hp0) theorem card_roots_le_map [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (h : p.map f β‰  0) : Multiset.card p.roots ≀ Multiset.card (p.map f).roots := by rw [← p.roots.card_map f] exact Multiset.card_le_card (map_roots_le h) theorem card_roots_le_map_of_injective [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (hf : Function.Injective f) : Multiset.card p.roots ≀ Multiset.card (p.map f).roots := by by_cases hp0 : p = 0 Β· simp only [hp0, roots_zero, Polynomial.map_zero, Multiset.card_zero, le_rfl] exact card_roots_le_map ((Polynomial.map_ne_zero_iff hf).mpr hp0) theorem roots_map_of_injective_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} {f : A β†’+* B} (hf : Function.Injective f) (hroots : Multiset.card p.roots = p.natDegree) : p.roots.map f = (p.map f).roots := by apply Multiset.eq_of_le_of_card_le (map_roots_le_of_injective p hf) simpa only [Multiset.card_map, hroots] using (card_roots' _).trans natDegree_map_le theorem roots_map_of_map_ne_zero_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} (f : A β†’+* B) (h : p.map f β‰  0) (hroots : p.roots.card = p.natDegree) : p.roots.map f = (p.map f).roots := eq_of_le_of_card_le (map_roots_le h) <| by simpa only [Multiset.card_map, hroots] using (p.map f).card_roots'.trans natDegree_map_le theorem Monic.roots_map_of_card_eq_natDegree [IsDomain A] [IsDomain B] {p : A[X]} (hm : p.Monic) (f : A β†’+* B) (hroots : p.roots.card = p.natDegree) : p.roots.map f = (p.map f).roots := roots_map_of_map_ne_zero_of_card_eq_natDegree f (map_monic_ne_zero hm) hroots end end Polynomial
Mathlib/Algebra/Polynomial/Roots.lean
812
816
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Nat.Even import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute import Mathlib.Data.Set.Operations import Mathlib.Logic.Function.Iterate /-! # Even and odd elements in rings This file defines odd elements and proves some general facts about even and odd elements of rings. As opposed to `Even`, `Odd` does not have a multiplicative counterpart. ## TODO Try to generalize `Even` lemmas further. For example, there are still a few lemmas whose `Semiring` assumptions I (DT) am not convinced are necessary. If that turns out to be true, they could be moved to `Mathlib.Algebra.Group.Even`. ## See also `Mathlib.Algebra.Group.Even` for the definition of even elements. -/ assert_not_exists DenselyOrdered OrderedRing open MulOpposite variable {F Ξ± Ξ² : Type*} section Monoid variable [Monoid Ξ±] [HasDistribNeg Ξ±] {n : β„•} {a : Ξ±} @[simp] lemma Even.neg_pow : Even n β†’ βˆ€ a : Ξ±, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a simp_rw [← two_mul, pow_mul, neg_sq] lemma Even.neg_one_pow (h : Even n) : (-1 : Ξ±) ^ n = 1 := by rw [h.neg_pow, one_pow] end Monoid section DivisionMonoid variable [DivisionMonoid Ξ±] [HasDistribNeg Ξ±] {a : Ξ±} {n : β„€} lemma Even.neg_zpow : Even n β†’ βˆ€ a : Ξ±, (-a) ^ n = a ^ n := by rintro ⟨c, rfl⟩ a; simp_rw [← Int.two_mul, zpow_mul, zpow_two, neg_mul_neg] lemma Even.neg_one_zpow (h : Even n) : (-1 : Ξ±) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end DivisionMonoid @[simp] lemma IsSquare.zero [MulZeroClass Ξ±] : IsSquare (0 : Ξ±) := ⟨0, (mul_zero _).symm⟩ section Semiring variable [Semiring Ξ±] [Semiring Ξ²] {a b : Ξ±} {m n : β„•} lemma even_iff_exists_two_mul : Even a ↔ βˆƒ b, a = 2 * b := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd : Even a ↔ 2 ∣ a := by simp [Even, Dvd.dvd, two_mul] alias ⟨Even.two_dvd, _⟩ := even_iff_two_dvd lemma Even.trans_dvd (ha : Even a) (hab : a ∣ b) : Even b :=
even_iff_two_dvd.2 <| ha.two_dvd.trans hab
Mathlib/Algebra/Ring/Parity.lean
69
69
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin, Lu-Ming Zhang -/ import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Algebra.Pi import Mathlib.Algebra.BigOperators.RingEquiv import Mathlib.Data.Finite.Prod import Mathlib.Data.Matrix.Mul import Mathlib.LinearAlgebra.Pi /-! # Matrices This file contains basic results on matrices including bundled versions of matrix operators. ## Implementation notes For convenience, `Matrix m n Ξ±` is defined as `m β†’ n β†’ Ξ±`, as this allows elements of the matrix to be accessed with `A i j`. However, it is not advisable to _construct_ matrices using terms of the form `fun i j ↦ _` or even `(fun i j ↦ _ : Matrix m n Ξ±)`, as these are not recognized by Lean as having the right type. Instead, `Matrix.of` should be used. ## TODO Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented. -/ assert_not_exists Star universe u u' v w variable {l m n o : Type*} {m' : o β†’ Type*} {n' : o β†’ Type*} variable {R : Type*} {S : Type*} {Ξ± : Type v} {Ξ² : Type w} {Ξ³ : Type*} namespace Matrix instance decidableEq [DecidableEq Ξ±] [Fintype m] [Fintype n] : DecidableEq (Matrix m n Ξ±) := Fintype.decidablePiFintype instance {n m} [Fintype m] [DecidableEq m] [Fintype n] [DecidableEq n] (Ξ±) [Fintype Ξ±] : Fintype (Matrix m n Ξ±) := inferInstanceAs (Fintype (m β†’ n β†’ Ξ±)) instance {n m} [Finite m] [Finite n] (Ξ±) [Finite Ξ±] : Finite (Matrix m n Ξ±) := inferInstanceAs (Finite (m β†’ n β†’ Ξ±)) section variable (R) /-- This is `Matrix.of` bundled as a linear equivalence. -/ def ofLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : (m β†’ n β†’ Ξ±) ≃ₗ[R] Matrix m n Ξ± where __ := ofAddEquiv map_smul' _ _ := rfl @[simp] lemma coe_ofLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : ⇑(ofLinearEquiv _ : (m β†’ n β†’ Ξ±) ≃ₗ[R] Matrix m n Ξ±) = of := rfl @[simp] lemma coe_ofLinearEquiv_symm [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : ⇑((ofLinearEquiv _).symm : Matrix m n Ξ± ≃ₗ[R] (m β†’ n β†’ Ξ±)) = of.symm := rfl end theorem sum_apply [AddCommMonoid Ξ±] (i : m) (j : n) (s : Finset Ξ²) (g : Ξ² β†’ Matrix m n Ξ±) : (βˆ‘ c ∈ s, g c) i j = βˆ‘ c ∈ s, g c i j := (congr_fun (s.sum_apply i g) j).trans (s.sum_apply j _) end Matrix open Matrix namespace Matrix section Diagonal variable [DecidableEq n] variable (n Ξ±) /-- `Matrix.diagonal` as an `AddMonoidHom`. -/ @[simps] def diagonalAddMonoidHom [AddZeroClass Ξ±] : (n β†’ Ξ±) β†’+ Matrix n n Ξ± where toFun := diagonal map_zero' := diagonal_zero map_add' x y := (diagonal_add x y).symm variable (R) /-- `Matrix.diagonal` as a `LinearMap`. -/ @[simps] def diagonalLinearMap [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : (n β†’ Ξ±) β†’β‚—[R] Matrix n n Ξ± := { diagonalAddMonoidHom n Ξ± with map_smul' := diagonal_smul } variable {n Ξ± R} section One variable [Zero Ξ±] [One Ξ±] lemma zero_le_one_elem [Preorder Ξ±] [ZeroLEOneClass Ξ±] (i j : n) : 0 ≀ (1 : Matrix n n Ξ±) i j := by by_cases hi : i = j Β· subst hi simp Β· simp [hi] lemma zero_le_one_row [Preorder Ξ±] [ZeroLEOneClass Ξ±] (i : n) : 0 ≀ (1 : Matrix n n Ξ±) i := zero_le_one_elem i end One end Diagonal section Diag variable (n Ξ±) /-- `Matrix.diag` as an `AddMonoidHom`. -/ @[simps] def diagAddMonoidHom [AddZeroClass Ξ±] : Matrix n n Ξ± β†’+ n β†’ Ξ± where toFun := diag map_zero' := diag_zero map_add' := diag_add variable (R) /-- `Matrix.diag` as a `LinearMap`. -/ @[simps] def diagLinearMap [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : Matrix n n Ξ± β†’β‚—[R] n β†’ Ξ± := { diagAddMonoidHom n Ξ± with map_smul' := diag_smul } variable {n Ξ± R} @[simp] theorem diag_list_sum [AddMonoid Ξ±] (l : List (Matrix n n Ξ±)) : diag l.sum = (l.map diag).sum := map_list_sum (diagAddMonoidHom n Ξ±) l @[simp] theorem diag_multiset_sum [AddCommMonoid Ξ±] (s : Multiset (Matrix n n Ξ±)) : diag s.sum = (s.map diag).sum := map_multiset_sum (diagAddMonoidHom n Ξ±) s @[simp] theorem diag_sum {ΞΉ} [AddCommMonoid Ξ±] (s : Finset ΞΉ) (f : ΞΉ β†’ Matrix n n Ξ±) : diag (βˆ‘ i ∈ s, f i) = βˆ‘ i ∈ s, diag (f i) := map_sum (diagAddMonoidHom n Ξ±) f s end Diag open Matrix section AddCommMonoid variable [AddCommMonoid Ξ±] [Mul Ξ±] end AddCommMonoid section NonAssocSemiring variable [NonAssocSemiring Ξ±] variable (Ξ± n) /-- `Matrix.diagonal` as a `RingHom`. -/ @[simps] def diagonalRingHom [Fintype n] [DecidableEq n] : (n β†’ Ξ±) β†’+* Matrix n n Ξ± := { diagonalAddMonoidHom n Ξ± with toFun := diagonal map_one' := diagonal_one map_mul' := fun _ _ => (diagonal_mul_diagonal' _ _).symm } end NonAssocSemiring section Semiring variable [Semiring Ξ±] theorem diagonal_pow [Fintype n] [DecidableEq n] (v : n β†’ Ξ±) (k : β„•) : diagonal v ^ k = diagonal (v ^ k) := (map_pow (diagonalRingHom n Ξ±) v k).symm /-- The ring homomorphism `Ξ± β†’+* Matrix n n Ξ±` sending `a` to the diagonal matrix with `a` on the diagonal. -/ def scalar (n : Type u) [DecidableEq n] [Fintype n] : Ξ± β†’+* Matrix n n Ξ± := (diagonalRingHom n Ξ±).comp <| Pi.constRingHom n Ξ± section Scalar variable [DecidableEq n] [Fintype n] @[simp] theorem scalar_apply (a : Ξ±) : scalar n a = diagonal fun _ => a := rfl theorem scalar_inj [Nonempty n] {r s : Ξ±} : scalar n r = scalar n s ↔ r = s := (diagonal_injective.comp Function.const_injective).eq_iff theorem scalar_commute_iff {r : Ξ±} {M : Matrix n n Ξ±} : Commute (scalar n r) M ↔ r β€’ M = MulOpposite.op r β€’ M := by simp_rw [Commute, SemiconjBy, scalar_apply, ← smul_eq_diagonal_mul, ← op_smul_eq_mul_diagonal] theorem scalar_commute (r : Ξ±) (hr : βˆ€ r', Commute r r') (M : Matrix n n Ξ±) : Commute (scalar n r) M := scalar_commute_iff.2 <| ext fun _ _ => hr _ end Scalar end Semiring section Algebra variable [Fintype n] [DecidableEq n] variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Algebra R Ξ±] [Algebra R Ξ²] instance instAlgebra : Algebra R (Matrix n n Ξ±) where algebraMap := (Matrix.scalar n).comp (algebraMap R Ξ±) commutes' _ _ := scalar_commute _ (fun _ => Algebra.commutes _ _) _ smul_def' r x := by ext; simp [Matrix.scalar, Algebra.smul_def r] theorem algebraMap_matrix_apply {r : R} {i j : n} : algebraMap R (Matrix n n Ξ±) r i j = if i = j then algebraMap R Ξ± r else 0 := by dsimp [algebraMap, Algebra.algebraMap, Matrix.scalar] split_ifs with h <;> simp [h, Matrix.one_apply_ne] theorem algebraMap_eq_diagonal (r : R) : algebraMap R (Matrix n n Ξ±) r = diagonal (algebraMap R (n β†’ Ξ±) r) := rfl theorem algebraMap_eq_diagonalRingHom : algebraMap R (Matrix n n Ξ±) = (diagonalRingHom n Ξ±).comp (algebraMap R _) := rfl @[simp] theorem map_algebraMap (r : R) (f : Ξ± β†’ Ξ²) (hf : f 0 = 0) (hfβ‚‚ : f (algebraMap R Ξ± r) = algebraMap R Ξ² r) : (algebraMap R (Matrix n n Ξ±) r).map f = algebraMap R (Matrix n n Ξ²) r := by rw [algebraMap_eq_diagonal, algebraMap_eq_diagonal, diagonal_map hf] simp [hfβ‚‚] variable (R) /-- `Matrix.diagonal` as an `AlgHom`. -/ @[simps] def diagonalAlgHom : (n β†’ Ξ±) →ₐ[R] Matrix n n Ξ± := { diagonalRingHom n Ξ± with toFun := diagonal commutes' := fun r => (algebraMap_eq_diagonal r).symm } end Algebra section AddHom variable [Add Ξ±] variable (R Ξ±) in /-- Extracting entries from a matrix as an additive homomorphism. -/ @[simps] def entryAddHom (i : m) (j : n) : AddHom (Matrix m n Ξ±) Ξ± where toFun M := M i j map_add' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddHom_eq_comp {i : m} {j : n} : entryAddHom Ξ± i j = ((Pi.evalAddHom (fun _ => Ξ±) j).comp (Pi.evalAddHom _ i)).comp (AddHomClass.toAddHom ofAddEquiv.symm) := rfl end AddHom section AddMonoidHom variable [AddZeroClass Ξ±] variable (R Ξ±) in /-- Extracting entries from a matrix as an additive monoid homomorphism. Note this cannot be upgraded to a ring homomorphism, as it does not respect multiplication. -/ @[simps] def entryAddMonoidHom (i : m) (j : n) : Matrix m n Ξ± β†’+ Ξ± where toFun M := M i j map_add' _ _ := rfl map_zero' := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryAddMonoidHom_eq_comp {i : m} {j : n} : entryAddMonoidHom Ξ± i j = ((Pi.evalAddMonoidHom (fun _ => Ξ±) j).comp (Pi.evalAddMonoidHom _ i)).comp (AddMonoidHomClass.toAddMonoidHom ofAddEquiv.symm) := by rfl @[simp] lemma evalAddMonoidHom_comp_diagAddMonoidHom (i : m) : (Pi.evalAddMonoidHom _ i).comp (diagAddMonoidHom m Ξ±) = entryAddMonoidHom Ξ± i i := by simp [AddMonoidHom.ext_iff] @[simp] lemma entryAddMonoidHom_toAddHom {i : m} {j : n} : (entryAddMonoidHom Ξ± i j : AddHom _ _) = entryAddHom Ξ± i j := rfl end AddMonoidHom section LinearMap variable [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] variable (R Ξ±) in /-- Extracting entries from a matrix as a linear map. Note this cannot be upgraded to an algebra homomorphism, as it does not respect multiplication. -/ @[simps] def entryLinearMap (i : m) (j : n) : Matrix m n Ξ± β†’β‚—[R] Ξ± where toFun M := M i j map_add' _ _ := rfl map_smul' _ _ := rfl -- It is necessary to spell out the name of the coercion explicitly on the RHS -- for unification to succeed lemma entryLinearMap_eq_comp {i : m} {j : n} : entryLinearMap R Ξ± i j = LinearMap.proj j βˆ˜β‚— LinearMap.proj i βˆ˜β‚— (ofLinearEquiv R).symm.toLinearMap := by rfl @[simp] lemma proj_comp_diagLinearMap (i : m) : LinearMap.proj i βˆ˜β‚— diagLinearMap m R Ξ± = entryLinearMap R Ξ± i i := by simp [LinearMap.ext_iff] @[simp] lemma entryLinearMap_toAddMonoidHom {i : m} {j : n} : (entryLinearMap R Ξ± i j : _ β†’+ _) = entryAddMonoidHom Ξ± i j := rfl @[simp] lemma entryLinearMap_toAddHom {i : m} {j : n} : (entryLinearMap R Ξ± i j : AddHom _ _) = entryAddHom Ξ± i j := rfl end LinearMap end Matrix /-! ### Bundled versions of `Matrix.map` -/ namespace Equiv /-- The `Equiv` between spaces of matrices induced by an `Equiv` between their coefficients. This is `Matrix.map` as an `Equiv`. -/ @[simps apply] def mapMatrix (f : Ξ± ≃ Ξ²) : Matrix m n Ξ± ≃ Matrix m n Ξ² where toFun M := M.map f invFun M := M.map f.symm left_inv _ := Matrix.ext fun _ _ => f.symm_apply_apply _ right_inv _ := Matrix.ext fun _ _ => f.apply_symm_apply _ @[simp] theorem mapMatrix_refl : (Equiv.refl Ξ±).mapMatrix = Equiv.refl (Matrix m n Ξ±) := rfl @[simp] theorem mapMatrix_symm (f : Ξ± ≃ Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² ≃ _) := rfl @[simp] theorem mapMatrix_trans (f : Ξ± ≃ Ξ²) (g : Ξ² ≃ Ξ³) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± ≃ _) := rfl end Equiv namespace AddMonoidHom variable [AddZeroClass Ξ±] [AddZeroClass Ξ²] [AddZeroClass Ξ³] /-- The `AddMonoidHom` between spaces of matrices induced by an `AddMonoidHom` between their coefficients. This is `Matrix.map` as an `AddMonoidHom`. -/ @[simps] def mapMatrix (f : Ξ± β†’+ Ξ²) : Matrix m n Ξ± β†’+ Matrix m n Ξ² where toFun M := M.map f map_zero' := Matrix.map_zero f f.map_zero map_add' := Matrix.map_add f f.map_add @[simp] theorem mapMatrix_id : (AddMonoidHom.id Ξ±).mapMatrix = AddMonoidHom.id (Matrix m n Ξ±) := rfl @[simp] theorem mapMatrix_comp (f : Ξ² β†’+ Ξ³) (g : Ξ± β†’+ Ξ²) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n Ξ± β†’+ _) := rfl @[simp] lemma entryAddMonoidHom_comp_mapMatrix (f : Ξ± β†’+ Ξ²) (i : m) (j : n) : (entryAddMonoidHom Ξ² i j).comp f.mapMatrix = f.comp (entryAddMonoidHom Ξ± i j) := rfl end AddMonoidHom namespace AddEquiv variable [Add Ξ±] [Add Ξ²] [Add Ξ³] /-- The `AddEquiv` between spaces of matrices induced by an `AddEquiv` between their coefficients. This is `Matrix.map` as an `AddEquiv`. -/ @[simps apply] def mapMatrix (f : Ξ± ≃+ Ξ²) : Matrix m n Ξ± ≃+ Matrix m n Ξ² := { f.toEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm map_add' := Matrix.map_add f (map_add f) } @[simp] theorem mapMatrix_refl : (AddEquiv.refl Ξ±).mapMatrix = AddEquiv.refl (Matrix m n Ξ±) := rfl @[simp] theorem mapMatrix_symm (f : Ξ± ≃+ Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² ≃+ _) := rfl @[simp] theorem mapMatrix_trans (f : Ξ± ≃+ Ξ²) (g : Ξ² ≃+ Ξ³) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± ≃+ _) := rfl @[simp] lemma entryAddHom_comp_mapMatrix (f : Ξ± ≃+ Ξ²) (i : m) (j : n) : (entryAddHom Ξ² i j).comp (AddHomClass.toAddHom f.mapMatrix) = (f : AddHom Ξ± Ξ²).comp (entryAddHom _ i j) := rfl end AddEquiv namespace LinearMap variable [Semiring R] [AddCommMonoid Ξ±] [AddCommMonoid Ξ²] [AddCommMonoid Ξ³] variable [Module R Ξ±] [Module R Ξ²] [Module R Ξ³] /-- The `LinearMap` between spaces of matrices induced by a `LinearMap` between their coefficients. This is `Matrix.map` as a `LinearMap`. -/ @[simps] def mapMatrix (f : Ξ± β†’β‚—[R] Ξ²) : Matrix m n Ξ± β†’β‚—[R] Matrix m n Ξ² where toFun M := M.map f map_add' := Matrix.map_add f f.map_add map_smul' r := Matrix.map_smul f r (f.map_smul r) @[simp] theorem mapMatrix_id : LinearMap.id.mapMatrix = (LinearMap.id : Matrix m n Ξ± β†’β‚—[R] _) := rfl @[simp] theorem mapMatrix_comp (f : Ξ² β†’β‚—[R] Ξ³) (g : Ξ± β†’β‚—[R] Ξ²) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m n Ξ± β†’β‚—[R] _) := rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : Ξ± β†’β‚—[R] Ξ²) (i : m) (j : n) : entryLinearMap R _ i j βˆ˜β‚— f.mapMatrix = f βˆ˜β‚— entryLinearMap R _ i j := rfl end LinearMap namespace LinearEquiv variable [Semiring R] [AddCommMonoid Ξ±] [AddCommMonoid Ξ²] [AddCommMonoid Ξ³] variable [Module R Ξ±] [Module R Ξ²] [Module R Ξ³] /-- The `LinearEquiv` between spaces of matrices induced by a `LinearEquiv` between their coefficients. This is `Matrix.map` as a `LinearEquiv`. -/ @[simps apply] def mapMatrix (f : Ξ± ≃ₗ[R] Ξ²) : Matrix m n Ξ± ≃ₗ[R] Matrix m n Ξ² := { f.toEquiv.mapMatrix, f.toLinearMap.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : (LinearEquiv.refl R Ξ±).mapMatrix = LinearEquiv.refl R (Matrix m n Ξ±) := rfl @[simp] theorem mapMatrix_symm (f : Ξ± ≃ₗ[R] Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m n Ξ² ≃ₗ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : Ξ± ≃ₗ[R] Ξ²) (g : Ξ² ≃ₗ[R] Ξ³) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m n Ξ± ≃ₗ[R] _) := rfl @[simp] lemma mapMatrix_toLinearMap (f : Ξ± ≃ₗ[R] Ξ²) : (f.mapMatrix : _ ≃ₗ[R] Matrix m n Ξ²).toLinearMap = f.toLinearMap.mapMatrix := by rfl @[simp] lemma entryLinearMap_comp_mapMatrix (f : Ξ± ≃ₗ[R] Ξ²) (i : m) (j : n) : entryLinearMap R _ i j βˆ˜β‚— f.mapMatrix.toLinearMap = f.toLinearMap βˆ˜β‚— entryLinearMap R _ i j := by simp only [mapMatrix_toLinearMap, LinearMap.entryLinearMap_comp_mapMatrix] end LinearEquiv namespace RingHom variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring Ξ±] [NonAssocSemiring Ξ²] [NonAssocSemiring Ξ³] /-- The `RingHom` between spaces of square matrices induced by a `RingHom` between their coefficients. This is `Matrix.map` as a `RingHom`. -/ @[simps] def mapMatrix (f : Ξ± β†’+* Ξ²) : Matrix m m Ξ± β†’+* Matrix m m Ξ² := { f.toAddMonoidHom.mapMatrix with toFun := fun M => M.map f map_one' := by simp map_mul' := fun _ _ => Matrix.map_mul } @[simp] theorem mapMatrix_id : (RingHom.id Ξ±).mapMatrix = RingHom.id (Matrix m m Ξ±) := rfl @[simp] theorem mapMatrix_comp (f : Ξ² β†’+* Ξ³) (g : Ξ± β†’+* Ξ²) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m Ξ± β†’+* _) := rfl end RingHom namespace RingEquiv variable [Fintype m] [DecidableEq m] variable [NonAssocSemiring Ξ±] [NonAssocSemiring Ξ²] [NonAssocSemiring Ξ³] /-- The `RingEquiv` between spaces of square matrices induced by a `RingEquiv` between their coefficients. This is `Matrix.map` as a `RingEquiv`. -/ @[simps apply] def mapMatrix (f : Ξ± ≃+* Ξ²) : Matrix m m Ξ± ≃+* Matrix m m Ξ² := { f.toRingHom.mapMatrix, f.toAddEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : (RingEquiv.refl Ξ±).mapMatrix = RingEquiv.refl (Matrix m m Ξ±) := rfl @[simp] theorem mapMatrix_symm (f : Ξ± ≃+* Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m Ξ² ≃+* _) := rfl @[simp] theorem mapMatrix_trans (f : Ξ± ≃+* Ξ²) (g : Ξ² ≃+* Ξ³) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m Ξ± ≃+* _) := rfl open MulOpposite in /-- For any ring `R`, we have ring isomorphism `Matβ‚™β‚“β‚™(Rα΅’α΅–) β‰… (Matβ‚™β‚“β‚™(R))α΅’α΅–` given by transpose. -/ @[simps apply symm_apply] def mopMatrix : Matrix m m αᡐᡒᡖ ≃+* (Matrix m m Ξ±)ᡐᡒᡖ where toFun M := op (M.transpose.map unop) invFun M := M.unop.transpose.map op left_inv _ := by aesop right_inv _ := by aesop map_mul' _ _ := unop_injective <| by ext; simp [transpose, mul_apply] map_add' _ _ := by aesop end RingEquiv namespace AlgHom variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Semiring Ξ³] variable [Algebra R Ξ±] [Algebra R Ξ²] [Algebra R Ξ³] /-- The `AlgHom` between spaces of square matrices induced by an `AlgHom` between their coefficients. This is `Matrix.map` as an `AlgHom`. -/ @[simps] def mapMatrix (f : Ξ± →ₐ[R] Ξ²) : Matrix m m Ξ± →ₐ[R] Matrix m m Ξ² := { f.toRingHom.mapMatrix with toFun := fun M => M.map f commutes' := fun r => Matrix.map_algebraMap r f (map_zero _) (f.commutes r) } @[simp] theorem mapMatrix_id : (AlgHom.id R Ξ±).mapMatrix = AlgHom.id R (Matrix m m Ξ±) := rfl @[simp] theorem mapMatrix_comp (f : Ξ² →ₐ[R] Ξ³) (g : Ξ± →ₐ[R] Ξ²) : f.mapMatrix.comp g.mapMatrix = ((f.comp g).mapMatrix : Matrix m m Ξ± →ₐ[R] _) := rfl end AlgHom namespace AlgEquiv variable [Fintype m] [DecidableEq m] variable [CommSemiring R] [Semiring Ξ±] [Semiring Ξ²] [Semiring Ξ³] variable [Algebra R Ξ±] [Algebra R Ξ²] [Algebra R Ξ³] /-- The `AlgEquiv` between spaces of square matrices induced by an `AlgEquiv` between their coefficients. This is `Matrix.map` as an `AlgEquiv`. -/ @[simps apply] def mapMatrix (f : Ξ± ≃ₐ[R] Ξ²) : Matrix m m Ξ± ≃ₐ[R] Matrix m m Ξ² := { f.toAlgHom.mapMatrix, f.toRingEquiv.mapMatrix with toFun := fun M => M.map f invFun := fun M => M.map f.symm } @[simp] theorem mapMatrix_refl : AlgEquiv.refl.mapMatrix = (AlgEquiv.refl : Matrix m m Ξ± ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_symm (f : Ξ± ≃ₐ[R] Ξ²) : f.mapMatrix.symm = (f.symm.mapMatrix : Matrix m m Ξ² ≃ₐ[R] _) := rfl @[simp] theorem mapMatrix_trans (f : Ξ± ≃ₐ[R] Ξ²) (g : Ξ² ≃ₐ[R] Ξ³) : f.mapMatrix.trans g.mapMatrix = ((f.trans g).mapMatrix : Matrix m m Ξ± ≃ₐ[R] _) := rfl /-- For any algebra `Ξ±` over a ring `R`, we have an `R`-algebra isomorphism `Matβ‚™β‚“β‚™(Ξ±α΅’α΅–) β‰… (Matβ‚™β‚“β‚™(R))α΅’α΅–` given by transpose. If `Ξ±` is commutative, we can get rid of the `α΅’α΅–` in the left-hand side, see `Matrix.transposeAlgEquiv`. -/ @[simps!] def mopMatrix : Matrix m m αᡐᡒᡖ ≃ₐ[R] (Matrix m m Ξ±)ᡐᡒᡖ where __ := RingEquiv.mopMatrix commutes' _ := MulOpposite.unop_injective <| by ext; simp [algebraMap_matrix_apply, eq_comm, apply_ite MulOpposite.unop] end AlgEquiv open Matrix namespace Matrix section Transpose open Matrix variable (m n Ξ±) /-- `Matrix.transpose` as an `AddEquiv` -/ @[simps apply] def transposeAddEquiv [Add Ξ±] : Matrix m n Ξ± ≃+ Matrix n m Ξ± where toFun := transpose invFun := transpose left_inv := transpose_transpose right_inv := transpose_transpose map_add' := transpose_add @[simp] theorem transposeAddEquiv_symm [Add Ξ±] : (transposeAddEquiv m n Ξ±).symm = transposeAddEquiv n m Ξ± := rfl variable {m n Ξ±} theorem transpose_list_sum [AddMonoid Ξ±] (l : List (Matrix m n Ξ±)) : l.sumα΅€ = (l.map transpose).sum := map_list_sum (transposeAddEquiv m n Ξ±) l theorem transpose_multiset_sum [AddCommMonoid Ξ±] (s : Multiset (Matrix m n Ξ±)) : s.sumα΅€ = (s.map transpose).sum := (transposeAddEquiv m n Ξ±).toAddMonoidHom.map_multiset_sum s theorem transpose_sum [AddCommMonoid Ξ±] {ΞΉ : Type*} (s : Finset ΞΉ) (M : ΞΉ β†’ Matrix m n Ξ±) : (βˆ‘ i ∈ s, M i)α΅€ = βˆ‘ i ∈ s, (M i)α΅€ := map_sum (transposeAddEquiv m n Ξ±) _ s variable (m n R Ξ±) /-- `Matrix.transpose` as a `LinearMap` -/ @[simps apply] def transposeLinearEquiv [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : Matrix m n Ξ± ≃ₗ[R] Matrix n m Ξ± := { transposeAddEquiv m n Ξ± with map_smul' := transpose_smul } @[simp] theorem transposeLinearEquiv_symm [Semiring R] [AddCommMonoid Ξ±] [Module R Ξ±] : (transposeLinearEquiv m n R Ξ±).symm = transposeLinearEquiv n m R Ξ± := rfl variable {m n R Ξ±} variable (m Ξ±) /-- `Matrix.transpose` as a `RingEquiv` to the opposite ring -/ @[simps] def transposeRingEquiv [AddCommMonoid Ξ±] [CommSemigroup Ξ±] [Fintype m] : Matrix m m Ξ± ≃+* (Matrix m m Ξ±)ᡐᡒᡖ := { (transposeAddEquiv m m Ξ±).trans MulOpposite.opAddEquiv with toFun := fun M => MulOpposite.op Mα΅€ invFun := fun M => M.unopα΅€ map_mul' := fun M N => (congr_arg MulOpposite.op (transpose_mul M N)).trans (MulOpposite.op_mul _ _) left_inv := fun M => transpose_transpose M right_inv := fun M => MulOpposite.unop_injective <| transpose_transpose M.unop } variable {m Ξ±} @[simp] theorem transpose_pow [CommSemiring Ξ±] [Fintype m] [DecidableEq m] (M : Matrix m m Ξ±) (k : β„•) : (M ^ k)α΅€ = Mα΅€ ^ k := MulOpposite.op_injective <| map_pow (transposeRingEquiv m Ξ±) M k theorem transpose_list_prod [CommSemiring Ξ±] [Fintype m] [DecidableEq m] (l : List (Matrix m m Ξ±)) : l.prodα΅€ = (l.map transpose).reverse.prod := (transposeRingEquiv m Ξ±).unop_map_list_prod l variable (R m Ξ±) /-- `Matrix.transpose` as an `AlgEquiv` to the opposite ring -/ @[simps] def transposeAlgEquiv [CommSemiring R] [CommSemiring Ξ±] [Fintype m] [DecidableEq m] [Algebra R Ξ±] : Matrix m m Ξ± ≃ₐ[R] (Matrix m m Ξ±)ᡐᡒᡖ := { (transposeAddEquiv m m Ξ±).trans MulOpposite.opAddEquiv, transposeRingEquiv m Ξ± with toFun := fun M => MulOpposite.op Mα΅€ commutes' := fun r => by simp only [algebraMap_eq_diagonal, diagonal_transpose, MulOpposite.algebraMap_apply] } variable {R m Ξ±} end Transpose end Matrix
Mathlib/Data/Matrix/Basic.lean
1,232
1,234
/- Copyright (c) 2023 JoΓ«l Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: JoΓ«l Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Homology /-! # Quasi-isomorphisms of short complexes This file introduces the typeclass `QuasiIso Ο†` for a morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes (which have homology): the condition is that the induced morphism `homologyMap Ο†` in homology is an isomorphism. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type _} [Category C] [HasZeroMorphisms C] {S₁ Sβ‚‚ S₃ Sβ‚„ : ShortComplex C} [S₁.HasHomology] [Sβ‚‚.HasHomology] [S₃.HasHomology] [Sβ‚„.HasHomology] /-- A morphism `Ο† : S₁ ⟢ Sβ‚‚` of short complexes that have homology is a quasi-isomorphism if the induced map `homologyMap Ο† : S₁.homology ⟢ Sβ‚‚.homology` is an isomorphism. -/ class QuasiIso (Ο† : S₁ ⟢ Sβ‚‚) : Prop where /-- the homology map is an isomorphism -/ isIso' : IsIso (homologyMap Ο†) instance QuasiIso.isIso (Ο† : S₁ ⟢ Sβ‚‚) [QuasiIso Ο†] : IsIso (homologyMap Ο†) := QuasiIso.isIso' lemma quasiIso_iff (Ο† : S₁ ⟢ Sβ‚‚) : QuasiIso Ο† ↔ IsIso (homologyMap Ο†) := by constructor Β· intro h infer_instance Β· intro h exact ⟨h⟩ instance quasiIso_of_isIso (Ο† : S₁ ⟢ Sβ‚‚) [IsIso Ο†] : QuasiIso Ο† := ⟨(homologyMapIso (asIso Ο†)).isIso_hom⟩ instance quasiIso_comp (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : Sβ‚‚ ⟢ S₃) [hΟ† : QuasiIso Ο†] [hΟ†' : QuasiIso Ο†'] : QuasiIso (Ο† ≫ Ο†') := by rw [quasiIso_iff] at hΟ† hΟ†' ⊒ rw [homologyMap_comp] infer_instance lemma quasiIso_of_comp_left (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : Sβ‚‚ ⟢ S₃) [hΟ† : QuasiIso Ο†] [hφφ' : QuasiIso (Ο† ≫ Ο†')] : QuasiIso Ο†' := by rw [quasiIso_iff] at hΟ† hφφ' ⊒ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_left (homologyMap Ο†) (homologyMap Ο†') lemma quasiIso_iff_comp_left (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : Sβ‚‚ ⟢ S₃) [hΟ† : QuasiIso Ο†] : QuasiIso (Ο† ≫ Ο†') ↔ QuasiIso Ο†' := by constructor Β· intro exact quasiIso_of_comp_left Ο† Ο†' Β· intro exact quasiIso_comp Ο† Ο†' lemma quasiIso_of_comp_right (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : Sβ‚‚ ⟢ S₃) [hΟ†' : QuasiIso Ο†'] [hφφ' : QuasiIso (Ο† ≫ Ο†')] : QuasiIso Ο† := by rw [quasiIso_iff] at hΟ†' hφφ' ⊒ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_right (homologyMap Ο†) (homologyMap Ο†') lemma quasiIso_iff_comp_right (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : Sβ‚‚ ⟢ S₃) [hΟ†' : QuasiIso Ο†'] : QuasiIso (Ο† ≫ Ο†') ↔ QuasiIso Ο† := by constructor Β· intro exact quasiIso_of_comp_right Ο† Ο†' Β· intro exact quasiIso_comp Ο† Ο†' lemma quasiIso_of_arrow_mk_iso (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : S₃ ⟢ Sβ‚„) (e : Arrow.mk Ο† β‰… Arrow.mk Ο†') [hΟ† : QuasiIso Ο†] : QuasiIso Ο†' := by let Ξ± : S₃ ⟢ S₁ := e.inv.left let Ξ² : Sβ‚‚ ⟢ Sβ‚„ := e.hom.right suffices Ο†' = Ξ± ≫ Ο† ≫ Ξ² by rw [this] infer_instance simp only [Ξ±, Ξ², Arrow.w_mk_right_assoc, Arrow.mk_left, Arrow.mk_right, Arrow.mk_hom, ← Arrow.comp_right, e.inv_hom_id, Arrow.id_right, comp_id] lemma quasiIso_iff_of_arrow_mk_iso (Ο† : S₁ ⟢ Sβ‚‚) (Ο†' : S₃ ⟢ Sβ‚„) (e : Arrow.mk Ο† β‰… Arrow.mk Ο†') : QuasiIso Ο† ↔ QuasiIso Ο†' := ⟨fun _ => quasiIso_of_arrow_mk_iso Ο† Ο†' e, fun _ => quasiIso_of_arrow_mk_iso Ο†' Ο† e.symm⟩ lemma LeftHomologyMapData.quasiIso_iff {Ο† : S₁ ⟢ Sβ‚‚} {h₁ : S₁.LeftHomologyData} {hβ‚‚ : Sβ‚‚.LeftHomologyData} (Ξ³ : LeftHomologyMapData Ο† h₁ hβ‚‚) : QuasiIso Ο† ↔ IsIso Ξ³.Ο†H := by rw [ShortComplex.quasiIso_iff, Ξ³.homologyMap_eq] constructor Β· intro h haveI : IsIso (Ξ³.Ο†H ≫ (LeftHomologyData.homologyIso hβ‚‚).inv) := IsIso.of_isIso_comp_left (LeftHomologyData.homologyIso h₁).hom _ exact IsIso.of_isIso_comp_right _ (LeftHomologyData.homologyIso hβ‚‚).inv Β· intro h infer_instance lemma RightHomologyMapData.quasiIso_iff {Ο† : S₁ ⟢ Sβ‚‚} {h₁ : S₁.RightHomologyData} {hβ‚‚ : Sβ‚‚.RightHomologyData} (Ξ³ : RightHomologyMapData Ο† h₁ hβ‚‚) : QuasiIso Ο† ↔ IsIso Ξ³.Ο†H := by rw [ShortComplex.quasiIso_iff, Ξ³.homologyMap_eq] constructor Β· intro h haveI : IsIso (Ξ³.Ο†H ≫ (RightHomologyData.homologyIso hβ‚‚).inv) := IsIso.of_isIso_comp_left (RightHomologyData.homologyIso h₁).hom _ exact IsIso.of_isIso_comp_right _ (RightHomologyData.homologyIso hβ‚‚).inv Β· intro h infer_instance lemma quasiIso_iff_isIso_leftHomologyMap' (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.LeftHomologyData) (hβ‚‚ : Sβ‚‚.LeftHomologyData) : QuasiIso Ο† ↔ IsIso (leftHomologyMap' Ο† h₁ hβ‚‚) := by have Ξ³ : LeftHomologyMapData Ο† h₁ hβ‚‚ := default rw [Ξ³.quasiIso_iff, Ξ³.leftHomologyMap'_eq] lemma quasiIso_iff_isIso_rightHomologyMap' (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.RightHomologyData) (hβ‚‚ : Sβ‚‚.RightHomologyData) : QuasiIso Ο† ↔ IsIso (rightHomologyMap' Ο† h₁ hβ‚‚) := by have Ξ³ : RightHomologyMapData Ο† h₁ hβ‚‚ := default rw [Ξ³.quasiIso_iff, Ξ³.rightHomologyMap'_eq] lemma quasiIso_iff_isIso_homologyMap' (Ο† : S₁ ⟢ Sβ‚‚) (h₁ : S₁.HomologyData) (hβ‚‚ : Sβ‚‚.HomologyData) : QuasiIso Ο† ↔ IsIso (homologyMap' Ο† h₁ hβ‚‚) := quasiIso_iff_isIso_leftHomologyMap' _ _ _ lemma quasiIso_of_epi_of_isIso_of_mono (Ο† : S₁ ⟢ Sβ‚‚) [Epi Ο†.τ₁] [IsIso Ο†.Ο„β‚‚] [Mono Ο†.τ₃] : QuasiIso Ο† := by rw [((LeftHomologyMapData.ofEpiOfIsIsoOfMono Ο†) S₁.leftHomologyData).quasiIso_iff] dsimp infer_instance lemma quasiIso_opMap_iff (Ο† : S₁ ⟢ Sβ‚‚) : QuasiIso (opMap Ο†) ↔ QuasiIso Ο† := by have Ξ³ : HomologyMapData Ο† S₁.homologyData Sβ‚‚.homologyData := default rw [Ξ³.left.quasiIso_iff, Ξ³.op.right.quasiIso_iff] dsimp constructor Β· intro h apply isIso_of_op Β· intro h infer_instance lemma quasiIso_opMap (Ο† : S₁ ⟢ Sβ‚‚) [QuasiIso Ο†] : QuasiIso (opMap Ο†) := by rw [quasiIso_opMap_iff] infer_instance lemma quasiIso_unopMap {S₁ Sβ‚‚ : ShortComplex Cα΅’α΅–} [S₁.HasHomology] [Sβ‚‚.HasHomology] [S₁.unop.HasHomology] [Sβ‚‚.unop.HasHomology] (Ο† : S₁ ⟢ Sβ‚‚) [QuasiIso Ο†] : QuasiIso (unopMap Ο†) := by rw [← quasiIso_opMap_iff] change QuasiIso Ο† infer_instance lemma quasiIso_iff_isIso_liftCycles (Ο† : S₁ ⟢ Sβ‚‚) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hfβ‚‚ : Sβ‚‚.f = 0) : QuasiIso Ο† ↔ IsIso (Sβ‚‚.liftCycles Ο†.Ο„β‚‚ (by rw [Ο†.comm₂₃, hg₁, zero_comp])) := by let H : LeftHomologyMapData Ο† (LeftHomologyData.ofZeros S₁ hf₁ hg₁) (LeftHomologyData.ofIsLimitKernelFork Sβ‚‚ hfβ‚‚ _ Sβ‚‚.cyclesIsKernel) := { Ο†K := Sβ‚‚.liftCycles Ο†.Ο„β‚‚ (by rw [Ο†.comm₂₃, hg₁, zero_comp]) Ο†H := Sβ‚‚.liftCycles Ο†.Ο„β‚‚ (by rw [Ο†.comm₂₃, hg₁, zero_comp]) } exact H.quasiIso_iff
lemma quasiIso_iff_isIso_descOpcycles (Ο† : S₁ ⟢ Sβ‚‚) (hg₁ : S₁.g = 0) (hfβ‚‚ : Sβ‚‚.f = 0) (hgβ‚‚ : Sβ‚‚.g = 0) : QuasiIso Ο† ↔ IsIso (S₁.descOpcycles Ο†.Ο„β‚‚ (by rw [← Ο†.comm₁₂, hfβ‚‚, comp_zero])) := by let H : RightHomologyMapData Ο† (RightHomologyData.ofIsColimitCokernelCofork S₁ hg₁ _ S₁.opcyclesIsCokernel) (RightHomologyData.ofZeros Sβ‚‚ hfβ‚‚ hgβ‚‚) := { Ο†Q := S₁.descOpcycles Ο†.Ο„β‚‚ (by rw [← Ο†.comm₁₂, hfβ‚‚, comp_zero]) Ο†H := S₁.descOpcycles Ο†.Ο„β‚‚ (by rw [← Ο†.comm₁₂, hfβ‚‚, comp_zero]) } exact H.quasiIso_iff
Mathlib/Algebra/Homology/ShortComplex/QuasiIso.lean
176
184
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {Ξ± Ξ² G M : Type*} section ite variable [Pow Ξ± Ξ²] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : Ξ±) (b : p β†’ Ξ²) (c : Β¬ p β†’ Ξ²) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p β†’ Ξ±) (b : Β¬ p β†’ Ξ±) (c : Ξ²) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : Ξ±) (b c : Ξ²) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : Ξ±) (c : Ξ²) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup Ξ±] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· * Β·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : Ξ±) : (x * Β·) ∘ (y * Β·) = (x * y * Β·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : Ξ±) : (Β· * x) ∘ (Β· * y) = (Β· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (Ξ± := G) (Β· * Β·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * Β·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (Β· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : β„•} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≀ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≀ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n β‰  0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n β‰  0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n β€’ x = 0`, then `m β€’ x` is the same as `(m % n) β€’ x`"] lemma pow_eq_pow_mod (m : β„•) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : βˆ€ n, a * b = 1 β†’ a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : βˆ€ n : β„•, (a * Β·)^[n] = (a ^ n * Β·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : βˆ€ n : β„•, (Β· * a)^[n] = (Β· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * Β·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (Β· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : β„•) : βˆ€ n : β„•, (fun x : M ↦ x ^ k)^[n] = (Β· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : βˆ€ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b β‰  a ↔ b β‰  1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self @[to_additive] theorem left_ne_mul : a β‰  a * b ↔ b β‰  1 := left_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_right end LeftCancelMonoid section RightCancelMonoid variable [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_right : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right @[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_eq_self @[to_additive (attr := simp)] theorem right_eq_mul : b = a * b ↔ a = 1 := eq_comm.trans mul_eq_right @[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul
@[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add set_option linter.existingAttributeWarning false in
Mathlib/Algebra/Group/Basic.lean
276
278
/- Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Data.Rat.Cast.Defs /-! # Casts of rational numbers into characteristic zero fields (or division rings). -/ open Function variable {F ΞΉ Ξ± Ξ² : Type*} namespace Rat variable [DivisionRing Ξ±] [CharZero Ξ±] {p q : β„š} @[stacks 09FR "Characteristic zero case."] lemma cast_injective : Injective ((↑) : β„š β†’ Ξ±) | ⟨n₁, d₁, d₁0, cβ‚βŸ©, ⟨nβ‚‚, dβ‚‚, dβ‚‚0, cβ‚‚βŸ©, h => by have d₁a : (d₁ : Ξ±) β‰  0 := Nat.cast_ne_zero.2 d₁0 have dβ‚‚a : (dβ‚‚ : Ξ±) β‰  0 := Nat.cast_ne_zero.2 dβ‚‚0 rw [mk'_eq_divInt, mk'_eq_divInt] at h ⊒ rw [cast_divInt_of_ne_zero, cast_divInt_of_ne_zero] at h <;> simp [d₁0, dβ‚‚0] at h ⊒ rwa [eq_div_iff_mul_eq dβ‚‚a, division_def, mul_assoc, (d₁.cast_commute (dβ‚‚ : Ξ±)).inv_leftβ‚€.eq, ←
mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq d₁a, eq_comm, ← Int.cast_natCast d₁, ← Int.cast_mul, ← Int.cast_natCast dβ‚‚, ← Int.cast_mul, Int.cast_inj, ← mkRat_eq_iff d₁0 dβ‚‚0] at h @[simp, norm_cast] lemma cast_inj : (p : Ξ±) = q ↔ p = q := cast_injective.eq_iff @[simp, norm_cast] lemma cast_eq_zero : (p : Ξ±) = 0 ↔ p = 0 := cast_injective.eq_iff' cast_zero lemma cast_ne_zero : (p : Ξ±) β‰  0 ↔ p β‰  0 := cast_eq_zero.ne @[simp, norm_cast] lemma cast_add (p q : β„š) : ↑(p + q) = (p + q : Ξ±) := cast_add_of_ne_zero (Nat.cast_ne_zero.2 p.pos.ne') (Nat.cast_ne_zero.2 q.pos.ne')
Mathlib/Data/Rat/Cast/CharZero.lean
28
38
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.SetTheory.PGame.Algebra import Mathlib.Tactic.Abel /-! # Combinatorial games. In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`. ## Multiplication on pre-games We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x β‰ˆ y` does not imply `x * z β‰ˆ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless, the abelian group structure on games allows us to simplify many proofs for pre-games. -/ -- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec noncomputable section namespace SetTheory open Function PGame universe u -- Porting note: moved the setoid instance to PGame.lean /-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a combinatorial pre-game is built inductively from two families of combinatorial games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. A combinatorial game is then constructed by quotienting by the equivalence `x β‰ˆ y ↔ x ≀ y ∧ y ≀ x`. -/ abbrev Game := Quotient PGame.setoid namespace Game -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition /-- Negation of games. -/ instance : Neg Game where neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2 instance : Zero Game where zero := ⟦0⟧ instance : Add Game where add := Quotient.mapβ‚‚ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where zero := ⟦0⟧ one := ⟦1⟧ add_zero := by rintro ⟨x⟩ exact Quot.sound (add_zero_equiv x) zero_add := by rintro ⟨x⟩ exact Quot.sound (zero_add_equiv x) add_assoc := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact Quot.sound add_assoc_equiv neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x) add_comm := by rintro ⟨x⟩ ⟨y⟩ exact Quot.sound add_comm_equiv nsmul := nsmulRec zsmul := zsmulRec instance : Inhabited Game := ⟨0⟩ theorem zero_def : (0 : Game) = ⟦0⟧ := rfl instance instPartialOrderGame : PartialOrder Game where le := Quotient.liftβ‚‚ (Β· ≀ Β·) fun _ _ _ _ hx hy => propext (le_congr hx hy) le_refl := by rintro ⟨x⟩ exact le_refl x le_trans := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact @le_trans _ _ x y z le_antisymm := by rintro ⟨x⟩ ⟨y⟩ h₁ hβ‚‚ apply Quot.sound exact ⟨h₁, hβ‚‚βŸ© lt := Quotient.liftβ‚‚ (Β· < Β·) fun _ _ _ _ hx hy => propext (lt_congr hx hy) lt_iff_le_not_le := by rintro ⟨x⟩ ⟨y⟩ exact @lt_iff_le_not_le _ _ x y /-- The less or fuzzy relation on games. If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/ def LF : Game β†’ Game β†’ Prop := Quotient.liftβ‚‚ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy) /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_le : βˆ€ {x y : Game}, Β¬x ≀ y ↔ Game.LF y x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_le /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_lf : βˆ€ {x y : Game}, Β¬Game.LF x y ↔ y ≀ x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_lf /-- The fuzzy, confused, or incomparable relation on games. If `x β€– 0`, then the first player can always win `x`. -/ def Fuzzy : Game β†’ Game β†’ Prop := Quotient.liftβ‚‚ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy) -- Porting note: had to replace ⧏ with LF, otherwise cannot differentiate with the operator on PGame instance : IsTrichotomous Game LF := ⟨by rintro ⟨x⟩ ⟨y⟩ change _ ∨ ⟦x⟧ = ⟦y⟧ ∨ _ rw [Quotient.eq] apply lf_or_equiv_or_gf⟩ /-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as the `AddCommGroup` structure on `Game` often simplifies many proofs. -/ end Game namespace PGame -- Porting note: In a lot of places, I had to add explicitly that the quotient element was a Game. -- In Lean4, quotients don't have the setoid as an instance argument, -- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354 theorem le_iff_game_le {x y : PGame} : x ≀ y ↔ (⟦x⟧ : Game) ≀ ⟦y⟧ := Iff.rfl theorem lf_iff_game_lf {x y : PGame} : x ⧏ y ↔ Game.LF ⟦x⟧ ⟦y⟧ := Iff.rfl theorem lt_iff_game_lt {x y : PGame} : x < y ↔ (⟦x⟧ : Game) < ⟦y⟧ := Iff.rfl theorem equiv_iff_game_eq {x y : PGame} : x β‰ˆ y ↔ (⟦x⟧ : Game) = ⟦y⟧ := (@Quotient.eq' _ _ x y).symm alias ⟨game_eq, _⟩ := equiv_iff_game_eq theorem fuzzy_iff_game_fuzzy {x y : PGame} : x β€– y ↔ Game.Fuzzy ⟦x⟧ ⟦y⟧ := Iff.rfl end PGame namespace Game local infixl:50 " ⧏ " => LF local infixl:50 " β€– " => Fuzzy instance addLeftMono : AddLeftMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_left _ _ _ _ b c h a⟩ instance addRightMono : AddRightMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_right _ _ _ _ b c h a⟩ instance addLeftStrictMono : AddLeftStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_left _ _ _ _ b c h a⟩ instance addRightStrictMono : AddRightStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_right _ _ _ _ b c h a⟩ theorem add_lf_add_right : βˆ€ {b c : Game} (_ : b ⧏ c) (a), (b + a : Game) ⧏ c + a := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_right h theorem add_lf_add_left : βˆ€ {b c : Game} (_ : b ⧏ c) (a), (a + b : Game) ⧏ a + c := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_left h instance isOrderedAddMonoid : IsOrderedAddMonoid Game := { add_le_add_left := @add_le_add_left _ _ _ Game.addLeftMono } /-- A small family of games is bounded above. -/ lemma bddAbove_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β†’ Game.{u}) : BddAbove (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddAbove_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded above. -/ lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s β†’ Game.{u}) /-- A small family of games is bounded below. -/ lemma bddBelow_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β†’ Game.{u}) : BddBelow (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddBelow_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded below. -/ lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s β†’ Game.{u}) end Game namespace PGame @[simp] theorem quot_zero : (⟦0⟧ : Game) = 0 := rfl @[simp] theorem quot_one : (⟦1⟧ : Game) = 1 := rfl @[simp] theorem quot_neg (a : PGame) : (⟦-a⟧ : Game) = -⟦a⟧ := rfl @[simp] theorem quot_add (a b : PGame) : ⟦a + b⟧ = (⟦a⟧ : Game) + ⟦b⟧ := rfl @[simp] theorem quot_sub (a b : PGame) : ⟦a - b⟧ = (⟦a⟧ : Game) - ⟦b⟧ := rfl @[simp] theorem quot_natCast : βˆ€ n : β„•, ⟦(n : PGame)⟧ = (n : Game) | 0 => rfl | n + 1 => by rw [PGame.nat_succ, quot_add, Nat.cast_add, Nat.cast_one, quot_natCast] rfl theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : βˆ€ i, (⟦x.moveLeft i⟧ : Game) = ⟦y.moveLeft (L i)⟧) (hr : βˆ€ j, (⟦x.moveRight j⟧ : Game) = ⟦y.moveRight (R j)⟧) : (⟦x⟧ : Game) = ⟦y⟧ := game_eq (.of_equiv L R (fun _ => equiv_iff_game_eq.2 (hl _)) (fun _ => equiv_iff_game_eq.2 (hr _))) /-! Multiplicative operations can be defined at the level of pre-games, but to prove their properties we need to use the abelian group structure of games. Hence we define them here. -/ /-- The product of `x = {xL | xR}` and `y = {yL | yR}` is `{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, xR*y + x*yL - xR*yL}`. -/ instance : Mul PGame.{u} := ⟨fun x y => by induction x generalizing y with | mk xl xr _ _ IHxl IHxr => _ induction y with | mk yl yr yL yR IHyl IHyr => _ have y := mk yl yr yL yR refine ⟨(xl Γ— yl) βŠ• (xr Γ— yr), (xl Γ— yr) βŠ• (xr Γ— yl), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) Β· exact IHxl i y + IHyl j - IHxl i (yL j) Β· exact IHxr i y + IHyr j - IHxr i (yR j) Β· exact IHxl i y + IHyr j - IHxl i (yR j) Β· exact IHxr i y + IHyl j - IHxr i (yL j)⟩ theorem leftMoves_mul : βˆ€ x y : PGame.{u}, (x * y).LeftMoves = (x.LeftMoves Γ— y.LeftMoves βŠ• x.RightMoves Γ— y.RightMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl theorem rightMoves_mul : βˆ€ x y : PGame.{u}, (x * y).RightMoves = (x.LeftMoves Γ— y.RightMoves βŠ• x.RightMoves Γ— y.LeftMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl /-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toLeftMovesMul {x y : PGame} : (x.LeftMoves Γ— y.LeftMoves) βŠ• (x.RightMoves Γ— y.RightMoves) ≃ (x * y).LeftMoves := Equiv.cast (leftMoves_mul x y).symm /-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toRightMovesMul {x y : PGame} : (x.LeftMoves Γ— y.RightMoves) βŠ• (x.RightMoves Γ— y.LeftMoves) ≃ (x * y).RightMoves := Equiv.cast (rightMoves_mul x y).symm @[simp] theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j := rfl @[simp] theorem mul_moveLeft_inl {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by cases x cases y rfl @[simp] theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j := rfl @[simp] theorem mul_moveLeft_inr {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j := rfl @[simp] theorem mul_moveRight_inl {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j := rfl @[simp] theorem mul_moveRight_inr {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by cases x cases y rfl @[simp] theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) := rfl @[simp] theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) := rfl theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves β†’ Prop} (hl : βˆ€ ix iy, P <| toLeftMovesMul (Sum.inl ⟨ix, iy⟩)) (hr : βˆ€ jx jy, P <| toLeftMovesMul (Sum.inr ⟨jx, jy⟩)) : P k := by rw [← toLeftMovesMul.apply_symm_apply k] rcases toLeftMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) Β· apply hl Β· apply hr theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves β†’ Prop} (hl : βˆ€ ix jy, P <| toRightMovesMul (Sum.inl ⟨ix, jy⟩)) (hr : βˆ€ jx iy, P <| toRightMovesMul (Sum.inr ⟨jx, iy⟩)) : P k := by rw [← toRightMovesMul.apply_symm_apply k] rcases toRightMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) Β· apply hl Β· apply hr /-- `x * y` and `y * x` have the same moves. -/ protected lemma mul_comm (x y : PGame) : x * y ≑ y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine Identical.of_equiv ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _)) ((Equiv.sumComm _ _).trans ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))) ?_ ?_ <;> Β· rintro (⟨_, _⟩ | ⟨_, _⟩) <;> exact ((((PGame.mul_comm _ (mk _ _ _ _)).add (PGame.mul_comm (mk _ _ _ _) _)).trans (PGame.add_comm _ _)).sub (PGame.mul_comm _ _)) termination_by (x, y) /-- `x * y` and `y * x` have the same moves. -/ def mulCommRelabelling (x y : PGame.{u}) : x * y ≑r y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _), (Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> { dsimp exact ((addCommRelabelling _ _).trans <| (mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr (mulCommRelabelling _ _) } termination_by (x, y) theorem quot_mul_comm (x y : PGame.{u}) : (⟦x * y⟧ : Game) = ⟦y * x⟧ := game_eq (x.mul_comm y).equiv /-- `x * y` is equivalent to `y * x`. -/ theorem mul_comm_equiv (x y : PGame) : x * y β‰ˆ y * x := Quotient.exact <| quot_mul_comm _ _ instance isEmpty_leftMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves Γ— y.LeftMoves βŠ• x.RightMoves Γ— y.RightMoves)] : IsEmpty (x * y).LeftMoves := by cases x cases y assumption instance isEmpty_rightMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves Γ— y.RightMoves βŠ• x.RightMoves Γ— y.LeftMoves)] : IsEmpty (x * y).RightMoves := by cases x cases y assumption /-- `x * 0` has exactly the same moves as `0`. -/ protected lemma mul_zero (x : PGame) : x * 0 ≑ 0 := identical_zero _ /-- `x * 0` has exactly the same moves as `0`. -/ def mulZeroRelabelling (x : PGame) : x * 0 ≑r 0 := Relabelling.isEmpty _ /-- `x * 0` is equivalent to `0`. -/ theorem mul_zero_equiv (x : PGame) : x * 0 β‰ˆ 0 := x.mul_zero.equiv @[simp] theorem quot_mul_zero (x : PGame) : (⟦x * 0⟧ : Game) = 0 := game_eq x.mul_zero_equiv /-- `0 * x` has exactly the same moves as `0`. -/ protected lemma zero_mul (x : PGame) : 0 * x ≑ 0 := identical_zero _ /-- `0 * x` has exactly the same moves as `0`. -/ def zeroMulRelabelling (x : PGame) : 0 * x ≑r 0 := Relabelling.isEmpty _ /-- `0 * x` is equivalent to `0`. -/ theorem zero_mul_equiv (x : PGame) : 0 * x β‰ˆ 0 := x.zero_mul.equiv @[simp] theorem quot_zero_mul (x : PGame) : (⟦0 * x⟧ : Game) = 0 := game_eq x.zero_mul_equiv /-- `-x * y` and `-(x * y)` have the same moves. -/ def negMulRelabelling (x y : PGame.{u}) : -x * y ≑r -(x * y) := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> Β· dsimp apply ((negAddRelabelling _ _).trans _).symm apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr -- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here. Β· exact (negMulRelabelling _ _).symm Β· exact (negMulRelabelling _ _).symm -- Porting note: not sure what has gone wrong here. -- The goal is hideous here, and the `exact` doesn't work, -- but if we just `change` it to look like the mathlib3 goal then we're fine!? change -(mk xl xr xL xR * _) ≑r _ exact (negMulRelabelling _ _).symm termination_by (x, y) /-- `x * -y` and `-(x * y)` have the same moves. -/ @[simp] lemma mul_neg (x y : PGame) : x * -y = -(x * y) := match x, y with | mk xl xr xL xR, mk yl yr yL yR => by refine ext rfl rfl ?_ ?_ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) _ ⟨rfl⟩ all_goals dsimp rw [PGame.neg_sub', PGame.neg_add] congr exacts [mul_neg _ (mk ..), mul_neg .., mul_neg ..] termination_by (x, y) /-- `-x * y` and `-(x * y)` have the same moves. -/ lemma neg_mul (x y : PGame) : -x * y ≑ -(x * y) := ((PGame.mul_comm _ _).trans (of_eq (mul_neg _ _))).trans (PGame.mul_comm _ _).neg @[simp] theorem quot_neg_mul (x y : PGame) : (⟦-x * y⟧ : Game) = -⟦x * y⟧ := game_eq (x.neg_mul y).equiv /-- `x * -y` and `-(x * y)` have the same moves. -/ def mulNegRelabelling (x y : PGame) : x * -y ≑r -(x * y) := (mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr theorem quot_mul_neg (x y : PGame) : ⟦x * -y⟧ = (-⟦x * y⟧ : Game) := game_eq (by rw [mul_neg]) theorem quot_neg_mul_neg (x y : PGame) : ⟦-x * -y⟧ = (⟦x * y⟧ : Game) := by simp @[simp] theorem quot_left_distrib (x y z : PGame) : (⟦x * (y + z)⟧ : Game) = ⟦x * y⟧ + ⟦x * z⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ Β· fconstructor Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> -- Porting note: we've increased `maxDepth` here from `5` to `6`. -- Likely this sort of off-by-one error is just a change in the implementation -- of `solve_by_elim`. solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl Β· fconstructor Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_left_distrib reference below, because otherwise the decreasing_by block -- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel` -- See https://github.com/leanprover/lean4/issues/2288 Β· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) Β· change ⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧ = ⟦xL i * y + x * yL j - xL i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)] abel Β· change ⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧ = ⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)] abel Β· change ⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧ = ⟦xR i * y + x * yR j - xR i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)] abel Β· change ⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧ = ⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)] abel Β· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) Β· change ⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧ = ⟦xL i * y + x * yR j - xL i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)] abel Β· change ⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧ = ⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)] abel Β· change ⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧ = ⟦xR i * y + x * yL j - xR i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)] abel Β· change ⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧ = ⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)] abel termination_by (x, y, z) /-- `x * (y + z)` is equivalent to `x * y + x * z`. -/ theorem left_distrib_equiv (x y z : PGame) : x * (y + z) β‰ˆ x * y + x * z := Quotient.exact <| quot_left_distrib _ _ _ @[simp] theorem quot_left_distrib_sub (x y z : PGame) : (⟦x * (y - z)⟧ : Game) = ⟦x * y⟧ - ⟦x * z⟧ := by change (⟦x * (y + -z)⟧ : Game) = ⟦x * y⟧ + -⟦x * z⟧ rw [quot_left_distrib, quot_mul_neg] @[simp] theorem quot_right_distrib (x y z : PGame) : (⟦(x + y) * z⟧ : Game) = ⟦x * z⟧ + ⟦y * z⟧ := by simp only [quot_mul_comm, quot_left_distrib] /-- `(x + y) * z` is equivalent to `x * z + y * z`. -/ theorem right_distrib_equiv (x y z : PGame) : (x + y) * z β‰ˆ x * z + y * z := Quotient.exact <| quot_right_distrib _ _ _ @[simp] theorem quot_right_distrib_sub (x y z : PGame) : (⟦(y - z) * x⟧ : Game) = ⟦y * x⟧ - ⟦z * x⟧ := by change (⟦(y + -z) * x⟧ : Game) = ⟦y * x⟧ + -⟦z * x⟧ rw [quot_right_distrib, quot_neg_mul] /-- `x * 1` has the same moves as `x`. -/ def mulOneRelabelling : βˆ€ x : PGame.{u}, x * 1 ≑r x | ⟨xl, xr, xL, xR⟩ => by -- Porting note: the next four lines were just `unfold has_one.one,` show _ * One.one ≑r _ unfold One.one unfold instOnePGame change mk _ _ _ _ * mk _ _ _ _ ≑r _ refine ⟨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _), (Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_⟩ <;> (try rintro (⟨i, ⟨⟩⟩ | ⟨i, ⟨⟩⟩)) <;> { dsimp apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans rw [sub_zero_eq_add_zero] exact (addZeroRelabelling _).trans <| (((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) } /-- `1 * x` has the same moves as `x`. -/ protected lemma one_mul : βˆ€ (x : PGame), 1 * x ≑ x | ⟨xl, xr, xL, xR⟩ => by refine Identical.of_equiv ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ?_ ?_ <;> Β· rintro (⟨⟨⟩, _⟩ | ⟨⟨⟩, _⟩) exact ((((PGame.zero_mul (mk _ _ _ _)).add (PGame.one_mul _)).trans (PGame.zero_add _)).sub (PGame.zero_mul _)).trans (PGame.sub_zero _) /-- `x * 1` has the same moves as `x`. -/ protected lemma mul_one (x : PGame) : x * 1 ≑ x := (x.mul_comm _).trans x.one_mul @[simp] theorem quot_mul_one (x : PGame) : (⟦x * 1⟧ : Game) = ⟦x⟧ := game_eq x.mul_one.equiv /-- `x * 1` is equivalent to `x`. -/ theorem mul_one_equiv (x : PGame) : x * 1 β‰ˆ x := Quotient.exact <| quot_mul_one x /-- `1 * x` has the same moves as `x`. -/ def oneMulRelabelling (x : PGame) : 1 * x ≑r x := (mulCommRelabelling 1 x).trans <| mulOneRelabelling x @[simp] theorem quot_one_mul (x : PGame) : (⟦1 * x⟧ : Game) = ⟦x⟧ := game_eq x.one_mul.equiv /-- `1 * x` is equivalent to `x`. -/ theorem one_mul_equiv (x : PGame) : 1 * x β‰ˆ x := Quotient.exact <| quot_one_mul x theorem quot_mul_assoc (x y z : PGame) : (⟦x * y * z⟧ : Game) = ⟦x * (y * z)⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ Β· fconstructor Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> -- Porting note: as above, increased the `maxDepth` here by 1. solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl Β· fconstructor Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_mul_assoc reference below, because otherwise the decreasing_by block -- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel` -- See https://github.com/leanprover/lean4/issues/2288 Β· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) Β· change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k - (xL i * y + x * yL j - xL i * yL j) * zL k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xL i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xL i) (yL j) (zL k)] abel Β· change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k - (xR i * y + x * yR j - xR i * yR j) * zL k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xR i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xR i) (yR j) (zL k)] abel Β· change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k - (xL i * y + x * yR j - xL i * yR j) * zR k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xL i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xL i) (yR j) (zR k)] abel Β· change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k - (xR i * y + x * yL j - xR i * yL j) * zR k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xR i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xR i) (yL j) (zR k)] abel Β· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) Β· change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k - (xL i * y + x * yL j - xL i * yL j) * zR k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xL i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xL i) (yL j) (zR k)] abel Β· change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k - (xR i * y + x * yR j - xR i * yR j) * zR k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xR i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xR i) (yR j) (zR k)] abel Β· change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k - (xL i * y + x * yR j - xL i * yR j) * zL k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xL i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xL i) (yR j) (zL k)] abel Β· change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k - (xR i * y + x * yL j - xR i * yL j) * zL k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xR i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xR i) (yL j) (zL k)] abel termination_by (x, y, z) /-- `x * y * z` is equivalent to `x * (y * z)`. -/ theorem mul_assoc_equiv (x y z : PGame) : x * y * z β‰ˆ x * (y * z) := Quotient.exact <| quot_mul_assoc _ _ _ /-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/ def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame := x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j /-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of the first kind. -/ lemma mulOption_neg_neg {x} (y) {i j} : mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by simp [mulOption] /-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/ lemma mulOption_symm (x y) {i j} : ⟦mulOption x y i j⟧ = (⟦mulOption y x j i⟧ : Game) := by dsimp only [mulOption, quot_sub, quot_add] rw [add_comm] congr 1 on_goal 1 => congr 1 all_goals rw [quot_mul_comm] /-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the first kind, up to equivalence. -/ lemma leftMoves_mul_iff {x y : PGame} (P : Game β†’ Prop) : (βˆ€ k, P ⟦(x * y).moveLeft k⟧) ↔ (βˆ€ i j, P ⟦mulOption x y i j⟧) ∧ (βˆ€ i j, P ⟦mulOption (-x) (-y) i j⟧) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j Β· exact h (Sum.inl (i, j)) convert h (Sum.inr (i, j)) using 1 on_goal 2 => rintro (⟨i, j⟩ | ⟨i, j⟩) Β· exact h.1 i j convert h.2 i j using 1 all_goals dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk] rw [← neg_def, ← neg_def] congr 1 on_goal 1 => congr 1 all_goals rw [quot_neg_mul_neg] /-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first kind, up to equivalence. -/ lemma rightMoves_mul_iff {x y : PGame} (P : Game β†’ Prop) : (βˆ€ k, P ⟦(x * y).moveRight k⟧) ↔ (βˆ€ i j, P (-⟦mulOption x (-y) i j⟧)) ∧ (βˆ€ i j, P (-⟦mulOption (-x) y i j⟧)) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j on_goal 1 => convert h (Sum.inl (i, j)) on_goal 2 => convert h (Sum.inr (i, j)) on_goal 3 => rintro (⟨i, j⟩ | ⟨i, j⟩) on_goal 1 => convert h.1 i j using 1 on_goal 2 => convert h.2 i j using 1 all_goals dsimp [mulOption] rw [neg_sub', neg_add, ← neg_def] congr 1 on_goal 1 => congr 1 any_goals rw [quot_neg_mul, neg_neg] iterate 6 rw [quot_mul_neg, neg_neg] /-- Because the two halves of the definition of `inv` produce more elements on each side, we have to define the two families inductively. This is the indexing set for the function, and `invVal` is the function part. -/ inductive InvTy (l r : Type u) : Bool β†’ Type u | zero : InvTy l r false | left₁ : r β†’ InvTy l r false β†’ InvTy l r false | leftβ‚‚ : l β†’ InvTy l r true β†’ InvTy l r false | right₁ : l β†’ InvTy l r false β†’ InvTy l r true | rightβ‚‚ : r β†’ InvTy l r true β†’ InvTy l r true instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) := ⟨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim a⟩ instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) := ⟨InvTy.zero⟩ instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) := { InvTy.instInhabited l r with uniq := by rintro (a | a | a) Β· rfl all_goals exact isEmptyElim a } /-- Because the two halves of the definition of `inv` produce more elements of each side, we have to define the two families inductively. This is the function part, defined by recursion on `InvTy`. -/ def invVal {l r} (L : l β†’ PGame) (R : r β†’ PGame) (IHl : l β†’ PGame) (IHr : r β†’ PGame) (x : PGame) : βˆ€ {b}, InvTy l r b β†’ PGame | _, InvTy.zero => 0 | _, InvTy.left₁ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i | _, InvTy.leftβ‚‚ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.right₁ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.rightβ‚‚ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i @[simp] theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l] [IsEmpty r] : invVal L R IHl IHr x i = 0 := by obtain - | a | a | a | a := i Β· rfl all_goals exact isEmptyElim a /-- The inverse of a positive surreal number `x = {L | R}` is given by `x⁻¹ = {0, (1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L | (1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`. Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own definition, the sets and elements are inductively generated. -/ def inv' : PGame β†’ PGame | ⟨l, r, L, R⟩ => let l' := { i // 0 < L i } let L' : l' β†’ PGame := fun i => L i.1 let IHl' : l' β†’ PGame := fun i => inv' (L i.1) let IHr i := inv' (R i) let x := mk l r L R ⟨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr x⟩ theorem zero_lf_inv' : βˆ€ x : PGame, 0 ⧏ inv' x | ⟨xl, xr, xL, xR⟩ => by convert lf_mk _ _ InvTy.zero rfl /-- `inv' 0` has exactly the same moves as `1`. -/ def inv'Zero : inv' 0 ≑r 1 := by change mk _ _ _ _ ≑r 1 refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩ Β· apply Equiv.equivPUnit (InvTy _ _ _) Β· apply Equiv.equivPEmpty (InvTy _ _ _) Β· -- Porting note: we added `rfl` after the `simp` -- (because `simp` now uses `rfl` only at reducible transparency) -- Can we improve the simp set so it is not needed? simp; rfl Β· dsimp infer_instance theorem inv'_zero_equiv : inv' 0 β‰ˆ 1 := inv'Zero.equiv /-- `inv' 1` has exactly the same moves as `1`. -/ lemma inv'_one : inv' 1 ≑ 1 := by rw [Identical.ext_iff] constructor Β· simp [memβ‚—_def, inv', isEmpty_subtype] Β· simp [memα΅£_def, inv', isEmpty_subtype] /-- `inv' 1` has exactly the same moves as `1`. -/
def inv'One : inv' 1 ≑r (1 : PGame.{u}) := by change Relabelling (mk _ _ _ _) 1 have : IsEmpty { _i : PUnit.{u + 1} // (0 : PGame.{u}) < 0 } := by rw [lt_self_iff_false]
Mathlib/SetTheory/Game/Basic.lean
975
978
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Order.Filter.Tendsto import Mathlib.Data.PFun /-! # `Tendsto` for relations and partial functions This file generalizes `Filter` definitions from functions to partial functions and relations. ## Considering functions and partial functions as relations A function `f : Ξ± β†’ Ξ²` can be considered as the relation `Rel Ξ± Ξ²` which relates `x` and `f x` for all `x`, and nothing else. This relation is called `Function.Graph f`. A partial function `f : Ξ± β†’. Ξ²` can be considered as the relation `Rel Ξ± Ξ²` which relates `x` and `f x` for all `x` for which `f x` exists, and nothing else. This relation is called `PFun.Graph' f`. In this regard, a function is a relation for which every element in `Ξ±` is related to exactly one element in `Ξ²` and a partial function is a relation for which every element in `Ξ±` is related to at most one element in `Ξ²`. This file leverages this analogy to generalize `Filter` definitions from functions to partial functions and relations. ## Notes `Set.preimage` can be generalized to relations in two ways: * `Rel.preimage` returns the image of the set under the inverse relation. * `Rel.core` returns the set of elements that are only related to those in the set. Both generalizations are sensible in the context of filters, so `Filter.comap` and `Filter.Tendsto` get two generalizations each. We first take care of relations. Then the definitions for partial functions are taken as special cases of the definitions for relations. -/ universe u v w namespace Filter variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} open Filter /-! ### Relations -/ /-- The forward map of a filter under a relation. Generalization of `Filter.map` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rmap (r : Rel Ξ± Ξ²) (l : Filter Ξ±) : Filter Ξ² where sets := { s | r.core s ∈ l } univ_sets := by simp sets_of_superset hs st := mem_of_superset hs (Rel.core_mono _ st) inter_sets hs ht := by simp only [Set.mem_setOf_eq] convert inter_mem hs ht rw [← Rel.core_inter] theorem rmap_sets (r : Rel Ξ± Ξ²) (l : Filter Ξ±) : (l.rmap r).sets = r.core ⁻¹' l.sets := rfl @[simp] theorem mem_rmap (r : Rel Ξ± Ξ²) (l : Filter Ξ±) (s : Set Ξ²) : s ∈ l.rmap r ↔ r.core s ∈ l := Iff.rfl @[simp] theorem rmap_rmap (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ±) : rmap s (rmap r l) = rmap (r.comp s) l := filter_eq <| by simp [rmap_sets, Set.preimage, Rel.core_comp] @[simp] theorem rmap_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rmap s ∘ rmap r = rmap (r.comp s) := funext <| rmap_rmap _ _ /-- Generic "limit of a relation" predicate. `RTendsto r l₁ lβ‚‚` asserts that for every `lβ‚‚`-neighborhood `a`, the `r`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto (r : Rel Ξ± Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) := l₁.rmap r ≀ lβ‚‚ theorem rtendsto_def (r : Rel Ξ± Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) : RTendsto r l₁ lβ‚‚ ↔ βˆ€ s ∈ lβ‚‚, r.core s ∈ l₁ := Iff.rfl /-- One way of taking the inverse map of a filter under a relation. One generalization of `Filter.comap` to relations. Note that `Rel.core` generalizes `Set.preimage`. -/ def rcomap (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : Filter Ξ± where sets := Rel.image (fun s t => r.core s βŠ† t) f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, haβ‚‚βŸ© ⟨b', hb₁, hbβ‚‚βŸ© => ⟨a' ∩ b', inter_mem ha₁ hb₁, (r.core_inter a' b').subset.trans (Set.inter_subset_inter haβ‚‚ hbβ‚‚)⟩ theorem rcomap_sets (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : (rcomap r f).sets = Rel.image (fun s t => r.core s βŠ† t) f.sets := rfl theorem rcomap_rcomap (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ³) : rcomap r (rcomap s l) = rcomap (r.comp s) l := filter_eq <| by ext t; simp only [rcomap_sets, Rel.image, Filter.mem_sets, Set.mem_setOf_eq, Rel.core_comp] constructor Β· rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, Set.Subset.trans (Rel.core_mono _ hv) h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨Rel.core s t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rcomap r ∘ rcomap s = rcomap (r.comp s) := funext <| rcomap_rcomap _ _ theorem rtendsto_iff_le_rcomap (r : Rel Ξ± Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) : RTendsto r l₁ lβ‚‚ ↔ l₁ ≀ lβ‚‚.rcomap r := by rw [rtendsto_def] simp_rw [← lβ‚‚.mem_sets] constructor Β· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h s t tlβ‚‚ => mem_of_superset (h t tlβ‚‚) Β· simpa [Filter.le_def, rcomap, Rel.mem_image] using fun h t tlβ‚‚ => h _ t tlβ‚‚ Set.Subset.rfl -- Interestingly, there does not seem to be a way to express this relation using a forward map. -- Given a filter `f` on `Ξ±`, we want a filter `f'` on `Ξ²` such that `r.preimage s ∈ f` if -- and only if `s ∈ f'`. But the intersection of two sets satisfying the lhs may be empty. /-- One way of taking the inverse map of a filter under a relation. Generalization of `Filter.comap` to relations. -/ def rcomap' (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : Filter Ξ± where sets := Rel.image (fun s t => r.preimage s βŠ† t) f.sets univ_sets := ⟨Set.univ, univ_mem, Set.subset_univ _⟩ sets_of_superset := fun ⟨a', ha', ma'a⟩ ab => ⟨a', ha', ma'a.trans ab⟩ inter_sets := fun ⟨a', ha₁, haβ‚‚βŸ© ⟨b', hb₁, hbβ‚‚βŸ© => ⟨a' ∩ b', inter_mem ha₁ hb₁, (@Rel.preimage_inter _ _ r _ _).trans (Set.inter_subset_inter haβ‚‚ hbβ‚‚)⟩ @[simp] theorem mem_rcomap' (r : Rel Ξ± Ξ²) (l : Filter Ξ²) (s : Set Ξ±) : s ∈ l.rcomap' r ↔ βˆƒ t ∈ l, r.preimage t βŠ† s := Iff.rfl theorem rcomap'_sets (r : Rel Ξ± Ξ²) (f : Filter Ξ²) : (rcomap' r f).sets = Rel.image (fun s t => r.preimage s βŠ† t) f.sets := rfl @[simp] theorem rcomap'_rcomap' (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) (l : Filter Ξ³) : rcomap' r (rcomap' s l) = rcomap' (r.comp s) l := Filter.ext fun t => by simp only [mem_rcomap', Rel.preimage_comp] constructor Β· rintro ⟨u, ⟨v, vsets, hv⟩, h⟩ exact ⟨v, vsets, (Rel.preimage_mono _ hv).trans h⟩ rintro ⟨t, tsets, ht⟩ exact ⟨s.preimage t, ⟨t, tsets, Set.Subset.rfl⟩, ht⟩ @[simp] theorem rcomap'_compose (r : Rel Ξ± Ξ²) (s : Rel Ξ² Ξ³) : rcomap' r ∘ rcomap' s = rcomap' (r.comp s) := funext <| rcomap'_rcomap' _ _ /-- Generic "limit of a relation" predicate. `RTendsto' r l₁ lβ‚‚` asserts that for every `lβ‚‚`-neighborhood `a`, the `r`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to relations. -/ def RTendsto' (r : Rel Ξ± Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) := l₁ ≀ lβ‚‚.rcomap' r theorem rtendsto'_def (r : Rel Ξ± Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) : RTendsto' r l₁ lβ‚‚ ↔ βˆ€ s ∈ lβ‚‚, r.preimage s ∈ l₁ := by unfold RTendsto' rcomap'; constructor Β· simpa [le_def, Rel.mem_image] using fun h s hs => h _ _ hs Set.Subset.rfl Β· simpa [le_def, Rel.mem_image] using fun h s t ht => mem_of_superset (h t ht) theorem tendsto_iff_rtendsto (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) (f : Ξ± β†’ Ξ²) : Tendsto f l₁ lβ‚‚ ↔ RTendsto (Function.graph f) l₁ lβ‚‚ := by simp [tendsto_def, Function.graph, rtendsto_def, Rel.core, Set.preimage] theorem tendsto_iff_rtendsto' (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) (f : Ξ± β†’ Ξ²) : Tendsto f l₁ lβ‚‚ ↔ RTendsto' (Function.graph f) l₁ lβ‚‚ := by simp [tendsto_def, Function.graph, rtendsto'_def, Rel.preimage_def, Set.preimage] /-! ### Partial functions -/ /-- The forward map of a filter under a partial function. Generalization of `Filter.map` to partial functions. -/ def pmap (f : Ξ± β†’. Ξ²) (l : Filter Ξ±) : Filter Ξ² := Filter.rmap f.graph' l @[simp] theorem mem_pmap (f : Ξ± β†’. Ξ²) (l : Filter Ξ±) (s : Set Ξ²) : s ∈ l.pmap f ↔ f.core s ∈ l := Iff.rfl /-- Generic "limit of a partial function" predicate. `PTendsto r l₁ lβ‚‚` asserts that for every `lβ‚‚`-neighborhood `a`, the `p`-core of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial function. -/ def PTendsto (f : Ξ± β†’. Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) := l₁.pmap f ≀ lβ‚‚ theorem ptendsto_def (f : Ξ± β†’. Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) : PTendsto f l₁ lβ‚‚ ↔ βˆ€ s ∈ lβ‚‚, f.core s ∈ l₁ := Iff.rfl theorem ptendsto_iff_rtendsto (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) (f : Ξ± β†’. Ξ²) : PTendsto f l₁ lβ‚‚ ↔ RTendsto f.graph' l₁ lβ‚‚ := Iff.rfl theorem pmap_res (l : Filter Ξ±) (s : Set Ξ±) (f : Ξ± β†’ Ξ²) : pmap (PFun.res f s) l = map f (l βŠ“ π“Ÿ s) := by ext t simp only [PFun.core_res, mem_pmap, mem_map, mem_inf_principal, imp_iff_not_or] rfl theorem tendsto_iff_ptendsto (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) (s : Set Ξ±) (f : Ξ± β†’ Ξ²) : Tendsto f (l₁ βŠ“ π“Ÿ s) lβ‚‚ ↔ PTendsto (PFun.res f s) l₁ lβ‚‚ := by simp only [Tendsto, PTendsto, pmap_res] theorem tendsto_iff_ptendsto_univ (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) (f : Ξ± β†’ Ξ²) : Tendsto f l₁ lβ‚‚ ↔ PTendsto (PFun.res f Set.univ) l₁ lβ‚‚ := by rw [← tendsto_iff_ptendsto] simp [principal_univ] /-- Inverse map of a filter under a partial function. One generalization of `Filter.comap` to partial functions. -/ def pcomap' (f : Ξ± β†’. Ξ²) (l : Filter Ξ²) : Filter Ξ± := Filter.rcomap' f.graph' l /-- Generic "limit of a partial function" predicate. `PTendsto' r l₁ lβ‚‚` asserts that for every `lβ‚‚`-neighborhood `a`, the `p`-preimage of `a` is an `l₁`-neighborhood. One generalization of `Filter.Tendsto` to partial functions. -/ def PTendsto' (f : Ξ± β†’. Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) := l₁ ≀ lβ‚‚.rcomap' f.graph' theorem ptendsto'_def (f : Ξ± β†’. Ξ²) (l₁ : Filter Ξ±) (lβ‚‚ : Filter Ξ²) :
PTendsto' f l₁ lβ‚‚ ↔ βˆ€ s ∈ lβ‚‚, f.preimage s ∈ l₁ := rtendsto'_def _ _ _ theorem ptendsto_of_ptendsto' {f : Ξ± β†’. Ξ²} {l₁ : Filter Ξ±} {lβ‚‚ : Filter Ξ²} : PTendsto' f l₁ lβ‚‚ β†’ PTendsto f l₁ lβ‚‚ := by
Mathlib/Order/Filter/Partial.lean
236
240
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.Algebra.Order.Group.Pointwise.Interval import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.Rat.Cardinal import Mathlib.SetTheory.Cardinal.Continuum /-! # The cardinality of the reals This file shows that the real numbers have cardinality continuum, i.e. `#ℝ = 𝔠`. We show that `#ℝ ≀ 𝔠` by noting that every real number is determined by a Cauchy-sequence of the form `β„• β†’ β„š`, which has cardinality `𝔠`. To show that `#ℝ β‰₯ 𝔠` we define an injection from `{0, 1} ^ β„•` to `ℝ` with `f ↦ Ξ£ n, f n * (1 / 3) ^ n`. We conclude that all intervals with distinct endpoints have cardinality continuum. ## Main definitions * `Cardinal.cantorFunction` is the function that sends `f` in `{0, 1} ^ β„•` to `ℝ` by `f ↦ Ξ£' n, f n * (1 / 3) ^ n` ## Main statements * `Cardinal.mk_real : #ℝ = 𝔠`: the reals have cardinality continuum. * `Cardinal.not_countable_real`: the universal set of real numbers is not countable. We can use this same proof to show that all the other sets in this file are not countable. * 8 lemmas of the form `mk_Ixy_real` for `x,y ∈ {i,o,c}` state that intervals on the reals have cardinality continuum. ## Notation * `𝔠` : notation for `Cardinal.continuum` in locale `Cardinal`, defined in `SetTheory.Continuum`. ## Tags continuum, cardinality, reals, cardinality of the reals -/ open Nat Set open Cardinal noncomputable section namespace Cardinal variable {c : ℝ} {f g : β„• β†’ Bool} {n : β„•} /-- The body of the sum in `cantorFunction`. `cantorFunctionAux c f n = c ^ n` if `f n = true`; `cantorFunctionAux c f n = 0` if `f n = false`. -/ def cantorFunctionAux (c : ℝ) (f : β„• β†’ Bool) (n : β„•) : ℝ := cond (f n) (c ^ n) 0 @[simp] theorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by simp [cantorFunctionAux, h] @[simp] theorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by simp [cantorFunctionAux, h] theorem cantorFunctionAux_nonneg (h : 0 ≀ c) : 0 ≀ cantorFunctionAux c f n := by cases h' : f n Β· simp [h'] Β· simpa [h'] using pow_nonneg h _ theorem cantorFunctionAux_eq (h : f n = g n) : cantorFunctionAux c f n = cantorFunctionAux c g n := by simp [cantorFunctionAux, h] theorem cantorFunctionAux_zero (f : β„• β†’ Bool) : cantorFunctionAux c f 0 = cond (f 0) 1 0 := by cases h : f 0 <;> simp [h] theorem cantorFunctionAux_succ (f : β„• β†’ Bool) : (fun n => cantorFunctionAux c f (n + 1)) = fun n => c * cantorFunctionAux c (fun n => f (n + 1)) n := by ext n cases h : f (n + 1) <;> simp [h, _root_.pow_succ'] theorem summable_cantor_function (f : β„• β†’ Bool) (h1 : 0 ≀ c) (h2 : c < 1) : Summable (cantorFunctionAux c f) := by apply (summable_geometric_of_lt_one h1 h2).summable_of_eq_zero_or_self intro n; cases h : f n <;> simp [h] /-- `cantorFunction c (f : β„• β†’ Bool)` is `Ξ£ n, f n * c ^ n`, where `true` is interpreted as `1` and `false` is interpreted as `0`. It is implemented using `cantorFunctionAux`. -/ def cantorFunction (c : ℝ) (f : β„• β†’ Bool) : ℝ := βˆ‘' n, cantorFunctionAux c f n theorem cantorFunction_le (h1 : 0 ≀ c) (h2 : c < 1) (h3 : βˆ€ n, f n β†’ g n) : cantorFunction c f ≀ cantorFunction c g := by apply (summable_cantor_function f h1 h2).tsum_le_tsum _ (summable_cantor_function g h1 h2) intro n; cases h : f n Β· simp [h, cantorFunctionAux_nonneg h1] replace h3 : g n = true := h3 n h; simp [h, h3] theorem cantorFunction_succ (f : β„• β†’ Bool) (h1 : 0 ≀ c) (h2 : c < 1) : cantorFunction c f = cond (f 0) 1 0 + c * cantorFunction c fun n => f (n + 1) := by rw [cantorFunction, (summable_cantor_function f h1 h2).tsum_eq_zero_add] rw [cantorFunctionAux_succ, tsum_mul_left, cantorFunctionAux, pow_zero, cantorFunction] /-- `cantorFunction c` is strictly increasing with if `0 < c < 1/2`, if we endow `β„• β†’ Bool` with a lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we explicitly write out what it means. -/ theorem increasing_cantorFunction (h1 : 0 < c) (h2 : c < 1 / 2) {n : β„•} {f g : β„• β†’ Bool} (hn : βˆ€ k < n, f k = g k) (fn : f n = false) (gn : g n = true) : cantorFunction c f < cantorFunction c g := by have h3 : c < 1 := by apply h2.trans norm_num induction' n with n ih generalizing f g Β· let f_max : β„• β†’ Bool := fun n => Nat.rec false (fun _ _ => true) n have hf_max : βˆ€ n, f n β†’ f_max n := by intro n hn cases n Β· rw [fn] at hn contradiction simp [f_max] let g_min : β„• β†’ Bool := fun n => Nat.rec true (fun _ _ => false) n have hg_min : βˆ€ n, g_min n β†’ g n := by intro n hn cases n Β· rw [gn] simp at hn apply (cantorFunction_le (le_of_lt h1) h3 hf_max).trans_lt refine lt_of_lt_of_le ?_ (cantorFunction_le (le_of_lt h1) h3 hg_min) have : c / (1 - c) < 1 := by rw [div_lt_one, lt_sub_iff_add_lt] Β· convert _root_.add_lt_add h2 h2 norm_num rwa [sub_pos] convert this Β· rw [cantorFunction_succ _ (le_of_lt h1) h3, div_eq_mul_inv, ← tsum_geometric_of_lt_one (le_of_lt h1) h3] apply zero_add Β· refine (tsum_eq_single 0 ?_).trans ?_ Β· intro n hn cases n Β· contradiction simp [g_min] Β· exact cantorFunctionAux_zero _ rw [cantorFunction_succ f (le_of_lt h1) h3, cantorFunction_succ g (le_of_lt h1) h3] rw [hn 0 <| zero_lt_succ n] apply add_lt_add_left rw [mul_lt_mul_left h1] exact ih (fun k hk => hn _ <| Nat.succ_lt_succ hk) fn gn /-- `cantorFunction c` is injective if `0 < c < 1/2`. -/ theorem cantorFunction_injective (h1 : 0 < c) (h2 : c < 1 / 2) : Function.Injective (cantorFunction c) := by intro f g hfg classical contrapose hfg with h have : βˆƒ n, f n β‰  g n := Function.ne_iff.mp h let n := Nat.find this have hn : βˆ€ k : β„•, k < n β†’ f k = g k := by intro k hk apply of_not_not exact Nat.find_min this hk cases fn : f n Β· apply _root_.ne_of_lt refine increasing_cantorFunction h1 h2 hn fn ?_
apply Bool.eq_true_of_not_eq_false rw [← fn] apply Ne.symm exact Nat.find_spec this Β· apply _root_.ne_of_gt refine increasing_cantorFunction h1 h2 (fun k hk => (hn k hk).symm) ?_ fn apply Bool.eq_false_of_not_eq_true rw [← fn] apply Ne.symm exact Nat.find_spec this /-- The cardinality of the reals, as a type. -/ theorem mk_real : #ℝ = 𝔠 := by apply le_antisymm Β· rw [Real.equivCauchy.cardinal_eq] apply mk_quotient_le.trans apply (mk_subtype_le _).trans_eq rw [← power_def, mk_nat, mkRat, aleph0_power_aleph0] Β· convert mk_le_of_injective (cantorFunction_injective _ _) Β· rw [← power_def, mk_bool, mk_nat, two_power_aleph0] Β· exact 1 / 3 Β· norm_num Β· norm_num /-- The cardinality of the reals, as a set. -/ theorem mk_univ_real : #(Set.univ : Set ℝ) = 𝔠 := by rw [mk_univ, mk_real] /-- **Non-Denumerability of the Continuum**: The reals are not countable. -/ instance : Uncountable ℝ := by rw [← aleph0_lt_mk_iff, mk_real]
Mathlib/Data/Real/Cardinality.lean
168
197
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.Polynomial.CancelLeads import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Algebra.Polynomial.FieldDivision /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : R[X]`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.IsPrimitive` indicates that `p.content = 1`. ## Main Results - `Polynomial.content_mul`: If `p q : R[X]`, then `(p * q).content = p.content * q.content`. - `Polynomial.NormalizedGcdMonoid`: The polynomial ring of a GCD domain is itself a GCD domain. ## Note This has nothing to do with minimal polynomials of primitive elements in finite fields. -/ namespace Polynomial section Primitive variable {R : Type*} [CommSemiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units. Note: This has nothing to do with minimal polynomials of primitive elements in finite fields. -/ def IsPrimitive (p : R[X]) : Prop := βˆ€ r : R, C r ∣ p β†’ IsUnit r theorem isPrimitive_iff_isUnit_of_C_dvd {p : R[X]} : p.IsPrimitive ↔ βˆ€ r : R, C r ∣ p β†’ IsUnit r := Iff.rfl @[simp] theorem isPrimitive_one : IsPrimitive (1 : R[X]) := fun _ h => isUnit_C.mp (isUnit_of_dvd_one h) theorem Monic.isPrimitive {p : R[X]} (hp : p.Monic) : p.IsPrimitive := by rintro r ⟨q, h⟩ exact isUnit_of_mul_eq_one r (q.coeff p.natDegree) (by rwa [← coeff_C_mul, ← h]) theorem IsPrimitive.ne_zero [Nontrivial R] {p : R[X]} (hp : p.IsPrimitive) : p β‰  0 := by rintro rfl exact (hp 0 (dvd_zero (C 0))).ne_zero rfl theorem isPrimitive_of_dvd {p q : R[X]} (hp : IsPrimitive p) (hq : q ∣ p) : IsPrimitive q := fun a ha => isPrimitive_iff_isUnit_of_C_dvd.mp hp a (dvd_trans ha hq) /-- An irreducible nonconstant polynomial over a domain is primitive. -/ theorem _root_.Irreducible.isPrimitive [NoZeroDivisors R] {p : Polynomial R} (hp : Irreducible p) (hp' : p.natDegree β‰  0) : p.IsPrimitive := by rintro r ⟨q, hq⟩ suffices Β¬IsUnit q by simpa using ((hp.2 hq).resolve_right this).map Polynomial.constantCoeff intro H have hr : r β‰  0 := by rintro rfl; simp_all obtain ⟨s, hs, rfl⟩ := Polynomial.isUnit_iff.mp H simp [hq, Polynomial.natDegree_C_mul hr] at hp' end Primitive variable {R : Type*} [CommRing R] [IsDomain R] section NormalizedGCDMonoid variable [NormalizedGCDMonoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : R[X]) : R := p.support.gcd p.coeff theorem content_dvd_coeff {p : R[X]} (n : β„•) : p.content ∣ p.coeff n := by by_cases h : n ∈ p.support Β· apply Finset.gcd_dvd h rw [mem_support_iff, Classical.not_not] at h rw [h] apply dvd_zero @[simp] theorem content_C {r : R} : (C r).content = normalize r := by rw [content] by_cases h0 : r = 0 Β· simp [h0] have h : (C r).support = {0} := support_monomial _ h0 simp [h] @[simp] theorem content_zero : content (0 : R[X]) = 0 := by rw [← C_0, content_C, normalize_zero] @[simp] theorem content_one : content (1 : R[X]) = 1 := by rw [← C_1, content_C, normalize_one] theorem content_X_mul {p : R[X]} : content (X * p) = content p := by rw [content, content, Finset.gcd_def, Finset.gcd_def] refine congr rfl ?_ have h : (X * p).support = p.support.map ⟨Nat.succ, Nat.succ_injective⟩ := by ext a simp only [exists_prop, Finset.mem_map, Function.Embedding.coeFn_mk, Ne, mem_support_iff] rcases a with - | a Β· simp [coeff_X_mul_zero, Nat.succ_ne_zero] rw [mul_comm, coeff_mul_X] constructor Β· intro h use a Β· rintro ⟨b, ⟨h1, h2⟩⟩ rw [← Nat.succ_injective h2] apply h1 rw [h] simp only [Finset.map_val, Function.comp_apply, Function.Embedding.coeFn_mk, Multiset.map_map] refine congr (congr rfl ?_) rfl ext a rw [mul_comm] simp [coeff_mul_X] @[simp] theorem content_X_pow {k : β„•} : content ((X : R[X]) ^ k) = 1 := by induction' k with k hi Β· simp rw [pow_succ', content_X_mul, hi] @[simp] theorem content_X : content (X : R[X]) = 1 := by rw [← mul_one X, content_X_mul, content_one] theorem content_C_mul (r : R) (p : R[X]) : (C r * p).content = normalize r * p.content := by by_cases h0 : r = 0; Β· simp [h0] rw [content]; rw [content]; rw [← Finset.gcd_mul_left] refine congr (congr rfl ?_) ?_ <;> ext <;> simp [h0, mem_support_iff] @[simp] theorem content_monomial {r : R} {k : β„•} : content (monomial k r) = normalize r := by rw [← C_mul_X_pow_eq_monomial, content_C_mul, content_X_pow, mul_one] theorem content_eq_zero_iff {p : R[X]} : content p = 0 ↔ p = 0 := by rw [content, Finset.gcd_eq_zero_iff] constructor <;> intro h Β· ext n by_cases h0 : n ∈ p.support Β· rw [h n h0, coeff_zero] Β· rw [mem_support_iff] at h0 push_neg at h0 simp [h0] Β· intro x simp [h] -- Porting note: this reduced with simp so created `normUnit_content` and put simp on it theorem normalize_content {p : R[X]} : normalize p.content = p.content := Finset.normalize_gcd @[simp] theorem normUnit_content {p : R[X]} : normUnit (content p) = 1 := by by_cases hp0 : p.content = 0 Β· simp [hp0] Β· ext apply mul_left_cancelβ‚€ hp0 rw [← normalize_apply, normalize_content, Units.val_one, mul_one] theorem content_eq_gcd_range_of_lt (p : R[X]) (n : β„•) (h : p.natDegree < n) : p.content = (Finset.range n).gcd p.coeff := by apply dvd_antisymm_of_normalize_eq normalize_content Finset.normalize_gcd Β· rw [Finset.dvd_gcd_iff] intro i _ apply content_dvd_coeff _ Β· apply Finset.gcd_mono intro i simp only [Nat.lt_succ_iff, mem_support_iff, Ne, Finset.mem_range] contrapose! intro h1 apply coeff_eq_zero_of_natDegree_lt (lt_of_lt_of_le h h1) theorem content_eq_gcd_range_succ (p : R[X]) : p.content = (Finset.range p.natDegree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (Nat.lt_succ_self _) theorem content_eq_gcd_leadingCoeff_content_eraseLead (p : R[X]) : p.content = GCDMonoid.gcd p.leadingCoeff (eraseLead p).content := by by_cases h : p = 0 Β· simp [h] rw [← leadingCoeff_eq_zero, leadingCoeff, ← Ne, ← mem_support_iff] at h rw [content, ← Finset.insert_erase h, Finset.gcd_insert, leadingCoeff, content, eraseLead_support] refine congr rfl (Finset.gcd_congr rfl fun i hi => ?_) rw [Finset.mem_erase] at hi rw [eraseLead_coeff, if_neg hi.1] theorem dvd_content_iff_C_dvd {p : R[X]} {r : R} : r ∣ p.content ↔ C r ∣ p := by rw [C_dvd_iff_dvd_coeff] constructor Β· intro h i apply h.trans (content_dvd_coeff _) Β· intro h rw [content, Finset.dvd_gcd_iff] intro i _ apply h i theorem C_content_dvd (p : R[X]) : C p.content ∣ p := dvd_content_iff_C_dvd.1 dvd_rfl theorem isPrimitive_iff_content_eq_one {p : R[X]} : p.IsPrimitive ↔ p.content = 1 := by rw [← normalize_content, normalize_eq_one, IsPrimitive] simp_rw [← dvd_content_iff_C_dvd] exact ⟨fun h => h p.content (dvd_refl p.content), fun h r hdvd => isUnit_of_dvd_unit hdvd h⟩ theorem IsPrimitive.content_eq_one {p : R[X]} (hp : p.IsPrimitive) : p.content = 1 := isPrimitive_iff_content_eq_one.mp hp section PrimPart /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.primPart = 1`. -/ noncomputable def primPart (p : R[X]) : R[X] := letI := Classical.decEq R if p = 0 then 1 else Classical.choose (C_content_dvd p) theorem eq_C_content_mul_primPart (p : R[X]) : p = C p.content * p.primPart := by by_cases h : p = 0; Β· simp [h] rw [primPart, if_neg h, ← Classical.choose_spec (C_content_dvd p)] @[simp] theorem primPart_zero : primPart (0 : R[X]) = 1 := if_pos rfl theorem isPrimitive_primPart (p : R[X]) : p.primPart.IsPrimitive := by by_cases h : p = 0; Β· simp [h] rw [← content_eq_zero_iff] at h rw [isPrimitive_iff_content_eq_one] apply mul_left_cancelβ‚€ h conv_rhs => rw [p.eq_C_content_mul_primPart, mul_one, content_C_mul, normalize_content] theorem content_primPart (p : R[X]) : p.primPart.content = 1 := p.isPrimitive_primPart.content_eq_one theorem primPart_ne_zero (p : R[X]) : p.primPart β‰  0 := p.isPrimitive_primPart.ne_zero theorem natDegree_primPart (p : R[X]) : p.primPart.natDegree = p.natDegree := by by_cases h : C p.content = 0 Β· rw [C_eq_zero, content_eq_zero_iff] at h simp [h] conv_rhs => rw [p.eq_C_content_mul_primPart, natDegree_mul h p.primPart_ne_zero, natDegree_C, zero_add] @[simp] theorem IsPrimitive.primPart_eq {p : R[X]} (hp : p.IsPrimitive) : p.primPart = p := by rw [← one_mul p.primPart, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_primPart] theorem isUnit_primPart_C (r : R) : IsUnit (C r).primPart := by by_cases h0 : r = 0 Β· simp [h0] unfold IsUnit refine ⟨⟨C ↑(normUnit r)⁻¹, C ↑(normUnit r), by rw [← RingHom.map_mul, Units.inv_mul, C_1], by rw [← RingHom.map_mul, Units.mul_inv, C_1]⟩, ?_⟩ rw [← normalize_eq_zero, ← C_eq_zero] at h0 apply mul_left_cancelβ‚€ h0 conv_rhs => rw [← content_C, ← (C r).eq_C_content_mul_primPart] simp only [Units.val_mk, normalize_apply, RingHom.map_mul] rw [mul_assoc, ← RingHom.map_mul, Units.mul_inv, C_1, mul_one] theorem primPart_dvd (p : R[X]) : p.primPart ∣ p := Dvd.intro_left (C p.content) p.eq_C_content_mul_primPart.symm theorem aeval_primPart_eq_zero {S : Type*} [Ring S] [IsDomain S] [Algebra R S] [NoZeroSMulDivisors R S] {p : R[X]} {s : S} (hpzero : p β‰  0) (hp : aeval s p = 0) : aeval s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, map_mul, aeval_C] at hp have hcont : p.content β‰  0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne (FaithfulSMul.algebraMap_injective R S) hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp theorem evalβ‚‚_primPart_eq_zero {S : Type*} [CommSemiring S] [IsDomain S] {f : R β†’+* S} (hinj : Function.Injective f) {p : R[X]} {s : S} (hpzero : p β‰  0) (hp : evalβ‚‚ f s p = 0) : evalβ‚‚ f s p.primPart = 0 := by rw [eq_C_content_mul_primPart p, evalβ‚‚_mul, evalβ‚‚_C] at hp have hcont : p.content β‰  0 := fun h => hpzero (content_eq_zero_iff.1 h) replace hcont := Function.Injective.ne hinj hcont rw [map_zero] at hcont exact eq_zero_of_ne_zero_of_mul_left_eq_zero hcont hp end PrimPart theorem gcd_content_eq_of_dvd_sub {a : R} {p q : R[X]} (h : C a ∣ p - q) : GCDMonoid.gcd a p.content = GCDMonoid.gcd a q.content := by rw [content_eq_gcd_range_of_lt p (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_left _ _) (Nat.lt_succ_self _))] rw [content_eq_gcd_range_of_lt q (max p.natDegree q.natDegree).succ (lt_of_le_of_lt (le_max_right _ _) (Nat.lt_succ_self _))] apply Finset.gcd_eq_of_dvd_sub intro x _ obtain ⟨w, hw⟩ := h use w.coeff x rw [← coeff_sub, hw, coeff_C_mul] theorem content_mul_aux {p q : R[X]} : GCDMonoid.gcd (p * q).eraseLead.content p.leadingCoeff = GCDMonoid.gcd (p.eraseLead * q).content p.leadingCoeff := by rw [gcd_comm (content _) _, gcd_comm (content _) _] apply gcd_content_eq_of_dvd_sub rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add, sub_sub_cancel, leadingCoeff_mul, RingHom.map_mul, mul_assoc, mul_assoc] apply dvd_sub (Dvd.intro _ rfl) (Dvd.intro _ rfl) @[simp] theorem content_mul {p q : R[X]} : (p * q).content = p.content * q.content := by classical suffices h : βˆ€ (n : β„•) (p q : R[X]), (p * q).degree < n β†’ (p * q).content = p.content * q.content by apply h apply lt_of_le_of_lt degree_le_natDegree (WithBot.coe_lt_coe.2 (Nat.lt_succ_self _)) intro n induction' n with n ih Β· intro p q hpq rw [Nat.cast_zero, Nat.WithBot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq rcases hpq with (rfl | rfl) <;> simp intro p q hpq by_cases p0 : p = 0 Β· simp [p0] by_cases q0 : q = 0 Β· simp [q0] rw [degree_eq_natDegree (mul_ne_zero p0 q0), Nat.cast_lt, Nat.lt_succ_iff_lt_or_eq, ← Nat.cast_lt (Ξ± := WithBot β„•), ← degree_eq_natDegree (mul_ne_zero p0 q0), natDegree_mul p0 q0] at hpq rcases hpq with (hlt | heq) Β· apply ih _ _ hlt rw [← p.natDegree_primPart, ← q.natDegree_primPart, ← Nat.cast_inj (R := WithBot β„•), Nat.cast_add, ← degree_eq_natDegree p.primPart_ne_zero, ← degree_eq_natDegree q.primPart_ne_zero] at heq rw [p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] suffices h : (q.primPart * p.primPart).content = 1 by rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.primPart, mul_assoc, content_C_mul, content_C_mul, h, mul_one, content_primPart, content_primPart, mul_one, mul_one] rw [← normalize_content, normalize_eq_one, isUnit_iff_dvd_one, content_eq_gcd_leadingCoeff_content_eraseLead, leadingCoeff_mul, gcd_comm] apply (gcd_mul_dvd_mul_gcd _ _ _).trans rw [content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart, one_mul, mul_comm q.primPart, content_mul_aux, ih, content_primPart, mul_one, gcd_comm, ← content_eq_gcd_leadingCoeff_content_eraseLead, content_primPart] Β· rw [← heq, degree_mul, WithBot.add_lt_add_iff_right] Β· apply degree_erase_lt p.primPart_ne_zero Β· rw [Ne, degree_eq_bot] apply q.primPart_ne_zero Β· rw [mul_comm, ← heq, degree_mul, WithBot.add_lt_add_iff_left] Β· apply degree_erase_lt q.primPart_ne_zero Β· rw [Ne, degree_eq_bot] apply p.primPart_ne_zero theorem IsPrimitive.mul {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : (p * q).IsPrimitive := by rw [isPrimitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one] @[simp] theorem primPart_mul {p q : R[X]} (h0 : p * q β‰  0) : (p * q).primPart = p.primPart * q.primPart := by rw [Ne, ← content_eq_zero_iff, ← C_eq_zero] at h0 apply mul_left_cancelβ‚€ h0 conv_lhs => rw [← (p * q).eq_C_content_mul_primPart, p.eq_C_content_mul_primPart, q.eq_C_content_mul_primPart] rw [content_mul, RingHom.map_mul] ring theorem IsPrimitive.dvd_primPart_iff_dvd {p q : R[X]} (hp : p.IsPrimitive) (hq : q β‰  0) : p ∣ q.primPart ↔ p ∣ q := by refine ⟨fun h => h.trans (Dvd.intro_left _ q.eq_C_content_mul_primPart.symm), fun h => ?_⟩ rcases h with ⟨r, rfl⟩ apply Dvd.intro _ rw [primPart_mul hq, hp.primPart_eq] theorem exists_primitive_lcm_of_isPrimitive {p q : R[X]} (hp : p.IsPrimitive) (hq : q.IsPrimitive) : βˆƒ r : R[X], r.IsPrimitive ∧ βˆ€ s : R[X], p ∣ s ∧ q ∣ s ↔ r ∣ s := by classical have h : βˆƒ (n : β„•) (r : R[X]), r.natDegree = n ∧ r.IsPrimitive ∧ p ∣ r ∧ q ∣ r := ⟨(p * q).natDegree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩ rcases Nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩ refine ⟨r, rprim, fun s => ⟨?_, fun rs => ⟨pr.trans rs, qr.trans rs⟩⟩⟩ suffices hs : βˆ€ (n : β„•) (s : R[X]), s.natDegree = n β†’ p ∣ s ∧ q ∣ s β†’ r ∣ s from hs s.natDegree s rfl clear s by_contra! con rcases Nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩ have s0 : s β‰  0 := by contrapose! rs simp [rs] have hs := Nat.find_min' h
⟨_, s.natDegree_primPart, s.isPrimitive_primPart, (hp.dvd_primPart_iff_dvd s0).2 ps, (hq.dvd_primPart_iff_dvd s0).2 qs⟩ rw [← rdeg] at hs
Mathlib/RingTheory/Polynomial/Content.lean
403
405
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {Ξ± Ξ² G M : Type*} section ite variable [Pow Ξ± Ξ²] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : Ξ±) (b : p β†’ Ξ²) (c : Β¬ p β†’ Ξ²) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p β†’ Ξ±) (b : Β¬ p β†’ Ξ±) (c : Ξ²) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : Ξ±) (b c : Ξ²) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : Ξ±) (c : Ξ²) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup Ξ±] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· * Β·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : Ξ±) : (x * Β·) ∘ (y * Β·) = (x * y * Β·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : Ξ±) : (Β· * x) ∘ (Β· * y) = (Β· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (Ξ± := G) (Β· * Β·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * Β·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (Β· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : β„•} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≀ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≀ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n β‰  0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n β‰  0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n β€’ x = 0`, then `m β€’ x` is the same as `(m % n) β€’ x`"] lemma pow_eq_pow_mod (m : β„•) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : βˆ€ n, a * b = 1 β†’ a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : βˆ€ n : β„•, (a * Β·)^[n] = (a ^ n * Β·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : βˆ€ n : β„•, (Β· * a)^[n] = (Β· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * Β·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (Β· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : β„•) : βˆ€ n : β„•, (fun x : M ↦ x ^ k)^[n] = (Β· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : βˆ€ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b β‰  a ↔ b β‰  1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self @[to_additive] theorem left_ne_mul : a β‰  a * b ↔ b β‰  1 := left_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_right end LeftCancelMonoid section RightCancelMonoid variable [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_right : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right @[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_eq_self @[to_additive (attr := simp)] theorem right_eq_mul : b = a * b ↔ a = 1 := eq_comm.trans mul_eq_right @[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_left @[to_additive] theorem mul_ne_right : a * b β‰  b ↔ a β‰  1 := mul_eq_right.not @[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right @[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_ne_self @[to_additive] theorem right_ne_mul : b β‰  a * b ↔ a β‰  1 := right_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid Ξ±] {a b c d : Ξ±} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a β‰  c ↔ b β‰  d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G β†’ G) := inv_inv @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G β†’ G) := inv_involutive.surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G β†’ G) := inv_involutive.injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h β–Έ (inv_inv a).symm, fun h => h.symm β–Έ inv_inv b⟩ variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid Ξ±] {a b c d : Ξ±} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] @[to_additive] lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a β‰  b β†’ a / b β‰  1 := mt eq_of_div_eq_one variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid Ξ± := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : Ξ±) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : Ξ±) : βˆ€ n : β„•, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : βˆ€ n : β„€, (1 : Ξ±) ^ n = 1 | (n : β„•) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : Ξ±) : βˆ€ n : β„€, a ^ (-n) = (a ^ n)⁻¹ | (_ + 1 : β„•) => DivInvMonoid.zpow_neg' _ _ | 0 => by simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : Ξ±) : (a * b) ^ (-1 : β„€) = b ^ (-1 : β„€) * a ^ (-1 : β„€) := by simp only [zpow_neg, zpow_one, mul_inv_rev] @[to_additive zsmul_neg] lemma inv_zpow (a : Ξ±) : βˆ€ n : β„€, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : β„•) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : Ξ±) (n : β„€) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] @[to_additive nsmul_zero_sub] lemma one_div_pow (a : Ξ±) (n : β„•) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : Ξ±) (n : β„€) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one @[to_additive] theorem inv_ne_one : a⁻¹ β‰  1 ↔ a β‰  1 := inv_eq_one.not @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : Ξ±) : βˆ€ m n : β„€, a ^ (m * n) = (a ^ m) ^ n | (m : β„•), (n : β„•) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : β„•), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : β„•) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl @[to_additive mul_zsmul] lemma zpow_mul' (a : Ξ±) (m n : β„€) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] @[to_additive] theorem zpow_comm (a : Ξ±) (m n : β„€) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul'] variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] end DivisionMonoid section DivisionCommMonoid variable [DivisionCommMonoid Ξ±] (a b c d : Ξ±) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp @[to_additive] lemma inv_div_comm (a b : Ξ±) : a⁻¹ / b = b⁻¹ / a := by simp @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp @[to_additive, field_simps] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp @[to_additive zsmul_add] lemma mul_zpow : βˆ€ n : β„€, (a * b) ^ n = a ^ n * b ^ n | (n : β„•) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] @[to_additive nsmul_sub] lemma div_pow (a b : Ξ±) (n : β„•) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] @[to_additive zsmul_sub] lemma div_zpow (a b : Ξ±) (n : β„€) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] attribute [field_simps] div_pow div_zpow end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : β„€} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right] @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * Β·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩ @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] /-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by rw [mul_eq_one_iff_inv_eq, eq_comm] /-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by rw [mul_eq_one_iff_eq_inv, eq_comm] @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_eq_left] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] @[to_additive (attr := simp)] theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right] @[to_additive eq_sub_of_add_eq] theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h] @[to_additive sub_eq_of_eq_add] theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h]
Mathlib/Algebra/Group/Basic.lean
741
741
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Subsemigroup.Operations import Mathlib.Algebra.MonoidAlgebra.Support import Mathlib.Order.Filter.Extr /-! # Lemmas about the `sup` and `inf` of the support of `AddMonoidAlgebra` ## TODO The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a "generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`. Next, the general lemmas get specialized for some yet-to-be-defined `degree`s. -/ variable {R R' A T B ΞΉ : Type*} namespace AddMonoidAlgebra /-! # sup-degree and inf-degree of an `AddMonoidAlgebra` Let `R` be a semiring and let `A` be a `SemilatticeSup`. For an element `f : R[A]`, this file defines * `AddMonoidAlgebra.supDegree`: the sup-degree taking values in `WithBot A`, * `AddMonoidAlgebra.infDegree`: the inf-degree taking values in `WithTop A`. If the grading type `A` is a linearly ordered additive monoid, then these two notions of degree coincide with the standard one: * the sup-degree is the maximum of the exponents of the monomials that appear with non-zero coefficient in `f`, or `βŠ₯`, if `f = 0`; * the inf-degree is the minimum of the exponents of the monomials that appear with non-zero coefficient in `f`, or `⊀`, if `f = 0`. The main results are * `AddMonoidAlgebra.supDegree_mul_le`: the sup-degree of a product is at most the sum of the sup-degrees, * `AddMonoidAlgebra.le_infDegree_mul`: the inf-degree of a product is at least the sum of the inf-degrees, * `AddMonoidAlgebra.supDegree_add_le`: the sup-degree of a sum is at most the sup of the sup-degrees, * `AddMonoidAlgebra.le_infDegree_add`: the inf-degree of a sum is at least the inf of the inf-degrees. ## Implementation notes The current plan is to state and prove lemmas about `Finset.sup (Finsupp.support f) D` with a "generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`. Next, the general lemmas get specialized twice: * once for `supDegree` (essentially a simple application) and * once for `infDegree` (a simple application, via `OrderDual`). These final lemmas are the ones that likely get used the most. The generic lemmas about `Finset.support.sup` may not be used directly much outside of this file. To see this in action, you can look at the triple `(sup_support_mul_le, maxDegree_mul_le, le_minDegree_mul)`. -/ section GeneralResultsAssumingSemilatticeSup variable [SemilatticeSup B] [OrderBot B] [SemilatticeInf T] [OrderTop T] section Semiring variable [Semiring R] section ExplicitDegrees /-! In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in a type with *b*ot or *t*op respectively. -/ variable (degb : A β†’ B) (degt : A β†’ T) (f g : R[A]) theorem sup_support_add_le : (f + g).support.sup degb ≀ f.support.sup degb βŠ” g.support.sup degb := by classical exact (Finset.sup_mono Finsupp.support_add).trans_eq Finset.sup_union theorem le_inf_support_add : f.support.inf degt βŠ“ g.support.inf degt ≀ (f + g).support.inf degt := sup_support_add_le (fun a : A => OrderDual.toDual (degt a)) f g end ExplicitDegrees section AddOnly variable [Add A] [Add B] [Add T] [AddLeftMono B] [AddRightMono B] [AddLeftMono T] [AddRightMono T] theorem sup_support_mul_le {degb : A β†’ B} (degbm : βˆ€ {a b}, degb (a + b) ≀ degb a + degb b) (f g : R[A]) : (f * g).support.sup degb ≀ f.support.sup degb + g.support.sup degb := by classical exact (Finset.sup_mono <| support_mul _ _).trans <| Finset.sup_add_le.2 fun _fd fds _gd gds ↦ degbm.trans <| add_le_add (Finset.le_sup fds) (Finset.le_sup gds) theorem le_inf_support_mul {degt : A β†’ T} (degtm : βˆ€ {a b}, degt a + degt b ≀ degt (a + b)) (f g : R[A]) : f.support.inf degt + g.support.inf degt ≀ (f * g).support.inf degt := sup_support_mul_le (B := Tα΅’α΅ˆ) degtm f g end AddOnly section AddMonoids variable [AddMonoid A] [AddMonoid B] [AddLeftMono B] [AddRightMono B] [AddMonoid T] [AddLeftMono T] [AddRightMono T] {degb : A β†’ B} {degt : A β†’ T} theorem sup_support_list_prod_le (degb0 : degb 0 ≀ 0) (degbm : βˆ€ a b, degb (a + b) ≀ degb a + degb b) : βˆ€ l : List R[A], l.prod.support.sup degb ≀ (l.map fun f : R[A] => f.support.sup degb).sum | [] => by rw [List.map_nil, Finset.sup_le_iff, List.prod_nil, List.sum_nil] exact fun a ha => by rwa [Finset.mem_singleton.mp (Finsupp.support_single_subset ha)] | f::fs => by rw [List.prod_cons, List.map_cons, List.sum_cons] exact (sup_support_mul_le (@fun a b => degbm a b) _ _).trans (add_le_add_left (sup_support_list_prod_le degb0 degbm fs) _) theorem le_inf_support_list_prod (degt0 : 0 ≀ degt 0) (degtm : βˆ€ a b, degt a + degt b ≀ degt (a + b)) (l : List R[A]) : (l.map fun f : R[A] => f.support.inf degt).sum ≀ l.prod.support.inf degt := by refine OrderDual.ofDual_le_ofDual.mpr ?_ refine sup_support_list_prod_le ?_ ?_ l Β· refine (OrderDual.ofDual_le_ofDual.mp ?_)
exact degt0 Β· refine (fun a b => OrderDual.ofDual_le_ofDual.mp ?_) exact degtm a b theorem sup_support_pow_le (degb0 : degb 0 ≀ 0) (degbm : βˆ€ a b, degb (a + b) ≀ degb a + degb b) (n : β„•) (f : R[A]) : (f ^ n).support.sup degb ≀ n β€’ f.support.sup degb := by rw [← List.prod_replicate, ← List.sum_replicate] refine (sup_support_list_prod_le degb0 degbm _).trans_eq ?_ rw [List.map_replicate]
Mathlib/Algebra/MonoidAlgebra/Degree.lean
138
146
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Ring.CharZero import Mathlib.Algebra.Ring.Int.Units import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## HNN Extensions of Groups This file defines the HNN extension of a group `G`, `HNNExtension G A B Ο†`. Given a group `G`, subgroups `A` and `B` and an isomorphism `Ο†` of `A` and `B`, we adjoin a letter `t` to `G`, such that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (Ο† a)`, where `of` is the canonical map from `G` into the `HNNExtension`. This construction is named after Graham Higman, Bernhard Neumann and Hanna Neumann. ## Main definitions - `HNNExtension G A B Ο†` : The HNN Extension of a group `G`, where `A` and `B` are subgroups and `Ο†` is an isomorphism between `A` and `B`. - `HNNExtension.of` : The canonical embedding of `G` into `HNNExtension G A B Ο†`. - `HNNExtension.t` : The stable letter of the HNN extension. - `HNNExtension.lift` : Define a function `HNNExtension G A B Ο† β†’* H`, by defining it on `G` and `t` - `HNNExtension.of_injective` : The canonical embedding `G β†’* HNNExtension G A B Ο†` is injective. - `HNNExtension.ReducedWord.toList_eq_nil_of_mem_of_range` : Britton's Lemma. If an element of `G` is represented by a reduced word, then this reduced word does not contain `t`. -/ assert_not_exists Field open Monoid Coprod Multiplicative Subgroup Function /-- The relation we quotient the coproduct by to form an `HNNExtension`. -/ def HNNExtension.con (G : Type*) [Group G] (A B : Subgroup G) (Ο† : A ≃* B) : Con (G βˆ— Multiplicative β„€) := conGen (fun x y => βˆƒ (a : A), x = inr (ofAdd 1) * inl (a : G) ∧ y = inl (Ο† a : G) * inr (ofAdd 1)) /-- The HNN Extension of a group `G`, `HNNExtension G A B Ο†`. Given a group `G`, subgroups `A` and `B` and an isomorphism `Ο†` of `A` and `B`, we adjoin a letter `t` to `G`, such that for any `a ∈ A`, the conjugate of `of a` by `t` is `of (Ο† a)`, where `of` is the canonical map from `G` into the `HNNExtension`. -/ def HNNExtension (G : Type*) [Group G] (A B : Subgroup G) (Ο† : A ≃* B) : Type _ := (HNNExtension.con G A B Ο†).Quotient variable {G : Type*} [Group G] {A B : Subgroup G} {Ο† : A ≃* B} {H : Type*} [Group H] {M : Type*} [Monoid M] instance : Group (HNNExtension G A B Ο†) := by delta HNNExtension; infer_instance namespace HNNExtension /-- The canonical embedding `G β†’* HNNExtension G A B Ο†` -/ def of : G β†’* HNNExtension G A B Ο† := (HNNExtension.con G A B Ο†).mk'.comp inl /-- The stable letter of the `HNNExtension` -/ def t : HNNExtension G A B Ο† := (HNNExtension.con G A B Ο†).mk'.comp inr (ofAdd 1) theorem t_mul_of (a : A) : t * (of (a : G) : HNNExtension G A B Ο†) = of (Ο† a : G) * t := (Con.eq _).2 <| ConGen.Rel.of _ _ <| ⟨a, by simp⟩ theorem of_mul_t (b : B) : (of (b : G) : HNNExtension G A B Ο†) * t = t * of (Ο†.symm b : G) := by rw [t_mul_of]; simp theorem equiv_eq_conj (a : A) : (of (Ο† a : G) : HNNExtension G A B Ο†) = t * of (a : G) * t⁻¹ := by rw [t_mul_of]; simp theorem equiv_symm_eq_conj (b : B) : (of (Ο†.symm b : G) : HNNExtension G A B Ο†) = t⁻¹ * of (b : G) * t := by rw [mul_assoc, of_mul_t]; simp theorem inv_t_mul_of (b : B) : t⁻¹ * (of (b : G) : HNNExtension G A B Ο†) = of (Ο†.symm b : G) * t⁻¹ := by rw [equiv_symm_eq_conj]; simp theorem of_mul_inv_t (a : A) : (of (a : G) : HNNExtension G A B Ο†) * t⁻¹ = t⁻¹ * of (Ο† a : G) := by rw [equiv_eq_conj]; simp [mul_assoc] /-- Define a function `HNNExtension G A B Ο† β†’* H`, by defining it on `G` and `t` -/ def lift (f : G β†’* H) (x : H) (hx : βˆ€ a : A, x * f ↑a = f (Ο† a : G) * x) : HNNExtension G A B Ο† β†’* H := Con.lift _ (Coprod.lift f (zpowersHom H x)) (Con.conGen_le <| by rintro _ _ ⟨a, rfl, rfl⟩ simp [hx]) @[simp] theorem lift_t (f : G β†’* H) (x : H) (hx : βˆ€ a : A, x * f ↑a = f (Ο† a : G) * x) : lift f x hx t = x := by delta HNNExtension; simp [lift, t] @[simp] theorem lift_of (f : G β†’* H) (x : H) (hx : βˆ€ a : A, x * f ↑a = f (Ο† a : G) * x) (g : G) : lift f x hx (of g) = f g := by delta HNNExtension; simp [lift, of] @[ext high] theorem hom_ext {f g : HNNExtension G A B Ο† β†’* M} (hg : f.comp of = g.comp of) (ht : f t = g t) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext hg (MonoidHom.ext_mint ht) @[elab_as_elim] theorem induction_on {motive : HNNExtension G A B Ο† β†’ Prop} (x : HNNExtension G A B Ο†) (of : βˆ€ g, motive (of g)) (t : motive t) (mul : βˆ€ x y, motive x β†’ motive y β†’ motive (x * y)) (inv : βˆ€ x, motive x β†’ motive x⁻¹) : motive x := by let S : Subgroup (HNNExtension G A B Ο†) := { carrier := setOf motive one_mem' := by simpa using of 1 mul_mem' := mul _ _ inv_mem' := inv _ } let f : HNNExtension G A B Ο† β†’* S := lift (HNNExtension.of.codRestrict S of) ⟨HNNExtension.t, t⟩ (by intro a; ext; simp [equiv_eq_conj, mul_assoc]) have hf : S.subtype.comp f = MonoidHom.id _ := hom_ext (by ext; simp [f]) (by simp [f]) show motive (MonoidHom.id _ x) rw [← hf] exact (f x).2 variable (A B Ο†) /-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u` where `u : β„€Λ£` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`, and `toSubgroupEquiv` is `Ο†` when `u = 1` and `φ⁻¹` when `u = -1`. `toSubgroup u` is the subgroup such that for any `a ∈ toSubgroup u`, `t ^ (u : β„€) * a = toSubgroupEquiv a * t ^ (u : β„€)`. -/ def toSubgroup (u : β„€Λ£) : Subgroup G := if u = 1 then A else B @[simp] theorem toSubgroup_one : toSubgroup A B 1 = A := rfl @[simp] theorem toSubgroup_neg_one : toSubgroup A B (-1) = B := rfl variable {A B} /-- To avoid duplicating code, we define `toSubgroup A B u` and `toSubgroupEquiv u` where `u : β„€Λ£` is `1` or `-1`. `toSubgroup A B u` is `A` when `u = 1` and `B` when `u = -1`, and `toSubgroupEquiv` is the group ismorphism from `toSubgroup A B u` to `toSubgroup A B (-u)`. It is defined to be `Ο†` when `u = 1` and `φ⁻¹` when `u = -1`. -/ def toSubgroupEquiv (u : β„€Λ£) : toSubgroup A B u ≃* toSubgroup A B (-u) := if hu : u = 1 then hu β–Έ Ο† else by convert Ο†.symm <;> cases Int.units_eq_one_or u <;> simp_all @[simp] theorem toSubgroupEquiv_one : toSubgroupEquiv Ο† 1 = Ο† := rfl @[simp] theorem toSubgroupEquiv_neg_one : toSubgroupEquiv Ο† (-1) = Ο†.symm := rfl @[simp] theorem toSubgroupEquiv_neg_apply (u : β„€Λ£) (a : toSubgroup A B u) : (toSubgroupEquiv Ο† (-u) (toSubgroupEquiv Ο† u a) : G) = a := by rcases Int.units_eq_one_or u with rfl | rfl Β· simp [toSubgroup] Β· simp only [toSubgroup_neg_one, toSubgroupEquiv_neg_one, SetLike.coe_eq_coe] exact Ο†.apply_symm_apply a namespace NormalWord variable (G A B) /-- To put word in the HNN Extension into a normal form, we must choose an element of each right coset of both `A` and `B`, such that the chosen element of the subgroup itself is `1`. -/ structure TransversalPair : Type _ where /-- The transversal of each subgroup -/ set : β„€Λ£ β†’ Set G /-- We have exactly one element of each coset of the subgroup -/ compl : βˆ€ u, IsComplement (toSubgroup A B u : Subgroup G) (set u) instance TransversalPair.nonempty : Nonempty (TransversalPair G A B) := by choose t ht using fun u ↦ (toSubgroup A B u).exists_isComplement_right 1 exact ⟨⟨t, fun i ↦ (ht i).1⟩⟩ /-- A reduced word is a `head`, which is an element of `G`, followed by the product list of pairs. There should also be no sequences of the form `t^u * g * t^-u`, where `g` is in `toSubgroup A B u` This is a less strict condition than required for `NormalWord`. -/ structure ReducedWord : Type _ where /-- Every `ReducedWord` is the product of an element of the group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : G /-- The list of pairs `(β„€Λ£ Γ— G)`, where each pair `(u, g)` represents the element `t^u * g` of `HNNExtension G A B Ο†` -/ toList : List (β„€Λ£ Γ— G) /-- There are no sequences of the form `t^u * g * t^-u` where `g ∈ toSubgroup A B u` -/ chain : toList.Chain' (fun a b => a.2 ∈ toSubgroup A B a.1 β†’ a.1 = b.1) /-- The empty reduced word. -/ @[simps] def ReducedWord.empty : ReducedWord G A B := { head := 1 toList := [] chain := List.chain'_nil } variable {G A B} /-- The product of a `ReducedWord` as an element of the `HNNExtension` -/ def ReducedWord.prod : ReducedWord G A B β†’ HNNExtension G A B Ο† := fun w => of w.head * (w.toList.map (fun x => t ^ (x.1 : β„€) * of x.2)).prod /-- Given a `TransversalPair`, we can make a normal form for words in the `HNNExtension G A B Ο†`. The normal form is a `head`, which is an element of `G`, followed by the product list of pairs, `t ^ u * g`, where `u` is `1` or `-1` and `g` is the chosen element of its right coset of `toSubgroup A B u`. There should also be no sequences of the form `t^u * g * t^-u` where `g ∈ toSubgroup A B u` -/ structure _root_.HNNExtension.NormalWord (d : TransversalPair G A B) : Type _ extends ReducedWord G A B where /-- Every element `g : G` in the list is the chosen element of its coset -/ mem_set : βˆ€ (u : β„€Λ£) (g : G), (u, g) ∈ toList β†’ g ∈ d.set u variable {d : TransversalPair G A B} @[ext] theorem ext {w w' : NormalWord d} (h1 : w.head = w'.head) (h2 : w.toList = w'.toList) : w = w' := by rcases w with ⟨⟨⟩, _⟩; cases w'; simp_all /-- The empty word -/ @[simps] def empty : NormalWord d := { head := 1 toList := [] mem_set := by simp chain := List.chain'_nil } /-- The `NormalWord` representing an element `g` of the group `G`, which is just the element `g` itself. -/ @[simps] def ofGroup (g : G) : NormalWord d := { head := g toList := [] mem_set := by simp chain := List.chain'_nil } instance : Inhabited (NormalWord d) := ⟨empty⟩ instance : MulAction G (NormalWord d) := { smul := fun g w => { w with head := g * w.head } one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem group_smul_def (g : G) (w : NormalWord d) : g β€’ w = { w with head := g * w.head } := rfl @[simp] theorem group_smul_head (g : G) (w : NormalWord d) : (g β€’ w).head = g * w.head := rfl @[simp] theorem group_smul_toList (g : G) (w : NormalWord d) : (g β€’ w).toList = w.toList := rfl instance : FaithfulSMul G (NormalWord d) := ⟨by simp [group_smul_def]⟩ /-- A constructor to append an element `g` of `G` and `u : β„€Λ£` to a word `w` with sufficient hypotheses that no normalization or cancellation need take place for the result to be in normal form -/ @[simps] def cons (g : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u') : NormalWord d := { head := g, toList := (u, w.head) :: w.toList, mem_set := by intro u' g' h' simp only [List.mem_cons, Prod.mk.injEq] at h' rcases h' with ⟨rfl, rfl⟩ | h' Β· exact h1 Β· exact w.mem_set _ _ h' chain := by refine List.chain'_cons'.2 ⟨?_, w.chain⟩ rintro ⟨u', g'⟩ hu' hw1 exact h2 _ (by simp_all) hw1 } /-- A recursor to induct on a `NormalWord`, by proving the property is preserved under `cons` -/ @[elab_as_elim] def consRecOn {motive : NormalWord d β†’ Sort*} (w : NormalWord d) (ofGroup : βˆ€ g, motive (ofGroup g)) (cons : βˆ€ (g : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u'), motive w β†’ motive (cons g u w h1 h2)) : motive w := by rcases w with ⟨⟨g, l, chain⟩, mem_set⟩ induction l generalizing g with | nil => exact ofGroup _ | cons a l ih => exact cons g a.1 { head := a.2 toList := l mem_set := fun _ _ h => mem_set _ _ (List.mem_cons_of_mem _ h), chain := (List.chain'_cons'.1 chain).2 } (mem_set a.1 a.2 List.mem_cons_self) (by simpa using (List.chain'_cons'.1 chain).1) (ih _ _ _) @[simp] theorem consRecOn_ofGroup {motive : NormalWord d β†’ Sort*} (g : G) (ofGroup : βˆ€ g, motive (ofGroup g)) (cons : βˆ€ (g : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u'), motive w β†’ motive (cons g u w h1 h2)) : consRecOn (.ofGroup g) ofGroup cons = ofGroup g := rfl @[simp] theorem consRecOn_cons {motive : NormalWord d β†’ Sort*} (g : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u') (ofGroup : βˆ€ g, motive (ofGroup g)) (cons : βˆ€ (g : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u'), motive w β†’ motive (cons g u w h1 h2)) : consRecOn (.cons g u w h1 h2) ofGroup cons = cons g u w h1 h2 (consRecOn w ofGroup cons) := rfl @[simp] theorem smul_cons (g₁ gβ‚‚ : G) (u : β„€Λ£) (w : NormalWord d) (h1 : w.head ∈ d.set u) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u') : g₁ β€’ cons gβ‚‚ u w h1 h2 = cons (g₁ * gβ‚‚) u w h1 h2 := rfl @[simp] theorem smul_ofGroup (g₁ gβ‚‚ : G) : g₁ β€’ (ofGroup gβ‚‚ : NormalWord d) = ofGroup (g₁ * gβ‚‚) := rfl variable (d) /-- The action of `t^u` on `ofGroup g`. The normal form will be `a * t^u * g'` where `a ∈ toSubgroup A B (-u)` -/ noncomputable def unitsSMulGroup (u : β„€Λ£) (g : G) : (toSubgroup A B (-u)) Γ— d.set u := let g' := (d.compl u).equiv g (toSubgroupEquiv Ο† u g'.1, g'.2) theorem unitsSMulGroup_snd (u : β„€Λ£) (g : G) : (unitsSMulGroup Ο† d u g).2 = ((d.compl u).equiv g).2 := by rcases Int.units_eq_one_or u with rfl | rfl <;> rfl variable {d} /-- `Cancels u w` is a predicate expressing whether `t^u` cancels with some occurrence of `t^-u` when we multiply `t^u` by `w`. -/ def Cancels (u : β„€Λ£) (w : NormalWord d) : Prop := (w.head ∈ (toSubgroup A B u : Subgroup G)) ∧ w.toList.head?.map Prod.fst = some (-u) /-- Multiplying `t^u` by `w` in the special case where cancellation happens -/ def unitsSMulWithCancel (u : β„€Λ£) (w : NormalWord d) : Cancels u w β†’ NormalWord d := consRecOn w (by simp [Cancels, ofGroup]; tauto) (fun g _ w _ _ _ can => (toSubgroupEquiv Ο† u ⟨g, can.1⟩ : G) β€’ w) /-- Multiplying `t^u` by a `NormalWord`, `w` and putting the result in normal form. -/ noncomputable def unitsSMul (u : β„€Λ£) (w : NormalWord d) : NormalWord d := letI := Classical.dec if h : Cancels u w then unitsSMulWithCancel Ο† u w h else let g' := unitsSMulGroup Ο† d u w.head cons g'.1 u ((g'.2 * w.head⁻¹ : G) β€’ w) (by simp) (by simp only [g', group_smul_toList, Option.mem_def, Option.map_eq_some_iff, Prod.exists, exists_and_right, exists_eq_right, group_smul_head, inv_mul_cancel_right, forall_exists_index, unitsSMulGroup] simp only [Cancels, Option.map_eq_some_iff, Prod.exists, exists_and_right, exists_eq_right, not_and, not_exists] at h intro u' x hx hmem have : w.head ∈ toSubgroup A B u := by have := (d.compl u).rightCosetEquivalence_equiv_snd w.head rw [RightCosetEquivalence, rightCoset_eq_iff, mul_mem_cancel_left hmem] at this simp_all have := h this x simp_all [Int.units_ne_iff_eq_neg])
/-- A condition for not cancelling whose hypothese are the same as those of the `cons` function. -/ theorem not_cancels_of_cons_hyp (u : β„€Λ£) (w : NormalWord d) (h2 : βˆ€ u' ∈ Option.map Prod.fst w.toList.head?, w.head ∈ toSubgroup A B u β†’ u = u') : Β¬ Cancels u w := by simp only [Cancels, Option.map_eq_some_iff, Prod.exists, exists_and_right, exists_eq_right, not_and, not_exists] intro hw x hx
Mathlib/GroupTheory/HNNExtension.lean
385
393
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Basic /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝβ‰₯0∞ β†’ ℝ` and `ENNReal.ofReal : ℝ β†’ ℝβ‰₯0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝβ‰₯0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝβ‰₯0∞) [Fact (1 ≀ p)] : p = ∞ ∨ 1 ≀ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝβ‰₯0` and `ℝβ‰₯0∞`. This is especially useful because `ℝβ‰₯0∞` is a complete lattice. -/ assert_not_exists Finset open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝβ‰₯0∞} {r p q : ℝβ‰₯0} theorem toReal_add (ha : a β‰  ∞) (hb : b β‰  ∞) : (a + b).toReal = a.toReal + b.toReal := by lift a to ℝβ‰₯0 using ha lift b to ℝβ‰₯0 using hb rfl theorem toReal_add_le : (a + b).toReal ≀ a.toReal + b.toReal := if ha : a = ∞ then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg] else le_of_eq (toReal_add ha hb) theorem ofReal_add {p q : ℝ} (hp : 0 ≀ p) (hq : 0 ≀ q) : ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj, Real.toNNReal_add hp hq] theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≀ ENNReal.ofReal p + ENNReal.ofReal q := coe_le_coe.2 Real.toNNReal_add_le @[simp] theorem toReal_le_toReal (ha : a β‰  ∞) (hb : b β‰  ∞) : a.toReal ≀ b.toReal ↔ a ≀ b := by lift a to ℝβ‰₯0 using ha lift b to ℝβ‰₯0 using hb norm_cast @[gcongr] theorem toReal_mono (hb : b β‰  ∞) (h : a ≀ b) : a.toReal ≀ b.toReal := (toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h theorem toReal_mono' (h : a ≀ b) (ht : b = ∞ β†’ a = ∞) : a.toReal ≀ b.toReal := by rcases eq_or_ne a ∞ with rfl | ha Β· exact toReal_nonneg Β· exact toReal_mono (mt ht ha) h @[simp] theorem toReal_lt_toReal (ha : a β‰  ∞) (hb : b β‰  ∞) : a.toReal < b.toReal ↔ a < b := by lift a to ℝβ‰₯0 using ha lift b to ℝβ‰₯0 using hb norm_cast @[gcongr] theorem toReal_strict_mono (hb : b β‰  ∞) (h : a < b) : a.toReal < b.toReal := (toReal_lt_toReal h.ne_top hb).2 h @[gcongr] theorem toNNReal_mono (hb : b β‰  ∞) (h : a ≀ b) : a.toNNReal ≀ b.toNNReal := toReal_mono hb h theorem le_toNNReal_of_coe_le (h : p ≀ a) (ha : a β‰  ∞) : p ≀ a.toNNReal := @toNNReal_coe p β–Έ toNNReal_mono ha h @[simp] theorem toNNReal_le_toNNReal (ha : a β‰  ∞) (hb : b β‰  ∞) : a.toNNReal ≀ b.toNNReal ↔ a ≀ b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩ @[gcongr] theorem toNNReal_strict_mono (hb : b β‰  ∞) (h : a < b) : a.toNNReal < b.toNNReal := by simpa [← ENNReal.coe_lt_coe, hb, h.ne_top] @[simp] theorem toNNReal_lt_toNNReal (ha : a β‰  ∞) (hb : b β‰  ∞) : a.toNNReal < b.toNNReal ↔ a < b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩ theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p := @toNNReal_coe p β–Έ toNNReal_strict_mono coe_ne_top h theorem toReal_max (hr : a β‰  ∞) (hp : b β‰  ∞) : ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by simp only [h, ENNReal.toReal_mono hr h, max_eq_left] theorem toReal_min {a b : ℝβ‰₯0∞} (hr : a β‰  ∞) (hp : b β‰  ∞) : ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left]) fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right] theorem toReal_sup {a b : ℝβ‰₯0∞} : a β‰  ∞ β†’ b β‰  ∞ β†’ (a βŠ” b).toReal = a.toReal βŠ” b.toReal := toReal_max theorem toReal_inf {a b : ℝβ‰₯0∞} : a β‰  ∞ β†’ b β‰  ∞ β†’ (a βŠ“ b).toReal = a.toReal βŠ“ b.toReal := toReal_min theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by induction a <;> simp theorem toNNReal_pos {a : ℝβ‰₯0∞} (haβ‚€ : a β‰  0) (ha_top : a β‰  ∞) : 0 < a.toNNReal := toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr haβ‚€, lt_top_iff_ne_top.mpr ha_top⟩ theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ := NNReal.coe_pos.trans toNNReal_pos_iff theorem toReal_pos {a : ℝβ‰₯0∞} (haβ‚€ : a β‰  0) (ha_top : a β‰  ∞) : 0 < a.toReal := toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr haβ‚€, lt_top_iff_ne_top.mpr ha_top⟩ @[gcongr, bound] theorem ofReal_le_ofReal {p q : ℝ} (h : p ≀ q) : ENNReal.ofReal p ≀ ENNReal.ofReal q := by simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h] theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝβ‰₯0∞} (h : a ≀ ENNReal.toReal b) : ENNReal.ofReal a ≀ b :=
(ofReal_le_ofReal h).trans ofReal_toReal_le @[simp] theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≀ q) : ENNReal.ofReal p ≀ ENNReal.ofReal q ↔ p ≀ q := by
Mathlib/Data/ENNReal/Real.lean
138
142
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.CharP.Two import Mathlib.Data.Nat.Cast.Field import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Data.Nat.Factorization.Induction import Mathlib.Data.Nat.Periodic /-! # Euler's totient function This file defines [Euler's totient function](https://en.wikipedia.org/wiki/Euler's_totient_function) `Nat.totient n` which counts the number of naturals less than `n` that are coprime with `n`. We prove the divisor sum formula, namely that `n` equals `Ο†` summed over the divisors of `n`. See `sum_totient`. We also prove two lemmas to help compute totients, namely `totient_mul` and `totient_prime_pow`. -/ assert_not_exists Algebra LinearMap open Finset namespace Nat /-- Euler's totient function. This counts the number of naturals strictly less than `n` which are coprime with `n`. -/ def totient (n : β„•) : β„• := #{a ∈ range n | n.Coprime a} @[inherit_doc] scoped notation "Ο†" => Nat.totient @[simp] theorem totient_zero : Ο† 0 = 0 := rfl @[simp] theorem totient_one : Ο† 1 = 1 := rfl theorem totient_eq_card_coprime (n : β„•) : Ο† n = #{a ∈ range n | n.Coprime a} := rfl /-- A characterisation of `Nat.totient` that avoids `Finset`. -/ theorem totient_eq_card_lt_and_coprime (n : β„•) : Ο† n = Nat.card { m | m < n ∧ n.Coprime m } := by let e : { m | m < n ∧ n.Coprime m } ≃ {x ∈ range n | n.Coprime x} := { toFun := fun m => ⟨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property⟩ invFun := fun m => ⟨m, by simpa only [Finset.mem_filter, Finset.mem_range] using m.property⟩ left_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta] right_inv := fun m => by simp only [Subtype.coe_mk, Subtype.coe_eta] } rw [totient_eq_card_coprime, card_congr e, card_eq_fintype_card, Fintype.card_coe] theorem totient_le (n : β„•) : Ο† n ≀ n := ((range n).card_filter_le _).trans_eq (card_range n) theorem totient_lt (n : β„•) (hn : 1 < n) : Ο† n < n := (card_lt_card (filter_ssubset.2 ⟨0, by simp [hn.ne', pos_of_gt hn]⟩)).trans_eq (card_range n) @[simp] theorem totient_eq_zero : βˆ€ {n : β„•}, Ο† n = 0 ↔ n = 0 | 0 => by decide | n + 1 => suffices βˆƒ x < n + 1, (n + 1).gcd x = 1 by simpa [totient, filter_eq_empty_iff] ⟨1 % (n + 1), mod_lt _ n.succ_pos, by rw [gcd_comm, ← gcd_rec, gcd_one_right]⟩ @[simp] theorem totient_pos {n : β„•} : 0 < Ο† n ↔ 0 < n := by simp [pos_iff_ne_zero] instance neZero_totient {n : β„•} [NeZero n] : NeZero n.totient := ⟨(totient_pos.mpr <| NeZero.pos n).ne'⟩ theorem filter_coprime_Ico_eq_totient (a n : β„•) : #{x ∈ Ico n (n + a) | a.Coprime x} = totient a := by rw [totient, filter_Ico_card_eq_of_periodic, count_eq_card_filter_range] exact periodic_coprime a theorem Ico_filter_coprime_le {a : β„•} (k n : β„•) (a_pos : 0 < a) : #{x ∈ Ico k (k + n) | a.Coprime x} ≀ totient a * (n / a + 1) := by conv_lhs => rw [← Nat.mod_add_div n a] induction' n / a with i ih Β· rw [← filter_coprime_Ico_eq_totient a k] simp only [add_zero, mul_one, mul_zero, le_of_lt (mod_lt n a_pos), zero_add] gcongr exact le_of_lt (mod_lt n a_pos) simp only [mul_succ] simp_rw [← add_assoc] at ih ⊒ calc #{x ∈ Ico k (k + n % a + a * i + a) | a.Coprime x} ≀ #{x ∈ Ico k (k + n % a + a * i) βˆͺ Ico (k + n % a + a * i) (k + n % a + a * i + a) | a.Coprime x} := by gcongr apply Ico_subset_Ico_union_Ico _ ≀ #{x ∈ Ico k (k + n % a + a * i) | a.Coprime x} + a.totient := by rw [filter_union, ← filter_coprime_Ico_eq_totient a (k + n % a + a * i)] apply card_union_le _ ≀ a.totient * i + a.totient + a.totient := add_le_add_right ih (totient a) open ZMod /-- Note this takes an explicit `Fintype ((ZMod n)Λ£)` argument to avoid trouble with instance diamonds. -/ @[simp] theorem _root_.ZMod.card_units_eq_totient (n : β„•) [NeZero n] [Fintype (ZMod n)Λ£] : Fintype.card (ZMod n)Λ£ = Ο† n := calc Fintype.card (ZMod n)Λ£ = Fintype.card { x : ZMod n // x.val.Coprime n } := Fintype.card_congr ZMod.unitsEquivCoprime _ = Ο† n := by obtain ⟨m, rfl⟩ : βˆƒ m, n = m + 1 := exists_eq_succ_of_ne_zero NeZero.out simp only [totient, Finset.card_eq_sum_ones, Fintype.card_subtype, Finset.sum_filter, ← Fin.sum_univ_eq_sum_range, @Nat.coprime_comm (m + 1)] rfl theorem totient_even {n : β„•} (hn : 2 < n) : Even n.totient := by haveI : Fact (1 < n) := ⟨one_lt_two.trans hn⟩ haveI : NeZero n := NeZero.of_gt hn suffices 2 = orderOf (-1 : (ZMod n)Λ£) by rw [← ZMod.card_units_eq_totient, even_iff_two_dvd, this] exact orderOf_dvd_card rw [← orderOf_units, Units.coe_neg_one, orderOf_neg_one, ringChar.eq (ZMod n) n, if_neg hn.ne'] theorem totient_mul {m n : β„•} (h : m.Coprime n) : Ο† (m * n) = Ο† m * Ο† n := if hmn0 : m * n = 0 then by rcases Nat.mul_eq_zero.1 hmn0 with h | h <;> simp only [totient_zero, mul_zero, zero_mul, h] else by haveI : NeZero (m * n) := ⟨hmn0⟩ haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩ haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩ simp only [← ZMod.card_units_eq_totient] rw [Fintype.card_congr (Units.mapEquiv (ZMod.chineseRemainder h).toMulEquiv).toEquiv, Fintype.card_congr (@MulEquiv.prodUnits (ZMod m) (ZMod n) _ _).toEquiv, Fintype.card_prod] /-- For `d ∣ n`, the totient of `n/d` equals the number of values `k < n` such that `gcd n k = d` -/ theorem totient_div_of_dvd {n d : β„•} (hnd : d ∣ n) : Ο† (n / d) = #{k ∈ range n | n.gcd k = d} := by rcases d.eq_zero_or_pos with (rfl | hd0); Β· simp [eq_zero_of_zero_dvd hnd] rcases hnd with ⟨x, rfl⟩ rw [Nat.mul_div_cancel_left x hd0] apply Finset.card_bij fun k _ => d * k Β· simp only [mem_filter, mem_range, and_imp, Coprime] refine fun a ha1 ha2 => ⟨(mul_lt_mul_left hd0).2 ha1, ?_⟩ rw [gcd_mul_left, ha2, mul_one] Β· simp [hd0.ne'] Β· simp only [mem_filter, mem_range, exists_prop, and_imp] refine fun b hb1 hb2 => ?_ have : d ∣ b := by rw [← hb2] apply gcd_dvd_right rcases this with ⟨q, rfl⟩ refine ⟨q, ⟨⟨(mul_lt_mul_left hd0).1 hb1, ?_⟩, rfl⟩⟩ rwa [gcd_mul_left, mul_right_eq_self_iff hd0] at hb2 theorem sum_totient (n : β„•) : n.divisors.sum Ο† = n := by rcases n.eq_zero_or_pos with (rfl | hn) Β· simp rw [← sum_div_divisors n Ο†] have : n = βˆ‘ d ∈ n.divisors, #{k ∈ range n | n.gcd k = d} := by nth_rw 1 [← card_range n] refine card_eq_sum_card_fiberwise fun x _ => mem_divisors.2 ⟨?_, hn.ne'⟩ apply gcd_dvd_left nth_rw 3 [this] exact sum_congr rfl fun x hx => totient_div_of_dvd (dvd_of_mem_divisors hx) theorem sum_totient' (n : β„•) : βˆ‘ m ∈ range n.succ with m ∣ n, Ο† m = n := by convert sum_totient _ using 1 simp only [Nat.divisors, sum_filter, range_eq_Ico] rw [sum_eq_sum_Ico_succ_bot] <;> simp /-- When `p` is prime, then the totient of `p ^ (n + 1)` is `p ^ n * (p - 1)` -/ theorem totient_prime_pow_succ {p : β„•} (hp : p.Prime) (n : β„•) : Ο† (p ^ (n + 1)) = p ^ n * (p - 1) := calc Ο† (p ^ (n + 1)) = #{a ∈ range (p ^ (n + 1)) | (p ^ (n + 1)).Coprime a} := totient_eq_card_coprime _ _ = #(range (p ^ (n + 1)) \ (range (p ^ n)).image (Β· * p)) := congr_arg card (by rw [sdiff_eq_filter] apply filter_congr simp only [mem_range, mem_filter, coprime_pow_left_iff n.succ_pos, mem_image, not_exists, hp.coprime_iff_not_dvd] intro a ha constructor Β· intro hap b h; rcases h with ⟨_, rfl⟩ exact hap (dvd_mul_left _ _) Β· rintro h ⟨b, rfl⟩ rw [pow_succ'] at ha exact h b ⟨lt_of_mul_lt_mul_left ha (zero_le _), mul_comm _ _⟩) _ = _ := by have h1 : Function.Injective (Β· * p) := mul_left_injectiveβ‚€ hp.ne_zero have h2 : (range (p ^ n)).image (Β· * p) βŠ† range (p ^ (n + 1)) := fun a => by simp only [mem_image, mem_range, exists_imp] rintro b ⟨h, rfl⟩ rw [Nat.pow_succ] exact (mul_lt_mul_right hp.pos).2 h rw [card_sdiff h2, Finset.card_image_of_injective _ h1, card_range, card_range, ← one_mul (p ^ n), pow_succ', ← tsub_mul, one_mul, mul_comm] /-- When `p` is prime, then the totient of `p ^ n` is `p ^ (n - 1) * (p - 1)` -/ theorem totient_prime_pow {p : β„•} (hp : p.Prime) {n : β„•} (hn : 0 < n) : Ο† (p ^ n) = p ^ (n - 1) * (p - 1) := by rcases exists_eq_succ_of_ne_zero (pos_iff_ne_zero.1 hn) with ⟨m, rfl⟩ exact totient_prime_pow_succ hp _ theorem totient_prime {p : β„•} (hp : p.Prime) : Ο† p = p - 1 := by rw [← pow_one p, totient_prime_pow hp] <;> simp theorem totient_eq_iff_prime {p : β„•} (hp : 0 < p) : p.totient = p - 1 ↔ p.Prime := by refine ⟨fun h => ?_, totient_prime⟩ replace hp : 1 < p := by apply lt_of_le_of_ne Β· rwa [succ_le_iff] Β· rintro rfl rw [totient_one, tsub_self] at h exact one_ne_zero h rw [totient_eq_card_coprime, range_eq_Ico, ← Ico_insert_succ_left hp.le, Finset.filter_insert, if_neg (not_coprime_of_dvd_of_dvd hp (dvd_refl p) (dvd_zero p)), ← Nat.card_Ico 1 p] at h refine p.prime_of_coprime hp fun n hn hnz => Finset.filter_card_eq h n <| Finset.mem_Ico.mpr ⟨?_, hn⟩ rwa [succ_le_iff, pos_iff_ne_zero] theorem card_units_zmod_lt_sub_one {p : β„•} (hp : 1 < p) [Fintype (ZMod p)Λ£] : Fintype.card (ZMod p)Λ£ ≀ p - 1 := by haveI : NeZero p := ⟨(pos_of_gt hp).ne'⟩ rw [ZMod.card_units_eq_totient p] exact Nat.le_sub_one_of_lt (Nat.totient_lt p hp) theorem prime_iff_card_units (p : β„•) [Fintype (ZMod p)Λ£] : p.Prime ↔ Fintype.card (ZMod p)Λ£ = p - 1 := by rcases eq_zero_or_neZero p with hp | hp Β· subst hp simp only [ZMod, not_prime_zero, false_iff, zero_tsub] -- the subst created a non-defeq but subsingleton instance diamond; resolve it suffices Fintype.card β„€Λ£ β‰  0 by convert this simp rw [ZMod.card_units_eq_totient, Nat.totient_eq_iff_prime <| NeZero.pos p] @[simp] theorem totient_two : Ο† 2 = 1 := (totient_prime prime_two).trans rfl theorem totient_eq_one_iff : βˆ€ {n : β„•}, n.totient = 1 ↔ n = 1 ∨ n = 2
| 0 => by simp | 1 => by simp | 2 => by simp | n + 3 => by have : 3 ≀ n + 3 := le_add_self
Mathlib/Data/Nat/Totient.lean
242
246
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Gabin Kolly -/ import Mathlib.Data.Finite.Sum import Mathlib.Data.Fintype.Order import Mathlib.ModelTheory.FinitelyGenerated import Mathlib.ModelTheory.Quotients import Mathlib.Order.DirectedInverseSystem /-! # Direct Limits of First-Order Structures This file constructs the direct limit of a directed system of first-order embeddings. ## Main Definitions - `FirstOrder.Language.DirectLimit G f` is the direct limit of the directed system `f` of first-order embeddings between the structures indexed by `G`. - `FirstOrder.Language.DirectLimit.lift` is the universal property of the direct limit: maps from the components to another module that respect the directed system structure give rise to a unique map out of the direct limit. - `FirstOrder.Language.DirectLimit.equiv_lift` is the equivalence between limits of isomorphic direct systems. -/ universe v w w' u₁ uβ‚‚ open FirstOrder namespace FirstOrder namespace Language open Structure Set variable {L : Language} {ΞΉ : Type v} [Preorder ΞΉ] variable {G : ΞΉ β†’ Type w} [βˆ€ i, L.Structure (G i)] variable (f : βˆ€ i j, i ≀ j β†’ G i β†ͺ[L] G j) namespace DirectedSystem alias map_self := DirectedSystem.map_self' alias map_map := DirectedSystem.map_map' variable {G' : β„• β†’ Type w} [βˆ€ i, L.Structure (G' i)] (f' : βˆ€ n : β„•, G' n β†ͺ[L] G' (n + 1)) /-- Given a chain of embeddings of structures indexed by `β„•`, defines a `DirectedSystem` by composing them. -/ def natLERec (m n : β„•) (h : m ≀ n) : G' m β†ͺ[L] G' n := Nat.leRecOn h (@fun k g => (f' k).comp g) (Embedding.refl L _) @[simp] theorem coe_natLERec (m n : β„•) (h : m ≀ n) : (natLERec f' m n h : G' m β†’ G' n) = Nat.leRecOn h (@fun k => f' k) := by obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le h ext x induction' k with k ih Β· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [natLERec, Nat.leRecOn_self, Embedding.refl_apply, Nat.leRecOn_self] Β· -- This used to be `rw`, but we need `erw` after https://github.com/leanprover/lean4/pull/2644 erw [Nat.leRecOn_succ le_self_add, natLERec, Nat.leRecOn_succ le_self_add, ← natLERec, Embedding.comp_apply, ih] instance natLERec.directedSystem : DirectedSystem G' fun i j h => natLERec f' i j h := ⟨fun _ _ => congr (congr rfl (Nat.leRecOn_self _)) rfl, fun _ _ _ hij hjk => by simp [Nat.leRecOn_trans hij hjk]⟩ end DirectedSystem set_option linter.unusedVariables false in /-- Alias for `Ξ£ i, G i`. Instead of `Ξ£ i, G i`, we use the alias `Language.Structure.Sigma` which depends on `f`. This way, Lean can infer what `L` and `f` are in the `Setoid` instance. Otherwise we have a "cannot find synthesization order" error. See also the discussion at https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/local.20instance.20cannot.20find.20synthesization.20order.20in.20porting -/ @[nolint unusedArguments] protected abbrev Structure.Sigma (f : βˆ€ i j, i ≀ j β†’ G i β†ͺ[L] G j) := Ξ£ i, G i local notation "Ξ£Λ£" => Structure.Sigma /-- Constructor for `FirstOrder.Language.Structure.Sigma` alias. -/ abbrev Structure.Sigma.mk (i : ΞΉ) (x : G i) : Ξ£Λ£ f := ⟨i, x⟩ namespace DirectLimit /-- Raises a family of elements in the `Ξ£`-type to the same level along the embeddings. -/ def unify {Ξ± : Type*} (x : Ξ± β†’ Ξ£Λ£ f) (i : ΞΉ) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) (a : Ξ±) : G i := f (x a).1 i (h (mem_range_self a)) (x a).2 variable [DirectedSystem G fun i j h => f i j h] @[simp] theorem unify_sigma_mk_self {Ξ± : Type*} {i : ΞΉ} {x : Ξ± β†’ G i} : (unify f (fun a => .mk f i (x a)) i fun _ ⟨_, hj⟩ => _root_.trans (le_of_eq hj.symm) (refl _)) = x := by ext a rw [unify] apply DirectedSystem.map_self theorem comp_unify {Ξ± : Type*} {x : Ξ± β†’ Ξ£Λ£ f} {i j : ΞΉ} (ij : i ≀ j) (h : i ∈ upperBounds (range (Sigma.fst ∘ x))) : f i j ij ∘ unify f x i h = unify f x j fun k hk => _root_.trans (mem_upperBounds.1 h k hk) ij := by ext a simp [unify, DirectedSystem.map_map] end DirectLimit variable (G) namespace DirectLimit /-- The directed limit glues together the structures along the embeddings. -/ def setoid [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· ≀ Β·)] : Setoid (Ξ£Λ£ f) where r := fun ⟨i, x⟩ ⟨j, y⟩ => βˆƒ (k : ΞΉ) (ik : i ≀ k) (jk : j ≀ k), f i k ik x = f j k jk y iseqv := ⟨fun ⟨i, _⟩ => ⟨i, refl i, refl i, rfl⟩, @fun ⟨_, _⟩ ⟨_, _⟩ ⟨k, ik, jk, h⟩ => ⟨k, jk, ik, h.symm⟩, @fun ⟨i, x⟩ ⟨j, y⟩ ⟨k, z⟩ ⟨ij, hiij, hjij, hij⟩ ⟨jk, hjjk, hkjk, hjk⟩ => by obtain ⟨ijk, hijijk, hjkijk⟩ := directed_of (Β· ≀ Β·) ij jk refine ⟨ijk, le_trans hiij hijijk, le_trans hkjk hjkijk, ?_⟩ rw [← DirectedSystem.map_map, hij, DirectedSystem.map_map] Β· symm rw [← DirectedSystem.map_map, ← hjk, DirectedSystem.map_map] assumption assumption⟩ /-- The structure on the `Ξ£`-type which becomes the structure on the direct limit after quotienting. -/ noncomputable def sigmaStructure [IsDirected ΞΉ (Β· ≀ Β·)] [Nonempty ΞΉ] : L.Structure (Ξ£Λ£ f) where funMap F x := ⟨_, funMap F (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1)))⟩ RelMap R x := RelMap R (unify f x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) (Classical.choose_spec (Finite.bddAbove_range fun a => (x a).1))) end DirectLimit /-- The direct limit of a directed system is the structures glued together along the embeddings. -/ def DirectLimit [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· ≀ Β·)] := Quotient (DirectLimit.setoid G f) attribute [local instance] DirectLimit.setoid DirectLimit.sigmaStructure instance [DirectedSystem G fun i j h => f i j h] [IsDirected ΞΉ (Β· ≀ Β·)] [Inhabited ΞΉ] [Inhabited (G default)] : Inhabited (DirectLimit G f) := ⟨⟦⟨default, default⟩⟧⟩ namespace DirectLimit variable [IsDirected ΞΉ (Β· ≀ Β·)] [DirectedSystem G fun i j h => f i j h] theorem equiv_iff {x y : Ξ£Λ£ f} {i : ΞΉ} (hx : x.1 ≀ i) (hy : y.1 ≀ i) : x β‰ˆ y ↔ (f x.1 i hx) x.2 = (f y.1 i hy) y.2 := by cases x cases y refine ⟨fun xy => ?_, fun xy => ⟨i, hx, hy, xy⟩⟩ obtain ⟨j, _, _, h⟩ := xy obtain ⟨k, ik, jk⟩ := directed_of (Β· ≀ Β·) i j have h := congr_arg (f j k jk) h apply (f i k ik).injective rw [DirectedSystem.map_map, DirectedSystem.map_map] at * exact h theorem funMap_unify_equiv {n : β„•} (F : L.Functions n) (x : Fin n β†’ Ξ£Λ£ f) (i j : ΞΉ) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : Structure.Sigma.mk f i (funMap F (unify f x i hi)) β‰ˆ .mk f j (funMap F (unify f x j hj)) := by obtain ⟨k, ik, jk⟩ := directed_of (Β· ≀ Β·) i j refine ⟨k, ik, jk, ?_⟩ rw [(f i k ik).map_fun, (f j k jk).map_fun, comp_unify, comp_unify] theorem relMap_unify_equiv {n : β„•} (R : L.Relations n) (x : Fin n β†’ Ξ£Λ£ f) (i j : ΞΉ) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hj : j ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R (unify f x i hi) = RelMap R (unify f x j hj) := by obtain ⟨k, ik, jk⟩ := directed_of (Β· ≀ Β·) i j rw [← (f i k ik).map_rel, comp_unify, ← (f j k jk).map_rel, comp_unify] variable [Nonempty ΞΉ] theorem exists_unify_eq {Ξ± : Type*} [Finite Ξ±] {x y : Ξ± β†’ Ξ£Λ£ f} (xy : x β‰ˆ y) : βˆƒ (i : ΞΉ) (hx : i ∈ upperBounds (range (Sigma.fst ∘ x))) (hy : i ∈ upperBounds (range (Sigma.fst ∘ y))), unify f x i hx = unify f y i hy := by obtain ⟨i, hi⟩ := Finite.bddAbove_range (Sum.elim (fun a => (x a).1) fun a => (y a).1) rw [Sum.elim_range, upperBounds_union] at hi simp_rw [← Function.comp_apply (f := Sigma.fst)] at hi exact ⟨i, hi.1, hi.2, funext fun a => (equiv_iff G f _ _).1 (xy a)⟩ theorem funMap_equiv_unify {n : β„•} (F : L.Functions n) (x : Fin n β†’ Ξ£Λ£ f) (i : ΞΉ) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : funMap F x β‰ˆ .mk f _ (funMap F (unify f x i hi)) := funMap_unify_equiv G f F x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi theorem relMap_equiv_unify {n : β„•} (R : L.Relations n) (x : Fin n β†’ Ξ£Λ£ f) (i : ΞΉ) (hi : i ∈ upperBounds (range (Sigma.fst ∘ x))) : RelMap R x = RelMap R (unify f x i hi) := relMap_unify_equiv G f R x (Classical.choose (Finite.bddAbove_range fun a => (x a).1)) i _ hi /-- The direct limit `setoid` respects the structure `sigmaStructure`, so quotienting by it gives rise to a valid structure. -/ noncomputable instance prestructure : L.Prestructure (DirectLimit.setoid G f) where toStructure := sigmaStructure G f fun_equiv {n} {F} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine Setoid.trans (funMap_equiv_unify G f F x i hx) (Setoid.trans ?_ (Setoid.symm (funMap_equiv_unify G f F y i hy))) rw [h] rel_equiv {n} {R} x y xy := by obtain ⟨i, hx, hy, h⟩ := exists_unify_eq G f xy refine _root_.trans (relMap_equiv_unify G f R x i hx) (_root_.trans ?_ (symm (relMap_equiv_unify G f R y i hy))) rw [h] /-- The `L.Structure` on a direct limit of `L.Structure`s. -/ noncomputable instance instStructureDirectLimit : L.Structure (DirectLimit G f) := Language.quotientStructure @[simp] theorem funMap_quotient_mk'_sigma_mk' {n : β„•} {F : L.Functions n} {i : ΞΉ} {x : Fin n β†’ G i} : funMap F (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = ⟦.mk f i (funMap F x)⟧ := by simp only [funMap_quotient_mk', Quotient.eq] obtain ⟨k, ik, jk⟩ := directed_of (Β· ≀ Β·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) refine ⟨k, jk, ik, ?_⟩ simp only [Embedding.map_fun, comp_unify] rfl @[simp] theorem relMap_quotient_mk'_sigma_mk' {n : β„•} {R : L.Relations n} {i : ΞΉ} {x : Fin n β†’ G i} : RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) = RelMap R x := by rw [relMap_quotient_mk'] obtain ⟨k, _, _⟩ := directed_of (Β· ≀ Β·) i (Classical.choose (Finite.bddAbove_range fun _ : Fin n => i)) rw [relMap_equiv_unify G f R (fun a => .mk f i (x a)) i] rw [unify_sigma_mk_self] theorem exists_quotient_mk'_sigma_mk'_eq {Ξ± : Type*} [Finite Ξ±] (x : Ξ± β†’ DirectLimit G f) : βˆƒ (i : ΞΉ) (y : Ξ± β†’ G i), x = fun a => ⟦.mk f i (y a)⟧ := by obtain ⟨i, hi⟩ := Finite.bddAbove_range fun a => (x a).out.1 refine ⟨i, unify f (Quotient.out ∘ x) i hi, ?_⟩ ext a rw [Quotient.eq_mk_iff_out, unify] generalize_proofs r change _ β‰ˆ Structure.Sigma.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) have : (.mk f i (f (Quotient.out (x a)).fst i r (Quotient.out (x a)).snd) : Ξ£Λ£ f).fst ≀ i := le_rfl rw [equiv_iff G f (i := i) (hi _) this] Β· simp only [DirectedSystem.map_self] exact ⟨a, rfl⟩ variable (L ΞΉ) /-- The canonical map from a component to the direct limit. -/ def of (i : ΞΉ) : G i β†ͺ[L] DirectLimit G f where toFun := fun a => ⟦.mk f i a⟧ inj' x y h := by rw [Quotient.eq] at h obtain ⟨j, h1, _, h3⟩ := h exact (f i j h1).injective h3 map_fun' F x := by rw [← funMap_quotient_mk'_sigma_mk'] rfl map_rel' := by intro n R x change RelMap R (fun a => (⟦.mk f i (x a)⟧ : DirectLimit G f)) ↔ _ simp only [relMap_quotient_mk'_sigma_mk']
variable {L ΞΉ G f} @[simp] theorem of_apply {i : ΞΉ} {x : G i} : of L ΞΉ G f i x = ⟦.mk f i x⟧ := rfl -- This is not a simp-lemma because it is not in simp-normal form, -- but the simp-normal version of this theorem would not be useful. theorem of_f {i j : ΞΉ} {hij : i ≀ j} {x : G i} : of L ΞΉ G f j (f i j hij x) = of L ΞΉ G f i x := by rw [of_apply, of_apply, Quotient.eq] refine Setoid.symm ⟨j, hij, refl j, ?_⟩ simp only [DirectedSystem.map_self]
Mathlib/ModelTheory/DirectLimit.lean
281
293
/- Copyright (c) 2022 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Data.Finset.NAry import Mathlib.Data.Finset.Slice import Mathlib.Data.Set.Sups /-! # Set family operations This file defines a few binary operations on `Finset Ξ±` for use in set family combinatorics. ## Main declarations * `Finset.sups s t`: Finset of elements of the form `a βŠ” b` where `a ∈ s`, `b ∈ t`. * `Finset.infs s t`: Finset of elements of the form `a βŠ“ b` where `a ∈ s`, `b ∈ t`. * `Finset.disjSups s t`: Finset of elements of the form `a βŠ” b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. * `Finset.diffs`: Finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. * `Finset.compls`: Finset of elements of the form `aᢜ` where `a ∈ s`. ## Notation We define the following notation in locale `FinsetFamily`: * `s ⊻ t` for `Finset.sups` * `s ⊼ t` for `Finset.infs` * `s β—‹ t` for `Finset.disjSups s t` * `s \\ t` for `Finset.diffs` * `sᢜ˒` for `Finset.compls` ## References [B. BollobΓ‘s, *Combinatorics*][bollobas1986] -/ open Function open SetFamily variable {F Ξ± Ξ² : Type*} namespace Finset section Sups variable [DecidableEq Ξ±] [DecidableEq Ξ²] variable [SemilatticeSup Ξ±] [SemilatticeSup Ξ²] [FunLike F Ξ± Ξ²] [SupHomClass F Ξ± Ξ²] variable (s s₁ sβ‚‚ t t₁ tβ‚‚ u v : Finset Ξ±) /-- `s ⊻ t` is the finset of elements of the form `a βŠ” b` where `a ∈ s`, `b ∈ t`. -/ protected def hasSups : HasSups (Finset Ξ±) := ⟨imageβ‚‚ (Β· βŠ” Β·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasSups open FinsetFamily variable {s t} {a b c : Ξ±} @[simp] theorem mem_sups : c ∈ s ⊻ t ↔ βˆƒ a ∈ s, βˆƒ b ∈ t, a βŠ” b = c := by simp [(Β· ⊻ Β·)] variable (s t) @[simp, norm_cast] theorem coe_sups : (↑(s ⊻ t) : Set Ξ±) = ↑s ⊻ ↑t := coe_imageβ‚‚ _ _ _ theorem card_sups_le : #(s ⊻ t) ≀ #s * #t := card_imageβ‚‚_le _ _ _ theorem card_sups_iff : #(s ⊻ t) = #s * #t ↔ (s Γ—Λ’ t : Set (Ξ± Γ— Ξ±)).InjOn fun x => x.1 βŠ” x.2 := card_imageβ‚‚_iff variable {s s₁ sβ‚‚ t t₁ tβ‚‚ u} theorem sup_mem_sups : a ∈ s β†’ b ∈ t β†’ a βŠ” b ∈ s ⊻ t := mem_imageβ‚‚_of_mem theorem sups_subset : s₁ βŠ† sβ‚‚ β†’ t₁ βŠ† tβ‚‚ β†’ s₁ ⊻ t₁ βŠ† sβ‚‚ ⊻ tβ‚‚ := imageβ‚‚_subset theorem sups_subset_left : t₁ βŠ† tβ‚‚ β†’ s ⊻ t₁ βŠ† s ⊻ tβ‚‚ := imageβ‚‚_subset_left theorem sups_subset_right : s₁ βŠ† sβ‚‚ β†’ s₁ ⊻ t βŠ† sβ‚‚ ⊻ t := imageβ‚‚_subset_right lemma image_subset_sups_left : b ∈ t β†’ s.image (Β· βŠ” b) βŠ† s ⊻ t := image_subset_imageβ‚‚_left lemma image_subset_sups_right : a ∈ s β†’ t.image (a βŠ” Β·) βŠ† s ⊻ t := image_subset_imageβ‚‚_right theorem forall_sups_iff {p : Ξ± β†’ Prop} : (βˆ€ c ∈ s ⊻ t, p c) ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, p (a βŠ” b) := forall_mem_imageβ‚‚ @[simp] theorem sups_subset_iff : s ⊻ t βŠ† u ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, a βŠ” b ∈ u := imageβ‚‚_subset_iff @[simp] theorem sups_nonempty : (s ⊻ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := imageβ‚‚_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.sups : s.Nonempty β†’ t.Nonempty β†’ (s ⊻ t).Nonempty := Nonempty.imageβ‚‚ theorem Nonempty.of_sups_left : (s ⊻ t).Nonempty β†’ s.Nonempty := Nonempty.of_imageβ‚‚_left theorem Nonempty.of_sups_right : (s ⊻ t).Nonempty β†’ t.Nonempty := Nonempty.of_imageβ‚‚_right @[simp] theorem empty_sups : βˆ… ⊻ t = βˆ… := imageβ‚‚_empty_left @[simp] theorem sups_empty : s ⊻ βˆ… = βˆ… := imageβ‚‚_empty_right @[simp] theorem sups_eq_empty : s ⊻ t = βˆ… ↔ s = βˆ… ∨ t = βˆ… := imageβ‚‚_eq_empty_iff @[simp] lemma singleton_sups : {a} ⊻ t = t.image (a βŠ” Β·) := imageβ‚‚_singleton_left @[simp] lemma sups_singleton : s ⊻ {b} = s.image (Β· βŠ” b) := imageβ‚‚_singleton_right theorem singleton_sups_singleton : ({a} ⊻ {b} : Finset Ξ±) = {a βŠ” b} := imageβ‚‚_singleton theorem sups_union_left : (s₁ βˆͺ sβ‚‚) ⊻ t = s₁ ⊻ t βˆͺ sβ‚‚ ⊻ t := imageβ‚‚_union_left theorem sups_union_right : s ⊻ (t₁ βˆͺ tβ‚‚) = s ⊻ t₁ βˆͺ s ⊻ tβ‚‚ := imageβ‚‚_union_right theorem sups_inter_subset_left : (s₁ ∩ sβ‚‚) ⊻ t βŠ† s₁ ⊻ t ∩ sβ‚‚ ⊻ t := imageβ‚‚_inter_subset_left theorem sups_inter_subset_right : s ⊻ (t₁ ∩ tβ‚‚) βŠ† s ⊻ t₁ ∩ s ⊻ tβ‚‚ := imageβ‚‚_inter_subset_right theorem subset_sups {s t : Set Ξ±} : ↑u βŠ† s ⊻ t β†’ βˆƒ s' t' : Finset Ξ±, ↑s' βŠ† s ∧ ↑t' βŠ† t ∧ u βŠ† s' ⊻ t' := subset_set_imageβ‚‚ lemma image_sups (f : F) (s t : Finset Ξ±) : image f (s ⊻ t) = image f s ⊻ image f t := image_imageβ‚‚_distrib <| map_sup f lemma map_sups (f : F) (hf) (s t : Finset Ξ±) : map ⟨f, hf⟩ (s ⊻ t) = map ⟨f, hf⟩ s ⊻ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_sups f s t lemma subset_sups_self : s βŠ† s ⊻ s := fun _a ha ↦ mem_sups.2 ⟨_, ha, _, ha, sup_idem _⟩ lemma sups_subset_self : s ⊻ s βŠ† s ↔ SupClosed (s : Set Ξ±) := sups_subset_iff @[simp] lemma sups_eq_self : s ⊻ s = s ↔ SupClosed (s : Set Ξ±) := by simp [← coe_inj] @[simp] lemma univ_sups_univ [Fintype Ξ±] : (univ : Finset Ξ±) ⊻ univ = univ := by simp lemma filter_sups_le [DecidableLE Ξ±] (s t : Finset Ξ±) (a : Ξ±) : {b ∈ s ⊻ t | b ≀ a} = {b ∈ s | b ≀ a} ⊻ {b ∈ t | b ≀ a} := by simp only [← coe_inj, coe_filter, coe_sups, ← mem_coe, Set.sep_sups_le] variable (s t u) lemma biUnion_image_sup_left : s.biUnion (fun a ↦ t.image (a βŠ” Β·)) = s ⊻ t := biUnion_image_left lemma biUnion_image_sup_right : t.biUnion (fun b ↦ s.image (Β· βŠ” b)) = s ⊻ t := biUnion_image_right theorem image_sup_product (s t : Finset Ξ±) : (s Γ—Λ’ t).image (uncurry (Β· βŠ” Β·)) = s ⊻ t := image_uncurry_product _ _ _ theorem sups_assoc : s ⊻ t ⊻ u = s ⊻ (t ⊻ u) := imageβ‚‚_assoc sup_assoc theorem sups_comm : s ⊻ t = t ⊻ s := imageβ‚‚_comm sup_comm theorem sups_left_comm : s ⊻ (t ⊻ u) = t ⊻ (s ⊻ u) := imageβ‚‚_left_comm sup_left_comm theorem sups_right_comm : s ⊻ t ⊻ u = s ⊻ u ⊻ t := imageβ‚‚_right_comm sup_right_comm theorem sups_sups_sups_comm : s ⊻ t ⊻ (u ⊻ v) = s ⊻ u ⊻ (t ⊻ v) := imageβ‚‚_imageβ‚‚_imageβ‚‚_comm sup_sup_sup_comm end Sups section Infs variable [DecidableEq Ξ±] [DecidableEq Ξ²] variable [SemilatticeInf Ξ±] [SemilatticeInf Ξ²] [FunLike F Ξ± Ξ²] [InfHomClass F Ξ± Ξ²] variable (s s₁ sβ‚‚ t t₁ tβ‚‚ u v : Finset Ξ±) /-- `s ⊼ t` is the finset of elements of the form `a βŠ“ b` where `a ∈ s`, `b ∈ t`. -/ protected def hasInfs : HasInfs (Finset Ξ±) := ⟨imageβ‚‚ (Β· βŠ“ Β·)⟩ scoped[FinsetFamily] attribute [instance] Finset.hasInfs open FinsetFamily variable {s t} {a b c : Ξ±} @[simp] theorem mem_infs : c ∈ s ⊼ t ↔ βˆƒ a ∈ s, βˆƒ b ∈ t, a βŠ“ b = c := by simp [(Β· ⊼ Β·)] variable (s t) @[simp, norm_cast] theorem coe_infs : (↑(s ⊼ t) : Set Ξ±) = ↑s ⊼ ↑t := coe_imageβ‚‚ _ _ _ theorem card_infs_le : #(s ⊼ t) ≀ #s * #t := card_imageβ‚‚_le _ _ _ theorem card_infs_iff : #(s ⊼ t) = #s * #t ↔ (s Γ—Λ’ t : Set (Ξ± Γ— Ξ±)).InjOn fun x => x.1 βŠ“ x.2 := card_imageβ‚‚_iff variable {s s₁ sβ‚‚ t t₁ tβ‚‚ u} theorem inf_mem_infs : a ∈ s β†’ b ∈ t β†’ a βŠ“ b ∈ s ⊼ t := mem_imageβ‚‚_of_mem theorem infs_subset : s₁ βŠ† sβ‚‚ β†’ t₁ βŠ† tβ‚‚ β†’ s₁ ⊼ t₁ βŠ† sβ‚‚ ⊼ tβ‚‚ := imageβ‚‚_subset theorem infs_subset_left : t₁ βŠ† tβ‚‚ β†’ s ⊼ t₁ βŠ† s ⊼ tβ‚‚ := imageβ‚‚_subset_left theorem infs_subset_right : s₁ βŠ† sβ‚‚ β†’ s₁ ⊼ t βŠ† sβ‚‚ ⊼ t := imageβ‚‚_subset_right lemma image_subset_infs_left : b ∈ t β†’ s.image (Β· βŠ“ b) βŠ† s ⊼ t := image_subset_imageβ‚‚_left lemma image_subset_infs_right : a ∈ s β†’ t.image (a βŠ“ Β·) βŠ† s ⊼ t := image_subset_imageβ‚‚_right theorem forall_infs_iff {p : Ξ± β†’ Prop} : (βˆ€ c ∈ s ⊼ t, p c) ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, p (a βŠ“ b) := forall_mem_imageβ‚‚ @[simp] theorem infs_subset_iff : s ⊼ t βŠ† u ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, a βŠ“ b ∈ u := imageβ‚‚_subset_iff @[simp] theorem infs_nonempty : (s ⊼ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := imageβ‚‚_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected theorem Nonempty.infs : s.Nonempty β†’ t.Nonempty β†’ (s ⊼ t).Nonempty := Nonempty.imageβ‚‚ theorem Nonempty.of_infs_left : (s ⊼ t).Nonempty β†’ s.Nonempty := Nonempty.of_imageβ‚‚_left theorem Nonempty.of_infs_right : (s ⊼ t).Nonempty β†’ t.Nonempty := Nonempty.of_imageβ‚‚_right @[simp] theorem empty_infs : βˆ… ⊼ t = βˆ… := imageβ‚‚_empty_left @[simp] theorem infs_empty : s ⊼ βˆ… = βˆ… := imageβ‚‚_empty_right @[simp] theorem infs_eq_empty : s ⊼ t = βˆ… ↔ s = βˆ… ∨ t = βˆ… := imageβ‚‚_eq_empty_iff @[simp] lemma singleton_infs : {a} ⊼ t = t.image (a βŠ“ Β·) := imageβ‚‚_singleton_left @[simp] lemma infs_singleton : s ⊼ {b} = s.image (Β· βŠ“ b) := imageβ‚‚_singleton_right theorem singleton_infs_singleton : ({a} ⊼ {b} : Finset Ξ±) = {a βŠ“ b} := imageβ‚‚_singleton theorem infs_union_left : (s₁ βˆͺ sβ‚‚) ⊼ t = s₁ ⊼ t βˆͺ sβ‚‚ ⊼ t := imageβ‚‚_union_left theorem infs_union_right : s ⊼ (t₁ βˆͺ tβ‚‚) = s ⊼ t₁ βˆͺ s ⊼ tβ‚‚ := imageβ‚‚_union_right theorem infs_inter_subset_left : (s₁ ∩ sβ‚‚) ⊼ t βŠ† s₁ ⊼ t ∩ sβ‚‚ ⊼ t := imageβ‚‚_inter_subset_left theorem infs_inter_subset_right : s ⊼ (t₁ ∩ tβ‚‚) βŠ† s ⊼ t₁ ∩ s ⊼ tβ‚‚ := imageβ‚‚_inter_subset_right theorem subset_infs {s t : Set Ξ±} : ↑u βŠ† s ⊼ t β†’ βˆƒ s' t' : Finset Ξ±, ↑s' βŠ† s ∧ ↑t' βŠ† t ∧ u βŠ† s' ⊼ t' := subset_set_imageβ‚‚ lemma image_infs (f : F) (s t : Finset Ξ±) : image f (s ⊼ t) = image f s ⊼ image f t := image_imageβ‚‚_distrib <| map_inf f lemma map_infs (f : F) (hf) (s t : Finset Ξ±) : map ⟨f, hf⟩ (s ⊼ t) = map ⟨f, hf⟩ s ⊼ map ⟨f, hf⟩ t := by simpa [map_eq_image] using image_infs f s t lemma subset_infs_self : s βŠ† s ⊼ s := fun _a ha ↦ mem_infs.2 ⟨_, ha, _, ha, inf_idem _⟩ lemma infs_self_subset : s ⊼ s βŠ† s ↔ InfClosed (s : Set Ξ±) := infs_subset_iff @[simp] lemma infs_self : s ⊼ s = s ↔ InfClosed (s : Set Ξ±) := by simp [← coe_inj] @[simp] lemma univ_infs_univ [Fintype Ξ±] : (univ : Finset Ξ±) ⊼ univ = univ := by simp lemma filter_infs_le [DecidableLE Ξ±] (s t : Finset Ξ±) (a : Ξ±) : {b ∈ s ⊼ t | a ≀ b} = {b ∈ s | a ≀ b} ⊼ {b ∈ t | a ≀ b} := by simp only [← coe_inj, coe_filter, coe_infs, ← mem_coe, Set.sep_infs_le] variable (s t u) lemma biUnion_image_inf_left : s.biUnion (fun a ↦ t.image (a βŠ“ Β·)) = s ⊼ t := biUnion_image_left lemma biUnion_image_inf_right : t.biUnion (fun b ↦ s.image (Β· βŠ“ b)) = s ⊼ t := biUnion_image_right theorem image_inf_product (s t : Finset Ξ±) : (s Γ—Λ’ t).image (uncurry (Β· βŠ“ Β·)) = s ⊼ t := image_uncurry_product _ _ _ theorem infs_assoc : s ⊼ t ⊼ u = s ⊼ (t ⊼ u) := imageβ‚‚_assoc inf_assoc theorem infs_comm : s ⊼ t = t ⊼ s := imageβ‚‚_comm inf_comm theorem infs_left_comm : s ⊼ (t ⊼ u) = t ⊼ (s ⊼ u) := imageβ‚‚_left_comm inf_left_comm theorem infs_right_comm : s ⊼ t ⊼ u = s ⊼ u ⊼ t := imageβ‚‚_right_comm inf_right_comm theorem infs_infs_infs_comm : s ⊼ t ⊼ (u ⊼ v) = s ⊼ u ⊼ (t ⊼ v) := imageβ‚‚_imageβ‚‚_imageβ‚‚_comm inf_inf_inf_comm end Infs open FinsetFamily section DistribLattice variable [DecidableEq Ξ±] variable [DistribLattice Ξ±] (s t u : Finset Ξ±) theorem sups_infs_subset_left : s ⊻ t ⊼ u βŠ† (s ⊻ t) ⊼ (s ⊻ u) := imageβ‚‚_distrib_subset_left sup_inf_left theorem sups_infs_subset_right : t ⊼ u ⊻ s βŠ† (t ⊻ s) ⊼ (u ⊻ s) := imageβ‚‚_distrib_subset_right sup_inf_right theorem infs_sups_subset_left : s ⊼ (t ⊻ u) βŠ† s ⊼ t ⊻ s ⊼ u := imageβ‚‚_distrib_subset_left inf_sup_left theorem infs_sups_subset_right : (t ⊻ u) ⊼ s βŠ† t ⊼ s ⊻ u ⊼ s := imageβ‚‚_distrib_subset_right inf_sup_right end DistribLattice section Finset variable [DecidableEq Ξ±] variable {π’œ ℬ : Finset (Finset Ξ±)} {s t : Finset Ξ±} @[simp] lemma powerset_union (s t : Finset Ξ±) : (s βˆͺ t).powerset = s.powerset ⊻ t.powerset := by ext u simp only [mem_sups, mem_powerset, le_eq_subset, sup_eq_union] refine ⟨fun h ↦ ⟨_, inter_subset_left (sβ‚‚ := u), _, inter_subset_left (sβ‚‚ := u), ?_⟩, ?_⟩ Β· rwa [← union_inter_distrib_right, inter_eq_right] Β· rintro ⟨v, hv, w, hw, rfl⟩ exact union_subset_union hv hw @[simp] lemma powerset_inter (s t : Finset Ξ±) : (s ∩ t).powerset = s.powerset ⊼ t.powerset := by ext u simp only [mem_infs, mem_powerset, le_eq_subset, inf_eq_inter] refine ⟨fun h ↦ ⟨_, inter_subset_left (sβ‚‚ := u), _, inter_subset_left (sβ‚‚ := u), ?_⟩, ?_⟩ Β· rwa [← inter_inter_distrib_right, inter_eq_right] Β· rintro ⟨v, hv, w, hw, rfl⟩ exact inter_subset_inter hv hw @[simp] lemma powerset_sups_powerset_self (s : Finset Ξ±) : s.powerset ⊻ s.powerset = s.powerset := by simp [← powerset_union] @[simp] lemma powerset_infs_powerset_self (s : Finset Ξ±) : s.powerset ⊼ s.powerset = s.powerset := by simp [← powerset_inter] lemma union_mem_sups : s ∈ π’œ β†’ t ∈ ℬ β†’ s βˆͺ t ∈ π’œ ⊻ ℬ := sup_mem_sups lemma inter_mem_infs : s ∈ π’œ β†’ t ∈ ℬ β†’ s ∩ t ∈ π’œ ⊼ ℬ := inf_mem_infs end Finset section DisjSups variable [DecidableEq Ξ±] variable [SemilatticeSup Ξ±] [OrderBot Ξ±] [DecidableRel (Ξ± := Ξ±) Disjoint] (s s₁ sβ‚‚ t t₁ tβ‚‚ u : Finset Ξ±) /-- The finset of elements of the form `a βŠ” b` where `a ∈ s`, `b ∈ t` and `a` and `b` are disjoint. -/ def disjSups : Finset Ξ± := {ab ∈ s Γ—Λ’ t | Disjoint ab.1 ab.2}.image fun ab => ab.1 βŠ” ab.2 @[inherit_doc] scoped[FinsetFamily] infixl:74 " β—‹ " => Finset.disjSups open FinsetFamily variable {s t u} {a b c : Ξ±} @[simp] theorem mem_disjSups : c ∈ s β—‹ t ↔ βˆƒ a ∈ s, βˆƒ b ∈ t, Disjoint a b ∧ a βŠ” b = c := by simp [disjSups, and_assoc] theorem disjSups_subset_sups : s β—‹ t βŠ† s ⊻ t := by simp_rw [subset_iff, mem_sups, mem_disjSups] exact fun c ⟨a, b, ha, hb, _, hc⟩ => ⟨a, b, ha, hb, hc⟩ variable (s t) theorem card_disjSups_le : #(s β—‹ t) ≀ #s * #t := (card_le_card disjSups_subset_sups).trans <| card_sups_le _ _ variable {s s₁ sβ‚‚ t t₁ tβ‚‚} theorem disjSups_subset (hs : s₁ βŠ† sβ‚‚) (ht : t₁ βŠ† tβ‚‚) : s₁ β—‹ t₁ βŠ† sβ‚‚ β—‹ tβ‚‚ := image_subset_image <| filter_subset_filter _ <| product_subset_product hs ht theorem disjSups_subset_left (ht : t₁ βŠ† tβ‚‚) : s β—‹ t₁ βŠ† s β—‹ tβ‚‚ := disjSups_subset Subset.rfl ht theorem disjSups_subset_right (hs : s₁ βŠ† sβ‚‚) : s₁ β—‹ t βŠ† sβ‚‚ β—‹ t := disjSups_subset hs Subset.rfl theorem forall_disjSups_iff {p : Ξ± β†’ Prop} : (βˆ€ c ∈ s β—‹ t, p c) ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, Disjoint a b β†’ p (a βŠ” b) := by simp_rw [mem_disjSups] refine ⟨fun h a ha b hb hab => h _ ⟨_, ha, _, hb, hab, rfl⟩, ?_⟩ rintro h _ ⟨a, ha, b, hb, hab, rfl⟩ exact h _ ha _ hb hab @[simp] theorem disjSups_subset_iff : s β—‹ t βŠ† u ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, Disjoint a b β†’ a βŠ” b ∈ u := forall_disjSups_iff theorem Nonempty.of_disjSups_left : (s β—‹ t).Nonempty β†’ s.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, a, ha, _⟩ => ⟨a, ha⟩ theorem Nonempty.of_disjSups_right : (s β—‹ t).Nonempty β†’ t.Nonempty := by simp_rw [Finset.Nonempty, mem_disjSups] exact fun ⟨_, _, _, b, hb, _⟩ => ⟨b, hb⟩ @[simp] theorem disjSups_empty_left : βˆ… β—‹ t = βˆ… := by simp [disjSups] @[simp] theorem disjSups_empty_right : s β—‹ βˆ… = βˆ… := by simp [disjSups] theorem disjSups_singleton : ({a} β—‹ {b} : Finset Ξ±) = if Disjoint a b then {a βŠ” b} else βˆ… := by split_ifs with h <;> simp [disjSups, filter_singleton, h] theorem disjSups_union_left : (s₁ βˆͺ sβ‚‚) β—‹ t = s₁ β—‹ t βˆͺ sβ‚‚ β—‹ t := by simp [disjSups, filter_union, image_union] theorem disjSups_union_right : s β—‹ (t₁ βˆͺ tβ‚‚) = s β—‹ t₁ βˆͺ s β—‹ tβ‚‚ := by simp [disjSups, filter_union, image_union] theorem disjSups_inter_subset_left : (s₁ ∩ sβ‚‚) β—‹ t βŠ† s₁ β—‹ t ∩ sβ‚‚ β—‹ t := by simpa only [disjSups, inter_product, filter_inter_distrib] using image_inter_subset _ _ _ theorem disjSups_inter_subset_right : s β—‹ (t₁ ∩ tβ‚‚) βŠ† s β—‹ t₁ ∩ s β—‹ tβ‚‚ := by simpa only [disjSups, product_inter, filter_inter_distrib] using image_inter_subset _ _ _ variable (s t) theorem disjSups_comm : s β—‹ t = t β—‹ s := by aesop (add simp disjoint_comm, simp sup_comm) instance : @Std.Commutative (Finset Ξ±) (Β· β—‹ Β·) := ⟨disjSups_comm⟩ end DisjSups open FinsetFamily section DistribLattice variable [DecidableEq Ξ±] variable [DistribLattice Ξ±] [OrderBot Ξ±] [DecidableRel (Ξ± := Ξ±) Disjoint] (s t u v : Finset Ξ±) theorem disjSups_assoc : βˆ€ s t u : Finset Ξ±, s β—‹ t β—‹ u = s β—‹ (t β—‹ u) := by refine (associative_of_commutative_of_le inferInstance ?_).assoc simp only [le_eq_subset, disjSups_subset_iff, mem_disjSups] rintro s t u _ ⟨a, ha, b, hb, hab, rfl⟩ c hc habc rw [disjoint_sup_left] at habc exact ⟨a, ha, _, ⟨b, hb, c, hc, habc.2, rfl⟩, hab.sup_right habc.1, (sup_assoc ..).symm⟩ instance : @Std.Associative (Finset Ξ±) (Β· β—‹ Β·) := ⟨disjSups_assoc⟩ theorem disjSups_left_comm : s β—‹ (t β—‹ u) = t β—‹ (s β—‹ u) := by simp_rw [← disjSups_assoc, disjSups_comm s] theorem disjSups_right_comm : s β—‹ t β—‹ u = s β—‹ u β—‹ t := by simp_rw [disjSups_assoc, disjSups_comm] theorem disjSups_disjSups_disjSups_comm : s β—‹ t β—‹ (u β—‹ v) = s β—‹ u β—‹ (t β—‹ v) := by simp_rw [← disjSups_assoc, disjSups_right_comm] end DistribLattice section Diffs variable [DecidableEq Ξ±] variable [GeneralizedBooleanAlgebra Ξ±] (s s₁ sβ‚‚ t t₁ tβ‚‚ u : Finset Ξ±) /-- `s \\ t` is the finset of elements of the form `a \ b` where `a ∈ s`, `b ∈ t`. -/ def diffs : Finset Ξ± β†’ Finset Ξ± β†’ Finset Ξ± := imageβ‚‚ (Β· \ Β·) @[inherit_doc] scoped[FinsetFamily] infixl:74 " \\\\ " => Finset.diffs -- This notation is meant to have higher precedence than `\` and `βŠ“`, but still within the -- realm of other binary notation open FinsetFamily variable {s t} {a b c : Ξ±} @[simp] lemma mem_diffs : c ∈ s \\ t ↔ βˆƒ a ∈ s, βˆƒ b ∈ t, a \ b = c := by simp [(Β· \\ Β·)] variable (s t) @[simp, norm_cast] lemma coe_diffs : (↑(s \\ t) : Set Ξ±) = Set.image2 (Β· \ Β·) s t := coe_imageβ‚‚ _ _ _ lemma card_diffs_le : #(s \\ t) ≀ #s * #t := card_imageβ‚‚_le _ _ _ lemma card_diffs_iff : #(s \\ t) = #s * #t ↔ (s Γ—Λ’ t : Set (Ξ± Γ— Ξ±)).InjOn fun x ↦ x.1 \ x.2 := card_imageβ‚‚_iff variable {s s₁ sβ‚‚ t t₁ tβ‚‚ u} lemma sdiff_mem_diffs : a ∈ s β†’ b ∈ t β†’ a \ b ∈ s \\ t := mem_imageβ‚‚_of_mem lemma diffs_subset : s₁ βŠ† sβ‚‚ β†’ t₁ βŠ† tβ‚‚ β†’ s₁ \\ t₁ βŠ† sβ‚‚ \\ tβ‚‚ := imageβ‚‚_subset lemma diffs_subset_left : t₁ βŠ† tβ‚‚ β†’ s \\ t₁ βŠ† s \\ tβ‚‚ := imageβ‚‚_subset_left lemma diffs_subset_right : s₁ βŠ† sβ‚‚ β†’ s₁ \\ t βŠ† sβ‚‚ \\ t := imageβ‚‚_subset_right lemma image_subset_diffs_left : b ∈ t β†’ s.image (Β· \ b) βŠ† s \\ t := image_subset_imageβ‚‚_left lemma image_subset_diffs_right : a ∈ s β†’ t.image (a \ Β·) βŠ† s \\ t := image_subset_imageβ‚‚_right lemma forall_mem_diffs {p : Ξ± β†’ Prop} : (βˆ€ c ∈ s \\ t, p c) ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, p (a \ b) := forall_mem_imageβ‚‚ @[simp] lemma diffs_subset_iff : s \\ t βŠ† u ↔ βˆ€ a ∈ s, βˆ€ b ∈ t, a \ b ∈ u := imageβ‚‚_subset_iff @[simp] lemma diffs_nonempty : (s \\ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := imageβ‚‚_nonempty_iff @[aesop safe apply (rule_sets := [finsetNonempty])] protected lemma Nonempty.diffs : s.Nonempty β†’ t.Nonempty β†’ (s \\ t).Nonempty := Nonempty.imageβ‚‚ lemma Nonempty.of_diffs_left : (s \\ t).Nonempty β†’ s.Nonempty := Nonempty.of_imageβ‚‚_left lemma Nonempty.of_diffs_right : (s \\ t).Nonempty β†’ t.Nonempty := Nonempty.of_imageβ‚‚_right @[simp] lemma empty_diffs : βˆ… \\ t = βˆ… := imageβ‚‚_empty_left @[simp] lemma diffs_empty : s \\ βˆ… = βˆ… := imageβ‚‚_empty_right @[simp] lemma diffs_eq_empty : s \\ t = βˆ… ↔ s = βˆ… ∨ t = βˆ… := imageβ‚‚_eq_empty_iff @[simp] lemma singleton_diffs : {a} \\ t = t.image (a \ Β·) := imageβ‚‚_singleton_left @[simp] lemma diffs_singleton : s \\ {b} = s.image (Β· \ b) := imageβ‚‚_singleton_right lemma singleton_diffs_singleton : ({a} \\ {b} : Finset Ξ±) = {a \ b} := imageβ‚‚_singleton lemma diffs_union_left : (s₁ βˆͺ sβ‚‚) \\ t = s₁ \\ t βˆͺ sβ‚‚ \\ t := imageβ‚‚_union_left lemma diffs_union_right : s \\ (t₁ βˆͺ tβ‚‚) = s \\ t₁ βˆͺ s \\ tβ‚‚ := imageβ‚‚_union_right lemma diffs_inter_subset_left : (s₁ ∩ sβ‚‚) \\ t βŠ† s₁ \\ t ∩ sβ‚‚ \\ t := imageβ‚‚_inter_subset_left lemma diffs_inter_subset_right : s \\ (t₁ ∩ tβ‚‚) βŠ† s \\ t₁ ∩ s \\ tβ‚‚ := imageβ‚‚_inter_subset_right lemma subset_diffs {s t : Set Ξ±} : ↑u βŠ† Set.image2 (Β· \ Β·) s t β†’ βˆƒ s' t' : Finset Ξ±, ↑s' βŠ† s ∧ ↑t' βŠ† t ∧ u βŠ† s' \\ t' := subset_set_imageβ‚‚ variable (s t u) lemma biUnion_image_sdiff_left : s.biUnion (fun a ↦ t.image (a \ Β·)) = s \\ t := biUnion_image_left lemma biUnion_image_sdiff_right : t.biUnion (fun b ↦ s.image (Β· \ b)) = s \\ t := biUnion_image_right lemma image_sdiff_product (s t : Finset Ξ±) : (s Γ—Λ’ t).image (uncurry (Β· \ Β·)) = s \\ t := image_uncurry_product _ _ _ lemma diffs_right_comm : s \\ t \\ u = s \\ u \\ t := imageβ‚‚_right_comm sdiff_right_comm end Diffs section Compls variable [BooleanAlgebra Ξ±] (s s₁ sβ‚‚ t : Finset Ξ±) /-- `sᢜ˒` is the finset of elements of the form `aᢜ` where `a ∈ s`. -/ def compls : Finset Ξ± β†’ Finset Ξ± := map ⟨compl, compl_injective⟩ @[inherit_doc] scoped[FinsetFamily] postfix:max "ᢜ˒" => Finset.compls open FinsetFamily variable {s t} {a : Ξ±} @[simp] lemma mem_compls : a ∈ sᢜ˒ ↔ aᢜ ∈ s := by rw [Iff.comm, ← mem_map' ⟨compl, compl_injective⟩, Embedding.coeFn_mk, compl_compl, compls] variable (s t) @[simp] lemma image_compl [DecidableEq Ξ±] : s.image compl = sᢜ˒ := by simp [compls, map_eq_image] @[simp, norm_cast] lemma coe_compls : (↑sᢜ˒ : Set Ξ±) = compl '' ↑s := coe_map _ _ @[simp] lemma card_compls : #sᢜ˒ = #s := card_map _ variable {s s₁ sβ‚‚ t} lemma compl_mem_compls : a ∈ s β†’ aᢜ ∈ sᢜ˒ := mem_map_of_mem _ @[simp] lemma compls_subset_compls : sβ‚αΆœΛ’ βŠ† sβ‚‚αΆœΛ’ ↔ s₁ βŠ† sβ‚‚ := map_subset_map lemma forall_mem_compls {p : Ξ± β†’ Prop} : (βˆ€ a ∈ sᢜ˒, p a) ↔ βˆ€ a ∈ s, p aᢜ := forall_mem_map lemma exists_compls_iff {p : Ξ± β†’ Prop} : (βˆƒ a ∈ sᢜ˒, p a) ↔ βˆƒ a ∈ s, p aᢜ := by aesop @[simp] lemma compls_compls (s : Finset Ξ±) : sᢜ˒ᢜ˒ = s := by ext; simp lemma compls_subset_iff : sᢜ˒ βŠ† t ↔ s βŠ† tᢜ˒ := by rw [← compls_subset_compls, compls_compls] @[simp] lemma compls_nonempty : sᢜ˒.Nonempty ↔ s.Nonempty := map_nonempty protected alias ⟨Nonempty.of_compls, Nonempty.compls⟩ := compls_nonempty attribute [aesop safe apply (rule_sets := [finsetNonempty])] Nonempty.compls @[simp] lemma compls_empty : (βˆ… : Finset Ξ±)ᢜ˒ = βˆ… := map_empty _ @[simp] lemma compls_eq_empty : sᢜ˒ = βˆ… ↔ s = βˆ… := map_eq_empty @[simp] lemma compls_singleton (a : Ξ±) : {a}ᢜ˒ = {aᢜ} := map_singleton _ _ @[simp] lemma compls_univ [Fintype Ξ±] : (univ : Finset Ξ±)ᢜ˒ = univ := by ext; simp variable [DecidableEq Ξ±] @[simp] lemma compls_union (s t : Finset Ξ±) : (s βˆͺ t)ᢜ˒ = sᢜ˒ βˆͺ tᢜ˒ := map_union _ _ @[simp] lemma compls_inter (s t : Finset Ξ±) : (s ∩ t)ᢜ˒ = sᢜ˒ ∩ tᢜ˒ := map_inter _ _ @[simp] lemma compls_infs (s t : Finset Ξ±) : (s ⊼ t)ᢜ˒ = sᢜ˒ ⊻ tᢜ˒ := by simp_rw [← image_compl]; exact image_imageβ‚‚_distrib fun _ _ ↦ compl_inf @[simp] lemma compls_sups (s t : Finset Ξ±) : (s ⊻ t)ᢜ˒ = sᢜ˒ ⊼ tᢜ˒ := by simp_rw [← image_compl]; exact image_imageβ‚‚_distrib fun _ _ ↦ compl_sup @[simp] lemma infs_compls_eq_diffs (s t : Finset Ξ±) : s ⊼ tᢜ˒ = s \\ t := by ext; simp [sdiff_eq]; aesop @[simp] lemma compls_infs_eq_diffs (s t : Finset Ξ±) : sᢜ˒ ⊼ t = t \\ s := by rw [infs_comm, infs_compls_eq_diffs] @[simp] lemma diffs_compls_eq_infs (s t : Finset Ξ±) : s \\ tᢜ˒ = s ⊼ t := by rw [← infs_compls_eq_diffs, compls_compls] variable {Ξ± : Type*} [DecidableEq Ξ±] [Fintype Ξ±] {π’œ : Finset (Finset Ξ±)} {n : β„•} protected lemma _root_.Set.Sized.compls (hπ’œ : (π’œ : Set (Finset Ξ±)).Sized n) : (π’œαΆœΛ’ : Set (Finset Ξ±)).Sized (Fintype.card Ξ± - n) := Finset.forall_mem_compls.2 <| fun s hs ↦ by rw [Finset.card_compl, hπ’œ hs] lemma sized_compls (hn : n ≀ Fintype.card Ξ±) : (π’œαΆœΛ’ : Set (Finset Ξ±)).Sized n ↔ (π’œ : Set (Finset Ξ±)).Sized (Fintype.card Ξ± - n) where mp hπ’œ := by simpa using hπ’œ.compls mpr hπ’œ := by simpa only [Nat.sub_sub_self hn] using hπ’œ.compls end Compls end Finset
Mathlib/Data/Finset/Sups.lean
737
737
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Topology.Algebra.Constructions import Mathlib.Topology.Bases import Mathlib.Algebra.Order.Group.Nat import Mathlib.Topology.UniformSpace.Basic /-! # Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets. -/ universe u v open Filter Function TopologicalSpace Topology Set UniformSpace Uniformity variable {Ξ± : Type u} {Ξ² : Type v} [uniformSpace : UniformSpace Ξ±] /-- A filter `f` is Cauchy if for every entourage `r`, there exists an `s ∈ f` such that `s Γ— s βŠ† r`. This is a generalization of Cauchy sequences, because if `a : β„• β†’ Ξ±` then the filter of sets containing cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/ def Cauchy (f : Filter Ξ±) := NeBot f ∧ f Γ—Λ’ f ≀ 𝓀 Ξ± /-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f` has a limit in `s` (formally, it satisfies `f ≀ 𝓝 x` for some `x ∈ s`). -/ def IsComplete (s : Set Ξ±) := βˆ€ f, Cauchy f β†’ f ≀ π“Ÿ s β†’ βˆƒ x ∈ s, f ≀ 𝓝 x theorem Filter.HasBasis.cauchy_iff {ΞΉ} {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ Set (Ξ± Γ— Ξ±)} (h : (𝓀 Ξ±).HasBasis p s) {f : Filter Ξ±} : Cauchy f ↔ NeBot f ∧ βˆ€ i, p i β†’ βˆƒ t ∈ f, βˆ€ x ∈ t, βˆ€ y ∈ t, (x, y) ∈ s i := and_congr Iff.rfl <| (f.basis_sets.prod_self.le_basis_iff h).trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] theorem cauchy_iff' {f : Filter Ξ±} : Cauchy f ↔ NeBot f ∧ βˆ€ s ∈ 𝓀 Ξ±, βˆƒ t ∈ f, βˆ€ x ∈ t, βˆ€ y ∈ t, (x, y) ∈ s := (𝓀 Ξ±).basis_sets.cauchy_iff theorem cauchy_iff {f : Filter Ξ±} : Cauchy f ↔ NeBot f ∧ βˆ€ s ∈ 𝓀 Ξ±, βˆƒ t ∈ f, t Γ—Λ’ t βŠ† s := cauchy_iff'.trans <| by simp only [subset_def, Prod.forall, mem_prod_eq, and_imp, id, forall_mem_comm] lemma cauchy_iff_le {l : Filter Ξ±} [hl : l.NeBot] : Cauchy l ↔ l Γ—Λ’ l ≀ 𝓀 Ξ± := by simp only [Cauchy, hl, true_and] theorem Cauchy.ultrafilter_of {l : Filter Ξ±} (h : Cauchy l) : Cauchy (@Ultrafilter.of _ l h.1 : Filter Ξ±) := by haveI := h.1 have := Ultrafilter.of_le l exact ⟨Ultrafilter.neBot _, (Filter.prod_mono this this).trans h.2⟩ theorem cauchy_map_iff {l : Filter Ξ²} {f : Ξ² β†’ Ξ±} : Cauchy (l.map f) ↔ NeBot l ∧ Tendsto (fun p : Ξ² Γ— Ξ² => (f p.1, f p.2)) (l Γ—Λ’ l) (𝓀 Ξ±) := by rw [Cauchy, map_neBot_iff, prod_map_map_eq, Tendsto] theorem cauchy_map_iff' {l : Filter Ξ²} [hl : NeBot l] {f : Ξ² β†’ Ξ±} : Cauchy (l.map f) ↔ Tendsto (fun p : Ξ² Γ— Ξ² => (f p.1, f p.2)) (l Γ—Λ’ l) (𝓀 Ξ±) := cauchy_map_iff.trans <| and_iff_right hl theorem Cauchy.mono {f g : Filter Ξ±} [hg : NeBot g] (h_c : Cauchy f) (h_le : g ≀ f) : Cauchy g := ⟨hg, le_trans (Filter.prod_mono h_le h_le) h_c.right⟩ theorem Cauchy.mono' {f g : Filter Ξ±} (h_c : Cauchy f) (_ : NeBot g) (h_le : g ≀ f) : Cauchy g := h_c.mono h_le theorem cauchy_nhds {a : Ξ±} : Cauchy (𝓝 a) := ⟨nhds_neBot, nhds_prod_eq.symm.trans_le (nhds_le_uniformity a)⟩ theorem cauchy_pure {a : Ξ±} : Cauchy (pure a) := cauchy_nhds.mono (pure_le_nhds a) theorem Filter.Tendsto.cauchy_map {l : Filter Ξ²} [NeBot l] {f : Ξ² β†’ Ξ±} {a : Ξ±} (h : Tendsto f l (𝓝 a)) : Cauchy (map f l) := cauchy_nhds.mono h lemma Cauchy.mono_uniformSpace {u v : UniformSpace Ξ²} {F : Filter Ξ²} (huv : u ≀ v) (hF : Cauchy (uniformSpace := u) F) : Cauchy (uniformSpace := v) F := ⟨hF.1, hF.2.trans huv⟩ lemma cauchy_inf_uniformSpace {u v : UniformSpace Ξ²} {F : Filter Ξ²} : Cauchy (uniformSpace := u βŠ“ v) F ↔ Cauchy (uniformSpace := u) F ∧ Cauchy (uniformSpace := v) F := by unfold Cauchy rw [inf_uniformity (u := u), le_inf_iff, and_and_left] lemma cauchy_iInf_uniformSpace {ΞΉ : Sort*} [Nonempty ΞΉ] {u : ΞΉ β†’ UniformSpace Ξ²} {l : Filter Ξ²} : Cauchy (uniformSpace := β¨… i, u i) l ↔ βˆ€ i, Cauchy (uniformSpace := u i) l := by unfold Cauchy rw [iInf_uniformity, le_iInf_iff, forall_and, forall_const] lemma cauchy_iInf_uniformSpace' {ΞΉ : Sort*} {u : ΞΉ β†’ UniformSpace Ξ²} {l : Filter Ξ²} [l.NeBot] : Cauchy (uniformSpace := β¨… i, u i) l ↔ βˆ€ i, Cauchy (uniformSpace := u i) l := by simp_rw [cauchy_iff_le (uniformSpace := _), iInf_uniformity, le_iInf_iff] lemma cauchy_comap_uniformSpace {u : UniformSpace Ξ²} {Ξ±} {f : Ξ± β†’ Ξ²} {l : Filter Ξ±} : Cauchy (uniformSpace := comap f u) l ↔ Cauchy (map f l) := by simp only [Cauchy, map_neBot_iff, prod_map_map_eq, map_le_iff_le_comap] rfl lemma cauchy_prod_iff [UniformSpace Ξ²] {F : Filter (Ξ± Γ— Ξ²)} : Cauchy F ↔ Cauchy (map Prod.fst F) ∧ Cauchy (map Prod.snd F) := by simp_rw [instUniformSpaceProd, ← cauchy_comap_uniformSpace, ← cauchy_inf_uniformSpace] theorem Cauchy.prod [UniformSpace Ξ²] {f : Filter Ξ±} {g : Filter Ξ²} (hf : Cauchy f) (hg : Cauchy g) : Cauchy (f Γ—Λ’ g) := by have := hf.1; have := hg.1 simpa [cauchy_prod_iff, hf.1] using ⟨hf, hg⟩ /-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and `SequentiallyComplete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s` one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y` with `(x, y) ∈ s`, then `f` converges to `x`. -/ theorem le_nhds_of_cauchy_adhp_aux {f : Filter Ξ±} {x : Ξ±} (adhs : βˆ€ s ∈ 𝓀 Ξ±, βˆƒ t ∈ f, t Γ—Λ’ t βŠ† s ∧ βˆƒ y, (x, y) ∈ s ∧ y ∈ t) : f ≀ 𝓝 x := by -- Consider a neighborhood `s` of `x` intro s hs -- Take an entourage twice smaller than `s` rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩ -- Take a set `t ∈ f`, `t Γ— t βŠ† U`, and a point `y ∈ t` such that `(x, y) ∈ U` rcases adhs U U_mem with ⟨t, t_mem, ht, y, hxy, hy⟩ apply mem_of_superset t_mem -- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t Γ— t βŠ† U`, hence `z ∈ s` exact fun z hz => hU (prodMk_mem_compRel hxy (ht <| mk_mem_prod hy hz)) rfl /-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point for `f`. -/ theorem le_nhds_of_cauchy_adhp {f : Filter Ξ±} {x : Ξ±} (hf : Cauchy f) (adhs : ClusterPt x f) : f ≀ 𝓝 x := le_nhds_of_cauchy_adhp_aux (fun s hs => by obtain ⟨t, t_mem, ht⟩ : βˆƒ t ∈ f, t Γ—Λ’ t βŠ† s := (cauchy_iff.1 hf).2 s hs use t, t_mem, ht exact forall_mem_nonempty_iff_neBot.2 adhs _ (inter_mem_inf (mem_nhds_left x hs) t_mem)) theorem le_nhds_iff_adhp_of_cauchy {f : Filter Ξ±} {x : Ξ±} (hf : Cauchy f) : f ≀ 𝓝 x ↔ ClusterPt x f := ⟨fun h => ClusterPt.of_le_nhds' h hf.1, le_nhds_of_cauchy_adhp hf⟩ nonrec theorem Cauchy.map [UniformSpace Ξ²] {f : Filter Ξ±} {m : Ξ± β†’ Ξ²} (hf : Cauchy f) (hm : UniformContinuous m) : Cauchy (map m f) := ⟨hf.1.map _, calc map m f Γ—Λ’ map m f = map (Prod.map m m) (f Γ—Λ’ f) := Filter.prod_map_map_eq _ ≀ Filter.map (Prod.map m m) (𝓀 Ξ±) := map_mono hf.right _ ≀ 𝓀 Ξ² := hm⟩ nonrec theorem Cauchy.comap [UniformSpace Ξ²] {f : Filter Ξ²} {m : Ξ± β†’ Ξ²} (hf : Cauchy f) (hm : comap (fun p : Ξ± Γ— Ξ± => (m p.1, m p.2)) (𝓀 Ξ²) ≀ 𝓀 Ξ±) [NeBot (comap m f)] : Cauchy (comap m f) := βŸ¨β€Ή_β€Ί, calc comap m f Γ—Λ’ comap m f = comap (Prod.map m m) (f Γ—Λ’ f) := prod_comap_comap_eq _ ≀ comap (Prod.map m m) (𝓀 Ξ²) := comap_mono hf.right _ ≀ 𝓀 Ξ± := hm⟩ theorem Cauchy.comap' [UniformSpace Ξ²] {f : Filter Ξ²} {m : Ξ± β†’ Ξ²} (hf : Cauchy f) (hm : Filter.comap (fun p : Ξ± Γ— Ξ± => (m p.1, m p.2)) (𝓀 Ξ²) ≀ 𝓀 Ξ±) (_ : NeBot (Filter.comap m f)) : Cauchy (Filter.comap m f) := hf.comap hm /-- Cauchy sequences. Usually defined on β„•, but often it is also useful to say that a function defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that is general enough to cover both β„• and ℝ, which are the main motivating examples. -/ def CauchySeq [Preorder Ξ²] (u : Ξ² β†’ Ξ±) := Cauchy (atTop.map u) theorem CauchySeq.tendsto_uniformity [Preorder Ξ²] {u : Ξ² β†’ Ξ±} (h : CauchySeq u) : Tendsto (Prod.map u u) atTop (𝓀 Ξ±) := by simpa only [Tendsto, prod_map_map_eq', prod_atTop_atTop_eq] using h.right theorem CauchySeq.nonempty [Preorder Ξ²] {u : Ξ² β†’ Ξ±} (hu : CauchySeq u) : Nonempty Ξ² := @nonempty_of_neBot _ _ <| (map_neBot_iff _).1 hu.1 theorem CauchySeq.mem_entourage {Ξ² : Type*} [SemilatticeSup Ξ²] {u : Ξ² β†’ Ξ±} (h : CauchySeq u) {V : Set (Ξ± Γ— Ξ±)} (hV : V ∈ 𝓀 Ξ±) : βˆƒ kβ‚€, βˆ€ i j, kβ‚€ ≀ i β†’ kβ‚€ ≀ j β†’ (u i, u j) ∈ V := by haveI := h.nonempty have := h.tendsto_uniformity; rw [← prod_atTop_atTop_eq] at this simpa [MapsTo] using atTop_basis.prod_self.tendsto_left_iff.1 this V hV theorem Filter.Tendsto.cauchySeq [SemilatticeSup Ξ²] [Nonempty Ξ²] {f : Ξ² β†’ Ξ±} {x} (hx : Tendsto f atTop (𝓝 x)) : CauchySeq f := hx.cauchy_map theorem cauchySeq_const [SemilatticeSup Ξ²] [Nonempty Ξ²] (x : Ξ±) : CauchySeq fun _ : Ξ² => x := tendsto_const_nhds.cauchySeq theorem cauchySeq_iff_tendsto [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β†’ Ξ±} : CauchySeq u ↔ Tendsto (Prod.map u u) atTop (𝓀 Ξ±) := cauchy_map_iff'.trans <| by simp only [prod_atTop_atTop_eq, Prod.map_def] theorem CauchySeq.comp_tendsto {Ξ³} [Preorder Ξ²] [SemilatticeSup Ξ³] [Nonempty Ξ³] {f : Ξ² β†’ Ξ±} (hf : CauchySeq f) {g : Ξ³ β†’ Ξ²} (hg : Tendsto g atTop atTop) : CauchySeq (f ∘ g) := ⟨inferInstance, le_trans (prod_le_prod.mpr ⟨Tendsto.comp le_rfl hg, Tendsto.comp le_rfl hg⟩) hf.2⟩ theorem CauchySeq.comp_injective [SemilatticeSup Ξ²] [NoMaxOrder Ξ²] [Nonempty Ξ²] {u : β„• β†’ Ξ±} (hu : CauchySeq u) {f : Ξ² β†’ β„•} (hf : Injective f) : CauchySeq (u ∘ f) := hu.comp_tendsto <| Nat.cofinite_eq_atTop β–Έ hf.tendsto_cofinite.mono_left atTop_le_cofinite theorem Function.Bijective.cauchySeq_comp_iff {f : β„• β†’ β„•} (hf : Bijective f) (u : β„• β†’ Ξ±) : CauchySeq (u ∘ f) ↔ CauchySeq u := by refine ⟨fun H => ?_, fun H => H.comp_injective hf.injective⟩ lift f to β„• ≃ β„• using hf simpa only [Function.comp_def, f.apply_symm_apply] using H.comp_injective f.symm.injective theorem CauchySeq.subseq_subseq_mem {V : β„• β†’ Set (Ξ± Γ— Ξ±)} (hV : βˆ€ n, V n ∈ 𝓀 Ξ±) {u : β„• β†’ Ξ±} (hu : CauchySeq u) {f g : β„• β†’ β„•} (hf : Tendsto f atTop atTop) (hg : Tendsto g atTop atTop) : βˆƒ Ο† : β„• β†’ β„•, StrictMono Ο† ∧ βˆ€ n, ((u ∘ f ∘ Ο†) n, (u ∘ g ∘ Ο†) n) ∈ V n := by rw [cauchySeq_iff_tendsto] at hu exact ((hu.comp <| hf.prod_atTop hg).comp tendsto_atTop_diagonal).subseq_mem hV -- todo: generalize this and other lemmas to a nonempty semilattice theorem cauchySeq_iff' {u : β„• β†’ Ξ±} : CauchySeq u ↔ βˆ€ V ∈ 𝓀 Ξ±, βˆ€αΆ  k in atTop, k ∈ Prod.map u u ⁻¹' V := cauchySeq_iff_tendsto theorem cauchySeq_iff {u : β„• β†’ Ξ±} : CauchySeq u ↔ βˆ€ V ∈ 𝓀 Ξ±, βˆƒ N, βˆ€ k β‰₯ N, βˆ€ l β‰₯ N, (u k, u l) ∈ V := by simp only [cauchySeq_iff', Filter.eventually_atTop_prod_self', mem_preimage, Prod.map_apply] theorem CauchySeq.prodMap {Ξ³ Ξ΄} [UniformSpace Ξ²] [Preorder Ξ³] [Preorder Ξ΄] {u : Ξ³ β†’ Ξ±} {v : Ξ΄ β†’ Ξ²} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq (Prod.map u v) := by simpa only [CauchySeq, prod_map_map_eq', prod_atTop_atTop_eq] using hu.prod hv @[deprecated (since := "2025-03-10")] alias CauchySeq.prod_map := CauchySeq.prodMap theorem CauchySeq.prodMk {Ξ³} [UniformSpace Ξ²] [Preorder Ξ³] {u : Ξ³ β†’ Ξ±} {v : Ξ³ β†’ Ξ²} (hu : CauchySeq u) (hv : CauchySeq v) : CauchySeq fun x => (u x, v x) := haveI := hu.1.of_map (Cauchy.prod hu hv).mono (tendsto_map.prodMk tendsto_map) @[deprecated (since := "2025-03-10")] alias CauchySeq.prod := CauchySeq.prodMk theorem CauchySeq.eventually_eventually [Preorder Ξ²] {u : Ξ² β†’ Ξ±} (hu : CauchySeq u) {V : Set (Ξ± Γ— Ξ±)} (hV : V ∈ 𝓀 Ξ±) : βˆ€αΆ  k in atTop, βˆ€αΆ  l in atTop, (u k, u l) ∈ V := eventually_atTop_curry <| hu.tendsto_uniformity hV theorem UniformContinuous.comp_cauchySeq {Ξ³} [UniformSpace Ξ²] [Preorder Ξ³] {f : Ξ± β†’ Ξ²} (hf : UniformContinuous f) {u : Ξ³ β†’ Ξ±} (hu : CauchySeq u) : CauchySeq (f ∘ u) := hu.map hf theorem CauchySeq.subseq_mem {V : β„• β†’ Set (Ξ± Γ— Ξ±)} (hV : βˆ€ n, V n ∈ 𝓀 Ξ±) {u : β„• β†’ Ξ±} (hu : CauchySeq u) : βˆƒ Ο† : β„• β†’ β„•, StrictMono Ο† ∧ βˆ€ n, (u <| Ο† (n + 1), u <| Ο† n) ∈ V n := by have : βˆ€ n, βˆƒ N, βˆ€ k β‰₯ N, βˆ€ l β‰₯ k, (u l, u k) ∈ V n := fun n => by rw [cauchySeq_iff] at hu rcases hu _ (hV n) with ⟨N, H⟩ exact ⟨N, fun k hk l hl => H _ (le_trans hk hl) _ hk⟩ obtain βŸ¨Ο† : β„• β†’ β„•, Ο†_extr : StrictMono Ο†, hΟ† : βˆ€ n, βˆ€ l β‰₯ Ο† n, (u l, u <| Ο† n) ∈ V n⟩ := extraction_forall_of_eventually' this exact βŸ¨Ο†, Ο†_extr, fun n => hΟ† _ _ (Ο†_extr <| Nat.lt_add_one n).le⟩ theorem Filter.Tendsto.subseq_mem_entourage {V : β„• β†’ Set (Ξ± Γ— Ξ±)} (hV : βˆ€ n, V n ∈ 𝓀 Ξ±) {u : β„• β†’ Ξ±} {a : Ξ±} (hu : Tendsto u atTop (𝓝 a)) : βˆƒ Ο† : β„• β†’ β„•, StrictMono Ο† ∧ (u (Ο† 0), a) ∈ V 0 ∧ βˆ€ n, (u <| Ο† (n + 1), u <| Ο† n) ∈ V (n + 1) := by rcases mem_atTop_sets.1 (hu (ball_mem_nhds a (symm_le_uniformity <| hV 0))) with ⟨n, hn⟩ rcases (hu.comp (tendsto_add_atTop_nat n)).cauchySeq.subseq_mem fun n => hV (n + 1) with βŸ¨Ο†, Ο†_mono, hΟ†V⟩ exact ⟨fun k => Ο† k + n, Ο†_mono.add_const _, hn _ le_add_self, hΟ†V⟩ /-- If a Cauchy sequence has a convergent subsequence, then it converges. -/ theorem tendsto_nhds_of_cauchySeq_of_subseq [Preorder Ξ²] {u : Ξ² β†’ Ξ±} (hu : CauchySeq u) {ΞΉ : Type*} {f : ΞΉ β†’ Ξ²} {p : Filter ΞΉ} [NeBot p] (hf : Tendsto f p atTop) {a : Ξ±} (ha : Tendsto (u ∘ f) p (𝓝 a)) : Tendsto u atTop (𝓝 a) := le_nhds_of_cauchy_adhp hu (ha.mapClusterPt.of_comp hf) /-- Any shift of a Cauchy sequence is also a Cauchy sequence. -/ theorem cauchySeq_shift {u : β„• β†’ Ξ±} (k : β„•) : CauchySeq (fun n ↦ u (n + k)) ↔ CauchySeq u := by constructor <;> intro h Β· rw [cauchySeq_iff] at h ⊒ intro V mV obtain ⟨N, h⟩ := h V mV use N + k intro a ha b hb convert h (a - k) (Nat.le_sub_of_add_le ha) (b - k) (Nat.le_sub_of_add_le hb) <;> omega Β· exact h.comp_tendsto (tendsto_add_atTop_nat k) theorem Filter.HasBasis.cauchySeq_iff {Ξ³} [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β†’ Ξ±} {p : Ξ³ β†’ Prop} {s : Ξ³ β†’ Set (Ξ± Γ— Ξ±)} (h : (𝓀 Ξ±).HasBasis p s) : CauchySeq u ↔ βˆ€ i, p i β†’ βˆƒ N, βˆ€ m, N ≀ m β†’ βˆ€ n, N ≀ n β†’ (u m, u n) ∈ s i := by rw [cauchySeq_iff_tendsto, ← prod_atTop_atTop_eq] refine (atTop_basis.prod_self.tendsto_iff h).trans ?_ simp only [exists_prop, true_and, MapsTo, preimage, subset_def, Prod.forall, mem_prod_eq, mem_setOf_eq, mem_Ici, and_imp, Prod.map, @forall_swap (_ ≀ _) Ξ²] theorem Filter.HasBasis.cauchySeq_iff' {Ξ³} [Nonempty Ξ²] [SemilatticeSup Ξ²] {u : Ξ² β†’ Ξ±} {p : Ξ³ β†’ Prop} {s : Ξ³ β†’ Set (Ξ± Γ— Ξ±)} (H : (𝓀 Ξ±).HasBasis p s) : CauchySeq u ↔ βˆ€ i, p i β†’ βˆƒ N, βˆ€ n β‰₯ N, (u n, u N) ∈ s i := by refine H.cauchySeq_iff.trans ⟨fun h i hi => ?_, fun h i hi => ?_⟩ Β· exact (h i hi).imp fun N hN n hn => hN n hn N le_rfl Β· rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩ rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩ refine (h j hj).imp fun N hN m hm n hn => hts ⟨u N, hjt ?_, ht' <| hjt ?_⟩ exacts [hN m hm, hN n hn] theorem cauchySeq_of_controlled [SemilatticeSup Ξ²] [Nonempty Ξ²] (U : Ξ² β†’ Set (Ξ± Γ— Ξ±)) (hU : βˆ€ s ∈ 𝓀 Ξ±, βˆƒ n, U n βŠ† s) {f : Ξ² β†’ Ξ±} (hf : βˆ€ ⦃N m n : β⦄, N ≀ m β†’ N ≀ n β†’ (f m, f n) ∈ U N) : CauchySeq f := cauchySeq_iff_tendsto.2 (by intro s hs rw [mem_map, mem_atTop_sets] obtain ⟨N, hN⟩ := hU s hs refine ⟨(N, N), fun mn hmn => ?_⟩ obtain ⟨m, n⟩ := mn exact hN (hf hmn.1 hmn.2)) theorem isComplete_iff_clusterPt {s : Set Ξ±} : IsComplete s ↔ βˆ€ l, Cauchy l β†’ l ≀ π“Ÿ s β†’ βˆƒ x ∈ s, ClusterPt x l := forall₃_congr fun _ hl _ => exists_congr fun _ => and_congr_right fun _ => le_nhds_iff_adhp_of_cauchy hl theorem isComplete_iff_ultrafilter {s : Set Ξ±} : IsComplete s ↔ βˆ€ l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β†’ ↑l ≀ π“Ÿ s β†’ βˆƒ x ∈ s, ↑l ≀ 𝓝 x := by refine ⟨fun h l => h l, fun H => isComplete_iff_clusterPt.2 fun l hl hls => ?_⟩ haveI := hl.1 rcases H (Ultrafilter.of l) hl.ultrafilter_of ((Ultrafilter.of_le l).trans hls) with ⟨x, hxs, hxl⟩ exact ⟨x, hxs, (ClusterPt.of_le_nhds hxl).mono (Ultrafilter.of_le l)⟩ theorem isComplete_iff_ultrafilter' {s : Set Ξ±} : IsComplete s ↔ βˆ€ l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β†’ s ∈ l β†’ βˆƒ x ∈ s, ↑l ≀ 𝓝 x := isComplete_iff_ultrafilter.trans <| by simp only [le_principal_iff, Ultrafilter.mem_coe] protected theorem IsComplete.union {s t : Set Ξ±} (hs : IsComplete s) (ht : IsComplete t) : IsComplete (s βˆͺ t) := by simp only [isComplete_iff_ultrafilter', Ultrafilter.union_mem_iff, or_imp] at * exact fun l hl => ⟨fun hsl => (hs l hl hsl).imp fun x hx => ⟨Or.inl hx.1, hx.2⟩, fun htl => (ht l hl htl).imp fun x hx => ⟨Or.inr hx.1, hx.2⟩⟩ theorem isComplete_iUnion_separated {ΞΉ : Sort*} {s : ΞΉ β†’ Set Ξ±} (hs : βˆ€ i, IsComplete (s i)) {U : Set (Ξ± Γ— Ξ±)} (hU : U ∈ 𝓀 Ξ±) (hd : βˆ€ (i j : ΞΉ), βˆ€ x ∈ s i, βˆ€ y ∈ s j, (x, y) ∈ U β†’ i = j) : IsComplete (⋃ i, s i) := by set S := ⋃ i, s i intro l hl hls rw [le_principal_iff] at hls obtain ⟨hl_ne, hl'⟩ := cauchy_iff.1 hl obtain ⟨t, htS, htl, htU⟩ : βˆƒ t, t βŠ† S ∧ t ∈ l ∧ t Γ—Λ’ t βŠ† U := by rcases hl' U hU with ⟨t, htl, htU⟩ refine ⟨t ∩ S, inter_subset_right, inter_mem htl hls, Subset.trans ?_ htU⟩ gcongr <;> apply inter_subset_left obtain ⟨i, hi⟩ : βˆƒ i, t βŠ† s i := by rcases Filter.nonempty_of_mem htl with ⟨x, hx⟩ rcases mem_iUnion.1 (htS hx) with ⟨i, hi⟩ refine ⟨i, fun y hy => ?_⟩ rcases mem_iUnion.1 (htS hy) with ⟨j, hj⟩ rwa [hd i j x hi y hj (htU <| mk_mem_prod hx hy)] rcases hs i l hl (le_principal_iff.2 <| mem_of_superset htl hi) with ⟨x, hxs, hlx⟩ exact ⟨x, mem_iUnion.2 ⟨i, hxs⟩, hlx⟩ /-- A complete space is defined here using uniformities. A uniform space is complete if every Cauchy filter converges. -/ class CompleteSpace (Ξ± : Type u) [UniformSpace Ξ±] : Prop where /-- In a complete uniform space, every Cauchy filter converges. -/ complete : βˆ€ {f : Filter Ξ±}, Cauchy f β†’ βˆƒ x, f ≀ 𝓝 x theorem complete_univ {Ξ± : Type u} [UniformSpace Ξ±] [CompleteSpace Ξ±] : IsComplete (univ : Set Ξ±) := fun f hf _ => by rcases CompleteSpace.complete hf with ⟨x, hx⟩ exact ⟨x, mem_univ x, hx⟩ instance CompleteSpace.prod [UniformSpace Ξ²] [CompleteSpace Ξ±] [CompleteSpace Ξ²] : CompleteSpace (Ξ± Γ— Ξ²) where complete hf := let ⟨x1, hx1⟩ := CompleteSpace.complete <| hf.map uniformContinuous_fst let ⟨x2, hx2⟩ := CompleteSpace.complete <| hf.map uniformContinuous_snd ⟨(x1, x2), by rw [nhds_prod_eq, le_prod]; constructor <;> assumption⟩ lemma CompleteSpace.fst_of_prod [UniformSpace Ξ²] [CompleteSpace (Ξ± Γ— Ξ²)] [h : Nonempty Ξ²] : CompleteSpace Ξ± where complete hf := let ⟨y⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| hf.prod <| cauchy_pure (a := y) ⟨a, by simpa only [map_fst_prod, nhds_prod_eq] using map_mono (m := Prod.fst) hab⟩ lemma CompleteSpace.snd_of_prod [UniformSpace Ξ²] [CompleteSpace (Ξ± Γ— Ξ²)] [h : Nonempty Ξ±] : CompleteSpace Ξ² where complete hf := let ⟨x⟩ := h let ⟨(a, b), hab⟩ := CompleteSpace.complete <| (cauchy_pure (a := x)).prod hf ⟨b, by simpa only [map_snd_prod, nhds_prod_eq] using map_mono (m := Prod.snd) hab⟩ lemma completeSpace_prod_of_nonempty [UniformSpace Ξ²] [Nonempty Ξ±] [Nonempty Ξ²] : CompleteSpace (Ξ± Γ— Ξ²) ↔ CompleteSpace Ξ± ∧ CompleteSpace Ξ² := ⟨fun _ ↦ ⟨.fst_of_prod (Ξ² := Ξ²), .snd_of_prod (Ξ± := Ξ±)⟩, fun ⟨_, _⟩ ↦ .prod⟩ @[to_additive] instance CompleteSpace.mulOpposite [CompleteSpace Ξ±] : CompleteSpace αᡐᡒᡖ where complete hf := MulOpposite.op_surjective.exists.mpr <| let ⟨x, hx⟩ := CompleteSpace.complete (hf.map MulOpposite.uniformContinuous_unop) ⟨x, (map_le_iff_le_comap.mp hx).trans_eq <| MulOpposite.comap_unop_nhds _⟩ /-- If `univ` is complete, the space is a complete space -/ theorem completeSpace_of_isComplete_univ (h : IsComplete (univ : Set Ξ±)) : CompleteSpace Ξ± := ⟨fun hf => let ⟨x, _, hx⟩ := h _ hf ((@principal_univ Ξ±).symm β–Έ le_top); ⟨x, hx⟩⟩ theorem completeSpace_iff_isComplete_univ : CompleteSpace Ξ± ↔ IsComplete (univ : Set Ξ±) := ⟨@complete_univ Ξ± _, completeSpace_of_isComplete_univ⟩ theorem completeSpace_iff_ultrafilter : CompleteSpace Ξ± ↔ βˆ€ l : Ultrafilter Ξ±, Cauchy (l : Filter Ξ±) β†’ βˆƒ x : Ξ±, ↑l ≀ 𝓝 x := by simp [completeSpace_iff_isComplete_univ, isComplete_iff_ultrafilter] theorem cauchy_iff_exists_le_nhds [CompleteSpace Ξ±] {l : Filter Ξ±} [NeBot l] : Cauchy l ↔ βˆƒ x, l ≀ 𝓝 x := ⟨CompleteSpace.complete, fun ⟨_, hx⟩ => cauchy_nhds.mono hx⟩ theorem cauchy_map_iff_exists_tendsto [CompleteSpace Ξ±] {l : Filter Ξ²} {f : Ξ² β†’ Ξ±} [NeBot l] : Cauchy (l.map f) ↔ βˆƒ x, Tendsto f l (𝓝 x) := cauchy_iff_exists_le_nhds /-- A Cauchy sequence in a complete space converges -/ theorem cauchySeq_tendsto_of_complete [Preorder Ξ²] [CompleteSpace Ξ±] {u : Ξ² β†’ Ξ±} (H : CauchySeq u) : βˆƒ x, Tendsto u atTop (𝓝 x) := CompleteSpace.complete H /-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/ theorem cauchySeq_tendsto_of_isComplete [Preorder Ξ²] {K : Set Ξ±} (h₁ : IsComplete K) {u : Ξ² β†’ Ξ±} (hβ‚‚ : βˆ€ n, u n ∈ K) (h₃ : CauchySeq u) : βˆƒ v ∈ K, Tendsto u atTop (𝓝 v) := h₁ _ h₃ <| le_principal_iff.2 <| mem_map_iff_exists_image.2 ⟨univ, univ_mem, by rwa [image_univ, range_subset_iff]⟩ theorem Cauchy.le_nhds_lim [CompleteSpace Ξ±] {f : Filter Ξ±} (hf : Cauchy f) : haveI := hf.1.nonempty; f ≀ 𝓝 (lim f) := _root_.le_nhds_lim (CompleteSpace.complete hf) theorem CauchySeq.tendsto_limUnder [Preorder Ξ²] [CompleteSpace Ξ±] {u : Ξ² β†’ Ξ±} (h : CauchySeq u) : haveI := h.1.nonempty; Tendsto u atTop (𝓝 <| limUnder atTop u) := h.le_nhds_lim theorem IsClosed.isComplete [CompleteSpace Ξ±] {s : Set Ξ±} (h : IsClosed s) : IsComplete s := fun _ cf fs => let ⟨x, hx⟩ := CompleteSpace.complete cf ⟨x, isClosed_iff_clusterPt.mp h x (cf.left.mono (le_inf hx fs)), hx⟩ /-- A set `s` is totally bounded if for every entourage `d` there is a finite set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/ def TotallyBounded (s : Set Ξ±) : Prop := βˆ€ d ∈ 𝓀 Ξ±, βˆƒ t : Set Ξ±, t.Finite ∧ s βŠ† ⋃ y ∈ t, { x | (x, y) ∈ d } theorem TotallyBounded.exists_subset {s : Set Ξ±} (hs : TotallyBounded s) {U : Set (Ξ± Γ— Ξ±)} (hU : U ∈ 𝓀 Ξ±) : βˆƒ t, t βŠ† s ∧ Set.Finite t ∧ s βŠ† ⋃ y ∈ t, { x | (x, y) ∈ U } := by rcases comp_symm_of_uniformity hU with ⟨r, hr, rs, rU⟩ rcases hs r hr with ⟨k, fk, ks⟩ let u := k ∩ { y | βˆƒ x ∈ s, (x, y) ∈ r } choose f hfs hfr using fun x : u => x.coe_prop.2 refine ⟨range f, ?_, ?_, ?_⟩ Β· exact range_subset_iff.2 hfs Β· haveI : Fintype u := (fk.inter_of_left _).fintype exact finite_range f Β· intro x xs obtain ⟨y, hy, xy⟩ := mem_iUnionβ‚‚.1 (ks xs) rw [biUnion_range, mem_iUnion] set z : β†₯u := ⟨y, hy, ⟨x, xs, xy⟩⟩ exact ⟨z, rU <| mem_compRel.2 ⟨y, xy, rs (hfr z)⟩⟩ theorem totallyBounded_iff_subset {s : Set Ξ±} : TotallyBounded s ↔ βˆ€ d ∈ 𝓀 Ξ±, βˆƒ t, t βŠ† s ∧ Set.Finite t ∧ s βŠ† ⋃ y ∈ t, { x | (x, y) ∈ d } := ⟨fun H _ hd ↦ H.exists_subset hd, fun H d hd ↦ let ⟨t, _, ht⟩ := H d hd; ⟨t, ht⟩⟩ theorem Filter.HasBasis.totallyBounded_iff {ΞΉ} {p : ΞΉ β†’ Prop} {U : ΞΉ β†’ Set (Ξ± Γ— Ξ±)} (H : (𝓀 Ξ±).HasBasis p U) {s : Set Ξ±} : TotallyBounded s ↔ βˆ€ i, p i β†’ βˆƒ t : Set Ξ±, Set.Finite t ∧ s βŠ† ⋃ y ∈ t, { x | (x, y) ∈ U i } := H.forall_iff fun _ _ hUV h => h.imp fun _ ht => ⟨ht.1, ht.2.trans <| iUnionβ‚‚_mono fun _ _ _ hy => hUV hy⟩ theorem totallyBounded_of_forall_symm {s : Set Ξ±} (h : βˆ€ V ∈ 𝓀 Ξ±, IsSymmetricRel V β†’ βˆƒ t : Set Ξ±, Set.Finite t ∧ s βŠ† ⋃ y ∈ t, ball y V) : TotallyBounded s := UniformSpace.hasBasis_symmetric.totallyBounded_iff.2 fun V hV => by simpa only [ball_eq_of_symmetry hV.2] using h V hV.1 hV.2 theorem TotallyBounded.subset {s₁ sβ‚‚ : Set Ξ±} (hs : s₁ βŠ† sβ‚‚) (h : TotallyBounded sβ‚‚) : TotallyBounded s₁ := fun d hd => let ⟨t, ht₁, htβ‚‚βŸ© := h d hd ⟨t, ht₁, Subset.trans hs htβ‚‚βŸ© /-- The closure of a totally bounded set is totally bounded. -/ theorem TotallyBounded.closure {s : Set Ξ±} (h : TotallyBounded s) : TotallyBounded (closure s) := uniformity_hasBasis_closed.totallyBounded_iff.2 fun V hV => let ⟨t, htf, hst⟩ := h V hV.1 ⟨t, htf, closure_minimal hst <| htf.isClosed_biUnion fun _ _ => hV.2.preimage (.prodMk_left _)⟩ @[simp] lemma totallyBounded_closure {s : Set Ξ±} : TotallyBounded (closure s) ↔ TotallyBounded s := ⟨fun h ↦ h.subset subset_closure, TotallyBounded.closure⟩ /-- A finite indexed union is totally bounded if and only if each set of the family is totally bounded. -/ @[simp] lemma totallyBounded_iUnion {ΞΉ : Sort*} [Finite ΞΉ] {s : ΞΉ β†’ Set Ξ±} : TotallyBounded (⋃ i, s i) ↔ βˆ€ i, TotallyBounded (s i) := by refine ⟨fun h i ↦ h.subset (subset_iUnion _ _), fun h U hU ↦ ?_⟩ choose t htf ht using (h Β· U hU) refine βŸ¨β‹ƒ i, t i, finite_iUnion htf, ?_⟩ rw [biUnion_iUnion] gcongr; apply ht /-- A union indexed by a finite set is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_biUnion {ΞΉ : Type*} {I : Set ΞΉ} (hI : I.Finite) {s : ΞΉ β†’ Set Ξ±} : TotallyBounded (⋃ i ∈ I, s i) ↔ βˆ€ i ∈ I, TotallyBounded (s i) := by have := hI.to_subtype rw [biUnion_eq_iUnion, totallyBounded_iUnion, Subtype.forall] /-- A union of a finite family of sets is totally bounded if and only if each set of the family is totally bounded. -/ lemma totallyBounded_sUnion {S : Set (Set Ξ±)} (hS : S.Finite) : TotallyBounded (⋃₀ S) ↔ βˆ€ s ∈ S, TotallyBounded s := by rw [sUnion_eq_biUnion, totallyBounded_biUnion hS] /-- A finite set is totally bounded. -/ lemma Set.Finite.totallyBounded {s : Set Ξ±} (hs : s.Finite) : TotallyBounded s := fun _U hU ↦ ⟨s, hs, fun _x hx ↦ mem_biUnion hx <| refl_mem_uniformity hU⟩ /-- A subsingleton is totally bounded. -/ lemma Set.Subsingleton.totallyBounded {s : Set Ξ±} (hs : s.Subsingleton) : TotallyBounded s := hs.finite.totallyBounded @[simp] lemma totallyBounded_singleton (a : Ξ±) : TotallyBounded {a} := (finite_singleton a).totallyBounded @[simp] theorem totallyBounded_empty : TotallyBounded (βˆ… : Set Ξ±) := finite_empty.totallyBounded /-- The union of two sets is totally bounded if and only if each of the two sets is totally bounded. -/ @[simp] lemma totallyBounded_union {s t : Set Ξ±} : TotallyBounded (s βˆͺ t) ↔ TotallyBounded s ∧ TotallyBounded t := by rw [union_eq_iUnion, totallyBounded_iUnion] simp [and_comm] /-- The union of two totally bounded sets is totally bounded. -/ protected lemma TotallyBounded.union {s t : Set Ξ±} (hs : TotallyBounded s) (ht : TotallyBounded t) : TotallyBounded (s βˆͺ t) := totallyBounded_union.2 ⟨hs, ht⟩ @[simp] lemma totallyBounded_insert (a : Ξ±) {s : Set Ξ±} : TotallyBounded (insert a s) ↔ TotallyBounded s := by simp_rw [← singleton_union, totallyBounded_union, totallyBounded_singleton, true_and] protected alias ⟨_, TotallyBounded.insert⟩ := totallyBounded_insert /-- The image of a totally bounded set under a uniformly continuous map is totally bounded. -/ theorem TotallyBounded.image [UniformSpace Ξ²] {f : Ξ± β†’ Ξ²} {s : Set Ξ±} (hs : TotallyBounded s) (hf : UniformContinuous f) : TotallyBounded (f '' s) := fun t ht => have : { p : Ξ± Γ— Ξ± | (f p.1, f p.2) ∈ t } ∈ 𝓀 Ξ± := hf ht let ⟨c, hfc, hct⟩ := hs _ this ⟨f '' c, hfc.image f, by simp only [mem_image, iUnion_exists, biUnion_and', iUnion_iUnion_eq_right, image_subset_iff, preimage_iUnion, preimage_setOf_eq] simp? [subset_def] at hct says simp only [mem_setOf_eq, subset_def, mem_iUnion, exists_prop] at hct intro x hx simpa using hct x hx⟩ theorem Ultrafilter.cauchy_of_totallyBounded {s : Set Ξ±} (f : Ultrafilter Ξ±) (hs : TotallyBounded s) (h : ↑f ≀ π“Ÿ s) : Cauchy (f : Filter Ξ±) := ⟨f.neBot', fun _ ht => let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht let ⟨i, hi, hs_union⟩ := hs t' ht'₁ have : (⋃ y ∈ i, { x | (x, y) ∈ t' }) ∈ f := mem_of_superset (le_principal_iff.mp h) hs_union have : βˆƒ y ∈ i, { x | (x, y) ∈ t' } ∈ f := (Ultrafilter.finite_biUnion_mem_iff hi).1 this let ⟨y, _, hif⟩ := this have : { x | (x, y) ∈ t' } Γ—Λ’ { x | (x, y) ∈ t' } βŠ† compRel t' t' := fun ⟨_, _⟩ ⟨(h₁ : (_, y) ∈ t'), (hβ‚‚ : (_, y) ∈ t')⟩ => ⟨y, h₁, ht'_symm hβ‚‚βŸ© mem_of_superset (prod_mem_prod hif hif) (Subset.trans this ht'_t)⟩ theorem totallyBounded_iff_filter {s : Set Ξ±} : TotallyBounded s ↔ βˆ€ f, NeBot f β†’ f ≀ π“Ÿ s β†’ βˆƒ c ≀ f, Cauchy c := by constructor Β· exact fun H f hf hfs => ⟨Ultrafilter.of f, Ultrafilter.of_le f, (Ultrafilter.of f).cauchy_of_totallyBounded H ((Ultrafilter.of_le f).trans hfs)⟩ Β· intro H d hd contrapose! H with hd_cover set f := β¨… t : Finset Ξ±, π“Ÿ (s \ ⋃ y ∈ t, { x | (x, y) ∈ d }) have hb : HasAntitoneBasis f fun t : Finset Ξ± ↦ s \ ⋃ y ∈ t, { x | (x, y) ∈ d } := .iInf_principal fun _ _ ↦ diff_subset_diff_right ∘ biUnion_subset_biUnion_left have : Filter.NeBot f := hb.1.neBot_iff.2 fun _ ↦ diff_nonempty.2 <| hd_cover _ (Finset.finite_toSet _) have : f ≀ π“Ÿ s := iInf_le_of_le βˆ… (by simp) refine ⟨f, β€Ή_β€Ί, β€Ή_β€Ί, fun c hcf hc => ?_⟩ rcases mem_prod_same_iff.1 (hc.2 hd) with ⟨m, hm, hmd⟩ rcases hc.1.nonempty_of_mem hm with ⟨y, hym⟩ have : s \ {x | (x, y) ∈ d} ∈ c := by simpa using hcf (hb.mem {y}) rcases hc.1.nonempty_of_mem (inter_mem hm this) with ⟨z, hzm, -, hyz⟩ exact hyz (hmd ⟨hzm, hym⟩)
theorem totallyBounded_iff_ultrafilter {s : Set Ξ±} : TotallyBounded s ↔ βˆ€ f : Ultrafilter Ξ±, ↑f ≀ π“Ÿ s β†’ Cauchy (f : Filter Ξ±) := by refine ⟨fun hs f => f.cauchy_of_totallyBounded hs, fun H => totallyBounded_iff_filter.2 ?_⟩ intro f hf hfs exact ⟨Ultrafilter.of f, Ultrafilter.of_le f, H _ ((Ultrafilter.of_le f).trans hfs)⟩ theorem isCompact_iff_totallyBounded_isComplete {s : Set Ξ±} : IsCompact s ↔ TotallyBounded s ∧ IsComplete s := ⟨fun hs => ⟨totallyBounded_iff_ultrafilter.2 fun f hf => let ⟨_, _, fx⟩ := isCompact_iff_ultrafilter_le_nhds.1 hs f hf cauchy_nhds.mono fx, fun f fc fs => let ⟨a, as, fa⟩ := @hs f fc.1 fs ⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩, fun ⟨ht, hc⟩ => isCompact_iff_ultrafilter_le_nhds.2 fun f hf => hc _ (totallyBounded_iff_ultrafilter.1 ht f hf) hf⟩
Mathlib/Topology/UniformSpace/Cauchy.lean
601
619
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ΞΉ : Sort*} {Ξ± : Type u} {Ξ² : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] {x y : Ξ±} {s t : Set Ξ±} {Ξ¦ : Ξ± β†’ Ξ²} /-! ### Distance of a point to a set as a function into `ℝβ‰₯0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : Ξ±) (s : Set Ξ±) : ℝβ‰₯0∞ := β¨… y ∈ s, edist x y @[simp] theorem infEdist_empty : infEdist x βˆ… = ∞ := iInf_emptyset theorem le_infEdist {d} : d ≀ infEdist x s ↔ βˆ€ y ∈ s, d ≀ edist x y := by simp only [infEdist, le_iInf_iff] /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s βˆͺ t) = infEdist x s βŠ“ infEdist x t := iInf_union @[simp] theorem infEdist_iUnion (f : ΞΉ β†’ Set Ξ±) (x : Ξ±) : infEdist x (⋃ i, f i) = β¨… i, infEdist x (f i) := iInf_iUnion f _ lemma infEdist_biUnion {ΞΉ : Type*} (f : ΞΉ β†’ Set Ξ±) (I : Set ΞΉ) (x : Ξ±) : infEdist x (⋃ i ∈ I, f i) = β¨… i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≀ edist x y := iInfβ‚‚_le y h /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x β–Έ infEdist_le_edist_of_mem h /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s βŠ† t) : infEdist x t ≀ infEdist x s := iInf_le_iInf_of_subset h /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝβ‰₯0∞} : infEdist x s < r ↔ βˆƒ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≀ infEdist y s + edist x y := calc β¨… z ∈ s, edist x z ≀ β¨… z ∈ s, edist y z + edist x y := iInfβ‚‚_mono fun _ _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (β¨… z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] theorem infEdist_le_edist_add_infEdist : infEdist x s ≀ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≀ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInfβ‚‚ fun i hi => ?_ calc edist x y ≀ edist x i + edist i y := edist_triangle _ _ _ _ ≀ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forallβ‚‚_true_iff] /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun Ξ΅ Ξ΅pos h => ?_ have Ξ΅0 : 0 < (Ξ΅ / 2 : ℝβ‰₯0∞) := by simpa [pos_iff_ne_zero] using Ξ΅pos have : infEdist x (closure s) < infEdist x (closure s) + Ξ΅ / 2 := ENNReal.lt_add_right h.ne Ξ΅0.ne' obtain ⟨y : Ξ±, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑Ρ / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : Ξ±, zs : z ∈ s, dyz : edist y z < ↑Ρ / 2⟩ := EMetric.mem_closure_iff.1 ycs (Ξ΅ / 2) Ξ΅0 calc infEdist x s ≀ edist x z := infEdist_le_edist_of_mem zs _ ≀ edist x y + edist y z := edist_triangle _ _ _ _ ≀ infEdist x (closure s) + Ξ΅ / 2 + Ξ΅ / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑Ρ := by rw [add_assoc, ENNReal.add_halves] /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun Ξ΅ Ξ΅pos => infEdist_lt_iff.mp <| by rwa [h]⟩ /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : Ξ±} {E : Set Ξ±} : 0 < infEdist x E ↔ x βˆ‰ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] theorem infEdist_closure_pos_iff_not_mem_closure {x : Ξ±} {E : Set Ξ±} : 0 < infEdist x (closure E) ↔ x βˆ‰ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : Ξ±} {E : Set Ξ±} (h : x βˆ‰ closure E) : βˆƒ Ξ΅ : ℝ, 0 < Ξ΅ ∧ ENNReal.ofReal Ξ΅ < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨Ρ, ⟨_, ⟨Ρ_pos, Ξ΅_lt⟩⟩⟩ exact ⟨Ρ, ⟨ENNReal.ofReal_pos.mp Ξ΅_pos, Ξ΅_lt⟩⟩ theorem disjoint_closedBall_of_lt_infEdist {r : ℝβ‰₯0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≀ edist x y := infEdist_le_edist_of_mem h'y _ ≀ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΞ¦ : Isometry Ξ¦) : infEdist (Ξ¦ x) (Ξ¦ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΞ¦.edist_eq] @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M Ξ±] [IsIsometricSMul M Ξ±] (c : M) (x : Ξ±) (s : Set Ξ±) : infEdist (c β€’ x) (c β€’ s) = infEdist x s := infEdist_image (isometry_smul _ _) theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set Ξ±} (hU : IsOpen U) : βˆƒ F : β„• β†’ Set Ξ±, (βˆ€ n, IsClosed (F n)) ∧ (βˆ€ n, F n βŠ† U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : βˆƒ a : ℝβ‰₯0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : β„• => (fun x => infEdist x Uᢜ) ⁻¹' Ici (a ^ n) have F_subset : βˆ€ n, F n βŠ† U := fun n x hx ↦ by by_contra h have : infEdist x Uᢜ β‰  0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ Β· show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : Β¬x ∈ Uᢜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᢜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊒ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : Ξ±) : βˆƒ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : βˆƒ r : ℝβ‰₯0, 0 < r ∧ βˆ€ x ∈ s, βˆ€ y ∈ t, (r : ℝβ‰₯0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) Β· use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, hβ‚€, hr⟩ exact ⟨r, ENNReal.coe_pos.mp hβ‚€, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ end InfEdist /-! ### The Hausdorff distance as a function into `ℝβ‰₯0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {Ξ± : Type u} [PseudoEMetricSpace Ξ±] (s t : Set Ξ±) : ℝβ‰₯0∞ := (⨆ x ∈ s, infEdist x t) βŠ” ⨆ y ∈ t, infEdist y s section HausdorffEdist variable [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] {x : Ξ±} {s t u : Set Ξ±} {Ξ¦ : Ξ± β†’ Ξ²} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝβ‰₯0∞} (H1 : βˆ€ x ∈ s, infEdist x t ≀ r) (H2 : βˆ€ x ∈ t, infEdist x s ≀ r) : hausdorffEdist s t ≀ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝβ‰₯0∞} (H1 : βˆ€ x ∈ s, βˆƒ y ∈ t, edist x y ≀ r) (H2 : βˆ€ x ∈ t, βˆƒ y ∈ s, edist x y ≀ r) : hausdorffEdist s t ≀ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) Β· rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy Β· rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≀ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSupβ‚‚ (Ξ± := ℝβ‰₯0∞) x h /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝβ‰₯0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : βˆƒ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≀ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≀ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun Ξ΅ Ξ΅pos h => by have Ξ΅0 : (Ξ΅ / 2 : ℝβ‰₯0∞) β‰  0 := by simpa [pos_iff_ne_zero] using Ξ΅pos have : infEdist x s < infEdist x s + Ξ΅ / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne Ξ΅0 obtain ⟨y : Ξ±, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑Ρ / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + Ξ΅ / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne Ξ΅0 obtain ⟨z : Ξ±, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑Ρ / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≀ edist x z := infEdist_le_edist_of_mem zt _ ≀ edist x y + edist y z := edist_triangle _ _ _ _ ≀ infEdist x s + Ξ΅ / 2 + (hausdorffEdist s t + Ξ΅ / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + Ξ΅ := by simp [ENNReal.add_halves, add_comm, add_left_comm] /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Ξ¦) : hausdorffEdist (Ξ¦ '' s) (Ξ¦ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≀ diam (s βˆͺ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ Β· intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ Β· intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≀ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor Β· show βˆ€ x ∈ s, infEdist x u ≀ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≀ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≀ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ Β· show βˆ€ x ∈ u, infEdist x s ≀ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≀ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≀ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ Β· calc _ ≀ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] Β· calc _ ≀ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closureβ‚‚ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] /-- The Hausdorff edistance between sets or their closures is the same. -/ theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/ theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq] /-- The Haudorff edistance to the empty set is infinite. -/ theorem hausdorffEdist_empty (ne : s.Nonempty) : hausdorffEdist s βˆ… = ∞ := by rcases ne with ⟨x, xs⟩ have : infEdist x βˆ… ≀ hausdorffEdist s βˆ… := infEdist_le_hausdorffEdist_of_mem xs simpa using this /-- If a set is at finite Hausdorff edistance of a nonempty set, it is nonempty. -/ theorem nonempty_of_hausdorffEdist_ne_top (hs : s.Nonempty) (fin : hausdorffEdist s t β‰  ⊀) : t.Nonempty := t.eq_empty_or_nonempty.resolve_left fun ht ↦ fin (ht.symm β–Έ hausdorffEdist_empty hs) theorem empty_or_nonempty_of_hausdorffEdist_ne_top (fin : hausdorffEdist s t β‰  ⊀) : (s = βˆ… ∧ t = βˆ…) ∨ (s.Nonempty ∧ t.Nonempty) := by rcases s.eq_empty_or_nonempty with hs | hs Β· rcases t.eq_empty_or_nonempty with ht | ht Β· exact Or.inl ⟨hs, ht⟩ Β· rw [hausdorffEdist_comm] at fin exact Or.inr ⟨nonempty_of_hausdorffEdist_ne_top ht fin, ht⟩ Β· exact Or.inr ⟨hs, nonempty_of_hausdorffEdist_ne_top hs fin⟩ end HausdorffEdist -- section end EMetric /-! Now, we turn to the same notions in metric spaces. To avoid the difficulties related to `sInf` and `sSup` on `ℝ` (which is only conditionally complete), we use the notions in `ℝβ‰₯0∞` formulated in terms of the edistance, and coerce them to `ℝ`. Then their properties follow readily from the corresponding properties in `ℝβ‰₯0∞`, modulo some tedious rewriting of inequalities from one to the other. -/ --namespace namespace Metric section variable [PseudoMetricSpace Ξ±] [PseudoMetricSpace Ξ²] {s t u : Set Ξ±} {x y : Ξ±} {Ξ¦ : Ξ± β†’ Ξ²} open EMetric /-! ### Distance of a point to a set as a function into `ℝ`. -/ /-- The minimal distance of a point to a set -/ def infDist (x : Ξ±) (s : Set Ξ±) : ℝ := ENNReal.toReal (infEdist x s) theorem infDist_eq_iInf : infDist x s = β¨… y : s, dist x y := by rw [infDist, infEdist, iInf_subtype', ENNReal.toReal_iInf] Β· simp only [dist_edist] Β· exact fun _ ↦ edist_ne_top _ _ /-- The minimal distance is always nonnegative -/ theorem infDist_nonneg : 0 ≀ infDist x s := toReal_nonneg /-- The minimal distance to the empty set is 0 (if you want to have the more reasonable value `∞` instead, use `EMetric.infEdist`, which takes values in `ℝβ‰₯0∞`) -/ @[simp] theorem infDist_empty : infDist x βˆ… = 0 := by simp [infDist] lemma isGLB_infDist (hs : s.Nonempty) : IsGLB ((dist x Β·) '' s) (infDist x s) := by simpa [infDist_eq_iInf, sInf_image'] using isGLB_csInf (hs.image _) ⟨0, by simp [lowerBounds, dist_nonneg]⟩ /-- In a metric space, the minimal edistance to a nonempty set is finite. -/ theorem infEdist_ne_top (h : s.Nonempty) : infEdist x s β‰  ⊀ := by rcases h with ⟨y, hy⟩ exact ne_top_of_le_ne_top (edist_ne_top _ _) (infEdist_le_edist_of_mem hy) @[simp] theorem infEdist_eq_top_iff : infEdist x s = ∞ ↔ s = βˆ… := by rcases s.eq_empty_or_nonempty with rfl | hs <;> simp [*, Nonempty.ne_empty, infEdist_ne_top] /-- The minimal distance of a point to a set containing it vanishes. -/ theorem infDist_zero_of_mem (h : x ∈ s) : infDist x s = 0 := by simp [infEdist_zero_of_mem h, infDist] /-- The minimal distance to a singleton is the distance to the unique point in this singleton. -/ @[simp] theorem infDist_singleton : infDist x {y} = dist x y := by simp [infDist, dist_edist] /-- The minimal distance to a set is bounded by the distance to any point in this set. -/ theorem infDist_le_dist_of_mem (h : y ∈ s) : infDist x s ≀ dist x y := by rw [dist_edist, infDist] exact ENNReal.toReal_mono (edist_ne_top _ _) (infEdist_le_edist_of_mem h) /-- The minimal distance is monotone with respect to inclusion. -/ theorem infDist_le_infDist_of_subset (h : s βŠ† t) (hs : s.Nonempty) : infDist x t ≀ infDist x s := ENNReal.toReal_mono (infEdist_ne_top hs) (infEdist_anti h) lemma le_infDist {r : ℝ} (hs : s.Nonempty) : r ≀ infDist x s ↔ βˆ€ ⦃y⦄, y ∈ s β†’ r ≀ dist x y := by simp_rw [infDist, ← ENNReal.ofReal_le_iff_le_toReal (infEdist_ne_top hs), le_infEdist, ENNReal.ofReal_le_iff_le_toReal (edist_ne_top _ _), ← dist_edist] /-- The minimal distance to a set `s` is `< r` iff there exists a point in `s` at distance `< r`. -/ theorem infDist_lt_iff {r : ℝ} (hs : s.Nonempty) : infDist x s < r ↔ βˆƒ y ∈ s, dist x y < r := by simp [← not_le, le_infDist hs] /-- The minimal distance from `x` to `s` is bounded by the distance from `y` to `s`, modulo the distance between `x` and `y`. -/ theorem infDist_le_infDist_add_dist : infDist x s ≀ infDist y s + dist x y := by rw [infDist, infDist, dist_edist] refine ENNReal.toReal_le_add' infEdist_le_infEdist_add_edist ?_ (flip absurd (edist_ne_top _ _)) simp only [infEdist_eq_top_iff, imp_self] theorem not_mem_of_dist_lt_infDist (h : dist x y < infDist x s) : y βˆ‰ s := fun hy => h.not_le <| infDist_le_dist_of_mem hy theorem disjoint_ball_infDist : Disjoint (ball x (infDist x s)) s := disjoint_left.2 fun _y hy => not_mem_of_dist_lt_infDist <| mem_ball'.1 hy theorem ball_infDist_subset_compl : ball x (infDist x s) βŠ† sᢜ := (disjoint_ball_infDist (s := s)).subset_compl_right theorem ball_infDist_compl_subset : ball x (infDist x sᢜ) βŠ† s := ball_infDist_subset_compl.trans_eq (compl_compl s) theorem disjoint_closedBall_of_lt_infDist {r : ℝ} (h : r < infDist x s) : Disjoint (closedBall x r) s := disjoint_ball_infDist.mono_left <| closedBall_subset_ball h theorem dist_le_infDist_add_diam (hs : IsBounded s) (hy : y ∈ s) : dist x y ≀ infDist x s + diam s := by rw [infDist, diam, dist_edist] exact toReal_le_add (edist_le_infEdist_add_ediam hy) (infEdist_ne_top ⟨y, hy⟩) hs.ediam_ne_top variable (s) /-- The minimal distance to a set is Lipschitz in point with constant 1 -/ theorem lipschitz_infDist_pt : LipschitzWith 1 (infDist Β· s) := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set is uniformly continuous in point -/ theorem uniformContinuous_infDist_pt : UniformContinuous (infDist Β· s) := (lipschitz_infDist_pt s).uniformContinuous /-- The minimal distance to a set is continuous in point -/ @[continuity] theorem continuous_infDist_pt : Continuous (infDist Β· s) := (uniformContinuous_infDist_pt s).continuous variable {s} /-- The minimal distances to a set and its closure coincide. -/ theorem infDist_closure : infDist x (closure s) = infDist x s := by simp [infDist, infEdist_closure] /-- If a point belongs to the closure of `s`, then its infimum distance to `s` equals zero. The converse is true provided that `s` is nonempty, see `Metric.mem_closure_iff_infDist_zero`. -/ theorem infDist_zero_of_mem_closure (hx : x ∈ closure s) : infDist x s = 0 := by rw [← infDist_closure] exact infDist_zero_of_mem hx /-- A point belongs to the closure of `s` iff its infimum distance to this set vanishes. -/ theorem mem_closure_iff_infDist_zero (h : s.Nonempty) : x ∈ closure s ↔ infDist x s = 0 := by simp [mem_closure_iff_infEdist_zero, infDist, ENNReal.toReal_eq_zero_iff, infEdist_ne_top h] theorem infDist_pos_iff_not_mem_closure (hs : s.Nonempty) : x βˆ‰ closure s ↔ 0 < infDist x s := (mem_closure_iff_infDist_zero hs).not.trans infDist_nonneg.gt_iff_ne.symm /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes -/ theorem _root_.IsClosed.mem_iff_infDist_zero (h : IsClosed s) (hs : s.Nonempty) : x ∈ s ↔ infDist x s = 0 := by rw [← mem_closure_iff_infDist_zero hs, h.closure_eq] /-- Given a closed set `s`, a point belongs to `s` iff its infimum distance to this set vanishes. -/ theorem _root_.IsClosed.not_mem_iff_infDist_pos (h : IsClosed s) (hs : s.Nonempty) : x βˆ‰ s ↔ 0 < infDist x s := by simp [h.mem_iff_infDist_zero hs, infDist_nonneg.gt_iff_ne] theorem continuousAt_inv_infDist_pt (h : x βˆ‰ closure s) : ContinuousAt (fun x ↦ (infDist x s)⁻¹) x := by rcases s.eq_empty_or_nonempty with (rfl | hs) Β· simp only [infDist_empty, continuousAt_const] Β· refine (continuous_infDist_pt s).continuousAt.invβ‚€ ?_ rwa [Ne, ← mem_closure_iff_infDist_zero hs] /-- The infimum distance is invariant under isometries. -/ theorem infDist_image (hΞ¦ : Isometry Ξ¦) : infDist (Ξ¦ x) (Ξ¦ '' t) = infDist x t := by simp [infDist, infEdist_image hΞ¦] theorem infDist_inter_closedBall_of_mem (h : y ∈ s) : infDist x (s ∩ closedBall x (dist y x)) = infDist x s := by replace h : y ∈ s ∩ closedBall x (dist y x) := ⟨h, mem_closedBall.2 le_rfl⟩ refine le_antisymm ?_ (infDist_le_infDist_of_subset inter_subset_left ⟨y, h⟩) refine not_lt.1 fun hlt => ?_ rcases (infDist_lt_iff ⟨y, h.1⟩).mp hlt with ⟨z, hzs, hz⟩ rcases le_or_lt (dist z x) (dist y x) with hle | hlt Β· exact hz.not_le (infDist_le_dist_of_mem ⟨hzs, hle⟩) Β· rw [dist_comm z, dist_comm y] at hlt exact (hlt.trans hz).not_le (infDist_le_dist_of_mem h) theorem _root_.IsCompact.exists_infDist_eq_dist (h : IsCompact s) (hne : s.Nonempty) (x : Ξ±) : βˆƒ y ∈ s, infDist x s = dist x y := let ⟨y, hys, hy⟩ := h.exists_infEdist_eq_edist hne x ⟨y, hys, by rw [infDist, dist_edist, hy]⟩ theorem _root_.IsClosed.exists_infDist_eq_dist [ProperSpace Ξ±] (h : IsClosed s) (hne : s.Nonempty) (x : Ξ±) : βˆƒ y ∈ s, infDist x s = dist x y := by rcases hne with ⟨z, hz⟩ rw [← infDist_inter_closedBall_of_mem hz] set t := s ∩ closedBall x (dist z x) have htc : IsCompact t := (isCompact_closedBall x (dist z x)).inter_left h have htne : t.Nonempty := ⟨z, hz, mem_closedBall.2 le_rfl⟩ obtain ⟨y, ⟨hys, -⟩, hyd⟩ : βˆƒ y ∈ t, infDist x t = dist x y := htc.exists_infDist_eq_dist htne x exact ⟨y, hys, hyd⟩ theorem exists_mem_closure_infDist_eq_dist [ProperSpace Ξ±] (hne : s.Nonempty) (x : Ξ±) : βˆƒ y ∈ closure s, infDist x s = dist x y := by simpa only [infDist_closure] using isClosed_closure.exists_infDist_eq_dist hne.closure x /-! ### Distance of a point to a set as a function into `ℝβ‰₯0`. -/ /-- The minimal distance of a point to a set as a `ℝβ‰₯0` -/ def infNndist (x : Ξ±) (s : Set Ξ±) : ℝβ‰₯0 := ENNReal.toNNReal (infEdist x s) @[simp] theorem coe_infNndist : (infNndist x s : ℝ) = infDist x s := rfl /-- The minimal distance to a set (as `ℝβ‰₯0`) is Lipschitz in point with constant 1 -/ theorem lipschitz_infNndist_pt (s : Set Ξ±) : LipschitzWith 1 fun x => infNndist x s := LipschitzWith.of_le_add fun _ _ => infDist_le_infDist_add_dist /-- The minimal distance to a set (as `ℝβ‰₯0`) is uniformly continuous in point -/ theorem uniformContinuous_infNndist_pt (s : Set Ξ±) : UniformContinuous fun x => infNndist x s := (lipschitz_infNndist_pt s).uniformContinuous /-- The minimal distance to a set (as `ℝβ‰₯0`) is continuous in point -/ theorem continuous_infNndist_pt (s : Set Ξ±) : Continuous fun x => infNndist x s := (uniformContinuous_infNndist_pt s).continuous /-! ### The Hausdorff distance as a function into `ℝ`. -/ /-- The Hausdorff distance between two sets is the smallest nonnegative `r` such that each set is included in the `r`-neighborhood of the other. If there is no such `r`, it is defined to be `0`, arbitrarily. -/ def hausdorffDist (s t : Set Ξ±) : ℝ := ENNReal.toReal (hausdorffEdist s t) /-- The Hausdorff distance is nonnegative. -/ theorem hausdorffDist_nonneg : 0 ≀ hausdorffDist s t := by simp [hausdorffDist] /-- If two sets are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. -/ theorem hausdorffEdist_ne_top_of_nonempty_of_bounded (hs : s.Nonempty) (ht : t.Nonempty) (bs : IsBounded s) (bt : IsBounded t) : hausdorffEdist s t β‰  ⊀ := by rcases hs with ⟨cs, hcs⟩ rcases ht with ⟨ct, hct⟩ rcases bs.subset_closedBall ct with ⟨rs, hrs⟩ rcases bt.subset_closedBall cs with ⟨rt, hrt⟩ have : hausdorffEdist s t ≀ ENNReal.ofReal (max rs rt) := by apply hausdorffEdist_le_of_mem_edist Β· intro x xs exists ct, hct have : dist x ct ≀ max rs rt := le_trans (hrs xs) (le_max_left _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this Β· intro x xt exists cs, hcs have : dist x cs ≀ max rs rt := le_trans (hrt xt) (le_max_right _ _) rwa [edist_dist, ENNReal.ofReal_le_ofReal_iff] exact le_trans dist_nonneg this exact ne_top_of_le_ne_top ENNReal.ofReal_ne_top this /-- The Hausdorff distance between a set and itself is zero. -/ @[simp] theorem hausdorffDist_self_zero : hausdorffDist s s = 0 := by simp [hausdorffDist] /-- The Hausdorff distances from `s` to `t` and from `t` to `s` coincide. -/ theorem hausdorffDist_comm : hausdorffDist s t = hausdorffDist t s := by simp [hausdorffDist, hausdorffEdist_comm] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝβ‰₯0∞`). -/ @[simp] theorem hausdorffDist_empty : hausdorffDist s βˆ… = 0 := by rcases s.eq_empty_or_nonempty with h | h Β· simp [h] Β· simp [hausdorffDist, hausdorffEdist_empty h] /-- The Hausdorff distance to the empty set vanishes (if you want to have the more reasonable value `∞` instead, use `EMetric.hausdorffEdist`, which takes values in `ℝβ‰₯0∞`). -/ @[simp] theorem hausdorffDist_empty' : hausdorffDist βˆ… s = 0 := by simp [hausdorffDist_comm] /-- Bounding the Hausdorff distance by bounding the distance of any point in each set to the other set -/ theorem hausdorffDist_le_of_infDist {r : ℝ} (hr : 0 ≀ r) (H1 : βˆ€ x ∈ s, infDist x t ≀ r) (H2 : βˆ€ x ∈ t, infDist x s ≀ r) : hausdorffDist s t ≀ r := by rcases s.eq_empty_or_nonempty with hs | hs Β· rwa [hs, hausdorffDist_empty'] rcases t.eq_empty_or_nonempty with ht | ht Β· rwa [ht, hausdorffDist_empty] have : hausdorffEdist s t ≀ ENNReal.ofReal r := by apply hausdorffEdist_le_of_infEdist _ _ Β· simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top ht) hr] using H1 Β· simpa only [infDist, ← ENNReal.le_ofReal_iff_toReal_le (infEdist_ne_top hs) hr] using H2 exact ENNReal.toReal_le_of_le_ofReal hr this /-- Bounding the Hausdorff distance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffDist_le_of_mem_dist {r : ℝ} (hr : 0 ≀ r) (H1 : βˆ€ x ∈ s, βˆƒ y ∈ t, dist x y ≀ r) (H2 : βˆ€ x ∈ t, βˆƒ y ∈ s, dist x y ≀ r) : hausdorffDist s t ≀ r := by apply hausdorffDist_le_of_infDist hr Β· intro x xs rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infDist_le_dist_of_mem yt) hy Β· intro x xt rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infDist_le_dist_of_mem ys) hy /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffDist_le_diam (hs : s.Nonempty) (bs : IsBounded s) (ht : t.Nonempty) (bt : IsBounded t) : hausdorffDist s t ≀ diam (s βˆͺ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffDist_le_of_mem_dist diam_nonneg ?_ ?_ Β· exact fun z hz => ⟨y, yt, dist_le_diam_of_mem (bs.union bt) (subset_union_left hz) (subset_union_right yt)⟩ Β· exact fun z hz => ⟨x, xs, dist_le_diam_of_mem (bs.union bt) (subset_union_right hz) (subset_union_left xs)⟩ /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infDist_le_hausdorffDist_of_mem (hx : x ∈ s) (fin : hausdorffEdist s t β‰  ⊀) : infDist x t ≀ hausdorffDist s t := toReal_mono fin (infEdist_le_hausdorffEdist_of_mem hx) /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt {r : ℝ} (h : x ∈ s) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t β‰  ⊀) : βˆƒ y ∈ t, dist x y < r := by have r0 : 0 < r := lt_of_le_of_lt hausdorffDist_nonneg H have : hausdorffEdist s t < ENNReal.ofReal r := by rwa [hausdorffDist, ← ENNReal.toReal_ofReal (le_of_lt r0), ENNReal.toReal_lt_toReal fin ENNReal.ofReal_ne_top] at H rcases exists_edist_lt_of_hausdorffEdist_lt h this with ⟨y, hy, yr⟩ rw [edist_dist, ENNReal.ofReal_lt_ofReal_iff r0] at yr exact ⟨y, hy, yr⟩ /-- If the Hausdorff distance is `< r`, any point in one of the sets is at distance `< r` of a point in the other set. -/ theorem exists_dist_lt_of_hausdorffDist_lt' {r : ℝ} (h : y ∈ t) (H : hausdorffDist s t < r) (fin : hausdorffEdist s t β‰  ⊀) : βˆƒ x ∈ s, dist x y < r := by rw [hausdorffDist_comm] at H rw [hausdorffEdist_comm] at fin simpa [dist_comm] using exists_dist_lt_of_hausdorffDist_lt h H fin /-- The infimum distance to `s` and `t` are the same, up to the Hausdorff distance between `s` and `t` -/ theorem infDist_le_infDist_add_hausdorffDist (fin : hausdorffEdist s t β‰  ⊀) : infDist x t ≀ infDist x s + hausdorffDist s t := by refine toReal_le_add' infEdist_le_infEdist_add_hausdorffEdist (fun h ↦ ?_) (flip absurd fin) rw [infEdist_eq_top_iff, ← not_nonempty_iff_eq_empty] at h ⊒ rw [hausdorffEdist_comm] at fin exact mt (nonempty_of_hausdorffEdist_ne_top Β· fin) h /-- The Hausdorff distance is invariant under isometries. -/ theorem hausdorffDist_image (h : Isometry Ξ¦) : hausdorffDist (Ξ¦ '' s) (Ξ¦ '' t) = hausdorffDist s t := by simp [hausdorffDist, hausdorffEdist_image h] /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle (fin : hausdorffEdist s t β‰  ⊀) : hausdorffDist s u ≀ hausdorffDist s t + hausdorffDist t u := by refine toReal_le_add' hausdorffEdist_triangle (flip absurd fin) (not_imp_not.1 fun h ↦ ?_) rw [hausdorffEdist_comm] at fin exact ne_top_of_le_ne_top (add_ne_top.2 ⟨fin, h⟩) hausdorffEdist_triangle /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffDist_triangle' (fin : hausdorffEdist t u β‰  ⊀) : hausdorffDist s u ≀ hausdorffDist s t + hausdorffDist t u := by rw [hausdorffEdist_comm] at fin have I : hausdorffDist u s ≀ hausdorffDist u t + hausdorffDist t s := hausdorffDist_triangle fin simpa [add_comm, hausdorffDist_comm] using I /-- The Hausdorff distance between a set and its closure vanishes. -/ @[simp] theorem hausdorffDist_self_closure : hausdorffDist s (closure s) = 0 := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closure₁ : hausdorffDist (closure s) t = hausdorffDist s t := by simp [hausdorffDist] /-- Replacing a set by its closure does not change the Hausdorff distance. -/ @[simp] theorem hausdorffDist_closureβ‚‚ : hausdorffDist s (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- The Hausdorff distances between two sets and their closures coincide. -/ theorem hausdorffDist_closure : hausdorffDist (closure s) (closure t) = hausdorffDist s t := by simp [hausdorffDist] /-- Two sets are at zero Hausdorff distance if and only if they have the same closures. -/ theorem hausdorffDist_zero_iff_closure_eq_closure (fin : hausdorffEdist s t β‰  ⊀) : hausdorffDist s t = 0 ↔ closure s = closure t := by simp [← hausdorffEdist_zero_iff_closure_eq_closure, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] /-- Two closed sets are at zero Hausdorff distance if and only if they coincide. -/ theorem _root_.IsClosed.hausdorffDist_zero_iff_eq (hs : IsClosed s) (ht : IsClosed t) (fin : hausdorffEdist s t β‰  ⊀) : hausdorffDist s t = 0 ↔ s = t := by simp [← hausdorffEdist_zero_iff_eq_of_closed hs ht, hausdorffDist, ENNReal.toReal_eq_zero_iff, fin] end end Metric
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
870
870
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, YaΓ«l Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) βŠ” (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) βŠ“ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a βˆ† b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ assert_not_exists RelIso open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} {Ο€ : ΞΉ β†’ Type*} /-- The symmetric difference operator on a type with `βŠ”` and `\` is `(A \ B) βŠ” (B \ A)`. -/ def symmDiff [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : Ξ± := a \ b βŠ” b \ a /-- The Heyting bi-implication is `(b ⇨ a) βŠ“ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : Ξ± := (b ⇨ a) βŠ“ (a ⇨ b) /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " βˆ† " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : a βˆ† b = a \ b βŠ” b \ a := rfl theorem bihimp_def [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : a ⇔ b = (b ⇨ a) βŠ“ (a ⇨ b) := rfl theorem symmDiff_eq_Xor' (p q : Prop) : p βˆ† q = Xor' p q := rfl @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := iff_iff_implies_and_implies.symm.trans Iff.comm @[simp] theorem Bool.symmDiff_eq_xor : βˆ€ p q : Bool, p βˆ† q = xor p q := by decide section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_symmDiff : toDual (a βˆ† b) = toDual a ⇔ toDual b := rfl @[simp] theorem ofDual_bihimp (a b : Ξ±α΅’α΅ˆ) : ofDual (a ⇔ b) = ofDual a βˆ† ofDual b := rfl theorem symmDiff_comm : a βˆ† b = b βˆ† a := by simp only [symmDiff, sup_comm] instance symmDiff_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· βˆ† Β·) := ⟨symmDiff_comm⟩ @[simp] theorem symmDiff_self : a βˆ† a = βŠ₯ := by rw [symmDiff, sup_idem, sdiff_self] @[simp] theorem symmDiff_bot : a βˆ† βŠ₯ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] @[simp] theorem bot_symmDiff : βŠ₯ βˆ† a = a := by rw [symmDiff_comm, symmDiff_bot] @[simp] theorem symmDiff_eq_bot {a b : Ξ±} : a βˆ† b = βŠ₯ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] theorem symmDiff_of_le {a b : Ξ±} (h : a ≀ b) : a βˆ† b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] theorem symmDiff_of_ge {a b : Ξ±} (h : b ≀ a) : a βˆ† b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] theorem symmDiff_le {a b c : Ξ±} (ha : a ≀ b βŠ” c) (hb : b ≀ a βŠ” c) : a βˆ† b ≀ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb theorem symmDiff_le_iff {a b c : Ξ±} : a βˆ† b ≀ c ↔ a ≀ b βŠ” c ∧ b ≀ a βŠ” c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] @[simp] theorem symmDiff_le_sup {a b : Ξ±} : a βˆ† b ≀ a βŠ” b := sup_le_sup sdiff_le sdiff_le theorem symmDiff_eq_sup_sdiff_inf : a βˆ† b = (a βŠ” b) \ (a βŠ“ b) := by simp [sup_sdiff, symmDiff] theorem Disjoint.symmDiff_eq_sup {a b : Ξ±} (h : Disjoint a b) : a βˆ† b = a βŠ” b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] theorem symmDiff_sdiff : a βˆ† b \ c = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] @[simp] theorem symmDiff_sdiff_inf : a βˆ† b \ (a βŠ“ b) = a βˆ† b := by rw [symmDiff_sdiff] simp [symmDiff] @[simp] theorem symmDiff_sdiff_eq_sup : a βˆ† (b \ a) = a βŠ” b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) βˆ† b = a βŠ” b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] @[simp] theorem symmDiff_sup_inf : a βˆ† b βŠ” a βŠ“ b = a βŠ” b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) Β· rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup Β· rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup @[simp] theorem inf_sup_symmDiff : a βŠ“ b βŠ” a βˆ† b = a βŠ” b := by rw [sup_comm, symmDiff_sup_inf] @[simp] theorem symmDiff_symmDiff_inf : a βˆ† b βˆ† (a βŠ“ b) = a βŠ” b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] @[simp] theorem inf_symmDiff_symmDiff : (a βŠ“ b) βˆ† (a βˆ† b) = a βŠ” b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] theorem symmDiff_triangle : a βˆ† c ≀ a βˆ† b βŠ” b βˆ† c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] theorem le_symmDiff_sup_right (a b : Ξ±) : a ≀ (a βˆ† b) βŠ” b := by convert symmDiff_triangle a b βŠ₯ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : Ξ±) : b ≀ (a βˆ† b) βŠ” a := symmDiff_comm a b β–Έ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a βˆ† toDual b := rfl @[simp] theorem ofDual_symmDiff (a b : Ξ±α΅’α΅ˆ) : ofDual (a βˆ† b) = ofDual a ⇔ ofDual b := rfl theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(Β· ⇔ Β·), inf_comm] instance bihimp_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· ⇔ Β·) := ⟨bihimp_comm⟩ @[simp] theorem bihimp_self : a ⇔ a = ⊀ := by rw [bihimp, inf_idem, himp_self] @[simp] theorem bihimp_top : a ⇔ ⊀ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] @[simp] theorem top_bihimp : ⊀ ⇔ a = a := by rw [bihimp_comm, bihimp_top] @[simp] theorem bihimp_eq_top {a b : Ξ±} : a ⇔ b = ⊀ ↔ a = b := @symmDiff_eq_bot Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_of_le {a b : Ξ±} (h : a ≀ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] theorem bihimp_of_ge {a b : Ξ±} (h : b ≀ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] theorem le_bihimp {a b c : Ξ±} (hb : a βŠ“ b ≀ c) (hc : a βŠ“ c ≀ b) : a ≀ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb theorem le_bihimp_iff {a b c : Ξ±} : a ≀ b ⇔ c ↔ a βŠ“ b ≀ c ∧ a βŠ“ c ≀ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] @[simp] theorem inf_le_bihimp {a b : Ξ±} : a βŠ“ b ≀ a ⇔ b := inf_le_inf le_himp le_himp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a βŠ” b ⇨ a βŠ“ b := by simp [himp_inf_distrib, bihimp] theorem Codisjoint.bihimp_eq_inf {a b : Ξ±} (h : Codisjoint a b) : a ⇔ b = a βŠ“ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] theorem himp_bihimp : a ⇨ b ⇔ c = (a βŠ“ c ⇨ b) βŠ“ (a βŠ“ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] @[simp] theorem sup_himp_bihimp : a βŠ” b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a βŠ“ b := @symmDiff_sdiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a βŠ“ b := @sdiff_symmDiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_inf_sup : a ⇔ b βŠ“ (a βŠ” b) = a βŠ“ b := @symmDiff_sup_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem sup_inf_bihimp : (a βŠ” b) βŠ“ a ⇔ b = a βŠ“ b := @inf_sup_symmDiff Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a βŠ” b) = a βŠ“ b := @symmDiff_symmDiff_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem sup_bihimp_bihimp : (a βŠ” b) ⇔ (a ⇔ b) = a βŠ“ b := @inf_symmDiff_symmDiff Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_triangle : a ⇔ b βŠ“ b ⇔ c ≀ a ⇔ c := @symmDiff_triangle Ξ±α΅’α΅ˆ _ _ _ _ end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra Ξ±] (a : Ξ±) @[simp] theorem symmDiff_top' : a βˆ† ⊀ = οΏ’a := by simp [symmDiff] @[simp] theorem top_symmDiff' : ⊀ βˆ† a = οΏ’a := by simp [symmDiff] @[simp] theorem hnot_symmDiff_self : (οΏ’a) βˆ† a = ⊀ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left @[simp] theorem symmDiff_hnot_self : a βˆ† (οΏ’a) = ⊀ := by rw [symmDiff_comm, hnot_symmDiff_self] theorem IsCompl.symmDiff_eq_top {a b : Ξ±} (h : IsCompl a b) : a βˆ† b = ⊀ := by rw [h.eq_hnot, hnot_symmDiff_self] end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra Ξ±] (a : Ξ±) @[simp] theorem bihimp_bot : a ⇔ βŠ₯ = aᢜ := by simp [bihimp] @[simp] theorem bot_bihimp : βŠ₯ ⇔ a = aᢜ := by simp [bihimp] @[simp] theorem compl_bihimp_self : aᢜ ⇔ a = βŠ₯ := @hnot_symmDiff_self Ξ±α΅’α΅ˆ _ _ @[simp] theorem bihimp_hnot_self : a ⇔ aᢜ = βŠ₯ := @symmDiff_hnot_self Ξ±α΅’α΅ˆ _ _ theorem IsCompl.bihimp_eq_bot {a b : Ξ±} (h : IsCompl a b) : a ⇔ b = βŠ₯ := by rw [h.eq_compl, compl_bihimp_self] end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] (a b c d : Ξ±) @[simp] theorem sup_sdiff_symmDiff : (a βŠ” b) \ a βˆ† b = a βŠ“ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) theorem disjoint_symmDiff_inf : Disjoint (a βˆ† b) (a βŠ“ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left theorem inf_symmDiff_distrib_left : a βŠ“ b βˆ† c = (a βŠ“ b) βˆ† (a βŠ“ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] theorem inf_symmDiff_distrib_right : a βˆ† b βŠ“ c = (a βŠ“ c) βˆ† (b βŠ“ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] theorem sdiff_symmDiff : c \ a βˆ† b = c βŠ“ a βŠ“ b βŠ” c \ a βŠ“ c \ b := by simp only [(Β· βˆ† Β·), sdiff_sdiff_sup_sdiff'] theorem sdiff_symmDiff' : c \ a βˆ† b = c βŠ“ a βŠ“ b βŠ” c \ (a βŠ” b) := by rw [sdiff_symmDiff, sdiff_sup] @[simp] theorem symmDiff_sdiff_left : a βˆ† b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] @[simp] theorem symmDiff_sdiff_right : a βˆ† b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] @[simp] theorem sdiff_symmDiff_left : a \ a βˆ† b = a βŠ“ b := by simp [sdiff_symmDiff] @[simp] theorem sdiff_symmDiff_right : b \ a βˆ† b = a βŠ“ b := by rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left] theorem symmDiff_eq_sup : a βˆ† b = a βŠ” b ↔ Disjoint a b := by refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩ rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h exact h.of_disjoint_inf_of_le le_sup_left @[simp] theorem le_symmDiff_iff_left : a ≀ a βˆ† b ↔ Disjoint a b := by refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm β–Έ le_sup_left⟩ rw [symmDiff_eq_sup_sdiff_inf] at h exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le @[simp] theorem le_symmDiff_iff_right : b ≀ a βˆ† b ↔ Disjoint a b := by rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm] theorem symmDiff_symmDiff_left : a βˆ† b βˆ† c = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := calc a βˆ† b βˆ† c = a βˆ† b \ c βŠ” c \ a βˆ† b := symmDiff_def _ _ _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” (c \ (a βŠ” b) βŠ” c βŠ“ a βŠ“ b) := by { rw [sdiff_symmDiff', sup_comm (c βŠ“ a βŠ“ b), symmDiff_sdiff] } _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := by ac_rfl theorem symmDiff_symmDiff_right : a βˆ† (b βˆ† c) = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := calc a βˆ† (b βˆ† c) = a \ b βˆ† c βŠ” b βˆ† c \ a := symmDiff_def _ _ _ = a \ (b βŠ” c) βŠ” a βŠ“ b βŠ“ c βŠ” (b \ (c βŠ” a) βŠ” c \ (b βŠ” a)) := by { rw [sdiff_symmDiff', sup_comm (a βŠ“ b βŠ“ c), symmDiff_sdiff] } _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := by ac_rfl theorem symmDiff_assoc : a βˆ† b βˆ† c = a βˆ† (b βˆ† c) := by rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right] instance symmDiff_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· βˆ† Β·) := ⟨symmDiff_assoc⟩ theorem symmDiff_left_comm : a βˆ† (b βˆ† c) = b βˆ† (a βˆ† c) := by simp_rw [← symmDiff_assoc, symmDiff_comm] theorem symmDiff_right_comm : a βˆ† b βˆ† c = a βˆ† c βˆ† b := by simp_rw [symmDiff_assoc, symmDiff_comm] theorem symmDiff_symmDiff_symmDiff_comm : a βˆ† b βˆ† (c βˆ† d) = a βˆ† c βˆ† (b βˆ† d) := by simp_rw [symmDiff_assoc, symmDiff_left_comm] @[simp] theorem symmDiff_symmDiff_cancel_left : a βˆ† (a βˆ† b) = b := by simp [← symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_cancel_right : b βˆ† a βˆ† a = b := by simp [symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_self' : a βˆ† b βˆ† a = b := by rw [symmDiff_comm, symmDiff_symmDiff_cancel_left] theorem symmDiff_left_involutive (a : Ξ±) : Involutive (Β· βˆ† a) := symmDiff_symmDiff_cancel_right _ theorem symmDiff_right_involutive (a : Ξ±) : Involutive (a βˆ† Β·) := symmDiff_symmDiff_cancel_left _ theorem symmDiff_left_injective (a : Ξ±) : Injective (Β· βˆ† a) := Function.Involutive.injective (symmDiff_left_involutive a) theorem symmDiff_right_injective (a : Ξ±) : Injective (a βˆ† Β·) := Function.Involutive.injective (symmDiff_right_involutive _) theorem symmDiff_left_surjective (a : Ξ±) : Surjective (Β· βˆ† a) := Function.Involutive.surjective (symmDiff_left_involutive _) theorem symmDiff_right_surjective (a : Ξ±) : Surjective (a βˆ† Β·) := Function.Involutive.surjective (symmDiff_right_involutive _) variable {a b c} @[simp] theorem symmDiff_left_inj : a βˆ† b = c βˆ† b ↔ a = c := (symmDiff_left_injective _).eq_iff @[simp] theorem symmDiff_right_inj : a βˆ† b = a βˆ† c ↔ b = c := (symmDiff_right_injective _).eq_iff @[simp] theorem symmDiff_eq_left : a βˆ† b = a ↔ b = βŠ₯ := calc a βˆ† b = a ↔ a βˆ† b = a βˆ† βŠ₯ := by rw [symmDiff_bot] _ ↔ b = βŠ₯ := by rw [symmDiff_right_inj] @[simp] theorem symmDiff_eq_right : a βˆ† b = b ↔ a = βŠ₯ := by rw [symmDiff_comm, symmDiff_eq_left] protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a βˆ† b) c := by rw [symmDiff_eq_sup_sdiff_inf] exact (ha.sup_left hb).disjoint_sdiff_left protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) : Disjoint a (b βˆ† c) := (ha.symm.symmDiff_left hb.symm).symm theorem symmDiff_eq_iff_sdiff_eq (ha : a ≀ c) : a βˆ† b = c ↔ c \ a = b := by rw [← symmDiff_of_le ha] exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm end GeneralizedBooleanAlgebra section BooleanAlgebra variable [BooleanAlgebra Ξ±] (a b c d : Ξ±) /-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to the `GeneralizedBooleanAlgebra` ones -/ section CogeneralizedBooleanAlgebra @[simp] theorem inf_himp_bihimp : a ⇔ b ⇨ a βŠ“ b = a βŠ” b := @sup_sdiff_symmDiff Ξ±α΅’α΅ˆ _ _ _ theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a βŠ” b) := @disjoint_symmDiff_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b := @symmDiff_sdiff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a := @symmDiff_sdiff_right Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_himp_left : a ⇔ b ⇨ a = a βŠ” b := @sdiff_symmDiff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_himp_right : a ⇔ b ⇨ b = a βŠ” b := @sdiff_symmDiff_right Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_eq_inf : a ⇔ b = a βŠ“ b ↔ Codisjoint a b := @symmDiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_le_iff_left : a ⇔ b ≀ a ↔ Codisjoint a b := @le_symmDiff_iff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_le_iff_right : a ⇔ b ≀ b ↔ Codisjoint a b := @le_symmDiff_iff_right Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) := @symmDiff_assoc Ξ±α΅’α΅ˆ _ _ _ _ instance bihimp_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· ⇔ Β·) := ⟨bihimp_assoc⟩ theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm] theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm] theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by simp_rw [bihimp_assoc, bihimp_left_comm] @[simp] theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc] @[simp] theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc] @[simp] theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left] theorem bihimp_left_involutive (a : Ξ±) : Involutive (Β· ⇔ a) := bihimp_bihimp_cancel_right _ theorem bihimp_right_involutive (a : Ξ±) : Involutive (a ⇔ Β·) := bihimp_bihimp_cancel_left _ theorem bihimp_left_injective (a : Ξ±) : Injective (Β· ⇔ a) := @symmDiff_left_injective Ξ±α΅’α΅ˆ _ _ theorem bihimp_right_injective (a : Ξ±) : Injective (a ⇔ Β·) := @symmDiff_right_injective Ξ±α΅’α΅ˆ _ _ theorem bihimp_left_surjective (a : Ξ±) : Surjective (Β· ⇔ a) := @symmDiff_left_surjective Ξ±α΅’α΅ˆ _ _ theorem bihimp_right_surjective (a : Ξ±) : Surjective (a ⇔ Β·) := @symmDiff_right_surjective Ξ±α΅’α΅ˆ _ _ variable {a b c} @[simp] theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c := (bihimp_left_injective _).eq_iff @[simp] theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c := (bihimp_right_injective _).eq_iff @[simp] theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊀ := @symmDiff_eq_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊀ := @symmDiff_eq_right Ξ±α΅’α΅ˆ _ _ _ protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⇔ b) c := (ha.inf_left hb).mono_left inf_le_bihimp protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) : Codisjoint a (b ⇔ c) := (ha.inf_right hb).mono_right inf_le_bihimp end CogeneralizedBooleanAlgebra theorem symmDiff_eq : a βˆ† b = a βŠ“ bᢜ βŠ” b βŠ“ aᢜ := by simp only [(Β· βˆ† Β·), sdiff_eq] theorem bihimp_eq : a ⇔ b = (a βŠ” bᢜ) βŠ“ (b βŠ” aᢜ) := by simp only [(Β· ⇔ Β·), himp_eq] theorem symmDiff_eq' : a βˆ† b = (a βŠ” b) βŠ“ (aᢜ βŠ” bᢜ) := by rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf] theorem bihimp_eq' : a ⇔ b = a βŠ“ b βŠ” aᢜ βŠ“ bᢜ := @symmDiff_eq' Ξ±α΅’α΅ˆ _ _ _ theorem symmDiff_top : a βˆ† ⊀ = aᢜ := symmDiff_top' _ theorem top_symmDiff : ⊀ βˆ† a = aᢜ := top_symmDiff' _ @[simp] theorem compl_symmDiff : (a βˆ† b)ᢜ = a ⇔ b := by simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm] @[simp] theorem compl_bihimp : (a ⇔ b)ᢜ = a βˆ† b := @compl_symmDiff Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem compl_symmDiff_compl : aᢜ βˆ† bᢜ = a βˆ† b := (sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq] @[simp] theorem compl_bihimp_compl : aᢜ ⇔ bᢜ = a ⇔ b := @compl_symmDiff_compl Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem symmDiff_eq_top : a βˆ† b = ⊀ ↔ IsCompl a b := by rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff, codisjoint_iff, and_comm] @[simp] theorem bihimp_eq_bot : a ⇔ b = βŠ₯ ↔ IsCompl a b := by rw [bihimp_eq', ← compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff, codisjoint_iff] @[simp] theorem compl_symmDiff_self : aᢜ βˆ† a = ⊀ := hnot_symmDiff_self _ @[simp] theorem symmDiff_compl_self : a βˆ† aᢜ = ⊀ := symmDiff_hnot_self _ theorem symmDiff_symmDiff_right' : a βˆ† (b βˆ† c) = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” aᢜ βŠ“ b βŠ“ cᢜ βŠ” aᢜ βŠ“ bᢜ βŠ“ c := calc a βˆ† (b βˆ† c) = a βŠ“ (b βŠ“ c βŠ” bᢜ βŠ“ cᢜ) βŠ” (b βŠ“ cᢜ βŠ” c βŠ“ bᢜ) βŠ“ aᢜ := by { rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] } _ = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” b βŠ“ cᢜ βŠ“ aᢜ βŠ” c βŠ“ bᢜ βŠ“ aᢜ := by { rw [inf_sup_left, inf_sup_right, ← sup_assoc, ← inf_assoc, ← inf_assoc] }
_ = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” aᢜ βŠ“ b βŠ“ cᢜ βŠ” aᢜ βŠ“ bᢜ βŠ“ c := (by congr 1
Mathlib/Order/SymmDiff.lean
642
643
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Yury Kudryashov, Kim Morrison -/ import Mathlib.Algebra.Algebra.Equiv import Mathlib.Algebra.Algebra.NonUnitalHom import Mathlib.Algebra.Module.BigOperators import Mathlib.Algebra.MonoidAlgebra.MapDomain import Mathlib.Data.Finsupp.SMul import Mathlib.LinearAlgebra.Finsupp.SumProd /-! # Monoid algebras -/ noncomputable section open Finset open Finsupp hiding single mapDomain universe u₁ uβ‚‚ u₃ uβ‚„ variable (k : Type u₁) (G : Type uβ‚‚) (H : Type*) {R : Type*} /-! ### Multiplicative monoids -/ namespace MonoidAlgebra variable {k G} /-! #### Non-unital, non-associative algebra structure -/ section NonUnitalNonAssocAlgebra variable (k) [Semiring k] [DistribSMul R k] [Mul G] variable {A : Type u₃} [NonUnitalNonAssocSemiring A] /-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ Ο†β‚‚ : MonoidAlgebra k G →ₙₐ[k] A} (h : βˆ€ x, φ₁ (single x 1) = Ο†β‚‚ (single x 1)) : φ₁ = Ο†β‚‚ := NonUnitalAlgHom.to_distribMulActionHom_injective <| Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a) /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ Ο†β‚‚ : MonoidAlgebra k G →ₙₐ[k] A} (h : φ₁.toMulHom.comp (ofMagma k G) = Ο†β‚‚.toMulHom.comp (ofMagma k G)) : φ₁ = Ο†β‚‚ := nonUnitalAlgHom_ext k <| DFunLike.congr_fun h /-- The functor `G ↦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps apply_apply symm_apply] def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] : (G β†’β‚™* A) ≃ (MonoidAlgebra k G →ₙₐ[k] A) where toFun f := { liftAddHom fun x => (smulAddHom k A).flip (f x) with toFun := fun a => a.sum fun m t => t β€’ f m map_smul' := fun t' a => by rw [Finsupp.smul_sum, sum_smul_index'] Β· simp_rw [smul_assoc, MonoidHom.id_apply] Β· intro m exact zero_smul k (f m) map_mul' := fun a₁ aβ‚‚ => by let g : G β†’ k β†’ A := fun m t => t β€’ f m have h₁ : βˆ€ m, g m 0 = 0 := by intro m exact zero_smul k (f m) have hβ‚‚ : βˆ€ (m) (t₁ tβ‚‚ : k), g m (t₁ + tβ‚‚) = g m t₁ + g m tβ‚‚ := by intros rw [← add_smul] -- Porting note: `reducible` cannot be `local` so proof gets long. simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul_comm, ← f.map_mul, mul_def, sum_comm aβ‚‚ a₁] rw [sum_sum_index h₁ hβ‚‚]; congr; ext rw [sum_sum_index h₁ hβ‚‚]; congr; ext rw [sum_single_index (h₁ _)] } invFun F := F.toMulHom.comp (ofMagma k G) left_inv f := by ext m simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe, sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp, NonUnitalAlgHom.coe_to_mulHom] right_inv F := by ext m simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe, sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp, NonUnitalAlgHom.coe_to_mulHom] end NonUnitalNonAssocAlgebra /-! #### Algebra structure -/ section Algebra /-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`. In particular this provides the instance `Algebra k (MonoidAlgebra k G)`. -/ instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : Algebra k (MonoidAlgebra A G) where algebraMap := singleOneRingHom.comp (algebraMap k A) smul_def' := fun r a => by ext rw [Finsupp.coe_smul] simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply] commutes' := fun r f => by refine Finsupp.ext fun _ => ?_ simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes] /-- `Finsupp.single 1` as an `AlgHom` -/ @[simps! apply] def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : A →ₐ[k] MonoidAlgebra A G := { singleOneRingHom with commutes' := fun r => by ext simp rfl } @[simp] theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : ⇑(algebraMap k (MonoidAlgebra A G)) = single 1 ∘ algebraMap k A := rfl theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) : single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] (a : G) (b : k) : single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp instance isLocalHom_singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] : IsLocalHom (singleOneAlgHom : A →ₐ[k] MonoidAlgebra A G) where map_nonunit := isLocalHom_singleOneRingHom.map_nonunit instance isLocalHom_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] [IsLocalHom (algebraMap k A)] : IsLocalHom (algebraMap k (MonoidAlgebra A G)) where map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleOneAlgHom (k := k).map_nonunit _ hx end Algebra section lift variable [CommSemiring k] [Monoid G] [Monoid H] variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B] /-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/ def liftNCAlgHom (f : A →ₐ[k] B) (g : G β†’* B) (h_comm : βˆ€ x y, Commute (f x) (g y)) : MonoidAlgebra A G →ₐ[k] B := { liftNCRingHom (f : A β†’+* B) g h_comm with commutes' := by simp [liftNCRingHom] } /-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its values on the functions `single a 1`. -/ theorem algHom_ext ⦃φ₁ Ο†β‚‚ : MonoidAlgebra k G →ₐ[k] A⦄ (h : βˆ€ x, φ₁ (single x 1) = Ο†β‚‚ (single x 1)) : φ₁ = Ο†β‚‚ := AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a) -- The priority must be `high`. /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem algHom_ext' ⦃φ₁ Ο†β‚‚ : MonoidAlgebra k G →ₐ[k] A⦄ (h : (φ₁ : MonoidAlgebra k G β†’* A).comp (of k G) = (Ο†β‚‚ : MonoidAlgebra k G β†’* A).comp (of k G)) : φ₁ = Ο†β‚‚ := algHom_ext <| DFunLike.congr_fun h variable (k G A) /-- Any monoid homomorphism `G β†’* A` can be lifted to an algebra homomorphism `MonoidAlgebra k G →ₐ[k] A`. -/ def lift : (G β†’* A) ≃ (MonoidAlgebra k G →ₐ[k] A) where invFun f := (f : MonoidAlgebra k G β†’* A).comp (of k G) toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ left_inv f := by ext simp [liftNCAlgHom, liftNCRingHom] right_inv F := by ext simp [liftNCAlgHom, liftNCRingHom] variable {k G H A} theorem lift_apply' (F : G β†’* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => algebraMap k A b * F a := rfl theorem lift_apply (F : G β†’* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => b β€’ F a := by simp only [lift_apply', Algebra.smul_def] theorem lift_def (F : G β†’* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k β†’+* A) : k β†’+ A) F := rfl @[simp] theorem lift_symm_apply (F : MonoidAlgebra k G →ₐ[k] A) (x : G) : (lift k G A).symm F x = F (single x 1) := rfl @[simp] theorem lift_single (F : G β†’* A) (a b) : lift k G A F (single a b) = b β€’ F a := by rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe] theorem lift_of (F : G β†’* A) (x) : lift k G A F (of k G x) = F x := by simp theorem lift_unique' (F : MonoidAlgebra k G →ₐ[k] A) : F = lift k G A ((F : MonoidAlgebra k G β†’* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by its values on `F (single a 1)`. -/ theorem lift_unique (F : MonoidAlgebra k G →ₐ[k] A) (f : MonoidAlgebra k G) : F f = f.sum fun a b => b β€’ F (single a 1) := by conv_lhs => rw [lift_unique' F] simp [lift_apply] /-- If `f : G β†’ H` is a homomorphism between two magmas, then `Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/ @[simps apply] def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) : MonoidAlgebra A G →ₙₐ[k] MonoidAlgebra A H := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G β†’+ MonoidAlgebra A H) with map_mul' := fun x y => mapDomain_mul f x y map_smul' := fun r x => mapDomain_smul r x } variable (A) in theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) : mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by simp only [coe_algebraMap, mapDomain_single, map_one, (Β· ∘ Β·)] /-- If `f : G β†’ H` is a multiplicative homomorphism between two monoids, then `Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/ @[simps!] def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*} [Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) : MonoidAlgebra A G →ₐ[k] MonoidAlgebra A H := { mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f } @[simp] lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] : mapDomainAlgHom k A (MonoidHom.id G) = AlgHom.id k (MonoidAlgebra A G) := by ext; simp [MonoidHom.id, ← Function.id_def] @[simp] lemma mapDomainAlgHom_comp (k A) {G₁ Gβ‚‚ G₃} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G₁] [Monoid Gβ‚‚] [Monoid G₃] (f : G₁ β†’* Gβ‚‚) (g : Gβ‚‚ β†’* G₃) : mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by ext; simp [mapDomain_comp] variable (k A) /-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then `MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/ def domCongr (e : G ≃* H) : MonoidAlgebra A G ≃ₐ[k] MonoidAlgebra A H := AlgEquiv.ofLinearEquiv (Finsupp.domLCongr e : (G β†’β‚€ A) ≃ₗ[k] (H β†’β‚€ A)) ((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e) (fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <| congr_argβ‚‚ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm) theorem domCongr_toAlgHom (e : G ≃* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e := AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _ @[simp] theorem domCongr_apply (e : G ≃* H) (f : MonoidAlgebra A G) (h : H) : domCongr k A e f h = f (e.symm h) := rfl @[simp] theorem domCongr_support (e : G ≃* H) (f : MonoidAlgebra A G) : (domCongr k A e f).support = f.support.map e := rfl @[simp] theorem domCongr_single (e : G ≃* H) (g : G) (a : A) : domCongr k A e (single g a) = single (e g) a := Finsupp.equivMapDomain_single _ _ _ @[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl := AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl @[simp] theorem domCongr_symm (e : G ≃* H) : (domCongr k A e).symm = domCongr k A e.symm := rfl end lift section variable (k) /-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/ def GroupSMul.linearMap [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) : V β†’β‚—[k] V where toFun v := single g (1 : k) β€’ v map_add' x y := smul_add (single g (1 : k)) x y map_smul' _c _x := smul_algebra_smul_comm _ _ _ @[simp] theorem GroupSMul.linearMap_apply [Monoid G] [CommSemiring k] (V : Type u₃) [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] (g : G) (v : V) : (GroupSMul.linearMap k V g) v = single g (1 : k) β€’ v := rfl section variable {k} variable [Monoid G] [CommSemiring k] {V : Type u₃} {W : Type uβ‚„} [AddCommMonoid V] [Module k V] [Module (MonoidAlgebra k G) V] [IsScalarTower k (MonoidAlgebra k G) V] [AddCommMonoid W] [Module k W] [Module (MonoidAlgebra k G) W] [IsScalarTower k (MonoidAlgebra k G) W] (f : V β†’β‚—[k] W) /-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/ def equivariantOfLinearOfComm (h : βˆ€ (g : G) (v : V), f (single g (1 : k) β€’ v) = single g (1 : k) β€’ f v) : V β†’β‚—[MonoidAlgebra k G] W where toFun := f map_add' v v' := by simp map_smul' c v := by refine Finsupp.induction c ?_ ?_ Β· simp Β· intro g r c' _nm _nz w dsimp at * simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebraMap_mul_of, ← smul_smul] rw [algebraMap_smul (MonoidAlgebra k G) r, algebraMap_smul (MonoidAlgebra k G) r, f.map_smul, of_apply, h g v] variable (h : βˆ€ (g : G) (v : V), f (single g (1 : k) β€’ v) = single g (1 : k) β€’ f v) @[simp] theorem equivariantOfLinearOfComm_apply (v : V) : (equivariantOfLinearOfComm f h) v = f v := rfl end end end MonoidAlgebra namespace AddMonoidAlgebra variable {k G H} /-! #### Non-unital, non-associative algebra structure -/ section NonUnitalNonAssocAlgebra variable (k) [Semiring k] [DistribSMul R k] [Add G] variable {A : Type u₃} [NonUnitalNonAssocSemiring A] /-- A non_unital `k`-algebra homomorphism from `k[G]` is uniquely defined by its values on the functions `single a 1`. -/ theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ Ο†β‚‚ : k[G] →ₙₐ[k] A} (h : βˆ€ x, φ₁ (single x 1) = Ο†β‚‚ (single x 1)) : φ₁ = Ο†β‚‚ := @MonoidAlgebra.nonUnitalAlgHom_ext k (Multiplicative G) _ _ _ _ _ φ₁ Ο†β‚‚ h /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ Ο†β‚‚ : k[G] →ₙₐ[k] A} (h : φ₁.toMulHom.comp (ofMagma k G) = Ο†β‚‚.toMulHom.comp (ofMagma k G)) : φ₁ = Ο†β‚‚ := @MonoidAlgebra.nonUnitalAlgHom_ext' k (Multiplicative G) _ _ _ _ _ φ₁ Ο†β‚‚ h /-- The functor `G ↦ k[G]`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps apply_apply symm_apply] def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] : (Multiplicative G β†’β‚™* A) ≃ (k[G] →ₙₐ[k] A) := { (MonoidAlgebra.liftMagma k : (Multiplicative G β†’β‚™* A) ≃ (_ →ₙₐ[k] A)) with toFun := fun f => { (MonoidAlgebra.liftMagma k f :) with toFun := fun a => sum a fun m t => t β€’ f (Multiplicative.ofAdd m) } invFun := fun F => F.toMulHom.comp (ofMagma k G) } end NonUnitalNonAssocAlgebra /-! #### Algebra structure -/ section Algebra /-- The instance `Algebra R k[G]` whenever we have `Algebra R k`. In particular this provides the instance `Algebra k k[G]`. -/ instance algebra [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : Algebra R k[G] where algebraMap := singleZeroRingHom.comp (algebraMap R k) smul_def' := fun r a => by ext rw [Finsupp.coe_smul] simp [single_zero_mul_apply, Algebra.smul_def, Pi.smul_apply] commutes' := fun r f => by refine Finsupp.ext fun _ => ?_ simp [single_zero_mul_apply, mul_single_zero_apply, Algebra.commutes] /-- `Finsupp.single 0` as an `AlgHom` -/ @[simps! apply] def singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : k →ₐ[R] k[G] := { singleZeroRingHom with commutes' := fun r => by ext simp rfl } @[simp] theorem coe_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : (algebraMap R k[G] : R β†’ k[G]) = single 0 ∘ algebraMap R k := rfl instance isLocalHom_singleZeroAlgHom [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] : IsLocalHom (singleZeroAlgHom : k →ₐ[R] k[G]) where map_nonunit := isLocalHom_singleZeroRingHom.map_nonunit instance isLocalHom_algebraMap [CommSemiring R] [Semiring k] [Algebra R k] [AddMonoid G] [IsLocalHom (algebraMap R k)] : IsLocalHom (algebraMap R k[G]) where map_nonunit _ hx := .of_map _ _ <| isLocalHom_singleZeroAlgHom (R := R).map_nonunit _ hx end Algebra section lift variable [CommSemiring k] [AddMonoid G] variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B] /-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/ def liftNCAlgHom (f : A →ₐ[k] B) (g : Multiplicative G β†’* B) (h_comm : βˆ€ x y, Commute (f x) (g y)) : A[G] →ₐ[k] B := { liftNCRingHom (f : A β†’+* B) g h_comm with commutes' := by simp [liftNCRingHom] } /-- A `k`-algebra homomorphism from `k[G]` is uniquely defined by its values on the functions `single a 1`. -/ theorem algHom_ext ⦃φ₁ Ο†β‚‚ : k[G] →ₐ[k] A⦄ (h : βˆ€ x, φ₁ (single x 1) = Ο†β‚‚ (single x 1)) : φ₁ = Ο†β‚‚ := @MonoidAlgebra.algHom_ext k (Multiplicative G) _ _ _ _ _ _ _ h /-- See note [partially-applied ext lemmas]. -/ @[ext high] theorem algHom_ext' ⦃φ₁ Ο†β‚‚ : k[G] →ₐ[k] A⦄ (h : (φ₁ : k[G] β†’* A).comp (of k G) = (Ο†β‚‚ : k[G] β†’* A).comp (of k G)) : φ₁ = Ο†β‚‚ := algHom_ext <| DFunLike.congr_fun h variable (k G A) /-- Any monoid homomorphism `G β†’* A` can be lifted to an algebra homomorphism `k[G] →ₐ[k] A`. -/ def lift : (Multiplicative G β†’* A) ≃ (k[G] →ₐ[k] A) := { @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ with invFun := fun f => (f : k[G] β†’* A).comp (of k G) toFun := fun F => { @MonoidAlgebra.lift k (Multiplicative G) _ _ A _ _ F with toFun := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _ } } variable {k G A} theorem lift_apply' (F : Multiplicative G β†’* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => algebraMap k A b * F (Multiplicative.ofAdd a) := rfl theorem lift_apply (F : Multiplicative G β†’* A) (f : MonoidAlgebra k G) : lift k G A F f = f.sum fun a b => b β€’ F (Multiplicative.ofAdd a) := by simp only [lift_apply', Algebra.smul_def] theorem lift_def (F : Multiplicative G β†’* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k β†’+* A) : k β†’+ A) F := rfl @[simp] theorem lift_symm_apply (F : k[G] →ₐ[k] A) (x : Multiplicative G) : (lift k G A).symm F x = F (single x.toAdd 1) := rfl theorem lift_of (F : Multiplicative G β†’* A) (x : Multiplicative G) : lift k G A F (of k G x) = F x := MonoidAlgebra.lift_of F x @[simp] theorem lift_single (F : Multiplicative G β†’* A) (a b) : lift k G A F (single a b) = b β€’ F (Multiplicative.ofAdd a) := MonoidAlgebra.lift_single F (.ofAdd a) b lemma lift_of' (F : Multiplicative G β†’* A) (x : G) : lift k G A F (of' k G x) = F (Multiplicative.ofAdd x) := lift_of F x theorem lift_unique' (F : k[G] →ₐ[k] A) : F = lift k G A ((F : k[G] β†’* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by its values on `F (single a 1)`. -/ theorem lift_unique (F : k[G] →ₐ[k] A) (f : MonoidAlgebra k G) : F f = f.sum fun a b => b β€’ F (single a 1) := by conv_lhs => rw [lift_unique' F] simp [lift_apply] theorem algHom_ext_iff {φ₁ Ο†β‚‚ : k[G] →ₐ[k] A} : (βˆ€ x, φ₁ (Finsupp.single x 1) = Ο†β‚‚ (Finsupp.single x 1)) ↔ φ₁ = Ο†β‚‚ := ⟨fun h => algHom_ext h, by rintro rfl _; rfl⟩ end lift theorem mapDomain_algebraMap (A : Type*) {H F : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) (r : k) : mapDomain f (algebraMap k A[G] r) = algebraMap k A[H] r := by simp only [Function.comp_apply, mapDomain_single, AddMonoidAlgebra.coe_algebraMap, map_zero] /-- If `f : G β†’ H` is a homomorphism between two additive magmas, then `Finsupp.mapDomain f` is a non-unital algebra homomorphism between their additive magma algebras. -/ @[simps apply] def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {G H F : Type*} [Add G] [Add H] [FunLike F G H] [AddHomClass F G H] (f : F) : A[G] →ₙₐ[k] A[H] := { (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G β†’+ MonoidAlgebra A H) with map_mul' := fun x y => mapDomain_mul f x y map_smul' := fun r x => mapDomain_smul r x } /-- If `f : G β†’ H` is an additive homomorphism between two additive monoids, then `Finsupp.mapDomain f` is an algebra homomorphism between their add monoid algebras. -/ @[simps!] def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] {H F : Type*} [AddMonoid H] [FunLike F G H] [AddMonoidHomClass F G H] (f : F) : A[G] →ₐ[k] A[H] := { mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f } @[simp] lemma mapDomainAlgHom_id (k A) [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G] : mapDomainAlgHom k A (AddMonoidHom.id G) = AlgHom.id k (AddMonoidAlgebra A G) := by ext; simp [AddMonoidHom.id, ← Function.id_def] @[simp] lemma mapDomainAlgHom_comp (k A) {G₁ Gβ‚‚ G₃} [CommSemiring k] [Semiring A] [Algebra k A] [AddMonoid G₁] [AddMonoid Gβ‚‚] [AddMonoid G₃] (f : G₁ β†’+ Gβ‚‚) (g : Gβ‚‚ β†’+ G₃) : mapDomainAlgHom k A (g.comp f) = (mapDomainAlgHom k A g).comp (mapDomainAlgHom k A f) := by ext; simp [mapDomain_comp] variable (k A) variable [CommSemiring k] [AddMonoid G] [AddMonoid H] [Semiring A] [Algebra k A] /-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then `AddMonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/ def domCongr (e : G ≃+ H) : A[G] ≃ₐ[k] A[H] := AlgEquiv.ofLinearEquiv (Finsupp.domLCongr e : (G β†’β‚€ A) ≃ₗ[k] (H β†’β‚€ A)) ((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e) (fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <| congr_argβ‚‚ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm) theorem domCongr_toAlgHom (e : G ≃+ H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e := AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _ @[simp] theorem domCongr_apply (e : G ≃+ H) (f : MonoidAlgebra A G) (h : H) : domCongr k A e f h = f (e.symm h) := rfl @[simp] theorem domCongr_support (e : G ≃+ H) (f : MonoidAlgebra A G) : (domCongr k A e f).support = f.support.map e := rfl @[simp] theorem domCongr_single (e : G ≃+ H) (g : G) (a : A) : domCongr k A e (single g a) = single (e g) a := Finsupp.equivMapDomain_single _ _ _ @[simp] theorem domCongr_refl : domCongr k A (AddEquiv.refl G) = AlgEquiv.refl := AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl @[simp] theorem domCongr_symm (e : G ≃+ H) : (domCongr k A e).symm = domCongr k A e.symm := rfl end AddMonoidAlgebra variable [CommSemiring R] /-- The algebra equivalence between `AddMonoidAlgebra` and `MonoidAlgebra` in terms of `Multiplicative`. -/ def AddMonoidAlgebra.toMultiplicativeAlgEquiv [Semiring k] [Algebra R k] [AddMonoid G] : AddMonoidAlgebra k G ≃ₐ[R] MonoidAlgebra k (Multiplicative G) := { AddMonoidAlgebra.toMultiplicative k G with commutes' := fun r => by simp [AddMonoidAlgebra.toMultiplicative] } /-- The algebra equivalence between `MonoidAlgebra` and `AddMonoidAlgebra` in terms of `Additive`. -/ def MonoidAlgebra.toAdditiveAlgEquiv [Semiring k] [Algebra R k] [Monoid G] : MonoidAlgebra k G ≃ₐ[R] AddMonoidAlgebra k (Additive G) := { MonoidAlgebra.toAdditive k G with commutes' := fun r => by simp [MonoidAlgebra.toAdditive] }
Mathlib/Algebra/MonoidAlgebra/Basic.lean
986
990
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes HΓΆlzl -/ import Mathlib.Algebra.Order.Group.Unbundled.Basic import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Sub.Defs import Mathlib.Util.AssertExists /-! # Ordered groups This file defines bundled ordered groups and develops a few basic results. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. -/ /- `NeZero` theory should not be needed at this point in the ordered algebraic hierarchy. -/ assert_not_imported Mathlib.Algebra.NeZero open Function universe u variable {Ξ± : Type u} /-- An ordered additive commutative group is an additive commutative group with a partial order in which addition is strictly monotone. -/ @[deprecated "Use `[AddCommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedAddMonoid Ξ±]` instead." (since := "2025-04-10")] structure OrderedAddCommGroup (Ξ± : Type u) extends AddCommGroup Ξ±, PartialOrder Ξ± where /-- Addition is monotone in an ordered additive commutative group. -/ protected add_le_add_left : βˆ€ a b : Ξ±, a ≀ b β†’ βˆ€ c : Ξ±, c + a ≀ c + b set_option linter.existingAttributeWarning false in /-- An ordered commutative group is a commutative group with a partial order in which multiplication is strictly monotone. -/ @[to_additive, deprecated "Use `[CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±]` instead." (since := "2025-04-10")] structure OrderedCommGroup (Ξ± : Type u) extends CommGroup Ξ±, PartialOrder Ξ± where /-- Multiplication is monotone in an ordered commutative group. -/ protected mul_le_mul_left : βˆ€ a b : Ξ±, a ≀ b β†’ βˆ€ c : Ξ±, c * a ≀ c * b alias OrderedCommGroup.mul_lt_mul_left' := mul_lt_mul_left' attribute [to_additive OrderedAddCommGroup.add_lt_add_left] OrderedCommGroup.mul_lt_mul_left' alias OrderedCommGroup.le_of_mul_le_mul_left := le_of_mul_le_mul_left' attribute [to_additive] OrderedCommGroup.le_of_mul_le_mul_left alias OrderedCommGroup.lt_of_mul_lt_mul_left := lt_of_mul_lt_mul_left' attribute [to_additive] OrderedCommGroup.lt_of_mul_lt_mul_left -- See note [lower instance priority] @[to_additive IsOrderedAddMonoid.toIsOrderedCancelAddMonoid] instance (priority := 100) IsOrderedMonoid.toIsOrderedCancelMonoid [CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±] : IsOrderedCancelMonoid Ξ± where le_of_mul_le_mul_left a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ le_of_mul_le_mul_right a b c bc := by simpa using mul_le_mul_left' bc a⁻¹ /-! ### Linearly ordered commutative groups -/ set_option linter.deprecated false in /-- A linearly ordered additive commutative group is an additive commutative group with a linear order in which addition is monotone. -/ @[deprecated "Use `[AddCommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedAddMonoid Ξ±]` instead." (since := "2025-04-10")] structure LinearOrderedAddCommGroup (Ξ± : Type u) extends OrderedAddCommGroup Ξ±, LinearOrder Ξ± set_option linter.existingAttributeWarning false in set_option linter.deprecated false in /-- A linearly ordered commutative group is a commutative group with a linear order in which multiplication is monotone. -/ @[to_additive, deprecated "Use `[CommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedMonoid Ξ±]` instead." (since := "2025-04-10")] structure LinearOrderedCommGroup (Ξ± : Type u) extends OrderedCommGroup Ξ±, LinearOrder Ξ± attribute [nolint docBlame] LinearOrderedCommGroup.toLinearOrder LinearOrderedAddCommGroup.toLinearOrder section LinearOrderedCommGroup variable [CommGroup Ξ±] [LinearOrder Ξ±] [IsOrderedMonoid Ξ±] {a : Ξ±} @[to_additive LinearOrderedAddCommGroup.add_lt_add_left] theorem LinearOrderedCommGroup.mul_lt_mul_left' (a b : Ξ±) (h : a < b) (c : Ξ±) : c * a < c * b := _root_.mul_lt_mul_left' h c @[to_additive eq_zero_of_neg_eq] theorem eq_one_of_inv_eq' (h : a⁻¹ = a) : a = 1 := match lt_trichotomy a 1 with | Or.inl h₁ => have : 1 < a := h β–Έ one_lt_inv_of_inv h₁ absurd h₁ this.asymm | Or.inr (Or.inl h₁) => h₁ | Or.inr (Or.inr h₁) => have : a < 1 := h β–Έ inv_lt_one'.mpr h₁ absurd h₁ this.asymm @[to_additive exists_zero_lt] theorem exists_one_lt' [Nontrivial Ξ±] : βˆƒ a : Ξ±, 1 < a := by obtain ⟨y, hy⟩ := Decidable.exists_ne (1 : Ξ±) obtain h|h := hy.lt_or_lt Β· exact ⟨y⁻¹, one_lt_inv'.mpr h⟩ Β· exact ⟨y, h⟩ -- see Note [lower instance priority] @[to_additive] instance (priority := 100) LinearOrderedCommGroup.to_noMaxOrder [Nontrivial Ξ±] : NoMaxOrder Ξ± := ⟨by obtain ⟨y, hy⟩ : βˆƒ a : Ξ±, 1 < a := exists_one_lt' exact fun a => ⟨a * y, lt_mul_of_one_lt_right' a hy⟩⟩ -- see Note [lower instance priority] @[to_additive] instance (priority := 100) LinearOrderedCommGroup.to_noMinOrder [Nontrivial Ξ±] : NoMinOrder Ξ± := ⟨by obtain ⟨y, hy⟩ : βˆƒ a : Ξ±, 1 < a := exists_one_lt' exact fun a => ⟨a / y, (div_lt_self_iff a).mpr hy⟩⟩ @[to_additive (attr := simp)] theorem inv_le_self_iff : a⁻¹ ≀ a ↔ 1 ≀ a := by simp [inv_le_iff_one_le_mul'] @[to_additive (attr := simp)] theorem inv_lt_self_iff : a⁻¹ < a ↔ 1 < a := by simp [inv_lt_iff_one_lt_mul] @[to_additive (attr := simp)] theorem le_inv_self_iff : a ≀ a⁻¹ ↔ a ≀ 1 := by simp [← not_iff_not] @[to_additive (attr := simp)] theorem lt_inv_self_iff : a < a⁻¹ ↔ a < 1 := by simp [← not_iff_not] end LinearOrderedCommGroup section NormNumLemmas /- The following lemmas are stated so that the `norm_num` tactic can use them with the expected signatures. -/ variable [CommGroup Ξ±] [PartialOrder Ξ±] [IsOrderedMonoid Ξ±] {a b : Ξ±} @[to_additive (attr := gcongr) neg_le_neg] theorem inv_le_inv' : a ≀ b β†’ b⁻¹ ≀ a⁻¹ := inv_le_inv_iff.mpr @[to_additive (attr := gcongr) neg_lt_neg] theorem inv_lt_inv' : a < b β†’ b⁻¹ < a⁻¹ := inv_lt_inv_iff.mpr -- The additive version is also a `linarith` lemma. @[to_additive] theorem inv_lt_one_of_one_lt : 1 < a β†’ a⁻¹ < 1 := inv_lt_one_iff_one_lt.mpr -- The additive version is also a `linarith` lemma. @[to_additive] theorem inv_le_one_of_one_le : 1 ≀ a β†’ a⁻¹ ≀ 1 := inv_le_one'.mpr @[to_additive neg_nonneg_of_nonpos] theorem one_le_inv_of_le_one : a ≀ 1 β†’ 1 ≀ a⁻¹ := one_le_inv'.mpr end NormNumLemmas
Mathlib/Algebra/Order/Group/Defs.lean
215
217
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel -/ import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.MetricSpace.Pseudo.Defs import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Products of pseudometric spaces and other constructions This file constructs the supremum distance on binary products of pseudometric spaces and provides instances for type synonyms. -/ open Bornology Filter Metric Set Topology open scoped NNReal variable {Ξ± Ξ² : Type*} [PseudoMetricSpace Ξ±] /-- Pseudometric space structure pulled back by a function. -/ abbrev PseudoMetricSpace.induced {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (m : PseudoMetricSpace Ξ²) : PseudoMetricSpace Ξ± where dist x y := dist (f x) (f y) dist_self _ := dist_self _ dist_comm _ _ := dist_comm _ _ dist_triangle _ _ _ := dist_triangle _ _ _ edist x y := edist (f x) (f y) edist_dist _ _ := edist_dist _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf toBornology := Bornology.induced f cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by simp only [← isBounded_def, isBounded_iff, forall_mem_image, mem_setOf] /-- Pull back a pseudometric space structure by an inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ def Topology.IsInducing.comapPseudoMetricSpace {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±] [m : PseudoMetricSpace Ξ²] {f : Ξ± β†’ Ξ²} (hf : IsInducing f) : PseudoMetricSpace Ξ± := .replaceTopology (.induced f m) hf.eq_induced @[deprecated (since := "2024-10-28")] alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace /-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ def IsUniformInducing.comapPseudoMetricSpace {Ξ± Ξ²} [UniformSpace Ξ±] [m : PseudoMetricSpace Ξ²] (f : Ξ± β†’ Ξ²) (h : IsUniformInducing f) : PseudoMetricSpace Ξ± := .replaceUniformity (.induced f m) h.comap_uniformity.symm instance Subtype.pseudoMetricSpace {p : Ξ± β†’ Prop} : PseudoMetricSpace (Subtype p) := PseudoMetricSpace.induced Subtype.val β€Ή_β€Ί lemma Subtype.dist_eq {p : Ξ± β†’ Prop} (x y : Subtype p) : dist x y = dist (x : Ξ±) y := rfl lemma Subtype.nndist_eq {p : Ξ± β†’ Prop} (x y : Subtype p) : nndist x y = nndist (x : Ξ±) y := rfl namespace MulOpposite @[to_additive] instance instPseudoMetricSpace : PseudoMetricSpace αᡐᡒᡖ := PseudoMetricSpace.induced MulOpposite.unop β€Ή_β€Ί @[to_additive (attr := simp)] lemma dist_unop (x y : αᡐᡒᡖ) : dist (unop x) (unop y) = dist x y := rfl @[to_additive (attr := simp)] lemma dist_op (x y : Ξ±) : dist (op x) (op y) = dist x y := rfl @[to_additive (attr := simp)] lemma nndist_unop (x y : αᡐᡒᡖ) : nndist (unop x) (unop y) = nndist x y := rfl @[to_additive (attr := simp)] lemma nndist_op (x y : Ξ±) : nndist (op x) (op y) = nndist x y := rfl end MulOpposite section NNReal instance : PseudoMetricSpace ℝβ‰₯0 := Subtype.pseudoMetricSpace lemma NNReal.dist_eq (a b : ℝβ‰₯0) : dist a b = |(a : ℝ) - b| := rfl lemma NNReal.nndist_eq (a b : ℝβ‰₯0) : nndist a b = max (a - b) (b - a) := eq_of_forall_ge_iff fun _ => by simp only [max_le_iff, tsub_le_iff_right (Ξ± := ℝβ‰₯0)] simp only [← NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff, tsub_le_iff_right, NNReal.coe_add] @[simp] lemma NNReal.nndist_zero_eq_val (z : ℝβ‰₯0) : nndist 0 z = z := by simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le'] @[simp]
lemma NNReal.nndist_zero_eq_val' (z : ℝβ‰₯0) : nndist z 0 = z := by rw [nndist_comm] exact NNReal.nndist_zero_eq_val z lemma NNReal.le_add_nndist (a b : ℝβ‰₯0) : a ≀ b + nndist a b := by
Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean
98
102
/- Copyright (c) 2023 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Data.Finset.Lattice.Fold /-! # Irreducible and prime elements in an order This file defines irreducible and prime elements in an order and shows that in a well-founded lattice every element decomposes as a supremum of irreducible elements. An element is sup-irreducible (resp. inf-irreducible) if it isn't `βŠ₯` and can't be written as the supremum of any strictly smaller elements. An element is sup-prime (resp. inf-prime) if it isn't `βŠ₯` and is greater than the supremum of any two elements less than it. Primality implies irreducibility in general. The converse only holds in distributive lattices. Both hold for all (non-minimal) elements in a linear order. ## Main declarations * `SupIrred a`: Sup-irreducibility, `a` isn't minimal and `a = b βŠ” c β†’ a = b ∨ a = c` * `InfIrred a`: Inf-irreducibility, `a` isn't maximal and `a = b βŠ“ c β†’ a = b ∨ a = c` * `SupPrime a`: Sup-primality, `a` isn't minimal and `a ≀ b βŠ” c β†’ a ≀ b ∨ a ≀ c` * `InfIrred a`: Inf-primality, `a` isn't maximal and `a β‰₯ b βŠ“ c β†’ a β‰₯ b ∨ a β‰₯ c` * `exists_supIrred_decomposition`/`exists_infIrred_decomposition`: Decomposition into irreducibles in a well-founded semilattice. -/ open Finset OrderDual variable {ΞΉ Ξ± : Type*} /-! ### Irreducible and prime elements -/ section SemilatticeSup variable [SemilatticeSup Ξ±] {a b c : Ξ±} /-- A sup-irreducible element is a non-bottom element which isn't the supremum of anything smaller. -/ def SupIrred (a : Ξ±) : Prop := Β¬IsMin a ∧ βˆ€ ⦃b c⦄, b βŠ” c = a β†’ b = a ∨ c = a /-- A sup-prime element is a non-bottom element which isn't less than the supremum of anything smaller. -/ def SupPrime (a : Ξ±) : Prop := Β¬IsMin a ∧ βˆ€ ⦃b c⦄, a ≀ b βŠ” c β†’ a ≀ b ∨ a ≀ c theorem SupIrred.not_isMin (ha : SupIrred a) : Β¬IsMin a := ha.1 theorem SupPrime.not_isMin (ha : SupPrime a) : Β¬IsMin a := ha.1 theorem IsMin.not_supIrred (ha : IsMin a) : Β¬SupIrred a := fun h => h.1 ha theorem IsMin.not_supPrime (ha : IsMin a) : Β¬SupPrime a := fun h => h.1 ha @[simp] theorem not_supIrred : Β¬SupIrred a ↔ IsMin a ∨ βˆƒ b c, b βŠ” c = a ∧ b < a ∧ c < a := by rw [SupIrred, not_and_or] push_neg rw [existsβ‚‚_congr] simp +contextual [@eq_comm _ _ a] @[simp] theorem not_supPrime : Β¬SupPrime a ↔ IsMin a ∨ βˆƒ b c, a ≀ b βŠ” c ∧ Β¬a ≀ b ∧ Β¬a ≀ c := by rw [SupPrime, not_and_or]; push_neg; rfl protected theorem SupPrime.supIrred : SupPrime a β†’ SupIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.ge theorem SupPrime.le_sup (ha : SupPrime a) : a ≀ b βŠ” c ↔ a ≀ b ∨ a ≀ c := ⟨fun h => ha.2 h, fun h => h.elim le_sup_of_le_left le_sup_of_le_right⟩ variable [OrderBot Ξ±] {s : Finset ΞΉ} {f : ΞΉ β†’ Ξ±} @[simp] theorem not_supIrred_bot : Β¬SupIrred (βŠ₯ : Ξ±) := isMin_bot.not_supIrred @[simp] theorem not_supPrime_bot : Β¬SupPrime (βŠ₯ : Ξ±) := isMin_bot.not_supPrime theorem SupIrred.ne_bot (ha : SupIrred a) : a β‰  βŠ₯ := by rintro rfl; exact not_supIrred_bot ha theorem SupPrime.ne_bot (ha : SupPrime a) : a β‰  βŠ₯ := by rintro rfl; exact not_supPrime_bot ha theorem SupIrred.finset_sup_eq (ha : SupIrred a) (h : s.sup f = a) : βˆƒ i ∈ s, f i = a := by classical induction' s using Finset.induction with i s _ ih Β· simpa [ha.ne_bot] using h.symm simp only [exists_prop, exists_mem_insert] at ih ⊒ rw [sup_insert] at h exact (ha.2 h).imp_right ih theorem SupPrime.le_finset_sup (ha : SupPrime a) : a ≀ s.sup f ↔ βˆƒ i ∈ s, a ≀ f i := by classical induction' s using Finset.induction with i s _ ih Β· simp [ha.ne_bot] Β· simp only [exists_prop, exists_mem_insert, sup_insert, ha.le_sup, ih] variable [WellFoundedLT Ξ±] /-- In a well-founded lattice, any element is the supremum of finitely many sup-irreducible elements. This is the order-theoretic analogue of prime factorisation. -/ theorem exists_supIrred_decomposition (a : Ξ±) : βˆƒ s : Finset Ξ±, s.sup id = a ∧ βˆ€ ⦃b⦄, b ∈ s β†’ SupIrred b := by classical apply WellFoundedLT.induction a _ clear a rintro a ih by_cases ha : SupIrred a Β· exact ⟨{a}, by simp [ha]⟩ rw [not_supIrred] at ha obtain ha | ⟨b, c, rfl, hb, hc⟩ := ha Β· exact βŸ¨βˆ…, by simp [ha.eq_bot]⟩ obtain ⟨s, rfl, hs⟩ := ih _ hb obtain ⟨t, rfl, ht⟩ := ih _ hc exact ⟨s βˆͺ t, sup_union, forall_mem_union.2 ⟨hs, ht⟩⟩ end SemilatticeSup section SemilatticeInf variable [SemilatticeInf Ξ±] {a b c : Ξ±} /-- An inf-irreducible element is a non-top element which isn't the infimum of anything bigger. -/ def InfIrred (a : Ξ±) : Prop := Β¬IsMax a ∧ βˆ€ ⦃b c⦄, b βŠ“ c = a β†’ b = a ∨ c = a /-- An inf-prime element is a non-top element which isn't bigger than the infimum of anything bigger. -/ def InfPrime (a : Ξ±) : Prop := Β¬IsMax a ∧ βˆ€ ⦃b c⦄, b βŠ“ c ≀ a β†’ b ≀ a ∨ c ≀ a @[simp] theorem IsMax.not_infIrred (ha : IsMax a) : Β¬InfIrred a := fun h => h.1 ha @[simp] theorem IsMax.not_infPrime (ha : IsMax a) : Β¬InfPrime a := fun h => h.1 ha @[simp] theorem not_infIrred : Β¬InfIrred a ↔ IsMax a ∨ βˆƒ b c, b βŠ“ c = a ∧ a < b ∧ a < c := @not_supIrred Ξ±α΅’α΅ˆ _ _ @[simp] theorem not_infPrime : Β¬InfPrime a ↔ IsMax a ∨ βˆƒ b c, b βŠ“ c ≀ a ∧ Β¬b ≀ a ∧ Β¬c ≀ a := @not_supPrime Ξ±α΅’α΅ˆ _ _ protected theorem InfPrime.infIrred : InfPrime a β†’ InfIrred a := And.imp_right fun h b c ha => by simpa [← ha] using h ha.le theorem InfPrime.inf_le (ha : InfPrime a) : b βŠ“ c ≀ a ↔ b ≀ a ∨ c ≀ a := ⟨fun h => ha.2 h, fun h => h.elim inf_le_of_left_le inf_le_of_right_le⟩ variable [OrderTop Ξ±] {s : Finset ΞΉ} {f : ΞΉ β†’ Ξ±} theorem not_infIrred_top : Β¬InfIrred (⊀ : Ξ±) := isMax_top.not_infIrred theorem not_infPrime_top : Β¬InfPrime (⊀ : Ξ±) := isMax_top.not_infPrime theorem InfIrred.ne_top (ha : InfIrred a) : a β‰  ⊀ := by rintro rfl; exact not_infIrred_top ha theorem InfPrime.ne_top (ha : InfPrime a) : a β‰  ⊀ := by rintro rfl; exact not_infPrime_top ha theorem InfIrred.finset_inf_eq : InfIrred a β†’ s.inf f = a β†’ βˆƒ i ∈ s, f i = a := @SupIrred.finset_sup_eq _ Ξ±α΅’α΅ˆ _ _ _ _ _ theorem InfPrime.finset_inf_le (ha : InfPrime a) : s.inf f ≀ a ↔ βˆƒ i ∈ s, f i ≀ a := @SupPrime.le_finset_sup _ Ξ±α΅’α΅ˆ _ _ _ _ _ ha variable [WellFoundedGT Ξ±]
/-- In a cowell-founded lattice, any element is the infimum of finitely many inf-irreducible
Mathlib/Order/Irreducible.lean
181
182
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : β„‚) : IsCauSeq abs fun n => βˆ‘ m ∈ range n, β€–z ^ m / m.factorialβ€– := let ⟨n, hn⟩ := exists_nat_gt β€–zβ€– have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (β€–zβ€– / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iffβ‚€ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : β„‚) : IsCauSeq (β€–Β·β€–) fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : β„‚) : CauSeq β„‚ (β€–Β·β€–) := ⟨fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : β„‚) : β„‚ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : β„‚) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) Ξ΅0 -- Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅ rcases j with - | j Β· exact absurd hj (not_le_of_gt zero_lt_one) Β· dsimp [exp'] induction' j with j ih Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] Β· rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : βˆ€ j : β„•, (βˆ‘ m ∈ range j, (x + y) ^ m / m.factorial) = βˆ‘ i ∈ range j, βˆ‘ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : β„‚) β‰  0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have hβ‚‚ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← hβ‚‚, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : β„‚), mul_assoc, mul_left_comm (m.choose I : β„‚)⁻¹, mul_comm (m.choose I : β„‚)] rw [inv_mul_cancelβ‚€ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative β„‚` to `β„‚` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative β„‚) β„‚ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List β„‚) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative β„‚) expMonoidHom l theorem exp_multiset_sum (s : Multiset β„‚) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative β„‚) β„‚ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ β„‚) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative β„‚) expMonoidHom f s lemma exp_nsmul (x : β„‚) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative β„‚) β„‚ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : β„‚) : βˆ€ n : β„•, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x β‰  0 := fun h => zero_ne_one (Ξ± := β„‚) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancelβ‚€ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : β„‚) (n : β„€) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n Β· simp [exp_nat_mul] Β· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_divβ‚€, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : β„‚) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : β„‚) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : β„•) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x β‰  0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) (n : β„•) : βˆ‘ i ∈ range n, x ^ i / i ! ≀ exp x := calc βˆ‘ i ∈ range n, x ^ i / i ! ≀ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≀ x) (n : β„•) : x ^ n / n ! ≀ exp x := calc x ^ n / n ! ≀ βˆ‘ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≀ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : 1 + x + x ^ 2 / 2 ≀ exp x := calc 1 + x + x ^ 2 / 2 = βˆ‘ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≀ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : x + 1 ≀ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) Β· simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≀ x) : 1 ≀ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≀ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≀ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≀ y) : exp x ≀ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≀ exp y ↔ x ≀ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp]
theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp]
Mathlib/Data/Complex/Exponential.lean
319
323
/- Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Data.Finset.Sort /-! # Compositions A composition of a natural number `n` is a decomposition `n = iβ‚€ + ... + i_{k-1}` of `n` into a sum of positive integers. Combinatorially, it corresponds to a decomposition of `{0, ..., n-1}` into non-empty blocks of consecutive integers, where the `iβ±Ό` are the lengths of the blocks. This notion is closely related to that of a partition of `n`, but in a composition of `n` the order of the `iβ±Ό`s matters. We implement two different structures covering these two viewpoints on compositions. The first one, made of a list of positive integers summing to `n`, is the main one and is called `Composition n`. The second one is useful for combinatorial arguments (for instance to show that the number of compositions of `n` is `2^(n-1)`). It is given by a subset of `{0, ..., n}` containing `0` and `n`, where the elements of the subset (other than `n`) correspond to the leftmost points of each block. The main API is built on `Composition n`, and we provide an equivalence between the two types. ## Main functions * `c : Composition n` is a structure, made of a list of integers which are all positive and add up to `n`. * `composition_card` states that the cardinality of `Composition n` is exactly `2^(n-1)`, which is proved by constructing an equiv with `CompositionAsSet n` (see below), which is itself in bijection with the subsets of `Fin (n-1)` (this holds even for `n = 0`, where `-` is nat subtraction). Let `c : Composition n` be a composition of `n`. Then * `c.blocks` is the list of blocks in `c`. * `c.length` is the number of blocks in the composition. * `c.blocksFun : Fin c.length β†’ β„•` is the realization of `c.blocks` as a function on `Fin c.length`. This is the main object when using compositions to understand the composition of analytic functions. * `c.sizeUpTo : β„• β†’ β„•` is the sum of the size of the blocks up to `i`.; * `c.embedding i : Fin (c.blocksFun i) β†’ Fin n` is the increasing embedding of the `i`-th block in `Fin n`; * `c.index j`, for `j : Fin n`, is the index of the block containing `j`. * `Composition.ones n` is the composition of `n` made of ones, i.e., `[1, ..., 1]`. * `Composition.single n (hn : 0 < n)` is the composition of `n` made of a single block of size `n`. Compositions can also be used to split lists. Let `l` be a list of length `n` and `c` a composition of `n`. * `l.splitWrtComposition c` is a list of lists, made of the slices of `l` corresponding to the blocks of `c`. * `join_splitWrtComposition` states that splitting a list and then joining it gives back the original list. * `splitWrtComposition_join` states that joining a list of lists, and then splitting it back according to the right composition, gives back the original list of lists. We turn to the second viewpoint on compositions, that we realize as a finset of `Fin (n+1)`. `c : CompositionAsSet n` is a structure made of a finset of `Fin (n+1)` called `c.boundaries` and proofs that it contains `0` and `n`. (Taking a finset of `Fin n` containing `0` would not make sense in the edge case `n = 0`, while the previous description works in all cases). The elements of this set (other than `n`) correspond to leftmost points of blocks. Thus, there is an equiv between `Composition n` and `CompositionAsSet n`. We only construct basic API on `CompositionAsSet` (notably `c.length` and `c.blocks`) to be able to construct this equiv, called `compositionEquiv n`. Since there is a straightforward equiv between `CompositionAsSet n` and finsets of `{1, ..., n-1}` (obtained by removing `0` and `n` from a `CompositionAsSet` and called `compositionAsSetEquiv n`), we deduce that `CompositionAsSet n` and `Composition n` are both fintypes of cardinality `2^(n - 1)` (see `compositionAsSet_card` and `composition_card`). ## Implementation details The main motivation for this structure and its API is in the construction of the composition of formal multilinear series, and the proof that the composition of analytic functions is analytic. The representation of a composition as a list is very handy as lists are very flexible and already have a well-developed API. ## Tags Composition, partition ## References <https://en.wikipedia.org/wiki/Composition_(combinatorics)> -/ assert_not_exists Field open List variable {n : β„•} /-- A composition of `n` is a list of positive integers summing to `n`. -/ @[ext] structure Composition (n : β„•) where /-- List of positive integers summing to `n` -/ blocks : List β„• /-- Proof of positivity for `blocks` -/ blocks_pos : βˆ€ {i}, i ∈ blocks β†’ 0 < i /-- Proof that `blocks` sums to `n` -/ blocks_sum : blocks.sum = n deriving DecidableEq attribute [simp] Composition.blocks_sum /-- Combinatorial viewpoint on a composition of `n`, by seeing it as non-empty blocks of consecutive integers in `{0, ..., n-1}`. We register every block by its left end-point, yielding a finset containing `0`. As this does not make sense for `n = 0`, we add `n` to this finset, and get a finset of `{0, ..., n}` containing `0` and `n`. This is the data in the structure `CompositionAsSet n`. -/ @[ext] structure CompositionAsSet (n : β„•) where /-- Combinatorial viewpoint on a composition of `n` as consecutive integers `{0, ..., n-1}` -/ boundaries : Finset (Fin n.succ) /-- Proof that `0` is a member of `boundaries` -/ zero_mem : (0 : Fin n.succ) ∈ boundaries /-- Last element of the composition -/ getLast_mem : Fin.last n ∈ boundaries deriving DecidableEq instance {n : β„•} : Inhabited (CompositionAsSet n) := ⟨⟨Finset.univ, Finset.mem_univ _, Finset.mem_univ _⟩⟩ attribute [simp] CompositionAsSet.zero_mem CompositionAsSet.getLast_mem /-! ### Compositions A composition of an integer `n` is a decomposition `n = iβ‚€ + ... + i_{k-1}` of `n` into a sum of positive integers. -/ namespace Composition variable (c : Composition n) instance (n : β„•) : ToString (Composition n) := ⟨fun c => toString c.blocks⟩ /-- The length of a composition, i.e., the number of blocks in the composition. -/ abbrev length : β„• := c.blocks.length theorem blocks_length : c.blocks.length = c.length := rfl /-- The blocks of a composition, seen as a function on `Fin c.length`. When composing analytic functions using compositions, this is the main player. -/ def blocksFun : Fin c.length β†’ β„• := c.blocks.get @[simp] theorem ofFn_blocksFun : ofFn c.blocksFun = c.blocks := ofFn_get _ @[simp] theorem sum_blocksFun : βˆ‘ i, c.blocksFun i = n := by conv_rhs => rw [← c.blocks_sum, ← ofFn_blocksFun, sum_ofFn] @[simp] theorem blocksFun_mem_blocks (i : Fin c.length) : c.blocksFun i ∈ c.blocks := get_mem _ _ theorem one_le_blocks {i : β„•} (h : i ∈ c.blocks) : 1 ≀ i := c.blocks_pos h theorem blocks_le {i : β„•} (h : i ∈ c.blocks) : i ≀ n := by rw [← c.blocks_sum] exact List.le_sum_of_mem h @[simp] theorem one_le_blocks' {i : β„•} (h : i < c.length) : 1 ≀ c.blocks[i] := c.one_le_blocks (get_mem (blocks c) _) @[simp] theorem blocks_pos' (i : β„•) (h : i < c.length) : 0 < c.blocks[i] := c.one_le_blocks' h @[simp] theorem one_le_blocksFun (i : Fin c.length) : 1 ≀ c.blocksFun i := c.one_le_blocks (c.blocksFun_mem_blocks i) @[simp] theorem blocksFun_le {n} (c : Composition n) (i : Fin c.length) : c.blocksFun i ≀ n := c.blocks_le <| getElem_mem _ @[simp] theorem length_le : c.length ≀ n := by conv_rhs => rw [← c.blocks_sum] exact length_le_sum_of_one_le _ fun i hi => c.one_le_blocks hi @[simp] theorem blocks_eq_nil : c.blocks = [] ↔ n = 0 := by constructor Β· intro h simpa using congr(List.sum $h) Β· rintro rfl rw [← length_eq_zero_iff, ← nonpos_iff_eq_zero] exact c.length_le protected theorem length_eq_zero : c.length = 0 ↔ n = 0 := by simp @[simp] theorem length_pos_iff : 0 < c.length ↔ 0 < n := by simp [pos_iff_ne_zero] alias ⟨_, length_pos_of_pos⟩ := length_pos_iff /-- The sum of the sizes of the blocks in a composition up to `i`. -/ def sizeUpTo (i : β„•) : β„• := (c.blocks.take i).sum @[simp] theorem sizeUpTo_zero : c.sizeUpTo 0 = 0 := by simp [sizeUpTo] theorem sizeUpTo_ofLength_le (i : β„•) (h : c.length ≀ i) : c.sizeUpTo i = n := by dsimp [sizeUpTo] convert c.blocks_sum exact take_of_length_le h @[simp] theorem sizeUpTo_length : c.sizeUpTo c.length = n := c.sizeUpTo_ofLength_le c.length le_rfl theorem sizeUpTo_le (i : β„•) : c.sizeUpTo i ≀ n := by conv_rhs => rw [← c.blocks_sum, ← sum_take_add_sum_drop _ i] exact Nat.le_add_right _ _ theorem sizeUpTo_succ {i : β„•} (h : i < c.length) : c.sizeUpTo (i + 1) = c.sizeUpTo i + c.blocks[i] := by simp only [sizeUpTo] rw [sum_take_succ _ _ h] theorem sizeUpTo_succ' (i : Fin c.length) : c.sizeUpTo ((i : β„•) + 1) = c.sizeUpTo i + c.blocksFun i := c.sizeUpTo_succ i.2 theorem sizeUpTo_strict_mono {i : β„•} (h : i < c.length) : c.sizeUpTo i < c.sizeUpTo (i + 1) := by rw [c.sizeUpTo_succ h] simp theorem monotone_sizeUpTo : Monotone c.sizeUpTo := monotone_sum_take _ /-- The `i`-th boundary of a composition, i.e., the leftmost point of the `i`-th block. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundary : Fin (c.length + 1) β†ͺo Fin (n + 1) := (OrderEmbedding.ofStrictMono fun i => ⟨c.sizeUpTo i, Nat.lt_succ_of_le (c.sizeUpTo_le i)⟩) <| Fin.strictMono_iff_lt_succ.2 fun ⟨_, hi⟩ => c.sizeUpTo_strict_mono hi @[simp] theorem boundary_zero : c.boundary 0 = 0 := by simp [boundary, Fin.ext_iff] @[simp] theorem boundary_last : c.boundary (Fin.last c.length) = Fin.last n := by simp [boundary, Fin.ext_iff] /-- The boundaries of a composition, i.e., the leftmost point of all the blocks. We include a virtual point at the right of the last block, to make for a nice equiv with `CompositionAsSet n`. -/ def boundaries : Finset (Fin (n + 1)) := Finset.univ.map c.boundary.toEmbedding theorem card_boundaries_eq_succ_length : c.boundaries.card = c.length + 1 := by simp [boundaries] /-- To `c : Composition n`, one can associate a `CompositionAsSet n` by registering the leftmost point of each block, and adding a virtual point at the right of the last block. -/ def toCompositionAsSet : CompositionAsSet n where boundaries := c.boundaries zero_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨0, And.intro True.intro rfl⟩ getLast_mem := by simp only [boundaries, Finset.mem_univ, exists_prop_of_true, Finset.mem_map] exact ⟨Fin.last c.length, And.intro True.intro c.boundary_last⟩ /-- The canonical increasing bijection between `Fin (c.length + 1)` and `c.boundaries` is exactly `c.boundary`. -/ theorem orderEmbOfFin_boundaries : c.boundaries.orderEmbOfFin c.card_boundaries_eq_succ_length = c.boundary := by refine (Finset.orderEmbOfFin_unique' _ ?_).symm exact fun i => (Finset.mem_map' _).2 (Finset.mem_univ _) /-- Embedding the `i`-th block of a composition (identified with `Fin (c.blocksFun i)`) into `Fin n` at the relevant position. -/ def embedding (i : Fin c.length) : Fin (c.blocksFun i) β†ͺo Fin n := (Fin.natAddOrderEmb <| c.sizeUpTo i).trans <| Fin.castLEOrderEmb <| calc c.sizeUpTo i + c.blocksFun i = c.sizeUpTo (i + 1) := (c.sizeUpTo_succ i.2).symm _ ≀ c.sizeUpTo c.length := monotone_sum_take _ i.2 _ = n := c.sizeUpTo_length @[simp] theorem coe_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.embedding i j : β„•) = c.sizeUpTo i + j := rfl /-- `index_exists` asserts there is some `i` with `j < c.sizeUpTo (i+1)`. In the next definition `index` we use `Nat.find` to produce the minimal such index. -/ theorem index_exists {j : β„•} (h : j < n) : βˆƒ i : β„•, j < c.sizeUpTo (i + 1) ∧ i < c.length := by have n_pos : 0 < n := lt_of_le_of_lt (zero_le j) h have : 0 < c.blocks.sum := by rwa [← c.blocks_sum] at n_pos have length_pos : 0 < c.blocks.length := length_pos_of_sum_pos (blocks c) this refine ⟨c.length - 1, ?_, Nat.pred_lt (ne_of_gt length_pos)⟩ have : c.length - 1 + 1 = c.length := Nat.succ_pred_eq_of_pos length_pos simp [this, h] /-- `c.index j` is the index of the block in the composition `c` containing `j`. -/ def index (j : Fin n) : Fin c.length := ⟨Nat.find (c.index_exists j.2), (Nat.find_spec (c.index_exists j.2)).2⟩ theorem lt_sizeUpTo_index_succ (j : Fin n) : (j : β„•) < c.sizeUpTo (c.index j).succ := (Nat.find_spec (c.index_exists j.2)).1 theorem sizeUpTo_index_le (j : Fin n) : c.sizeUpTo (c.index j) ≀ j := by by_contra H set i := c.index j push_neg at H have i_pos : (0 : β„•) < i := by by_contra! i_pos revert H simp [nonpos_iff_eq_zero.1 i_pos, c.sizeUpTo_zero] let i₁ := (i : β„•).pred have i₁_lt_i : i₁ < i := Nat.pred_lt (ne_of_gt i_pos) have i₁_succ : i₁ + 1 = i := Nat.succ_pred_eq_of_pos i_pos have := Nat.find_min (c.index_exists j.2) i₁_lt_i simp [lt_trans i₁_lt_i (c.index j).2, i₁_succ] at this exact Nat.lt_le_asymm H this /-- Mapping an element `j` of `Fin n` to the element in the block containing it, identified with `Fin (c.blocksFun (c.index j))` through the canonical increasing bijection. -/ def invEmbedding (j : Fin n) : Fin (c.blocksFun (c.index j)) := ⟨j - c.sizeUpTo (c.index j), by rw [tsub_lt_iff_right, add_comm, ← sizeUpTo_succ'] Β· exact lt_sizeUpTo_index_succ _ _ Β· exact sizeUpTo_index_le _ _⟩ @[simp] theorem coe_invEmbedding (j : Fin n) : (c.invEmbedding j : β„•) = j - c.sizeUpTo (c.index j) := rfl theorem embedding_comp_inv (j : Fin n) : c.embedding (c.index j) (c.invEmbedding j) = j := by rw [Fin.ext_iff] apply add_tsub_cancel_of_le (c.sizeUpTo_index_le j) theorem mem_range_embedding_iff {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ c.sizeUpTo i ≀ j ∧ (j : β„•) < c.sizeUpTo (i : β„•).succ := by constructor Β· intro h rcases Set.mem_range.2 h with ⟨k, hk⟩ rw [Fin.ext_iff] at hk dsimp at hk rw [← hk] simp [sizeUpTo_succ', k.is_lt] Β· intro h apply Set.mem_range.2 refine ⟨⟨j - c.sizeUpTo i, ?_⟩, ?_⟩ Β· rw [tsub_lt_iff_left, ← sizeUpTo_succ'] Β· exact h.2 Β· exact h.1 Β· rw [Fin.ext_iff] exact add_tsub_cancel_of_le h.1 /-- The embeddings of different blocks of a composition are disjoint. -/ theorem disjoint_range {i₁ iβ‚‚ : Fin c.length} (h : i₁ β‰  iβ‚‚) : Disjoint (Set.range (c.embedding i₁)) (Set.range (c.embedding iβ‚‚)) := by classical wlog h' : i₁ < iβ‚‚ Β· exact (this c h.symm (h.lt_or_lt.resolve_left h')).symm by_contra d obtain ⟨x, hx₁, hxβ‚‚βŸ© : βˆƒ x : Fin n, x ∈ Set.range (c.embedding i₁) ∧ x ∈ Set.range (c.embedding iβ‚‚) := Set.not_disjoint_iff.1 d have A : (i₁ : β„•).succ ≀ iβ‚‚ := Nat.succ_le_of_lt h' apply lt_irrefl (x : β„•) calc (x : β„•) < c.sizeUpTo (i₁ : β„•).succ := (c.mem_range_embedding_iff.1 hx₁).2 _ ≀ c.sizeUpTo (iβ‚‚ : β„•) := monotone_sum_take _ A _ ≀ x := (c.mem_range_embedding_iff.1 hxβ‚‚).1 theorem mem_range_embedding (j : Fin n) : j ∈ Set.range (c.embedding (c.index j)) := by have : c.embedding (c.index j) (c.invEmbedding j) ∈ Set.range (c.embedding (c.index j)) := Set.mem_range_self _ rwa [c.embedding_comp_inv j] at this theorem mem_range_embedding_iff' {j : Fin n} {i : Fin c.length} : j ∈ Set.range (c.embedding i) ↔ i = c.index j := by constructor Β· rw [← not_imp_not] intro h exact Set.disjoint_right.1 (c.disjoint_range h) (c.mem_range_embedding j) Β· intro h rw [h] exact c.mem_range_embedding j theorem index_embedding (i : Fin c.length) (j : Fin (c.blocksFun i)) : c.index (c.embedding i j) = i := by symm rw [← mem_range_embedding_iff'] apply Set.mem_range_self theorem invEmbedding_comp (i : Fin c.length) (j : Fin (c.blocksFun i)) : (c.invEmbedding (c.embedding i j) : β„•) = j := by simp_rw [coe_invEmbedding, index_embedding, coe_embedding, add_tsub_cancel_left] /-- Equivalence between the disjoint union of the blocks (each of them seen as `Fin (c.blocksFun i)`) with `Fin n`. -/ def blocksFinEquiv : (Ξ£i : Fin c.length, Fin (c.blocksFun i)) ≃ Fin n where toFun x := c.embedding x.1 x.2 invFun j := ⟨c.index j, c.invEmbedding j⟩ left_inv x := by rcases x with ⟨i, y⟩ dsimp congr; Β· exact c.index_embedding _ _ rw [Fin.heq_ext_iff] Β· exact c.invEmbedding_comp _ _ Β· rw [c.index_embedding] right_inv j := c.embedding_comp_inv j theorem blocksFun_congr {n₁ nβ‚‚ : β„•} (c₁ : Composition n₁) (cβ‚‚ : Composition nβ‚‚) (i₁ : Fin c₁.length) (iβ‚‚ : Fin cβ‚‚.length) (hn : n₁ = nβ‚‚) (hc : c₁.blocks = cβ‚‚.blocks) (hi : (i₁ : β„•) = iβ‚‚) : c₁.blocksFun i₁ = cβ‚‚.blocksFun iβ‚‚ := by cases hn rw [← Composition.ext_iff] at hc cases hc congr rwa [Fin.ext_iff] /-- Two compositions (possibly of different integers) coincide if and only if they have the same sequence of blocks. -/ theorem sigma_eq_iff_blocks_eq {c : Ξ£ n, Composition n} {c' : Ξ£ n, Composition n} : c = c' ↔ c.2.blocks = c'.2.blocks := by refine ⟨fun H => by rw [H], fun H => ?_⟩ rcases c with ⟨n, c⟩ rcases c' with ⟨n', c'⟩ have : n = n' := by rw [← c.blocks_sum, ← c'.blocks_sum, H] induction this congr ext1 exact H /-! ### The composition `Composition.ones` -/ /-- The composition made of blocks all of size `1`. -/ def ones (n : β„•) : Composition n := ⟨replicate n (1 : β„•), fun {i} hi => by simp [List.eq_of_mem_replicate hi], by simp⟩ instance {n : β„•} : Inhabited (Composition n) := ⟨Composition.ones n⟩ @[simp] theorem ones_length (n : β„•) : (ones n).length = n := List.length_replicate @[simp] theorem ones_blocks (n : β„•) : (ones n).blocks = replicate n (1 : β„•) := rfl @[simp] theorem ones_blocksFun (n : β„•) (i : Fin (ones n).length) : (ones n).blocksFun i = 1 := by simp only [blocksFun, ones, get_eq_getElem, getElem_replicate] @[simp] theorem ones_sizeUpTo (n : β„•) (i : β„•) : (ones n).sizeUpTo i = min i n := by simp [sizeUpTo, ones_blocks, take_replicate] @[simp] theorem ones_embedding (i : Fin (ones n).length) (h : 0 < (ones n).blocksFun i) : (ones n).embedding i ⟨0, h⟩ = ⟨i, lt_of_lt_of_le i.2 (ones n).length_le⟩ := by ext simpa using i.2.le theorem eq_ones_iff {c : Composition n} : c = ones n ↔ βˆ€ i ∈ c.blocks, i = 1 := by constructor Β· rintro rfl exact fun i => eq_of_mem_replicate Β· intro H ext1 have A : c.blocks = replicate c.blocks.length 1 := eq_replicate_of_mem H have : c.blocks.length = n := by conv_rhs => rw [← c.blocks_sum, A] simp rw [A, this, ones_blocks] theorem ne_ones_iff {c : Composition n} : c β‰  ones n ↔ βˆƒ i ∈ c.blocks, 1 < i := by refine (not_congr eq_ones_iff).trans ?_ have : βˆ€ j ∈ c.blocks, j = 1 ↔ j ≀ 1 := fun j hj => by simp [le_antisymm_iff, c.one_le_blocks hj] simp +contextual [this] theorem eq_ones_iff_length {c : Composition n} : c = ones n ↔ c.length = n := by constructor Β· rintro rfl exact ones_length n Β· contrapose intro H length_n apply lt_irrefl n calc n = βˆ‘ i : Fin c.length, 1 := by simp [length_n] _ < βˆ‘ i : Fin c.length, c.blocksFun i := by { obtain ⟨i, hi, i_blocks⟩ : βˆƒ i ∈ c.blocks, 1 < i := ne_ones_iff.1 H rw [← ofFn_blocksFun, mem_ofFn' c.blocksFun, Set.mem_range] at hi obtain ⟨j : Fin c.length, hj : c.blocksFun j = i⟩ := hi rw [← hj] at i_blocks exact Finset.sum_lt_sum (fun i _ => one_le_blocksFun c i) ⟨j, Finset.mem_univ _, i_blocks⟩ } _ = n := c.sum_blocksFun theorem eq_ones_iff_le_length {c : Composition n} : c = ones n ↔ n ≀ c.length := by simp [eq_ones_iff_length, le_antisymm_iff, c.length_le] /-! ### The composition `Composition.single` -/ /-- The composition made of a single block of size `n`. -/ def single (n : β„•) (h : 0 < n) : Composition n := ⟨[n], by simp [h], by simp⟩ @[simp] theorem single_length {n : β„•} (h : 0 < n) : (single n h).length = 1 := rfl @[simp] theorem single_blocks {n : β„•} (h : 0 < n) : (single n h).blocks = [n] := rfl @[simp] theorem single_blocksFun {n : β„•} (h : 0 < n) (i : Fin (single n h).length) : (single n h).blocksFun i = n := by simp [blocksFun, single, blocks, i.2] @[simp] theorem single_embedding {n : β„•} (h : 0 < n) (i : Fin n) : ((single n h).embedding (0 : Fin 1)) i = i := by ext simp theorem eq_single_iff_length {n : β„•} (h : 0 < n) {c : Composition n} : c = single n h ↔ c.length = 1 := by
constructor Β· intro H
Mathlib/Combinatorics/Enumerative/Composition.lean
544
545
/- Copyright (c) 2022 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Nat /-! # Double countings This file gathers a few double counting arguments. ## Bipartite graphs In a bipartite graph (considered as a relation `r : Ξ± β†’ Ξ² β†’ Prop`), we can bound the number of edges between `s : Finset Ξ±` and `t : Finset Ξ²` by the minimum/maximum of edges over all `a ∈ s` times the size of `s`. Similarly for `t`. Combining those two yields inequalities between the sizes of `s` and `t`. * `bipartiteBelow`: `s.bipartiteBelow r b` are the elements of `s` below `b` wrt to `r`. Its size is the number of edges of `b` in `s`. * `bipartiteAbove`: `t.bipartite_Above r a` are the elements of `t` above `a` wrt to `r`. Its size is the number of edges of `a` in `t`. * `card_mul_le_card_mul`, `card_mul_le_card_mul'`: Double counting the edges of a bipartite graph from below and from above. * `card_mul_eq_card_mul`: Equality combination of the previous. ## Implementation notes For the formulation of double-counting arguments where a bipartite graph is considered as a bipartite simple graph `G : SimpleGraph V`, see `Mathlib.Combinatorics.SimpleGraph.Bipartite`. -/ assert_not_exists Field open Finset Function Relator variable {R Ξ± Ξ² : Type*} /-! ### Bipartite graph -/ namespace Finset section Bipartite variable (r : Ξ± β†’ Ξ² β†’ Prop) (s : Finset Ξ±) (t : Finset Ξ²) (a : Ξ±) (b : Ξ²) [DecidablePred (r a)] [βˆ€ a, Decidable (r a b)] {m n : β„•} /-- Elements of `s` which are "below" `b` according to relation `r`. -/ def bipartiteBelow : Finset Ξ± := {a ∈ s | r a b} /-- Elements of `t` which are "above" `a` according to relation `r`. -/ def bipartiteAbove : Finset Ξ² := {b ∈ t | r a b} theorem bipartiteBelow_swap : t.bipartiteBelow (swap r) a = t.bipartiteAbove r a := rfl theorem bipartiteAbove_swap : s.bipartiteAbove (swap r) b = s.bipartiteBelow r b := rfl @[simp, norm_cast] theorem coe_bipartiteBelow : s.bipartiteBelow r b = ({a ∈ s | r a b} : Set Ξ±) := coe_filter _ _ @[simp, norm_cast] theorem coe_bipartiteAbove : t.bipartiteAbove r a = ({b ∈ t | r a b} : Set Ξ²) := coe_filter _ _ variable {s t a b} @[simp] theorem mem_bipartiteBelow {a : Ξ±} : a ∈ s.bipartiteBelow r b ↔ a ∈ s ∧ r a b := mem_filter @[simp] theorem mem_bipartiteAbove {b : Ξ²} : b ∈ t.bipartiteAbove r a ↔ b ∈ t ∧ r a b := mem_filter @[to_additive] theorem prod_prod_bipartiteAbove_eq_prod_prod_bipartiteBelow [CommMonoid R] (f : Ξ± β†’ Ξ² β†’ R) [βˆ€ a b, Decidable (r a b)] : ∏ a ∈ s, ∏ b ∈ t.bipartiteAbove r a, f a b = ∏ b ∈ t, ∏ a ∈ s.bipartiteBelow r b, f a b := by simp_rw [bipartiteAbove, bipartiteBelow, prod_filter] exact prod_comm theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [βˆ€ a b, Decidable (r a b)] : (βˆ‘ a ∈ s, #(t.bipartiteAbove r a)) = βˆ‘ b ∈ t, #(s.bipartiteBelow r b) := by simp_rw [card_eq_sum_ones, sum_sum_bipartiteAbove_eq_sum_sum_bipartiteBelow] section OrderedSemiring variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {m n : R} /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_le_card_nsmul [βˆ€ a b, Decidable (r a b)] (hm : βˆ€ a ∈ s, m ≀ #(t.bipartiteAbove r a)) (hn : βˆ€ b ∈ t, #(s.bipartiteBelow r b) ≀ n) : #s β€’ m ≀ #t β€’ n := calc _ ≀ βˆ‘ a ∈ s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm _ = βˆ‘ b ∈ t, (#(s.bipartiteBelow r b) : R) := by norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] _ ≀ _ := t.sum_le_card_nsmul _ _ hn /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_le_card_nsmul' [βˆ€ a b, Decidable (r a b)] (hn : βˆ€ b ∈ t, n ≀ #(s.bipartiteBelow r b)) (hm : βˆ€ a ∈ s, #(t.bipartiteAbove r a) ≀ m) : #t β€’ n ≀ #s β€’ m := card_nsmul_le_card_nsmul (swap r) hn hm end OrderedSemiring section StrictOrderedSemiring variable [Semiring R] [PartialOrder R] [IsStrictOrderedRing R] (r : Ξ± β†’ Ξ² β†’ Prop) {s : Finset Ξ±} {t : Finset Ξ²} (a b) {m n : R} /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a strict lower bound on the number of edges while the RHS is an upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_lt_of_le [βˆ€ a b, Decidable (r a b)] (hs : s.Nonempty) (hm : βˆ€ a ∈ s, m < #(t.bipartiteAbove r a)) (hn : βˆ€ b ∈ t, #(s.bipartiteBelow r b) ≀ n) : #s β€’ m < #t β€’ n := calc _ = βˆ‘ _a ∈ s, m := by rw [sum_const] _ < βˆ‘ a ∈ s, (#(t.bipartiteAbove r a) : R) := sum_lt_sum_of_nonempty hs hm _ = βˆ‘ b ∈ t, (#(s.bipartiteBelow r b) : R) := by norm_cast; rw [sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow] _ ≀ _ := t.sum_le_card_nsmul _ _ hn /-- **Double counting** argument. Considering `r` as a bipartite graph, the LHS is a lower bound on the number of edges while the RHS is a strict upper bound. -/ theorem card_nsmul_lt_card_nsmul_of_le_of_lt [βˆ€ a b, Decidable (r a b)] (ht : t.Nonempty) (hm : βˆ€ a ∈ s, m ≀ #(t.bipartiteAbove r a))
(hn : βˆ€ b ∈ t, #(s.bipartiteBelow r b) < n) : #s β€’ m < #t β€’ n := calc _ ≀ βˆ‘ a ∈ s, (#(t.bipartiteAbove r a) : R) := s.card_nsmul_le_sum _ _ hm
Mathlib/Combinatorics/Enumerative/DoubleCounting.lean
138
140
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * Ο€`. For some purposes, angles modulo `Ο€` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `Ο€` can be represented modulo `2 * Ο€` as equalities of `(2 : β„€) β€’ ΞΈ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "Ο‰" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * Ο€`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V Γ— V} (hx1 : x.1 β‰  0) (hx2 : x.2 β‰  0) : ContinuousAt (fun y : V Γ— V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ Β· exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuousβ‚‚).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_right (x : V) : o.oangle x 0 = 0 := by simp [oangle] /-- If the two vectors passed to `oangle` are the same, the result is 0. -/ @[simp] theorem oangle_self (x : V) : o.oangle x x = 0 := by rw [oangle, kahler_apply_self, ← ofReal_pow] convert QuotientAddGroup.mk_zero (AddSubgroup.zmultiples (2 * Ο€)) apply arg_ofReal_of_nonneg positivity /-- If the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : y β‰  0 := by rintro rfl; simp at h /-- If the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_ne_zero {x y : V} (h : o.oangle x y β‰  0) : x β‰  y := by rintro rfl; simp at h /-- If the angle between two vectors is `Ο€`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi {x y : V} (h : o.oangle x y = Ο€) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = (Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the angle between two vectors is `-Ο€ / 2`, the vectors are not equal. -/ theorem ne_of_oangle_eq_neg_pi_div_two {x y : V} (h : o.oangle x y = (-Ο€ / 2 : ℝ)) : x β‰  y := o.ne_of_oangle_ne_zero (h.symm β–Έ Real.Angle.neg_pi_div_two_ne_zero : o.oangle x y β‰  0) /-- If the sign of the angle between two vectors is nonzero, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  0 := o.left_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : y β‰  0 := o.right_ne_zero_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is nonzero, the vectors are not equal. -/ theorem ne_of_oangle_sign_ne_zero {x y : V} (h : (o.oangle x y).sign β‰  0) : x β‰  y := o.ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between two vectors is positive, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is positive, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_one {x y : V} (h : (o.oangle x y).sign = 1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the first vector is nonzero. -/ theorem left_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  0 := o.left_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the second vector is nonzero. -/ theorem right_ne_zero_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : y β‰  0 := o.right_ne_zero_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- If the sign of the angle between two vectors is negative, the vectors are not equal. -/ theorem ne_of_oangle_sign_eq_neg_one {x y : V} (h : (o.oangle x y).sign = -1) : x β‰  y := o.ne_of_oangle_sign_ne_zero (h.symm β–Έ by decide : (o.oangle x y).sign β‰  0) /-- Swapping the two vectors passed to `oangle` negates the angle. -/ theorem oangle_rev (x y : V) : o.oangle y x = -o.oangle x y := by simp only [oangle, o.kahler_swap y x, Complex.arg_conj_coe_angle] /-- Adding the angles between two vectors in each order results in 0. -/ @[simp] theorem oangle_add_oangle_rev (x y : V) : o.oangle x y + o.oangle y x = 0 := by simp [o.oangle_rev y x] /-- Negating the first vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_left {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle (-x) y = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the second vector passed to `oangle` adds `Ο€` to the angle. -/ theorem oangle_neg_right {x y : V} (hx : x β‰  0) (hy : y β‰  0) : o.oangle x (-y) = o.oangle x y + Ο€ := by simp only [oangle, map_neg] convert Complex.arg_neg_coe_angle _ exact o.kahler_ne_zero hx hy /-- Negating the first vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_left (x y : V) : (2 : β„€) β€’ o.oangle (-x) y = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_left hx hy] /-- Negating the second vector passed to `oangle` does not change twice the angle. -/ @[simp] theorem two_zsmul_oangle_neg_right (x y : V) : (2 : β„€) β€’ o.oangle x (-y) = (2 : β„€) β€’ o.oangle x y := by by_cases hx : x = 0 Β· simp [hx] Β· by_cases hy : y = 0 Β· simp [hy] Β· simp [o.oangle_neg_right hx hy] /-- Negating both vectors passed to `oangle` does not change the angle. -/ @[simp] theorem oangle_neg_neg (x y : V) : o.oangle (-x) (-y) = o.oangle x y := by simp [oangle] /-- Negating the first vector produces the same angle as negating the second vector. -/ theorem oangle_neg_left_eq_neg_right (x y : V) : o.oangle (-x) y = o.oangle x (-y) := by rw [← neg_neg y, oangle_neg_neg, neg_neg] /-- The angle between the negation of a nonzero vector and that vector is `Ο€`. -/ @[simp] theorem oangle_neg_self_left {x : V} (hx : x β‰  0) : o.oangle (-x) x = Ο€ := by simp [oangle_neg_left, hx] /-- The angle between a nonzero vector and its negation is `Ο€`. -/ @[simp] theorem oangle_neg_self_right {x : V} (hx : x β‰  0) : o.oangle x (-x) = Ο€ := by simp [oangle_neg_right, hx] /-- Twice the angle between the negation of a vector and that vector is 0. -/ theorem two_zsmul_oangle_neg_self_left (x : V) : (2 : β„€) β€’ o.oangle (-x) x = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Twice the angle between a vector and its negation is 0. -/ theorem two_zsmul_oangle_neg_self_right (x : V) : (2 : β„€) β€’ o.oangle x (-x) = 0 := by by_cases hx : x = 0 <;> simp [hx] /-- Adding the angles between two vectors in each order, with the first vector in each angle negated, results in 0. -/ @[simp] theorem oangle_add_oangle_rev_neg_left (x y : V) : o.oangle (-x) y + o.oangle (-y) x = 0 := by rw [oangle_neg_left_eq_neg_right, oangle_rev, neg_add_cancel] /-- Adding the angles between two vectors in each order, with the second vector in each angle negated, results in 0. -/ @[simp]
theorem oangle_add_oangle_rev_neg_right (x y : V) : o.oangle x (-y) + o.oangle y (-x) = 0 := by
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
243
243
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.Basic import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} section LinearOrderedSemifield variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β„€} /-! ### Relating two divisions. -/ @[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")] theorem div_le_div_right (hc : 0 < c) : a / c ≀ b / c ↔ a ≀ b := div_le_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")] theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")] theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := div_lt_div_iff_of_pos_left ha hb hc @[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")] theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≀ a / c ↔ c ≀ b := div_le_div_iff_of_pos_left ha hb hc @[deprecated div_lt_div_iffβ‚€ (since := "2024-11-12")] theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := div_lt_div_iffβ‚€ b0 d0 @[deprecated div_le_div_iffβ‚€ (since := "2024-11-12")] theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≀ c / d ↔ a * d ≀ c * b := div_le_div_iffβ‚€ b0 d0 @[deprecated div_le_divβ‚€ (since := "2024-11-12")] theorem div_le_div (hc : 0 ≀ c) (hac : a ≀ c) (hd : 0 < d) (hbd : d ≀ b) : a / b ≀ c / d := div_le_divβ‚€ hc hac hd hbd @[deprecated div_lt_divβ‚€ (since := "2024-11-12")] theorem div_lt_div (hac : a < c) (hbd : d ≀ b) (c0 : 0 ≀ c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€ hac hbd c0 d0 @[deprecated div_lt_divβ‚€' (since := "2024-11-12")] theorem div_lt_div' (hac : a ≀ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€' hac hbd c0 d0 /-! ### Relating one division and involving `1` -/ @[bound] theorem div_le_self (ha : 0 ≀ a) (hb : 1 ≀ b) : a / b ≀ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb @[bound] theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb @[bound] theorem le_div_self (ha : 0 ≀ a) (hbβ‚€ : 0 < b) (hb₁ : b ≀ 1) : a ≀ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ‚€ hb₁ theorem one_le_div (hb : 0 < b) : 1 ≀ a / b ↔ b ≀ a := by rw [le_div_iffβ‚€ hb, one_mul] theorem div_le_one (hb : 0 < b) : a / b ≀ 1 ↔ a ≀ b := by rw [div_le_iffβ‚€ hb, one_mul] theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iffβ‚€ hb, one_mul] theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iffβ‚€ hb, one_mul] theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≀ b ↔ 1 / b ≀ a := by simpa using inv_le_commβ‚€ ha hb theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_commβ‚€ ha hb theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≀ 1 / b ↔ b ≀ 1 / a := by simpa using le_inv_commβ‚€ ha hb theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_commβ‚€ ha hb @[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a β†’ 1 < a / b := (one_lt_div b0).mpr @[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b β†’ a / b < 1 := (div_lt_one b0).mpr /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≀ b) : 1 / b ≀ 1 / a := by simpa using inv_antiβ‚€ ha h theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iffβ‚€' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≀ 1 / b) : b ≀ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≀ 1 / b ↔ b ≀ a := div_le_div_iff_of_pos_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_iff_of_pos_left zero_lt_one ha hb theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one] theorem one_le_one_div (h1 : 0 < a) (h2 : a ≀ 1) : 1 ≀ 1 / a := by rwa [le_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one] /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two theorem one_half_pos : (0 : Ξ±) < 1 / 2 := half_pos zero_lt_one @[simp] theorem half_le_self_iff : a / 2 ≀ a ↔ 0 ≀ a := by rw [div_le_iffβ‚€ (zero_lt_two' Ξ±), mul_two, le_add_iff_nonneg_left] @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iffβ‚€ (zero_lt_two' Ξ±), mul_two, lt_add_iff_pos_left] alias ⟨_, half_le_self⟩ := half_le_self_iff alias ⟨_, half_lt_self⟩ := half_lt_self_iff alias div_two_lt_of_pos := half_lt_self theorem one_half_lt_one : (1 / 2 : Ξ±) < 1 := half_lt_self zero_lt_one theorem two_inv_lt_one : (2⁻¹ : Ξ±) < 1 := (one_div _).symm.trans_lt one_half_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iffβ‚€, mul_two] theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iffβ‚€, mul_two] theorem add_thirds (a : Ξ±) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_leftβ‚€ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≀ d) (hc : 0 < c) : b * a ≀ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iffβ‚€ hc] theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≀ c / d) (he : 0 ≀ e) : a / (b * e) ≀ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) theorem exists_pos_mul_lt {a : Ξ±} (h : 0 < a) (b : Ξ±) : βˆƒ c : Ξ±, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iffβ‚€ this, div_div_cancelβ‚€ h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) theorem exists_pos_lt_mul {a : Ξ±} (h : 0 < a) (b : Ξ±) : βˆƒ c : Ξ±, 0 < c ∧ b < c * a := let ⟨c, hcβ‚€, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hcβ‚€, by rwa [← div_eq_inv_mul, lt_div_iffβ‚€ hcβ‚€]⟩ lemma monotone_div_right_of_nonneg (ha : 0 ≀ a) : Monotone (Β· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (Β· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : Monotone f) {c : Ξ±} (hc : 0 ≀ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf theorem StrictMono.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : StrictMono f) {c : Ξ±} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered Ξ± where dense a₁ aβ‚‚ h := ⟨(a₁ + aβ‚‚) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + aβ‚‚) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + aβ‚‚) / 2 < (aβ‚‚ + aβ‚‚) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = aβ‚‚ := add_self_div_two aβ‚‚ ⟩ theorem min_div_div_right {c : Ξ±} (hc : 0 ≀ c) (a b : Ξ±) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm theorem max_div_div_right {c : Ξ±} (hc : 0 ≀ c) (a b : Ξ±) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm theorem one_div_strictAntiOn : StrictAntiOn (fun x : Ξ± => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≀ a) {m n : β„•} (mn : m ≀ n) : 1 / a ^ n ≀ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_right_monoβ‚€ a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : β„•} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_rightβ‚€ a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ theorem one_div_pow_anti (a1 : 1 ≀ a) : Antitone fun n : β„• => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β„• => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 theorem inv_strictAntiOn : StrictAntiOn (fun x : Ξ± => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_invβ‚€ hy hx).2 xy theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≀ a) {m n : β„•} (mn : m ≀ n) : (a ^ n)⁻¹ ≀ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : β„•} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp theorem inv_pow_anti (a1 : 1 ≀ a) : Antitone fun n : β„• => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β„• => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 theorem le_iff_forall_one_lt_le_mulβ‚€ {Ξ± : Type*} [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b : Ξ±} (hb : 0 ≀ b) : a ≀ b ↔ βˆ€ Ξ΅, 1 < Ξ΅ β†’ a ≀ b * Ξ΅ := by refine ⟨fun h _ hΞ΅ ↦ h.trans <| le_mul_of_one_le_right hb hΞ΅.le, fun h ↦ ?_⟩ obtain rfl|hb := hb.eq_or_lt Β· simp_rw [zero_mul] at h exact h 2 one_lt_two refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_ convert h (x / b) ((one_lt_div hb).mpr hbx) rw [mul_div_cancelβ‚€ _ hb.ne'] /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) Β· exact (OrderIso.mulLeftβ‚€ _ ha).isGLB_image'.2 hs Β· simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton theorem IsGLB.mul_right {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha end LinearOrderedSemifield section variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d : Ξ±} {n : β„€} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] theorem div_nonneg_iff : 0 ≀ a / b ↔ 0 ≀ a ∧ 0 ≀ b ∨ a ≀ 0 ∧ b ≀ 0 := by simp [division_def, mul_nonneg_iff] theorem div_nonpos_iff : a / b ≀ 0 ↔ 0 ≀ a ∧ b ≀ 0 ∨ a ≀ 0 ∧ 0 ≀ b := by simp [division_def, mul_nonpos_iff] theorem div_nonneg_of_nonpos (ha : a ≀ 0) (hb : b ≀ 0) : 0 ≀ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≀ a ↔ a * c ≀ b := ⟨fun h => div_mul_cancelβ‚€ b (ne_of_lt hc) β–Έ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ β‰₯ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≀ a ↔ c * a ≀ b := by rw [mul_comm, div_le_iff_of_neg hc] theorem le_div_iff_of_neg (hc : c < 0) : a ≀ b / c ↔ b ≀ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iffβ‚€ (neg_pos.2 hc), neg_mul] theorem le_div_iff_of_neg' (hc : c < 0) : a ≀ b / c ↔ b ≀ c * a := by rw [mul_comm, le_div_iff_of_neg hc] theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] theorem div_le_one_of_ge (h : b ≀ a) (hb : b ≀ 0) : a / b ≀ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_leβ‚€ (neg_le_neg h) (neg_nonneg_of_nonpos hb) /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≀ b⁻¹ ↔ b ≀ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≀ b ↔ b⁻¹ ≀ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≀ b⁻¹ ↔ b ≀ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_invβ‚€ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≀ b Β· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha Β· simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≀ b Β· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha Β· simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi (Ξ± := Ξ±) exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio (Ξ± := Ξ±) exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≀ 0) (h : b ≀ a) : a / c ≀ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≀ b / c ↔ b ≀ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≀ a / b ↔ a ≀ b := by rw [le_div_iff_of_neg hb, one_mul] theorem div_le_one_of_neg (hb : b < 0) : a / b ≀ 1 ↔ b ≀ a := by rw [div_le_iff_of_neg hb, one_mul] theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≀ b ↔ 1 / b ≀ a := by simpa using inv_le_of_neg ha hb theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≀ 1 / b ↔ b ≀ 1 / a := by simpa using le_inv_of_neg ha hb theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, one_lt_div_of_neg] Β· simp [lt_irrefl, zero_le_one] Β· simp [hb, hb.not_lt, one_lt_div] theorem one_le_div_iff : 1 ≀ a / b ↔ 0 < b ∧ b ≀ a ∨ b < 0 ∧ a ≀ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, one_le_div_of_neg] Β· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one]
Β· simp [hb, hb.not_lt, one_le_div]
Mathlib/Algebra/Order/Field/Basic.lean
483
483
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne -/ import Mathlib.MeasureTheory.Integral.Bochner.Basic import Mathlib.MeasureTheory.Integral.Bochner.L1 import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Bochner.lean
1,714
1,719
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, SΓ©bastien GouΓ«zel -/ import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic /-! # Relationship between the Haar and Lebesgue measures We prove that the Haar measure and Lebesgue measure are equal on `ℝ` and on `ℝ^ΞΉ`, in `MeasureTheory.addHaarMeasure_eq_volume` and `MeasureTheory.addHaarMeasure_eq_volume_pi`. We deduce basic properties of any Haar measure on a finite dimensional real vector space: * `map_linearMap_addHaar_eq_smul_addHaar`: a linear map rescales the Haar measure by the absolute value of its determinant. * `addHaar_preimage_linearMap` : when `f` is a linear map with nonzero determinant, the measure of `f ⁻¹' s` is the measure of `s` multiplied by the absolute value of the inverse of the determinant of `f`. * `addHaar_image_linearMap` : when `f` is a linear map, the measure of `f '' s` is the measure of `s` multiplied by the absolute value of the determinant of `f`. * `addHaar_submodule` : a strict submodule has measure `0`. * `addHaar_smul` : the measure of `r β€’ s` is `|r| ^ dim * ΞΌ s`. * `addHaar_ball`: the measure of `ball x r` is `r ^ dim * ΞΌ (ball 0 1)`. * `addHaar_closedBall`: the measure of `closedBall x r` is `r ^ dim * ΞΌ (ball 0 1)`. * `addHaar_sphere`: spheres have zero measure. This makes it possible to associate a Lebesgue measure to an `n`-alternating map in dimension `n`. This measure is called `AlternatingMap.measure`. Its main property is `Ο‰.measure_parallelepiped v`, stating that the associated measure of the parallelepiped spanned by vectors `v₁, ..., vβ‚™` is given by `|Ο‰ v|`. We also show that a Lebesgue density point `x` of a set `s` (with respect to closed balls) has density one for the rescaled copies `{x} + r β€’ t` of a given set `t` with positive measure, in `tendsto_addHaar_inter_smul_one_of_density_one`. In particular, `s` intersects `{x} + r β€’ t` for small `r`, see `eventually_nonempty_inter_smul_of_density_one`. Statements on integrals of functions with respect to an additive Haar measure can be found in `MeasureTheory.Measure.Haar.NormedSpace`. -/ assert_not_exists MeasureTheory.integral open TopologicalSpace Set Filter Metric Bornology open scoped ENNReal Pointwise Topology NNReal /-- The interval `[0,1]` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.Icc01 : PositiveCompacts ℝ where carrier := Icc 0 1 isCompact' := isCompact_Icc interior_nonempty' := by simp_rw [interior_Icc, nonempty_Ioo, zero_lt_one] universe u /-- The set `[0,1]^ΞΉ` as a compact set with non-empty interior. -/ def TopologicalSpace.PositiveCompacts.piIcc01 (ΞΉ : Type*) [Finite ΞΉ] : PositiveCompacts (ΞΉ β†’ ℝ) where carrier := pi univ fun _ => Icc 0 1 isCompact' := isCompact_univ_pi fun _ => isCompact_Icc interior_nonempty' := by simp only [interior_pi_set, Set.toFinite, interior_Icc, univ_pi_nonempty_iff, nonempty_Ioo, imp_true_iff, zero_lt_one] /-- The parallelepiped formed from the standard basis for `ΞΉ β†’ ℝ` is `[0,1]^ΞΉ` -/ theorem Basis.parallelepiped_basisFun (ΞΉ : Type*) [Fintype ΞΉ] : (Pi.basisFun ℝ ΞΉ).parallelepiped = TopologicalSpace.PositiveCompacts.piIcc01 ΞΉ := SetLike.coe_injective <| by refine Eq.trans ?_ ((uIcc_of_le ?_).trans (Set.pi_univ_Icc _ _).symm) Β· classical convert parallelepiped_single (ΞΉ := ΞΉ) 1 Β· exact zero_le_one /-- A parallelepiped can be expressed on the standard basis. -/ theorem Basis.parallelepiped_eq_map {ΞΉ E : Type*} [Fintype ΞΉ] [NormedAddCommGroup E] [NormedSpace ℝ E] (b : Basis ΞΉ ℝ E) : b.parallelepiped = (PositiveCompacts.piIcc01 ΞΉ).map b.equivFun.symm b.equivFunL.symm.continuous b.equivFunL.symm.isOpenMap := by classical rw [← Basis.parallelepiped_basisFun, ← Basis.parallelepiped_map] congr with x simp [Pi.single_apply] open MeasureTheory MeasureTheory.Measure theorem Basis.map_addHaar {ΞΉ E F : Type*} [Fintype ΞΉ] [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace ℝ E] [NormedSpace ℝ F] [MeasurableSpace E] [MeasurableSpace F] [BorelSpace E] [BorelSpace F] [SecondCountableTopology F] [SigmaCompactSpace F] (b : Basis ΞΉ ℝ E) (f : E ≃L[ℝ] F) : map f b.addHaar = (b.map f.toLinearEquiv).addHaar := by have : IsAddHaarMeasure (map f b.addHaar) := AddEquiv.isAddHaarMeasure_map b.addHaar f.toAddEquiv f.continuous f.symm.continuous rw [eq_comm, Basis.addHaar_eq_iff, Measure.map_apply f.continuous.measurable (PositiveCompacts.isCompact _).measurableSet, Basis.coe_parallelepiped, Basis.coe_map] erw [← image_parallelepiped, f.toEquiv.preimage_image, addHaar_self] namespace MeasureTheory open Measure TopologicalSpace.PositiveCompacts Module /-! ### The Lebesgue measure is a Haar measure on `ℝ` and on `ℝ^ΞΉ`. -/ /-- The Haar measure equals the Lebesgue measure on `ℝ`. -/ theorem addHaarMeasure_eq_volume : addHaarMeasure Icc01 = volume := by convert (addHaarMeasure_unique volume Icc01).symm; simp [Icc01] /-- The Haar measure equals the Lebesgue measure on `ℝ^ΞΉ`. -/ theorem addHaarMeasure_eq_volume_pi (ΞΉ : Type*) [Fintype ΞΉ] : addHaarMeasure (piIcc01 ΞΉ) = volume := by convert (addHaarMeasure_unique volume (piIcc01 ΞΉ)).symm simp only [piIcc01, volume_pi_pi fun _ => Icc (0 : ℝ) 1, PositiveCompacts.coe_mk, Compacts.coe_mk, Finset.prod_const_one, ENNReal.ofReal_one, Real.volume_Icc, one_smul, sub_zero] theorem isAddHaarMeasure_volume_pi (ΞΉ : Type*) [Fintype ΞΉ] : IsAddHaarMeasure (volume : Measure (ΞΉ β†’ ℝ)) := inferInstance namespace Measure /-! ### Strict subspaces have zero measure -/ open scoped Function -- required for scoped `on` notation /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. This auxiliary lemma proves this assuming additionally that the set is bounded. -/ theorem addHaar_eq_zero_of_disjoint_translates_aux {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] {s : Set E} (u : β„• β†’ E) (sb : IsBounded s) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : ΞΌ s = 0 := by by_contra h apply lt_irrefl ∞ calc ∞ = βˆ‘' _ : β„•, ΞΌ s := (ENNReal.tsum_const_eq_top_of_ne_zero h).symm _ = βˆ‘' n : β„•, ΞΌ ({u n} + s) := by congr 1; ext1 n; simp only [image_add_left, measure_preimage_add, singleton_add] _ = ΞΌ (⋃ n, {u n} + s) := Eq.symm <| measure_iUnion hs fun n => by simpa only [image_add_left, singleton_add] using measurable_id.const_add _ h's _ = ΞΌ (range u + s) := by rw [← iUnion_add, iUnion_singleton_eq_range] _ < ∞ := (hu.add sb).measure_lt_top /-- If a set is disjoint of its translates by infinitely many bounded vectors, then it has measure zero. -/ theorem addHaar_eq_zero_of_disjoint_translates {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] {s : Set E} (u : β„• β†’ E) (hu : IsBounded (range u)) (hs : Pairwise (Disjoint on fun n => {u n} + s)) (h's : MeasurableSet s) : ΞΌ s = 0 := by suffices H : βˆ€ R, ΞΌ (s ∩ closedBall 0 R) = 0 by apply le_antisymm _ (zero_le _) calc ΞΌ s ≀ βˆ‘' n : β„•, ΞΌ (s ∩ closedBall 0 n) := by conv_lhs => rw [← iUnion_inter_closedBall_nat s 0] exact measure_iUnion_le _ _ = 0 := by simp only [H, tsum_zero] intro R apply addHaar_eq_zero_of_disjoint_translates_aux ΞΌ u (isBounded_closedBall.subset inter_subset_right) hu _ (h's.inter measurableSet_closedBall) refine pairwise_disjoint_mono hs fun n => ?_ exact add_subset_add Subset.rfl inter_subset_left /-- A strict vector subspace has measure zero. -/ theorem addHaar_submodule {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (s : Submodule ℝ E) (hs : s β‰  ⊀) : ΞΌ s = 0 := by obtain ⟨x, hx⟩ : βˆƒ x, x βˆ‰ s := by simpa only [Submodule.eq_top_iff', not_exists, Ne, not_forall] using hs obtain ⟨c, cpos, cone⟩ : βˆƒ c : ℝ, 0 < c ∧ c < 1 := ⟨1 / 2, by norm_num, by norm_num⟩ have A : IsBounded (range fun n : β„• => c ^ n β€’ x) := have : Tendsto (fun n : β„• => c ^ n β€’ x) atTop (𝓝 ((0 : ℝ) β€’ x)) := (tendsto_pow_atTop_nhds_zero_of_lt_one cpos.le cone).smul_const x isBounded_range_of_tendsto _ this apply addHaar_eq_zero_of_disjoint_translates ΞΌ _ A _ (Submodule.closed_of_finiteDimensional s).measurableSet intro m n hmn simp only [Function.onFun, image_add_left, singleton_add, disjoint_left, mem_preimage, SetLike.mem_coe] intro y hym hyn have A : (c ^ n - c ^ m) β€’ x ∈ s := by convert s.sub_mem hym hyn using 1 simp only [sub_smul, neg_sub_neg, add_sub_add_right_eq_sub] have H : c ^ n - c ^ m β‰  0 := by simpa only [sub_eq_zero, Ne] using (pow_right_strictAntiβ‚€ cpos cone).injective.ne hmn.symm have : x ∈ s := by convert s.smul_mem (c ^ n - c ^ m)⁻¹ A rw [smul_smul, inv_mul_cancelβ‚€ H, one_smul] exact hx this /-- A strict affine subspace has measure zero. -/ theorem addHaar_affineSubspace {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (s : AffineSubspace ℝ E) (hs : s β‰  ⊀) : ΞΌ s = 0 := by rcases s.eq_bot_or_nonempty with (rfl | hne) Β· rw [AffineSubspace.bot_coe, measure_empty] rw [Ne, ← AffineSubspace.direction_eq_top_iff_of_nonempty hne] at hs rcases hne with ⟨x, hx : x ∈ s⟩ simpa only [AffineSubspace.coe_direction_eq_vsub_set_right hx, vsub_eq_sub, sub_eq_add_neg, image_add_right, neg_neg, measure_preimage_add_right] using addHaar_submodule ΞΌ s.direction hs /-! ### Applying a linear map rescales Haar measure by the determinant We first prove this on `ΞΉ β†’ ℝ`, using that this is already known for the product Lebesgue measure (thanks to matrices computations). Then, we extend this to any finite-dimensional real vector space by using a linear equiv with a space of the form `ΞΉ β†’ ℝ`, and arguing that such a linear equiv maps Haar measure to Haar measure. -/ theorem map_linearMap_addHaar_pi_eq_smul_addHaar {ΞΉ : Type*} [Finite ΞΉ] {f : (ΞΉ β†’ ℝ) β†’β‚—[ℝ] ΞΉ β†’ ℝ} (hf : LinearMap.det f β‰  0) (ΞΌ : Measure (ΞΉ β†’ ℝ)) [IsAddHaarMeasure ΞΌ] : Measure.map f ΞΌ = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) β€’ ΞΌ := by cases nonempty_fintype ΞΉ /- We have already proved the result for the Lebesgue product measure, using matrices. We deduce it for any Haar measure by uniqueness (up to scalar multiplication). -/ have := addHaarMeasure_unique ΞΌ (piIcc01 ΞΉ) rw [this, addHaarMeasure_eq_volume_pi, Measure.map_smul, Real.map_linearMap_volume_pi_eq_smul_volume_pi hf, smul_comm] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] theorem map_linearMap_addHaar_eq_smul_addHaar {f : E β†’β‚—[ℝ] E} (hf : LinearMap.det f β‰  0) : Measure.map f ΞΌ = ENNReal.ofReal |(LinearMap.det f)⁻¹| β€’ ΞΌ := by -- we reduce to the case of `E = ΞΉ β†’ ℝ`, for which we have already proved the result using -- matrices in `map_linearMap_addHaar_pi_eq_smul_addHaar`. let ΞΉ := Fin (finrank ℝ E) haveI : FiniteDimensional ℝ (ΞΉ β†’ ℝ) := by infer_instance have : finrank ℝ E = finrank ℝ (ΞΉ β†’ ℝ) := by simp [ΞΉ] have e : E ≃ₗ[ℝ] ΞΉ β†’ ℝ := LinearEquiv.ofFinrankEq E (ΞΉ β†’ ℝ) this -- next line is to avoid `g` getting reduced by `simp`. obtain ⟨g, hg⟩ : βˆƒ g, g = (e : E β†’β‚—[ℝ] ΞΉ β†’ ℝ).comp (f.comp (e.symm : (ΞΉ β†’ ℝ) β†’β‚—[ℝ] E)) := ⟨_, rfl⟩ have gdet : LinearMap.det g = LinearMap.det f := by rw [hg]; exact LinearMap.det_conj f e rw [← gdet] at hf ⊒ have fg : f = (e.symm : (ΞΉ β†’ ℝ) β†’β‚—[ℝ] E).comp (g.comp (e : E β†’β‚—[ℝ] ΞΉ β†’ ℝ)) := by ext x simp only [LinearEquiv.coe_coe, Function.comp_apply, LinearMap.coe_comp, LinearEquiv.symm_apply_apply, hg] simp only [fg, LinearEquiv.coe_coe, LinearMap.coe_comp] have Ce : Continuous e := (e : E β†’β‚—[ℝ] ΞΉ β†’ ℝ).continuous_of_finiteDimensional have Cg : Continuous g := LinearMap.continuous_of_finiteDimensional g have Cesymm : Continuous e.symm := (e.symm : (ΞΉ β†’ ℝ) β†’β‚—[ℝ] E).continuous_of_finiteDimensional rw [← map_map Cesymm.measurable (Cg.comp Ce).measurable, ← map_map Cg.measurable Ce.measurable] haveI : IsAddHaarMeasure (map e ΞΌ) := (e : E ≃+ (ΞΉ β†’ ℝ)).isAddHaarMeasure_map ΞΌ Ce Cesymm have ecomp : e.symm ∘ e = id := by ext x; simp only [id, Function.comp_apply, LinearEquiv.symm_apply_apply] rw [map_linearMap_addHaar_pi_eq_smul_addHaar hf (map e ΞΌ), Measure.map_smul, map_map Cesymm.measurable Ce.measurable, ecomp, Measure.map_id] /-- The preimage of a set `s` under a linear map `f` with nonzero determinant has measure equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearMap {f : E β†’β‚—[ℝ] E} (hf : LinearMap.det f β‰  0) (s : Set E) : ΞΌ (f ⁻¹' s) = ENNReal.ofReal |(LinearMap.det f)⁻¹| * ΞΌ s := calc ΞΌ (f ⁻¹' s) = Measure.map f ΞΌ s := ((f.equivOfDetNeZero hf).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal |(LinearMap.det f)⁻¹| * ΞΌ s := by rw [map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf]; rfl /-- The preimage of a set `s` under a continuous linear map `f` with nonzero determinant has measure equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearMap {f : E β†’L[ℝ] E} (hf : LinearMap.det (f : E β†’β‚—[ℝ] E) β‰  0) (s : Set E) : ΞΌ (f ⁻¹' s) = ENNReal.ofReal (abs (LinearMap.det (f : E β†’β‚—[ℝ] E))⁻¹) * ΞΌ s := addHaar_preimage_linearMap ΞΌ hf s /-- The preimage of a set `s` under a linear equiv `f` has measure equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_linearEquiv (f : E ≃ₗ[ℝ] E) (s : Set E) : ΞΌ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E β†’β‚—[ℝ] E)| * ΞΌ s := by have A : LinearMap.det (f : E β†’β‚—[ℝ] E) β‰  0 := (LinearEquiv.isUnit_det' f).ne_zero convert addHaar_preimage_linearMap ΞΌ A s simp only [LinearEquiv.det_coe_symm] /-- The preimage of a set `s` under a continuous linear equiv `f` has measure equal to `ΞΌ s` times the absolute value of the inverse of the determinant of `f`. -/ @[simp] theorem addHaar_preimage_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : ΞΌ (f ⁻¹' s) = ENNReal.ofReal |LinearMap.det (f.symm : E β†’β‚—[ℝ] E)| * ΞΌ s := addHaar_preimage_linearEquiv ΞΌ _ s /-- The image of a set `s` under a linear map `f` has measure equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_linearMap (f : E β†’β‚—[ℝ] E) (s : Set E) : ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det f| * ΞΌ s := by rcases ne_or_eq (LinearMap.det f) 0 with (hf | hf) Β· let g := (f.equivOfDetNeZero hf).toContinuousLinearEquiv change ΞΌ (g '' s) = _ rw [ContinuousLinearEquiv.image_eq_preimage g s, addHaar_preimage_continuousLinearEquiv] congr Β· simp only [hf, zero_mul, ENNReal.ofReal_zero, abs_zero] have : ΞΌ (LinearMap.range f) = 0 := addHaar_submodule ΞΌ _ (LinearMap.range_lt_top_of_det_eq_zero hf).ne exact le_antisymm (le_trans (measure_mono (image_subset_range _ _)) this.le) (zero_le _) /-- The image of a set `s` under a continuous linear map `f` has measure equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearMap (f : E β†’L[ℝ] E) (s : Set E) : ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E β†’β‚—[ℝ] E)| * ΞΌ s := addHaar_image_linearMap ΞΌ _ s /-- The image of a set `s` under a continuous linear equiv `f` has measure equal to `ΞΌ s` times the absolute value of the determinant of `f`. -/ @[simp] theorem addHaar_image_continuousLinearEquiv (f : E ≃L[ℝ] E) (s : Set E) : ΞΌ (f '' s) = ENNReal.ofReal |LinearMap.det (f : E β†’β‚—[ℝ] E)| * ΞΌ s := ΞΌ.addHaar_image_linearMap (f : E β†’β‚—[ℝ] E) s theorem LinearMap.quasiMeasurePreserving (f : E β†’β‚—[ℝ] E) (hf : LinearMap.det f β‰  0) : QuasiMeasurePreserving f ΞΌ ΞΌ := by refine ⟨f.continuous_of_finiteDimensional.measurable, ?_⟩ rw [map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf] exact smul_absolutelyContinuous theorem ContinuousLinearMap.quasiMeasurePreserving (f : E β†’L[ℝ] E) (hf : f.det β‰  0) : QuasiMeasurePreserving f ΞΌ ΞΌ := LinearMap.quasiMeasurePreserving ΞΌ (f : E β†’β‚—[ℝ] E) hf /-! ### Basic properties of Haar measures on real vector spaces -/ theorem map_addHaar_smul {r : ℝ} (hr : r β‰  0) : Measure.map (r β€’ Β·) ΞΌ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) β€’ ΞΌ := by let f : E β†’β‚—[ℝ] E := r β€’ (1 : E β†’β‚—[ℝ] E) change Measure.map f ΞΌ = _ have hf : LinearMap.det f β‰  0 := by simp only [f, mul_one, LinearMap.det_smul, Ne, MonoidHom.map_one] intro h exact hr (pow_eq_zero h) simp only [f, map_linearMap_addHaar_eq_smul_addHaar ΞΌ hf, mul_one, LinearMap.det_smul, map_one] theorem quasiMeasurePreserving_smul {r : ℝ} (hr : r β‰  0) : QuasiMeasurePreserving (r β€’ Β·) ΞΌ ΞΌ := by refine ⟨measurable_const_smul r, ?_⟩ rw [map_addHaar_smul ΞΌ hr] exact smul_absolutelyContinuous @[simp] theorem addHaar_preimage_smul {r : ℝ} (hr : r β‰  0) (s : Set E) : ΞΌ ((r β€’ Β·) ⁻¹' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * ΞΌ s := calc ΞΌ ((r β€’ Β·) ⁻¹' s) = Measure.map (r β€’ Β·) ΞΌ s := ((Homeomorph.smul (isUnit_iff_ne_zero.2 hr).unit).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)⁻¹) * ΞΌ s := by rw [map_addHaar_smul ΞΌ hr, coe_smul, Pi.smul_apply, smul_eq_mul] /-- Rescaling a set by a factor `r` multiplies its measure by `abs (r ^ dim)`. -/ @[simp] theorem addHaar_smul (r : ℝ) (s : Set E) : ΞΌ (r β€’ s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * ΞΌ s := by rcases ne_or_eq r 0 with (h | rfl) Β· rw [← preimage_smul_invβ‚€ h, addHaar_preimage_smul ΞΌ (inv_ne_zero h), inv_pow, inv_inv] rcases eq_empty_or_nonempty s with (rfl | hs) Β· simp only [measure_empty, mul_zero, smul_set_empty] rw [zero_smul_set hs, ← singleton_zero] by_cases h : finrank ℝ E = 0 Β· haveI : Subsingleton E := finrank_zero_iff.1 h simp only [h, one_mul, ENNReal.ofReal_one, abs_one, Subsingleton.eq_univ_of_nonempty hs, pow_zero, Subsingleton.eq_univ_of_nonempty (singleton_nonempty (0 : E))] Β· haveI : Nontrivial E := nontrivial_of_finrank_pos (bot_lt_iff_ne_bot.2 h) simp only [h, zero_mul, ENNReal.ofReal_zero, abs_zero, Ne, not_false_iff, zero_pow, measure_singleton] theorem addHaar_smul_of_nonneg {r : ℝ} (hr : 0 ≀ r) (s : Set E) : ΞΌ (r β€’ s) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ s := by rw [addHaar_smul, abs_pow, abs_of_nonneg hr] variable {ΞΌ} {s : Set E} -- Note: We might want to rename this once we acquire the lemma corresponding to -- `MeasurableSet.const_smul` theorem NullMeasurableSet.const_smul (hs : NullMeasurableSet s ΞΌ) (r : ℝ) : NullMeasurableSet (r β€’ s) ΞΌ := by obtain rfl | hs' := s.eq_empty_or_nonempty Β· simp obtain rfl | hr := eq_or_ne r 0 Β· simpa [zero_smul_set hs'] using nullMeasurableSet_singleton _ obtain ⟨t, ht, hst⟩ := hs refine ⟨_, ht.const_smul_of_ne_zero hr, ?_⟩ rw [← measure_symmDiff_eq_zero_iff] at hst ⊒ rw [← smul_set_symmDiffβ‚€ hr, addHaar_smul ΞΌ, hst, mul_zero] variable (ΞΌ) @[simp] theorem addHaar_image_homothety (x : E) (r : ℝ) (s : Set E) : ΞΌ (AffineMap.homothety x r '' s) = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * ΞΌ s := calc ΞΌ (AffineMap.homothety x r '' s) = ΞΌ ((fun y => y + x) '' (r β€’ (fun y => y + -x) '' s)) := by simp only [← image_smul, image_image, ← sub_eq_add_neg]; rfl _ = ENNReal.ofReal (abs (r ^ finrank ℝ E)) * ΞΌ s := by simp only [image_add_right, measure_preimage_add_right, addHaar_smul] /-! We don't need to state `map_addHaar_neg` here, because it has already been proved for general Haar measures on general commutative groups. -/ /-! ### Measure of balls -/ theorem addHaar_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : ℝ) : ΞΌ (ball x r) = ΞΌ (ball (0 : E) r) := by have : ball (0 : E) r = (x + Β·) ⁻¹' ball x r := by simp [preimage_add_ball] rw [this, measure_preimage_add] theorem addHaar_real_ball_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : ℝ) : ΞΌ.real (ball x r) = ΞΌ.real (ball (0 : E) r) := by simp [measureReal_def, addHaar_ball_center] theorem addHaar_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : ℝ) : ΞΌ (closedBall x r) = ΞΌ (closedBall (0 : E) r) := by have : closedBall (0 : E) r = (x + Β·) ⁻¹' closedBall x r := by simp [preimage_add_closedBall] rw [this, measure_preimage_add] theorem addHaar_real_closedBall_center {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] [BorelSpace E] (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] (x : E) (r : ℝ) : ΞΌ.real (closedBall x r) = ΞΌ.real (closedBall (0 : E) r) := by simp [measureReal_def, addHaar_closedBall_center] theorem addHaar_ball_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : ΞΌ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ (ball 0 s) := by have : ball (0 : E) (r * s) = r β€’ ball (0 : E) s := by simp only [_root_.smul_ball hr.ne' (0 : E) s, Real.norm_eq_abs, abs_of_nonneg hr.le, smul_zero] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_ball_center, abs_pow] theorem addHaar_ball_of_pos (x : E) {r : ℝ} (hr : 0 < r) : ΞΌ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ (ball 0 1) := by rw [← addHaar_ball_mul_of_pos ΞΌ x hr, mul_one] theorem addHaar_ball_mul [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≀ r) (s : ℝ) : ΞΌ (ball x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ (ball 0 s) := by rcases hr.eq_or_lt with (rfl | h) Β· simp only [zero_pow (finrank_pos (R := ℝ) (M := E)).ne', measure_empty, zero_mul, ENNReal.ofReal_zero, ball_zero] Β· exact addHaar_ball_mul_of_pos ΞΌ x h s theorem addHaar_ball [Nontrivial E] (x : E) {r : ℝ} (hr : 0 ≀ r) : ΞΌ (ball x r) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ (ball 0 1) := by rw [← addHaar_ball_mul ΞΌ x hr, mul_one]
theorem addHaar_closedBall_mul_of_pos (x : E) {r : ℝ} (hr : 0 < r) (s : ℝ) : ΞΌ (closedBall x (r * s)) = ENNReal.ofReal (r ^ finrank ℝ E) * ΞΌ (closedBall 0 s) := by have : closedBall (0 : E) (r * s) = r β€’ closedBall (0 : E) s := by simp [smul_closedBall' hr.ne' (0 : E), abs_of_nonneg hr.le]
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
454
458
/- Copyright (c) 2023 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.Topology.Connected.Basic import Mathlib.Topology.Separation.Hausdorff import Mathlib.Topology.Connected.Clopen /-! # Separated maps and locally injective maps out of a topological space. This module introduces a pair of dual notions `IsSeparatedMap` and `IsLocallyInjective`. A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. A constant function is a separated map if and only if `X` is a `T2Space`. A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. A constant function is locally injective if and only if `X` is discrete. Given `f : X β†’ Y` we can form the pullback $X \times_Y X$; the diagonal map $\Delta: X \to X \times_Y X$ is always an embedding. It is a closed embedding iff `f` is a separated map, iff the equal locus of any two continuous maps coequalized by `f` is closed. It is an open embedding iff `f` is locally injective, iff any such equal locus is open. Therefore, if `f` is a locally injective separated map, the equal locus of two continuous maps coequalized by `f` is clopen, so if the two maps agree on a point, then they agree on the whole connected component. The analogue of separated maps and locally injective maps in algebraic geometry are separated morphisms and unramified morphisms, respectively. ## Reference https://stacks.math.columbia.edu/tag/0CY0 -/ open Topology variable {X Y A} [TopologicalSpace X] [TopologicalSpace A] protected lemma Topology.IsEmbedding.toPullbackDiag (f : X β†’ Y) : IsEmbedding (toPullbackDiag f) := .mk' _ (injective_toPullbackDiag f) fun x ↦ by simp [nhds_induced, Filter.comap_comap, nhds_prod_eq, Filter.comap_prod, Function.comp_def, Filter.comap_id'] @[deprecated (since := "2024-10-26")] alias embedding_toPullbackDiag := IsEmbedding.toPullbackDiag lemma Continuous.mapPullback {X₁ Xβ‚‚ Y₁ Yβ‚‚ Z₁ Zβ‚‚} [TopologicalSpace X₁] [TopologicalSpace Xβ‚‚] [TopologicalSpace Z₁] [TopologicalSpace Zβ‚‚] {f₁ : X₁ β†’ Y₁} {g₁ : Z₁ β†’ Y₁} {fβ‚‚ : Xβ‚‚ β†’ Yβ‚‚} {gβ‚‚ : Zβ‚‚ β†’ Yβ‚‚} {mapX : X₁ β†’ Xβ‚‚} (contX : Continuous mapX) {mapY : Y₁ β†’ Yβ‚‚} {mapZ : Z₁ β†’ Zβ‚‚} (contZ : Continuous mapZ) {commX : fβ‚‚ ∘ mapX = mapY ∘ f₁} {commZ : gβ‚‚ ∘ mapZ = mapY ∘ g₁} : Continuous (Function.mapPullback mapX mapY mapZ commX commZ) := by refine continuous_induced_rng.mpr (.prodMk ?_ ?_) <;> apply_rules [continuous_fst, continuous_snd, continuous_subtype_val, Continuous.comp] /-- A function from a topological space `X` to a type `Y` is a separated map if any two distinct points in `X` with the same image in `Y` can be separated by open neighborhoods. -/ def IsSeparatedMap (f : X β†’ Y) : Prop := βˆ€ x₁ xβ‚‚, f x₁ = f xβ‚‚ β†’ x₁ β‰  xβ‚‚ β†’ βˆƒ s₁ sβ‚‚, IsOpen s₁ ∧ IsOpen sβ‚‚ ∧ x₁ ∈ s₁ ∧ xβ‚‚ ∈ sβ‚‚ ∧ Disjoint s₁ sβ‚‚ lemma t2space_iff_isSeparatedMap (y : Y) : T2Space X ↔ IsSeparatedMap fun _ : X ↦ y := ⟨fun ⟨t2⟩ _ _ _ hne ↦ t2 hne, fun sep ↦ ⟨fun x₁ xβ‚‚ hne ↦ sep x₁ xβ‚‚ rfl hne⟩⟩ lemma T2Space.isSeparatedMap [T2Space X] (f : X β†’ Y) : IsSeparatedMap f := fun _ _ _ ↦ t2_separation lemma Function.Injective.isSeparatedMap {f : X β†’ Y} (inj : f.Injective) : IsSeparatedMap f := fun _ _ he hne ↦ (hne (inj he)).elim lemma isSeparatedMap_iff_disjoint_nhds {f : X β†’ Y} : IsSeparatedMap f ↔ βˆ€ x₁ xβ‚‚, f x₁ = f xβ‚‚ β†’ x₁ β‰  xβ‚‚ β†’ Disjoint (𝓝 x₁) (𝓝 xβ‚‚) := forall₃_congr fun x x' _ ↦ by simp only [(nhds_basis_opens x).disjoint_iff (nhds_basis_opens x'), exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] lemma isSeparatedMap_iff_nhds {f : X β†’ Y} : IsSeparatedMap f ↔ βˆ€ x₁ xβ‚‚, f x₁ = f xβ‚‚ β†’ x₁ β‰  xβ‚‚ β†’ βˆƒ s₁ ∈ 𝓝 x₁, βˆƒ sβ‚‚ ∈ 𝓝 xβ‚‚, Disjoint s₁ sβ‚‚ := by simp_rw [isSeparatedMap_iff_disjoint_nhds, Filter.disjoint_iff] open Set Filter in theorem isSeparatedMap_iff_isClosed_diagonal {f : X β†’ Y} : IsSeparatedMap f ↔ IsClosed f.pullbackDiagonal := by simp_rw [isSeparatedMap_iff_nhds, ← isOpen_compl_iff, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq] refine forallβ‚„_congr fun x₁ xβ‚‚ _ _ ↦ ⟨fun h ↦ ?_, fun ⟨t, ht, t_sub⟩ ↦ ?_⟩ Β· simp_rw [← Filter.disjoint_iff, ← compl_diagonal_mem_prod] at h exact ⟨_, h, subset_rfl⟩ Β· obtain ⟨s₁, h₁, sβ‚‚, hβ‚‚, s_sub⟩ := mem_prod_iff.mp ht exact ⟨s₁, h₁, sβ‚‚, hβ‚‚, disjoint_left.2 fun x h₁ hβ‚‚ ↦ @t_sub ⟨(x, x), rfl⟩ (s_sub ⟨h₁, hβ‚‚βŸ©) rfl⟩ theorem isSeparatedMap_iff_isClosedEmbedding {f : X β†’ Y} : IsSeparatedMap f ↔ IsClosedEmbedding (toPullbackDiag f) := by rw [isSeparatedMap_iff_isClosed_diagonal, ← range_toPullbackDiag] exact ⟨fun h ↦ ⟨.toPullbackDiag f, h⟩, fun h ↦ h.isClosed_range⟩ theorem isSeparatedMap_iff_isClosedMap {f : X β†’ Y} : IsSeparatedMap f ↔ IsClosedMap (toPullbackDiag f) := isSeparatedMap_iff_isClosedEmbedding.trans ⟨IsClosedEmbedding.isClosedMap, .of_continuous_injective_isClosedMap (IsEmbedding.toPullbackDiag f).continuous (injective_toPullbackDiag f)⟩ open Function.Pullback in theorem IsSeparatedMap.pullback {f : X β†’ Y} (sep : IsSeparatedMap f) (g : A β†’ Y) : IsSeparatedMap (@snd X Y A f g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊒ rw [← preimage_map_fst_pullbackDiagonal] refine sep.preimage (Continuous.mapPullback ?_ ?_) <;> apply_rules [continuous_fst, continuous_subtype_val, Continuous.comp] theorem IsSeparatedMap.comp_left {A} {f : X β†’ Y} (sep : IsSeparatedMap f) {g : Y β†’ A} (inj : g.Injective) : IsSeparatedMap (g ∘ f) := fun x₁ xβ‚‚ he ↦ sep x₁ xβ‚‚ (inj he) theorem IsSeparatedMap.comp_right {f : X β†’ Y} (sep : IsSeparatedMap f) {g : A β†’ X} (cont : Continuous g) (inj : g.Injective) : IsSeparatedMap (f ∘ g) := by rw [isSeparatedMap_iff_isClosed_diagonal] at sep ⊒ rw [← inj.preimage_pullbackDiagonal] exact sep.preimage (cont.mapPullback cont) /-- A function from a topological space `X` is locally injective if every point of `X` has a neighborhood on which `f` is injective. -/ def IsLocallyInjective (f : X β†’ Y) : Prop := βˆ€ x : X, βˆƒ U, IsOpen U ∧ x ∈ U ∧ U.InjOn f lemma Function.Injective.IsLocallyInjective {f : X β†’ Y} (inj : f.Injective) : IsLocallyInjective f := fun _ ↦ ⟨_, isOpen_univ, trivial, fun _ _ _ _ ↦ @inj _ _⟩ lemma isLocallyInjective_iff_nhds {f : X β†’ Y} : IsLocallyInjective f ↔ βˆ€ x : X, βˆƒ U ∈ 𝓝 x, U.InjOn f := by constructor <;> intro h x Β· obtain ⟨U, ho, hm, hi⟩ := h x; exact ⟨U, ho.mem_nhds hm, hi⟩ Β· obtain ⟨U, hn, hi⟩ := h x exact ⟨interior U, isOpen_interior, mem_interior_iff_mem_nhds.mpr hn, hi.mono interior_subset⟩ theorem isLocallyInjective_iff_isOpen_diagonal {f : X β†’ Y} : IsLocallyInjective f ↔ IsOpen f.pullbackDiagonal := by simp_rw [isLocallyInjective_iff_nhds, isOpen_iff_mem_nhds, Subtype.forall, Prod.forall, nhds_induced, nhds_prod_eq, Filter.mem_comap] refine ⟨?_, fun h x ↦ ?_⟩ Β· rintro h x x' hx (rfl : x = x') obtain ⟨U, hn, hi⟩ := h x exact ⟨_, Filter.prod_mem_prod hn hn, fun {p} hp ↦ hi hp.1 hp.2 p.2⟩ Β· obtain ⟨t, ht, t_sub⟩ := h x x rfl rfl
obtain ⟨t₁, h₁, tβ‚‚, hβ‚‚, prod_sub⟩ := Filter.mem_prod_iff.mp ht exact ⟨t₁ ∩ tβ‚‚, Filter.inter_mem h₁ hβ‚‚, fun x₁ h₁ xβ‚‚ hβ‚‚ he ↦ @t_sub ⟨(x₁, xβ‚‚), he⟩ (prod_sub ⟨h₁.1, hβ‚‚.2⟩)⟩
Mathlib/Topology/SeparatedMap.lean
144
147
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Kexing Ying, Eric Wieser -/ import Mathlib.Data.Finset.Sym import Mathlib.LinearAlgebra.BilinearMap import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.SesquilinearForm import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Quadratic maps This file defines quadratic maps on an `R`-module `M`, taking values in an `R`-module `N`. An `N`-valued quadratic map on a module `M` over a commutative ring `R` is a map `Q : M β†’ N` such that: * `QuadraticMap.map_smul`: `Q (a β€’ x) = (a * a) β€’ Q x` * `QuadraticMap.polar_add_left`, `QuadraticMap.polar_add_right`, `QuadraticMap.polar_smul_left`, `QuadraticMap.polar_smul_right`: the map `QuadraticMap.polar Q := fun x y ↦ Q (x + y) - Q x - Q y` is bilinear. This notion generalizes to commutative semirings using the approach in [izhakian2016][] which requires that there be a (possibly non-unique) companion bilinear map `B` such that `βˆ€ x y, Q (x + y) = Q x + Q y + B x y`. Over a ring, this `B` is precisely `QuadraticMap.polar Q`. To build a `QuadraticMap` from the `polar` axioms, use `QuadraticMap.ofPolar`. Quadratic maps come with a scalar multiplication, `(a β€’ Q) x = a β€’ Q x`, and composition with linear maps `f`, `Q.comp f x = Q (f x)`. ## Main definitions * `QuadraticMap.ofPolar`: a more familiar constructor that works on rings * `QuadraticMap.associated`: associated bilinear map * `QuadraticMap.PosDef`: positive definite quadratic maps * `QuadraticMap.Anisotropic`: anisotropic quadratic maps * `QuadraticMap.discr`: discriminant of a quadratic map * `QuadraticMap.IsOrtho`: orthogonality of vectors with respect to a quadratic map. ## Main statements * `QuadraticMap.associated_left_inverse`, * `QuadraticMap.associated_rightInverse`: in a commutative ring where 2 has an inverse, there is a correspondence between quadratic maps and symmetric bilinear forms * `LinearMap.BilinForm.exists_orthogonal_basis`: There exists an orthogonal basis with respect to any nondegenerate, symmetric bilinear map `B`. ## Notation In this file, the variable `R` is used when a `CommSemiring` structure is available. The variable `S` is used when `R` itself has a `β€’` action. ## Implementation notes While the definition and many results make sense if we drop commutativity assumptions, the correct definition of a quadratic maps in the noncommutative setting would require substantial refactors from the current version, such that $Q(rm) = rQ(m)r^*$ for some suitable conjugation $r^*$. The [Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/Quadratic.20Maps/near/395529867) has some further discussion. ## References * https://en.wikipedia.org/wiki/Quadratic_form * https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms ## Tags quadratic map, homogeneous polynomial, quadratic polynomial -/ universe u v w variable {S T : Type*} variable {R : Type*} {M N P A : Type*} open LinearMap (BilinMap BilinForm) section Polar variable [CommRing R] [AddCommGroup M] [AddCommGroup N] namespace QuadraticMap /-- Up to a factor 2, `Q.polar` is the associated bilinear map for a quadratic map `Q`. Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization -/ def polar (f : M β†’ N) (x y : M) := f (x + y) - f x - f y protected theorem map_add (f : M β†’ N) (x y : M) : f (x + y) = f x + f y + polar f x y := by rw [polar] abel theorem polar_add (f g : M β†’ N) (x y : M) : polar (f + g) x y = polar f x y + polar g x y := by simp only [polar, Pi.add_apply] abel theorem polar_neg (f : M β†’ N) (x y : M) : polar (-f) x y = -polar f x y := by simp only [polar, Pi.neg_apply, sub_eq_add_neg, neg_add] theorem polar_smul [Monoid S] [DistribMulAction S N] (f : M β†’ N) (s : S) (x y : M) : polar (s β€’ f) x y = s β€’ polar f x y := by simp only [polar, Pi.smul_apply, smul_sub] theorem polar_comm (f : M β†’ N) (x y : M) : polar f x y = polar f y x := by rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)] /-- Auxiliary lemma to express bilinearity of `QuadraticMap.polar` without subtraction. -/ theorem polar_add_left_iff {f : M β†’ N} {x x' y : M} : polar f (x + x') y = polar f x y + polar f x' y ↔ f (x + x' + y) + (f x + f x' + f y) = f (x + x') + f (x' + y) + f (y + x) := by simp only [← add_assoc] simp only [polar, sub_eq_iff_eq_add, eq_sub_iff_add_eq, sub_add_eq_add_sub, add_sub] simp only [add_right_comm _ (f y) _, add_right_comm _ (f x') (f x)] rw [add_comm y x, add_right_comm _ _ (f (x + y)), add_comm _ (f (x + y)), add_right_comm (f (x + y)), add_left_inj] theorem polar_comp {F : Type*} [AddCommGroup S] [FunLike F N S] [AddMonoidHomClass F N S] (f : M β†’ N) (g : F) (x y : M) : polar (g ∘ f) x y = g (polar f x y) := by simp only [polar, Pi.smul_apply, Function.comp_apply, map_sub] /-- `QuadraticMap.polar` as a function from `Sym2`. -/ def polarSym2 (f : M β†’ N) : Sym2 M β†’ N := Sym2.lift ⟨polar f, polar_comm _⟩ @[simp] lemma polarSym2_sym2Mk (f : M β†’ N) (xy : M Γ— M) : polarSym2 f (.mk xy) = polar f xy.1 xy.2 := rfl end QuadraticMap end Polar /-- A quadratic map on a module. For a more familiar constructor when `R` is a ring, see `QuadraticMap.ofPolar`. -/ structure QuadraticMap (R : Type u) (M : Type v) (N : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] where toFun : M β†’ N toFun_smul : βˆ€ (a : R) (x : M), toFun (a β€’ x) = (a * a) β€’ toFun x exists_companion' : βˆƒ B : BilinMap R M N, βˆ€ x y, toFun (x + y) = toFun x + toFun y + B x y section QuadraticForm variable (R : Type u) (M : Type v) [CommSemiring R] [AddCommMonoid M] [Module R M] /-- A quadratic form on a module. -/ abbrev QuadraticForm : Type _ := QuadraticMap R M R end QuadraticForm namespace QuadraticMap section DFunLike variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable {Q Q' : QuadraticMap R M N} instance instFunLike : FunLike (QuadraticMap R M N) M N where coe := toFun coe_injective' x y h := by cases x; cases y; congr variable (Q) /-- The `simp` normal form for a quadratic map is `DFunLike.coe`, not `toFun`. -/ @[simp] theorem toFun_eq_coe : Q.toFun = ⇑Q := rfl -- this must come after the coe_to_fun definition initialize_simps_projections QuadraticMap (toFun β†’ apply) variable {Q} @[ext] theorem ext (H : βˆ€ x : M, Q x = Q' x) : Q = Q' := DFunLike.ext _ _ H theorem congr_fun (h : Q = Q') (x : M) : Q x = Q' x := DFunLike.congr_fun h _ /-- Copy of a `QuadraticMap` with a new `toFun` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (Q : QuadraticMap R M N) (Q' : M β†’ N) (h : Q' = ⇑Q) : QuadraticMap R M N where toFun := Q' toFun_smul := h.symm β–Έ Q.toFun_smul exists_companion' := h.symm β–Έ Q.exists_companion' @[simp] theorem coe_copy (Q : QuadraticMap R M N) (Q' : M β†’ N) (h : Q' = ⇑Q) : ⇑(Q.copy Q' h) = Q' := rfl theorem copy_eq (Q : QuadraticMap R M N) (Q' : M β†’ N) (h : Q' = ⇑Q) : Q.copy Q' h = Q := DFunLike.ext' h end DFunLike section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] variable (Q : QuadraticMap R M N) protected theorem map_smul (a : R) (x : M) : Q (a β€’ x) = (a * a) β€’ Q x := Q.toFun_smul a x theorem exists_companion : βˆƒ B : BilinMap R M N, βˆ€ x y, Q (x + y) = Q x + Q y + B x y := Q.exists_companion' theorem map_add_add_add_map (x y z : M) : Q (x + y + z) + (Q x + Q y + Q z) = Q (x + y) + Q (y + z) + Q (z + x) := by obtain ⟨B, h⟩ := Q.exists_companion rw [add_comm z x] simp only [h, LinearMap.map_addβ‚‚] abel theorem map_add_self (x : M) : Q (x + x) = 4 β€’ Q x := by rw [← two_smul R x, Q.map_smul, ← Nat.cast_smul_eq_nsmul R] norm_num -- not @[simp] because it is superseded by `ZeroHomClass.map_zero` protected theorem map_zero : Q 0 = 0 := by rw [← @zero_smul R _ _ _ _ (0 : M), Q.map_smul, zero_mul, zero_smul] instance zeroHomClass : ZeroHomClass (QuadraticMap R M N) M N := { QuadraticMap.instFunLike (R := R) (M := M) (N := N) with map_zero := QuadraticMap.map_zero } theorem map_smul_of_tower [CommSemiring S] [Algebra S R] [SMul S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] (a : S) (x : M) : Q (a β€’ x) = (a * a) β€’ Q x := by rw [← IsScalarTower.algebraMap_smul R a x, Q.map_smul, ← RingHom.map_mul, algebraMap_smul] end CommSemiring section CommRing variable [CommRing R] [AddCommGroup M] [AddCommGroup N] variable [Module R M] [Module R N] (Q : QuadraticMap R M N) @[simp] protected theorem map_neg (x : M) : Q (-x) = Q x := by rw [← @neg_one_smul R _ _ _ _ x, Q.map_smul, neg_one_mul, neg_neg, one_smul] protected theorem map_sub (x y : M) : Q (x - y) = Q (y - x) := by rw [← neg_sub, Q.map_neg] @[simp] theorem polar_zero_left (y : M) : polar Q 0 y = 0 := by simp only [polar, zero_add, QuadraticMap.map_zero, sub_zero, sub_self] @[simp] theorem polar_add_left (x x' y : M) : polar Q (x + x') y = polar Q x y + polar Q x' y := polar_add_left_iff.mpr <| Q.map_add_add_add_map x x' y @[simp] theorem polar_smul_left (a : R) (x y : M) : polar Q (a β€’ x) y = a β€’ polar Q x y := by obtain ⟨B, h⟩ := Q.exists_companion simp_rw [polar, h, Q.map_smul, LinearMap.map_smulβ‚‚, sub_sub, add_sub_cancel_left] @[simp] theorem polar_neg_left (x y : M) : polar Q (-x) y = -polar Q x y := by rw [← neg_one_smul R x, polar_smul_left, neg_one_smul] @[simp] theorem polar_sub_left (x x' y : M) : polar Q (x - x') y = polar Q x y - polar Q x' y := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left] @[simp] theorem polar_zero_right (y : M) : polar Q y 0 = 0 := by simp only [add_zero, polar, QuadraticMap.map_zero, sub_self] @[simp] theorem polar_add_right (x y y' : M) : polar Q x (y + y') = polar Q x y + polar Q x y' := by rw [polar_comm Q x, polar_comm Q x, polar_comm Q x, polar_add_left] @[simp] theorem polar_smul_right (a : R) (x y : M) : polar Q x (a β€’ y) = a β€’ polar Q x y := by rw [polar_comm Q x, polar_comm Q x, polar_smul_left] @[simp] theorem polar_neg_right (x y : M) : polar Q x (-y) = -polar Q x y := by rw [← neg_one_smul R y, polar_smul_right, neg_one_smul] @[simp] theorem polar_sub_right (x y y' : M) : polar Q x (y - y') = polar Q x y - polar Q x y' := by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right] @[simp] theorem polar_self (x : M) : polar Q x x = 2 β€’ Q x := by rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ← two_smul β„•, ← two_smul β„•, ← mul_smul] norm_num /-- `QuadraticMap.polar` as a bilinear map -/ @[simps!] def polarBilin : BilinMap R M N := LinearMap.mkβ‚‚ R (polar Q) (polar_add_left Q) (polar_smul_left Q) (polar_add_right Q) (polar_smul_right Q) lemma polarSym2_map_smul {ΞΉ} (Q : QuadraticMap R M N) (g : ΞΉ β†’ M) (l : ΞΉ β†’ R) (p : Sym2 ΞΉ) : polarSym2 Q (p.map (l β€’ g)) = (p.map l).mul β€’ polarSym2 Q (p.map g) := by obtain ⟨_, _⟩ := p; simp [← smul_assoc, mul_comm] variable [CommSemiring S] [Algebra S R] [Module S M] [IsScalarTower S R M] [Module S N] [IsScalarTower S R N] @[simp] theorem polar_smul_left_of_tower (a : S) (x y : M) : polar Q (a β€’ x) y = a β€’ polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a x, polar_smul_left, algebraMap_smul]
@[simp] theorem polar_smul_right_of_tower (a : S) (x y : M) : polar Q x (a β€’ y) = a β€’ polar Q x y := by rw [← IsScalarTower.algebraMap_smul R a y, polar_smul_right, algebraMap_smul]
Mathlib/LinearAlgebra/QuadraticForm/Basic.lean
316
318
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Logic.IsEmpty import Mathlib.Tactic.Inhabit /-! # Types with a unique term In this file we define a typeclass `Unique`, which expresses that a type has a unique term. In other words, a type that is `Inhabited` and a `Subsingleton`. ## Main declaration * `Unique`: a typeclass that expresses that a type has a unique term. ## Main statements * `Unique.mk'`: an inhabited subsingleton type is `Unique`. This can not be an instance because it would lead to loops in typeclass inference. * `Function.Surjective.unique`: if the domain of a surjective function is `Unique`, then its codomain is `Unique` as well. * `Function.Injective.subsingleton`: if the codomain of an injective function is `Subsingleton`, then its domain is `Subsingleton` as well. * `Function.Injective.unique`: if the codomain of an injective function is `Subsingleton` and its domain is `Inhabited`, then its domain is `Unique`. ## Implementation details The typeclass `Unique Ξ±` is implemented as a type, rather than a `Prop`-valued predicate, for good definitional properties of the default term. -/ universe u v w -- Don't generate injectivity lemmas, which the `simpNF` linter will complain about. set_option genInjectivity false in /-- `Unique Ξ±` expresses that `Ξ±` is a type with a unique term `default`. This is implemented as a type, rather than a `Prop`-valued predicate, for good definitional properties of the default term. -/ @[ext] structure Unique (Ξ± : Sort u) extends Inhabited Ξ± where /-- In a `Unique` type, every term is equal to the default element (from `Inhabited`). -/ uniq : βˆ€ a : Ξ±, a = default attribute [class] Unique theorem unique_iff_existsUnique (Ξ± : Sort u) : Nonempty (Unique Ξ±) ↔ βˆƒ! _ : Ξ±, True := ⟨fun ⟨u⟩ ↦ ⟨u.default, trivial, fun a _ ↦ u.uniq a⟩, fun ⟨a, _, h⟩ ↦ ⟨⟨⟨a⟩, fun _ ↦ h _ trivial⟩⟩⟩ @[deprecated (since := "2024-12-17")] alias unique_iff_exists_unique := unique_iff_existsUnique theorem unique_subtype_iff_existsUnique {Ξ±} (p : Ξ± β†’ Prop) : Nonempty (Unique (Subtype p)) ↔ βˆƒ! a, p a := ⟨fun ⟨u⟩ ↦ ⟨u.default.1, u.default.2, fun a h ↦ congr_arg Subtype.val (u.uniq ⟨a, h⟩)⟩, fun ⟨a, ha, he⟩ ↦ ⟨⟨⟨⟨a, ha⟩⟩, fun ⟨b, hb⟩ ↦ by congr exact he b hb⟩⟩⟩ @[deprecated (since := "2024-12-17")] alias unique_subtype_iff_exists_unique := unique_subtype_iff_existsUnique /-- Given an explicit `a : Ξ±` with `Subsingleton Ξ±`, we can construct a `Unique Ξ±` instance. This is a def because the typeclass search cannot arbitrarily invent the `a : Ξ±` term. Nevertheless, these instances are all equivalent by `Unique.Subsingleton.unique`. See note [reducible non-instances]. -/ abbrev uniqueOfSubsingleton {Ξ± : Sort*} [Subsingleton Ξ±] (a : Ξ±) : Unique Ξ± where default := a uniq _ := Subsingleton.elim _ _ instance PUnit.instUnique : Unique PUnit.{u} where default := PUnit.unit uniq x := subsingleton x _ @[simp] theorem PUnit.default_eq_unit : (default : PUnit) = PUnit.unit := rfl /-- Every provable proposition is unique, as all proofs are equal. -/ def uniqueProp {p : Prop} (h : p) : Unique.{0} p where default := h uniq _ := rfl instance : Unique True := uniqueProp trivial namespace Unique open Function section variable {Ξ± : Sort*} [Unique Ξ±] -- see Note [lower instance priority] instance (priority := 100) : Inhabited Ξ± := toInhabited β€ΉUnique Ξ±β€Ί theorem eq_default (a : Ξ±) : a = default := uniq _ a theorem default_eq (a : Ξ±) : default = a := (uniq _ a).symm -- see Note [lower instance priority] instance (priority := 100) instSubsingleton : Subsingleton Ξ± := subsingleton_of_forall_eq _ eq_default theorem forall_iff {p : Ξ± β†’ Prop} : (βˆ€ a, p a) ↔ p default := ⟨fun h ↦ h _, fun h x ↦ by rwa [Unique.eq_default x]⟩ theorem exists_iff {p : Ξ± β†’ Prop} : Exists p ↔ p default := ⟨fun ⟨a, ha⟩ ↦ eq_default a β–Έ ha, Exists.intro default⟩ end variable {Ξ± : Sort*} @[ext] protected theorem subsingleton_unique' : βˆ€ h₁ hβ‚‚ : Unique Ξ±, h₁ = hβ‚‚ | ⟨⟨x⟩, h⟩, ⟨⟨y⟩, _⟩ => by congr; rw [h x, h y] instance subsingleton_unique : Subsingleton (Unique Ξ±) := ⟨Unique.subsingleton_unique'⟩ /-- Construct `Unique` from `Inhabited` and `Subsingleton`. Making this an instance would create a loop in the class inheritance graph. -/ abbrev mk' (Ξ± : Sort u) [h₁ : Inhabited Ξ±] [Subsingleton Ξ±] : Unique Ξ± := { h₁ with uniq := fun _ ↦ Subsingleton.elim _ _ } end Unique theorem nonempty_unique (Ξ± : Sort u) [Subsingleton Ξ±] [Nonempty Ξ±] : Nonempty (Unique Ξ±) := by inhabit Ξ± exact ⟨Unique.mk' α⟩ theorem unique_iff_subsingleton_and_nonempty (Ξ± : Sort u) : Nonempty (Unique Ξ±) ↔ Subsingleton Ξ± ∧ Nonempty Ξ± := ⟨fun ⟨u⟩ ↦ by constructor <;> exact inferInstance, fun ⟨hs, hn⟩ ↦ nonempty_unique α⟩ variable {Ξ± : Sort*} @[simp] theorem Pi.default_def {Ξ² : Ξ± β†’ Sort v} [βˆ€ a, Inhabited (Ξ² a)] : @default (βˆ€ a, Ξ² a) _ = fun a : Ξ± ↦ @default (Ξ² a) _ := rfl theorem Pi.default_apply {Ξ² : Ξ± β†’ Sort v} [βˆ€ a, Inhabited (Ξ² a)] (a : Ξ±) : @default (βˆ€ a, Ξ² a) _ a = default := rfl instance Pi.unique {Ξ² : Ξ± β†’ Sort v} [βˆ€ a, Unique (Ξ² a)] : Unique (βˆ€ a, Ξ² a) where uniq := fun _ ↦ funext fun _ ↦ Unique.eq_default _ /-- There is a unique function on an empty domain. -/ instance Pi.uniqueOfIsEmpty [IsEmpty Ξ±] (Ξ² : Ξ± β†’ Sort v) : Unique (βˆ€ a, Ξ² a) where default := isEmptyElim uniq _ := funext isEmptyElim theorem eq_const_of_subsingleton {Ξ² : Sort*} [Subsingleton Ξ±] (f : Ξ± β†’ Ξ²) (a : Ξ±) : f = Function.const Ξ± (f a) := funext fun x ↦ Subsingleton.elim x a β–Έ rfl theorem eq_const_of_unique {Ξ² : Sort*} [Unique Ξ±] (f : Ξ± β†’ Ξ²) : f = Function.const Ξ± (f default) := eq_const_of_subsingleton .. theorem heq_const_of_unique [Unique Ξ±] {Ξ² : Ξ± β†’ Sort v} (f : βˆ€ a, Ξ² a) : HEq f (Function.const Ξ± (f default)) := (Function.hfunext rfl) fun i _ _ ↦ by rw [Subsingleton.elim i default]; rfl namespace Function variable {Ξ² : Sort*} {f : Ξ± β†’ Ξ²} /-- If the codomain of an injective function is a subsingleton, then the domain is a subsingleton as well. -/ protected theorem Injective.subsingleton (hf : Injective f) [Subsingleton Ξ²] : Subsingleton Ξ± := ⟨fun _ _ ↦ hf <| Subsingleton.elim _ _⟩ /-- If the domain of a surjective function is a subsingleton, then the codomain is a subsingleton as well. -/ protected theorem Surjective.subsingleton [Subsingleton Ξ±] (hf : Surjective f) : Subsingleton Ξ² :=
⟨hf.forallβ‚‚.2 fun x y ↦ congr_arg f <| Subsingleton.elim x y⟩ /-- If the domain of a surjective function is a singleton,
Mathlib/Logic/Unique.lean
196
198
/- Copyright (c) 2021 RΓ©my Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: RΓ©my Degenne -/ import Mathlib.Probability.Independence.Basic import Mathlib.Probability.Independence.Conditional /-! # Kolmogorov's 0-1 law Let `s : ΞΉ β†’ MeasurableSpace Ξ©` be an independent sequence of sub-Οƒ-algebras. Then any set which is measurable with respect to the tail Οƒ-algebra `limsup s atTop` has probability 0 or 1. ## Main statements * `measure_zero_or_one_of_measurableSet_limsup_atTop`: Kolmogorov's 0-1 law. Any set which is measurable with respect to the tail Οƒ-algebra `limsup s atTop` of an independent sequence of Οƒ-algebras `s` has probability 0 or 1. -/ open MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory variable {Ξ± Ξ© ΞΉ : Type*} {_mΞ± : MeasurableSpace Ξ±} {s : ΞΉ β†’ MeasurableSpace Ξ©} {m m0 : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌΞ± : Measure Ξ±} {ΞΌ : Measure Ξ©} theorem Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ξ©} (h_indep : Kernel.IndepSet t t ΞΊ ΞΌΞ±) : βˆ€α΅ a βˆ‚ΞΌΞ±, ΞΊ a t = 0 ∨ ΞΊ a t = 1 ∨ ΞΊ a t = ∞ := by specialize h_indep t t (measurableSet_generateFrom (Set.mem_singleton t)) (measurableSet_generateFrom (Set.mem_singleton t)) filter_upwards [h_indep] with a ha by_cases h0 : ΞΊ a t = 0 Β· exact Or.inl h0 by_cases h_top : ΞΊ a t = ∞ Β· exact Or.inr (Or.inr h_top) rw [← one_mul (ΞΊ a (t ∩ t)), Set.inter_self, ENNReal.mul_left_inj h0 h_top] at ha exact Or.inr (Or.inl ha.symm) theorem measure_eq_zero_or_one_or_top_of_indepSet_self {t : Set Ξ©} (h_indep : IndepSet t t ΞΌ) : ΞΌ t = 0 ∨ ΞΌ t = 1 ∨ ΞΌ t = ∞ := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_eq_zero_or_one_or_top_of_indepSet_self h_indep theorem Kernel.measure_eq_zero_or_one_of_indepSet_self' (h : βˆ€α΅ a βˆ‚ΞΌΞ±, IsFiniteMeasure (ΞΊ a)) {t : Set Ξ©} (h_indep : IndepSet t t ΞΊ ΞΌΞ±) : βˆ€α΅ a βˆ‚ΞΌΞ±, ΞΊ a t = 0 ∨ ΞΊ a t = 1 := by filter_upwards [measure_eq_zero_or_one_or_top_of_indepSet_self h_indep, h] with a h_0_1_top h' simpa only [measure_ne_top (ΞΊ a), or_false] using h_0_1_top theorem Kernel.measure_eq_zero_or_one_of_indepSet_self [h : βˆ€ a, IsFiniteMeasure (ΞΊ a)] {t : Set Ξ©} (h_indep : IndepSet t t ΞΊ ΞΌΞ±) : βˆ€α΅ a βˆ‚ΞΌΞ±, ΞΊ a t = 0 ∨ ΞΊ a t = 1 := Kernel.measure_eq_zero_or_one_of_indepSet_self' (ae_of_all ΞΌΞ± h) h_indep theorem measure_eq_zero_or_one_of_indepSet_self [IsFiniteMeasure ΞΌ] {t : Set Ξ©} (h_indep : IndepSet t t ΞΌ) : ΞΌ t = 0 ∨ ΞΌ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep theorem condExp_eq_zero_or_one_of_condIndepSet_self [StandardBorelSpace Ξ©] (hm : m ≀ m0) [hΞΌ : IsFiniteMeasure ΞΌ] {t : Set Ξ©} (ht : MeasurableSet t) (h_indep : CondIndepSet m hm t t ΞΌ) : βˆ€α΅ Ο‰ βˆ‚ΞΌ, (μ⟦t | m⟧) Ο‰ = 0 ∨ (μ⟦t | m⟧) Ο‰ = 1 := by -- TODO: Why is not inferred? have (a) : IsFiniteMeasure (condExpKernel ΞΌ m a) := inferInstance have h := ae_of_ae_trim hm (Kernel.measure_eq_zero_or_one_of_indepSet_self h_indep) filter_upwards [condExpKernel_ae_eq_condExp hm ht, h] with Ο‰ hΟ‰_eq hΟ‰ rwa [← hΟ‰_eq, measureReal_eq_zero_iff, measureReal_def, ENNReal.toReal_eq_one_iff] @[deprecated (since := "2025-01-21")] alias condexp_eq_zero_or_one_of_condIndepSet_self := condExp_eq_zero_or_one_of_condIndepSet_self open Filter theorem Kernel.indep_biSup_compl (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (t : Set ΞΉ) : Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᢜ, s n) ΞΊ ΞΌΞ± := indep_iSup_of_disjoint h_le h_indep disjoint_compl_right theorem indep_biSup_compl (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ) (t : Set ΞΉ) : Indep (⨆ n ∈ t, s n) (⨆ n ∈ tᢜ, s n) ΞΌ := Kernel.indep_biSup_compl h_le h_indep t theorem condIndep_biSup_compl [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (t : Set ΞΉ) : CondIndep m (⨆ n ∈ t, s n) (⨆ n ∈ tᢜ, s n) hm ΞΌ := Kernel.indep_biSup_compl h_le h_indep t section Abstract variable {Ξ² : Type*} {p : Set ΞΉ β†’ Prop} {f : Filter ΞΉ} {ns : Ξ² β†’ Set ΞΉ} /-! We prove a version of Kolmogorov's 0-1 law for the Οƒ-algebra `limsup s f` where `f` is a filter for which we can define the following two functions: * `p : Set ΞΉ β†’ Prop` such that for a set `t`, `p t β†’ tᢜ ∈ f`, * `ns : Ξ± β†’ Set ΞΉ` a directed sequence of sets which all verify `p` and such that `⋃ a, ns a = Set.univ`. For the example of `f = atTop`, we can take `p = bddAbove` and `ns : ΞΉ β†’ Set ΞΉ := fun i => Set.Iic i`. -/ theorem Kernel.indep_biSup_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) {t : Set ΞΉ} (ht : p t) : Indep (⨆ n ∈ t, s n) (limsup s f) ΞΊ ΞΌΞ± := by refine indep_of_indep_of_le_right (indep_biSup_compl h_le h_indep t) ?_ refine limsSup_le_of_le (by isBoundedDefault) ?_ simp only [Set.mem_compl_iff, eventually_map] exact eventually_of_mem (hf t ht) le_iSupβ‚‚ theorem indep_biSup_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) {t : Set ΞΉ} (ht : p t) : Indep (⨆ n ∈ t, s n) (limsup s f) ΞΌ := Kernel.indep_biSup_limsup h_le h_indep hf ht theorem condIndep_biSup_limsup [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) {t : Set ΞΉ} (ht : p t) : CondIndep m (⨆ n ∈ t, s n) (limsup s f) hm ΞΌ := Kernel.indep_biSup_limsup h_le h_indep hf ht theorem Kernel.indep_iSup_directed_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) : Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) ΞΊ ΞΌΞ± := by rcases eq_or_ne ΞΌΞ± 0 with rfl | hΞΌ Β· simp obtain ⟨η, Ξ·_eq, hη⟩ : βˆƒ (Ξ· : Kernel Ξ± Ξ©), ΞΊ =ᡐ[ΞΌΞ±] Ξ· ∧ IsMarkovKernel Ξ· := exists_ae_eq_isMarkovKernel h_indep.ae_isProbabilityMeasure hΞΌ replace h_indep := h_indep.congr Ξ·_eq apply Indep.congr (Filter.EventuallyEq.symm Ξ·_eq) apply indep_iSup_of_directed_le Β· exact fun a => indep_biSup_limsup h_le h_indep hf (hnsp a) Β· exact fun a => iSupβ‚‚_le fun n _ => h_le n Β· exact limsup_le_iSup.trans (iSup_le h_le) Β· intro a b obtain ⟨c, hc⟩ := hns a b refine ⟨c, ?_, ?_⟩ <;> refine iSup_mono fun n => iSup_mono' fun hn => ⟨?_, le_rfl⟩ Β· exact hc.1 hn Β· exact hc.2 hn theorem indep_iSup_directed_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) : Indep (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) ΞΌ := Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp theorem condIndep_iSup_directed_limsup [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) : CondIndep m (⨆ a, ⨆ n ∈ ns a, s n) (limsup s f) hm ΞΌ := Kernel.indep_iSup_directed_limsup h_le h_indep hf hns hnsp theorem Kernel.indep_iSup_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : Indep (⨆ n, s n) (limsup s f) ΞΊ ΞΌΞ± := by suffices (⨆ a, ⨆ n ∈ ns a, s n) = ⨆ n, s n by rw [← this] exact indep_iSup_directed_limsup h_le h_indep hf hns hnsp rw [iSup_comm] refine iSup_congr fun n => ?_ have h : ⨆ (i : Ξ²) (_ : n ∈ ns i), s n = ⨆ _ : βˆƒ i, n ∈ ns i, s n := by rw [iSup_exists] haveI : Nonempty (βˆƒ i : Ξ², n ∈ ns i) := ⟨hns_univ n⟩ rw [h, iSup_const] theorem indep_iSup_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : Indep (⨆ n, s n) (limsup s f) ΞΌ := Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ theorem condIndep_iSup_limsup [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : CondIndep m (⨆ n, s n) (limsup s f) hm ΞΌ := Kernel.indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ theorem Kernel.indep_limsup_self (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : Indep (limsup s f) (limsup s f) ΞΊ ΞΌΞ± := indep_of_indep_of_le_left (indep_iSup_limsup h_le h_indep hf hns hnsp hns_univ) limsup_le_iSup theorem indep_limsup_self (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : Indep (limsup s f) (limsup s f) ΞΌ := Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ theorem condIndep_limsup_self [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) : CondIndep m (limsup s f) (limsup s f) hm ΞΌ := Kernel.indep_limsup_self h_le h_indep hf hns hnsp hns_univ theorem Kernel.measure_zero_or_one_of_measurableSet_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΊ ΞΌΞ±) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) : βˆ€α΅ a βˆ‚ΞΌΞ±, ΞΊ a t = 0 ∨ ΞΊ a t = 1 := by apply measure_eq_zero_or_one_of_indepSet_self' ?_ ((indep_limsup_self h_le h_indep hf hns hnsp hns_univ).indepSet_of_measurableSet ht_tail ht_tail) filter_upwards [h_indep.ae_isProbabilityMeasure] with a ha using by infer_instance theorem measure_zero_or_one_of_measurableSet_limsup (h_le : βˆ€ n, s n ≀ m0) (h_indep : iIndep s ΞΌ)
(hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) : ΞΌ t = 0 ∨ ΞΌ t = 1 := by simpa only [ae_dirac_eq, Filter.eventually_pure] using Kernel.measure_zero_or_one_of_measurableSet_limsup h_le h_indep hf hns hnsp hns_univ ht_tail theorem condExp_zero_or_one_of_measurableSet_limsup [StandardBorelSpace Ξ©] (hm : m ≀ m0) [IsFiniteMeasure ΞΌ] (h_le : βˆ€ n, s n ≀ m0) (h_indep : iCondIndep m hm s ΞΌ) (hf : βˆ€ t, p t β†’ tᢜ ∈ f) (hns : Directed (Β· ≀ Β·) ns) (hnsp : βˆ€ a, p (ns a)) (hns_univ : βˆ€ n, βˆƒ a, n ∈ ns a) {t : Set Ξ©} (ht_tail : MeasurableSet[limsup s f] t) : βˆ€α΅ Ο‰ βˆ‚ΞΌ, (μ⟦t | m⟧) Ο‰ = 0 ∨ (μ⟦t | m⟧) Ο‰ = 1 := by have h := ae_of_ae_trim hm
Mathlib/Probability/Independence/ZeroOne.lean
219
232
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Chris Hughes, Floris van Doorn, YaΓ«l Dillies -/ import Mathlib.Data.Nat.Basic import Mathlib.Tactic.GCongr.CoreAttrs import Mathlib.Tactic.Common import Mathlib.Tactic.Monotonicity.Attr /-! # Factorial and variants This file defines the factorial, along with the ascending and descending variants. For the proof that the factorial of `n` counts the permutations of an `n`-element set, see `Fintype.card_perm`. ## Main declarations * `Nat.factorial`: The factorial. * `Nat.ascFactorial`: The ascending factorial. It is the product of natural numbers from `n` to `n + k - 1`. * `Nat.descFactorial`: The descending factorial. It is the product of natural numbers from `n - k + 1` to `n`. -/ namespace Nat /-- `Nat.factorial n` is the factorial of `n`. -/ def factorial : β„• β†’ β„• | 0 => 1 | succ n => succ n * factorial n /-- factorial notation `(n)!` for `Nat.factorial n`. In Lean, names can end with exclamation marks (e.g. `List.get!`), so you cannot write `n!` in Lean, but must write `(n)!` or `n !` instead. The former is preferred, since Lean can confuse the `!` in `n !` as the (prefix) boolean negation operation in some cases. For numerals the parentheses are not required, so e.g. `0!` or `1!` work fine. Todo: replace occurrences of `n !` with `(n)!` in Mathlib. -/ scoped notation:10000 n "!" => Nat.factorial n section Factorial variable {m n : β„•} @[simp] theorem factorial_zero : 0! = 1 := rfl theorem factorial_succ (n : β„•) : (n + 1)! = (n + 1) * n ! := rfl @[simp] theorem factorial_one : 1! = 1 := rfl @[simp] theorem factorial_two : 2! = 2 := rfl theorem mul_factorial_pred (hn : n β‰  0) : n * (n - 1)! = n ! := Nat.sub_add_cancel (one_le_iff_ne_zero.mpr hn) β–Έ rfl theorem factorial_pos : βˆ€ n, 0 < n ! | 0 => Nat.zero_lt_one | succ n => Nat.mul_pos (succ_pos _) (factorial_pos n) theorem factorial_ne_zero (n : β„•) : n ! β‰  0 := ne_of_gt (factorial_pos _) theorem factorial_dvd_factorial {m n} (h : m ≀ n) : m ! ∣ n ! := by induction h with | refl => exact Nat.dvd_refl _ | step _ ih => exact Nat.dvd_trans ih (Nat.dvd_mul_left _ _) theorem dvd_factorial : βˆ€ {m n}, 0 < m β†’ m ≀ n β†’ m ∣ n ! | succ _, _, _, h => Nat.dvd_trans (Nat.dvd_mul_right _ _) (factorial_dvd_factorial h) @[mono, gcongr] theorem factorial_le {m n} (h : m ≀ n) : m ! ≀ n ! := le_of_dvd (factorial_pos _) (factorial_dvd_factorial h) theorem factorial_mul_pow_le_factorial : βˆ€ {m n : β„•}, m ! * (m + 1) ^ n ≀ (m + n)! | m, 0 => by simp | m, n + 1 => by rw [← Nat.add_assoc, factorial_succ, Nat.mul_comm (_ + 1), Nat.pow_succ, ← Nat.mul_assoc] exact Nat.mul_le_mul factorial_mul_pow_le_factorial (succ_le_succ (le_add_right _ _)) theorem factorial_lt (hn : 0 < n) : n ! < m ! ↔ n < m := by refine ⟨fun h => not_le.mp fun hmn => Nat.not_le_of_lt h (factorial_le hmn), fun h => ?_⟩ have : βˆ€ {n}, 0 < n β†’ n ! < (n + 1)! := by intro k hk rw [factorial_succ, succ_mul, Nat.lt_add_left_iff_pos] exact Nat.mul_pos hk k.factorial_pos induction h generalizing hn with | refl => exact this hn | step hnk ih => exact lt_trans (ih hn) <| this <| lt_trans hn <| lt_of_succ_le hnk @[gcongr] lemma factorial_lt_of_lt {m n : β„•} (hn : 0 < n) (h : n < m) : n ! < m ! := (factorial_lt hn).mpr h @[simp] lemma one_lt_factorial : 1 < n ! ↔ 1 < n := factorial_lt Nat.one_pos @[simp] theorem factorial_eq_one : n ! = 1 ↔ n ≀ 1 := by constructor Β· intro h rw [← not_lt, ← one_lt_factorial, h] apply lt_irrefl Β· rintro (_|_|_) <;> rfl theorem factorial_inj (hn : 1 < n) : n ! = m ! ↔ n = m := by refine ⟨fun h => ?_, congr_arg _⟩ obtain hnm | rfl | hnm := lt_trichotomy n m Β· rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm Β· rfl rw [← one_lt_factorial, h, one_lt_factorial] at hn rw [← factorial_lt <| lt_of_succ_lt hn, h] at hnm cases lt_irrefl _ hnm theorem factorial_inj' (h : 1 < n ∨ 1 < m) : n ! = m ! ↔ n = m := by obtain hn|hm := h Β· exact factorial_inj hn Β· rw [eq_comm, factorial_inj hm, eq_comm] theorem self_le_factorial : βˆ€ n : β„•, n ≀ n ! | 0 => Nat.zero_le _ | k + 1 => Nat.le_mul_of_pos_right _ (Nat.one_le_of_lt k.factorial_pos) theorem lt_factorial_self {n : β„•} (hi : 3 ≀ n) : n < n ! := by have : 0 < n := by omega have hn : 1 < pred n := le_pred_of_lt (succ_le_iff.mp hi) rw [← succ_pred_eq_of_pos β€Ή0 < nβ€Ί, factorial_succ] exact (Nat.lt_mul_iff_one_lt_right (pred n).succ_pos).2 ((Nat.lt_of_lt_of_le hn (self_le_factorial _))) theorem add_factorial_succ_lt_factorial_add_succ {i : β„•} (n : β„•) (hi : 2 ≀ i) : i + (n + 1)! < (i + n + 1)! := by rw [factorial_succ (i + _), Nat.add_mul, Nat.one_mul] have := (i + n).self_le_factorial refine Nat.add_lt_add_of_lt_of_le (Nat.lt_of_le_of_lt ?_ ((Nat.lt_mul_iff_one_lt_right ?_).2 ?_)) (factorial_le ?_) <;> omega theorem add_factorial_lt_factorial_add {i n : β„•} (hi : 2 ≀ i) (hn : 1 ≀ n) : i + n ! < (i + n)! := by cases hn Β· rw [factorial_one] exact lt_factorial_self (succ_le_succ hi) exact add_factorial_succ_lt_factorial_add_succ _ hi theorem add_factorial_succ_le_factorial_add_succ (i : β„•) (n : β„•) : i + (n + 1)! ≀ (i + (n + 1))! := by cases (le_or_lt (2 : β„•) i) Β· rw [← Nat.add_assoc] apply Nat.le_of_lt apply add_factorial_succ_lt_factorial_add_succ assumption Β· match i with | 0 => simp | 1 => rw [← Nat.add_assoc, factorial_succ (1 + n), Nat.add_mul, Nat.one_mul, Nat.add_comm 1 n, Nat.add_le_add_iff_right] exact Nat.mul_pos n.succ_pos n.succ.factorial_pos | succ (succ n) => contradiction theorem add_factorial_le_factorial_add (i : β„•) {n : β„•} (n1 : 1 ≀ n) : i + n ! ≀ (i + n)! := by rcases n1 with - | @h Β· exact self_le_factorial _ exact add_factorial_succ_le_factorial_add_succ i h theorem factorial_mul_pow_sub_le_factorial {n m : β„•} (hnm : n ≀ m) : n ! * n ^ (m - n) ≀ m ! := by calc _ ≀ n ! * (n + 1) ^ (m - n) := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _) _ ≀ _ := by simpa [hnm] using @Nat.factorial_mul_pow_le_factorial n (m - n) lemma factorial_le_pow : βˆ€ n, n ! ≀ n ^ n | 0 => le_refl _ | n + 1 => calc _ ≀ (n + 1) * n ^ n := Nat.mul_le_mul_left _ n.factorial_le_pow _ ≀ (n + 1) * (n + 1) ^ n := Nat.mul_le_mul_left _ (Nat.pow_le_pow_left n.le_succ _) _ = _ := by rw [pow_succ'] end Factorial /-! ### Ascending and descending factorials -/ section AscFactorial /-- `n.ascFactorial k = n (n + 1) β‹― (n + k - 1)`. This is closely related to `ascPochhammer`, but much less general. -/ def ascFactorial (n : β„•) : β„• β†’ β„• | 0 => 1 | k + 1 => (n + k) * ascFactorial n k @[simp] theorem ascFactorial_zero (n : β„•) : n.ascFactorial 0 = 1 := rfl theorem ascFactorial_succ {n k : β„•} : n.ascFactorial k.succ = (n + k) * n.ascFactorial k := rfl theorem zero_ascFactorial : βˆ€ (k : β„•), (0 : β„•).ascFactorial k.succ = 0 | 0 => by rw [ascFactorial_succ, ascFactorial_zero, Nat.zero_add, Nat.zero_mul] | (k+1) => by rw [ascFactorial_succ, zero_ascFactorial k, Nat.mul_zero] @[simp] theorem one_ascFactorial : βˆ€ (k : β„•), (1 : β„•).ascFactorial k = k.factorial | 0 => ascFactorial_zero 1 | (k+1) => by rw [ascFactorial_succ, one_ascFactorial k, Nat.add_comm, factorial_succ] theorem succ_ascFactorial (n : β„•) : βˆ€ k, n * n.succ.ascFactorial k = (n + k) * n.ascFactorial k | 0 => by rw [Nat.add_zero, ascFactorial_zero, ascFactorial_zero] | k + 1 => by rw [ascFactorial, Nat.mul_left_comm, succ_ascFactorial n k, ascFactorial, succ_add, ← Nat.add_assoc] /-- `(n + 1).ascFactorial k = (n + k) ! / n !` but without β„•-division. See `Nat.ascFactorial_eq_div` for the version with β„•-division. -/ theorem factorial_mul_ascFactorial (n : β„•) : βˆ€ k, n ! * (n + 1).ascFactorial k = (n + k)! | 0 => by rw [ascFactorial_zero, Nat.add_zero, Nat.mul_one] | k + 1 => by rw [ascFactorial_succ, ← Nat.add_assoc, factorial_succ, Nat.mul_comm (n + 1 + k), ← Nat.mul_assoc, factorial_mul_ascFactorial n k, Nat.mul_comm, Nat.add_right_comm] /-- `n.ascFactorial k = (n + k - 1)! / (n - 1)!` for `n > 0` but without β„•-division. See `Nat.ascFactorial_eq_div` for the version with β„•-division. Consider using `factorial_mul_ascFactorial` to avoid complications of β„•-subtraction. -/ theorem factorial_mul_ascFactorial' (n k : β„•) (h : 0 < n) : (n - 1) ! * n.ascFactorial k = (n + k - 1)! := by rw [Nat.sub_add_comm h, Nat.sub_one] nth_rw 2 [Nat.eq_add_of_sub_eq h rfl] rw [Nat.sub_one, factorial_mul_ascFactorial] theorem ascFactorial_mul_ascFactorial (n l k : β„•) : n.ascFactorial l * (n + l).ascFactorial k = n.ascFactorial (l + k) := by cases n with | zero => cases l Β· simp only [ascFactorial_zero, Nat.add_zero, Nat.one_mul, Nat.zero_add] Β· simp only [Nat.add_right_comm, zero_ascFactorial, Nat.zero_add, Nat.zero_mul] | succ n' => apply Nat.mul_left_cancel (factorial_pos n') simp only [Nat.add_assoc, ← Nat.mul_assoc, factorial_mul_ascFactorial] rw [Nat.add_comm 1 l, ← Nat.add_assoc, factorial_mul_ascFactorial, Nat.add_assoc] /-- Avoid in favor of `Nat.factorial_mul_ascFactorial` if you can. β„•-division isn't worth it. -/ theorem ascFactorial_eq_div (n k : β„•) : (n + 1).ascFactorial k = (n + k)! / n ! := Nat.eq_div_of_mul_eq_right n.factorial_ne_zero (factorial_mul_ascFactorial _ _) /-- Avoid in favor of `Nat.factorial_mul_ascFactorial'` if you can. β„•-division isn't worth it. -/ theorem ascFactorial_eq_div' (n k : β„•) (h : 0 < n) : n.ascFactorial k = (n + k - 1)! / (n - 1) ! := Nat.eq_div_of_mul_eq_right (n - 1).factorial_ne_zero (factorial_mul_ascFactorial' _ _ h) theorem ascFactorial_of_sub {n k : β„•} : (n - k) * (n - k + 1).ascFactorial k = (n - k).ascFactorial (k + 1) := by rw [succ_ascFactorial, ascFactorial_succ] theorem pow_succ_le_ascFactorial (n : β„•) : βˆ€ k : β„•, n ^ k ≀ n.ascFactorial k | 0 => by rw [ascFactorial_zero, Nat.pow_zero] | k + 1 => by rw [Nat.pow_succ, Nat.mul_comm, ascFactorial_succ, ← succ_ascFactorial] exact Nat.mul_le_mul (Nat.le_refl n) (Nat.le_trans (Nat.pow_le_pow_left (le_succ n) k) (pow_succ_le_ascFactorial n.succ k))
theorem pow_lt_ascFactorial' (n k : β„•) : (n + 1) ^ (k + 2) < (n + 1).ascFactorial (k + 2) := by rw [Nat.pow_succ, ascFactorial, Nat.mul_comm] exact Nat.mul_lt_mul_of_lt_of_le' (Nat.lt_add_of_pos_right k.succ_pos)
Mathlib/Data/Nat/Factorial/Basic.lean
272
274
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (βˆ€ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : β„•} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add] theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add] theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d := of_b_eq_zero rfl rfl theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add] theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d := of_c_eq_zero rfl rfl rfl theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly = 0 := by rw [of_c_eq_zero ha hb hc, hd, C_0] theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 := of_d_eq_zero rfl rfl rfl rfl theorem zero : (0 : Cubic R).toPoly = 0 := of_d_eq_zero' theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by rw [← zero, toPoly_injective] private theorem ne_zero (h0 : P.a β‰  0 ∨ P.b β‰  0 ∨ P.c β‰  0 ∨ P.d β‰  0) : P.toPoly β‰  0 := by contrapose! h0 rw [(toPoly_eq_zero_iff P).mp h0] exact ⟨rfl, rfl, rfl, rfl⟩ theorem ne_zero_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly β‰  0 := (or_imp.mp ne_zero).1 ha theorem ne_zero_of_b_ne_zero (hb : P.b β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp ne_zero).2).1 hb theorem ne_zero_of_c_ne_zero (hc : P.c β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc theorem ne_zero_of_d_ne_zero (hd : P.d β‰  0) : P.toPoly β‰  0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd @[simp] theorem leadingCoeff_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.leadingCoeff = P.a := leadingCoeff_cubic ha @[simp] theorem leadingCoeff_of_a_ne_zero' (ha : a β‰  0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a := leadingCoeff_of_a_ne_zero ha @[simp] theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b β‰  0) : P.toPoly.leadingCoeff = P.b := by rw [of_a_eq_zero ha, leadingCoeff_quadratic hb] @[simp] theorem leadingCoeff_of_b_ne_zero' (hb : b β‰  0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b := leadingCoeff_of_b_ne_zero rfl hb @[simp] theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β‰  0) : P.toPoly.leadingCoeff = P.c := by rw [of_b_eq_zero ha hb, leadingCoeff_linear hc] @[simp] theorem leadingCoeff_of_c_ne_zero' (hc : c β‰  0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c := leadingCoeff_of_c_ne_zero rfl rfl hc @[simp] theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.leadingCoeff = P.d := by rw [of_c_eq_zero ha hb hc, leadingCoeff_C] theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d := leadingCoeff_of_c_eq_zero rfl rfl rfl theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_a_ne_zero (ha β–Έ one_ne_zero), ha] theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic := monic_of_a_eq_one rfl theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_b_ne_zero ha (hb β–Έ one_ne_zero), hb] theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic := monic_of_b_eq_one rfl rfl theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc β–Έ one_ne_zero), hc] theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic := monic_of_c_eq_one rfl rfl rfl theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) : P.toPoly.Monic := by rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd] theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic := monic_of_d_eq_one rfl rfl rfl rfl end Coeff /-! ### Degrees -/ section Degree /-- The equivalence between cubic polynomials and polynomials of degree at most three. -/ @[simps] def equiv : Cubic R ≃ { p : R[X] // p.degree ≀ 3 } where toFun P := ⟨P.toPoly, degree_cubic_le⟩ invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩ left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs] right_inv f := by ext n obtain hn | hn := le_or_lt n 3 Β· interval_cases n <;> simp only [Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs] Β· rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2] simpa using hn @[simp] theorem degree_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.degree = 3 := degree_cubic ha @[simp] theorem degree_of_a_ne_zero' (ha : a β‰  0) : (toPoly ⟨a, b, c, d⟩).degree = 3 := degree_of_a_ne_zero ha theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≀ 2 := by simpa only [of_a_eq_zero ha] using degree_quadratic_le theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≀ 2 := degree_of_a_eq_zero rfl @[simp] theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b β‰  0) : P.toPoly.degree = 2 := by rw [of_a_eq_zero ha, degree_quadratic hb] @[simp] theorem degree_of_b_ne_zero' (hb : b β‰  0) : (toPoly ⟨0, b, c, d⟩).degree = 2 := degree_of_b_ne_zero rfl hb theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≀ 1 := by simpa only [of_b_eq_zero ha hb] using degree_linear_le theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≀ 1 := degree_of_b_eq_zero rfl rfl @[simp] theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β‰  0) : P.toPoly.degree = 1 := by rw [of_b_eq_zero ha hb, degree_linear hc] @[simp] theorem degree_of_c_ne_zero' (hc : c β‰  0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 := degree_of_c_ne_zero rfl rfl hc theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≀ 0 := by simpa only [of_c_eq_zero ha hb hc] using degree_C_le theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≀ 0 := degree_of_c_eq_zero rfl rfl rfl @[simp] theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d β‰  0) : P.toPoly.degree = 0 := by rw [of_c_eq_zero ha hb hc, degree_C hd] @[simp] theorem degree_of_d_ne_zero' (hd : d β‰  0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 := degree_of_d_ne_zero rfl rfl rfl hd @[simp] theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly.degree = βŠ₯ := by rw [of_d_eq_zero ha hb hc hd, degree_zero] theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = βŠ₯ := degree_of_d_eq_zero rfl rfl rfl rfl @[simp] theorem degree_of_zero : (0 : Cubic R).toPoly.degree = βŠ₯ := degree_of_d_eq_zero' @[simp] theorem natDegree_of_a_ne_zero (ha : P.a β‰  0) : P.toPoly.natDegree = 3 := natDegree_cubic ha @[simp] theorem natDegree_of_a_ne_zero' (ha : a β‰  0) : (toPoly ⟨a, b, c, d⟩).natDegree = 3 := natDegree_of_a_ne_zero ha theorem natDegree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.natDegree ≀ 2 := by simpa only [of_a_eq_zero ha] using natDegree_quadratic_le theorem natDegree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).natDegree ≀ 2 := natDegree_of_a_eq_zero rfl @[simp] theorem natDegree_of_b_ne_zero (ha : P.a = 0) (hb : P.b β‰  0) : P.toPoly.natDegree = 2 := by rw [of_a_eq_zero ha, natDegree_quadratic hb] @[simp] theorem natDegree_of_b_ne_zero' (hb : b β‰  0) : (toPoly ⟨0, b, c, d⟩).natDegree = 2 := natDegree_of_b_ne_zero rfl hb theorem natDegree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.natDegree ≀ 1 := by simpa only [of_b_eq_zero ha hb] using natDegree_linear_le theorem natDegree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).natDegree ≀ 1 := natDegree_of_b_eq_zero rfl rfl @[simp] theorem natDegree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c β‰  0) : P.toPoly.natDegree = 1 := by rw [of_b_eq_zero ha hb, natDegree_linear hc] @[simp] theorem natDegree_of_c_ne_zero' (hc : c β‰  0) : (toPoly ⟨0, 0, c, d⟩).natDegree = 1 := natDegree_of_c_ne_zero rfl rfl hc @[simp] theorem natDegree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.natDegree = 0 := by rw [of_c_eq_zero ha hb hc, natDegree_C] theorem natDegree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).natDegree = 0 := natDegree_of_c_eq_zero rfl rfl rfl @[simp] theorem natDegree_of_zero : (0 : Cubic R).toPoly.natDegree = 0 := natDegree_of_c_eq_zero' end Degree /-! ### Map across a homomorphism -/ section Map variable [Semiring S] {Ο† : R β†’+* S} /-- Map a cubic polynomial across a semiring homomorphism. -/ def map (Ο† : R β†’+* S) (P : Cubic R) : Cubic S := βŸ¨Ο† P.a, Ο† P.b, Ο† P.c, Ο† P.d⟩ theorem map_toPoly : (map Ο† P).toPoly = Polynomial.map Ο† P.toPoly := by simp only [map, toPoly, map_C, map_X, Polynomial.map_add, Polynomial.map_mul, Polynomial.map_pow] end Map end Basic section Roots open Multiset /-! ### Roots over an extension -/ section Extension variable {P : Cubic R} [CommRing R] [CommRing S] {Ο† : R β†’+* S} /-- The roots of a cubic polynomial. -/ def roots [IsDomain R] (P : Cubic R) : Multiset R := P.toPoly.roots theorem map_roots [IsDomain S] : (map Ο† P).roots = (Polynomial.map Ο† P.toPoly).roots := by rw [roots, map_toPoly] theorem mem_roots_iff [IsDomain R] (h0 : P.toPoly β‰  0) (x : R) : x ∈ P.roots ↔ P.a * x ^ 3 + P.b * x ^ 2 + P.c * x + P.d = 0 := by rw [roots, mem_roots h0, IsRoot, toPoly] simp only [eval_C, eval_X, eval_add, eval_mul, eval_pow] theorem card_roots_le [IsDomain R] [DecidableEq R] : P.roots.toFinset.card ≀ 3 := by apply (toFinset_card_le P.toPoly.roots).trans by_cases hP : P.toPoly = 0 Β· exact (card_roots' P.toPoly).trans (by rw [hP, natDegree_zero]; exact zero_le 3) Β· exact WithBot.coe_le_coe.1 ((card_roots hP).trans degree_cubic_le) end Extension variable {P : Cubic F} [Field F] [Field K] {Ο† : F β†’+* K} {x y z : K} /-! ### Roots over a splitting field -/ section Split theorem splits_iff_card_roots (ha : P.a β‰  0) : Splits Ο† P.toPoly ↔ Multiset.card (map Ο† P).roots = 3 := by replace ha : (map Ο† P).a β‰  0 := (_root_.map_ne_zero Ο†).mpr ha nth_rw 1 [← RingHom.id_comp Ο†] rw [roots, ← splits_map_iff, ← map_toPoly, Polynomial.splits_iff_card_roots, ← ((degree_eq_iff_natDegree_eq <| ne_zero_of_a_ne_zero ha).1 <| degree_of_a_ne_zero ha : _ = 3)] theorem splits_iff_roots_eq_three (ha : P.a β‰  0) : Splits Ο† P.toPoly ↔ βˆƒ x y z : K, (map Ο† P).roots = {x, y, z} := by rw [splits_iff_card_roots ha, card_eq_three] theorem eq_prod_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : (map Ο† P).toPoly = C (Ο† P.a) * (X - C x) * (X - C y) * (X - C z) := by rw [map_toPoly, eq_prod_roots_of_splits <| (splits_iff_roots_eq_three ha).mpr <| Exists.intro x <| Exists.intro y <| Exists.intro z h3, leadingCoeff_of_a_ne_zero ha, ← map_roots, h3] change C (Ο† P.a) * ((X - C x) ::β‚˜ (X - C y) ::β‚˜ {X - C z}).prod = _ rw [prod_cons, prod_cons, prod_singleton, mul_assoc, mul_assoc] theorem eq_sum_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : map Ο† P = βŸ¨Ο† P.a, Ο† P.a * -(x + y + z), Ο† P.a * (x * y + x * z + y * z), Ο† P.a * -(x * y * z)⟩ := by apply_fun @toPoly _ _ Β· rw [eq_prod_three_roots ha h3, C_mul_prod_X_sub_C_eq] Β· exact fun P Q ↦ (toPoly_injective P Q).mp theorem b_eq_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : Ο† P.b = Ο† P.a * -(x + y + z) := by injection eq_sum_three_roots ha h3 theorem c_eq_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : Ο† P.c = Ο† P.a * (x * y + x * z + y * z) := by injection eq_sum_three_roots ha h3 theorem d_eq_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : Ο† P.d = Ο† P.a * -(x * y * z) := by injection eq_sum_three_roots ha h3 end Split /-! ### Discriminant over a splitting field -/ section Discriminant /-- The discriminant of a cubic polynomial. -/ def disc {R : Type*} [Ring R] (P : Cubic R) : R := P.b ^ 2 * P.c ^ 2 - 4 * P.a * P.c ^ 3 - 4 * P.b ^ 3 * P.d - 27 * P.a ^ 2 * P.d ^ 2 + 18 * P.a * P.b * P.c * P.d theorem disc_eq_prod_three_roots (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : Ο† P.disc = (Ο† P.a * Ο† P.a * (x - y) * (x - z) * (y - z)) ^ 2 := by simp only [disc, RingHom.map_add, RingHom.map_sub, RingHom.map_mul, map_pow, map_ofNat] rw [b_eq_three_roots ha h3, c_eq_three_roots ha h3, d_eq_three_roots ha h3] ring1 theorem disc_ne_zero_iff_roots_ne (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : P.disc β‰  0 ↔ x β‰  y ∧ x β‰  z ∧ y β‰  z := by rw [← _root_.map_ne_zero Ο†, disc_eq_prod_three_roots ha h3, pow_two] simp_rw [mul_ne_zero_iff, sub_ne_zero, _root_.map_ne_zero, and_self_iff, and_iff_right ha, and_assoc] theorem disc_ne_zero_iff_roots_nodup (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) : P.disc β‰  0 ↔ (map Ο† P).roots.Nodup := by rw [disc_ne_zero_iff_roots_ne ha h3, h3] change _ ↔ (x ::β‚˜ y ::β‚˜ {z}).Nodup rw [nodup_cons, nodup_cons, mem_cons, mem_singleton, mem_singleton] simp only [nodup_singleton] tauto theorem card_roots_of_disc_ne_zero [DecidableEq K] (ha : P.a β‰  0) (h3 : (map Ο† P).roots = {x, y, z}) (hd : P.disc β‰  0) : (map Ο† P).roots.toFinset.card = 3 := by rw [toFinset_card_of_nodup <| (disc_ne_zero_iff_roots_nodup ha h3).mp hd, ← splits_iff_card_roots ha, splits_iff_roots_eq_three ha] exact ⟨x, ⟨y, ⟨z, h3⟩⟩⟩ end Discriminant end Roots end Cubic
Mathlib/Algebra/CubicDiscriminant.lean
521
528
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Logic.Encodable.Pi import Mathlib.Logic.Function.Iterate /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `β„• β†’ β„•` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := β„•`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (GΓΆdel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with *`n`-ary* functions. We formalize the textbook definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is equivalent to our chosen formulation. For more discussionn of this and other design choices in this formalization, see [carneiro2019]. ## Main definitions - `Nat.Primrec f`: `f` is primitive recursive, for functions `f : β„• β†’ β„•` - `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types - `Primcodable Ξ±`: well-behaved encoding of `Ξ±` into `β„•`, i.e. one such that roundtripping through the encoding functions adds no computational power ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Denumerable Encodable Function namespace Nat /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {Ξ±} (f : β„• β†’ β„• β†’ Ξ±) (n : β„•) : Ξ± := f n.unpair.1 n.unpair.2 /-- The primitive recursive functions `β„• β†’ β„•`. -/ protected inductive Primrec : (β„• β†’ β„•) β†’ Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f β†’ Nat.Primrec g β†’ Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) namespace Primrec theorem of_eq {f g : β„• β†’ β„•} (hf : Nat.Primrec f) (H : βˆ€ n, f n = g n) : Nat.Primrec g := (funext H : f = g) β–Έ hf theorem const : βˆ€ n : β„•, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp theorem prec1 {f} (m : β„•) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp theorem casesOn1 {f} (m : β„•) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn Β· m f) := (prec1 m (hf.comp left)).of_eq <| by simp -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] theorem add : Nat.Primrec (unpaired (Β· + Β·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] theorem sub : Nat.Primrec (unpaired (Β· - Β·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] theorem mul : Nat.Primrec (unpaired (Β· * Β·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by
simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst]
Mathlib/Computability/Primrec.lean
110
111
/- Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Rat import Mathlib.Algebra.Ring.Int.Parity import Mathlib.Data.PNat.Defs /-! # Further lemmas for the Rational Numbers -/ namespace Rat theorem num_dvd (a) {b : β„€} (b0 : b β‰  0) : (a /. b).num ∣ a := by rcases e : a /. b with ⟨n, d, h, c⟩ rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.dvd_of_dvd_mul_right ?_ have := congr_arg Int.natAbs e simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this] theorem den_dvd (a b : β„€) : ((a /. b).den : β„€) ∣ b := by by_cases b0 : b = 0; Β· simp [b0] rcases e : a /. b with ⟨n, d, h, c⟩ rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_ rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp theorem num_den_mk {q : β„š} {n d : β„€} (hd : d β‰  0) (qdf : q = n /. d) : βˆƒ c : β„€, n = c * q.num ∧ d = c * q.den := by obtain rfl | hn := eq_or_ne n 0 Β· simp [qdf] have : q.num * d = n * ↑q.den := by refine (divInt_eq_iff ?_ hd).mp ?_ Β· exact Int.natCast_ne_zero.mpr (Rat.den_nz _) Β· rwa [num_divInt_den] have hqdn : q.num ∣ n := by rw [qdf] exact Rat.num_dvd _ hd refine ⟨n / q.num, ?_, ?_⟩ Β· rw [Int.ediv_mul_cancel hqdn] Β· refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this rw [qdf] exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn) theorem num_mk (n d : β„€) : (n /. d).num = d.sign * n / n.gcd d := by have (m : β„•) : Int.natAbs (m + 1) = m + 1 := by rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast] rcases d with ((_ | _) | _) <;> rw [← Int.tdiv_eq_ediv_of_dvd] <;> simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd, Int.zero_ediv, Int.ofNat_dvd_left, Nat.gcd_dvd_left, this] theorem den_mk (n d : β„€) : (n /. d).den = if d = 0 then 1 else d.natAbs / n.gcd d := by have (m : β„•) : Int.natAbs (m + 1) = m + 1 := by rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast] rcases d with ((_ | _) | _) <;> simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd, if_neg (Nat.cast_add_one_ne_zero _), this] theorem add_den_dvd_lcm (q₁ qβ‚‚ : β„š) : (q₁ + qβ‚‚).den ∣ q₁.den.lcm qβ‚‚.den := by rw [add_def, normalize_eq, Nat.div_dvd_iff_dvd_mul (Nat.gcd_dvd_right _ _) (Nat.gcd_ne_zero_right (by simp)), ← Nat.gcd_mul_lcm, mul_dvd_mul_iff_right (Nat.lcm_ne_zero (by simp) (by simp)), Nat.dvd_gcd_iff] refine ⟨?_, dvd_mul_right _ _⟩ rw [← Int.natCast_dvd_natCast, Int.dvd_natAbs] apply Int.dvd_add <;> apply dvd_mul_of_dvd_right <;> rw [Int.natCast_dvd_natCast] <;> [exact Nat.gcd_dvd_right _ _; exact Nat.gcd_dvd_left _ _] theorem add_den_dvd (q₁ qβ‚‚ : β„š) : (q₁ + qβ‚‚).den ∣ q₁.den * qβ‚‚.den := by rw [add_def, normalize_eq] apply Nat.div_dvd_of_dvd apply Nat.gcd_dvd_right theorem mul_den_dvd (q₁ qβ‚‚ : β„š) : (q₁ * qβ‚‚).den ∣ q₁.den * qβ‚‚.den := by rw [mul_def, normalize_eq] apply Nat.div_dvd_of_dvd apply Nat.gcd_dvd_right theorem mul_num (q₁ qβ‚‚ : β„š) : (q₁ * qβ‚‚).num = q₁.num * qβ‚‚.num / Nat.gcd (q₁.num * qβ‚‚.num).natAbs (q₁.den * qβ‚‚.den) := by rw [mul_def, normalize_eq] theorem mul_den (q₁ qβ‚‚ : β„š) : (q₁ * qβ‚‚).den = q₁.den * qβ‚‚.den / Nat.gcd (q₁.num * qβ‚‚.num).natAbs (q₁.den * qβ‚‚.den) := by rw [mul_def, normalize_eq] theorem mul_self_num (q : β„š) : (q * q).num = q.num * q.num := by rw [mul_num, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Int.ofNat_one, Int.ediv_one] exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced) theorem mul_self_den (q : β„š) : (q * q).den = q.den * q.den := by rw [Rat.mul_den, Int.natAbs_mul, Nat.Coprime.gcd_eq_one, Nat.div_one] exact (q.reduced.mul_right q.reduced).mul (q.reduced.mul_right q.reduced) theorem add_num_den (q r : β„š) : q + r = (q.num * r.den + q.den * r.num : β„€) /. (↑q.den * ↑r.den : β„€) := by have hqd : (q.den : β„€) β‰  0 := Int.natCast_ne_zero_iff_pos.2 q.den_pos have hrd : (r.den : β„€) β‰  0 := Int.natCast_ne_zero_iff_pos.2 r.den_pos conv_lhs => rw [← num_divInt_den q, ← num_divInt_den r, divInt_add_divInt _ _ hqd hrd] rw [mul_comm r.num q.den] theorem isSquare_iff {q : β„š} : IsSquare q ↔ IsSquare q.num ∧ IsSquare q.den := by constructor Β· rintro ⟨qr, rfl⟩ rw [Rat.mul_self_num, mul_self_den] simp only [IsSquare.mul_self, and_self] Β· rintro ⟨⟨nr, hnr⟩, ⟨dr, hdr⟩⟩ refine ⟨nr / dr, ?_⟩ rw [div_mul_div_comm, ← Int.cast_mul, ← Nat.cast_mul, ← hnr, ← hdr, num_div_den] @[norm_cast, simp] theorem isSquare_natCast_iff {n : β„•} : IsSquare (n : β„š) ↔ IsSquare n := by simp_rw [isSquare_iff, num_natCast, den_natCast, IsSquare.one, and_true, Int.isSquare_natCast_iff] @[norm_cast, simp] theorem isSquare_intCast_iff {z : β„€} : IsSquare (z : β„š) ↔ IsSquare z := by simp_rw [isSquare_iff, intCast_num, intCast_den, IsSquare.one, and_true] @[simp] theorem isSquare_ofNat_iff {n : β„•} : IsSquare (ofNat(n) : β„š) ↔ IsSquare (OfNat.ofNat n : β„•) := isSquare_natCast_iff section Casts theorem exists_eq_mul_div_num_and_eq_mul_div_den (n : β„€) {d : β„€} (d_ne_zero : d β‰  0) : βˆƒ c : β„€, n = c * ((n : β„š) / d).num ∧ (d : β„€) = c * ((n : β„š) / d).den :=
haveI : (n : β„š) / d = Rat.divInt n d := by rw [← Rat.divInt_eq_div] Rat.num_den_mk d_ne_zero this
Mathlib/Data/Rat/Lemmas.lean
137
138
/- Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Comap import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving /-! # Restricting a measure to a subset or a subtype Given a measure `ΞΌ` on a type `Ξ±` and a subset `s` of `Ξ±`, we define a measure `ΞΌ.restrict s` as the restriction of `ΞΌ` to `s` (still as a measure on `Ξ±`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R Ξ± Ξ² Ξ΄ Ξ³ ΞΉ : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace Ξ±} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³] variable {ΞΌ μ₁ ΞΌβ‚‚ μ₃ Ξ½ Ξ½' ν₁ Ξ½β‚‚ : Measure Ξ±} {s s' t : Set Ξ±} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `ΞΌ` to a set `s` as an `ℝβ‰₯0∞`-linear map. -/ noncomputable def restrictβ‚— {m0 : MeasurableSpace Ξ±} (s : Set Ξ±) : Measure Ξ± β†’β‚—[ℝβ‰₯0∞] Measure Ξ± := liftLinear (OuterMeasure.restrict s) fun ΞΌ s' hs' t => by suffices ΞΌ (s ∩ t) = ΞΌ (s ∩ t ∩ s') + ΞΌ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ /-- Restrict a measure `ΞΌ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace Ξ±} (ΞΌ : Measure Ξ±) (s : Set Ξ±) : Measure Ξ± := restrictβ‚— s ΞΌ @[simp] theorem restrictβ‚—_apply {_m0 : MeasurableSpace Ξ±} (s : Set Ξ±) (ΞΌ : Measure Ξ±) : restrictβ‚— s ΞΌ = ΞΌ.restrict s := rfl /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (ΞΌ.restrict s).toOuterMeasure = OuterMeasure.restrict s ΞΌ.toOuterMeasure := by simp_rw [restrict, restrictβ‚—, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, ΞΌ.trimmed] theorem restrict_applyβ‚€ (ht : NullMeasurableSet t (ΞΌ.restrict s)) : ΞΌ.restrict s t = ΞΌ (t ∩ s) := by rw [← restrictβ‚—_apply, restrictβ‚—, liftLinear_applyβ‚€ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : ΞΌ.restrict s t = ΞΌ (t ∩ s) := restrict_applyβ‚€ ht.nullMeasurableSet /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace Ξ±} ⦃s s' : Set α⦄ ⦃μ Ξ½ : Measure α⦄ (hs : s ≀ᡐ[ΞΌ] s') (hΞΌΞ½ : ΞΌ ≀ Ξ½) : ΞΌ.restrict s ≀ Ξ½.restrict s' := Measure.le_iff.2 fun t ht => calc ΞΌ.restrict s t = ΞΌ (t ∩ s) := restrict_apply ht _ ≀ ΞΌ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≀ Ξ½ (t ∩ s') := le_iff'.1 hΞΌΞ½ (t ∩ s') _ = Ξ½.restrict s' t := (restrict_apply ht).symm /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono, gcongr] theorem restrict_mono {_m0 : MeasurableSpace Ξ±} ⦃s s' : Set α⦄ (hs : s βŠ† s') ⦃μ Ξ½ : Measure α⦄ (hΞΌΞ½ : ΞΌ ≀ Ξ½) : ΞΌ.restrict s ≀ Ξ½.restrict s' := restrict_mono' (ae_of_all _ hs) hΞΌΞ½ @[gcongr] theorem restrict_mono_measure {_ : MeasurableSpace Ξ±} {ΞΌ Ξ½ : Measure Ξ±} (h : ΞΌ ≀ Ξ½) (s : Set Ξ±) : ΞΌ.restrict s ≀ Ξ½.restrict s := restrict_mono subset_rfl h @[gcongr] theorem restrict_mono_set {_ : MeasurableSpace Ξ±} (ΞΌ : Measure Ξ±) {s t : Set Ξ±} (h : s βŠ† t) : ΞΌ.restrict s ≀ ΞΌ.restrict t := restrict_mono h le_rfl theorem restrict_mono_ae (h : s ≀ᡐ[ΞΌ] t) : ΞΌ.restrict s ≀ ΞΌ.restrict t := restrict_mono' h (le_refl ΞΌ) theorem restrict_congr_set (h : s =ᡐ[ΞΌ] t) : ΞΌ.restrict s = ΞΌ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : ΞΌ.restrict s t = ΞΌ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] theorem restrict_applyβ‚€' (hs : NullMeasurableSet s ΞΌ) : ΞΌ.restrict s t = ΞΌ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] theorem restrict_le_self : ΞΌ.restrict s ≀ ΞΌ := Measure.le_iff.2 fun t ht => calc ΞΌ.restrict s t = ΞΌ (t ∩ s) := restrict_apply ht _ ≀ ΞΌ t := measure_mono inter_subset_left variable (ΞΌ) theorem restrict_eq_self (h : s βŠ† t) : ΞΌ.restrict t s = ΞΌ s := (le_iff'.1 restrict_le_self s).antisymm <| calc ΞΌ s ≀ ΞΌ (toMeasurable (ΞΌ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = ΞΌ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] @[simp] theorem restrict_apply_self (s : Set Ξ±) : (ΞΌ.restrict s) s = ΞΌ s := restrict_eq_self ΞΌ Subset.rfl variable {ΞΌ} theorem restrict_apply_univ (s : Set Ξ±) : ΞΌ.restrict s univ = ΞΌ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] theorem le_restrict_apply (s t : Set Ξ±) : ΞΌ (t ∩ s) ≀ ΞΌ.restrict s t := calc ΞΌ (t ∩ s) = ΞΌ.restrict s (t ∩ s) := (restrict_eq_self ΞΌ inter_subset_right).symm _ ≀ ΞΌ.restrict s t := measure_mono inter_subset_left theorem restrict_apply_le (s t : Set Ξ±) : ΞΌ.restrict s t ≀ ΞΌ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s βŠ† t) : ΞΌ.restrict s t = ΞΌ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self ΞΌ s).symm.trans_le <| measure_mono h) @[simp] theorem restrict_add {_m0 : MeasurableSpace Ξ±} (ΞΌ Ξ½ : Measure Ξ±) (s : Set Ξ±) : (ΞΌ + Ξ½).restrict s = ΞΌ.restrict s + Ξ½.restrict s := (restrictβ‚— s).map_add ΞΌ Ξ½ @[simp] theorem restrict_zero {_m0 : MeasurableSpace Ξ±} (s : Set Ξ±) : (0 : Measure Ξ±).restrict s = 0 := (restrictβ‚— s).map_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace Ξ±} {R : Type*} [SMul R ℝβ‰₯0∞] [IsScalarTower R ℝβ‰₯0∞ ℝβ‰₯0∞] (c : R) (ΞΌ : Measure Ξ±) (s : Set Ξ±) : (c β€’ ΞΌ).restrict s = c β€’ ΞΌ.restrict s := by simpa only [smul_one_smul] using (restrictβ‚— s).map_smul (c β€’ 1) ΞΌ theorem restrict_restrictβ‚€ (hs : NullMeasurableSet s (ΞΌ.restrict t)) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_applyβ‚€ (hu.nullMeasurableSet.inter hs)] @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict (s ∩ t) := restrict_restrictβ‚€ hs.nullMeasurableSet theorem restrict_restrict_of_subset (h : s βŠ† t) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h theorem restrict_restrictβ‚€' (ht : NullMeasurableSet t ΞΌ) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_applyβ‚€' ht, inter_assoc] theorem restrict_restrict' (ht : MeasurableSet t) : (ΞΌ.restrict t).restrict s = ΞΌ.restrict (s ∩ t) := restrict_restrictβ‚€' ht.nullMeasurableSet theorem restrict_comm (hs : MeasurableSet s) : (ΞΌ.restrict t).restrict s = (ΞΌ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] theorem restrict_apply_eq_zero (ht : MeasurableSet t) : ΞΌ.restrict s t = 0 ↔ ΞΌ (t ∩ s) = 0 := by rw [restrict_apply ht] theorem measure_inter_eq_zero_of_restrict (h : ΞΌ.restrict s t = 0) : ΞΌ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h β–Έ le_restrict_apply _ _) theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : ΞΌ.restrict s t = 0 ↔ ΞΌ (t ∩ s) = 0 := by rw [restrict_apply' hs] @[simp] theorem restrict_eq_zero : ΞΌ.restrict s = 0 ↔ ΞΌ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] /-- If `ΞΌ s β‰  0`, then `ΞΌ.restrict s β‰  0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (ΞΌ s)] : NeZero (ΞΌ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set Ξ±} (h : ΞΌ s = 0) : ΞΌ.restrict s = 0 := restrict_eq_zero.2 h @[simp] theorem restrict_empty : ΞΌ.restrict βˆ… = 0 := restrict_zero_set measure_empty @[simp] theorem restrict_univ : ΞΌ.restrict univ = ΞΌ := ext fun s hs => by simp [hs] theorem restrict_inter_add_diffβ‚€ (s : Set Ξ±) (ht : NullMeasurableSet t ΞΌ) : ΞΌ.restrict (s ∩ t) + ΞΌ.restrict (s \ t) = ΞΌ.restrict s := by ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diffβ‚€ (u ∩ s) ht theorem restrict_inter_add_diff (s : Set Ξ±) (ht : MeasurableSet t) : ΞΌ.restrict (s ∩ t) + ΞΌ.restrict (s \ t) = ΞΌ.restrict s := restrict_inter_add_diffβ‚€ s ht.nullMeasurableSet theorem restrict_union_add_interβ‚€ (s : Set Ξ±) (ht : NullMeasurableSet t ΞΌ) : ΞΌ.restrict (s βˆͺ t) + ΞΌ.restrict (s ∩ t) = ΞΌ.restrict s + ΞΌ.restrict t := by rw [← restrict_inter_add_diffβ‚€ (s βˆͺ t) ht, union_inter_cancel_right, union_diff_right, ← restrict_inter_add_diffβ‚€ s ht, add_comm, ← add_assoc, add_right_comm] theorem restrict_union_add_inter (s : Set Ξ±) (ht : MeasurableSet t) : ΞΌ.restrict (s βˆͺ t) + ΞΌ.restrict (s ∩ t) = ΞΌ.restrict s + ΞΌ.restrict t := restrict_union_add_interβ‚€ s ht.nullMeasurableSet theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set Ξ±) : ΞΌ.restrict (s βˆͺ t) + ΞΌ.restrict (s ∩ t) = ΞΌ.restrict s + ΞΌ.restrict t := by simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs theorem restrict_unionβ‚€ (h : AEDisjoint ΞΌ s t) (ht : NullMeasurableSet t ΞΌ) : ΞΌ.restrict (s βˆͺ t) = ΞΌ.restrict s + ΞΌ.restrict t := by simp [← restrict_union_add_interβ‚€ s ht, restrict_zero_set h] theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) : ΞΌ.restrict (s βˆͺ t) = ΞΌ.restrict s + ΞΌ.restrict t := restrict_unionβ‚€ h.aedisjoint ht.nullMeasurableSet theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) : ΞΌ.restrict (s βˆͺ t) = ΞΌ.restrict s + ΞΌ.restrict t := by rw [union_comm, restrict_union h.symm hs, add_comm] @[simp] theorem restrict_add_restrict_compl (hs : MeasurableSet s) : ΞΌ.restrict s + ΞΌ.restrict sᢜ = ΞΌ := by rw [← restrict_union (@disjoint_compl_right (Set Ξ±) _ _) hs.compl, union_compl_self, restrict_univ] @[simp] theorem restrict_compl_add_restrict (hs : MeasurableSet s) : ΞΌ.restrict sᢜ + ΞΌ.restrict s = ΞΌ := by rw [add_comm, restrict_add_restrict_compl hs] theorem restrict_union_le (s s' : Set Ξ±) : ΞΌ.restrict (s βˆͺ s') ≀ ΞΌ.restrict s + ΞΌ.restrict s' := le_iff.2 fun t ht ↦ by simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s') theorem restrict_iUnion_apply_ae [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} (hd : Pairwise (AEDisjoint ΞΌ on s)) (hm : βˆ€ i, NullMeasurableSet (s i) ΞΌ) {t : Set Ξ±} (ht : MeasurableSet t) : ΞΌ.restrict (⋃ i, s i) t = βˆ‘' i, ΞΌ.restrict (s i) t := by simp only [restrict_apply, ht, inter_iUnion] exact measure_iUnionβ‚€ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right) fun i => ht.nullMeasurableSet.inter (hm i) theorem restrict_iUnion_apply [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} (hd : Pairwise (Disjoint on s)) (hm : βˆ€ i, MeasurableSet (s i)) {t : Set Ξ±} (ht : MeasurableSet t) : ΞΌ.restrict (⋃ i, s i) t = βˆ‘' i, ΞΌ.restrict (s i) t := restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht theorem restrict_iUnion_apply_eq_iSup [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} (hd : Directed (Β· βŠ† Β·) s) {t : Set Ξ±} (ht : MeasurableSet t) : ΞΌ.restrict (⋃ i, s i) t = ⨆ i, ΞΌ.restrict (s i) t := by simp only [restrict_apply ht, inter_iUnion] rw [Directed.measure_iUnion] exacts [hd.mono_comp _ fun s₁ sβ‚‚ => inter_subset_inter_right _] /-- The restriction of the pushforward measure is the pushforward of the restriction. For a version assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/ theorem restrict_map {f : Ξ± β†’ Ξ²} (hf : Measurable f) {s : Set Ξ²} (hs : MeasurableSet s) : (ΞΌ.map f).restrict s = (ΞΌ.restrict <| f ⁻¹' s).map f := ext fun t ht => by simp [*, hf ht] theorem restrict_toMeasurable (h : ΞΌ s β‰  ∞) : ΞΌ.restrict (toMeasurable ΞΌ s) = ΞΌ.restrict s := ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h, inter_comm] theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace Ξ±} ⦃s : Set α⦄ ⦃μ : Measure α⦄ (hs : βˆ€α΅ x βˆ‚ΞΌ, x ∈ s) : ΞΌ.restrict s = ΞΌ := calc ΞΌ.restrict s = ΞΌ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs) _ = ΞΌ := restrict_univ theorem restrict_congr_meas (hs : MeasurableSet s) : ΞΌ.restrict s = Ξ½.restrict s ↔ βˆ€ t βŠ† s, MeasurableSet t β†’ ΞΌ t = Ξ½ t := ⟨fun H t hts ht => by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H => ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩ theorem restrict_congr_mono (hs : s βŠ† t) (h : ΞΌ.restrict t = Ξ½.restrict t) : ΞΌ.restrict s = Ξ½.restrict s := by rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs] /-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all measurable subsets of `s βˆͺ t`. -/ theorem restrict_union_congr : ΞΌ.restrict (s βˆͺ t) = Ξ½.restrict (s βˆͺ t) ↔ ΞΌ.restrict s = Ξ½.restrict s ∧ ΞΌ.restrict t = Ξ½.restrict t := by refine ⟨fun h ↦ ⟨restrict_congr_mono subset_union_left h, restrict_congr_mono subset_union_right h⟩, ?_⟩ rintro ⟨hs, ht⟩ ext1 u hu simp only [restrict_apply hu, inter_union_distrib_left] rcases exists_measurable_supersetβ‚‚ ΞΌ Ξ½ (u ∩ s) with ⟨US, hsub, hm, hΞΌ, hν⟩ calc ΞΌ (u ∩ s βˆͺ u ∩ t) = ΞΌ (US βˆͺ u ∩ t) := measure_union_congr_of_subset hsub hΞΌ.le Subset.rfl le_rfl _ = ΞΌ US + ΞΌ ((u ∩ t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm _ = restrict ΞΌ s u + restrict ΞΌ t (u \ US) := by simp only [restrict_apply, hu, hu.diff hm, hΞΌ, ← inter_comm t, inter_diff_assoc] _ = restrict Ξ½ s u + restrict Ξ½ t (u \ US) := by rw [hs, ht] _ = Ξ½ US + Ξ½ ((u ∩ t) \ US) := by simp only [restrict_apply, hu, hu.diff hm, hΞ½, ← inter_comm t, inter_diff_assoc] _ = Ξ½ (US βˆͺ u ∩ t) := measure_add_diff hm.nullMeasurableSet _ _ = Ξ½ (u ∩ s βˆͺ u ∩ t) := .symm <| measure_union_congr_of_subset hsub hΞ½.le Subset.rfl le_rfl theorem restrict_finset_biUnion_congr {s : Finset ΞΉ} {t : ΞΉ β†’ Set Ξ±} : ΞΌ.restrict (⋃ i ∈ s, t i) = Ξ½.restrict (⋃ i ∈ s, t i) ↔ βˆ€ i ∈ s, ΞΌ.restrict (t i) = Ξ½.restrict (t i) := by classical induction' s using Finset.induction_on with i s _ hs; Β· simp simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert] rw [restrict_union_congr, ← hs] theorem restrict_iUnion_congr [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} : ΞΌ.restrict (⋃ i, s i) = Ξ½.restrict (⋃ i, s i) ↔ βˆ€ i, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩ ext1 t ht have D : Directed (Β· βŠ† Β·) fun t : Finset ΞΉ => ⋃ i ∈ t, s i := Monotone.directed_le fun t₁ tβ‚‚ ht => biUnion_subset_biUnion_left ht rw [iUnion_eq_iUnion_finset] simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i] theorem restrict_biUnion_congr {s : Set ΞΉ} {t : ΞΉ β†’ Set Ξ±} (hc : s.Countable) : ΞΌ.restrict (⋃ i ∈ s, t i) = Ξ½.restrict (⋃ i ∈ s, t i) ↔ βˆ€ i ∈ s, ΞΌ.restrict (t i) = Ξ½.restrict (t i) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr] theorem restrict_sUnion_congr {S : Set (Set Ξ±)} (hc : S.Countable) : ΞΌ.restrict (⋃₀ S) = Ξ½.restrict (⋃₀ S) ↔ βˆ€ s ∈ S, ΞΌ.restrict s = Ξ½.restrict s := by rw [sUnion_eq_biUnion, restrict_biUnion_congr hc] /-- This lemma shows that `Inf` and `restrict` commute for measures. -/ theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace Ξ±} {m : Set (Measure Ξ±)} (hm : m.Nonempty) (ht : MeasurableSet t) : (sInf m).restrict t = sInf ((fun ΞΌ : Measure Ξ± => ΞΌ.restrict t) '' m) := by ext1 s hs simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht), Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ← Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _), OuterMeasure.restrict_apply] theorem exists_mem_of_measure_ne_zero_of_ae (hs : ΞΌ s β‰  0) {p : Ξ± β†’ Prop} (hp : βˆ€α΅ x βˆ‚ΞΌ.restrict s, p x) : βˆƒ x, x ∈ s ∧ p x := by rw [← ΞΌ.restrict_apply_self, ← frequently_ae_mem_iff] at hs exact (hs.and_eventually hp).exists /-- If a quasi measure preserving map `f` maps a set `s` to a set `t`, then it is quasi measure preserving with respect to the restrictions of the measures. -/ theorem QuasiMeasurePreserving.restrict {Ξ½ : Measure Ξ²} {f : Ξ± β†’ Ξ²} (hf : QuasiMeasurePreserving f ΞΌ Ξ½) {t : Set Ξ²} (hmaps : MapsTo f s t) : QuasiMeasurePreserving f (ΞΌ.restrict s) (Ξ½.restrict t) where measurable := hf.measurable absolutelyContinuous := by refine AbsolutelyContinuous.mk fun u hum ↦ ?_ suffices Ξ½ (u ∩ t) = 0 β†’ ΞΌ (f ⁻¹' u ∩ s) = 0 by simpa [hum, hf.measurable, hf.measurable hum] refine fun hu ↦ measure_mono_null ?_ (hf.preimage_null hu) rw [preimage_inter] gcongr assumption /-! ### Extensionality results -/ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `Union`). -/ theorem ext_iff_of_iUnion_eq_univ [Countable ΞΉ] {s : ΞΉ β†’ Set Ξ±} (hs : ⋃ i, s i = univ) : ΞΌ = Ξ½ ↔ βˆ€ i, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ] alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `biUnion`). -/ theorem ext_iff_of_biUnion_eq_univ {S : Set ΞΉ} {s : ΞΉ β†’ Set Ξ±} (hc : S.Countable) (hs : ⋃ i ∈ S, s i = univ) : ΞΌ = Ξ½ ↔ βˆ€ i ∈ S, ΞΌ.restrict (s i) = Ξ½.restrict (s i) := by rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ] alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `sUnion`). -/ theorem ext_iff_of_sUnion_eq_univ {S : Set (Set Ξ±)} (hc : S.Countable) (hs : ⋃₀ S = univ) :
ΞΌ = Ξ½ ↔ βˆ€ s ∈ S, ΞΌ.restrict s = Ξ½.restrict s := ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion] alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ theorem ext_of_generateFrom_of_cover {S T : Set (Set Ξ±)} (h_gen : β€Ή_β€Ί = generateFrom S) (hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : βˆ€ t ∈ T, ΞΌ t β‰  ∞) (ST_eq : βˆ€ t ∈ T, βˆ€ s ∈ S, ΞΌ (s ∩ t) = Ξ½ (s ∩ t)) (T_eq : βˆ€ t ∈ T, ΞΌ t = Ξ½ t) : ΞΌ = Ξ½ := by
Mathlib/MeasureTheory/Measure/Restrict.lean
417
424
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.FreeModule.Basic import Mathlib.LinearAlgebra.Matrix.ToLin /-! # Free modules over PID A free `R`-module `M` is a module with a basis over `R`, equivalently it is an `R`-module linearly equivalent to `ΞΉ β†’β‚€ R` for some `ΞΉ`. This file proves a submodule of a free `R`-module of finite rank is also a free `R`-module of finite rank, if `R` is a principal ideal domain (PID), i.e. we have instances `[IsDomain R] [IsPrincipalIdealRing R]`. We express "free `R`-module of finite rank" as a module `M` which has a basis `b : ΞΉ β†’ R`, where `ΞΉ` is a `Fintype`. We call the cardinality of `ΞΉ` the rank of `M` in this file; it would be equal to `finrank R M` if `R` is a field and `M` is a vector space. ## Main results In this section, `M` is a free and finitely generated `R`-module, and `N` is a submodule of `M`. - `Submodule.inductionOnRank`: if `P` holds for `βŠ₯ : Submodule R M` and if `P N` follows from `P N'` for all `N'` that are of lower rank, then `P` holds on all submodules - `Submodule.exists_basis_of_pid`: if `R` is a PID, then `N : Submodule R M` is free and finitely generated. This is the first part of the structure theorem for modules. - `Submodule.smithNormalForm`: if `R` is a PID, then `M` has a basis `bM` and `N` has a basis `bN` such that `bN i = a i β€’ bM i`. Equivalently, a linear map `f : M β†’β‚— M` with `range f = N` can be written as a matrix in Smith normal form, a diagonal matrix with the coefficients `a i` along the diagonal. ## Tags free module, finitely generated module, rank, structure theorem -/ universe u v section Ring variable {R : Type u} {M : Type v} [Ring R] [AddCommGroup M] [Module R M] variable {ΞΉ : Type*} (b : Basis ΞΉ R M) open Submodule.IsPrincipal Submodule theorem eq_bot_of_generator_maximal_map_eq_zero (b : Basis ΞΉ R M) {N : Submodule R M} {Ο• : M β†’β‚—[R] R} (hΟ• : βˆ€ ψ : M β†’β‚—[R] R, Β¬N.map Ο• < N.map ψ) [(N.map Ο•).IsPrincipal] (hgen : generator (N.map Ο•) = (0 : R)) : N = βŠ₯ := by rw [Submodule.eq_bot_iff] intro x hx refine b.ext_elem fun i ↦ ?_ rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hΟ• rw [LinearEquiv.map_zero, Finsupp.zero_apply] exact (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hΟ• (Finsupp.lapply i βˆ˜β‚— ↑b.repr)) _ ⟨x, hx, rfl⟩ theorem eq_bot_of_generator_maximal_submoduleImage_eq_zero {N O : Submodule R M} (b : Basis ΞΉ R O) (hNO : N ≀ O) {Ο• : O β†’β‚—[R] R} (hΟ• : βˆ€ ψ : O β†’β‚—[R] R, ¬ϕ.submoduleImage N < ψ.submoduleImage N) [(Ο•.submoduleImage N).IsPrincipal] (hgen : generator (Ο•.submoduleImage N) = 0) : N = βŠ₯ := by rw [Submodule.eq_bot_iff] intro x hx refine (mk_eq_zero _ _).mp (show (⟨x, hNO hx⟩ : O) = 0 from b.ext_elem fun i ↦ ?_) rw [(eq_bot_iff_generator_eq_zero _).mpr hgen] at hΟ• rw [LinearEquiv.map_zero, Finsupp.zero_apply] refine (Submodule.eq_bot_iff _).mp (not_bot_lt_iff.1 <| hΟ• (Finsupp.lapply i βˆ˜β‚— ↑b.repr)) _ ?_ exact (LinearMap.mem_submoduleImage_of_le hNO).mpr ⟨x, hx, rfl⟩ end Ring section IsDomain variable {ΞΉ : Type*} {R : Type*} [CommRing R] [IsDomain R] variable {M : Type*} [AddCommGroup M] [Module R M] {b : ΞΉ β†’ M} open Submodule.IsPrincipal Set Submodule theorem dvd_generator_iff {I : Ideal R} [I.IsPrincipal] {x : R} (hx : x ∈ I) : x ∣ generator I ↔ I = Ideal.span {x} := by conv_rhs => rw [← span_singleton_generator I]
rw [Ideal.submodule_span_eq, Ideal.span_singleton_eq_span_singleton, ← dvd_dvd_iff_associated, ← mem_iff_generator_dvd] exact ⟨fun h ↦ ⟨hx, h⟩, fun h ↦ h.2⟩ end IsDomain
Mathlib/LinearAlgebra/FreeModule/PID.lean
93
98
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, RΓ©my Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `Ο„` such that for all `i`, the preimage of `{j | j ≀ i}` along `Ο„` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the Οƒ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memLp_stoppedProcess`: if a process belongs to `β„’p` at every time in `β„•`, then its stopped process belongs to `β„’p` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ξ© Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ©} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `Ο„` such that for all `i`, the preimage of `{j | j ≀ i}` along `Ο„` is measurable with respect to `f i`. Intuitively, the stopping time `Ο„` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ΞΉ] (f : Filtration ΞΉ m) (Ο„ : Ξ© β†’ ΞΉ) := βˆ€ i : ΞΉ, MeasurableSet[f i] <| {Ο‰ | Ο„ Ο‰ ≀ i} theorem isStoppingTime_const [Preorder ΞΉ] (f : Filtration ΞΉ m) (i : ΞΉ) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] section MeasurableSet section Preorder variable [Preorder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} protected theorem IsStoppingTime.measurableSet_le (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ ≀ i} := hΟ„ i theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by by_cases hi_min : IsMin i Β· suffices {Ο‰ : Ξ© | Ο„ Ο‰ < i} = βˆ… by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 Ο‰ simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (Ο„ Ο‰) have : {Ο‰ : Ξ© | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hΟ„.measurableSet_le <| pred i) end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} protected theorem measurableSet_eq_of_countable_range (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := by have : {Ο‰ | Ο„ Ο‰ = i} = {Ο‰ | Ο„ Ο‰ ≀ i} \ ⋃ (j ∈ Set.range Ο„) (_ : j < i), {Ο‰ | Ο„ Ο‰ ≀ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h Β· simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] Β· exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hΟ„.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ classical rw [Set.iUnion_eq_if] split_ifs with hji Β· exact f.mono hji.le _ (hΟ„.measurableSet_le j) Β· exact @MeasurableSet.empty _ (f i) protected theorem measurableSet_eq_of_countable [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := hΟ„.measurableSet_eq_of_countable_range (Set.to_countable _) i protected theorem measurableSet_lt_of_countable_range (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by have : {Ο‰ | Ο„ Ο‰ < i} = {Ο‰ | Ο„ Ο‰ ≀ i} \ {Ο‰ | Ο„ Ο‰ = i} := by ext1 Ο‰; simp [lt_iff_le_and_ne] rw [this] exact (hΟ„.measurableSet_le i).diff (hΟ„.measurableSet_eq_of_countable_range h_countable i) protected theorem measurableSet_lt_of_countable [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := hΟ„.measurableSet_lt_of_countable_range (Set.to_countable _) i protected theorem measurableSet_ge_of_countable_range {ΞΉ} [LinearOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} (hΟ„ : IsStoppingTime f Ο„) (h_countable : (Set.range Ο„).Countable) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := by have : {Ο‰ | i ≀ Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ < i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hΟ„.measurableSet_lt_of_countable_range h_countable i).compl protected theorem measurableSet_ge_of_countable {ΞΉ} [LinearOrder ΞΉ] {Ο„ : Ξ© β†’ ΞΉ} {f : Filtration ΞΉ m} [Countable ΞΉ] (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := hΟ„.measurableSet_ge_of_countable_range (Set.to_countable _) i end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} theorem IsStoppingTime.measurableSet_gt (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i < Ο„ Ο‰} := by have : {Ο‰ | i < Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ ≀ i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hΟ„.measurableSet_le i).compl section TopologicalSpace variable [TopologicalSpace ΞΉ] [OrderTopology ΞΉ] [FirstCountableTopology ΞΉ] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by by_cases hi_min : IsMin i Β· suffices {Ο‰ | Ο„ Ο‰ < i} = βˆ… by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 Ο‰ simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false] exact isMin_iff_forall_not_lt.mp hi_min (Ο„ Ο‰) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : βˆƒ seq : β„• β†’ ΞΉ, Monotone seq ∧ (βˆ€ j, seq j ≀ i) ∧ Tendsto seq atTop (𝓝 i) ∧ βˆ€ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≀ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ Β· rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : βˆƒ a : β„•, βˆ€ b : β„•, b β‰₯ a β†’ k ≀ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ Β· obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {Ο‰ | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iio i := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hΟ„.measurableSet_le (seq n)) theorem IsStoppingTime.measurableSet_lt (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ < i} := by obtain ⟨i', hi'_lub⟩ : βˆƒ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i rcases lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i | h_Iio_eq_Iic Β· rw [← hi'_eq_i] at hi'_lub ⊒ exact hΟ„.measurableSet_lt_of_isLUB i' hi'_lub Β· have h_lt_eq_preimage : {Ο‰ : Ξ© | Ο„ Ο‰ < i} = Ο„ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hΟ„.measurableSet_le i') theorem IsStoppingTime.measurableSet_ge (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | i ≀ Ο„ Ο‰} := by have : {Ο‰ | i ≀ Ο„ Ο‰} = {Ο‰ | Ο„ Ο‰ < i}ᢜ := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hΟ„.measurableSet_lt i).compl theorem IsStoppingTime.measurableSet_eq (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i} := by have : {Ο‰ | Ο„ Ο‰ = i} = {Ο‰ | Ο„ Ο‰ ≀ i} ∩ {Ο‰ | Ο„ Ο‰ β‰₯ i} := by ext1 Ο‰; simp only [Set.mem_setOf_eq, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hΟ„.measurableSet_le i).inter (hΟ„.measurableSet_ge i) theorem IsStoppingTime.measurableSet_eq_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ = i} := f.mono hle _ <| hΟ„.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ < i} := f.mono hle _ <| hΟ„.measurableSet_lt i end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ΞΉ] [Countable ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : βˆ€ i, MeasurableSet[f i] {Ο‰ | Ο„ Ο‰ = i}) : IsStoppingTime f Ο„ := by intro i rw [show {Ο‰ | Ο„ Ο‰ ≀ i} = ⋃ k ≀ i, {Ο‰ | Ο„ Ο‰ = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hΟ„ k) end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ Ο€ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (hΟ€ : IsStoppingTime f Ο€) : IsStoppingTime f fun Ο‰ => max (Ο„ Ο‰) (Ο€ Ο‰) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hΟ„ i).inter (hΟ€ i) protected theorem max_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : IsStoppingTime f fun Ο‰ => max (Ο„ Ο‰) i := hΟ„.max (isStoppingTime_const f i) protected theorem min [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ Ο€ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (hΟ€ : IsStoppingTime f Ο€) : IsStoppingTime f fun Ο‰ => min (Ο„ Ο‰) (Ο€ Ο‰) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hΟ„ i).union (hΟ€ i) protected theorem min_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : IsStoppingTime f fun Ο‰ => min (Ο„ Ο‰) i := hΟ„.min (isStoppingTime_const f i)
theorem add_const [AddGroup ΞΉ] [Preorder ΞΉ] [AddRightMono ΞΉ] [AddLeftMono ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) {i : ΞΉ} (hi : 0 ≀ i) : IsStoppingTime f fun Ο‰ => Ο„ Ο‰ + i := by intro j
Mathlib/Probability/Process/Stopping.lean
248
252
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Function.ConvergenceInMeasure import Mathlib.MeasureTheory.Function.L1Space.Integrable /-! # Uniform integrability This file contains the definitions for uniform integrability (both in the measure theory sense as well as the probability theory sense). This file also contains the Vitali convergence theorem which establishes a relation between uniform integrability, convergence in measure and Lp convergence. Uniform integrability plays a vital role in the theory of martingales most notably is used to formulate the martingale convergence theorem. ## Main definitions * `MeasureTheory.UnifIntegrable`: uniform integrability in the measure theory sense. In particular, a sequence of functions `f` is uniformly integrable if for all `Ξ΅ > 0`, there exists some `Ξ΄ > 0` such that for all sets `s` of smaller measure than `Ξ΄`, the Lp-norm of `f i` restricted `s` is smaller than `Ξ΅` for all `i`. * `MeasureTheory.UniformIntegrable`: uniform integrability in the probability theory sense. In particular, a sequence of measurable functions `f` is uniformly integrable in the probability theory sense if it is uniformly integrable in the measure theory sense and has uniformly bounded Lp-norm. # Main results * `MeasureTheory.unifIntegrable_finite`: a finite sequence of Lp functions is uniformly integrable. * `MeasureTheory.tendsto_Lp_finite_of_tendsto_ae`: a sequence of Lp functions which is uniformly integrable converges in Lp if they converge almost everywhere. * `MeasureTheory.tendstoInMeasure_iff_tendsto_Lp_finite`: Vitali convergence theorem: a sequence of Lp functions converges in Lp if and only if it is uniformly integrable and converges in measure. ## Tags uniform integrable, uniformly absolutely continuous integral, Vitali convergence theorem -/ noncomputable section open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory open Set Filter TopologicalSpace variable {Ξ± Ξ² ΞΉ : Type*} {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} [NormedAddCommGroup Ξ²] /-- Uniform integrability in the measure theory sense. A sequence of functions `f` is said to be uniformly integrable if for all `Ξ΅ > 0`, there exists some `Ξ΄ > 0` such that for all sets `s` with measure less than `Ξ΄`, the Lp-norm of `f i` restricted on `s` is less than `Ξ΅`. Uniform integrability is also known as uniformly absolutely continuous integrals. -/ def UnifIntegrable {_ : MeasurableSpace Ξ±} (f : ΞΉ β†’ Ξ± β†’ Ξ²) (p : ℝβ‰₯0∞) (ΞΌ : Measure Ξ±) : Prop := βˆ€ ⦃Ρ : ℝ⦄ (_ : 0 < Ξ΅), βˆƒ (Ξ΄ : ℝ) (_ : 0 < Ξ΄), βˆ€ i s, MeasurableSet s β†’ ΞΌ s ≀ ENNReal.ofReal Ξ΄ β†’ eLpNorm (s.indicator (f i)) p ΞΌ ≀ ENNReal.ofReal Ξ΅ /-- In probability theory, a family of measurable functions is uniformly integrable if it is uniformly integrable in the measure theory sense and is uniformly bounded. -/ def UniformIntegrable {_ : MeasurableSpace Ξ±} (f : ΞΉ β†’ Ξ± β†’ Ξ²) (p : ℝβ‰₯0∞) (ΞΌ : Measure Ξ±) : Prop := (βˆ€ i, AEStronglyMeasurable (f i) ΞΌ) ∧ UnifIntegrable f p ΞΌ ∧ βˆƒ C : ℝβ‰₯0, βˆ€ i, eLpNorm (f i) p ΞΌ ≀ C namespace UniformIntegrable protected theorem aestronglyMeasurable {f : ΞΉ β†’ Ξ± β†’ Ξ²} {p : ℝβ‰₯0∞} (hf : UniformIntegrable f p ΞΌ) (i : ΞΉ) : AEStronglyMeasurable (f i) ΞΌ := hf.1 i @[deprecated (since := "2025-04-09")] alias aeStronglyMeasurable := UniformIntegrable.aestronglyMeasurable protected theorem unifIntegrable {f : ΞΉ β†’ Ξ± β†’ Ξ²} {p : ℝβ‰₯0∞} (hf : UniformIntegrable f p ΞΌ) : UnifIntegrable f p ΞΌ := hf.2.1 protected theorem memLp {f : ΞΉ β†’ Ξ± β†’ Ξ²} {p : ℝβ‰₯0∞} (hf : UniformIntegrable f p ΞΌ) (i : ΞΉ) : MemLp (f i) p ΞΌ := ⟨hf.1 i, let ⟨_, _, hC⟩ := hf.2 lt_of_le_of_lt (hC i) ENNReal.coe_lt_top⟩ end UniformIntegrable section UnifIntegrable /-! ### `UnifIntegrable` This section deals with uniform integrability in the measure theory sense. -/ namespace UnifIntegrable variable {f g : ΞΉ β†’ Ξ± β†’ Ξ²} {p : ℝβ‰₯0∞} protected theorem add (hf : UnifIntegrable f p ΞΌ) (hg : UnifIntegrable g p ΞΌ) (hp : 1 ≀ p) (hf_meas : βˆ€ i, AEStronglyMeasurable (f i) ΞΌ) (hg_meas : βˆ€ i, AEStronglyMeasurable (g i) ΞΌ) : UnifIntegrable (f + g) p ΞΌ := by intro Ξ΅ hΞ΅ have hΞ΅2 : 0 < Ξ΅ / 2 := half_pos hΞ΅ obtain βŸ¨Ξ΄β‚, hδ₁_pos, hfΞ΄β‚βŸ© := hf hΞ΅2 obtain βŸ¨Ξ΄β‚‚, hΞ΄β‚‚_pos, hgΞ΄β‚‚βŸ© := hg hΞ΅2 refine ⟨min δ₁ Ξ΄β‚‚, lt_min hδ₁_pos hΞ΄β‚‚_pos, fun i s hs hΞΌs => ?_⟩ simp_rw [Pi.add_apply, Set.indicator_add'] refine (eLpNorm_add_le ((hf_meas i).indicator hs) ((hg_meas i).indicator hs) hp).trans ?_ have hΞ΅_halves : ENNReal.ofReal Ξ΅ = ENNReal.ofReal (Ξ΅ / 2) + ENNReal.ofReal (Ξ΅ / 2) := by rw [← ENNReal.ofReal_add hΞ΅2.le hΞ΅2.le, add_halves] rw [hΞ΅_halves] exact add_le_add (hfδ₁ i s hs (hΞΌs.trans (ENNReal.ofReal_le_ofReal (min_le_left _ _)))) (hgΞ΄β‚‚ i s hs (hΞΌs.trans (ENNReal.ofReal_le_ofReal (min_le_right _ _)))) protected theorem neg (hf : UnifIntegrable f p ΞΌ) : UnifIntegrable (-f) p ΞΌ := by simp_rw [UnifIntegrable, Pi.neg_apply, Set.indicator_neg', eLpNorm_neg] exact hf protected theorem sub (hf : UnifIntegrable f p ΞΌ) (hg : UnifIntegrable g p ΞΌ) (hp : 1 ≀ p) (hf_meas : βˆ€ i, AEStronglyMeasurable (f i) ΞΌ) (hg_meas : βˆ€ i, AEStronglyMeasurable (g i) ΞΌ) : UnifIntegrable (f - g) p ΞΌ := by rw [sub_eq_add_neg] exact hf.add hg.neg hp hf_meas fun i => (hg_meas i).neg protected theorem ae_eq (hf : UnifIntegrable f p ΞΌ) (hfg : βˆ€ n, f n =ᡐ[ΞΌ] g n) : UnifIntegrable g p ΞΌ := by classical intro Ξ΅ hΞ΅ obtain ⟨δ, hΞ΄_pos, hfδ⟩ := hf hΞ΅ refine ⟨δ, hΞ΄_pos, fun n s hs hΞΌs => (le_of_eq <| eLpNorm_congr_ae ?_).trans (hfΞ΄ n s hs hΞΌs)⟩ filter_upwards [hfg n] with x hx simp_rw [Set.indicator_apply, hx] /-- Uniform integrability is preserved by restriction of the functions to a set. -/ protected theorem indicator (hf : UnifIntegrable f p ΞΌ) (E : Set Ξ±) : UnifIntegrable (fun i => E.indicator (f i)) p ΞΌ := fun Ξ΅ hΞ΅ ↦ by obtain ⟨δ, hΞ΄_pos, hΡ⟩ := hf hΞ΅ refine ⟨δ, hΞ΄_pos, fun i s hs hΞΌs ↦ ?_⟩ calc eLpNorm (s.indicator (E.indicator (f i))) p ΞΌ = eLpNorm (E.indicator (s.indicator (f i))) p ΞΌ := by simp only [indicator_indicator, inter_comm] _ ≀ eLpNorm (s.indicator (f i)) p ΞΌ := eLpNorm_indicator_le _ _ ≀ ENNReal.ofReal Ξ΅ := hΞ΅ _ _ hs hΞΌs /-- Uniform integrability is preserved by restriction of the measure to a set. -/ protected theorem restrict (hf : UnifIntegrable f p ΞΌ) (E : Set Ξ±) : UnifIntegrable f p (ΞΌ.restrict E) := fun Ξ΅ hΞ΅ ↦ by obtain ⟨δ, hΞ΄_pos, hδΡ⟩ := hf hΞ΅ refine ⟨δ, hΞ΄_pos, fun i s hs hΞΌs ↦ ?_⟩ rw [ΞΌ.restrict_apply hs, ← measure_toMeasurable] at hΞΌs calc eLpNorm (indicator s (f i)) p (ΞΌ.restrict E) = eLpNorm (f i) p (ΞΌ.restrict (s ∩ E)) := by rw [eLpNorm_indicator_eq_eLpNorm_restrict hs, ΞΌ.restrict_restrict hs] _ ≀ eLpNorm (f i) p (ΞΌ.restrict (toMeasurable ΞΌ (s ∩ E))) := eLpNorm_mono_measure _ <| Measure.restrict_mono (subset_toMeasurable _ _) le_rfl _ = eLpNorm (indicator (toMeasurable ΞΌ (s ∩ E)) (f i)) p ΞΌ := (eLpNorm_indicator_eq_eLpNorm_restrict (measurableSet_toMeasurable _ _)).symm _ ≀ ENNReal.ofReal Ξ΅ := hδΡ i _ (measurableSet_toMeasurable _ _) hΞΌs end UnifIntegrable theorem unifIntegrable_zero_meas [MeasurableSpace Ξ±] {p : ℝβ‰₯0∞} {f : ΞΉ β†’ Ξ± β†’ Ξ²} : UnifIntegrable f p (0 : Measure Ξ±) := fun Ξ΅ _ => ⟨1, one_pos, fun i s _ _ => by simp⟩ theorem unifIntegrable_congr_ae {p : ℝβ‰₯0∞} {f g : ΞΉ β†’ Ξ± β†’ Ξ²} (hfg : βˆ€ n, f n =ᡐ[ΞΌ] g n) : UnifIntegrable f p ΞΌ ↔ UnifIntegrable g p ΞΌ := ⟨fun hf => hf.ae_eq hfg, fun hg => hg.ae_eq fun n => (hfg n).symm⟩ theorem tendsto_indicator_ge (f : Ξ± β†’ Ξ²) (x : Ξ±) : Tendsto (fun M : β„• => { x | (M : ℝ) ≀ β€–f xβ€–β‚Š }.indicator f x) atTop (𝓝 0) := by refine tendsto_atTop_of_eventually_const (iβ‚€ := Nat.ceil (β€–f xβ€–β‚Š : ℝ) + 1) fun n hn => ?_ rw [Set.indicator_of_not_mem] simp only [not_le, Set.mem_setOf_eq] refine lt_of_le_of_lt (Nat.le_ceil _) ?_ refine lt_of_lt_of_le (lt_add_one _) ?_ norm_cast variable {p : ℝβ‰₯0∞} section variable {f : Ξ± β†’ Ξ²} /-- This lemma is weaker than `MeasureTheory.MemLp.integral_indicator_norm_ge_nonneg_le` as the latter provides `0 ≀ M` and does not require the measurability of `f`. -/ theorem MemLp.integral_indicator_norm_ge_le (hf : MemLp f 1 ΞΌ) (hmeas : StronglyMeasurable f) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ M : ℝ, (∫⁻ x, β€–{ x | M ≀ β€–f xβ€–β‚Š }.indicator f xβ€–β‚Š βˆ‚ΞΌ) ≀ ENNReal.ofReal Ξ΅ := by have htendsto : βˆ€α΅ x βˆ‚ΞΌ, Tendsto (fun M : β„• => { x | (M : ℝ) ≀ β€–f xβ€–β‚Š }.indicator f x) atTop (𝓝 0) := univ_mem' (id fun x => tendsto_indicator_ge f x) have hmeas : βˆ€ M : β„•, AEStronglyMeasurable ({ x | (M : ℝ) ≀ β€–f xβ€–β‚Š }.indicator f) ΞΌ := by intro M apply hf.1.indicator apply StronglyMeasurable.measurableSet_le stronglyMeasurable_const hmeas.nnnorm.measurable.coe_nnreal_real.stronglyMeasurable have hbound : HasFiniteIntegral (fun x => β€–f xβ€–) ΞΌ := by rw [memLp_one_iff_integrable] at hf exact hf.norm.2 have : Tendsto (fun n : β„• ↦ ∫⁻ a, ENNReal.ofReal β€–{ x | n ≀ β€–f xβ€–β‚Š }.indicator f a - 0β€– βˆ‚ΞΌ) atTop (𝓝 0) := by refine tendsto_lintegral_norm_of_dominated_convergence hmeas hbound ?_ htendsto refine fun n => univ_mem' (id fun x => ?_) by_cases hx : (n : ℝ) ≀ β€–f xβ€– Β· dsimp rwa [Set.indicator_of_mem] Β· dsimp rw [Set.indicator_of_not_mem, norm_zero] Β· exact norm_nonneg _ Β· assumption rw [ENNReal.tendsto_atTop_zero] at this obtain ⟨M, hM⟩ := this (ENNReal.ofReal Ξ΅) (ENNReal.ofReal_pos.2 hΞ΅) simp only [zero_tsub, zero_le, sub_zero, zero_add, coe_nnnorm, Set.mem_Icc] at hM refine ⟨M, ?_⟩ convert hM M le_rfl simp only [coe_nnnorm, ENNReal.ofReal_eq_coe_nnreal (norm_nonneg _)] rfl /-- This lemma is superseded by `MeasureTheory.MemLp.integral_indicator_norm_ge_nonneg_le` which does not require measurability. -/ theorem MemLp.integral_indicator_norm_ge_nonneg_le_of_meas (hf : MemLp f 1 ΞΌ) (hmeas : StronglyMeasurable f) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ M : ℝ, 0 ≀ M ∧ (∫⁻ x, β€–{ x | M ≀ β€–f xβ€–β‚Š }.indicator f xβ€–β‚‘ βˆ‚ΞΌ) ≀ ENNReal.ofReal Ξ΅ := let ⟨M, hM⟩ := hf.integral_indicator_norm_ge_le hmeas hΞ΅ ⟨max M 0, le_max_right _ _, by simpa⟩ theorem MemLp.integral_indicator_norm_ge_nonneg_le (hf : MemLp f 1 ΞΌ) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ M : ℝ, 0 ≀ M ∧ (∫⁻ x, β€–{ x | M ≀ β€–f xβ€–β‚Š }.indicator f xβ€–β‚‘ βˆ‚ΞΌ) ≀ ENNReal.ofReal Ξ΅ := by have hf_mk : MemLp (hf.1.mk f) 1 ΞΌ := (memLp_congr_ae hf.1.ae_eq_mk).mp hf obtain ⟨M, hM_pos, hfM⟩ := hf_mk.integral_indicator_norm_ge_nonneg_le_of_meas hf.1.stronglyMeasurable_mk hΞ΅ refine ⟨M, hM_pos, (le_of_eq ?_).trans hfM⟩ refine lintegral_congr_ae ?_ filter_upwards [hf.1.ae_eq_mk] with x hx simp only [Set.indicator_apply, coe_nnnorm, Set.mem_setOf_eq, ENNReal.coe_inj, hx.symm] theorem MemLp.eLpNormEssSup_indicator_norm_ge_eq_zero (hf : MemLp f ∞ ΞΌ) (hmeas : StronglyMeasurable f) : βˆƒ M : ℝ, eLpNormEssSup ({ x | M ≀ β€–f xβ€–β‚Š }.indicator f) ΞΌ = 0 := by have hbdd : eLpNormEssSup f ΞΌ < ∞ := hf.eLpNorm_lt_top refine ⟨(eLpNorm f ∞ ΞΌ + 1).toReal, ?_⟩ rw [eLpNormEssSup_indicator_eq_eLpNormEssSup_restrict] Β· have : ΞΌ.restrict { x : Ξ± | (eLpNorm f ⊀ ΞΌ + 1).toReal ≀ β€–f xβ€–β‚Š } = 0 := by simp only [coe_nnnorm, eLpNorm_exponent_top, Measure.restrict_eq_zero] have : { x : Ξ± | (eLpNormEssSup f ΞΌ + 1).toReal ≀ β€–f xβ€– } βŠ† { x : Ξ± | eLpNormEssSup f ΞΌ < β€–f xβ€–β‚Š } := by intro x hx rw [Set.mem_setOf_eq, ← ENNReal.toReal_lt_toReal hbdd.ne ENNReal.coe_lt_top.ne, ENNReal.coe_toReal, coe_nnnorm] refine lt_of_lt_of_le ?_ hx rw [ENNReal.toReal_lt_toReal hbdd.ne] Β· exact ENNReal.lt_add_right hbdd.ne one_ne_zero Β· exact (ENNReal.add_lt_top.2 ⟨hbdd, ENNReal.one_lt_top⟩).ne rw [← nonpos_iff_eq_zero] refine (measure_mono this).trans ?_ have hle := enorm_ae_le_eLpNormEssSup f ΞΌ simp_rw [ae_iff, not_le] at hle exact nonpos_iff_eq_zero.2 hle rw [this, eLpNormEssSup_measure_zero] exact measurableSet_le measurable_const hmeas.nnnorm.measurable.subtype_coe /- This lemma is slightly weaker than `MeasureTheory.MemLp.eLpNorm_indicator_norm_ge_pos_le` as the latter provides `0 < M`. -/ theorem MemLp.eLpNorm_indicator_norm_ge_le (hf : MemLp f p ΞΌ) (hmeas : StronglyMeasurable f) {Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) : βˆƒ M : ℝ, eLpNorm ({ x | M ≀ β€–f xβ€–β‚Š }.indicator f) p ΞΌ ≀ ENNReal.ofReal Ξ΅ := by by_cases hp_ne_zero : p = 0 Β· refine ⟨1, hp_ne_zero.symm β–Έ ?_⟩ simp [eLpNorm_exponent_zero] by_cases hp_ne_top : p = ∞ Β· subst hp_ne_top obtain ⟨M, hM⟩ := hf.eLpNormEssSup_indicator_norm_ge_eq_zero hmeas refine ⟨M, ?_⟩ simp only [eLpNorm_exponent_top, hM, zero_le] obtain ⟨M, hM', hM⟩ := MemLp.integral_indicator_norm_ge_nonneg_le (ΞΌ := ΞΌ) (hf.norm_rpow hp_ne_zero hp_ne_top) (Real.rpow_pos_of_pos hΞ΅ p.toReal) refine ⟨M ^ (1 / p.toReal), ?_⟩ rw [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top, ← ENNReal.rpow_one (ENNReal.ofReal Ξ΅)] conv_rhs => rw [← mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm] rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top), ENNReal.ofReal_rpow_of_pos hΞ΅] convert hM using 3 with x rw [enorm_indicator_eq_indicator_enorm, enorm_indicator_eq_indicator_enorm] have hiff : M ^ (1 / p.toReal) ≀ β€–f xβ€–β‚Š ↔ M ≀ β€–β€–f xβ€– ^ p.toRealβ€–β‚Š := by rw [coe_nnnorm, coe_nnnorm, Real.norm_rpow_of_nonneg (norm_nonneg _), norm_norm, ← Real.rpow_le_rpow_iff hM' (Real.rpow_nonneg (norm_nonneg _) _) (one_div_pos.2 <| ENNReal.toReal_pos hp_ne_zero hp_ne_top), ← Real.rpow_mul (norm_nonneg _), mul_one_div_cancel (ENNReal.toReal_pos hp_ne_zero hp_ne_top).ne.symm, Real.rpow_one] by_cases hx : x ∈ { x : Ξ± | M ^ (1 / p.toReal) ≀ β€–f xβ€–β‚Š }
Β· rw [Set.indicator_of_mem hx, Set.indicator_of_mem, Real.enorm_of_nonneg (by positivity), ← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) ENNReal.toReal_nonneg, ofReal_norm] rw [Set.mem_setOf_eq] rwa [← hiff] Β· rw [Set.indicator_of_not_mem hx, Set.indicator_of_not_mem] Β· simp [ENNReal.toReal_pos hp_ne_zero hp_ne_top] Β· rw [Set.mem_setOf_eq] rwa [← hiff] /-- This lemma implies that a single function is uniformly integrable (in the probability sense). -/
Mathlib/MeasureTheory/Function/UniformIntegrable.lean
298
307
/- Copyright (c) 2024 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.LinearAlgebra.Dimension.Finite import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Some results on free modules over rings satisfying strong rank condition This file contains some results on free modules over rings satisfying strong rank condition. Most of them are generalized from the same result assuming the base ring being division ring, and are moved from the files `Mathlib/LinearAlgebra/Dimension/DivisionRing.lean` and `Mathlib/LinearAlgebra/FiniteDimensional.lean`. -/ open Cardinal Module Module Set Submodule universe u v section Module variable {K : Type u} {V : Type v} [Ring K] [StrongRankCondition K] [AddCommGroup V] [Module K V] /-- The `ΞΉ` indexed basis on `V`, where `ΞΉ` is an empty type and `V` is zero-dimensional. See also `Module.finBasis`. -/ noncomputable def Basis.ofRankEqZero [Module.Free K V] {ΞΉ : Type*} [IsEmpty ΞΉ] (hV : Module.rank K V = 0) : Basis ΞΉ K V := haveI : Subsingleton V := by obtain ⟨_, b⟩ := Module.Free.exists_basis (R := K) (M := V) haveI := mk_eq_zero_iff.1 (hV β–Έ b.mk_eq_rank'') exact b.repr.toEquiv.subsingleton Basis.empty _ @[simp] theorem Basis.ofRankEqZero_apply [Module.Free K V] {ΞΉ : Type*} [IsEmpty ΞΉ] (hV : Module.rank K V = 0) (i : ΞΉ) : Basis.ofRankEqZero hV i = 0 := rfl theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} : c ≀ Module.rank K V ↔ βˆƒ s : Set V, #s = c ∧ LinearIndepOn K id s := by haveI := nontrivial_of_invariantBasisNumber K constructor Β· intro h obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V) let t := t'.reindexRange have : LinearIndepOn K id (Set.range t') := by convert t.linearIndependent.linearIndepOn_id ext simp [t] rw [← t.mk_eq_rank'', le_mk_iff_exists_subset] at h rcases h with ⟨s, hst, hsc⟩ exact ⟨s, hsc, this.mono hst⟩ Β· rintro ⟨s, rfl, si⟩ exact si.cardinal_le_rank theorem le_rank_iff_exists_linearIndependent_finset [Module.Free K V] {n : β„•} : ↑n ≀ Module.rank K V ↔ βˆƒ s : Finset V, s.card = n ∧ LinearIndependent K ((↑) : β†₯(s : Set V) β†’ V) := by simp only [le_rank_iff_exists_linearIndependent, mk_set_eq_nat_iff_finset] constructor Β· rintro ⟨s, ⟨t, rfl, rfl⟩, si⟩ exact ⟨t, rfl, si⟩ Β· rintro ⟨s, rfl, si⟩ exact ⟨s, ⟨s, rfl, rfl⟩, si⟩ /-- A vector space has dimension at most `1` if and only if there is a single vector of which all vectors are multiples. -/ theorem rank_le_one_iff [Module.Free K V] : Module.rank K V ≀ 1 ↔ βˆƒ vβ‚€ : V, βˆ€ v, βˆƒ r : K, r β€’ vβ‚€ = v := by obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V) constructor Β· intro hd rw [← b.mk_eq_rank'', le_one_iff_subsingleton] at hd rcases isEmpty_or_nonempty ΞΊ with hb | ⟨⟨i⟩⟩ Β· use 0 have h' : βˆ€ v : V, v = 0 := by simpa [range_eq_empty, Submodule.eq_bot_iff] using b.span_eq.symm intro v simp [h' v] Β· use b i have h' : (K βˆ™ b i) = ⊀ := (subsingleton_range b).eq_singleton_of_mem (mem_range_self i) β–Έ b.span_eq intro v have hv : v ∈ (⊀ : Submodule K V) := mem_top rwa [← h', mem_span_singleton] at hv Β· rintro ⟨vβ‚€, hvβ‚€βŸ© have h : (K βˆ™ vβ‚€) = ⊀ := by ext simp [mem_span_singleton, hvβ‚€] rw [← rank_top, ← h] refine (rank_span_le _).trans_eq ?_ simp /-- A vector space has dimension `1` if and only if there is a single non-zero vector of which all vectors are multiples. -/ theorem rank_eq_one_iff [Module.Free K V] : Module.rank K V = 1 ↔ βˆƒ vβ‚€ : V, vβ‚€ β‰  0 ∧ βˆ€ v, βˆƒ r : K, r β€’ vβ‚€ = v := by haveI := nontrivial_of_invariantBasisNumber K refine ⟨fun h ↦ ?_, fun ⟨vβ‚€, h, hv⟩ ↦ (rank_le_one_iff.2 ⟨vβ‚€, hv⟩).antisymm ?_⟩ Β· obtain ⟨vβ‚€, hv⟩ := rank_le_one_iff.1 h.le refine ⟨vβ‚€, fun hzero ↦ ?_, hv⟩ simp_rw [hzero, smul_zero, exists_const] at hv haveI : Subsingleton V := .intro fun _ _ ↦ by simp_rw [← hv] exact one_ne_zero (h β–Έ rank_subsingleton' K V) Β· by_contra H rw [not_le, lt_one_iff_zero] at H obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := V) haveI := mk_eq_zero_iff.1 (H β–Έ b.mk_eq_rank'') haveI := b.repr.toEquiv.subsingleton exact h (Subsingleton.elim _ _) /-- A submodule has dimension at most `1` if and only if there is a single vector in the submodule such that the submodule is contained in its span. -/ theorem rank_submodule_le_one_iff (s : Submodule K V) [Module.Free K s] : Module.rank K s ≀ 1 ↔ βˆƒ vβ‚€ ∈ s, s ≀ K βˆ™ vβ‚€ := by simp_rw [rank_le_one_iff, le_span_singleton_iff] constructor Β· rintro ⟨⟨vβ‚€, hvβ‚€βŸ©, h⟩ use vβ‚€, hvβ‚€ intro v hv obtain ⟨r, hr⟩ := h ⟨v, hv⟩ use r rwa [Subtype.ext_iff, coe_smul] at hr Β· rintro ⟨vβ‚€, hvβ‚€, h⟩ use ⟨vβ‚€, hvβ‚€βŸ© rintro ⟨v, hv⟩ obtain ⟨r, hr⟩ := h v hv use r rwa [Subtype.ext_iff, coe_smul] /-- A submodule has dimension `1` if and only if there is a single non-zero vector in the submodule such that the submodule is contained in its span. -/ theorem rank_submodule_eq_one_iff (s : Submodule K V) [Module.Free K s] : Module.rank K s = 1 ↔ βˆƒ vβ‚€ ∈ s, vβ‚€ β‰  0 ∧ s ≀ K βˆ™ vβ‚€ := by simp_rw [rank_eq_one_iff, le_span_singleton_iff] refine ⟨fun ⟨⟨vβ‚€, hvβ‚€βŸ©, H, h⟩ ↦ ⟨vβ‚€, hvβ‚€, fun h' ↦ by simp only [h', ne_eq] at H; exact H rfl, fun v hv ↦ ?_⟩, fun ⟨vβ‚€, hvβ‚€, H, h⟩ ↦ ⟨⟨vβ‚€, hvβ‚€βŸ©, fun h' ↦ H (by rwa [AddSubmonoid.mk_eq_zero] at h'), fun ⟨v, hv⟩ ↦ ?_⟩⟩ Β· obtain ⟨r, hr⟩ := h ⟨v, hv⟩ exact ⟨r, by rwa [Subtype.ext_iff, coe_smul] at hr⟩ Β· obtain ⟨r, hr⟩ := h v hv exact ⟨r, by rwa [Subtype.ext_iff, coe_smul]⟩ /-- A submodule has dimension at most `1` if and only if there is a single vector, not necessarily in the submodule, such that the submodule is contained in its span. -/ theorem rank_submodule_le_one_iff' (s : Submodule K V) [Module.Free K s] : Module.rank K s ≀ 1 ↔ βˆƒ vβ‚€, s ≀ K βˆ™ vβ‚€ := by haveI := nontrivial_of_invariantBasisNumber K constructor Β· rw [rank_submodule_le_one_iff] rintro ⟨vβ‚€, _, h⟩ exact ⟨vβ‚€, h⟩ Β· rintro ⟨vβ‚€, h⟩ obtain ⟨κ, b⟩ := Module.Free.exists_basis (R := K) (M := s) simpa [b.mk_eq_rank''] using b.linearIndependent.map' _ (ker_inclusion _ _ h) |>.cardinal_le_rank.trans (rank_span_le {vβ‚€}) theorem Submodule.rank_le_one_iff_isPrincipal (W : Submodule K V) [Module.Free K W] : Module.rank K W ≀ 1 ↔ W.IsPrincipal := by simp only [rank_le_one_iff, Submodule.isPrincipal_iff, le_antisymm_iff, le_span_singleton_iff, span_singleton_le_iff_mem] constructor Β· rintro ⟨⟨m, hm⟩, hm'⟩ choose f hf using hm' exact ⟨m, ⟨fun v hv => ⟨f ⟨v, hv⟩, congr_arg ((↑) : W β†’ V) (hf ⟨v, hv⟩)⟩, hm⟩⟩ Β· rintro ⟨a, ⟨h, ha⟩⟩ choose f hf using h exact ⟨⟨a, ha⟩, fun v => ⟨f v.1 v.2, Subtype.ext (hf v.1 v.2)⟩⟩ theorem Module.rank_le_one_iff_top_isPrincipal [Module.Free K V] : Module.rank K V ≀ 1 ↔ (⊀ : Submodule K V).IsPrincipal := by haveI := Module.Free.of_equiv (topEquiv (R := K) (M := V)).symm rw [← Submodule.rank_le_one_iff_isPrincipal, rank_top] /-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis. -/ theorem finrank_eq_one_iff [Module.Free K V] (ΞΉ : Type*) [Unique ΞΉ] : finrank K V = 1 ↔ Nonempty (Basis ΞΉ K V) := by constructor Β· intro h exact ⟨Module.basisUnique ΞΉ h⟩ Β· rintro ⟨b⟩ simpa using finrank_eq_card_basis b /-- A module has dimension 1 iff there is some nonzero `v : V` so every vector is a multiple of `v`. -/ theorem finrank_eq_one_iff' [Module.Free K V] : finrank K V = 1 ↔ βˆƒ v β‰  0, βˆ€ w : V, βˆƒ c : K, c β€’ v = w := by rw [← rank_eq_one_iff] exact toNat_eq_iff one_ne_zero /-- A finite dimensional module has dimension at most 1 iff there is some `v : V` so every vector is a multiple of `v`.
-/ theorem finrank_le_one_iff [Module.Free K V] [Module.Finite K V] : finrank K V ≀ 1 ↔ βˆƒ v : V, βˆ€ w : V, βˆƒ c : K, c β€’ v = w := by rw [← rank_le_one_iff, ← finrank_eq_rank, Nat.cast_le_one]
Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean
203
206
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine import Mathlib.Tactic.IntervalCases /-! # Triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) triangles in real inner product spaces and Euclidean affine spaces. More specialized results, and results developed for simplices in general rather than just for triangles, are in separate files. Definitions and results that make sense in more general affine spaces rather than just in the Euclidean case go under `LinearAlgebra.AffineSpace`. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Law_of_cosines * https://en.wikipedia.org/wiki/Pons_asinorum * https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle -/ noncomputable section open scoped CharZero Real RealInnerProductSpace namespace InnerProductGeometry /-! ### Geometrical results on triangles in real inner product spaces This section develops some results on (possibly degenerate) triangles in real inner product spaces, where those definitions and results can most conveniently be developed in terms of vectors and then used to deduce corresponding results for Euclidean affine spaces. -/ variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- **Law of cosines** (cosine rule), vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_sub_two_mul_norm_mul_norm_mul_cos_angle (x y : V) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– - 2 * β€–xβ€– * β€–yβ€– * Real.cos (angle x y) := by rw [show 2 * β€–xβ€– * β€–yβ€– * Real.cos (angle x y) = 2 * (Real.cos (angle x y) * (β€–xβ€– * β€–yβ€–)) by ring, cos_angle_mul_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm, real_inner_sub_sub_self, sub_add_eq_add_sub] /-- **Pons asinorum**, vector angle form. -/ theorem angle_sub_eq_angle_sub_rev_of_norm_eq {x y : V} (h : β€–xβ€– = β€–yβ€–) : angle x (x - y) = angle y (y - x) := by refine Real.injOn_cos ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ⟨angle_nonneg _ _, angle_le_pi _ _⟩ ?_ rw [cos_angle, cos_angle, h, ← neg_sub, norm_neg, neg_sub, inner_sub_right, inner_sub_right, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, h, real_inner_comm x y] /-- **Converse of pons asinorum**, vector angle form. -/ theorem norm_eq_of_angle_sub_eq_angle_sub_rev_of_angle_ne_pi {x y : V} (h : angle x (x - y) = angle y (y - x)) (hpi : angle x y β‰  Ο€) : β€–xβ€– = β€–yβ€– := by replace h := Real.arccos_injOn (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x (x - y))) (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one y (y - x))) h by_cases hxy : x = y Β· rw [hxy] Β· rw [← norm_neg (y - x), neg_sub, mul_comm, mul_comm β€–yβ€–, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, mul_inv_rev, ← mul_assoc, ← mul_assoc] at h replace h := mul_right_cancelβ‚€ (inv_ne_zero fun hz => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 hz))) h rw [inner_sub_right, inner_sub_right, real_inner_comm x y, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, mul_sub_right_distrib, mul_sub_right_distrib, mul_self_mul_inv, mul_self_mul_inv, sub_eq_sub_iff_sub_eq_sub, ← mul_sub_left_distrib] at h by_cases hx0 : x = 0 Β· rw [hx0, norm_zero, inner_zero_left, zero_mul, zero_sub, neg_eq_zero] at h rw [hx0, norm_zero, h] Β· by_cases hy0 : y = 0 Β· rw [hy0, norm_zero, inner_zero_right, zero_mul, sub_zero] at h rw [hy0, norm_zero, h] Β· rw [inv_sub_inv (fun hz => hx0 (norm_eq_zero.1 hz)) fun hz => hy0 (norm_eq_zero.1 hz), ← neg_sub, ← mul_div_assoc, mul_comm, mul_div_assoc, ← mul_neg_one] at h symm by_contra hyx replace h := (mul_left_cancelβ‚€ (sub_ne_zero_of_ne hyx) h).symm rw [real_inner_div_norm_mul_norm_eq_neg_one_iff, ← angle_eq_pi_iff] at h exact hpi h /-- The cosine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.cos (angle x (x - y) + angle y (y - x)) = -Real.cos (angle x y) := by by_cases hxy : x = y Β· rw [hxy, angle_self hy] simp Β· rw [Real.cos_add, cos_angle, cos_angle, cos_angle] have hxn : β€–xβ€– β‰  0 := fun h => hx (norm_eq_zero.1 h) have hyn : β€–yβ€– β‰  0 := fun h => hy (norm_eq_zero.1 h) have hxyn : β€–x - yβ€– β‰  0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancelβ‚€ hxn apply mul_right_cancelβ‚€ hyn apply mul_right_cancelβ‚€ hxyn apply mul_right_cancelβ‚€ hxyn have H1 : Real.sin (angle x (x - y)) * Real.sin (angle y (y - x)) * β€–xβ€– * β€–yβ€– * β€–x - yβ€– * β€–x - yβ€– = Real.sin (angle x (x - y)) * (β€–xβ€– * β€–x - yβ€–) * (Real.sin (angle y (y - x)) * (β€–yβ€– * β€–x - yβ€–)) := by ring have H2 : βŸͺx, x⟫ * (βŸͺx, x⟫ - βŸͺx, y⟫ - (βŸͺx, y⟫ - βŸͺy, y⟫)) - (βŸͺx, x⟫ - βŸͺx, y⟫) * (βŸͺx, x⟫ - βŸͺx, y⟫) = βŸͺx, x⟫ * βŸͺy, y⟫ - βŸͺx, y⟫ * βŸͺx, y⟫ := by ring have H3 : βŸͺy, y⟫ * (βŸͺy, y⟫ - βŸͺx, y⟫ - (βŸͺx, y⟫ - βŸͺx, x⟫)) - (βŸͺy, y⟫ - βŸͺx, y⟫) * (βŸͺy, y⟫ - βŸͺx, y⟫) = βŸͺx, x⟫ * βŸͺy, y⟫ - βŸͺx, y⟫ * βŸͺx, y⟫ := by ring rw [mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, mul_sub_right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H2, H3, Real.mul_self_sqrt (sub_nonneg_of_le (real_inner_mul_inner_self_le x y)), real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [sub_div', div_div, mul_div_assoc', div_mul_eq_mul_div, div_sub', neg_div', neg_sub, eq_div_iff, div_eq_iff] ring /-- The sine of the sum of two angles in a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_sub_add_angle_sub_rev_eq_sin_angle {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.sin (angle x (x - y) + angle y (y - x)) = Real.sin (angle x y) := by by_cases hxy : x = y Β· rw [hxy, angle_self hy] simp Β· rw [Real.sin_add, cos_angle, cos_angle] have hxn : β€–xβ€– β‰  0 := fun h => hx (norm_eq_zero.1 h) have hyn : β€–yβ€– β‰  0 := fun h => hy (norm_eq_zero.1 h) have hxyn : β€–x - yβ€– β‰  0 := fun h => hxy (eq_of_sub_eq_zero (norm_eq_zero.1 h)) apply mul_right_cancelβ‚€ hxn apply mul_right_cancelβ‚€ hyn apply mul_right_cancelβ‚€ hxyn apply mul_right_cancelβ‚€ hxyn have H1 : Real.sin (angle x (x - y)) * (βŸͺy, y - x⟫ / (β€–yβ€– * β€–y - xβ€–)) * β€–xβ€– * β€–yβ€– * β€–x - yβ€– = Real.sin (angle x (x - y)) * (β€–xβ€– * β€–x - yβ€–) * (βŸͺy, y - x⟫ / (β€–yβ€– * β€–y - xβ€–)) * β€–yβ€– := by ring have H2 : βŸͺx, x - y⟫ / (β€–xβ€– * β€–y - xβ€–) * Real.sin (angle y (y - x)) * β€–xβ€– * β€–yβ€– * β€–y - xβ€– = βŸͺx, x - y⟫ / (β€–xβ€– * β€–y - xβ€–) * (Real.sin (angle y (y - x)) * (β€–yβ€– * β€–y - xβ€–)) * β€–xβ€– := by ring have H3 : βŸͺx, x⟫ * (βŸͺx, x⟫ - βŸͺx, y⟫ - (βŸͺx, y⟫ - βŸͺy, y⟫)) - (βŸͺx, x⟫ - βŸͺx, y⟫) * (βŸͺx, x⟫ - βŸͺx, y⟫) = βŸͺx, x⟫ * βŸͺy, y⟫ - βŸͺx, y⟫ * βŸͺx, y⟫ := by ring have H4 : βŸͺy, y⟫ * (βŸͺy, y⟫ - βŸͺx, y⟫ - (βŸͺx, y⟫ - βŸͺx, x⟫)) - (βŸͺy, y⟫ - βŸͺx, y⟫) * (βŸͺy, y⟫ - βŸͺx, y⟫) = βŸͺx, x⟫ * βŸͺy, y⟫ - βŸͺx, y⟫ * βŸͺx, y⟫ := by ring rw [right_distrib, right_distrib, right_distrib, right_distrib, H1, sin_angle_mul_norm_mul_norm, norm_sub_rev x y, H2, sin_angle_mul_norm_mul_norm, norm_sub_rev y x, mul_assoc (Real.sin (angle x y)), sin_angle_mul_norm_mul_norm, inner_sub_left, inner_sub_left, inner_sub_right, inner_sub_right, inner_sub_right, inner_sub_right, real_inner_comm x y, H3, H4, real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm, real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two] -- TODO(https://github.com/leanprover-community/mathlib4/issues/15486): used to be `field_simp [hxn, hyn, hxyn]`, but was really slow -- replaced by `simp only ...` to speed up. Reinstate `field_simp` once it is faster. simp (disch := field_simp_discharge) only [mul_div_assoc', div_mul_eq_mul_div, div_div, sub_div', Real.sqrt_div', Real.sqrt_mul_self, add_div', div_add', eq_div_iff, div_eq_iff] ring /-- The cosine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem cos_angle_add_angle_sub_add_angle_sub_eq_neg_one {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.cos (angle x y + angle x (x - y) + angle y (y - x)) = -1 := by rw [add_assoc, Real.cos_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy, mul_neg, ← neg_add', add_comm, ← sq, ← sq, Real.sin_sq_add_cos_sq] /-- The sine of the sum of the angles of a possibly degenerate triangle (where two given sides are nonzero), vector angle form. -/ theorem sin_angle_add_angle_sub_add_angle_sub_eq_zero {x y : V} (hx : x β‰  0) (hy : y β‰  0) : Real.sin (angle x y + angle x (x - y) + angle y (y - x)) = 0 := by rw [add_assoc, Real.sin_add, cos_angle_sub_add_angle_sub_rev_eq_neg_cos_angle hx hy, sin_angle_sub_add_angle_sub_rev_eq_sin_angle hx hy] ring /-- The sum of the angles of a possibly degenerate triangle (where the two given sides are nonzero), vector angle form. -/ theorem angle_add_angle_sub_add_angle_sub_eq_pi {x y : V} (hx : x β‰  0) (hy : y β‰  0) : angle x y + angle x (x - y) + angle y (y - x) = Ο€ := by have hcos := cos_angle_add_angle_sub_add_angle_sub_eq_neg_one hx hy have hsin := sin_angle_add_angle_sub_add_angle_sub_eq_zero hx hy rw [Real.sin_eq_zero_iff] at hsin obtain ⟨n, hn⟩ := hsin symm at hn have h0 : 0 ≀ angle x y + angle x (x - y) + angle y (y - x) :=
add_nonneg (add_nonneg (angle_nonneg _ _) (angle_nonneg _ _)) (angle_nonneg _ _) have h3lt : angle x y + angle x (x - y) + angle y (y - x) < Ο€ + Ο€ + Ο€ := by by_contra hnlt have hxy : angle x y = Ο€ := by by_contra hxy exact hnlt (add_lt_add_of_lt_of_le (add_lt_add_of_lt_of_le (lt_of_le_of_ne (angle_le_pi _ _) hxy) (angle_le_pi _ _)) (angle_le_pi _ _)) rw [hxy] at hnlt rw [angle_eq_pi_iff] at hxy rcases hxy with ⟨hx, ⟨r, ⟨hr, hxr⟩⟩⟩ rw [hxr, ← one_smul ℝ x, ← mul_smul, mul_one, ← sub_smul, one_smul, sub_eq_add_neg, angle_smul_right_of_pos _ _ (add_pos zero_lt_one (neg_pos_of_neg hr)), angle_self hx, add_zero] at hnlt apply hnlt rw [add_assoc] exact add_lt_add_left (lt_of_le_of_lt (angle_le_pi _ _) (lt_add_of_pos_right Ο€ Real.pi_pos)) _ have hn0 : 0 ≀ n := by rw [hn, mul_nonneg_iff_left_nonneg_of_pos Real.pi_pos] at h0 norm_cast at h0 have hn3 : n < 3 := by rw [hn, show Ο€ + Ο€ + Ο€ = 3 * Ο€ by ring] at h3lt replace h3lt := lt_of_mul_lt_mul_right h3lt (le_of_lt Real.pi_pos) norm_cast at h3lt interval_cases n Β· simp [hn] at hcos Β· norm_num [hn] Β· simp [hn] at hcos end InnerProductGeometry namespace EuclideanGeometry /-! ### Geometrical results on triangles in Euclidean affine spaces
Mathlib/Geometry/Euclidean/Triangle.lean
207
241
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.FiniteDimensional import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E β†’β‚—[ℝ] E β†’β‚—[ℝ] ℝ` (usual notation `Ο‰`). Morally, when `Ο‰` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `Ο‰`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᡒ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E β†’β‚—[ℝ] E β†’β‚—[ℝ] β„‚`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `β€–xβ€– * β€–yβ€–`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≀ βŸͺx, y⟫` and `Ο‰ x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = β€–aβ€– ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `β„‚` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `β„‚`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `β„‚` ## Implementation notes Notation `Ο‰` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `Ο‰[o]`). Write ``` local notation "Ο‰" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open Module lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `Ο‰`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E β†’β‚—[ℝ] E β†’β‚—[ℝ] ℝ := by let z : E [β‹€^Fin 0]β†’β‚—[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [β‹€^Fin 1]β†’β‚—[ℝ] ℝ β†’β‚—[ℝ] E β†’β‚—[ℝ] ℝ := LinearMap.llcomp ℝ E (E [β‹€^Fin 0]β†’β‚—[ℝ] ℝ) ℝ z βˆ˜β‚— AlternatingMap.curryLeftLinearMap exact y βˆ˜β‚— AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm local notation "Ο‰" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : Ο‰ x y = o.volumeForm ![x, y] := by simp [areaForm] @[simp] theorem areaForm_apply_self (x : E) : Ο‰ x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) β‰  1) Β· simp Β· norm_num theorem areaForm_swap (x y : E) : Ο‰ x y = -Ο‰ y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) β‰  1) Β· ext i fin_cases i <;> rfl Β· norm_num @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E β†’L[ℝ] E β†’L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E β†’β‚—[ℝ] ℝ) ≃ₗ[ℝ] E β†’L[ℝ] ℝ) βˆ˜β‚— o.areaForm) @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl theorem abs_areaForm_le (x y : E) : |Ο‰ x y| ≀ β€–xβ€– * β€–yβ€– := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] theorem areaForm_le (x y : E) : Ο‰ x y ≀ β€–xβ€– * β€–yβ€– := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] theorem abs_areaForm_of_orthogonal {x y : E} (h : βŸͺx, y⟫ = 0) : |Ο‰ x y| = β€–xβ€– * β€–yβ€– := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] Β· simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j Β· simp_all Β· simpa using h Β· simpa [real_inner_comm] using h Β· simp_all theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F]
[hF : Fact (finrank ℝ F = 2)] (Ο† : E ≃ₗᡒ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) Ο†.toLinearEquiv o).areaForm x y =
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
147
148
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.GroupTheory.GroupAction.Quotient import Mathlib.GroupTheory.Perm.Basic import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Multilinear.TensorProduct /-! # Exterior product of alternating maps In this file we define `AlternatingMap.domCoprod` to be the exterior product of two alternating maps, taking values in the tensor product of the codomains of the original maps. -/ suppress_compilation open TensorProduct variable {ΞΉa ΞΉb : Type*} [Fintype ΞΉa] [Fintype ΞΉb] variable {R' : Type*} {Mα΅’ N₁ Nβ‚‚ : Type*} [CommSemiring R'] [AddCommGroup N₁] [Module R' N₁] [AddCommGroup Nβ‚‚] [Module R' Nβ‚‚] [AddCommMonoid Mα΅’] [Module R' Mα΅’] namespace Equiv.Perm /-- Elements which are considered equivalent if they differ only by swaps within Ξ± or Ξ² -/ abbrev ModSumCongr (Ξ± Ξ² : Type*) := _ β§Έ (Equiv.Perm.sumCongrHom Ξ± Ξ²).range end Equiv.Perm namespace AlternatingMap open Equiv variable [DecidableEq ΞΉa] [DecidableEq ΞΉb] /-- summand used in `AlternatingMap.domCoprod` -/ def domCoprod.summand (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) (Οƒ : Perm.ModSumCongr ΞΉa ΞΉb) : MultilinearMap R' (fun _ : ΞΉa βŠ• ΞΉb => Mα΅’) (N₁ βŠ—[R'] Nβ‚‚) := Quotient.liftOn' Οƒ (fun Οƒ => Equiv.Perm.sign Οƒ β€’ (MultilinearMap.domCoprod ↑a ↑b : MultilinearMap R' (fun _ => Mα΅’) (N₁ βŠ— Nβ‚‚)).domDomCongr Οƒ) fun σ₁ Οƒβ‚‚ H => by rw [QuotientGroup.leftRel_apply] at H obtain ⟨⟨sl, sr⟩, h⟩ := H ext v simp only [MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply, coe_multilinearMap, MultilinearMap.smul_apply] replace h := inv_mul_eq_iff_eq_mul.mp h.symm have : Equiv.Perm.sign (σ₁ * Perm.sumCongrHom _ _ (sl, sr)) = Equiv.Perm.sign σ₁ * (Equiv.Perm.sign sl * Equiv.Perm.sign sr) := by simp rw [h, this, mul_smul, mul_smul, smul_left_cancel_iff, ← TensorProduct.tmul_smul, TensorProduct.smul_tmul', a.map_congr_perm _ sl, b.map_congr_perm _ sr] simp only [Sum.map_inr, Perm.sumCongrHom_apply, Perm.sumCongr_apply, Sum.map_inl, Function.comp_def, Perm.coe_mul] theorem domCoprod.summand_mk'' (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) (Οƒ : Equiv.Perm (ΞΉa βŠ• ΞΉb)) : domCoprod.summand a b (Quotient.mk'' Οƒ) = Equiv.Perm.sign Οƒ β€’ (MultilinearMap.domCoprod ↑a ↑b : MultilinearMap R' (fun _ => Mα΅’) (N₁ βŠ— Nβ‚‚)).domDomCongr Οƒ := rfl /-- Swapping elements in `Οƒ` with equal values in `v` results in an addition that cancels -/ theorem domCoprod.summand_add_swap_smul_eq_zero (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) (Οƒ : Perm.ModSumCongr ΞΉa ΞΉb) {v : ΞΉa βŠ• ΞΉb β†’ Mα΅’} {i j : ΞΉa βŠ• ΞΉb} (hv : v i = v j) (hij : i β‰  j) : domCoprod.summand a b Οƒ v + domCoprod.summand a b (swap i j β€’ Οƒ) v = 0 := by refine Quotient.inductionOn' Οƒ fun Οƒ => ?_ dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MulAction.Quotient.smul_mk, domCoprod.summand] rw [smul_eq_mul, Perm.sign_mul, Perm.sign_swap hij] simp only [one_mul, neg_mul, Function.comp_apply, Units.neg_smul, Perm.coe_mul, Units.val_neg, MultilinearMap.smul_apply, MultilinearMap.neg_apply, MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply] convert add_neg_cancel (G := N₁ βŠ—[R'] Nβ‚‚) _ using 6 <;> Β· ext k rw [Equiv.apply_swap_eq_self hv] /-- Swapping elements in `Οƒ` with equal values in `v` result in zero if the swap has no effect on the quotient. -/ theorem domCoprod.summand_eq_zero_of_smul_invariant (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) (Οƒ : Perm.ModSumCongr ΞΉa ΞΉb) {v : ΞΉa βŠ• ΞΉb β†’ Mα΅’} {i j : ΞΉa βŠ• ΞΉb} (hv : v i = v j) (hij : i β‰  j) : swap i j β€’ Οƒ = Οƒ β†’ domCoprod.summand a b Οƒ v = 0 := by refine Quotient.inductionOn' Οƒ fun Οƒ => ?_ dsimp only [Quotient.liftOn'_mk'', Quotient.map'_mk'', MultilinearMap.smul_apply, MultilinearMap.domDomCongr_apply, MultilinearMap.domCoprod_apply, domCoprod.summand] intro hΟƒ obtain ⟨⟨sl, sr⟩, hΟƒβŸ© := QuotientGroup.leftRel_apply.mp (Quotient.exact' hΟƒ) rcases hi : σ⁻¹ i with i' | i' <;> rcases hj : σ⁻¹ j with j' | j' <;> rw [Perm.inv_eq_iff_eq] at hi hj <;> substs hi hj -- the term pairs with and cancels another term case inl.inr => simpa using Equiv.congr_fun hΟƒ (Sum.inl i') case inr.inl => simpa using Equiv.congr_fun hΟƒ (Sum.inr i') -- the term does not pair but is zero case inl.inl => suffices (a fun i ↦ v (Οƒ (Sum.inl i))) = 0 by simp_all exact AlternatingMap.map_eq_zero_of_eq _ _ hv fun hij' => hij (hij' β–Έ rfl) case inr.inr => suffices (b fun i ↦ v (Οƒ (Sum.inr i))) = 0 by simp_all exact b.map_eq_zero_of_eq _ hv fun hij' => hij (hij' β–Έ rfl) /-- Like `MultilinearMap.domCoprod`, but ensures the result is also alternating. Note that this is usually defined (for instance, as used in Proposition 22.24 in [Gallier2011Notes]) over integer indices `ΞΉa = Fin n` and `ΞΉb = Fin m`, as $$ (f \wedge g)(u_1, \ldots, u_{m+n}) = \sum_{\operatorname{shuffle}(m, n)} \operatorname{sign}(\sigma) f(u_{\sigma(1)}, \ldots, u_{\sigma(m)}) g(u_{\sigma(m+1)}, \ldots, u_{\sigma(m+n)}), $$ where $\operatorname{shuffle}(m, n)$ consists of all permutations of $[1, m+n]$ such that $\sigma(1) < \cdots < \sigma(m)$ and $\sigma(m+1) < \cdots < \sigma(m+n)$. Here, we generalize this by replacing: * the product in the sum with a tensor product * the filtering of $[1, m+n]$ to shuffles with an isomorphic quotient * the additions in the subscripts of $\sigma$ with an index of type `Sum` The specialized version can be obtained by combining this definition with `finSumFinEquiv` and `LinearMap.mul'`. -/ @[simps] def domCoprod (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) : Mα΅’ [β‹€^ΞΉa βŠ• ΞΉb]β†’β‚—[R'] (N₁ βŠ—[R'] Nβ‚‚) := { βˆ‘ Οƒ : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Οƒ with toFun := fun v => (⇑(βˆ‘ Οƒ : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Οƒ)) v map_eq_zero_of_eq' := fun v i j hv hij => by rw [MultilinearMap.sum_apply] exact Finset.sum_involution (fun Οƒ _ => Equiv.swap i j β€’ Οƒ) (fun Οƒ _ => domCoprod.summand_add_swap_smul_eq_zero a b Οƒ hv hij) (fun Οƒ _ => mt <| domCoprod.summand_eq_zero_of_smul_invariant a b Οƒ hv hij) (fun Οƒ _ => Finset.mem_univ _) fun Οƒ _ => Equiv.swap_smul_involutive i j Οƒ } theorem domCoprod_coe (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) : (↑(a.domCoprod b) : MultilinearMap R' (fun _ => Mα΅’) _) = βˆ‘ Οƒ : Perm.ModSumCongr ΞΉa ΞΉb, domCoprod.summand a b Οƒ := MultilinearMap.ext fun _ => rfl /-- A more bundled version of `AlternatingMap.domCoprod` that maps `((ι₁ β†’ N) β†’ N₁) βŠ— ((ΞΉβ‚‚ β†’ N) β†’ Nβ‚‚)` to `(ι₁ βŠ• ΞΉβ‚‚ β†’ N) β†’ N₁ βŠ— Nβ‚‚`. -/ def domCoprod' : (Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) βŠ—[R'] (Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) β†’β‚—[R'] (Mα΅’ [β‹€^ΞΉa βŠ• ΞΉb]β†’β‚—[R'] (N₁ βŠ—[R'] Nβ‚‚)) := TensorProduct.lift <| by refine LinearMap.mkβ‚‚ R' domCoprod (fun m₁ mβ‚‚ n => ?_) (fun c m n => ?_) (fun m n₁ nβ‚‚ => ?_) fun c m n => ?_ <;> Β· ext simp only [domCoprod_apply, add_apply, smul_apply, ← Finset.sum_add_distrib, Finset.smul_sum, MultilinearMap.sum_apply, domCoprod.summand] congr ext Οƒ refine Quotient.inductionOn' Οƒ fun Οƒ => ?_ simp only [Quotient.liftOn'_mk'', coe_add, coe_smul, MultilinearMap.smul_apply, ← MultilinearMap.domCoprod'_apply] simp only [TensorProduct.add_tmul, ← TensorProduct.smul_tmul', TensorProduct.tmul_add, TensorProduct.tmul_smul, LinearMap.map_add, LinearMap.map_smul] first | rw [← smul_add] | rw [smul_comm] rfl @[simp] theorem domCoprod'_apply (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) : domCoprod' (a βŠ—β‚œ[R'] b) = domCoprod a b := rfl end AlternatingMap open Equiv /-- A helper lemma for `MultilinearMap.domCoprod_alternization`. -/ theorem MultilinearMap.domCoprod_alternization_coe [DecidableEq ΞΉa] [DecidableEq ΞΉb] (a : MultilinearMap R' (fun _ : ΞΉa => Mα΅’) N₁) (b : MultilinearMap R' (fun _ : ΞΉb => Mα΅’) Nβ‚‚) : MultilinearMap.domCoprod (MultilinearMap.alternatization a) (MultilinearMap.alternatization b) = βˆ‘ Οƒa : Perm ΞΉa, βˆ‘ Οƒb : Perm ΞΉb, Equiv.Perm.sign Οƒa β€’ Equiv.Perm.sign Οƒb β€’ MultilinearMap.domCoprod (a.domDomCongr Οƒa) (b.domDomCongr Οƒb) := by simp_rw [← MultilinearMap.domCoprod'_apply, MultilinearMap.alternatization_coe] simp_rw [TensorProduct.sum_tmul, TensorProduct.tmul_sum, _root_.map_sum, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul] rfl open AlternatingMap open Perm in /-- Computing the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` is the same as computing the `AlternatingMap.domCoprod` of the `MultilinearMap.alternatization`s. -/ theorem MultilinearMap.domCoprod_alternization [DecidableEq ΞΉa] [DecidableEq ΞΉb] (a : MultilinearMap R' (fun _ : ΞΉa => Mα΅’) N₁) (b : MultilinearMap R' (fun _ : ΞΉb => Mα΅’) Nβ‚‚) : MultilinearMap.alternatization (MultilinearMap.domCoprod a b) = a.alternatization.domCoprod (MultilinearMap.alternatization b) := by apply coe_multilinearMap_injective rw [domCoprod_coe, MultilinearMap.alternatization_coe, Finset.sum_partition (QuotientGroup.leftRel (Perm.sumCongrHom ΞΉa ΞΉb).range)] congr 1 ext1 Οƒ induction Οƒ using Quotient.inductionOn' with | h Οƒ => set f := sumCongrHom ΞΉa ΞΉb calc βˆ‘ Ο„ ∈ _, sign Ο„ β€’ domDomCongr Ο„ (a.domCoprod b) = βˆ‘ Ο„ ∈ {Ο„ | τ⁻¹ * Οƒ ∈ f.range}, sign Ο„ β€’ domDomCongr Ο„ (a.domCoprod b) := by simp [QuotientGroup.leftRel_apply, f] _ = βˆ‘ Ο„ ∈ {Ο„ | τ⁻¹ ∈ f.range}, sign (Οƒ * Ο„) β€’ domDomCongr (Οƒ * Ο„) (a.domCoprod b) := by conv_lhs => rw [← Finset.map_univ_equiv (Equiv.mulLeft Οƒ), Finset.filter_map, Finset.sum_map] simp [Function.comp_def, -MonoidHom.mem_range] _ = βˆ‘ Ο„, sign (Οƒ * f Ο„) β€’ domDomCongr (Οƒ * f Ο„) (a.domCoprod b) := by simp_rw [f, Subgroup.inv_mem_iff, MonoidHom.mem_range, Finset.univ_filter_exists, Finset.sum_image sumCongrHom_injective.injOn] _ = βˆ‘ Ο„ : Perm ΞΉa Γ— Perm ΞΉb, sign Οƒ β€’ (domDomCongrEquiv Οƒ) (sign Ο„.1 β€’ sign Ο„.2 β€’ (domDomCongr Ο„.1 a).domCoprod (domDomCongr Ο„.2 b)) := by simp [f, domDomCongr_mul, domCoprod_domDomCongr_sumCongr, mul_smul] _ = domCoprod.summand (alternatization a) (alternatization b) (Quotient.mk'' Οƒ) := by simp [domCoprod.summand_mk'', domCoprod_alternization_coe, ← domDomCongrEquiv_apply, Finset.smul_sum, ← Finset.sum_product']
/-- Taking the `MultilinearMap.alternatization` of the `MultilinearMap.domCoprod` of two `AlternatingMap`s gives a scaled version of the `AlternatingMap.coprod` of those maps. -/ theorem MultilinearMap.domCoprod_alternization_eq [DecidableEq ΞΉa] [DecidableEq ΞΉb] (a : Mα΅’ [β‹€^ΞΉa]β†’β‚—[R'] N₁) (b : Mα΅’ [β‹€^ΞΉb]β†’β‚—[R'] Nβ‚‚) : MultilinearMap.alternatization (MultilinearMap.domCoprod a b : MultilinearMap R' (fun _ : ΞΉa βŠ• ΞΉb => Mα΅’) (N₁ βŠ— Nβ‚‚)) = ((Fintype.card ΞΉa).factorial * (Fintype.card ΞΉb).factorial) β€’ a.domCoprod b := by rw [MultilinearMap.domCoprod_alternization, coe_alternatization, coe_alternatization, mul_smul, ← AlternatingMap.domCoprod'_apply, ← AlternatingMap.domCoprod'_apply, ← TensorProduct.smul_tmul', TensorProduct.tmul_smul, LinearMap.map_smul_of_tower AlternatingMap.domCoprod', LinearMap.map_smul_of_tower AlternatingMap.domCoprod']
Mathlib/LinearAlgebra/Alternating/DomCoprod.lean
230
266
/- Copyright (c) 2022 Vincent Beffara. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Vincent Beffara -/ import Mathlib.Analysis.Analytic.IsolatedZeros import Mathlib.Analysis.Complex.CauchyIntegral import Mathlib.Analysis.Complex.AbsMax import Mathlib.Topology.MetricSpace.ProperSpace.Lemmas /-! # The open mapping theorem for holomorphic functions This file proves the open mapping theorem for holomorphic functions, namely that an analytic function on a preconnected set of the complex plane is either constant or open. The main step is to show a local version of the theorem that states that if `f` is analytic at a point `zβ‚€`, then either it is constant in a neighborhood of `zβ‚€` or it maps any neighborhood of `zβ‚€` to a neighborhood of its image `f zβ‚€`. The results extend in higher dimension to `g : E β†’ β„‚`. The proof of the local version on `β„‚` goes through two main steps: first, assuming that the function is not constant around `zβ‚€`, use the isolated zero principle to show that `β€–f zβ€–` is bounded below on a small `sphere zβ‚€ r` around `zβ‚€`, and then use the maximum principle applied to the auxiliary function `(fun z ↦ β€–f z - vβ€–)` to show that any `v` close enough to `f zβ‚€` is in `f '' ball zβ‚€ r`. That second step is implemented in `DiffContOnCl.ball_subset_image_closedBall`. ## Main results * `AnalyticAt.eventually_constant_or_nhds_le_map_nhds` is the local version of the open mapping theorem around a point; * `AnalyticOnNhd.is_constant_or_isOpen` is the open mapping theorem on a connected open set. -/ open Set Filter Metric Complex open scoped Topology variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β„‚ E] {U : Set E} {f : β„‚ β†’ β„‚} {g : E β†’ β„‚} {zβ‚€ : β„‚} {Ξ΅ r : ℝ} /-- If the modulus of a holomorphic function `f` is bounded below by `Ξ΅` on a circle, then its range contains a disk of radius `Ξ΅ / 2`. -/ theorem DiffContOnCl.ball_subset_image_closedBall (h : DiffContOnCl β„‚ f (ball zβ‚€ r)) (hr : 0 < r)
(hf : βˆ€ z ∈ sphere zβ‚€ r, Ξ΅ ≀ β€–f z - f zβ‚€β€–) (hzβ‚€ : βˆƒαΆ  z in 𝓝 zβ‚€, f z β‰  f zβ‚€) : ball (f zβ‚€) (Ξ΅ / 2) βŠ† f '' closedBall zβ‚€ r := by /- This is a direct application of the maximum principle. Pick `v` close to `f zβ‚€`, and look at the function `fun z ↦ β€–f z - vβ€–`: it is bounded below on the circle, and takes a small value at `zβ‚€` so it is not constant on the disk, which implies that its infimum is equal to `0` and hence that `v` is in the range of `f`. -/ rintro v hv have h1 : DiffContOnCl β„‚ (fun z => f z - v) (ball zβ‚€ r) := h.sub_const v have h2 : ContinuousOn (fun z => β€–f z - vβ€–) (closedBall zβ‚€ r) := continuous_norm.comp_continuousOn (closure_ball zβ‚€ hr.ne.symm β–Έ h1.continuousOn) have h3 : AnalyticOnNhd β„‚ f (ball zβ‚€ r) := h.differentiableOn.analyticOnNhd isOpen_ball have h4 : βˆ€ z ∈ sphere zβ‚€ r, Ξ΅ / 2 ≀ β€–f z - vβ€– := fun z hz => by linarith [hf z hz, show β€–v - f zβ‚€β€– < Ξ΅ / 2 from mem_ball.mp hv, norm_sub_sub_norm_sub_le_norm_sub (f z) v (f zβ‚€)] have h5 : β€–f zβ‚€ - vβ€– < Ξ΅ / 2 := by simpa [← dist_eq_norm, dist_comm] using mem_ball.mp hv obtain ⟨z, hz1, hz2⟩ : βˆƒ z ∈ ball zβ‚€ r, IsLocalMin (fun z => β€–f z - vβ€–) z := exists_isLocalMin_mem_ball h2 (mem_closedBall_self hr.le) fun z hz => h5.trans_le (h4 z hz) refine ⟨z, ball_subset_closedBall hz1, sub_eq_zero.mp ?_⟩ have h6 := h1.differentiableOn.eventually_differentiableAt (isOpen_ball.mem_nhds hz1) refine (eventually_eq_or_eq_zero_of_isLocalMin_norm h6 hz2).resolve_left fun key => ?_ have h7 : βˆ€αΆ  w in 𝓝 z, f w = f z := by filter_upwards [key] with h; field_simp replace h7 : βˆƒαΆ  w in 𝓝[β‰ ] z, f w = f z := (h7.filter_mono nhdsWithin_le_nhds).frequently have h8 : IsPreconnected (ball zβ‚€ r) := (convex_ball zβ‚€ r).isPreconnected have h9 := h3.eqOn_of_preconnected_of_frequently_eq analyticOnNhd_const h8 hz1 h7 have h10 : f z = f zβ‚€ := (h9 (mem_ball_self hr)).symm exact not_eventually.mpr hzβ‚€ (mem_of_superset (ball_mem_nhds zβ‚€ hr) (h10 β–Έ h9))
Mathlib/Analysis/Complex/OpenMapping.lean
44
70
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Data.List.Lattice import Mathlib.Data.Bool.Basic import Mathlib.Order.Lattice /-! # Intervals in β„• This file defines intervals of naturals. `List.Ico m n` is the list of integers greater than `m` and strictly less than `n`. ## TODO - Define `Ioo` and `Icc`, state basic lemmas about them. - Also do the versions for integers? - One could generalise even further, defining 'locally finite partial orders', for which `Set.Ico a b` is `[Finite]`, and 'locally finite total orders', for which there is a list model. - Once the above is done, get rid of `Int.range` (and maybe `List.range'`?). -/ open Nat namespace List /-- `Ico n m` is the list of natural numbers `n ≀ x < m`. (Ico stands for "interval, closed-open".) See also `Mathlib/Order/Interval/Basic.lean` for modelling intervals in general preorders, as well as sibling definitions alongside it such as `Set.Ico`, `Multiset.Ico` and `Finset.Ico` for sets, multisets and finite sets respectively. -/ def Ico (n m : β„•) : List β„• := range' n (m - n) namespace Ico theorem zero_bot (n : β„•) : Ico 0 n = range n := by rw [Ico, Nat.sub_zero, range_eq_range'] @[simp] theorem length (n m : β„•) : length (Ico n m) = m - n := by dsimp [Ico] simp [length_range'] theorem pairwise_lt (n m : β„•) : Pairwise (Β· < Β·) (Ico n m) := by dsimp [Ico] simp [pairwise_lt_range'] theorem nodup (n m : β„•) : Nodup (Ico n m) := by dsimp [Ico] simp [nodup_range'] @[simp] theorem mem {n m l : β„•} : l ∈ Ico n m ↔ n ≀ l ∧ l < m := by suffices n ≀ l ∧ l < n + (m - n) ↔ n ≀ l ∧ l < m by simp [Ico, this] omega theorem eq_nil_of_le {n m : β„•} (h : m ≀ n) : Ico n m = [] := by simp [Ico, Nat.sub_eq_zero_iff_le.mpr h] theorem map_add (n m k : β„•) : (Ico n m).map (k + Β·) = Ico (n + k) (m + k) := by rw [Ico, Ico, map_add_range', Nat.add_sub_add_right m k, Nat.add_comm n k] theorem map_sub (n m k : β„•) (h₁ : k ≀ n) : ((Ico n m).map fun x => x - k) = Ico (n - k) (m - k) := by rw [Ico, Ico, Nat.sub_sub_sub_cancel_right h₁, map_sub_range' h₁] @[simp] theorem self_empty {n : β„•} : Ico n n = [] := eq_nil_of_le (le_refl n) @[simp] theorem eq_empty_iff {n m : β„•} : Ico n m = [] ↔ m ≀ n := Iff.intro (fun h => Nat.sub_eq_zero_iff_le.mp <| by rw [← length, h, List.length]) eq_nil_of_le theorem append_consecutive {n m l : β„•} (hnm : n ≀ m) (hml : m ≀ l) : Ico n m ++ Ico m l = Ico n l := by dsimp only [Ico] convert range'_append using 2 Β· rw [Nat.one_mul, Nat.add_sub_cancel' hnm] Β· omega @[simp] theorem inter_consecutive (n m l : β„•) : Ico n m ∩ Ico m l = [] := by apply eq_nil_iff_forall_not_mem.2 intro a simp only [and_imp, not_and, not_lt, List.mem_inter_iff, List.Ico.mem] intro _ hβ‚‚ h₃ exfalso exact not_lt_of_ge h₃ hβ‚‚ @[simp] theorem bagInter_consecutive (n m l : Nat) : @List.bagInter β„• instBEqOfDecidableEq (Ico n m) (Ico m l) = [] := (bagInter_nil_iff_inter_nil _ _).2 (by convert inter_consecutive n m l) @[simp] theorem succ_singleton {n : β„•} : Ico n (n + 1) = [n] := by dsimp [Ico] simp [range', Nat.add_sub_cancel_left] theorem succ_top {n m : β„•} (h : n ≀ m) : Ico n (m + 1) = Ico n m ++ [m] := by rwa [← succ_singleton, append_consecutive] exact Nat.le_succ _ theorem eq_cons {n m : β„•} (h : n < m) : Ico n m = n :: Ico (n + 1) m := by rw [← append_consecutive (Nat.le_succ n) h, succ_singleton] rfl @[simp] theorem pred_singleton {m : β„•} (h : 0 < m) : Ico (m - 1) m = [m - 1] := by simp [Ico, Nat.sub_sub_self (succ_le_of_lt h)] theorem chain'_succ (n m : β„•) : Chain' (fun a b => b = succ a) (Ico n m) := by by_cases h : n < m Β· rw [eq_cons h] exact chain_succ_range' _ _ 1 Β· rw [eq_nil_of_le (le_of_not_gt h)] trivial theorem not_mem_top {n m : β„•} : m βˆ‰ Ico n m := by simp theorem filter_lt_of_top_le {n m l : β„•} (hml : m ≀ l) : ((Ico n m).filter fun x => x < l) = Ico n m := filter_eq_self.2 fun k hk => by simp only [(lt_of_lt_of_le (mem.1 hk).2 hml), decide_true] theorem filter_lt_of_le_bot {n m l : β„•} (hln : l ≀ n) : ((Ico n m).filter fun x => x < l) = [] := filter_eq_nil_iff.2 fun k hk => by simp only [decide_eq_true_eq, not_lt] apply le_trans hln exact (mem.1 hk).1 theorem filter_lt_of_ge {n m l : β„•} (hlm : l ≀ m) : ((Ico n m).filter fun x => x < l) = Ico n l := by rcases le_total n l with hnl | hln Β· rw [← append_consecutive hnl hlm, filter_append, filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] Β· rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] @[simp] theorem filter_lt (n m l : β„•) : ((Ico n m).filter fun x => x < l) = Ico n (min m l) := by rcases le_total m l with hml | hlm Β· rw [min_eq_left hml, filter_lt_of_top_le hml] Β· rw [min_eq_right hlm, filter_lt_of_ge hlm] theorem filter_le_of_le_bot {n m l : β„•} (hln : l ≀ n) : ((Ico n m).filter fun x => l ≀ x) = Ico n m :=
filter_eq_self.2 fun k hk => by
Mathlib/Data/List/Intervals.lean
153
153
/- Copyright (c) 2022 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Additive Haar measure constructed from a basis Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue measure, which gives measure `1` to the parallelepiped spanned by the basis. ## Main definitions * `parallelepiped v` is the parallelepiped spanned by a finite family of vectors. * `Basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with nonempty interior. * `Basis.addHaar` is the Lebesgue measure associated to a basis, giving measure `1` to the corresponding parallelepiped. In particular, we declare a `MeasureSpace` instance on any finite-dimensional inner product space, by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent of the basis). -/ open Set TopologicalSpace MeasureTheory MeasureTheory.Measure Module open scoped Pointwise noncomputable section variable {ΞΉ ΞΉ' E F : Type*} section Fintype variable [Fintype ΞΉ] [Fintype ΞΉ'] section AddCommGroup variable [AddCommGroup E] [Module ℝ E] [AddCommGroup F] [Module ℝ F] /-- The closed parallelepiped spanned by a finite family of vectors. -/ def parallelepiped (v : ΞΉ β†’ E) : Set E := (fun t : ΞΉ β†’ ℝ => βˆ‘ i, t i β€’ v i) '' Icc 0 1 theorem mem_parallelepiped_iff (v : ΞΉ β†’ E) (x : E) : x ∈ parallelepiped v ↔ βˆƒ t ∈ Icc (0 : ΞΉ β†’ ℝ) 1, x = βˆ‘ i, t i β€’ v i := by simp [parallelepiped, eq_comm] theorem parallelepiped_basis_eq (b : Basis ΞΉ ℝ E) : parallelepiped b = {x | βˆ€ i, b.repr x i ∈ Set.Icc 0 1} := by classical ext x simp_rw [mem_parallelepiped_iff, mem_setOf_eq, b.ext_elem_iff, _root_.map_sum, map_smul, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single, smul_eq_mul, mul_one, Finsupp.single_apply, Finset.sum_ite_eq', Finset.mem_univ, ite_true, mem_Icc, Pi.le_def, Pi.zero_apply, Pi.one_apply, ← forall_and] aesop theorem image_parallelepiped (f : E β†’β‚—[ℝ] F) (v : ΞΉ β†’ E) : f '' parallelepiped v = parallelepiped (f ∘ v) := by simp only [parallelepiped, ← image_comp] congr 1 with t simp only [Function.comp_apply, _root_.map_sum, LinearMap.map_smulβ‚›β‚—, RingHom.id_apply] /-- Reindexing a family of vectors does not change their parallelepiped. -/ @[simp] theorem parallelepiped_comp_equiv (v : ΞΉ β†’ E) (e : ΞΉ' ≃ ΞΉ) : parallelepiped (v ∘ e) = parallelepiped v := by simp only [parallelepiped] let K : (ΞΉ' β†’ ℝ) ≃ (ΞΉ β†’ ℝ) := Equiv.piCongrLeft' (fun _a : ΞΉ' => ℝ) e have : Icc (0 : ΞΉ β†’ ℝ) 1 = K '' Icc (0 : ΞΉ' β†’ ℝ) 1 := by rw [← Equiv.preimage_eq_iff_eq_image] ext x simp only [K, mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Equiv.piCongrLeft'_apply, Pi.one_apply] refine ⟨fun h => ⟨fun i => ?_, fun i => ?_⟩, fun h => ⟨fun i => h.1 (e.symm i), fun i => h.2 (e.symm i)⟩⟩ Β· simpa only [Equiv.symm_apply_apply] using h.1 (e i) Β· simpa only [Equiv.symm_apply_apply] using h.2 (e i) rw [this, ← image_comp] congr 1 with x have := fun z : ΞΉ' β†’ ℝ => e.symm.sum_comp fun i => z i β€’ v (e i) simp_rw [Equiv.apply_symm_apply] at this simp_rw [Function.comp_apply, mem_image, mem_Icc, K, Equiv.piCongrLeft'_apply, this] -- The parallelepiped associated to an orthonormal basis of `ℝ` is either `[0, 1]` or `[-1, 0]`. theorem parallelepiped_orthonormalBasis_one_dim (b : OrthonormalBasis ΞΉ ℝ ℝ) : parallelepiped b = Icc 0 1 ∨ parallelepiped b = Icc (-1) 0 := by have e : ΞΉ ≃ Fin 1 := by apply Fintype.equivFinOfCardEq simp only [← finrank_eq_card_basis b.toBasis, finrank_self] have B : parallelepiped (b.reindex e) = parallelepiped b := by convert parallelepiped_comp_equiv b e.symm ext i simp only [OrthonormalBasis.coe_reindex] rw [← B] let F : ℝ β†’ Fin 1 β†’ ℝ := fun t => fun _i => t have A : Icc (0 : Fin 1 β†’ ℝ) 1 = F '' Icc (0 : ℝ) 1 := by apply Subset.antisymm Β· intro x hx refine ⟨x 0, ⟨hx.1 0, hx.2 0⟩, ?_⟩ ext j simp only [F, Subsingleton.elim j 0] Β· rintro x ⟨y, hy, rfl⟩ exact ⟨fun _j => hy.1, fun _j => hy.2⟩ rcases orthonormalBasis_one_dim (b.reindex e) with (H | H) Β· left simp_rw [parallelepiped, H, A, Algebra.id.smul_eq_mul, mul_one] simp only [F, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, ← image_comp, Function.comp_apply, image_id'] Β· right simp_rw [H, parallelepiped, Algebra.id.smul_eq_mul, A] simp only [F, Finset.univ_unique, Fin.default_eq_zero, mul_neg, mul_one, Finset.sum_neg_distrib, Finset.sum_singleton, ← image_comp, Function.comp, image_neg_eq_neg, neg_Icc, neg_zero] theorem parallelepiped_eq_sum_segment (v : ΞΉ β†’ E) : parallelepiped v = βˆ‘ i, segment ℝ 0 (v i) := by ext simp only [mem_parallelepiped_iff, Set.mem_finset_sum, Finset.mem_univ, forall_true_left, segment_eq_image, smul_zero, zero_add, ← Set.pi_univ_Icc, Set.mem_univ_pi] constructor Β· rintro ⟨t, ht, rfl⟩ exact ⟨t β€’ v, fun {i} => ⟨t i, ht _, by simp⟩, rfl⟩ rintro ⟨g, hg, rfl⟩ choose t ht hg using @hg refine ⟨@t, @ht, ?_⟩ simp_rw [hg] theorem convex_parallelepiped (v : ΞΉ β†’ E) : Convex ℝ (parallelepiped v) := by rw [parallelepiped_eq_sum_segment] exact convex_sum _ fun _i _hi => convex_segment _ _ /-- A `parallelepiped` is the convex hull of its vertices -/ theorem parallelepiped_eq_convexHull (v : ΞΉ β†’ E) : parallelepiped v = convexHull ℝ (βˆ‘ i, {(0 : E), v i}) := by simp_rw [convexHull_sum, convexHull_pair, parallelepiped_eq_sum_segment] /-- The axis aligned parallelepiped over `ΞΉ β†’ ℝ` is a cuboid. -/ theorem parallelepiped_single [DecidableEq ΞΉ] (a : ΞΉ β†’ ℝ) : (parallelepiped fun i => Pi.single i (a i)) = Set.uIcc 0 a := by ext x simp_rw [Set.uIcc, mem_parallelepiped_iff, Set.mem_Icc, Pi.le_def, ← forall_and, Pi.inf_apply,
Pi.sup_apply, ← Pi.single_smul', Pi.one_apply, Pi.zero_apply, ← Pi.smul_apply', Finset.univ_sum_single (_ : ΞΉ β†’ ℝ)] constructor
Mathlib/MeasureTheory/Measure/Haar/OfBasis.lean
147
149
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Filter import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Analysis.Oscillation import Mathlib.Data.Bool.Basic import Mathlib.MeasureTheory.Measure.Real import Mathlib.Topology.UniformSpace.Compact /-! # Integrals of Riemann, Henstock-Kurzweil, and McShane In this file we define the integral of a function over a box in `ℝⁿ`. The same definition works for Riemann, Henstock-Kurzweil, and McShane integrals. As usual, we represent `ℝⁿ` as the type of functions `ΞΉ β†’ ℝ` for some finite type `ΞΉ`. A rectangular box `(l, u]` in `ℝⁿ` is defined to be the set `{x : ΞΉ β†’ ℝ | βˆ€ i, l i < x i ∧ x i ≀ u i}`, see `BoxIntegral.Box`. Let `vol` be a box-additive function on boxes in `ℝⁿ` with codomain `E β†’L[ℝ] F`. Given a function `f : ℝⁿ β†’ E`, a box `I` and a tagged partition `Ο€` of this box, the *integral sum* of `f` over `Ο€` with respect to the volume `vol` is the sum of `vol J (f (Ο€.tag J))` over all boxes of `Ο€`. Here `Ο€.tag J` is the point (tag) in `ℝⁿ` associated with the box `J`. The integral is defined as the limit of integral sums along a filter. Different filters correspond to different integration theories. In order to avoid code duplication, all our definitions and theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three boolean values, and encodes eight filters including those corresponding to Riemann, Henstock-Kurzweil, and McShane integrals. Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate `BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying the predicate or zero if the function is not integrable. Then we prove some basic properties of box integrals (linearity, a formula for the integral of a constant). We also prove a version of the Henstock-Sacks inequality (see `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove integrability of continuous functions, and provide a criterion for integrability w.r.t. a non-Riemann filter (e.g., Henstock-Kurzweil and McShane). ## Notation - `ℝⁿ`: local notation for `ΞΉ β†’ ℝ` ## Tags integral -/ open scoped Topology NNReal Filter Uniformity BoxIntegral open Set Finset Function Filter Metric BoxIntegral.IntegrationParams noncomputable section namespace BoxIntegral universe u v w variable {ΞΉ : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {I J : Box ΞΉ} {Ο€ : TaggedPrepartition I} open TaggedPrepartition local notation "ℝⁿ" => ΞΉ β†’ ℝ /-! ### Integral sum and its basic properties -/ /-- The integral sum of `f : ℝⁿ β†’ E` over a tagged prepartition `Ο€` w.r.t. box-additive volume `vol` with codomain `E β†’L[ℝ] F` is the sum of `vol J (f (Ο€.tag J))` over all boxes of `Ο€`. -/ def integralSum (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : F := βˆ‘ J ∈ Ο€.boxes, vol J (f (Ο€.tag J)) theorem integralSum_biUnionTagged (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : Prepartition I) (Ο€i : βˆ€ J, TaggedPrepartition J) : integralSum f vol (Ο€.biUnionTagged Ο€i) = βˆ‘ J ∈ Ο€.boxes, integralSum f vol (Ο€i J) := by refine (Ο€.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_ rw [Ο€.tag_biUnionTagged hJ hJ'] theorem integralSum_biUnion_partition (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) (Ο€i : βˆ€ J, Prepartition J) (hΟ€i : βˆ€ J ∈ Ο€, (Ο€i J).IsPartition) : integralSum f vol (Ο€.biUnionPrepartition Ο€i) = integralSum f vol Ο€ := by refine (Ο€.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_) calc (βˆ‘ J' ∈ (Ο€i J).boxes, vol J' (f (Ο€.tag <| Ο€.toPrepartition.biUnionIndex Ο€i J'))) = βˆ‘ J' ∈ (Ο€i J).boxes, vol J' (f (Ο€.tag J)) := sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ'] _ = vol J (f (Ο€.tag J)) := (vol.map ⟨⟨fun g : E β†’L[ℝ] F => g (f (Ο€.tag J)), rfl⟩, fun _ _ => rfl⟩).sum_partition_boxes le_top (hΟ€i J hJ) theorem integralSum_inf_partition (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) {Ο€' : Prepartition I} (h : Ο€'.IsPartition) : integralSum f vol (Ο€.infPrepartition Ο€') = integralSum f vol Ο€ := integralSum_biUnion_partition f vol Ο€ _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ) open Classical in theorem integralSum_fiberwise {Ξ±} (g : Box ΞΉ β†’ Ξ±) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : (βˆ‘ y ∈ Ο€.boxes.image g, integralSum f vol (Ο€.filter (g Β· = y))) = integralSum f vol Ο€ := Ο€.sum_fiberwise g fun J => vol J (f <| Ο€.tag J) theorem integralSum_sub_partitions (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) {π₁ Ο€β‚‚ : TaggedPrepartition I} (h₁ : π₁.IsPartition) (hβ‚‚ : Ο€β‚‚.IsPartition) : integralSum f vol π₁ - integralSum f vol Ο€β‚‚ = βˆ‘ J ∈ (π₁.toPrepartition βŠ“ Ο€β‚‚.toPrepartition).boxes, (vol J (f <| (π₁.infPrepartition Ο€β‚‚.toPrepartition).tag J) - vol J (f <| (Ο€β‚‚.infPrepartition π₁.toPrepartition).tag J)) := by rw [← integralSum_inf_partition f vol π₁ hβ‚‚, ← integralSum_inf_partition f vol Ο€β‚‚ h₁, integralSum, integralSum, Finset.sum_sub_distrib] simp only [infPrepartition_toPrepartition, inf_comm] @[simp] theorem integralSum_disjUnion (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) {π₁ Ο€β‚‚ : TaggedPrepartition I} (h : Disjoint π₁.iUnion Ο€β‚‚.iUnion) : integralSum f vol (π₁.disjUnion Ο€β‚‚ h) = integralSum f vol π₁ + integralSum f vol Ο€β‚‚ := by refine (Prepartition.sum_disj_union_boxes h _).trans (congr_argβ‚‚ (Β· + Β·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_)) Β· rw [disjUnion_tag_of_mem_left _ hJ] Β· rw [disjUnion_tag_of_mem_right _ hJ] @[simp] theorem integralSum_add (f g : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (f + g) vol Ο€ = integralSum f vol Ο€ + integralSum g vol Ο€ := by simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib] @[simp] theorem integralSum_neg (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (-f) vol Ο€ = -integralSum f vol Ο€ := by simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib] @[simp] theorem integralSum_smul (c : ℝ) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (Ο€ : TaggedPrepartition I) : integralSum (c β€’ f) vol Ο€ = c β€’ integralSum f vol Ο€ := by simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul] variable [Fintype ΞΉ] /-! ### Basic integrability theory -/ /-- The predicate `HasIntegral I l f vol y` says that `y` is the integral of `f` over `I` along `l` w.r.t. volume `vol`. This means that integral sums of `f` tend to `𝓝 y` along `BoxIntegral.IntegrationParams.toFilteriUnion I ⊀`. -/ def HasIntegral (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) (y : F) : Prop := Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) /-- A function is integrable if there exists a vector that satisfies the `HasIntegral` predicate. -/ def Integrable (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) := βˆƒ y, HasIntegral I l f vol y open Classical in /-- The integral of a function `f` over a box `I` along a filter `l` w.r.t. a volume `vol`. Returns zero on non-integrable functions. -/ def integral (I : Box ΞΉ) (l : IntegrationParams) (f : ℝⁿ β†’ E) (vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F) := if h : Integrable I l f vol then h.choose else 0 -- Porting note: using the above notation ℝⁿ here causes the theorem below to be silently ignored -- see https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Lean.204.20doesn't.20add.20lemma.20to.20the.20environment/near/363764522 -- and https://github.com/leanprover/lean4/issues/2257 variable {l : IntegrationParams} {f g : (ΞΉ β†’ ℝ) β†’ E} {vol : ΞΉ →ᡇᡃ E β†’L[ℝ] F} {y y' : F} /-- Reinterpret `BoxIntegral.HasIntegral` as `Filter.Tendsto`, e.g., dot-notation theorems that are shadowed in the `BoxIntegral.HasIntegral` namespace. -/ theorem HasIntegral.tendsto (h : HasIntegral I l f vol y) : Tendsto (integralSum f vol) (l.toFilteriUnion I ⊀) (𝓝 y) := h /-- The `Ξ΅`-`Ξ΄` definition of `BoxIntegral.HasIntegral`. -/ theorem hasIntegral_iff : HasIntegral I l f vol y ↔ βˆ€ Ξ΅ > (0 : ℝ), βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c Ο€, l.MemBaseSet I c (r c) Ο€ β†’ IsPartition Ο€ β†’ dist (integralSum f vol Ο€) y ≀ Ξ΅ := ((l.hasBasis_toFilteriUnion_top I).tendsto_iff nhds_basis_closedBall).trans <| by simp [@forall_swap ℝβ‰₯0 (TaggedPrepartition I)] /-- Quite often it is more natural to prove an estimate of the form `a * Ξ΅`, not `Ξ΅` in the RHS of `BoxIntegral.hasIntegral_iff`, so we provide this auxiliary lemma. -/ theorem HasIntegral.of_mul (a : ℝ) (h : βˆ€ Ξ΅ : ℝ, 0 < Ξ΅ β†’ βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c Ο€, l.MemBaseSet I c (r c) Ο€ β†’ IsPartition Ο€ β†’ dist (integralSum f vol Ο€) y ≀ a * Ξ΅) : HasIntegral I l f vol y := by refine hasIntegral_iff.2 fun Ξ΅ hΞ΅ => ?_ rcases exists_pos_mul_lt hΞ΅ a with ⟨Ρ', hΞ΅', ha⟩ rcases h Ξ΅' hΞ΅' with ⟨r, hr, H⟩ exact ⟨r, hr, fun c Ο€ hΟ€ hΟ€p => (H c Ο€ hΟ€ hΟ€p).trans ha.le⟩ theorem integrable_iff_cauchy [CompleteSpace F] : Integrable I l f vol ↔ Cauchy ((l.toFilteriUnion I ⊀).map (integralSum f vol)) := cauchy_map_iff_exists_tendsto.symm /-- In a complete space, a function is integrable if and only if its integral sums form a Cauchy net. Here we restate this fact in terms of `βˆ€ Ξ΅ > 0, βˆƒ r, ...`. -/ theorem integrable_iff_cauchy_basis [CompleteSpace F] : Integrable I l f vol ↔ βˆ€ Ξ΅ > (0 : ℝ), βˆƒ r : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ), (βˆ€ c, l.RCond (r c)) ∧ βˆ€ c₁ cβ‚‚ π₁ Ο€β‚‚, l.MemBaseSet I c₁ (r c₁) π₁ β†’ π₁.IsPartition β†’ l.MemBaseSet I cβ‚‚ (r cβ‚‚) Ο€β‚‚ β†’ Ο€β‚‚.IsPartition β†’ dist (integralSum f vol π₁) (integralSum f vol Ο€β‚‚) ≀ Ξ΅ := by rw [integrable_iff_cauchy, cauchy_map_iff', (l.hasBasis_toFilteriUnion_top _).prod_self.tendsto_iff uniformity_basis_dist_le] refine forallβ‚‚_congr fun Ξ΅ _ => exists_congr fun r => ?_ simp only [exists_prop, Prod.forall, Set.mem_iUnion, exists_imp, prodMk_mem_set_prod_eq, and_imp, mem_inter_iff, mem_setOf_eq] exact and_congr Iff.rfl ⟨fun H c₁ cβ‚‚ π₁ Ο€β‚‚ h₁ hU₁ hβ‚‚ hUβ‚‚ => H π₁ Ο€β‚‚ c₁ h₁ hU₁ cβ‚‚ hβ‚‚ hUβ‚‚, fun H π₁ Ο€β‚‚ c₁ h₁ hU₁ cβ‚‚ hβ‚‚ hUβ‚‚ => H c₁ cβ‚‚ π₁ Ο€β‚‚ h₁ hU₁ hβ‚‚ hUβ‚‚βŸ© theorem HasIntegral.mono {l₁ lβ‚‚ : IntegrationParams} (h : HasIntegral I l₁ f vol y) (hl : lβ‚‚ ≀ l₁) : HasIntegral I lβ‚‚ f vol y := h.mono_left <| IntegrationParams.toFilteriUnion_mono _ hl _ protected theorem Integrable.hasIntegral (h : Integrable I l f vol) : HasIntegral I l f vol (integral I l f vol) := by rw [integral, dif_pos h] exact Classical.choose_spec h theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≀ l) : Integrable I l' f vol := ⟨_, h.hasIntegral.mono hle⟩ theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟨_, h⟩ theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h nonrec theorem HasIntegral.add (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f + g) vol (y + y') := by simpa only [HasIntegral, ← integralSum_add] using h.add h' theorem Integrable.add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f + g) vol := (hf.hasIntegral.add hg.hasIntegral).integrable theorem integral_add (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f + g) vol = integral I l f vol + integral I l g vol := (hf.hasIntegral.add hg.hasIntegral).integral_eq nonrec theorem HasIntegral.neg (hf : HasIntegral I l f vol y) : HasIntegral I l (-f) vol (-y) := by simpa only [HasIntegral, ← integralSum_neg] using hf.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f β–Έ hf.neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟨fun h => h.of_neg, fun h => h.neg⟩ @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := by classical exact if h : Integrable I l f vol then h.hasIntegral.neg.integral_eq else by rw [integral, integral, dif_neg h, dif_neg (mt Integrable.of_neg h), neg_zero] theorem HasIntegral.sub (h : HasIntegral I l f vol y) (h' : HasIntegral I l g vol y') : HasIntegral I l (f - g) vol (y - y') := by simpa only [sub_eq_add_neg] using h.add h'.neg theorem Integrable.sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : Integrable I l (f - g) vol := (hf.hasIntegral.sub hg.hasIntegral).integrable theorem integral_sub (hf : Integrable I l f vol) (hg : Integrable I l g vol) : integral I l (f - g) vol = integral I l f vol - integral I l g vol := (hf.hasIntegral.sub hg.hasIntegral).integral_eq theorem hasIntegral_const (c : E) : HasIntegral I l (fun _ => c) vol (vol I c) := tendsto_const_nhds.congr' <| (l.eventually_isPartition I).mono fun _Ο€ hΟ€ => Eq.symm <| (vol.map ⟨⟨fun g : E β†’L[ℝ] F ↦ g c, rfl⟩, fun _ _ ↦ rfl⟩).sum_partition_boxes le_top hΟ€ @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟨_, hasIntegral_const c⟩ theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟨0, hasIntegral_zero⟩ theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq theorem HasIntegral.sum {Ξ± : Type*} {s : Finset Ξ±} {f : Ξ± β†’ ℝⁿ β†’ E} {g : Ξ± β†’ F} (h : βˆ€ i ∈ s, HasIntegral I l (f i) vol (g i)) : HasIntegral I l (fun x => βˆ‘ i ∈ s, f i x) vol (βˆ‘ i ∈ s, g i) := by classical induction' s using Finset.induction_on with a s ha ihs; Β· simp [hasIntegral_zero] simp only [Finset.sum_insert ha]; rw [Finset.forall_mem_insert] at h exact h.1.add (ihs h.2) theorem HasIntegral.smul (hf : HasIntegral I l f vol y) (c : ℝ) : HasIntegral I l (c β€’ f) vol (c β€’ y) := by simpa only [HasIntegral, ← integralSum_smul] using (tendsto_const_nhds : Tendsto _ _ (𝓝 c)).smul hf theorem Integrable.smul (hf : Integrable I l f vol) (c : ℝ) : Integrable I l (c β€’ f) vol := (hf.hasIntegral.smul c).integrable theorem Integrable.of_smul {c : ℝ} (hf : Integrable I l (c β€’ f) vol) (hc : c β‰  0) : Integrable I l f vol := by simpa [inv_smul_smulβ‚€ hc] using hf.smul c⁻¹ @[simp] theorem integral_smul (c : ℝ) : integral I l (fun x => c β€’ f x) vol = c β€’ integral I l f vol := by rcases eq_or_ne c 0 with (rfl | hc); Β· simp only [zero_smul, integral_zero] by_cases hf : Integrable I l f vol Β· exact (hf.hasIntegral.smul c).integral_eq Β· have : Β¬Integrable I l (fun x => c β€’ f x) vol := mt (fun h => h.of_smul hc) hf rw [integral, integral, dif_neg hf, dif_neg this, smul_zero] open MeasureTheory /-- The integral of a nonnegative function w.r.t. a volume generated by a locally-finite measure is nonnegative. -/ theorem integral_nonneg {g : ℝⁿ β†’ ℝ} (hg : βˆ€ x ∈ Box.Icc I, 0 ≀ g x) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] : 0 ≀ integral I l g ΞΌ.toBoxAdditive.toSMul := by by_cases hgi : Integrable I l g ΞΌ.toBoxAdditive.toSMul Β· refine ge_of_tendsto' hgi.hasIntegral fun Ο€ => sum_nonneg fun J _ => ?_ exact mul_nonneg ENNReal.toReal_nonneg (hg _ <| Ο€.tag_mem_Icc _) Β· rw [integral, dif_neg hgi] /-- If `β€–f xβ€– ≀ g x` on `[l, u]` and `g` is integrable, then the norm of the integral of `f` is less than or equal to the integral of `g`. -/ theorem norm_integral_le_of_norm_le {g : ℝⁿ β†’ ℝ} (hle : βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ g x) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] (hg : Integrable I l g ΞΌ.toBoxAdditive.toSMul) : β€–(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β€– ≀ integral I l g ΞΌ.toBoxAdditive.toSMul := by by_cases hfi : Integrable.{u, v, v} I l f ΞΌ.toBoxAdditive.toSMul Β· refine le_of_tendsto_of_tendsto' hfi.hasIntegral.norm hg.hasIntegral fun Ο€ => ?_ refine norm_sum_le_of_le _ fun J _ => ?_ simp only [BoxAdditiveMap.toSMul_apply, norm_smul, smul_eq_mul, Real.norm_eq_abs, ΞΌ.toBoxAdditive_apply, abs_of_nonneg measureReal_nonneg] exact mul_le_mul_of_nonneg_left (hle _ <| Ο€.tag_mem_Icc _) ENNReal.toReal_nonneg Β· rw [integral, dif_neg hfi, norm_zero] exact integral_nonneg (fun x hx => (norm_nonneg _).trans (hle x hx)) ΞΌ theorem norm_integral_le_of_le_const {c : ℝ} (hc : βˆ€ x ∈ Box.Icc I, β€–f xβ€– ≀ c) (ΞΌ : Measure ℝⁿ) [IsLocallyFiniteMeasure ΞΌ] : β€–(integral I l f ΞΌ.toBoxAdditive.toSMul : E)β€– ≀ ΞΌ.real I * c := by simpa only [integral_const] using norm_integral_le_of_norm_le hc ΞΌ (integrable_const c) /-! # Henstock-Sacks inequality and integrability on subboxes Henstock-Sacks inequality for Henstock-Kurzweil integral says the following. Let `f` be a function integrable on a box `I`; let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged partition of `I` subordinate to `r`, the integral sum over this partition is `Ξ΅`-close to the integral. Then for any tagged prepartition (i.e. a finite collections of pairwise disjoint subboxes of `I` with tagged points) `Ο€`, the integral sum over `Ο€` differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement in the library is a bit more complicated to make it work for any `BoxIntegral.IntegrationParams`. We formalize several versions of this inequality in `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet`, `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`, and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. Instead of using predicate assumptions on `r`, we define `BoxIntegral.Integrable.convergenceR (h : integrable I l f vol) (Ξ΅ : ℝ) (c : ℝβ‰₯0) : ℝⁿ β†’ (0, ∞)` to be a function `r` such that - if `l.bRiemann`, then `r` is a constant; - if `Ξ΅ > 0`, then for any tagged partition `Ο€` of `I` subordinate to `r` (more precisely, satisfying the predicate `l.mem_base_set I c r`), the integral sum of `f` over `Ο€` differs from the integral of `f` over `I` by at most `Ξ΅`. The proof is mostly based on [Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55]. -/ namespace Integrable /-- If `Ξ΅ > 0`, then `BoxIntegral.Integrable.convergenceR` is a function `r : ℝβ‰₯0 β†’ ℝⁿ β†’ (0, ∞)` such that for every `c : ℝβ‰₯0`, for every tagged partition `Ο€` subordinate to `r` (and satisfying additional distortion estimates if `BoxIntegral.IntegrationParams.bDistortion l = true`), the corresponding integral sum is `Ξ΅`-close to the integral. If `BoxIntegral.IntegrationParams.bRiemann = true`, then `r c x` does not depend on `x`. If `Ξ΅ ≀ 0`, then we use `r c x = 1`. -/ def convergenceR (h : Integrable I l f vol) (Ξ΅ : ℝ) : ℝβ‰₯0 β†’ ℝⁿ β†’ Ioi (0 : ℝ) := if hΞ΅ : 0 < Ξ΅ then (hasIntegral_iff.1 h.hasIntegral Ξ΅ hΞ΅).choose else fun _ _ => ⟨1, Set.mem_Ioi.2 zero_lt_one⟩ variable {c c₁ cβ‚‚ : ℝβ‰₯0} {Ξ΅ Ρ₁ Ξ΅β‚‚ : ℝ} {π₁ Ο€β‚‚ : TaggedPrepartition I} theorem convergenceR_cond (h : Integrable I l f vol) (Ξ΅ : ℝ) (c : ℝβ‰₯0) : l.RCond (h.convergenceR Ξ΅ c) := by rw [convergenceR]; split_ifs with hβ‚€ exacts [(hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ‚€).choose_spec.1 _, fun _ x => rfl] theorem dist_integralSum_integral_le_of_memBaseSet (h : Integrable I l f vol) (hβ‚€ : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) (hΟ€p : Ο€.IsPartition) : dist (integralSum f vol Ο€) (integral I l f vol) ≀ Ξ΅ := by rw [convergenceR, dif_pos hβ‚€] at hΟ€ exact (hasIntegral_iff.1 h.hasIntegral Ξ΅ hβ‚€).choose_spec.2 c _ hΟ€ hΟ€p /-- **Henstock-Sacks inequality**. Let `r₁ rβ‚‚ : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `rβ‚–`, `k=1,2`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅β‚–`. Then for any two tagged *prepartition* `π₁ Ο€β‚‚` subordinate to `r₁` and `rβ‚‚` respectively and covering the same part of `I`, the integral sums of `f` over these prepartitions differ from each other by at most `Ρ₁ + Ξ΅β‚‚`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion. See also `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet`. -/ theorem dist_integralSum_le_of_memBaseSet (h : Integrable I l f vol) (hpos₁ : 0 < Ρ₁) (hposβ‚‚ : 0 < Ξ΅β‚‚) (h₁ : l.MemBaseSet I c₁ (h.convergenceR Ρ₁ c₁) π₁) (hβ‚‚ : l.MemBaseSet I cβ‚‚ (h.convergenceR Ξ΅β‚‚ cβ‚‚) Ο€β‚‚) (HU : π₁.iUnion = Ο€β‚‚.iUnion) : dist (integralSum f vol π₁) (integralSum f vol Ο€β‚‚) ≀ Ρ₁ + Ξ΅β‚‚ := by rcases h₁.exists_common_compl hβ‚‚ HU with βŸ¨Ο€, hΟ€U, hΟ€c₁, hΟ€cβ‚‚βŸ© set r : ℝⁿ β†’ Ioi (0 : ℝ) := fun x => min (h.convergenceR Ρ₁ c₁ x) (h.convergenceR Ξ΅β‚‚ cβ‚‚ x) set Ο€r := Ο€.toSubordinate r have H₁ : dist (integralSum f vol (π₁.unionComplToSubordinate Ο€ hΟ€U r)) (integral I l f vol) ≀ Ρ₁ := h.dist_integralSum_integral_le_of_memBaseSet hpos₁ (h₁.unionComplToSubordinate (fun _ _ => min_le_left _ _) hΟ€U hΟ€c₁) (isPartition_unionComplToSubordinate _ _ _ _) rw [HU] at hΟ€U have Hβ‚‚ : dist (integralSum f vol (Ο€β‚‚.unionComplToSubordinate Ο€ hΟ€U r)) (integral I l f vol) ≀ Ξ΅β‚‚ := h.dist_integralSum_integral_le_of_memBaseSet hposβ‚‚ (hβ‚‚.unionComplToSubordinate (fun _ _ => min_le_right _ _) hΟ€U hΟ€cβ‚‚) (isPartition_unionComplToSubordinate _ _ _ _) simpa [unionComplToSubordinate] using (dist_triangle_right _ _ _).trans (add_le_add H₁ Hβ‚‚) /-- If `f` is integrable on `I` along `l`, then for two sufficiently fine tagged prepartitions (in the sense of the filter `BoxIntegral.IntegrationParams.toFilter l I`) such that they cover the same part of `I`, the integral sums of `f` over `π₁` and `Ο€β‚‚` are very close to each other. -/ theorem tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity (h : Integrable I l f vol) : Tendsto (fun Ο€ : TaggedPrepartition I Γ— TaggedPrepartition I => (integralSum f vol Ο€.1, integralSum f vol Ο€.2)) ((l.toFilter I Γ—Λ’ l.toFilter I) βŠ“ π“Ÿ {Ο€ | Ο€.1.iUnion = Ο€.2.iUnion}) (𝓀 F) := by refine (((l.hasBasis_toFilter I).prod_self.inf_principal _).tendsto_iff uniformity_basis_dist_le).2 fun Ξ΅ Ξ΅0 => ?_ replace Ξ΅0 := half_pos Ξ΅0 use h.convergenceR (Ξ΅ / 2), h.convergenceR_cond (Ξ΅ / 2); rintro βŸ¨Ο€β‚, Ο€β‚‚βŸ© ⟨⟨h₁, hβ‚‚βŸ©, hU⟩ rw [← add_halves Ξ΅] exact h.dist_integralSum_le_of_memBaseSet Ξ΅0 Ξ΅0 h₁.choose_spec hβ‚‚.choose_spec hU /-- If `f` is integrable on a box `I` along `l`, then for any fixed subset `s` of `I` that can be represented as a finite union of boxes, the integral sums of `f` over tagged prepartitions that cover exactly `s` form a Cauchy β€œsequence” along `l`. -/ theorem cauchy_map_integralSum_toFilteriUnion (h : Integrable I l f vol) (Ο€β‚€ : Prepartition I) : Cauchy ((l.toFilteriUnion I Ο€β‚€).map (integralSum f vol)) := by refine ⟨inferInstance, ?_⟩ rw [prod_map_map_eq, ← toFilter_inf_iUnion_eq, ← prod_inf_prod, prod_principal_principal] exact h.tendsto_integralSum_toFilter_prod_self_inf_iUnion_eq_uniformity.mono_left (inf_le_inf_left _ <| principal_mono.2 fun Ο€ h => h.1.trans h.2.symm) variable [CompleteSpace F] theorem to_subbox_aux (h : Integrable I l f vol) (hJ : J ≀ I) : βˆƒ y : F, HasIntegral J l f vol y ∧ Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 y) := by refine (cauchy_map_iff_exists_tendsto.1 (h.cauchy_map_integralSum_toFilteriUnion (.single I J hJ))).imp fun y hy ↦ ⟨?_, hy⟩ convert hy.comp (l.tendsto_embedBox_toFilteriUnion_top hJ) -- faster than `exact` here /-- If `f` is integrable on a box `I`, then it is integrable on any subbox of `I`. -/ theorem to_subbox (h : Integrable I l f vol) (hJ : J ≀ I) : Integrable J l f vol := (h.to_subbox_aux hJ).imp fun _ => And.left /-- If `f` is integrable on a box `I`, then integral sums of `f` over tagged prepartitions that cover exactly a subbox `J ≀ I` tend to the integral of `f` over `J` along `l`. -/ theorem tendsto_integralSum_toFilteriUnion_single (h : Integrable I l f vol) (hJ : J ≀ I) : Tendsto (integralSum f vol) (l.toFilteriUnion I (Prepartition.single I J hJ)) (𝓝 <| integral J l f vol) := let ⟨_y, h₁, hβ‚‚βŸ© := h.to_subbox_aux hJ h₁.integral_eq.symm β–Έ hβ‚‚ /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο€` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to account for additional requirements like being a Henstock partition or having a bounded distortion; - takes an extra argument `Ο€β‚€ : prepartition I` and an assumption `Ο€.Union = Ο€β‚€.Union` instead of using `Ο€.to_prepartition`. -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq (h : Integrable I l f vol) (h0 : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) {Ο€β‚€ : Prepartition I} (hU : Ο€.iUnion = Ο€β‚€.iUnion) : dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) ≀ Ξ΅ := by -- Let us prove that the distance is less than or equal to `Ξ΅ + Ξ΄` for all positive `Ξ΄`. refine le_of_forall_pos_le_add fun Ξ΄ Ξ΄0 => ?_ -- First we choose some constants. set Ξ΄' : ℝ := Ξ΄ / (#Ο€β‚€.boxes + 1) have H0 : 0 < (#Ο€β‚€.boxes + 1 : ℝ) := Nat.cast_add_one_pos _ have Ξ΄'0 : 0 < Ξ΄' := div_pos Ξ΄0 H0 set C := max Ο€β‚€.distortion Ο€β‚€.compl.distortion /- Next we choose a tagged partition of each `J ∈ Ο€β‚€` such that the integral sum of `f` over this partition is `Ξ΄'`-close to the integral of `f` over `J`. -/ have : βˆ€ J ∈ Ο€β‚€, βˆƒ Ο€i : TaggedPrepartition J, Ο€i.IsPartition ∧ dist (integralSum f vol Ο€i) (integral J l f vol) ≀ Ξ΄' ∧ l.MemBaseSet J C (h.convergenceR Ξ΄' C) Ο€i := by intro J hJ have Hle : J ≀ I := Ο€β‚€.le_of_mem hJ have HJi : Integrable J l f vol := h.to_subbox Hle set r := fun x => min (h.convergenceR Ξ΄' C x) (HJi.convergenceR Ξ΄' C x) have hJd : J.distortion ≀ C := le_trans (Finset.le_sup hJ) (le_max_left _ _) rcases l.exists_memBaseSet_isPartition J hJd r with βŸ¨Ο€J, hC, hp⟩ have hC₁ : l.MemBaseSet J C (HJi.convergenceR Ξ΄' C) Ο€J := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_right _ _ have hCβ‚‚ : l.MemBaseSet J C (h.convergenceR Ξ΄' C) Ο€J := by refine hC.mono J le_rfl le_rfl fun x _ => ?_; exact min_le_left _ _ exact βŸ¨Ο€J, hp, HJi.dist_integralSum_integral_le_of_memBaseSet Ξ΄'0 hC₁ hp, hCβ‚‚βŸ© /- Now we combine these tagged partitions into a tagged prepartition of `I` that covers the same part of `I` as `Ο€β‚€` and apply `BoxIntegral.dist_integralSum_le_of_memBaseSet` to `Ο€` and this prepartition. -/ choose! Ο€i hΟ€ip hΟ€iΞ΄' hΟ€iC using this have : l.MemBaseSet I C (h.convergenceR Ξ΄' C) (Ο€β‚€.biUnionTagged Ο€i) := biUnionTagged_memBaseSet hΟ€iC hΟ€ip fun _ => le_max_right _ _ have hU' : Ο€.iUnion = (Ο€β‚€.biUnionTagged Ο€i).iUnion := hU.trans (Prepartition.iUnion_biUnion_partition _ hΟ€ip).symm have := h.dist_integralSum_le_of_memBaseSet h0 Ξ΄'0 hΟ€ this hU' rw [integralSum_biUnionTagged] at this calc dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) ≀ dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€β‚€.boxes, integralSum f vol (Ο€i J)) + dist (βˆ‘ J ∈ Ο€β‚€.boxes, integralSum f vol (Ο€i J)) (βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) := dist_triangle _ _ _ _ ≀ Ξ΅ + Ξ΄' + βˆ‘ _J ∈ Ο€β‚€.boxes, Ξ΄' := add_le_add this (dist_sum_sum_le_of_le _ hΟ€iΞ΄') _ = Ξ΅ + Ξ΄ := by field_simp [Ξ΄']; ring /-- **Henstock-Sacks inequality**. Let `r : ℝⁿ β†’ (0, ∞)` be a function such that for any tagged *partition* of `I` subordinate to `r`, the integral sum of `f` over this partition differs from the integral of `f` by at most `Ξ΅`. Then for any tagged *prepartition* `Ο€` subordinate to `r`, the integral sum of `f` over this prepartition differs from the integral of `f` over the part of `I` covered by `Ο€` by at most `Ξ΅`. The actual statement - uses `BoxIntegral.Integrable.convergenceR` instead of a predicate assumption on `r`; - uses `BoxIntegral.IntegrationParams.MemBaseSet` instead of β€œsubordinate to `r`” to
account for additional requirements like being a Henstock partition or having a bounded distortion; -/ theorem dist_integralSum_sum_integral_le_of_memBaseSet (h : Integrable I l f vol) (h0 : 0 < Ξ΅) (hΟ€ : l.MemBaseSet I c (h.convergenceR Ξ΅ c) Ο€) : dist (integralSum f vol Ο€) (βˆ‘ J ∈ Ο€.boxes, integral J l f vol) ≀ Ξ΅ := h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq h0 hΟ€ rfl /-- Integral sum of `f` over a tagged prepartition `Ο€` such that `Ο€.Union = Ο€β‚€.Union` tends to the sum of integrals of `f` over the boxes of `Ο€β‚€`. -/ theorem tendsto_integralSum_sum_integral (h : Integrable I l f vol) (Ο€β‚€ : Prepartition I) : Tendsto (integralSum f vol) (l.toFilteriUnion I Ο€β‚€) (𝓝 <| βˆ‘ J ∈ Ο€β‚€.boxes, integral J l f vol) := by refine ((l.hasBasis_toFilteriUnion I Ο€β‚€).tendsto_iff nhds_basis_closedBall).2 fun Ξ΅ Ξ΅0 => ?_ refine ⟨h.convergenceR Ξ΅, h.convergenceR_cond Ξ΅, ?_⟩ simp only [mem_inter_iff, Set.mem_iUnion, mem_setOf_eq] rintro Ο€ ⟨c, hc, hU⟩ exact h.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq Ξ΅0 hc hU /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `Ο€β‚‚` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `Ο€β‚‚`. See also `BoxIntegral.Integrable.toBoxAdditive` for a bundled version. -/ theorem sum_integral_congr (h : Integrable I l f vol) {π₁ Ο€β‚‚ : Prepartition I} (hU : π₁.iUnion = Ο€β‚‚.iUnion) : βˆ‘ J ∈ π₁.boxes, integral J l f vol = βˆ‘ J ∈ Ο€β‚‚.boxes, integral J l f vol := by refine tendsto_nhds_unique (h.tendsto_integralSum_sum_integral π₁) ?_ rw [l.toFilteriUnion_congr _ hU] exact h.tendsto_integralSum_sum_integral Ο€β‚‚ /-- If `f` is integrable on `I`, then `fun J ↦ integral J l f vol` is box-additive on subboxes of `I`: if `π₁`, `Ο€β‚‚` are two prepartitions of `I` covering the same part of `I`, the sum of integrals of `f` over the boxes of `π₁` is equal to the sum of integrals of `f` over the boxes of `Ο€β‚‚`. See also `BoxIntegral.Integrable.sum_integral_congr` for an unbundled version. -/ @[simps] def toBoxAdditive (h : Integrable I l f vol) : ΞΉ →ᡇᡃ[I] F where toFun J := integral J l f vol sum_partition_boxes' J hJ Ο€ hΟ€ := by replace hΟ€ := hΟ€.iUnion_eq; rw [← Prepartition.iUnion_top] at hΟ€ rw [(h.to_subbox (WithTop.coe_le_coe.1 hJ)).sum_integral_congr hΟ€, Prepartition.top_boxes, sum_singleton]
Mathlib/Analysis/BoxIntegral/Basic.lean
564
607
/- Copyright (c) 2021 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kyle Miller, Eric Wieser -/ import Mathlib.Algebra.Ring.Divisibility.Basic import Mathlib.Data.Int.GCD import Mathlib.Tactic.NormNum /-! # `norm_num` extensions for GCD-adjacent functions This module defines some `norm_num` extensions for functions such as `Nat.gcd`, `Nat.lcm`, `Int.gcd`, and `Int.lcm`. Note that `Nat.coprime` is reducible and defined in terms of `Nat.gcd`, so the `Nat.gcd` extension also indirectly provides a `Nat.coprime` extension. -/ namespace Tactic namespace NormNum theorem int_gcd_helper' {d : β„•} {x y : β„€} (a b : β„€) (h₁ : (d : β„€) ∣ x) (hβ‚‚ : (d : β„€) ∣ y) (h₃ : x * a + y * b = d) : Int.gcd x y = d := by refine Nat.dvd_antisymm ?_ (Int.natCast_dvd_natCast.1 (Int.dvd_coe_gcd h₁ hβ‚‚)) rw [← Int.natCast_dvd_natCast, ← h₃] apply dvd_add Β· exact Int.gcd_dvd_left.mul_right _ Β· exact Int.gcd_dvd_right.mul_right _ theorem nat_gcd_helper_dvd_left (x y : β„•) (h : y % x = 0) : Nat.gcd x y = x := Nat.gcd_eq_left (Nat.dvd_of_mod_eq_zero h) theorem nat_gcd_helper_dvd_right (x y : β„•) (h : x % y = 0) : Nat.gcd x y = y := Nat.gcd_eq_right (Nat.dvd_of_mod_eq_zero h)
theorem nat_gcd_helper_2 (d x y a b : β„•) (hu : x % d = 0) (hv : y % d = 0) (h : x * a = y * b + d) : Nat.gcd x y = d := by rw [← Int.gcd_natCast_natCast] apply int_gcd_helper' a (-b) (Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hu)) (Int.natCast_dvd_natCast.mpr (Nat.dvd_of_mod_eq_zero hv)) rw [mul_neg, ← sub_eq_add_neg, sub_eq_iff_eq_add']
Mathlib/Tactic/NormNum/GCD.lean
36
43
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Kim Morrison, Apurva Nakade, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.SetTheory.PGame.Algebra import Mathlib.Tactic.Abel /-! # Combinatorial games. In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`. ## Multiplication on pre-games We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x β‰ˆ y` does not imply `x * z β‰ˆ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless, the abelian group structure on games allows us to simplify many proofs for pre-games. -/ -- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec noncomputable section namespace SetTheory open Function PGame universe u -- Porting note: moved the setoid instance to PGame.lean /-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a combinatorial pre-game is built inductively from two families of combinatorial games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. A combinatorial game is then constructed by quotienting by the equivalence `x β‰ˆ y ↔ x ≀ y ∧ y ≀ x`. -/ abbrev Game := Quotient PGame.setoid namespace Game -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): added this definition /-- Negation of games. -/ instance : Neg Game where neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2 instance : Zero Game where zero := ⟦0⟧ instance : Add Game where add := Quotient.mapβ‚‚ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where zero := ⟦0⟧ one := ⟦1⟧ add_zero := by rintro ⟨x⟩ exact Quot.sound (add_zero_equiv x) zero_add := by rintro ⟨x⟩ exact Quot.sound (zero_add_equiv x) add_assoc := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact Quot.sound add_assoc_equiv neg_add_cancel := Quotient.ind <| fun x => Quot.sound (neg_add_cancel_equiv x) add_comm := by rintro ⟨x⟩ ⟨y⟩ exact Quot.sound add_comm_equiv nsmul := nsmulRec zsmul := zsmulRec instance : Inhabited Game := ⟨0⟩ theorem zero_def : (0 : Game) = ⟦0⟧ := rfl instance instPartialOrderGame : PartialOrder Game where le := Quotient.liftβ‚‚ (Β· ≀ Β·) fun _ _ _ _ hx hy => propext (le_congr hx hy) le_refl := by rintro ⟨x⟩ exact le_refl x le_trans := by rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ exact @le_trans _ _ x y z le_antisymm := by rintro ⟨x⟩ ⟨y⟩ h₁ hβ‚‚ apply Quot.sound exact ⟨h₁, hβ‚‚βŸ© lt := Quotient.liftβ‚‚ (Β· < Β·) fun _ _ _ _ hx hy => propext (lt_congr hx hy) lt_iff_le_not_le := by rintro ⟨x⟩ ⟨y⟩ exact @lt_iff_le_not_le _ _ x y /-- The less or fuzzy relation on games. If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/ def LF : Game β†’ Game β†’ Prop := Quotient.liftβ‚‚ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy) /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_le : βˆ€ {x y : Game}, Β¬x ≀ y ↔ Game.LF y x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_le /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_lf : βˆ€ {x y : Game}, Β¬Game.LF x y ↔ y ≀ x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_lf /-- The fuzzy, confused, or incomparable relation on games. If `x β€– 0`, then the first player can always win `x`. -/ def Fuzzy : Game β†’ Game β†’ Prop := Quotient.liftβ‚‚ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy) -- Porting note: had to replace ⧏ with LF, otherwise cannot differentiate with the operator on PGame instance : IsTrichotomous Game LF := ⟨by rintro ⟨x⟩ ⟨y⟩ change _ ∨ ⟦x⟧ = ⟦y⟧ ∨ _ rw [Quotient.eq] apply lf_or_equiv_or_gf⟩ /-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as the `AddCommGroup` structure on `Game` often simplifies many proofs. -/ end Game namespace PGame -- Porting note: In a lot of places, I had to add explicitly that the quotient element was a Game. -- In Lean4, quotients don't have the setoid as an instance argument, -- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354 theorem le_iff_game_le {x y : PGame} : x ≀ y ↔ (⟦x⟧ : Game) ≀ ⟦y⟧ := Iff.rfl theorem lf_iff_game_lf {x y : PGame} : x ⧏ y ↔ Game.LF ⟦x⟧ ⟦y⟧ := Iff.rfl theorem lt_iff_game_lt {x y : PGame} : x < y ↔ (⟦x⟧ : Game) < ⟦y⟧ := Iff.rfl theorem equiv_iff_game_eq {x y : PGame} : x β‰ˆ y ↔ (⟦x⟧ : Game) = ⟦y⟧ := (@Quotient.eq' _ _ x y).symm alias ⟨game_eq, _⟩ := equiv_iff_game_eq theorem fuzzy_iff_game_fuzzy {x y : PGame} : x β€– y ↔ Game.Fuzzy ⟦x⟧ ⟦y⟧ := Iff.rfl end PGame namespace Game local infixl:50 " ⧏ " => LF local infixl:50 " β€– " => Fuzzy instance addLeftMono : AddLeftMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_left _ _ _ _ b c h a⟩ instance addRightMono : AddRightMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_right _ _ _ _ b c h a⟩ instance addLeftStrictMono : AddLeftStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_left _ _ _ _ b c h a⟩ instance addRightStrictMono : AddRightStrictMono Game := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_right _ _ _ _ b c h a⟩ theorem add_lf_add_right : βˆ€ {b c : Game} (_ : b ⧏ c) (a), (b + a : Game) ⧏ c + a := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_right h theorem add_lf_add_left : βˆ€ {b c : Game} (_ : b ⧏ c) (a), (a + b : Game) ⧏ a + c := by rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩ apply PGame.add_lf_add_left h instance isOrderedAddMonoid : IsOrderedAddMonoid Game := { add_le_add_left := @add_le_add_left _ _ _ Game.addLeftMono } /-- A small family of games is bounded above. -/ lemma bddAbove_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β†’ Game.{u}) : BddAbove (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddAbove_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded above. -/ lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s β†’ Game.{u}) /-- A small family of games is bounded below. -/ lemma bddBelow_range_of_small {ΞΉ : Type*} [Small.{u} ΞΉ] (f : ΞΉ β†’ Game.{u}) : BddBelow (Set.range f) := by obtain ⟨x, hx⟩ := PGame.bddBelow_range_of_small (Quotient.out ∘ f) refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩ simpa [PGame.le_iff_game_le] using hx <| Set.mem_range_self i /-- A small set of games is bounded below. -/ lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s β†’ Game.{u}) end Game namespace PGame @[simp] theorem quot_zero : (⟦0⟧ : Game) = 0 := rfl @[simp] theorem quot_one : (⟦1⟧ : Game) = 1 := rfl @[simp] theorem quot_neg (a : PGame) : (⟦-a⟧ : Game) = -⟦a⟧ := rfl @[simp] theorem quot_add (a b : PGame) : ⟦a + b⟧ = (⟦a⟧ : Game) + ⟦b⟧ := rfl @[simp] theorem quot_sub (a b : PGame) : ⟦a - b⟧ = (⟦a⟧ : Game) - ⟦b⟧ := rfl @[simp] theorem quot_natCast : βˆ€ n : β„•, ⟦(n : PGame)⟧ = (n : Game) | 0 => rfl | n + 1 => by rw [PGame.nat_succ, quot_add, Nat.cast_add, Nat.cast_one, quot_natCast] rfl theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : βˆ€ i, (⟦x.moveLeft i⟧ : Game) = ⟦y.moveLeft (L i)⟧) (hr : βˆ€ j, (⟦x.moveRight j⟧ : Game) = ⟦y.moveRight (R j)⟧) : (⟦x⟧ : Game) = ⟦y⟧ := game_eq (.of_equiv L R (fun _ => equiv_iff_game_eq.2 (hl _)) (fun _ => equiv_iff_game_eq.2 (hr _))) /-! Multiplicative operations can be defined at the level of pre-games, but to prove their properties we need to use the abelian group structure of games. Hence we define them here. -/ /-- The product of `x = {xL | xR}` and `y = {yL | yR}` is `{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, xR*y + x*yL - xR*yL}`. -/ instance : Mul PGame.{u} := ⟨fun x y => by induction x generalizing y with | mk xl xr _ _ IHxl IHxr => _ induction y with | mk yl yr yL yR IHyl IHyr => _ have y := mk yl yr yL yR refine ⟨(xl Γ— yl) βŠ• (xr Γ— yr), (xl Γ— yr) βŠ• (xr Γ— yl), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) Β· exact IHxl i y + IHyl j - IHxl i (yL j) Β· exact IHxr i y + IHyr j - IHxr i (yR j) Β· exact IHxl i y + IHyr j - IHxl i (yR j) Β· exact IHxr i y + IHyl j - IHxr i (yL j)⟩ theorem leftMoves_mul : βˆ€ x y : PGame.{u}, (x * y).LeftMoves = (x.LeftMoves Γ— y.LeftMoves βŠ• x.RightMoves Γ— y.RightMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl theorem rightMoves_mul : βˆ€ x y : PGame.{u}, (x * y).RightMoves = (x.LeftMoves Γ— y.RightMoves βŠ• x.RightMoves Γ— y.LeftMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl /-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toLeftMovesMul {x y : PGame} : (x.LeftMoves Γ— y.LeftMoves) βŠ• (x.RightMoves Γ— y.RightMoves) ≃ (x * y).LeftMoves := Equiv.cast (leftMoves_mul x y).symm /-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa. Even though these types are the same (not definitionally so), this is the preferred way to convert between them. -/ def toRightMovesMul {x y : PGame} : (x.LeftMoves Γ— y.RightMoves) βŠ• (x.RightMoves Γ— y.LeftMoves) ≃ (x * y).RightMoves := Equiv.cast (rightMoves_mul x y).symm @[simp] theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j := rfl @[simp] theorem mul_moveLeft_inl {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by cases x cases y rfl @[simp] theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j := rfl @[simp] theorem mul_moveLeft_inr {x y : PGame} {i j} : (x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) = xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j := rfl @[simp] theorem mul_moveRight_inl {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) = x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by cases x cases y rfl @[simp] theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) = xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j := rfl @[simp] theorem mul_moveRight_inr {x y : PGame} {i j} : (x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) = x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by cases x cases y rfl @[simp] theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) := rfl @[simp] theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) = -(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) := rfl @[simp] theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} : (-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) = -(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) := rfl theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves β†’ Prop} (hl : βˆ€ ix iy, P <| toLeftMovesMul (Sum.inl ⟨ix, iy⟩)) (hr : βˆ€ jx jy, P <| toLeftMovesMul (Sum.inr ⟨jx, jy⟩)) : P k := by rw [← toLeftMovesMul.apply_symm_apply k] rcases toLeftMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) Β· apply hl Β· apply hr theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves β†’ Prop} (hl : βˆ€ ix jy, P <| toRightMovesMul (Sum.inl ⟨ix, jy⟩)) (hr : βˆ€ jx iy, P <| toRightMovesMul (Sum.inr ⟨jx, iy⟩)) : P k := by rw [← toRightMovesMul.apply_symm_apply k] rcases toRightMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩) Β· apply hl Β· apply hr /-- `x * y` and `y * x` have the same moves. -/ protected lemma mul_comm (x y : PGame) : x * y ≑ y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine Identical.of_equiv ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _)) ((Equiv.sumComm _ _).trans ((Equiv.prodComm _ _).sumCongr (Equiv.prodComm _ _))) ?_ ?_ <;> Β· rintro (⟨_, _⟩ | ⟨_, _⟩) <;> exact ((((PGame.mul_comm _ (mk _ _ _ _)).add (PGame.mul_comm (mk _ _ _ _) _)).trans (PGame.add_comm _ _)).sub (PGame.mul_comm _ _)) termination_by (x, y) /-- `x * y` and `y * x` have the same moves. -/ def mulCommRelabelling (x y : PGame.{u}) : x * y ≑r y * x := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _), (Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> { dsimp exact ((addCommRelabelling _ _).trans <| (mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr (mulCommRelabelling _ _) } termination_by (x, y) theorem quot_mul_comm (x y : PGame.{u}) : (⟦x * y⟧ : Game) = ⟦y * x⟧ := game_eq (x.mul_comm y).equiv /-- `x * y` is equivalent to `y * x`. -/ theorem mul_comm_equiv (x y : PGame) : x * y β‰ˆ y * x := Quotient.exact <| quot_mul_comm _ _ instance isEmpty_leftMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves Γ— y.LeftMoves βŠ• x.RightMoves Γ— y.RightMoves)] : IsEmpty (x * y).LeftMoves := by cases x cases y assumption instance isEmpty_rightMoves_mul (x y : PGame.{u}) [IsEmpty (x.LeftMoves Γ— y.RightMoves βŠ• x.RightMoves Γ— y.LeftMoves)] : IsEmpty (x * y).RightMoves := by cases x cases y assumption /-- `x * 0` has exactly the same moves as `0`. -/ protected lemma mul_zero (x : PGame) : x * 0 ≑ 0 := identical_zero _ /-- `x * 0` has exactly the same moves as `0`. -/ def mulZeroRelabelling (x : PGame) : x * 0 ≑r 0 := Relabelling.isEmpty _ /-- `x * 0` is equivalent to `0`. -/ theorem mul_zero_equiv (x : PGame) : x * 0 β‰ˆ 0 := x.mul_zero.equiv @[simp] theorem quot_mul_zero (x : PGame) : (⟦x * 0⟧ : Game) = 0 := game_eq x.mul_zero_equiv /-- `0 * x` has exactly the same moves as `0`. -/ protected lemma zero_mul (x : PGame) : 0 * x ≑ 0 := identical_zero _ /-- `0 * x` has exactly the same moves as `0`. -/ def zeroMulRelabelling (x : PGame) : 0 * x ≑r 0 := Relabelling.isEmpty _ /-- `0 * x` is equivalent to `0`. -/ theorem zero_mul_equiv (x : PGame) : 0 * x β‰ˆ 0 := x.zero_mul.equiv @[simp] theorem quot_zero_mul (x : PGame) : (⟦0 * x⟧ : Game) = 0 := game_eq x.zero_mul_equiv /-- `-x * y` and `-(x * y)` have the same moves. -/ def negMulRelabelling (x y : PGame.{u}) : -x * y ≑r -(x * y) := match x, y with | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by refine ⟨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) <;> Β· dsimp apply ((negAddRelabelling _ _).trans _).symm apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr -- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here. Β· exact (negMulRelabelling _ _).symm Β· exact (negMulRelabelling _ _).symm -- Porting note: not sure what has gone wrong here. -- The goal is hideous here, and the `exact` doesn't work, -- but if we just `change` it to look like the mathlib3 goal then we're fine!? change -(mk xl xr xL xR * _) ≑r _ exact (negMulRelabelling _ _).symm termination_by (x, y) /-- `x * -y` and `-(x * y)` have the same moves. -/ @[simp] lemma mul_neg (x y : PGame) : x * -y = -(x * y) := match x, y with | mk xl xr xL xR, mk yl yr yL yR => by refine ext rfl rfl ?_ ?_ <;> rintro (⟨i, j⟩ | ⟨i, j⟩) _ ⟨rfl⟩ all_goals dsimp rw [PGame.neg_sub', PGame.neg_add] congr exacts [mul_neg _ (mk ..), mul_neg .., mul_neg ..] termination_by (x, y) /-- `-x * y` and `-(x * y)` have the same moves. -/ lemma neg_mul (x y : PGame) : -x * y ≑ -(x * y) := ((PGame.mul_comm _ _).trans (of_eq (mul_neg _ _))).trans (PGame.mul_comm _ _).neg @[simp] theorem quot_neg_mul (x y : PGame) : (⟦-x * y⟧ : Game) = -⟦x * y⟧ := game_eq (x.neg_mul y).equiv /-- `x * -y` and `-(x * y)` have the same moves. -/ def mulNegRelabelling (x y : PGame) : x * -y ≑r -(x * y) := (mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr theorem quot_mul_neg (x y : PGame) : ⟦x * -y⟧ = (-⟦x * y⟧ : Game) := game_eq (by rw [mul_neg]) theorem quot_neg_mul_neg (x y : PGame) : ⟦-x * -y⟧ = (⟦x * y⟧ : Game) := by simp @[simp] theorem quot_left_distrib (x y z : PGame) : (⟦x * (y + z)⟧ : Game) = ⟦x * y⟧ + ⟦x * z⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ Β· fconstructor Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> -- Porting note: we've increased `maxDepth` here from `5` to `6`. -- Likely this sort of off-by-one error is just a change in the implementation -- of `solve_by_elim`. solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl Β· fconstructor Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_left_distrib reference below, because otherwise the decreasing_by block -- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel` -- See https://github.com/leanprover/lean4/issues/2288 Β· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) Β· change ⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧ = ⟦xL i * y + x * yL j - xL i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)] abel Β· change ⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧ = ⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)] abel Β· change ⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧ = ⟦xR i * y + x * yR j - xR i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)] abel Β· change ⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧ = ⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)] abel Β· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩) Β· change ⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧ = ⟦xL i * y + x * yR j - xL i * yR j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)] abel Β· change ⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧ = ⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)] abel Β· change ⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧ = ⟦xR i * y + x * yL j - xR i * yL j + x * z⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)] abel Β· change ⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧ = ⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧ simp only [quot_sub, quot_add] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)] abel termination_by (x, y, z) /-- `x * (y + z)` is equivalent to `x * y + x * z`. -/ theorem left_distrib_equiv (x y z : PGame) : x * (y + z) β‰ˆ x * y + x * z := Quotient.exact <| quot_left_distrib _ _ _ @[simp] theorem quot_left_distrib_sub (x y z : PGame) : (⟦x * (y - z)⟧ : Game) = ⟦x * y⟧ - ⟦x * z⟧ := by change (⟦x * (y + -z)⟧ : Game) = ⟦x * y⟧ + -⟦x * z⟧ rw [quot_left_distrib, quot_mul_neg] @[simp] theorem quot_right_distrib (x y z : PGame) : (⟦(x + y) * z⟧ : Game) = ⟦x * z⟧ + ⟦y * z⟧ := by simp only [quot_mul_comm, quot_left_distrib] /-- `(x + y) * z` is equivalent to `x * z + y * z`. -/ theorem right_distrib_equiv (x y z : PGame) : (x + y) * z β‰ˆ x * z + y * z := Quotient.exact <| quot_right_distrib _ _ _ @[simp] theorem quot_right_distrib_sub (x y z : PGame) : (⟦(y - z) * x⟧ : Game) = ⟦y * x⟧ - ⟦z * x⟧ := by change (⟦(y + -z) * x⟧ : Game) = ⟦y * x⟧ + -⟦z * x⟧ rw [quot_right_distrib, quot_neg_mul] /-- `x * 1` has the same moves as `x`. -/ def mulOneRelabelling : βˆ€ x : PGame.{u}, x * 1 ≑r x | ⟨xl, xr, xL, xR⟩ => by -- Porting note: the next four lines were just `unfold has_one.one,` show _ * One.one ≑r _ unfold One.one unfold instOnePGame change mk _ _ _ _ * mk _ _ _ _ ≑r _ refine ⟨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _), (Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_⟩ <;> (try rintro (⟨i, ⟨⟩⟩ | ⟨i, ⟨⟩⟩)) <;> { dsimp apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans rw [sub_zero_eq_add_zero] exact (addZeroRelabelling _).trans <| (((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) } /-- `1 * x` has the same moves as `x`. -/ protected lemma one_mul : βˆ€ (x : PGame), 1 * x ≑ x | ⟨xl, xr, xL, xR⟩ => by refine Identical.of_equiv ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ((Equiv.sumEmpty _ _).trans (Equiv.punitProd _)) ?_ ?_ <;> Β· rintro (⟨⟨⟩, _⟩ | ⟨⟨⟩, _⟩) exact ((((PGame.zero_mul (mk _ _ _ _)).add (PGame.one_mul _)).trans (PGame.zero_add _)).sub (PGame.zero_mul _)).trans (PGame.sub_zero _) /-- `x * 1` has the same moves as `x`. -/ protected lemma mul_one (x : PGame) : x * 1 ≑ x := (x.mul_comm _).trans x.one_mul @[simp] theorem quot_mul_one (x : PGame) : (⟦x * 1⟧ : Game) = ⟦x⟧ := game_eq x.mul_one.equiv /-- `x * 1` is equivalent to `x`. -/ theorem mul_one_equiv (x : PGame) : x * 1 β‰ˆ x := Quotient.exact <| quot_mul_one x /-- `1 * x` has the same moves as `x`. -/ def oneMulRelabelling (x : PGame) : 1 * x ≑r x := (mulCommRelabelling 1 x).trans <| mulOneRelabelling x @[simp] theorem quot_one_mul (x : PGame) : (⟦1 * x⟧ : Game) = ⟦x⟧ := game_eq x.one_mul.equiv /-- `1 * x` is equivalent to `x`. -/ theorem one_mul_equiv (x : PGame) : 1 * x β‰ˆ x := Quotient.exact <| quot_one_mul x theorem quot_mul_assoc (x y z : PGame) : (⟦x * y * z⟧ : Game) = ⟦x * (y * z)⟧ := match x, y, z with | mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by let x := mk xl xr xL xR let y := mk yl yr yL yR let z := mk zl zr zL zR refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_ Β· fconstructor Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> -- Porting note: as above, increased the `maxDepth` here by 1. solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl Β· fconstructor Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk] Β· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl Β· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl -- Porting note: explicitly wrote out arguments to each recursive -- quot_mul_assoc reference below, because otherwise the decreasing_by block -- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel` -- See https://github.com/leanprover/lean4/issues/2288 Β· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) Β· change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k - (xL i * y + x * yL j - xL i * yL j) * zL k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xL i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xL i) (yL j) (zL k)] abel Β· change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k - (xR i * y + x * yR j - xR i * yR j) * zL k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xR i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xR i) (yR j) (zL k)] abel Β· change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k - (xL i * y + x * yR j - xL i * yR j) * zR k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xL i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xL i) (yR j) (zR k)] abel Β· change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k - (xR i * y + x * yL j - xR i * yL j) * zR k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xR i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xR i) (yL j) (zR k)] abel Β· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩) Β· change ⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k - (xL i * y + x * yL j - xL i * yL j) * zR k⟧ = ⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) - xL i * (yL j * z + y * zR k - yL j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)] rw [quot_mul_assoc (xL i) (yL j) (zR k)] abel Β· change ⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k - (xR i * y + x * yR j - xR i * yR j) * zR k⟧ = ⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) - xR i * (yR j * z + y * zR k - yR j * zR k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)] rw [quot_mul_assoc (xR i) (yR j) (zR k)] abel Β· change ⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k - (xL i * y + x * yR j - xL i * yR j) * zL k⟧ = ⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) - xL i * (yR j * z + y * zL k - yR j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)] rw [quot_mul_assoc (xL i) (yR j) (zL k)] abel Β· change ⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k - (xR i * y + x * yL j - xR i * yL j) * zL k⟧ = ⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) - xR i * (yL j * z + y * zL k - yL j * zL k)⟧ simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib, quot_left_distrib_sub, quot_left_distrib] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)] rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)] rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)] rw [quot_mul_assoc (xR i) (yL j) (zL k)] abel termination_by (x, y, z) /-- `x * y * z` is equivalent to `x * (y * z)`. -/ theorem mul_assoc_equiv (x y z : PGame) : x * y * z β‰ˆ x * (y * z) := Quotient.exact <| quot_mul_assoc _ _ _ /-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/ def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame := x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j /-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of the first kind. -/ lemma mulOption_neg_neg {x} (y) {i j} : mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by simp [mulOption] /-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/ lemma mulOption_symm (x y) {i j} : ⟦mulOption x y i j⟧ = (⟦mulOption y x j i⟧ : Game) := by dsimp only [mulOption, quot_sub, quot_add] rw [add_comm] congr 1 on_goal 1 => congr 1 all_goals rw [quot_mul_comm] /-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the first kind, up to equivalence. -/ lemma leftMoves_mul_iff {x y : PGame} (P : Game β†’ Prop) : (βˆ€ k, P ⟦(x * y).moveLeft k⟧) ↔ (βˆ€ i j, P ⟦mulOption x y i j⟧) ∧ (βˆ€ i j, P ⟦mulOption (-x) (-y) i j⟧) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j Β· exact h (Sum.inl (i, j)) convert h (Sum.inr (i, j)) using 1 on_goal 2 => rintro (⟨i, j⟩ | ⟨i, j⟩) Β· exact h.1 i j convert h.2 i j using 1 all_goals dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk] rw [← neg_def, ← neg_def] congr 1 on_goal 1 => congr 1 all_goals rw [quot_neg_mul_neg] /-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first kind, up to equivalence. -/ lemma rightMoves_mul_iff {x y : PGame} (P : Game β†’ Prop) : (βˆ€ k, P ⟦(x * y).moveRight k⟧) ↔ (βˆ€ i j, P (-⟦mulOption x (-y) i j⟧)) ∧ (βˆ€ i j, P (-⟦mulOption (-x) y i j⟧)) := by cases x; cases y constructor <;> intro h on_goal 1 => constructor <;> intros i j on_goal 1 => convert h (Sum.inl (i, j)) on_goal 2 => convert h (Sum.inr (i, j)) on_goal 3 => rintro (⟨i, j⟩ | ⟨i, j⟩) on_goal 1 => convert h.1 i j using 1 on_goal 2 => convert h.2 i j using 1 all_goals dsimp [mulOption] rw [neg_sub', neg_add, ← neg_def] congr 1 on_goal 1 => congr 1 any_goals rw [quot_neg_mul, neg_neg] iterate 6 rw [quot_mul_neg, neg_neg] /-- Because the two halves of the definition of `inv` produce more elements on each side, we have to define the two families inductively. This is the indexing set for the function, and `invVal` is the function part. -/ inductive InvTy (l r : Type u) : Bool β†’ Type u | zero : InvTy l r false | left₁ : r β†’ InvTy l r false β†’ InvTy l r false | leftβ‚‚ : l β†’ InvTy l r true β†’ InvTy l r false | right₁ : l β†’ InvTy l r false β†’ InvTy l r true | rightβ‚‚ : r β†’ InvTy l r true β†’ InvTy l r true instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) := ⟨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim a⟩ instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) := ⟨InvTy.zero⟩ instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) := { InvTy.instInhabited l r with uniq := by rintro (a | a | a) Β· rfl all_goals exact isEmptyElim a } /-- Because the two halves of the definition of `inv` produce more elements of each side, we have to define the two families inductively. This is the function part, defined by recursion on `InvTy`. -/ def invVal {l r} (L : l β†’ PGame) (R : r β†’ PGame) (IHl : l β†’ PGame) (IHr : r β†’ PGame) (x : PGame) : βˆ€ {b}, InvTy l r b β†’ PGame | _, InvTy.zero => 0 | _, InvTy.left₁ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i | _, InvTy.leftβ‚‚ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.right₁ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i | _, InvTy.rightβ‚‚ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i @[simp] theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l] [IsEmpty r] : invVal L R IHl IHr x i = 0 := by obtain - | a | a | a | a := i Β· rfl all_goals exact isEmptyElim a /-- The inverse of a positive surreal number `x = {L | R}` is given by `x⁻¹ = {0, (1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L | (1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`. Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own definition, the sets and elements are inductively generated. -/ def inv' : PGame β†’ PGame | ⟨l, r, L, R⟩ => let l' := { i // 0 < L i } let L' : l' β†’ PGame := fun i => L i.1 let IHl' : l' β†’ PGame := fun i => inv' (L i.1) let IHr i := inv' (R i) let x := mk l r L R ⟨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr x⟩ theorem zero_lf_inv' : βˆ€ x : PGame, 0 ⧏ inv' x | ⟨xl, xr, xL, xR⟩ => by convert lf_mk _ _ InvTy.zero rfl /-- `inv' 0` has exactly the same moves as `1`. -/ def inv'Zero : inv' 0 ≑r 1 := by
change mk _ _ _ _ ≑r 1 refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩ Β· apply Equiv.equivPUnit (InvTy _ _ _) Β· apply Equiv.equivPEmpty (InvTy _ _ _) Β· -- Porting note: we added `rfl` after the `simp`
Mathlib/SetTheory/Game/Basic.lean
953
957
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring import Mathlib.Algebra.EuclideanDomain.Int /-! # β„€[√d] The ring of integers adjoined with a square root of `d : β„€`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `β„€βˆšd β†’+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : β„€`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : β„€) where /-- Component of the integer not multiplied by `√d` -/ re : β„€ /-- Component of the integer multiplied by `√d` -/ im : β„€ deriving DecidableEq @[inherit_doc] prefix:100 "β„€βˆš" => Zsqrtd namespace Zsqrtd section variable {d : β„€} /-- Convert an integer to a `β„€βˆšd` -/ def ofInt (n : β„€) : β„€βˆšd := ⟨n, 0⟩ theorem ofInt_re (n : β„€) : (ofInt n : β„€βˆšd).re = n := rfl theorem ofInt_im (n : β„€) : (ofInt n : β„€βˆšd).im = 0 := rfl /-- The zero of the ring -/ instance : Zero (β„€βˆšd) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : β„€βˆšd).re = 0 := rfl @[simp] theorem zero_im : (0 : β„€βˆšd).im = 0 := rfl instance : Inhabited (β„€βˆšd) := ⟨0⟩ /-- The one of the ring -/ instance : One (β„€βˆšd) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : β„€βˆšd).re = 1 := rfl @[simp] theorem one_im : (1 : β„€βˆšd).im = 0 := rfl /-- The representative of `√d` in the ring -/ def sqrtd : β„€βˆšd := ⟨0, 1⟩ @[simp] theorem sqrtd_re : (sqrtd : β„€βˆšd).re = 0 := rfl @[simp] theorem sqrtd_im : (sqrtd : β„€βˆšd).im = 1 := rfl /-- Addition of elements of `β„€βˆšd` -/ instance : Add (β„€βˆšd) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : β„€) : (⟨x, y⟩ + ⟨x', y'⟩ : β„€βˆšd) = ⟨x + x', y + y'⟩ := rfl @[simp] theorem add_re (z w : β„€βˆšd) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : β„€βˆšd) : (z + w).im = z.im + w.im := rfl /-- Negation in `β„€βˆšd` -/ instance : Neg (β„€βˆšd) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : β„€βˆšd) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : β„€βˆšd) : (-z).im = -z.im := rfl /-- Multiplication in `β„€βˆšd` -/ instance : Mul (β„€βˆšd) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : β„€βˆšd) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl @[simp] theorem mul_im (z w : β„€βˆšd) : (z * w).im = z.re * w.im + z.im * w.re := rfl instance addCommGroup : AddCommGroup (β„€βˆšd) := by refine { add := (Β· + Β·) zero := (0 : β„€βˆšd) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩ zsmul := @zsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩ ⟨Neg.neg⟩ (@nsmulRec (β„€βˆšd) ⟨0⟩ ⟨(Β· + Β·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ neg_add_cancel := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : β„€βˆšd) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : β„€βˆšd) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (β„€βˆšd) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (β„€βˆšd) := by refine { Zsqrtd.addGroupWithOne with mul := (Β· * Β·) npow := @npowRec (β„€βˆšd) ⟨1⟩ ⟨(Β· * Β·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (β„€βˆšd) := by infer_instance instance : Monoid (β„€βˆšd) := by infer_instance instance : CommMonoid (β„€βˆšd) := by infer_instance instance : CommSemigroup (β„€βˆšd) := by infer_instance instance : Semigroup (β„€βˆšd) := by infer_instance instance : AddCommSemigroup (β„€βˆšd) := by infer_instance instance : AddSemigroup (β„€βˆšd) := by infer_instance instance : CommSemiring (β„€βˆšd) := by infer_instance instance : Semiring (β„€βˆšd) := by infer_instance instance : Ring (β„€βˆšd) := by infer_instance instance : Distrib (β„€βˆšd) := by infer_instance /-- Conjugation in `β„€βˆšd`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (β„€βˆšd) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : β„€) : star (⟨x, y⟩ : β„€βˆšd) = ⟨x, -y⟩ := rfl @[simp] theorem star_re (z : β„€βˆšd) : (star z).re = z.re := rfl @[simp] theorem star_im (z : β„€βˆšd) : (star z).im = -z.im := rfl instance : StarRing (β„€βˆšd) where star_involutive _ := Zsqrtd.ext rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add _ _ := Zsqrtd.ext rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (β„€βˆšd) := ⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : β„•) : (n : β„€βˆšd).re = n := rfl @[simp] theorem ofNat_re (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„€βˆšd).re = n := rfl @[simp] theorem natCast_im (n : β„•) : (n : β„€βˆšd).im = 0 := rfl @[simp] theorem ofNat_im (n : β„•) [n.AtLeastTwo] : (ofNat(n) : β„€βˆšd).im = 0 := rfl theorem natCast_val (n : β„•) : (n : β„€βˆšd) = ⟨n, 0⟩ := rfl @[simp] theorem intCast_re (n : β„€) : (n : β„€βˆšd).re = n := by cases n <;> rfl @[simp] theorem intCast_im (n : β„€) : (n : β„€βˆšd).im = 0 := by cases n <;> rfl theorem intCast_val (n : β„€) : (n : β„€βˆšd) = ⟨n, 0⟩ := by ext <;> simp instance : CharZero (β„€βˆšd) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : β„€) : (ofInt n : β„€βˆšd) = n := by ext <;> simp [ofInt_re, ofInt_im] @[simp] theorem nsmul_val (n : β„•) (x y : β„€) : (n : β„€βˆšd) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp @[simp] theorem smul_val (n x y : β„€) : (n : β„€βˆšd) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp theorem smul_re (a : β„€) (b : β„€βˆšd) : (↑a * b).re = a * b.re := by simp theorem smul_im (a : β„€) (b : β„€βˆšd) : (↑a * b).im = a * b.im := by simp @[simp] theorem muld_val (x y : β„€) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp @[simp] theorem smuld_val (n x y : β„€) : sqrtd * (n : β„€βˆšd) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp theorem decompose {x y : β„€} : (⟨x, y⟩ : β„€βˆšd) = x + sqrtd (d := d) * y := by ext <;> simp theorem mul_star {x y : β„€} : (⟨x, y⟩ * star ⟨x, y⟩ : β„€βˆšd) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] theorem intCast_dvd (z : β„€) (a : β„€βˆšd) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor Β· rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] Β· rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ @[simp, norm_cast] theorem intCast_dvd_intCast (a b : β„€) : (a : β„€βˆšd) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor Β· rintro ⟨hre, -⟩ rwa [intCast_re] at hre Β· rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ protected theorem eq_of_smul_eq_smul_left {a : β„€} {b c : β„€βˆšd} (ha : a β‰  0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊒ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancelβ‚€ ha section Gcd theorem gcd_eq_zero_iff (a : β„€βˆšd) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] theorem gcd_pos_iff (a : β„€βˆšd) : 0 < Int.gcd a.re a.im ↔ a β‰  0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff theorem isCoprime_of_dvd_isCoprime {a b : β„€βˆšd} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd Β· rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime Β· rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb @[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime theorem exists_coprime_of_gcd_pos {a : β„€βˆšd} (hgcd : 0 < Int.gcd a.re a.im) : βˆƒ b : β„€βˆšd, a = ((Int.gcd a.re a.im : β„€) : β„€βˆšd) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ Β· rw [smul_val, ← Hre, ← Him] Β· rw [Int.isCoprime_iff_gcd_eq_one, H1] end Gcd /-- Read `SqLe a c b d` as `a √c ≀ b √d` -/ def SqLe (a c b d : β„•) : Prop := c * a * a ≀ d * b * b theorem sqLe_of_le {c d x y z w : β„•} (xz : z ≀ x) (yw : y ≀ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) theorem sqLe_add_mixed {c d x y z w : β„•} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≀ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by simpa [mul_comm, mul_left_comm] using mul_le_mul xy zw (Nat.zero_le _) (Nat.zero_le _) theorem sqLe_add {c d x y z w : β„•} (xy : SqLe x c y d) (zw : SqLe z c w d) : SqLe (x + z) c (y + w) d := by have xz := sqLe_add_mixed xy zw simp? [SqLe, mul_assoc] at xy zw says simp only [SqLe, mul_assoc] at xy zw simp [SqLe, mul_add, mul_comm, mul_left_comm, add_le_add, *] theorem sqLe_cancel {c d x y z w : β„•} (zw : SqLe y d x c) (h : SqLe (x + z) c (y + w) d) : SqLe z c w d := by apply le_of_not_gt intro l refine not_le_of_gt ?_ h simp only [SqLe, mul_add, mul_comm, mul_left_comm, add_assoc, gt_iff_lt] have hm := sqLe_add_mixed zw (le_of_lt l) simp only [SqLe, mul_assoc, gt_iff_lt] at l zw exact lt_of_le_of_lt (add_le_add_right zw _) (add_lt_add_left (add_lt_add_of_le_of_lt hm (add_lt_add_of_le_of_lt hm l)) _) theorem sqLe_smul {c d x y : β„•} (n : β„•) (xy : SqLe x c y d) : SqLe (n * x) c (n * y) d := by simpa [SqLe, mul_left_comm, mul_assoc] using Nat.mul_le_mul_left (n * n) xy theorem sqLe_mul {d x y z w : β„•} : (SqLe x 1 y d β†’ SqLe z 1 w d β†’ SqLe (x * w + y * z) d (x * z + d * y * w) 1) ∧ (SqLe x 1 y d β†’ SqLe w d z 1 β†’ SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 β†’ SqLe z 1 w d β†’ SqLe (x * z + d * y * w) 1 (x * w + y * z) d) ∧ (SqLe y d x 1 β†’ SqLe w d z 1 β†’ SqLe (x * w + y * z) d (x * z + d * y * w) 1) := by refine ⟨?_, ?_, ?_, ?_⟩ <;> Β· intro xy zw have := Int.mul_nonneg (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le xy)) (sub_nonneg_of_le (Int.ofNat_le_ofNat_of_le zw)) refine Int.le_of_ofNat_le_ofNat (le_of_sub_nonneg ?_) convert this using 1 simp only [one_mul, Int.natCast_add, Int.natCast_mul] ring open Int in /-- "Generalized" `nonneg`. `nonnegg c d x y` means `a √c + b √d β‰₯ 0`; we are interested in the case `c = 1` but this is more symmetric -/ def Nonnegg (c d : β„•) : β„€ β†’ β„€ β†’ Prop | (a : β„•), (b : β„•) => True | (a : β„•), -[b+1] => SqLe (b + 1) c a d | -[a+1], (b : β„•) => SqLe (a + 1) d b c | -[_+1], -[_+1] => False theorem nonnegg_comm {c d : β„•} {x y : β„€} : Nonnegg c d x y = Nonnegg d c y x := by cases x <;> cases y <;> rfl theorem nonnegg_neg_pos {c d} : βˆ€ {a b : β„•}, Nonnegg c d (-a) b ↔ SqLe a d b c | 0, b => ⟨by simp [SqLe, Nat.zero_le], fun _ => trivial⟩ | a + 1, b => by rfl theorem nonnegg_pos_neg {c d} {a b : β„•} : Nonnegg c d a (-b) ↔ SqLe b c a d := by rw [nonnegg_comm]; exact nonnegg_neg_pos open Int in theorem nonnegg_cases_right {c d} {a : β„•} : βˆ€ {b : β„€}, (βˆ€ x : β„•, b = -x β†’ SqLe x c a d) β†’ Nonnegg c d a b | (b : Nat), _ => trivial | -[b+1], h => h (b + 1) rfl theorem nonnegg_cases_left {c d} {b : β„•} {a : β„€} (h : βˆ€ x : β„•, a = -x β†’ SqLe x d b c) : Nonnegg c d a b := cast nonnegg_comm (nonnegg_cases_right h) section Norm /-- The norm of an element of `β„€[√d]`. -/ def norm (n : β„€βˆšd) : β„€ := n.re * n.re - d * n.im * n.im theorem norm_def (n : β„€βˆšd) : n.norm = n.re * n.re - d * n.im * n.im := rfl @[simp] theorem norm_zero : norm (0 : β„€βˆšd) = 0 := by simp [norm] @[simp] theorem norm_one : norm (1 : β„€βˆšd) = 1 := by simp [norm] @[simp] theorem norm_intCast (n : β„€) : norm (n : β„€βˆšd) = n * n := by simp [norm] @[simp] theorem norm_natCast (n : β„•) : norm (n : β„€βˆšd) = n * n := norm_intCast n
@[simp] theorem norm_mul (n m : β„€βˆšd) : norm (n * m) = norm n * norm m := by simp only [norm, mul_im, mul_re] ring /-- `norm` as a `MonoidHom`. -/ def normMonoidHom : β„€βˆšd β†’* β„€ where toFun := norm map_mul' := norm_mul map_one' := norm_one theorem norm_eq_mul_conj (n : β„€βˆšd) : (norm n : β„€βˆšd) = n * star n := by ext <;> simp [norm, star, mul_comm, sub_eq_add_neg]
Mathlib/NumberTheory/Zsqrtd/Basic.lean
446
459
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Complex.Arg import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The complex `log` function Basic properties, relationship with `exp`. -/ noncomputable section namespace Complex open Set Filter Bornology open scoped Real Topology ComplexConjugate /-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο€` and `(log x).im ≀ Ο€`. `log 0 = 0` -/ @[pp_nodot] noncomputable def log (x : β„‚) : β„‚ := Real.log β€–xβ€– + arg x * I theorem log_re (x : β„‚) : x.log.re = Real.log β€–xβ€– := by simp [log] theorem log_im (x : β„‚) : x.log.im = x.arg := by simp [log] theorem neg_pi_lt_log_im (x : β„‚) : -Ο€ < (log x).im := by simp only [log_im, neg_pi_lt_arg] theorem log_im_le_pi (x : β„‚) : (log x).im ≀ Ο€ := by simp only [log_im, arg_le_pi] theorem exp_log {x : β„‚} (hx : x β‰  0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← ofReal_sin, sin_arg, ← ofReal_cos, cos_arg hx, ← ofReal_exp, Real.exp_log (norm_pos_iff.mpr hx), mul_add, ofReal_div, ofReal_div, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), ← mul_assoc, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), re_add_im] @[simp] theorem range_exp : Set.range exp = {0}ᢜ := Set.ext fun x => ⟨by rintro ⟨x, rfl⟩ exact exp_ne_zero x, fun hx => ⟨log x, exp_log hx⟩⟩ theorem log_exp {x : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) : log (exp x) = x := by rw [log, norm_exp, Real.log_exp, exp_eq_exp_re_mul_sin_add_cos, ← ofReal_exp, arg_mul_cos_add_sin_mul_I (Real.exp_pos _) ⟨hx₁, hxβ‚‚βŸ©, re_add_im] theorem exp_inj_of_neg_pi_lt_of_le_pi {x y : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) (hy₁ : -Ο€ < y.im) (hyβ‚‚ : y.im ≀ Ο€) (hxy : exp x = exp y) : x = y := by rw [← log_exp hx₁ hxβ‚‚, ← log_exp hy₁ hyβ‚‚, hxy] theorem ofReal_log {x : ℝ} (hx : 0 ≀ x) : (x.log : β„‚) = log x := Complex.ext (by rw [log_re, ofReal_re, Complex.norm_of_nonneg hx]) (by rw [ofReal_im, log_im, arg_ofReal_of_nonneg hx]) @[simp, norm_cast] lemma natCast_log {n : β„•} : Real.log n = log n := ofReal_natCast n β–Έ ofReal_log n.cast_nonneg @[simp] lemma ofNat_log {n : β„•} [n.AtLeastTwo] : Real.log ofNat(n) = log (OfNat.ofNat n) := natCast_log theorem log_ofReal_re (x : ℝ) : (log (x : β„‚)).re = Real.log x := by simp [log_re] theorem log_ofReal_mul {r : ℝ} (hr : 0 < r) {x : β„‚} (hx : x β‰  0) : log (r * x) = Real.log r + log x := by replace hx := norm_ne_zero_iff.mpr hx simp_rw [log, norm_mul, norm_real, arg_real_mul _ hr, Real.norm_of_nonneg hr.le, Real.log_mul hr.ne' hx, ofReal_add, add_assoc] theorem log_mul_ofReal (r : ℝ) (hr : 0 < r) (x : β„‚) (hx : x β‰  0) : log (x * r) = Real.log r + log x := by rw [mul_comm, log_ofReal_mul hr hx] lemma log_mul_eq_add_log_iff {x y : β„‚} (hxβ‚€ : x β‰  0) (hyβ‚€ : y β‰  0) : log (x * y) = log x + log y ↔ arg x + arg y ∈ Set.Ioc (-Ο€) Ο€ := by refine Complex.ext_iff.trans <| Iff.trans ?_ <| arg_mul_eq_add_arg_iff hxβ‚€ hyβ‚€ simp_rw [add_re, add_im, log_re, log_im, norm_mul, Real.log_mul (norm_ne_zero_iff.mpr hxβ‚€) (norm_ne_zero_iff.mpr hyβ‚€), true_and]
alias ⟨_, log_mul⟩ := log_mul_eq_add_log_iff @[simp] theorem log_zero : log 0 = 0 := by simp [log]
Mathlib/Analysis/SpecialFunctions/Complex/Log.lean
86
90
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Eric Wieser -/ import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.Deriv.Add /-! # Derivatives of polynomials In this file we prove that derivatives of polynomials in the analysis sense agree with their derivatives in the algebraic sense. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## TODO * Add results about multivariable polynomials. * Generalize some (most?) results to an algebra over the base field. ## Keywords derivative, polynomial -/ universe u open scoped Polynomial open ContinuousLinearMap (smulRight) variable {π•œ : Type u} [NontriviallyNormedField π•œ] {x : π•œ} {s : Set π•œ} namespace Polynomial /-! ### Derivative of a polynomial -/ variable {R : Type*} [CommSemiring R] [Algebra R π•œ] variable (p : π•œ[X]) (q : R[X]) /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasStrictDerivAt (x : π•œ) : HasStrictDerivAt (fun x => p.eval x) (p.derivative.eval x) x := by induction p using Polynomial.induction_on' with | add p q hp hq => simpa using hp.add hq | monomial n a => simpa [mul_assoc, derivative_monomial] using (hasStrictDerivAt_pow n x).const_mul a protected theorem hasStrictDerivAt_aeval (x : π•œ) : HasStrictDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := by simpa only [aeval_def, evalβ‚‚_eq_eval_map, derivative_map] using (q.map (algebraMap R π•œ)).hasStrictDerivAt x /-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/ protected theorem hasDerivAt (x : π•œ) : HasDerivAt (fun x => p.eval x) (p.derivative.eval x) x := (p.hasStrictDerivAt x).hasDerivAt protected theorem hasDerivAt_aeval (x : π•œ) : HasDerivAt (fun x => aeval x q) (aeval x (derivative q)) x := (q.hasStrictDerivAt_aeval x).hasDerivAt protected theorem hasDerivWithinAt (x : π•œ) (s : Set π•œ) : HasDerivWithinAt (fun x => p.eval x) (p.derivative.eval x) s x := (p.hasDerivAt x).hasDerivWithinAt protected theorem hasDerivWithinAt_aeval (x : π•œ) (s : Set π•œ) : HasDerivWithinAt (fun x => aeval x q) (aeval x (derivative q)) s x := (q.hasDerivAt_aeval x).hasDerivWithinAt protected theorem differentiableAt : DifferentiableAt π•œ (fun x => p.eval x) x := (p.hasDerivAt x).differentiableAt protected theorem differentiableAt_aeval : DifferentiableAt π•œ (fun x => aeval x q) x := (q.hasDerivAt_aeval x).differentiableAt protected theorem differentiableWithinAt : DifferentiableWithinAt π•œ (fun x => p.eval x) s x := p.differentiableAt.differentiableWithinAt protected theorem differentiableWithinAt_aeval : DifferentiableWithinAt π•œ (fun x => aeval x q) s x := q.differentiableAt_aeval.differentiableWithinAt protected theorem differentiable : Differentiable π•œ fun x => p.eval x := fun _ => p.differentiableAt protected theorem differentiable_aeval : Differentiable π•œ fun x : π•œ => aeval x q := fun _ => q.differentiableAt_aeval protected theorem differentiableOn : DifferentiableOn π•œ (fun x => p.eval x) s := p.differentiable.differentiableOn protected theorem differentiableOn_aeval : DifferentiableOn π•œ (fun x => aeval x q) s := q.differentiable_aeval.differentiableOn @[simp] protected theorem deriv : deriv (fun x => p.eval x) x = p.derivative.eval x := (p.hasDerivAt x).deriv @[simp] protected theorem deriv_aeval : deriv (fun x => aeval x q) x = aeval x (derivative q) := (q.hasDerivAt_aeval x).deriv protected theorem derivWithin (hxs : UniqueDiffWithinAt π•œ s x) : derivWithin (fun x => p.eval x) s x = p.derivative.eval x := by rw [DifferentiableAt.derivWithin p.differentiableAt hxs] exact p.deriv protected theorem derivWithin_aeval (hxs : UniqueDiffWithinAt π•œ s x) : derivWithin (fun x => aeval x q) s x = aeval x (derivative q) := by simpa only [aeval_def, evalβ‚‚_eq_eval_map, derivative_map] using (q.map (algebraMap R π•œ)).derivWithin hxs protected theorem hasFDerivAt (x : π•œ) : HasFDerivAt (fun x => p.eval x) (smulRight (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x)) x := p.hasDerivAt x protected theorem hasFDerivAt_aeval (x : π•œ) : HasFDerivAt (fun x => aeval x q) (smulRight (1 : π•œ β†’L[π•œ] π•œ) (aeval x (derivative q))) x := q.hasDerivAt_aeval x protected theorem hasFDerivWithinAt (x : π•œ) : HasFDerivWithinAt (fun x => p.eval x) (smulRight (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x)) s x := (p.hasFDerivAt x).hasFDerivWithinAt protected theorem hasFDerivWithinAt_aeval (x : π•œ) : HasFDerivWithinAt (fun x => aeval x q) (smulRight (1 : π•œ β†’L[π•œ] π•œ) (aeval x (derivative q))) s x := (q.hasFDerivAt_aeval x).hasFDerivWithinAt @[simp] protected theorem fderiv : fderiv π•œ (fun x => p.eval x) x = smulRight (1 : π•œ β†’L[π•œ] π•œ) (p.derivative.eval x) := (p.hasFDerivAt x).fderiv
@[simp] protected theorem fderiv_aeval : fderiv π•œ (fun x => aeval x q) x = smulRight (1 : π•œ β†’L[π•œ] π•œ) (aeval x (derivative q)) := (q.hasFDerivAt_aeval x).fderiv
Mathlib/Analysis/Calculus/Deriv/Polynomial.lean
140
143
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes HΓΆlzl, Sander Dahmen, Kim Morrison -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.LinearAlgebra.LinearIndependent.Basic import Mathlib.Data.Set.Card /-! # Dimension of modules and vector spaces ## Main definitions * The rank of a module is defined as `Module.rank : Cardinal`. This is defined as the supremum of the cardinalities of linearly independent subsets. ## Main statements * `LinearMap.rank_le_of_injective`: the source of an injective linear map has dimension at most that of the target. * `LinearMap.rank_le_of_surjective`: the target of a surjective linear map has dimension at most that of that source. ## Implementation notes Many theorems in this file are not universe-generic when they relate dimensions in different universes. They should be as general as they can be without inserting `lift`s. The types `M`, `M'`, ... all live in different universes, and `M₁`, `Mβ‚‚`, ... all live in the same universe. -/ noncomputable section universe w w' u u' v v' variable {R : Type u} {R' : Type u'} {M M₁ : Type v} {M' : Type v'} open Cardinal Submodule Function Set section Module section variable [Semiring R] [AddCommMonoid M] [Module R M] variable (R M) /-- The rank of a module, defined as a term of type `Cardinal`. We define this as the supremum of the cardinalities of linearly independent subsets. The supremum may not be attained, see https://mathoverflow.net/a/263053. For a free module over any ring satisfying the strong rank condition (e.g. left-noetherian rings, commutative rings, and in particular division rings and fields), this is the same as the dimension of the space (i.e. the cardinality of any basis). In particular this agrees with the usual notion of the dimension of a vector space. See also `Module.finrank` for a `β„•`-valued function which returns the correct value for a finite-dimensional vector space (but 0 for an infinite-dimensional vector space). -/ @[stacks 09G3 "first part"] protected irreducible_def Module.rank : Cardinal := ⨆ ΞΉ : { s : Set M // LinearIndepOn R id s }, (#ΞΉ.1) theorem rank_le_card : Module.rank R M ≀ #M := (Module.rank_def _ _).trans_le (ciSup_le' fun _ ↦ mk_set_le _) lemma nonempty_linearIndependent_set : Nonempty {s : Set M // LinearIndepOn R id s } := βŸ¨βŸ¨βˆ…, linearIndepOn_empty _ _⟩⟩ end namespace LinearIndependent variable [Semiring R] [AddCommMonoid M] [Module R M] variable [Nontrivial R] theorem cardinal_lift_le_rank {ΞΉ : Type w} {v : ΞΉ β†’ M} (hv : LinearIndependent R v) : Cardinal.lift.{v} #ΞΉ ≀ Cardinal.lift.{w} (Module.rank R M) := by rw [Module.rank] refine le_trans ?_ (lift_le.mpr <| le_ciSup (bddAbove_range _) ⟨_, hv.linearIndepOn_id⟩) exact lift_mk_le'.mpr ⟨(Equiv.ofInjective _ hv.injective).toEmbedding⟩ lemma aleph0_le_rank {ΞΉ : Type w} [Infinite ΞΉ] {v : ΞΉ β†’ M} (hv : LinearIndependent R v) : β„΅β‚€ ≀ Module.rank R M := aleph0_le_lift.mp <| (aleph0_le_lift.mpr <| aleph0_le_mk ΞΉ).trans hv.cardinal_lift_le_rank theorem cardinal_le_rank {ΞΉ : Type v} {v : ΞΉ β†’ M} (hv : LinearIndependent R v) : #ΞΉ ≀ Module.rank R M := by simpa using hv.cardinal_lift_le_rank theorem cardinal_le_rank' {s : Set M} (hs : LinearIndependent R (fun x => x : s β†’ M)) : #s ≀ Module.rank R M := hs.cardinal_le_rank theorem _root_.LinearIndepOn.encard_le_toENat_rank {ΞΉ : Type*} {v : ΞΉ β†’ M} {s : Set ΞΉ} (hs : LinearIndepOn R v s) : s.encard ≀ (Module.rank R M).toENat := by simpa using OrderHom.mono (Ξ² := β„•βˆž) Cardinal.toENat hs.linearIndependent.cardinal_lift_le_rank end LinearIndependent section SurjectiveInjective section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] section variable [AddCommMonoid M'] [Module R' M'] /-- If `M / R` and `M' / R'` are modules, `i : R' β†’ R` is an injective map non-zero elements, `j : M β†’+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_injective_injectiveβ‚› (i : R' β†’ R) (j : M β†’+ M') (hi : Injective i) (hj : Injective j) (hc : βˆ€ (r : R') (m : M), j (i r β€’ m) = r β€’ j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by simp_rw [Module.rank, lift_iSup (bddAbove_range _)] exact ciSup_mono' (bddAbove_range _) fun ⟨s, h⟩ ↦ ⟨⟨j '' s, LinearIndepOn.id_image (h.linearIndependent.map_of_injective_injectiveβ‚› i j hi hj hc)⟩, lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩ /-- If `M / R` and `M' / R'` are modules, `i : R β†’ R'` is a surjective map, and `j : M β†’+ M'` is an injective monoid homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_surjective_injective (i : R β†’ R') (j : M β†’+ M') (hi : Surjective i) (hj : Injective j) (hc : βˆ€ (r : R) (m : M), j (r β€’ m) = i r β€’ j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by obtain ⟨i', hi'⟩ := hi.hasRightInverse refine lift_rank_le_of_injective_injectiveβ‚› i' j (fun _ _ h ↦ ?_) hj fun r m ↦ ?_ Β· apply_fun i at h rwa [hi', hi'] at h rw [hc (i' r) m, hi'] /-- If `M / R` and `M' / R'` are modules, `i : R β†’ R'` is a bijective map which maps zero to zero, `j : M ≃+ M'` is a group isomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearEquiv.lift_rank_eq`. -/ theorem lift_rank_eq_of_equiv_equiv (i : R β†’ R') (j : M ≃+ M') (hi : Bijective i) (hc : βˆ€ (r : R) (m : M), j (r β€’ m) = i r β€’ j m) : lift.{v'} (Module.rank R M) = lift.{v} (Module.rank R' M') := (lift_rank_le_of_surjective_injective i j hi.2 j.injective hc).antisymm <| lift_rank_le_of_injective_injectiveβ‚› i j.symm hi.1 j.symm.injective fun _ _ ↦ j.symm_apply_eq.2 <| by erw [hc, j.apply_symm_apply] end section variable [AddCommMonoid M₁] [Module R' M₁] /-- The same-universe version of `lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injectiveβ‚› (i : R' β†’ R) (j : M β†’+ M₁) (hi : Injective i) (hj : Injective j) (hc : βˆ€ (r : R') (m : M), j (i r β€’ m) = r β€’ j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_injective_injectiveβ‚› i j hi hj hc /-- The same-universe version of `lift_rank_le_of_surjective_injective`. -/ theorem rank_le_of_surjective_injective (i : R β†’ R') (j : M β†’+ M₁) (hi : Surjective i) (hj : Injective j) (hc : βˆ€ (r : R) (m : M), j (r β€’ m) = i r β€’ j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc /-- The same-universe version of `lift_rank_eq_of_equiv_equiv`. -/ theorem rank_eq_of_equiv_equiv (i : R β†’ R') (j : M ≃+ M₁) (hi : Bijective i) (hc : βˆ€ (r : R) (m : M), j (r β€’ m) = i r β€’ j m) : Module.rank R M = Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hi hc end end Semiring section Ring variable [Ring R] [AddCommGroup M] [Module R M] [Ring R'] /-- If `M / R` and `M' / R'` are modules, `i : R' β†’ R` is a map which sends non-zero elements to non-zero elements, `j : M β†’+ M'` is an injective group homomorphism, such that the scalar multiplications on `M` and `M'` are compatible, then the rank of `M / R` is smaller than or equal to the rank of `M' / R'`. As a special case, taking `R = R'` it is `LinearMap.lift_rank_le_of_injective`. -/ theorem lift_rank_le_of_injective_injective [AddCommGroup M'] [Module R' M'] (i : R' β†’ R) (j : M β†’+ M') (hi : βˆ€ r, i r = 0 β†’ r = 0) (hj : Injective j) (hc : βˆ€ (r : R') (m : M), j (i r β€’ m) = r β€’ j m) : lift.{v'} (Module.rank R M) ≀ lift.{v} (Module.rank R' M') := by simp_rw [Module.rank, lift_iSup (bddAbove_range _)] exact ciSup_mono' (bddAbove_range _) fun ⟨s, h⟩ ↦ ⟨⟨j '' s, LinearIndepOn.id_image <| h.linearIndependent.map_of_injective_injective i j hi (fun _ _ ↦ hj <| by rwa [j.map_zero]) hc⟩, lift_mk_le'.mpr ⟨(Equiv.Set.image j s hj).toEmbedding⟩⟩ /-- The same-universe version of `lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injective [AddCommGroup M₁] [Module R' M₁] (i : R' β†’ R) (j : M β†’+ M₁) (hi : βˆ€ r, i r = 0 β†’ r = 0) (hj : Injective j) (hc : βˆ€ (r : R') (m : M), j (i r β€’ m) = r β€’ j m) : Module.rank R M ≀ Module.rank R' M₁ := by simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc end Ring namespace Algebra variable {R : Type w} {S : Type v} [CommSemiring R] [Semiring S] [Algebra R S] {R' : Type w'} {S' : Type v'} [CommSemiring R'] [Semiring S'] [Algebra R' S'] /-- If `S / R` and `S' / R'` are algebras, `i : R' β†’+* R` and `j : S β†’+* S'` are injective ring homomorphisms, such that `R' β†’ R β†’ S β†’ S'` and `R' β†’ S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_injective_injective (i : R' β†’+* R) (j : S β†’+* S') (hi : Injective i) (hj : Injective j) (hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') : lift.{v'} (Module.rank R S) ≀ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_injective_injectiveβ‚› i j hi hj fun r _ ↦ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp_rw [smul_def, AddMonoidHom.coe_coe, map_mul, this] /-- If `S / R` and `S' / R'` are algebras, `i : R β†’+* R'` is a surjective ring homomorphism, `j : S β†’+* S'` is an injective ring homomorphism, such that `R β†’ R' β†’ S'` and `R β†’ S β†’ S'` commute, then the rank of `S / R` is smaller than or equal to the rank of `S' / R'`. -/ theorem lift_rank_le_of_surjective_injective (i : R β†’+* R') (j : S β†’+* S') (hi : Surjective i) (hj : Injective j) (hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) : lift.{v'} (Module.rank R S) ≀ lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_le_of_surjective_injective i j hi hj fun r _ ↦ ?_ have := congr($hc r) simp only [RingHom.coe_comp, comp_apply] at this simp only [smul_def, AddMonoidHom.coe_coe, map_mul, ZeroHom.coe_coe, this] /-- If `S / R` and `S' / R'` are algebras, `i : R ≃+* R'` and `j : S ≃+* S'` are ring isomorphisms, such that `R β†’ R' β†’ S'` and `R β†’ S β†’ S'` commute, then the rank of `S / R` is equal to the rank of `S' / R'`. -/ theorem lift_rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S') (hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) : lift.{v'} (Module.rank R S) = lift.{v} (Module.rank R' S') := by refine _root_.lift_rank_eq_of_equiv_equiv i j i.bijective fun r _ ↦ ?_ have := congr($hc r) simp only [RingEquiv.toRingHom_eq_coe, RingHom.coe_comp, RingHom.coe_coe, comp_apply] at this simp only [smul_def, RingEquiv.coe_toAddEquiv, map_mul, ZeroHom.coe_coe, this] variable {S' : Type v} [Semiring S'] [Algebra R' S'] /-- The same-universe version of `Algebra.lift_rank_le_of_injective_injective`. -/ theorem rank_le_of_injective_injective (i : R' β†’+* R) (j : S β†’+* S') (hi : Injective i) (hj : Injective j) (hc : (j.comp (algebraMap R S)).comp i = algebraMap R' S') : Module.rank R S ≀ Module.rank R' S' := by simpa only [lift_id] using lift_rank_le_of_injective_injective i j hi hj hc /-- The same-universe version of `Algebra.lift_rank_le_of_surjective_injective`. -/ theorem rank_le_of_surjective_injective (i : R β†’+* R') (j : S β†’+* S') (hi : Surjective i) (hj : Injective j) (hc : (algebraMap R' S').comp i = j.comp (algebraMap R S)) : Module.rank R S ≀ Module.rank R' S' := by simpa only [lift_id] using lift_rank_le_of_surjective_injective i j hi hj hc /-- The same-universe version of `Algebra.lift_rank_eq_of_equiv_equiv`. -/ theorem rank_eq_of_equiv_equiv (i : R ≃+* R') (j : S ≃+* S') (hc : (algebraMap R' S').comp i.toRingHom = j.toRingHom.comp (algebraMap R S)) : Module.rank R S = Module.rank R' S' := by simpa only [lift_id] using lift_rank_eq_of_equiv_equiv i j hc end Algebra end SurjectiveInjective variable [Semiring R] [AddCommMonoid M] [Module R M] [Semiring R'] [AddCommMonoid M'] [AddCommMonoid M₁] [Module R M'] [Module R M₁] [Module R' M'] [Module R' M₁] section theorem LinearMap.lift_rank_le_of_injective (f : M β†’β‚—[R] M') (i : Injective f) :
Cardinal.lift.{v'} (Module.rank R M) ≀ Cardinal.lift.{v} (Module.rank R M') := lift_rank_le_of_injective_injectiveβ‚› (RingHom.id R) f (fun _ _ h ↦ h) i f.map_smul theorem LinearMap.rank_le_of_injective (f : M β†’β‚—[R] M₁) (i : Injective f) :
Mathlib/LinearAlgebra/Dimension/Basic.lean
278
281
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta HernΓ‘ndez Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.FixedPoint /-! # Cofinality This file contains the definition of cofinality of an order and an ordinal number. ## Main Definitions * `Order.cof r` is the cofinality of a reflexive order. This is the smallest cardinality of a subset `s` that is *cofinal*, i.e. `βˆ€ x, βˆƒ y ∈ s, r x y`. * `Ordinal.cof o` is the cofinality of the ordinal `o` when viewed as a linear order. ## Main Statements * `Cardinal.lt_power_cof`: A consequence of KΓΆnig's theorem stating that `c < c ^ c.ord.cof` for `c β‰₯ β„΅β‚€`. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. -/ noncomputable section open Function Cardinal Set Order open scoped Ordinal universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {r : Ξ± β†’ Ξ± β†’ Prop} {s : Ξ² β†’ Ξ² β†’ Prop} /-! ### Cofinality of orders -/ attribute [local instance] IsRefl.swap namespace Order /-- Cofinality of a reflexive order `β‰Ό`. This is the smallest cardinality of a subset `S : Set Ξ±` such that `βˆ€ a, βˆƒ b ∈ S, a β‰Ό b`. -/ def cof (r : Ξ± β†’ Ξ± β†’ Prop) : Cardinal := sInf { c | βˆƒ S : Set Ξ±, (βˆ€ a, βˆƒ b ∈ S, r a b) ∧ #S = c } /-- The set in the definition of `Order.cof` is nonempty. -/ private theorem cof_nonempty (r : Ξ± β†’ Ξ± β†’ Prop) [IsRefl Ξ± r] : { c | βˆƒ S : Set Ξ±, (βˆ€ a, βˆƒ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ theorem cof_le (r : Ξ± β†’ Ξ± β†’ Prop) {S : Set Ξ±} (h : βˆ€ a, βˆƒ b ∈ S, r a b) : cof r ≀ #S := csInf_le' ⟨S, h, rfl⟩ theorem le_cof [IsRefl Ξ± r] (c : Cardinal) : c ≀ cof r ↔ βˆ€ {S : Set Ξ±}, (βˆ€ a, βˆƒ b ∈ S, r a b) β†’ c ≀ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h end Order namespace RelIso private theorem cof_le_lift [IsRefl Ξ² s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) ≀ Cardinal.lift.{u} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq'.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] theorem cof_eq_lift [IsRefl Ξ² s] (f : r ≃r s) : Cardinal.lift.{v} (Order.cof r) = Cardinal.lift.{u} (Order.cof s) := have := f.toRelEmbedding.isRefl (f.cof_le_lift).antisymm (f.symm.cof_le_lift) theorem cof_eq {Ξ± Ξ² : Type u} {r : Ξ± β†’ Ξ± β†’ Prop} {s} [IsRefl Ξ² s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (f.cof_eq_lift) end RelIso /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `βˆ€ a, βˆƒ b ∈ S, a ≀ b`. In particular, `cof 0 = 0` and `cof (succ o) = 1`. -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a ↦ Order.cof (swap a.rᢜ)) fun _ _ ⟨f⟩ ↦ f.compl.swap.cof_eq theorem cof_type (r : Ξ± β†’ Ξ± β†’ Prop) [IsWellOrder Ξ± r] : (type r).cof = Order.cof (swap rᢜ) := rfl theorem cof_type_lt [LinearOrder Ξ±] [IsWellOrder Ξ± (Β· < Β·)] : (@type Ξ± (Β· < Β·) _).cof = @Order.cof Ξ± (Β· ≀ Β·) := by rw [cof_type, compl_lt, swap_ge] theorem cof_eq_cof_toType (o : Ordinal) : o.cof = @Order.cof o.toType (Β· ≀ Β·) := by conv_lhs => rw [← type_toType o, cof_type_lt] theorem le_cof_type [IsWellOrder Ξ± r] {c} : c ≀ cof (type r) ↔ βˆ€ S, Unbounded r S β†’ c ≀ #S := (le_csInf_iff'' (Order.cof_nonempty _)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ theorem cof_type_le [IsWellOrder Ξ± r] {S : Set Ξ±} (h : Unbounded r S) : cof (type r) ≀ #S := le_cof_type.1 le_rfl S h theorem lt_cof_type [IsWellOrder Ξ± r] {S : Set Ξ±} : #S < cof (type r) β†’ Bounded r S := by simpa using not_imp_not.2 cof_type_le theorem cof_eq (r : Ξ± β†’ Ξ± β†’ Prop) [IsWellOrder Ξ± r] : βˆƒ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (Order.cof_nonempty (swap rᢜ)) theorem ord_cof_eq (r : Ξ± β†’ Ξ± β†’ Prop) [IsWellOrder Ξ± r] : βˆƒ S, Unbounded r S ∧ type (Subrel r (Β· ∈ S)) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set Ξ± := { a | βˆƒ aS : a ∈ S, βˆ€ b : S, s b ⟨_, aS⟩ β†’ r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ Β· exact asymm h (ha _ hn) Β· intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | Β¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : Β¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show βˆ€ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : βˆƒ (ΞΉ : _) (f : ΞΉ β†’ Ordinal), lsub.{u, u} f = o ∧ #ΞΉ = o.card := ⟨_, _, lsub_typein o, mk_toType o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | βˆƒ (ΞΉ : _) (f : ΞΉ β†’ Ordinal), lsub.{u, u} f = o ∧ #ΞΉ = a }.Nonempty := ⟨_, card_mem_cof⟩ theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | βˆƒ (ΞΉ : Type u) (f : ΞΉ β†’ Ordinal), lsub.{u, u} f = o ∧ #ΞΉ = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) Β· rintro a ⟨ι, f, hf, rfl⟩ rw [← type_toType o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((Β· < Β·) : o.toType β†’ o.toType β†’ Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this obtain ⟨i, hi⟩ := this refine ⟨enum (Ξ± := o.toType) (Β· < Β·) ⟨f i, ?_⟩, ?_, ?_⟩ Β· rw [type_toType, ← hf] apply lt_lsub Β· rw [mem_preimage, typein_enum] exact mem_range_self i Β· rwa [← typein_le_typein, typein_enum] Β· rcases cof_eq (Ξ± := o.toType) (Β· < Β·) with ⟨S, hS, hS'⟩ let f : S β†’ Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_toType o] at hS'⟩ rw [← type_toType o] at ha rcases hS (enum (Β· < Β·) ⟨a, ha⟩) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o fun Ξ± r _ ↦ ?_ rw [← type_uLift, cof_type, cof_type, ← Cardinal.lift_id'.{v, u} (Order.cof _), ← Cardinal.lift_umax] apply RelIso.cof_eq_lift ⟨Equiv.ulift.symm, _⟩ simp [swap] theorem cof_le_card (o) : cof o ≀ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof theorem cof_ord_le (c : Cardinal) : c.ord.cof ≀ c := by simpa using cof_le_card c.ord theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≀ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) theorem exists_lsub_cof (o : Ordinal) : βˆƒ (ΞΉ : _) (f : ΞΉ β†’ Ordinal), lsub.{u, u} f = o ∧ #ΞΉ = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) theorem cof_lsub_le {ΞΉ} (f : ΞΉ β†’ Ordinal) : cof (lsub.{u, u} f) ≀ #ΞΉ := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ theorem cof_lsub_le_lift {ΞΉ} (f : ΞΉ β†’ Ordinal) : cof (lsub.{u, v} f) ≀ Cardinal.lift.{v, u} #ΞΉ := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ΞΉ => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≀ cof o ↔ βˆ€ {ΞΉ} (f : ΞΉ β†’ Ordinal), lsub.{u, u} f = o β†’ a ≀ #ΞΉ := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ΞΉ f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ theorem lsub_lt_ord_lift {ΞΉ} {f : ΞΉ β†’ Ordinal} {c : Ordinal} (hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.cof) (hf : βˆ€ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hΞΉ theorem lsub_lt_ord {ΞΉ} {f : ΞΉ β†’ Ordinal} {c : Ordinal} (hΞΉ : #ΞΉ < c.cof) : (βˆ€ i, f i < c) β†’ lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ΞΉ).lift_id]) theorem cof_iSup_le_lift {ΞΉ} {f : ΞΉ β†’ Ordinal} (H : βˆ€ i, f i < iSup f) : cof (iSup f) ≀ Cardinal.lift.{v, u} #ΞΉ := by rw [← Ordinal.sup] at * rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f theorem cof_iSup_le {ΞΉ} {f : ΞΉ β†’ Ordinal} (H : βˆ€ i, f i < iSup f) : cof (iSup f) ≀ #ΞΉ := by rw [← (#ΞΉ).lift_id] exact cof_iSup_le_lift H theorem iSup_lt_ord_lift {ΞΉ} {f : ΞΉ β†’ Ordinal} {c : Ordinal} (hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.cof) (hf : βˆ€ i, f i < c) : iSup f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hΞΉ hf) theorem iSup_lt_ord {ΞΉ} {f : ΞΉ β†’ Ordinal} {c : Ordinal} (hΞΉ : #ΞΉ < c.cof) : (βˆ€ i, f i < c) β†’ iSup f < c := iSup_lt_ord_lift (by rwa [(#ΞΉ).lift_id]) theorem iSup_lt_lift {ΞΉ} {f : ΞΉ β†’ Cardinal} {c : Cardinal} (hΞΉ : Cardinal.lift.{v, u} #ΞΉ < c.ord.cof) (hf : βˆ€ i, f i < c) : iSup f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range _)] refine iSup_lt_ord_lift hΞΉ fun i => ?_ rw [ord_lt_ord] apply hf theorem iSup_lt {ΞΉ} {f : ΞΉ β†’ Cardinal} {c : Cardinal} (hΞΉ : #ΞΉ < c.ord.cof) : (βˆ€ i, f i < c) β†’ iSup f < c := iSup_lt_lift (by rwa [(#ΞΉ).lift_id]) theorem nfpFamily_lt_ord_lift {ΞΉ} {f : ΞΉ β†’ Ordinal β†’ Ordinal} {c} (hc : β„΅β‚€ < cof c) (hc' : Cardinal.lift.{v, u} #ΞΉ < cof c) (hf : βˆ€ (i), βˆ€ b < c, f i b < c) {a} (ha : a < c) : nfpFamily f a < c := by refine iSup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ΞΉ)).trans_lt ?_) fun l => ?_ Β· rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] Β· induction' l with i l H Β· exact ha Β· exact hf _ _ H theorem nfpFamily_lt_ord {ΞΉ} {f : ΞΉ β†’ Ordinal β†’ Ordinal} {c} (hc : β„΅β‚€ < cof c) (hc' : #ΞΉ < cof c) (hf : βˆ€ (i), βˆ€ b < c, f i b < c) {a} : a < c β†’ nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ΞΉ).lift_id]) hf theorem nfp_lt_ord {f : Ordinal β†’ Ordinal} {c} (hc : β„΅β‚€ < cof c) (hf : βˆ€ i < c, f i < c) {a} : a < c β†’ nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf theorem exists_blsub_cof (o : Ordinal) : βˆƒ f : βˆ€ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ΞΉ with ⟨r, hr, hΞΉ'⟩ rw [← @blsub_eq_lsub' ΞΉ r hr] at hf rw [← hΞΉ, hΞΉ'] exact ⟨_, hf⟩ theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≀ cof b ↔ βˆ€ {o} (f : βˆ€ a < o, Ordinal), blsub.{u, u} o f = b β†’ a ≀ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ΞΉ f hf => by rcases Cardinal.ord_eq ΞΉ with ⟨r, hr, hΞΉ'⟩ rw [← @blsub_eq_lsub' ΞΉ r hr] at hf simpa using H _ hf⟩ theorem cof_blsub_le_lift {o} (f : βˆ€ a < o, Ordinal) : cof (blsub.{u, v} o f) ≀ Cardinal.lift.{v, u} o.card := by rw [← mk_toType o] exact cof_lsub_le_lift _ theorem cof_blsub_le {o} (f : βˆ€ a < o, Ordinal) : cof (blsub.{u, u} o f) ≀ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : βˆ€ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : βˆ€ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) theorem blsub_lt_ord {o : Ordinal} {f : βˆ€ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : βˆ€ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf theorem cof_bsup_le_lift {o : Ordinal} {f : βˆ€ a < o, Ordinal} (H : βˆ€ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≀ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f theorem cof_bsup_le {o : Ordinal} {f : βˆ€ a < o, Ordinal} : (βˆ€ i h, f i h < bsup.{u, u} o f) β†’ cof (bsup.{u, u} o f) ≀ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift theorem bsup_lt_ord_lift {o : Ordinal} {f : βˆ€ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : βˆ€ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) theorem bsup_lt_ord {o : Ordinal} {f : βˆ€ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (βˆ€ i hi, f i hi < c) β†’ bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun _ r _ z => let ⟨_, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨_, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ theorem cof_ne_zero {o} : cof o β‰  0 ↔ o β‰  0 := cof_eq_zero.not @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm Β· refine inductionOn o fun Ξ± r _ => ?_ change cof (type _) ≀ _ rw [← (_ : #_ = 1)] Β· apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] Β· rw [Cardinal.mk_fintype, Set.card_singleton] simp Β· rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ βˆƒ a, o = succ a := ⟨inductionOn o fun Ξ± r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e obtain ⟨a⟩ := mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ Β· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] Β· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 Β· suffices r x a ∨ βˆƒ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) Β· exact Or.inl h Β· exact Or.inr ⟨PUnit.unit, h.symm⟩ Β· rcases hl x with ⟨a', aS, hn⟩ refine absurd h ?_ convert hn change (a : Ξ±) = ↑(⟨a', aS⟩ : S) have := le_one_iff_subsingleton.1 (le_of_eq e) congr!, fun ⟨a, e⟩ => by simp [e]⟩ /-! ### Fundamental sequences -/ -- TODO: move stuff about fundamental sequences to their own file. /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : βˆ€ b < o, Ordinal.{u}) : Prop := o ≀ a.cof.ord ∧ (βˆ€ {i j} (hi hj), i < j β†’ f i hi < f j hj) ∧ blsub.{u, u} o f = a namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : βˆ€ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : βˆ€ hi hj, i < j β†’ f i hi < f j hj := hf.2.1 theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf theorem id_of_le_cof (h : o ≀ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ protected theorem zero {f : βˆ€ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i _ hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ Β· rw [cof_succ, ord_one] Β· rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≀ j) : f i hi ≀ f j hj := by rcases lt_or_eq_of_le hij with (hij | rfl) Β· exact (hf.2.1 hi hj hij).le Β· rfl theorem trans {a o o' : Ordinal.{u}} {f : βˆ€ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f) {g : βˆ€ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) : IsFundamentalSequence a o' fun i hi => f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩ Β· rw [hf.cof_eq] exact hg.1.trans (ord_cof_le o) Β· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)] Β· exact hf.2.2 Β· exact hg.2.2 protected theorem lt {a o : Ordinal} {s : Ξ  p < o, Ordinal} (h : IsFundamentalSequence a o s) {p : Ordinal} (hp : p < o) : s p hp < a := h.blsub_eq β–Έ lt_blsub s p hp end IsFundamentalSequence /-- Every ordinal has a fundamental sequence. -/ theorem exists_fundamental_sequence (a : Ordinal.{u}) : βˆƒ f, IsFundamentalSequence a a.cof.ord f := by suffices h : βˆƒ o f, IsFundamentalSequence a o f by rcases h with ⟨o, f, hf⟩ exact ⟨_, hf.ord_cof⟩ rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩ rcases ord_eq ΞΉ with ⟨r, wo, hr⟩ haveI := wo let r' := Subrel r fun i ↦ βˆ€ j, r j i β†’ f j < f i let hrr' : r' β†ͺr r := Subrel.relEmbedding _ _ haveI := hrr'.isWellOrder refine ⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' ⟨j, h⟩).prop _ ?_, le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩ Β· rw [← hΞΉ, hr] Β· change r (hrr'.1 _) (hrr'.1 _) rwa [hrr'.2, @enum_lt_enum _ r'] Β· rw [← hf, lsub_le_iff] intro i suffices h : βˆƒ i' hi', f i ≀ bfamilyOfFamily' r' (fun i => f i) i' hi' by rcases h with ⟨i', hi', hfg⟩ exact hfg.trans_lt (lt_blsub _ _ _) by_cases h : βˆ€ j, r j i β†’ f j < f i Β· refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩ rw [bfamilyOfFamily'_typein] Β· push_neg at h obtain ⟨hji, hij⟩ := wo.wf.min_mem _ h refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩ Β· by_contra! H exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj Β· rwa [bfamilyOfFamily'_typein] @[simp] theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by obtain ⟨f, hf⟩ := exists_fundamental_sequence a obtain ⟨g, hg⟩ := exists_fundamental_sequence a.cof.ord exact ord_injective (hf.trans hg).cof_eq.symm protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} β†’ Ordinal.{u}} (hf : IsNormal f) {a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) : IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩ Β· rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩ rw [← hg.cof_eq, ord_le_ord, ← hΞΉ] suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≀ f b }) = a by rw [← this] apply cof_lsub_le have H : βˆ€ i, βˆƒ b < a, f' i ≀ f b := fun i => by have := lt_lsub.{u, u} f' i rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this simpa using this refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_) Β· rcases H i with ⟨b, hb, hb'⟩ exact lt_of_le_of_lt (csInf_le' hb') hb Β· have := hf.strictMono hb rw [← hf', lt_lsub_iff] at this obtain ⟨i, hi⟩ := this rcases H i with ⟨b, _, hb⟩ exact ((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc => hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i) Β· rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g hg.2.2] exact IsNormal.blsub_eq.{u, u} hf ha theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a := let ⟨_, hg⟩ := exists_fundamental_sequence a ord_injective (hf.isFundamentalSequence ha hg).cof_eq theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≀ cof (f a) := by rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha) Β· rw [cof_zero] exact zero_le _ Β· rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero] exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b) Β· rw [hf.cof_eq ha] @[simp] theorem cof_add (a b : Ordinal) : b β‰  0 β†’ cof (a + b) = cof b := fun h => by rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) Β· contradiction Β· rw [add_succ, cof_succ, cof_succ] Β· exact (isNormal_add_right a).cof_eq hb theorem aleph0_le_cof {o} : β„΅β‚€ ≀ cof o ↔ IsLimit o := by rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l)
Β· simp [not_zero_isLimit, Cardinal.aleph0_ne_zero] Β· simp [not_succ_isLimit, Cardinal.one_lt_aleph0]
Mathlib/SetTheory/Cardinal/Cofinality.lean
580
581
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Tape import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.PFun import Mathlib.Computability.PostTuringMachine /-! # Turing machines The files `PostTuringMachine.lean` and `TuringMachine.lean` define a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. `PostTuringMachine.lean` covers the TM0 model and TM1 model; `TuringMachine.lean` adds the TM2 model. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Ξ“` is the alphabet on the tape. * `Ξ›` is the set of labels, or internal machine states. * `Οƒ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Ξ›`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Ξ› β†’ Stmt`, although different models have different ways of halting and other actions. * `step : Cfg β†’ Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input β†’ Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Ξ“`. * `eval : Machine β†’ Input β†’ Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg β†’ Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine β†’ Finset Ξ› β†’ Prop` asserts that a machine `M` starts in `S : Finset Ξ›`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Ξ›` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open List (Vector) open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-! ## The TM2 model The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks, each with elements of different types (the alphabet of stack `k : K` is `Ξ“ k`). The statements are: * `push k (f : Οƒ β†’ Ξ“ k) q` puts `f a` on the `k`-th stack, then does `q`. * `pop k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, and removes this element from the stack, then does `q`. * `peek k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, then does `q`. * `load (f : Οƒ β†’ Οƒ) q` reads nothing but applies `f` to the internal state, then does `q`. * `branch (f : Οƒ β†’ Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`. * `goto (f : Οƒ β†’ Ξ›)` jumps to label `f a`. * `halt` halts on the next step. The configuration is a tuple `(l, var, stk)` where `l : Option Ξ›` is the current label to run or `none` for the halting state, `var : Οƒ` is the (finite) internal state, and `stk : βˆ€ k, List (Ξ“ k)` is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not `ListBlank`s, they have definite ends that can be detected by the `pop` command.) Given a designated stack `k` and a value `L : List (Ξ“ k)`, the initial configuration has all the stacks empty except the designated "input" stack; in `eval` this designated stack also functions as the output stack. -/ namespace TM2 variable {K : Type*} -- Index type of stacks variable (Ξ“ : K β†’ Type*) -- Type of stack elements variable (Ξ› : Type*) -- Type of function labels variable (Οƒ : Type*) -- Type of variable settings /-- The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks. The operation `push` puts an element on one of the stacks, and `pop` removes an element from a stack (and modifying the internal state based on the result). `peek` modifies the internal state but does not remove an element. -/ inductive Stmt | push : βˆ€ k, (Οƒ β†’ Ξ“ k) β†’ Stmt β†’ Stmt | peek : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | pop : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | load : (Οƒ β†’ Οƒ) β†’ Stmt β†’ Stmt | branch : (Οƒ β†’ Bool) β†’ Stmt β†’ Stmt β†’ Stmt | goto : (Οƒ β†’ Ξ›) β†’ Stmt | halt : Stmt open Stmt instance Stmt.inhabited : Inhabited (Stmt Ξ“ Ξ› Οƒ) := ⟨halt⟩ /-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite size.) -/ structure Cfg where /-- The current label to run (or `none` for the halting state) -/ l : Option Ξ› /-- The internal state -/ var : Οƒ /-- The (finite) collection of internal stacks -/ stk : βˆ€ k, List (Ξ“ k) instance Cfg.inhabited [Inhabited Οƒ] : Inhabited (Cfg Ξ“ Ξ› Οƒ) := ⟨⟨default, default, default⟩⟩ variable {Ξ“ Ξ› Οƒ} section variable [DecidableEq K] /-- The step function for the TM2 model. -/ def stepAux : Stmt Ξ“ Ξ› Οƒ β†’ Οƒ β†’ (βˆ€ k, List (Ξ“ k)) β†’ Cfg Ξ“ Ξ› Οƒ | push k f q, v, S => stepAux q v (update S k (f v :: S k)) | peek k f q, v, S => stepAux q (f v (S k).head?) S | pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail) | load a q, v, S => stepAux q (a v) S | branch f q₁ qβ‚‚, v, S => cond (f v) (stepAux q₁ v S) (stepAux qβ‚‚ v S) | goto f, v, S => ⟨some (f v), v, S⟩ | halt, v, S => ⟨none, v, S⟩ /-- The step function for the TM2 model. -/ def step (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Option (Cfg Ξ“ Ξ› Οƒ) | ⟨none, _, _⟩ => none | ⟨some l, v, S⟩ => some (stepAux (M l) v S) attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3 stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 /-- The (reflexive) reachability relation for the TM2 model. -/ def Reaches (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Cfg Ξ“ Ξ› Οƒ β†’ Prop := ReflTransGen fun a b ↦ b ∈ step M a end /-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/ def SupportsStmt (S : Finset Ξ›) : Stmt Ξ“ Ξ› Οƒ β†’ Prop | push _ _ q => SupportsStmt S q | peek _ _ q => SupportsStmt S q | pop _ _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ qβ‚‚ => SupportsStmt S q₁ ∧ SupportsStmt S qβ‚‚ | goto l => βˆ€ v, l v ∈ S | halt => True section open scoped Classical in /-- The set of subtree statements in a statement. -/ noncomputable def stmts₁ : Stmt Ξ“ Ξ› Οƒ β†’ Finset (Stmt Ξ“ Ξ› Οƒ) | Q@(push _ _ q) => insert Q (stmts₁ q) | Q@(peek _ _ q) => insert Q (stmts₁ q) | Q@(pop _ _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ qβ‚‚) => insert Q (stmts₁ q₁ βˆͺ stmts₁ qβ‚‚) | Q@(goto _) => {Q} | Q@halt => {Q} theorem stmts₁_self {q : Stmt Ξ“ Ξ› Οƒ} : q ∈ stmts₁ q := by cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] theorem stmts₁_trans {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} : q₁ ∈ stmts₁ qβ‚‚ β†’ stmts₁ q₁ βŠ† stmts₁ qβ‚‚ := by classical intro h₁₂ qβ‚€ h₀₁ induction qβ‚‚ with ( simp only [stmts₁] at h₁₂ ⊒ simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂) | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂)) Β· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IHβ‚‚ h₁₂)) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | load _ q IH | _ _ _ q IH => rcases h₁₂ with (rfl | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (IH h₁₂) theorem stmts₁_supportsStmt_mono {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h : q₁ ∈ stmts₁ qβ‚‚) (hs : SupportsStmt S qβ‚‚) : SupportsStmt S q₁ := by induction qβ‚‚ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IHβ‚‚ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] open scoped Classical in /-- The set of statements accessible from initial set `S` of labels. -/ noncomputable def stmts (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) : Finset (Option (Stmt Ξ“ Ξ› Οƒ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) theorem stmts_trans {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h₁ : q₁ ∈ stmts₁ qβ‚‚) : some qβ‚‚ ∈ stmts M S β†’ some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls hβ‚‚ ↦ ⟨_, ls, stmts₁_trans hβ‚‚ hβ‚βŸ© end variable [Inhabited Ξ›] /-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in `S` jump only to other states in `S`. -/ def Supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) := default ∈ S ∧ βˆ€ q ∈ S, SupportsStmt S (M q) theorem stmts_supportsStmt {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q : Stmt Ξ“ Ξ› Οƒ} (ss : Supports M S) : some q ∈ stmts M S β†’ SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) variable [DecidableEq K] theorem step_supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) {S : Finset Ξ›} (ss : Supports M S) : βˆ€ {c c' : Cfg Ξ“ Ξ› Οƒ}, c' ∈ step M c β†’ c.l ∈ Finset.insertNone S β†’ c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, hβ‚‚ => by replace hβ‚‚ := ss.2 _ (Finset.some_mem_insertNone.1 hβ‚‚) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert hβ‚‚; induction M l₁ generalizing v T with intro hs | branch p q₁' qβ‚‚' IH₁ IHβ‚‚ => unfold stepAux; cases p v Β· exact IHβ‚‚ _ _ hs.2 Β· exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _) | halt => apply Multiset.mem_cons_self | load _ _ IH | _ _ _ _ IH => exact IH _ _ hs variable [Inhabited Οƒ] /-- The initial state of the TM2 model. The input is provided on a designated stack. -/ def init (k : K) (L : List (Ξ“ k)) : Cfg Ξ“ Ξ› Οƒ := ⟨some default, default, update (fun _ ↦ []) k L⟩ /-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/ def eval (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (k : K) (L : List (Ξ“ k)) : Part (List (Ξ“ k)) := (Turing.eval (step M) (init k L)).map fun c ↦ c.stk k end TM2 /-! ## TM2 emulator in TM1 To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack 1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this: ``` bottom: ... | _ | T | _ | _ | _ | _ | ... stack 1: ... | _ | b | a | _ | _ | _ | ... stack 2: ... | _ | f | e | d | c | _ | ... ``` where a tape element is a vertical slice through the diagram. Here the alphabet is `Ξ“' := Bool Γ— βˆ€ k, Option (Ξ“ k)`, where: * `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the tail of all stacks. It is never modified. * `stk k : Option (Ξ“ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is the blank value). Note that the head of the stack is at the far end; this is so that push and pop don't have to do any shifting. In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions, it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the end of the appropriate stack, make its changes, and then return to the bottom. So the states are: * `normal (l : Ξ›)`: waiting at `bottom` to execute function `l` * `go k (s : StAct k) (q : Stmtβ‚‚)`: travelling to the right to get to the end of stack `k` in order to perform stack action `s`, and later continue with executing `q` * `ret (q : Stmtβ‚‚)`: travelling to the left after having performed a stack action, and executing `q` once we arrive Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)` steps to run when emulated in TM1, where `m` is the length of the input. -/ namespace TM2to1 -- A displaced lemma proved in unnecessary generality theorem stk_nth_val {K : Type*} {Ξ“ : K β†’ Type*} {L : ListBlank (βˆ€ k, Option (Ξ“ k))} {k S} (n) (hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) : L.nth n k = S.reverse[n]? := by rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.getElem?_map] cases S.reverse[n]? <;> rfl variable (K : Type*) variable (Ξ“ : K β†’ Type*) variable {Ξ› Οƒ : Type*} /-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom, plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/ def Ξ“' := Bool Γ— βˆ€ k, Option (Ξ“ k) variable {K Ξ“} instance Ξ“'.inhabited : Inhabited (Ξ“' K Ξ“) := ⟨⟨false, fun _ ↦ none⟩⟩ instance Ξ“'.fintype [DecidableEq K] [Fintype K] [βˆ€ k, Fintype (Ξ“ k)] : Fintype (Ξ“' K Ξ“) := instFintypeProd _ _ /-- The bottom marker is fixed throughout the calculation, so we use the `addBottom` function to express the program state in terms of a tape with only the stacks themselves. -/ def addBottom (L : ListBlank (βˆ€ k, Option (Ξ“ k))) : ListBlank (Ξ“' K Ξ“) := ListBlank.cons (true, L.head) (L.tail.map ⟨Prod.mk false, rfl⟩) theorem addBottom_map (L : ListBlank (βˆ€ k, Option (Ξ“ k))) : (addBottom L).map ⟨Prod.snd, by rfl⟩ = L := by simp only [addBottom, ListBlank.map_cons] convert ListBlank.cons_head_tail L generalize ListBlank.tail L = L' refine L'.induction_on fun l ↦ ?_; simp theorem addBottom_modifyNth (f : (βˆ€ k, Option (Ξ“ k)) β†’ βˆ€ k, Option (Ξ“ k)) (L : ListBlank (βˆ€ k, Option (Ξ“ k))) (n : β„•) : (addBottom L).modifyNth (fun a ↦ (a.1, f a.2)) n = addBottom (L.modifyNth f n) := by cases n <;> simp only [addBottom, ListBlank.head_cons, ListBlank.modifyNth, ListBlank.tail_cons] congr; symm; apply ListBlank.map_modifyNth; intro; rfl theorem addBottom_nth_snd (L : ListBlank (βˆ€ k, Option (Ξ“ k))) (n : β„•) : ((addBottom L).nth n).2 = L.nth n := by conv => rhs; rw [← addBottom_map L, ListBlank.nth_map] theorem addBottom_nth_succ_fst (L : ListBlank (βˆ€ k, Option (Ξ“ k))) (n : β„•) : ((addBottom L).nth (n + 1)).1 = false := by rw [ListBlank.nth_succ, addBottom, ListBlank.tail_cons, ListBlank.nth_map] theorem addBottom_head_fst (L : ListBlank (βˆ€ k, Option (Ξ“ k))) : (addBottom L).head.1 = true := by rw [addBottom, ListBlank.head_cons] variable (K Ξ“ Οƒ) in /-- A stack action is a command that interacts with the top of a stack. Our default position is at the bottom of all the stacks, so we have to hold on to this action while going to the end to modify the stack. -/ inductive StAct (k : K) | push : (Οƒ β†’ Ξ“ k) β†’ StAct k | peek : (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ StAct k | pop : (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ StAct k instance StAct.inhabited {k : K} : Inhabited (StAct K Ξ“ Οƒ k) := ⟨StAct.peek fun s _ ↦ s⟩ section open StAct /-- The TM2 statement corresponding to a stack action. -/ def stRun {k : K} : StAct K Ξ“ Οƒ k β†’ TM2.Stmt Ξ“ Ξ› Οƒ β†’ TM2.Stmt Ξ“ Ξ› Οƒ | push f => TM2.Stmt.push k f | peek f => TM2.Stmt.peek k f | pop f => TM2.Stmt.pop k f /-- The effect of a stack action on the local variables, given the value of the stack. -/ def stVar {k : K} (v : Οƒ) (l : List (Ξ“ k)) : StAct K Ξ“ Οƒ k β†’ Οƒ | push _ => v | peek f => f v l.head? | pop f => f v l.head? /-- The effect of a stack action on the stack. -/ def stWrite {k : K} (v : Οƒ) (l : List (Ξ“ k)) : StAct K Ξ“ Οƒ k β†’ List (Ξ“ k) | push f => f v :: l | peek _ => l | pop _ => l.tail /-- We have partitioned the TM2 statements into "stack actions", which require going to the end of the stack, and all other actions, which do not. This is a modified recursor which lumps the stack actions into one. -/ @[elab_as_elim] def stmtStRec.{l} {motive : TM2.Stmt Ξ“ Ξ› Οƒ β†’ Sort l} (run : βˆ€ (k) (s : StAct K Ξ“ Οƒ k) (q) (_ : motive q), motive (stRun s q)) (load : βˆ€ (a q) (_ : motive q), motive (TM2.Stmt.load a q)) (branch : βˆ€ (p q₁ qβ‚‚) (_ : motive q₁) (_ : motive qβ‚‚), motive (TM2.Stmt.branch p q₁ qβ‚‚)) (goto : βˆ€ l, motive (TM2.Stmt.goto l)) (halt : motive TM2.Stmt.halt) : βˆ€ n, motive n | TM2.Stmt.push _ f q => run _ (push f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.peek _ f q => run _ (peek f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.pop _ f q => run _ (pop f) _ (stmtStRec run load branch goto halt q) | TM2.Stmt.load _ q => load _ _ (stmtStRec run load branch goto halt q) | TM2.Stmt.branch _ q₁ qβ‚‚ => branch _ _ _ (stmtStRec run load branch goto halt q₁) (stmtStRec run load branch goto halt qβ‚‚) | TM2.Stmt.goto _ => goto _ | TM2.Stmt.halt => halt theorem supports_run (S : Finset Ξ›) {k : K} (s : StAct K Ξ“ Οƒ k) (q : TM2.Stmt Ξ“ Ξ› Οƒ) : TM2.SupportsStmt S (stRun s q) ↔ TM2.SupportsStmt S q := by cases s <;> rfl end variable (K Ξ“ Ξ› Οƒ) /-- The machine states of the TM2 emulator. We can either be in a normal state when waiting for the next TM2 action, or we can be in the "go" and "return" states to go to the top of the stack and return to the bottom, respectively. -/ inductive Ξ›' | normal : Ξ› β†’ Ξ›' | go (k : K) : StAct K Ξ“ Οƒ k β†’ TM2.Stmt Ξ“ Ξ› Οƒ β†’ Ξ›' | ret : TM2.Stmt Ξ“ Ξ› Οƒ β†’ Ξ›' variable {K Ξ“ Ξ› Οƒ} open Ξ›' instance Ξ›'.inhabited [Inhabited Ξ›] : Inhabited (Ξ›' K Ξ“ Ξ› Οƒ) := ⟨normal default⟩ open TM1.Stmt section variable [DecidableEq K] /-- The program corresponding to state transitions at the end of a stack. Here we start out just after the top of the stack, and should end just after the new top of the stack. -/ def trStAct {k : K} (q : TM1.Stmt (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ) : StAct K Ξ“ Οƒ k β†’ TM1.Stmt (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ | StAct.push f => (write fun a s ↦ (a.1, update a.2 k <| some <| f s)) <| move Dir.right q | StAct.peek f => move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| move Dir.right q | StAct.pop f => branch (fun a _ ↦ a.1) (load (fun _ s ↦ f s none) q) (move Dir.left <| (load fun a s ↦ f s (a.2 k)) <| write (fun a _ ↦ (a.1, update a.2 k none)) q) /-- The initial state for the TM2 emulator, given an initial TM2 state. All stacks start out empty except for the input stack, and the stack bottom mark is set at the head. -/ def trInit (k : K) (L : List (Ξ“ k)) : List (Ξ“' K Ξ“) := let L' : List (Ξ“' K Ξ“) := L.reverse.map fun a ↦ (false, update (fun _ ↦ none) k (some a)) (true, L'.headI.2) :: L'.tail theorem step_run {k : K} (q : TM2.Stmt Ξ“ Ξ› Οƒ) (v : Οƒ) (S : βˆ€ k, List (Ξ“ k)) : βˆ€ s : StAct K Ξ“ Οƒ k, TM2.stepAux (stRun s q) v S = TM2.stepAux q (stVar v (S k) s) (update S k (stWrite v (S k) s)) | StAct.push _ => rfl | StAct.peek f => by unfold stWrite; rw [Function.update_eq_self]; rfl | StAct.pop _ => rfl end /-- The translation of TM2 statements to TM1 statements. regular actions have direct equivalents, but stack actions are deferred by going to the corresponding `go` state, so that we can find the appropriate stack top. -/ def trNormal : TM2.Stmt Ξ“ Ξ› Οƒ β†’ TM1.Stmt (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ | TM2.Stmt.push k f q => goto fun _ _ ↦ go k (StAct.push f) q | TM2.Stmt.peek k f q => goto fun _ _ ↦ go k (StAct.peek f) q | TM2.Stmt.pop k f q => goto fun _ _ ↦ go k (StAct.pop f) q | TM2.Stmt.load a q => load (fun _ ↦ a) (trNormal q) | TM2.Stmt.branch f q₁ qβ‚‚ => branch (fun _ ↦ f) (trNormal q₁) (trNormal qβ‚‚) | TM2.Stmt.goto l => goto fun _ s ↦ normal (l s) | TM2.Stmt.halt => halt theorem trNormal_run {k : K} (s : StAct K Ξ“ Οƒ k) (q : TM2.Stmt Ξ“ Ξ› Οƒ) : trNormal (stRun s q) = goto fun _ _ ↦ go k s q := by cases s <;> rfl section open scoped Classical in /-- The set of machine states accessible from an initial TM2 statement. -/ noncomputable def trStmts₁ : TM2.Stmt Ξ“ Ξ› Οƒ β†’ Finset (Ξ›' K Ξ“ Ξ› Οƒ) | TM2.Stmt.push k f q => {go k (StAct.push f) q, ret q} βˆͺ trStmts₁ q | TM2.Stmt.peek k f q => {go k (StAct.peek f) q, ret q} βˆͺ trStmts₁ q | TM2.Stmt.pop k f q => {go k (StAct.pop f) q, ret q} βˆͺ trStmts₁ q | TM2.Stmt.load _ q => trStmts₁ q | TM2.Stmt.branch _ q₁ qβ‚‚ => trStmts₁ q₁ βˆͺ trStmts₁ qβ‚‚ | _ => βˆ… theorem trStmts₁_run {k : K} {s : StAct K Ξ“ Οƒ k} {q : TM2.Stmt Ξ“ Ξ› Οƒ} : open scoped Classical in trStmts₁ (stRun s q) = {go k s q, ret q} βˆͺ trStmts₁ q := by cases s <;> simp only [trStmts₁, stRun] theorem tr_respects_auxβ‚‚ [DecidableEq K] {k : K} {q : TM1.Stmt (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ} {v : Οƒ} {S : βˆ€ k, List (Ξ“ k)} {L : ListBlank (βˆ€ k, Option (Ξ“ k))} (hL : βˆ€ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) (o : StAct K Ξ“ Οƒ k) : let v' := stVar v (S k) o let Sk' := stWrite v (S k) o let S' := update S k Sk' βˆƒ L' : ListBlank (βˆ€ k, Option (Ξ“ k)), (βˆ€ k, L'.map (proj k) = ListBlank.mk ((S' k).map some).reverse) ∧ TM1.stepAux (trStAct q o) v ((Tape.move Dir.right)^[(S k).length] (Tape.mk' βˆ… (addBottom L))) = TM1.stepAux q v' ((Tape.move Dir.right)^[(S' k).length] (Tape.mk' βˆ… (addBottom L'))) := by simp only [Function.update_self]; cases o with simp only [stWrite, stVar, trStAct, TM1.stepAux] | push f => have := Tape.write_move_right_n fun a : Ξ“' K Ξ“ ↦ (a.1, update a.2 k (some (f v))) refine ⟨_, fun k' ↦ ?_, by -- Porting note: `rw [...]` to `erw [...]; rfl`. -- https://github.com/leanprover-community/mathlib4/issues/5164 rw [Tape.move_right_n_head, List.length, Tape.mk'_nth_nat, this] erw [addBottom_modifyNth fun a ↦ update a k (some (f v))] rw [Nat.add_one, iterate_succ'] rfl⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k Β· subst k' split_ifs with h <;> simp only [List.reverse_cons, Function.update_self, ListBlank.nth_mk, List.map] Β· rw [List.getI_eq_getElem _, List.getElem_append_right] <;> simp only [List.length_append, List.length_reverse, List.length_map, ← h, Nat.sub_self, List.length_singleton, List.getElem_singleton, le_refl, Nat.lt_succ_self] rw [← proj_map_nth, hL, ListBlank.nth_mk] rcases lt_or_gt_of_ne h with h | h Β· rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h Β· rw [gt_iff_lt] at h rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] Β· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] | peek f => rw [Function.update_eq_self] use L, hL; rw [Tape.move_left_right]; congr cases e : S k; Β· rfl rw [List.length_cons, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hL k), e, List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length] rfl | pop f => rcases e : S k with - | ⟨hd, tl⟩ Β· simp only [Tape.mk'_head, ListBlank.head_cons, Tape.move_left_mk', List.length, Tape.write_mk', List.head?, iterate_zero_apply, List.tail_nil] rw [← e, Function.update_eq_self] exact ⟨L, hL, by rw [addBottom_head_fst, cond]⟩ Β· refine ⟨_, fun k' ↦ ?_, by erw [List.length_cons, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, cond_false, iterate_succ', Function.comp, Tape.move_right_left, Tape.move_right_n_head, Tape.mk'_nth_nat, Tape.write_move_right_n fun a : Ξ“' K Ξ“ ↦ (a.1, update a.2 k none), addBottom_modifyNth fun a ↦ update a k none, addBottom_nth_snd, stk_nth_val _ (hL k), e, show (List.cons hd tl).reverse[tl.length]? = some hd by rw [List.reverse_cons, ← List.length_reverse, List.getElem?_concat_length], List.head?, List.tail]⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.nth_map, ListBlank.nth_modifyNth, proj, PointedMap.mk_val] by_cases h' : k' = k Β· subst k' split_ifs with h <;> simp only [Function.update_self, ListBlank.nth_mk, List.tail] Β· rw [List.getI_eq_default] Β· rfl rw [h, List.length_reverse, List.length_map] rw [← proj_map_nth, hL, ListBlank.nth_mk, e, List.map, List.reverse_cons] rcases lt_or_gt_of_ne h with h | h Β· rw [List.getI_append] simpa only [List.length_map, List.length_reverse] using h Β· rw [gt_iff_lt] at h rw [List.getI_eq_default, List.getI_eq_default] <;> simp only [Nat.add_one_le_iff, h, List.length, le_of_lt, List.length_reverse, List.length_append, List.length_map] Β· split_ifs <;> rw [Function.update_of_ne h', ← proj_map_nth, hL] rw [Function.update_of_ne h'] end variable [DecidableEq K] variable (M : Ξ› β†’ TM2.Stmt Ξ“ Ξ› Οƒ) /-- The TM2 emulator machine states written as a TM1 program. This handles the `go` and `ret` states, which shuttle to and from a stack top. -/ def tr : Ξ›' K Ξ“ Ξ› Οƒ β†’ TM1.Stmt (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ | normal q => trNormal (M q) | go k s q => branch (fun a _ ↦ (a.2 k).isNone) (trStAct (goto fun _ _ ↦ ret q) s) (move Dir.right <| goto fun _ _ ↦ go k s q) | ret q => branch (fun a _ ↦ a.1) (trNormal q) (move Dir.left <| goto fun _ _ ↦ ret q) /-- The relation between TM2 configurations and TM1 configurations of the TM2 emulator. -/ inductive TrCfg : TM2.Cfg Ξ“ Ξ› Οƒ β†’ TM1.Cfg (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ β†’ Prop | mk {q : Option Ξ›} {v : Οƒ} {S : βˆ€ k, List (Ξ“ k)} (L : ListBlank (βˆ€ k, Option (Ξ“ k))) : (βˆ€ k, L.map (proj k) = ListBlank.mk ((S k).map some).reverse) β†’ TrCfg ⟨q, v, S⟩ ⟨q.map normal, v, Tape.mk' βˆ… (addBottom L)⟩ theorem tr_respects_aux₁ {k} (o q v) {S : List (Ξ“ k)} {L : ListBlank (βˆ€ k, Option (Ξ“ k))} (hL : L.map (proj k) = ListBlank.mk (S.map some).reverse) (n) (H : n ≀ S.length) : Reachesβ‚€ (TM1.step (tr M)) ⟨some (go k o q), v, Tape.mk' βˆ… (addBottom L)⟩ ⟨some (go k o q), v, (Tape.move Dir.right)^[n] (Tape.mk' βˆ… (addBottom L))⟩ := by induction' n with n IH; Β· rfl apply (IH (le_of_lt H)).tail rw [iterate_succ_apply'] simp only [TM1.step, TM1.stepAux, tr, Tape.mk'_nth_nat, Tape.move_right_n_head, addBottom_nth_snd, Option.mem_def] rw [stk_nth_val _ hL, List.getElem?_eq_getElem] Β· rfl Β· rwa [List.length_reverse] theorem tr_respects_aux₃ {q v} {L : ListBlank (βˆ€ k, Option (Ξ“ k))} (n) : Reachesβ‚€ (TM1.step (tr M)) ⟨some (ret q), v, (Tape.move Dir.right)^[n] (Tape.mk' βˆ… (addBottom L))⟩ ⟨some (ret q), v, Tape.mk' βˆ… (addBottom L)⟩ := by induction' n with n IH; Β· rfl refine Reachesβ‚€.head ?_ IH simp only [Option.mem_def, TM1.step] rw [Option.some_inj, tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_succ_fst, TM1.stepAux, iterate_succ', Function.comp_apply, Tape.move_right_left] rfl theorem tr_respects_aux {q v T k} {S : βˆ€ k, List (Ξ“ k)} (hT : βˆ€ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) (o : StAct K Ξ“ Οƒ k) (IH : βˆ€ {v : Οƒ} {S : βˆ€ k : K, List (Ξ“ k)} {T : ListBlank (βˆ€ k, Option (Ξ“ k))}, (βˆ€ k, ListBlank.map (proj k) T = ListBlank.mk ((S k).map some).reverse) β†’ βˆƒ b, TrCfg (TM2.stepAux q v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal q) v (Tape.mk' βˆ… (addBottom T))) b) : βˆƒ b, TrCfg (TM2.stepAux (stRun o q) v S) b ∧ Reaches (TM1.step (tr M)) (TM1.stepAux (trNormal (stRun o q)) v (Tape.mk' βˆ… (addBottom T))) b := by simp only [trNormal_run, step_run] have hgo := tr_respects_aux₁ M o q v (hT k) _ le_rfl obtain ⟨T', hT', hrun⟩ := tr_respects_auxβ‚‚ (Ξ› := Ξ›) hT o have := hgo.tail' rfl rw [tr, TM1.stepAux, Tape.move_right_n_head, Tape.mk'_nth_nat, addBottom_nth_snd, stk_nth_val _ (hT k), List.getElem?_eq_none (le_of_eq List.length_reverse), Option.isNone, cond, hrun, TM1.stepAux] at this obtain ⟨c, gc, rc⟩ := IH hT' refine ⟨c, gc, (this.toβ‚€.trans (tr_respects_aux₃ M _) c (TransGen.head' rfl ?_)).to_reflTransGen⟩ rw [tr, TM1.stepAux, Tape.mk'_head, addBottom_head_fst] exact rc attribute [local simp] Respects TM2.step TM2.stepAux trNormal theorem tr_respects : Respects (TM2.step M) (TM1.step (tr M)) TrCfg := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed intro c₁ cβ‚‚ h obtain @⟨- | l, v, S, L, hT⟩ := h; Β· constructor rsuffices ⟨b, c, r⟩ : βˆƒ b, _ ∧ Reaches (TM1.step (tr M)) _ _ Β· exact ⟨b, c, TransGen.head' rfl r⟩ simp only [tr] generalize M l = N induction N using stmtStRec generalizing v S L hT with | run k s q IH => exact tr_respects_aux M hT s @IH | load a _ IH => exact IH _ hT | branch p q₁ qβ‚‚ IH₁ IHβ‚‚ => unfold TM2.stepAux trNormal TM1.stepAux beta_reduce cases p v <;> [exact IHβ‚‚ _ hT; exact IH₁ _ hT] | goto => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ | halt => exact ⟨_, ⟨_, hT⟩, ReflTransGen.refl⟩ section variable [Inhabited Ξ›] [Inhabited Οƒ] theorem trCfg_init (k) (L : List (Ξ“ k)) : TrCfg (TM2.init k L) (TM1.init (trInit k L) : TM1.Cfg (Ξ“' K Ξ“) (Ξ›' K Ξ“ Ξ› Οƒ) Οƒ) := by rw [(_ : TM1.init _ = _)] Β· refine ⟨ListBlank.mk (L.reverse.map fun a ↦ update default k (some a)), fun k' ↦ ?_⟩ refine ListBlank.ext fun i ↦ ?_ rw [ListBlank.map_mk, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map_map] have : ((proj k').f ∘ fun a => update (Ξ² := fun k => Option (Ξ“ k)) default k (some a)) = fun a => (proj k').f (update (Ξ² := fun k => Option (Ξ“ k)) default k (some a)) := rfl rw [this, List.getElem?_map, proj, PointedMap.mk_val] simp only [] by_cases h : k' = k Β· subst k' simp only [Function.update_self] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, ← List.map_reverse, List.getElem?_map] Β· simp only [Function.update_of_ne h] rw [ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.map, List.reverse_nil] cases L.reverse[i]? <;> rfl Β· rw [trInit, TM1.init] congr <;> cases L.reverse <;> try rfl simp only [List.map_map, List.tail_cons, List.map] rfl theorem tr_eval_dom (k) (L : List (Ξ“ k)) : (TM1.eval (tr M) (trInit k L)).Dom ↔ (TM2.eval M k L).Dom := Turing.tr_eval_dom (tr_respects M) (trCfg_init k L) theorem tr_eval (k) (L : List (Ξ“ k)) {L₁ Lβ‚‚} (H₁ : L₁ ∈ TM1.eval (tr M) (trInit k L)) (Hβ‚‚ : Lβ‚‚ ∈ TM2.eval M k L) : βˆƒ (S : βˆ€ k, List (Ξ“ k)) (L' : ListBlank (βˆ€ k, Option (Ξ“ k))), addBottom L' = L₁ ∧ (βˆ€ k, L'.map (proj k) = ListBlank.mk ((S k).map some).reverse) ∧ S k = Lβ‚‚ := by obtain ⟨c₁, h₁, rfl⟩ := (Part.mem_map_iff _).1 H₁ obtain ⟨cβ‚‚, hβ‚‚, rfl⟩ := (Part.mem_map_iff _).1 Hβ‚‚ obtain ⟨_, ⟨L', hT⟩, hβ‚ƒβŸ© := Turing.tr_eval (tr_respects M) (trCfg_init k L) hβ‚‚ cases Part.mem_unique h₁ h₃ exact ⟨_, L', by simp only [Tape.mk'_rightβ‚€], hT, rfl⟩ end section variable [Inhabited Ξ›] open scoped Classical in /-- The support of a set of TM2 states in the TM2 emulator. -/ noncomputable def trSupp (S : Finset Ξ›) : Finset (Ξ›' K Ξ“ Ξ› Οƒ) := S.biUnion fun l ↦ insert (normal l) (trStmts₁ (M l)) open scoped Classical in theorem tr_supports {S} (ss : TM2.Supports M S) : TM1.Supports (tr M) (trSupp M S) := ⟨Finset.mem_biUnion.2 ⟨_, ss.1, Finset.mem_insert.2 <| Or.inl rfl⟩, fun l' h ↦ by suffices βˆ€ (q) (_ : TM2.SupportsStmt S q) (_ : βˆ€ x ∈ trStmts₁ q, x ∈ trSupp M S), TM1.SupportsStmt (trSupp M S) (trNormal q) ∧ βˆ€ l' ∈ trStmts₁ q, TM1.SupportsStmt (trSupp M S) (tr M l') by rcases Finset.mem_biUnion.1 h with ⟨l, lS, h⟩ have := this _ (ss.2 l lS) fun x hx ↦ Finset.mem_biUnion.2 ⟨_, lS, Finset.mem_insert_of_mem hx⟩ rcases Finset.mem_insert.1 h with (rfl | h) <;> [exact this.1; exact this.2 _ h] clear h l' refine stmtStRec ?_ ?_ ?_ ?_ ?_ Β· intro _ s _ IH ss' sub -- stack op rw [TM2to1.supports_run] at ss' simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at sub have hgo := sub _ (Or.inl <| Or.inl rfl) have hret := sub _ (Or.inl <| Or.inr rfl) obtain ⟨IH₁, IHβ‚‚βŸ© := IH ss' fun x hx ↦ sub x <| Or.inr hx refine ⟨by simp only [trNormal_run, TM1.SupportsStmt]; intros; exact hgo, fun l h ↦ ?_⟩ rw [trStmts₁_run] at h simp only [TM2to1.trStmts₁_run, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton] at h rcases h with (⟨rfl | rfl⟩ | h) Β· cases s Β· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ Β· exact ⟨fun _ _ ↦ hret, fun _ _ ↦ hgo⟩ Β· exact ⟨⟨fun _ _ ↦ hret, fun _ _ ↦ hret⟩, fun _ _ ↦ hgo⟩ Β· unfold TM1.SupportsStmt TM2to1.tr exact ⟨IH₁, fun _ _ ↦ hret⟩ Β· exact IHβ‚‚ _ h Β· intro _ _ IH ss' sub -- load unfold TM2to1.trStmts₁ at sub ⊒ exact IH ss' sub Β· intro _ _ _ IH₁ IHβ‚‚ ss' sub -- branch unfold TM2to1.trStmts₁ at sub obtain ⟨IH₁₁, IHβ‚β‚‚βŸ© := IH₁ ss'.1 fun x hx ↦ sub x <| Finset.mem_union_left _ hx obtain ⟨IH₂₁, IHβ‚‚β‚‚βŸ© := IHβ‚‚ ss'.2 fun x hx ↦ sub x <| Finset.mem_union_right _ hx refine ⟨⟨IH₁₁, IHβ‚‚β‚βŸ©, fun l h ↦ ?_⟩ rw [trStmts₁] at h rcases Finset.mem_union.1 h with (h | h) <;> [exact IH₁₂ _ h; exact IHβ‚‚β‚‚ _ h] Β· intro _ ss' _ -- goto simp only [trStmts₁, Finset.not_mem_empty]; refine ⟨?_, fun _ ↦ False.elim⟩ exact fun _ v ↦ Finset.mem_biUnion.2 ⟨_, ss' v, Finset.mem_insert_self _ _⟩ Β· intro _ _ -- halt simp only [trStmts₁, Finset.not_mem_empty] exact ⟨trivial, fun _ ↦ False.elim⟩⟩ end end TM2to1 end Turing
Mathlib/Computability/TuringMachine.lean
2,382
2,387
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich -/ import Mathlib.Data.Set.Piecewise import Mathlib.Order.Filter.Tendsto import Mathlib.Order.Filter.Bases.Finite /-! # (Co)product of a family of filters In this file we define two filters on `Ξ  i, Ξ± i` and prove some basic properties of these filters. * `Filter.pi (f : Ξ  i, Filter (Ξ± i))` to be the maximal filter on `Ξ  i, Ξ± i` such that `βˆ€ i, Filter.Tendsto (Function.eval i) (Filter.pi f) (f i)`. It is defined as `Ξ  i, Filter.comap (Function.eval i) (f i)`. This is a generalization of `Filter.prod` to indexed products. * `Filter.coprodα΅’ (f : Ξ  i, Filter (Ξ± i))`: a generalization of `Filter.coprod`; it is the supremum of `comap (eval i) (f i)`. -/ open Set Function Filter namespace Filter variable {ΞΉ : Type*} {Ξ± : ΞΉ β†’ Type*} {f f₁ fβ‚‚ : (i : ΞΉ) β†’ Filter (Ξ± i)} {s : (i : ΞΉ) β†’ Set (Ξ± i)} {p : βˆ€ i, Ξ± i β†’ Prop} section Pi theorem tendsto_eval_pi (f : βˆ€ i, Filter (Ξ± i)) (i : ΞΉ) : Tendsto (eval i) (pi f) (f i) := tendsto_iInf' i tendsto_comap theorem tendsto_pi {Ξ² : Type*} {m : Ξ² β†’ βˆ€ i, Ξ± i} {l : Filter Ξ²} : Tendsto m l (pi f) ↔ βˆ€ i, Tendsto (fun x => m x i) l (f i) := by simp only [pi, tendsto_iInf, tendsto_comap_iff]; rfl /-- If a function tends to a product `Filter.pi f` of filters, then its `i`-th component tends to `f i`. See also `Filter.Tendsto.apply_nhds` for the special case of converging to a point in a product of topological spaces. -/ alias ⟨Tendsto.apply, _⟩ := tendsto_pi theorem le_pi {g : Filter (βˆ€ i, Ξ± i)} : g ≀ pi f ↔ βˆ€ i, Tendsto (eval i) g (f i) := tendsto_pi @[mono] theorem pi_mono (h : βˆ€ i, f₁ i ≀ fβ‚‚ i) : pi f₁ ≀ pi fβ‚‚ := iInf_mono fun i => comap_mono <| h i theorem mem_pi_of_mem (i : ΞΉ) {s : Set (Ξ± i)} (hs : s ∈ f i) : eval i ⁻¹' s ∈ pi f := mem_iInf_of_mem i <| preimage_mem_comap hs theorem pi_mem_pi {I : Set ΞΉ} (hI : I.Finite) (h : βˆ€ i ∈ I, s i ∈ f i) : I.pi s ∈ pi f := by rw [pi_def, biInter_eq_iInter] refine mem_iInf_of_iInter hI (fun i => ?_) Subset.rfl exact preimage_mem_comap (h i i.2) theorem mem_pi {s : Set (βˆ€ i, Ξ± i)} : s ∈ pi f ↔ βˆƒ I : Set ΞΉ, I.Finite ∧ βˆƒ t : βˆ€ i, Set (Ξ± i), (βˆ€ i, t i ∈ f i) ∧ I.pi t βŠ† s := by constructor Β· simp only [pi, mem_iInf', mem_comap, pi_def] rintro ⟨I, If, V, hVf, -, rfl, -⟩ choose t htf htV using hVf exact ⟨I, If, t, htf, iInterβ‚‚_mono fun i _ => htV i⟩ Β· rintro ⟨I, If, t, htf, hts⟩ exact mem_of_superset (pi_mem_pi If fun i _ => htf i) hts theorem mem_pi' {s : Set (βˆ€ i, Ξ± i)} : s ∈ pi f ↔ βˆƒ I : Finset ΞΉ, βˆƒ t : βˆ€ i, Set (Ξ± i), (βˆ€ i, t i ∈ f i) ∧ Set.pi (↑I) t βŠ† s := mem_pi.trans exists_finite_iff_finset theorem mem_of_pi_mem_pi [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} (h : I.pi s ∈ pi f) {i : ΞΉ} (hi : i ∈ I) : s i ∈ f i := by classical rcases mem_pi.1 h with ⟨I', -, t, htf, hts⟩ refine mem_of_superset (htf i) fun x hx => ?_ have : βˆ€ i, (t i).Nonempty := fun i => nonempty_of_mem (htf i) choose g hg using this have : update g i x ∈ I'.pi t := fun j _ => by rcases eq_or_ne j i with (rfl | hne) <;> simp [*] simpa using hts this i hi @[simp] theorem pi_mem_pi_iff [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} (hI : I.Finite) : I.pi s ∈ pi f ↔ βˆ€ i ∈ I, s i ∈ f i := ⟨fun h _i hi => mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩ theorem Eventually.eval_pi {i : ΞΉ} (hf : βˆ€αΆ  x : Ξ± i in f i, p i x) : βˆ€αΆ  x : βˆ€ i : ΞΉ, Ξ± i in pi f, p i (x i) := (tendsto_eval_pi _ _).eventually hf theorem eventually_pi [Finite ΞΉ] (hf : βˆ€ i, βˆ€αΆ  x in f i, p i x) : βˆ€αΆ  x : βˆ€ i, Ξ± i in pi f, βˆ€ i, p i (x i) := eventually_all.2 fun _i => (hf _).eval_pi theorem hasBasis_pi {ΞΉ' : ΞΉ β†’ Type*} {s : βˆ€ i, ΞΉ' i β†’ Set (Ξ± i)} {p : βˆ€ i, ΞΉ' i β†’ Prop} (h : βˆ€ i, (f i).HasBasis (p i) (s i)) : (pi f).HasBasis (fun If : Set ΞΉ Γ— βˆ€ i, ΞΉ' i => If.1.Finite ∧ βˆ€ i ∈ If.1, p i (If.2 i)) fun If : Set ΞΉ Γ— βˆ€ i, ΞΉ' i => If.1.pi fun i => s i <| If.2 i := by simpa [Set.pi_def] using hasBasis_iInf' fun i => (h i).comap (eval i : (βˆ€ j, Ξ± j) β†’ Ξ± i) theorem hasBasis_pi_same_index {ΞΊ : Type*} {p : ΞΊ β†’ Prop} {s : Ξ  i : ΞΉ, ΞΊ β†’ Set (Ξ± i)} (h : βˆ€ i : ΞΉ, (f i).HasBasis p (s i)) (h_dir : βˆ€ I : Set ΞΉ, βˆ€ k : ΞΉ β†’ ΞΊ, I.Finite β†’ (βˆ€ i ∈ I, p (k i)) β†’ βˆƒ kβ‚€, p kβ‚€ ∧ βˆ€ i ∈ I, s i kβ‚€ βŠ† s i (k i)) : (pi f).HasBasis (fun Ik : Set ΞΉ Γ— ΞΊ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun i ↦ s i Ik.2)) := by refine hasBasis_pi h |>.to_hasBasis ?_ ?_ Β· rintro ⟨I, k⟩ ⟨hI, hk⟩ rcases h_dir I k hI hk with ⟨kβ‚€, hkβ‚€, hkβ‚€'⟩ exact ⟨⟨I, kβ‚€βŸ©, ⟨hI, hkβ‚€βŸ©, Set.pi_mono hkβ‚€'⟩ Β· rintro ⟨I, k⟩ ⟨hI, hk⟩ exact ⟨⟨I, fun _ ↦ k⟩, ⟨hI, fun _ _ ↦ hk⟩, subset_rfl⟩ theorem HasBasis.pi_self {Ξ± : Type*} {ΞΊ : Type*} {f : Filter Ξ±} {p : ΞΊ β†’ Prop} {s : ΞΊ β†’ Set Ξ±} (h : f.HasBasis p s) : (pi fun _ ↦ f).HasBasis (fun Ik : Set ΞΉ Γ— ΞΊ ↦ Ik.1.Finite ∧ p Ik.2) (fun Ik ↦ Ik.1.pi (fun _ ↦ s Ik.2)) := by refine hasBasis_pi_same_index (fun _ ↦ h) (fun I k hI hk ↦ ?_) rcases h.mem_iff.mp (biInter_mem hI |>.mpr fun i hi ↦ h.mem_of_mem (hk i hi)) with ⟨kβ‚€, hkβ‚€, hkβ‚€'⟩ exact ⟨kβ‚€, hkβ‚€, fun i hi ↦ hkβ‚€'.trans (biInter_subset_of_mem hi)⟩ theorem le_pi_principal (s : (i : ΞΉ) β†’ Set (Ξ± i)) : π“Ÿ (univ.pi s) ≀ pi fun i ↦ π“Ÿ (s i) := le_pi.2 fun i ↦ tendsto_principal_principal.2 fun _f hf ↦ hf i trivial /-- The indexed product of finitely many principal filters is the principal filter corresponding to the cylinder `Set.univ.pi s`. If the index type is infinite, then `mem_pi_principal` and `hasBasis_pi_principal` may be useful. -/ @[simp] theorem pi_principal [Finite ΞΉ] (s : (i : ΞΉ) β†’ Set (Ξ± i)) : pi (fun i ↦ π“Ÿ (s i)) = π“Ÿ (univ.pi s) := by simp [Filter.pi, Set.pi_def] /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem mem_pi_principal {t : Set ((i : ΞΉ) β†’ Ξ± i)} : t ∈ pi (fun i ↦ π“Ÿ (s i)) ↔ βˆƒ I : Set ΞΉ, I.Finite ∧ I.pi s βŠ† t := (hasBasis_pi (fun i ↦ hasBasis_principal _)).mem_iff.trans <| by simp /-- The indexed product of a (possibly, infinite) family of principal filters is generated by the finite `Set.pi` cylinders. If the index type is finite, then the indexed product of principal filters is a pricipal filter, see `pi_principal`. -/ theorem hasBasis_pi_principal (s : (i : ΞΉ) β†’ Set (Ξ± i)) : HasBasis (pi fun i ↦ π“Ÿ (s i)) Set.Finite (Set.pi Β· s) := ⟨fun _ ↦ mem_pi_principal⟩ /-- The indexed product of finitely many pure filters `pure (f i)` is the pure filter `pure f`. If the index type is infinite, then `mem_pi_pure` and `hasBasis_pi_pure` below may be useful. -/ @[simp] theorem pi_pure [Finite ΞΉ] (f : (i : ΞΉ) β†’ Ξ± i) : pi (pure <| f Β·) = pure f := by simp only [← principal_singleton, pi_principal, univ_pi_singleton] /-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)` is generated by the sets of functions that are equal to `f` on a finite set. If the index type is finite, then the indexed product of pure filters is a pure filter, see `pi_pure`. -/ theorem mem_pi_pure {f : (i : ΞΉ) β†’ Ξ± i} {s : Set ((i : ΞΉ) β†’ Ξ± i)} : s ∈ pi (fun i ↦ pure (f i)) ↔ βˆƒ I : Set ΞΉ, I.Finite ∧ βˆ€ g, (βˆ€ i ∈ I, g i = f i) β†’ g ∈ s := by simp only [← principal_singleton, mem_pi_principal] simp [subset_def] /-- The indexed product of a (possibly, infinite) family of pure filters `pure (f i)` is generated by the sets of functions that are equal to `f` on a finite set. If the index type is finite, then the indexed product of pure filters is a pure filter, see `pi_pure`. -/ theorem hasBasis_pi_pure (f : (i : ΞΉ) β†’ Ξ± i) : HasBasis (pi fun i ↦ pure (f i)) Set.Finite (fun I ↦ {g | βˆ€ i ∈ I, g i = f i}) := ⟨fun _ ↦ mem_pi_pure⟩ @[simp] theorem pi_inf_principal_univ_pi_eq_bot : pi f βŠ“ π“Ÿ (Set.pi univ s) = βŠ₯ ↔ βˆƒ i, f i βŠ“ π“Ÿ (s i) = βŠ₯ := by constructor Β· simp only [inf_principal_eq_bot, mem_pi] contrapose! rintro (hsf : βˆ€ i, βˆƒαΆ  x in f i, x ∈ s i) I - t htf hts have : βˆ€ i, (s i ∩ t i).Nonempty := fun i => ((hsf i).and_eventually (htf i)).exists choose x hxs hxt using this exact hts (fun i _ => hxt i) (mem_univ_pi.2 hxs) Β· simp only [inf_principal_eq_bot] rintro ⟨i, hi⟩ filter_upwards [mem_pi_of_mem i hi] with x using mt fun h => h i trivial @[simp] theorem pi_inf_principal_pi_eq_bot [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} : pi f βŠ“ π“Ÿ (Set.pi I s) = βŠ₯ ↔ βˆƒ i ∈ I, f i βŠ“ π“Ÿ (s i) = βŠ₯ := by classical rw [← univ_pi_piecewise_univ I, pi_inf_principal_univ_pi_eq_bot] refine exists_congr fun i => ?_ by_cases hi : i ∈ I <;> simp [hi, NeBot.ne'] @[simp] theorem pi_inf_principal_univ_pi_neBot : NeBot (pi f βŠ“ π“Ÿ (Set.pi univ s)) ↔ βˆ€ i, NeBot (f i βŠ“ π“Ÿ (s i)) := by simp [neBot_iff] @[simp] theorem pi_inf_principal_pi_neBot [βˆ€ i, NeBot (f i)] {I : Set ΞΉ} : NeBot (pi f βŠ“ π“Ÿ (I.pi s)) ↔ βˆ€ i ∈ I, NeBot (f i βŠ“ π“Ÿ (s i)) := by simp [neBot_iff] instance PiInfPrincipalPi.neBot [h : βˆ€ i, NeBot (f i βŠ“ π“Ÿ (s i))] {I : Set ΞΉ} : NeBot (pi f βŠ“ π“Ÿ (I.pi s)) := (pi_inf_principal_univ_pi_neBot.2 β€Ή_β€Ί).mono <| inf_le_inf_left _ <| principal_mono.2 fun _ hx i _ => hx i trivial @[simp] theorem pi_eq_bot : pi f = βŠ₯ ↔ βˆƒ i, f i = βŠ₯ := by simpa using @pi_inf_principal_univ_pi_eq_bot ΞΉ Ξ± f fun _ => univ @[simp] theorem pi_neBot : NeBot (pi f) ↔ βˆ€ i, NeBot (f i) := by simp [neBot_iff] instance [βˆ€ i, NeBot (f i)] : NeBot (pi f) := pi_neBot.2 β€Ή_β€Ί @[simp] theorem map_eval_pi (f : βˆ€ i, Filter (Ξ± i)) [βˆ€ i, NeBot (f i)] (i : ΞΉ) :
map (eval i) (pi f) = f i := by refine le_antisymm (tendsto_eval_pi f i) fun s hs => ?_
Mathlib/Order/Filter/Pi.lean
229
230
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark -/ import Mathlib.Algebra.Polynomial.Expand import Mathlib.Algebra.Polynomial.Laurent import Mathlib.Algebra.Polynomial.Eval.SMul import Mathlib.LinearAlgebra.Matrix.Charpoly.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.RingTheory.Polynomial.Nilpotent /-! # Characteristic polynomials We give methods for computing coefficients of the characteristic polynomial. ## Main definitions - `Matrix.charpoly_degree_eq_dim` proves that the degree of the characteristic polynomial over a nonzero ring is the dimension of the matrix - `Matrix.det_eq_sign_charpoly_coeff` proves that the determinant is the constant term of the characteristic polynomial, up to sign. - `Matrix.trace_eq_neg_charpoly_coeff` proves that the trace is the negative of the (d-1)th coefficient of the characteristic polynomial, where d is the dimension of the matrix. For a nonzero ring, this is the second-highest coefficient. - `Matrix.charpolyRev` the reverse of the characteristic polynomial. - `Matrix.reverse_charpoly` characterises the reverse of the characteristic polynomial. -/ noncomputable section universe u v w z open Finset Matrix Polynomial variable {R : Type u} [CommRing R] variable {n G : Type v} [DecidableEq n] [Fintype n] variable {Ξ± Ξ² : Type v} [DecidableEq Ξ±] variable {M : Matrix n n R} namespace Matrix theorem charmatrix_apply_natDegree [Nontrivial R] (i j : n) : (charmatrix M i j).natDegree = ite (i = j) 1 0 := by by_cases h : i = j <;> simp [h, ← degree_eq_iff_natDegree_eq_of_pos (Nat.succ_pos 0)] theorem charmatrix_apply_natDegree_le (i j : n) : (charmatrix M i j).natDegree ≀ ite (i = j) 1 0 := by split_ifs with h <;> simp [h, natDegree_X_le] variable (M) theorem charpoly_sub_diagonal_degree_lt : (M.charpoly - ∏ i : n, (X - C (M i i))).degree < ↑(Fintype.card n - 1) := by rw [charpoly, det_apply', ← insert_erase (mem_univ (Equiv.refl n)), sum_insert (not_mem_erase (Equiv.refl n) univ), add_comm] simp only [charmatrix_apply_eq, one_mul, Equiv.Perm.sign_refl, id, Int.cast_one, Units.val_one, add_sub_cancel_right, Equiv.coe_refl] rw [← mem_degreeLT] apply Submodule.sum_mem (degreeLT R (Fintype.card n - 1)) intro c hc; rw [← C_eq_intCast, C_mul'] apply Submodule.smul_mem (degreeLT R (Fintype.card n - 1)) ↑↑(Equiv.Perm.sign c) rw [mem_degreeLT] apply lt_of_le_of_lt degree_le_natDegree _ rw [Nat.cast_lt] apply lt_of_le_of_lt _ (Equiv.Perm.fixed_point_card_lt_of_ne_one (ne_of_mem_erase hc)) apply le_trans (Polynomial.natDegree_prod_le univ fun i : n => charmatrix M (c i) i) _ rw [card_eq_sum_ones]; rw [sum_filter]; apply sum_le_sum intros apply charmatrix_apply_natDegree_le theorem charpoly_coeff_eq_prod_coeff_of_le {k : β„•} (h : Fintype.card n - 1 ≀ k) : M.charpoly.coeff k = (∏ i : n, (X - C (M i i))).coeff k := by apply eq_of_sub_eq_zero; rw [← coeff_sub] apply Polynomial.coeff_eq_zero_of_degree_lt apply lt_of_lt_of_le (charpoly_sub_diagonal_degree_lt M) ?_ rw [Nat.cast_le]; apply h theorem det_of_card_zero (h : Fintype.card n = 0) (M : Matrix n n R) : M.det = 1 := by rw [Fintype.card_eq_zero_iff] at h suffices M = 1 by simp [this] ext i exact h.elim i theorem charpoly_degree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.degree = Fintype.card n := by by_cases h : Fintype.card n = 0 Β· rw [h] unfold charpoly rw [det_of_card_zero] Β· simp Β· assumption rw [← sub_add_cancel M.charpoly (∏ i : n, (X - C (M i i)))] -- Porting note: added `↑` in front of `Fintype.card n` have h1 : (∏ i : n, (X - C (M i i))).degree = ↑(Fintype.card n) := by rw [degree_eq_iff_natDegree_eq_of_pos (Nat.pos_of_ne_zero h), natDegree_prod'] Β· simp_rw [natDegree_X_sub_C] rw [← Finset.card_univ, sum_const, smul_eq_mul, mul_one] simp_rw [(monic_X_sub_C _).leadingCoeff] simp rw [degree_add_eq_right_of_degree_lt] Β· exact h1 rw [h1] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h @[simp] theorem charpoly_natDegree_eq_dim [Nontrivial R] (M : Matrix n n R) : M.charpoly.natDegree = Fintype.card n := natDegree_eq_of_degree_eq_some (charpoly_degree_eq_dim M) theorem charpoly_monic (M : Matrix n n R) : M.charpoly.Monic := by nontriviality R by_cases h : Fintype.card n = 0 Β· rw [charpoly, det_of_card_zero h] apply monic_one have mon : (∏ i : n, (X - C (M i i))).Monic := by apply monic_prod_of_monic univ fun i : n => X - C (M i i) simp [monic_X_sub_C] rw [← sub_add_cancel (∏ i : n, (X - C (M i i))) M.charpoly] at mon rw [Monic] at * rwa [leadingCoeff_add_of_degree_lt] at mon rw [charpoly_degree_eq_dim] rw [← neg_sub] rw [degree_neg] apply lt_trans (charpoly_sub_diagonal_degree_lt M) rw [Nat.cast_lt] rw [← Nat.pred_eq_sub_one] apply Nat.pred_lt apply h /-- See also `Matrix.coeff_charpolyRev_eq_neg_trace`. -/ theorem trace_eq_neg_charpoly_coeff [Nonempty n] (M : Matrix n n R) : trace M = -M.charpoly.coeff (Fintype.card n - 1) := by rw [charpoly_coeff_eq_prod_coeff_of_le _ le_rfl, Fintype.card, prod_X_sub_C_coeff_card_pred univ (fun i : n => M i i) Fintype.card_pos, neg_neg, trace] simp_rw [diag_apply] theorem matPolyEquiv_symm_map_eval (M : (Matrix n n R)[X]) (r : R) : (matPolyEquiv.symm M).map (eval r) = M.eval (scalar n r) := by suffices ((aeval r).mapMatrix.comp matPolyEquiv.symm.toAlgHom : (Matrix n n R)[X] →ₐ[R] _) = (evalβ‚‚AlgHom' (AlgHom.id R _) (scalar n r) fun x => (scalar_commute _ (Commute.all _) _).symm) from DFunLike.congr_fun this M ext : 1 Β· ext M : 1 simp [Function.comp_def] Β· simp [smul_eq_diagonal_mul] theorem matPolyEquiv_eval_eq_map (M : Matrix n n R[X]) (r : R) :
(matPolyEquiv M).eval (scalar n r) = M.map (eval r) := by simpa only [AlgEquiv.symm_apply_apply] using (matPolyEquiv_symm_map_eval (matPolyEquiv M) r).symm -- I feel like this should use `Polynomial.algHom_evalβ‚‚_algebraMap` theorem matPolyEquiv_eval (M : Matrix n n R[X]) (r : R) (i j : n) : (matPolyEquiv M).eval (scalar n r) i j = (M i j).eval r := by rw [matPolyEquiv_eval_eq_map, map_apply] theorem eval_det (M : Matrix n n R[X]) (r : R) : Polynomial.eval r M.det = (Polynomial.eval (scalar n r) (matPolyEquiv M)).det := by
Mathlib/LinearAlgebra/Matrix/Charpoly/Coeff.lean
156
165
/- Copyright (c) 2022 Praneeth Kolichala. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Praneeth Kolichala -/ import Mathlib.Data.Nat.Basic import Mathlib.Data.Nat.BinaryRec import Mathlib.Data.List.Defs import Mathlib.Tactic.Convert import Mathlib.Tactic.GeneralizeProofs import Mathlib.Tactic.Says /-! # Additional properties of binary recursion on `Nat` This file documents additional properties of binary recursion, which allows us to more easily work with operations which do depend on the number of leading zeros in the binary representation of `n`. For example, we can more easily work with `Nat.bits` and `Nat.size`. See also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftLeft`/`shiftRight`), and `Nat.digits`. -/ assert_not_exists Monoid -- Once we're in the `Nat` namespace, `xor` will inconveniently resolve to `Nat.xor`. /-- `bxor` denotes the `xor` function i.e. the exclusive-or function on type `Bool`. -/ local notation "bxor" => xor namespace Nat universe u variable {m n : β„•} /-- `boddDiv2 n` returns a 2-tuple of type `(Bool, Nat)` where the `Bool` value indicates whether `n` is odd or not and the `Nat` value returns `⌊n/2βŒ‹` -/ def boddDiv2 : β„• β†’ Bool Γ— β„• | 0 => (false, 0) | succ n => match boddDiv2 n with | (false, m) => (true, m) | (true, m) => (false, succ m) /-- `div2 n = ⌊n/2βŒ‹` the greatest integer smaller than `n/2` -/ def div2 (n : β„•) : β„• := (boddDiv2 n).2 /-- `bodd n` returns `true` if `n` is odd -/ def bodd (n : β„•) : Bool := (boddDiv2 n).1 @[simp] lemma bodd_zero : bodd 0 = false := rfl @[simp] lemma bodd_one : bodd 1 = true := rfl lemma bodd_two : bodd 2 = false := rfl @[simp] lemma bodd_succ (n : β„•) : bodd (succ n) = not (bodd n) := by simp only [bodd, boddDiv2] let ⟨b,m⟩ := boddDiv2 n cases b <;> rfl @[simp] lemma bodd_add (m n : β„•) : bodd (m + n) = bxor (bodd m) (bodd n) := by induction n case zero => simp case succ n ih => simp [← Nat.add_assoc, Bool.xor_not, ih] @[simp] lemma bodd_mul (m n : β„•) : bodd (m * n) = (bodd m && bodd n) := by induction n with | zero => simp | succ n IH => simp only [mul_succ, bodd_add, IH, bodd_succ] cases bodd m <;> cases bodd n <;> rfl lemma mod_two_of_bodd (n : β„•) : n % 2 = (bodd n).toNat := by have := congr_arg bodd (mod_add_div n 2) simp? [not] at this says simp only [bodd_add, bodd_mul, bodd_succ, not, bodd_zero, Bool.false_and, Bool.bne_false] at this have _ : βˆ€ b, and false b = false := by intro b cases b <;> rfl have _ : βˆ€ b, bxor b false = b := by intro b cases b <;> rfl rw [← this] rcases mod_two_eq_zero_or_one n with h | h <;> rw [h] <;> rfl @[simp] lemma div2_zero : div2 0 = 0 := rfl @[simp] lemma div2_one : div2 1 = 0 := rfl lemma div2_two : div2 2 = 1 := rfl @[simp] lemma div2_succ (n : β„•) : div2 (n + 1) = cond (bodd n) (succ (div2 n)) (div2 n) := by simp only [bodd, boddDiv2, div2] rcases boddDiv2 n with ⟨_|_, _⟩ <;> simp attribute [local simp] Nat.add_comm Nat.add_assoc Nat.add_left_comm Nat.mul_comm Nat.mul_assoc lemma bodd_add_div2 : βˆ€ n, (bodd n).toNat + 2 * div2 n = n | 0 => rfl | succ n => by simp only [bodd_succ, Bool.cond_not, div2_succ, Nat.mul_comm] refine Eq.trans ?_ (congr_arg succ (bodd_add_div2 n)) cases bodd n Β· simp Β· simp; omega lemma div2_val (n) : div2 n = n / 2 := by refine Nat.eq_of_mul_eq_mul_left (by decide) (Nat.add_left_cancel (Eq.trans ?_ (Nat.mod_add_div n 2).symm)) rw [mod_two_of_bodd, bodd_add_div2] lemma bit_decomp (n : Nat) : bit (bodd n) (div2 n) = n := (bit_val _ _).trans <| (Nat.add_comm _ _).trans <| bodd_add_div2 _ lemma bit_zero : bit false 0 = 0 := rfl /-- `shiftLeft' b m n` performs a left shift of `m` `n` times and adds the bit `b` as the least significant bit each time. Returns the corresponding natural number -/ def shiftLeft' (b : Bool) (m : β„•) : β„• β†’ β„• | 0 => m | n + 1 => bit b (shiftLeft' b m n) @[simp] lemma shiftLeft'_false : βˆ€ n, shiftLeft' false m n = m <<< n | 0 => rfl | n + 1 => by have : 2 * (m * 2^n) = 2^(n+1)*m := by rw [Nat.mul_comm, Nat.mul_assoc, ← Nat.pow_succ]; simp simp [shiftLeft_eq, shiftLeft', bit_val, shiftLeft'_false, this] /-- Lean takes the unprimed name for `Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n`. -/ @[simp] lemma shiftLeft_eq' (m n : Nat) : shiftLeft m n = m <<< n := rfl @[simp] lemma shiftRight_eq (m n : Nat) : shiftRight m n = m >>> n := rfl lemma binaryRec_decreasing (h : n β‰  0) : div2 n < n := by rw [div2_val] apply (div_lt_iff_lt_mul <| succ_pos 1).2 have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1) (lt_of_le_of_ne n.zero_le h.symm) rwa [Nat.mul_one] at this /-- `size n` : Returns the size of a natural number in bits i.e. the length of its binary representation -/ def size : β„• β†’ β„• := binaryRec 0 fun _ _ => succ /-- `bits n` returns a list of Bools which correspond to the binary representation of n, where the head of the list represents the least significant bit -/ def bits : β„• β†’ List Bool := binaryRec [] fun b _ IH => b :: IH /-- `ldiff a b` performs bitwise set difference. For each corresponding pair of bits taken as booleans, say `aα΅’` and `bα΅’`, it applies the boolean operation `aα΅’ ∧ Β¬bα΅’` to obtain the `iα΅—Κ°` bit of the result. -/ def ldiff : β„• β†’ β„• β†’ β„• := bitwise fun a b => a && not b /-! bitwise ops -/ lemma bodd_bit (b n) : bodd (bit b n) = b := by rw [bit_val] simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false, Bool.not_true, Bool.and_false, Bool.xor_false] cases b <;> cases bodd n <;> rfl lemma div2_bit (b n) : div2 (bit b n) = n := by rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add] <;> cases b <;> decide lemma shiftLeft'_add (b m n) : βˆ€ k, shiftLeft' b m (n + k) = shiftLeft' b (shiftLeft' b m n) k | 0 => rfl | k + 1 => congr_arg (bit b) (shiftLeft'_add b m n k) lemma shiftLeft'_sub (b m) : βˆ€ {n k}, k ≀ n β†’ shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k | _, 0, _ => rfl | n + 1, k + 1, h => by rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add] simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero] simp [← div2_val, div2_bit] lemma shiftLeft_sub : βˆ€ (m : Nat) {n k}, k ≀ n β†’ m <<< (n - k) = (m <<< n) >>> k := fun _ _ _ hk => by simp only [← shiftLeft'_false, shiftLeft'_sub false _ hk] lemma bodd_eq_one_and_ne_zero : βˆ€ n, bodd n = (1 &&& n != 0) | 0 => rfl | 1 => rfl | n + 2 => by simpa using bodd_eq_one_and_ne_zero n lemma testBit_bit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by simp only [shiftRight_eq_div_pow] simp [← div2_val, div2_bit] rw [← shiftRight_add, Nat.add_comm] at this simp only [bodd_eq_one_and_ne_zero] at this exact this /-! ### `boddDiv2_eq` and `bodd` -/ @[simp] theorem boddDiv2_eq (n : β„•) : boddDiv2 n = (bodd n, div2 n) := rfl @[simp] theorem div2_bit0 (n) : div2 (2 * n) = n := div2_bit false n -- simp can prove this theorem div2_bit1 (n) : div2 (2 * n + 1) = n := div2_bit true n /-! ### `bit0` and `bit1` -/ theorem bit_add : βˆ€ (b : Bool) (n m : β„•), bit b (n + m) = bit false n + bit b m | true, _, _ => by dsimp [bit]; omega | false, _, _ => by dsimp [bit]; omega theorem bit_add' : βˆ€ (b : Bool) (n m : β„•), bit b (n + m) = bit b n + bit false m | true, _, _ => by dsimp [bit]; omega | false, _, _ => by dsimp [bit]; omega theorem bit_ne_zero (b) {n} (h : n β‰  0) : bit b n β‰  0 := by cases b <;> dsimp [bit] <;> omega @[simp] theorem bitCasesOn_bit0 {motive : β„• β†’ Sort u} (H : βˆ€ b n, motive (bit b n)) (n : β„•) : bitCasesOn (2 * n) H = H false n := bitCasesOn_bit H false n @[simp] theorem bitCasesOn_bit1 {motive : β„• β†’ Sort u} (H : βˆ€ b n, motive (bit b n)) (n : β„•) : bitCasesOn (2 * n + 1) H = H true n := bitCasesOn_bit H true n theorem bit_cases_on_injective {motive : β„• β†’ Sort u} : Function.Injective fun H : βˆ€ b n, motive (bit b n) => fun n => bitCasesOn n H := by intro H₁ Hβ‚‚ h ext b n simpa only [bitCasesOn_bit] using congr_fun h (bit b n) @[simp] theorem bit_cases_on_inj {motive : β„• β†’ Sort u} (H₁ Hβ‚‚ : βˆ€ b n, motive (bit b n)) : ((fun n => bitCasesOn n H₁) = fun n => bitCasesOn n Hβ‚‚) ↔ H₁ = Hβ‚‚ := bit_cases_on_injective.eq_iff lemma bit_le : βˆ€ (b : Bool) {m n : β„•}, m ≀ n β†’ bit b m ≀ bit b n | true, _, _, h => by dsimp [bit]; omega | false, _, _, h => by dsimp [bit]; omega lemma bit_lt_bit (a b) (h : m < n) : bit a m < bit b n := calc bit a m < 2 * n := by cases a <;> dsimp [bit] <;> omega _ ≀ bit b n := by cases b <;> dsimp [bit] <;> omega @[simp] theorem zero_bits : bits 0 = [] := by simp [Nat.bits] @[simp] theorem bits_append_bit (n : β„•) (b : Bool) (hn : n = 0 β†’ b = true) : (bit b n).bits = b :: n.bits := by rw [Nat.bits, Nat.bits, binaryRec_eq] simpa @[simp] theorem bit0_bits (n : β„•) (hn : n β‰  0) : (2 * n).bits = false :: n.bits := bits_append_bit n false fun hn' => absurd hn' hn @[simp] theorem bit1_bits (n : β„•) : (2 * n + 1).bits = true :: n.bits := bits_append_bit n true fun _ => rfl @[simp] theorem one_bits : Nat.bits 1 = [true] := by convert bit1_bits 0 simp -- TODO Find somewhere this can live. -- example : bits 3423 = [true, true, true, true, true, false, true, false, true, false, true, true] -- := by norm_num theorem bodd_eq_bits_head (n : β„•) : n.bodd = n.bits.headI := by induction n using Nat.binaryRec' with | z => simp | f _ _ h _ => simp [bodd_bit, bits_append_bit _ _ h] theorem div2_bits_eq_tail (n : β„•) : n.div2.bits = n.bits.tail := by induction n using Nat.binaryRec' with | z => simp | f _ _ h _ => simp [div2_bit, bits_append_bit _ _ h] end Nat
Mathlib/Data/Nat/Bits.lean
546
560
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Bilinear import Mathlib.Algebra.Algebra.Opposite import Mathlib.Algebra.Group.Pointwise.Finset.Basic import Mathlib.Algebra.Group.Pointwise.Set.BigOperators import Mathlib.Algebra.Module.Submodule.Pointwise import Mathlib.Algebra.Ring.NonZeroDivisors import Mathlib.Algebra.Ring.Submonoid.Pointwise import Mathlib.Data.Set.Semiring import Mathlib.GroupTheory.GroupAction.SubMulAction.Pointwise /-! # Multiplication and division of submodules of an algebra. An interface for multiplication and division of sub-R-modules of an R-algebra A is developed. ## Main definitions Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra. * `1 : Submodule R A` : the R-submodule R of the R-algebra A * `Mul (Submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be the smallest submodule containing all the products `m * n`. * `Div (Submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such that `a β€’ J βŠ† I` It is proved that `Submodule R A` is a semiring, and also an algebra over `Set A`. Additionally, in the `Pointwise` locale we promote `Submodule.pointwiseDistribMulAction` to a `MulSemiringAction` as `Submodule.pointwiseMulSemiringAction`. When `R` is not necessarily commutative, and `A` is merely a `R`-module with a ring structure such that `IsScalarTower R A A` holds (equivalent to the data of a ring homomorphism `R β†’+* A` by `ringHomEquivModuleIsScalarTower`), we can still define `1 : Submodule R A` and `Mul (Submodule R A)`, but `1` is only a left identity, not necessarily a right one. ## Tags multiplication of submodules, division of submodules, submodule semiring -/ universe uΞΉ u v open Algebra Set MulOpposite open Pointwise namespace SubMulAction variable {R : Type u} {A : Type v} [CommSemiring R] [Semiring A] [Algebra R A] theorem algebraMap_mem (r : R) : algebraMap R A r ∈ (1 : SubMulAction R A) := ⟨r, (algebraMap_eq_smul_one r).symm⟩ theorem mem_one' {x : A} : x ∈ (1 : SubMulAction R A) ↔ βˆƒ y, algebraMap R A y = x := exists_congr fun r => by rw [algebraMap_eq_smul_one] end SubMulAction namespace Submodule section Module variable {R : Type u} [Semiring R] {A : Type v} [Semiring A] [Module R A] -- TODO: Why is this in a file about `Algebra`? -- TODO: potentially change this back to `LinearMap.range (Algebra.linearMap R A)` -- once a version of `Algebra` without the `commutes'` field is introduced. -- See issue https://github.com/leanprover-community/mathlib4/issues/18110. /-- `1 : Submodule R A` is the submodule `R βˆ™ 1` of `A`. -/ instance one : One (Submodule R A) := ⟨LinearMap.range (LinearMap.toSpanSingleton R A 1)⟩ theorem one_eq_span : (1 : Submodule R A) = R βˆ™ 1 := (LinearMap.span_singleton_eq_range _ _ _).symm theorem le_one_toAddSubmonoid : 1 ≀ (1 : Submodule R A).toAddSubmonoid := by rintro x ⟨n, rfl⟩ exact ⟨n, show (n : R) β€’ (1 : A) = n by rw [Nat.cast_smul_eq_nsmul, nsmul_one]⟩ @[simp] theorem toSubMulAction_one : (1 : Submodule R A).toSubMulAction = 1 := SetLike.ext fun _ ↦ by rw [one_eq_span, SubMulAction.mem_one]; exact mem_span_singleton theorem one_eq_span_one_set : (1 : Submodule R A) = span R 1 := one_eq_span @[simp] theorem one_le {P : Submodule R A} : (1 : Submodule R A) ≀ P ↔ (1 : A) ∈ P := by simp [one_eq_span] variable {M : Type*} [AddCommMonoid M] [Module R M] [Module A M] [IsScalarTower R A M] instance : SMul (Submodule R A) (Submodule R M) where smul A' M' := { __ := A'.toAddSubmonoid β€’ M'.toAddSubmonoid smul_mem' := fun r m hm ↦ AddSubmonoid.smul_induction_on hm (fun a ha m hm ↦ by rw [← smul_assoc]; exact AddSubmonoid.smul_mem_smul (A'.smul_mem r ha) hm) fun m₁ mβ‚‚ h₁ hβ‚‚ ↦ by rw [smul_add]; exact (A'.1 β€’ M'.1).add_mem h₁ hβ‚‚ } section variable {I J : Submodule R A} {N P : Submodule R M} theorem smul_toAddSubmonoid : (I β€’ N).toAddSubmonoid = I.toAddSubmonoid β€’ N.toAddSubmonoid := rfl theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r β€’ n ∈ I β€’ N := AddSubmonoid.smul_mem_smul hr hn theorem smul_le : I β€’ N ≀ P ↔ βˆ€ r ∈ I, βˆ€ n ∈ N, r β€’ n ∈ P := AddSubmonoid.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set A) β€’ N = I β€’ N := set_smul_eq_of_le _ _ _ (fun _ _ hr hx ↦ smul_mem_smul hr hx) (smul_le.mpr fun _ hr _ hx ↦ mem_set_smul_of_mem_mem hr hx) @[elab_as_elim] theorem smul_induction_on {p : M β†’ Prop} {x} (H : x ∈ I β€’ N) (smul : βˆ€ r ∈ I, βˆ€ n ∈ N, p (r β€’ n)) (add : βˆ€ x y, p x β†’ p y β†’ p (x + y)) : p x := AddSubmonoid.smul_induction_on H smul add /-- Dependent version of `Submodule.smul_induction_on`. -/ @[elab_as_elim] theorem smul_induction_on' {x : M} (hx : x ∈ I β€’ N) {p : βˆ€ x, x ∈ I β€’ N β†’ Prop} (smul : βˆ€ (r : A) (hr : r ∈ I) (n : M) (hn : n ∈ N), p (r β€’ n) (smul_mem_smul hr hn)) (add : βˆ€ x hx y hy, p x hx β†’ p y hy β†’ p (x + y) (add_mem β€Ή_β€Ί β€Ή_β€Ί)) : p x hx := by refine Exists.elim ?_ fun (h : x ∈ I β€’ N) (H : p x h) ↦ H exact smul_induction_on hx (fun a ha x hx ↦ ⟨_, smul _ ha _ hx⟩) fun x y ⟨_, hx⟩ ⟨_, hy⟩ ↦ ⟨_, add _ _ _ _ hx hy⟩ theorem smul_mono (hij : I ≀ J) (hnp : N ≀ P) : I β€’ N ≀ J β€’ P := AddSubmonoid.smul_le_smul hij hnp theorem smul_mono_left (h : I ≀ J) : I β€’ N ≀ J β€’ N := smul_mono h le_rfl instance : CovariantClass (Submodule R A) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => smul_mono le_rfl⟩ variable (I J N P) @[simp] theorem smul_bot : I β€’ (βŠ₯ : Submodule R M) = βŠ₯ := toAddSubmonoid_injective <| AddSubmonoid.addSubmonoid_smul_bot _ @[simp] theorem bot_smul : (βŠ₯ : Submodule R A) β€’ N = βŠ₯ := le_bot_iff.mp <| smul_le.mpr <| by rintro _ rfl _ _; rw [zero_smul]; exact zero_mem _ theorem smul_sup : I β€’ (N βŠ” P) = I β€’ N βŠ” I β€’ P := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, sup_toAddSubmonoid, AddSubmonoid.addSubmonoid_smul_sup] theorem sup_smul : (I βŠ” J) β€’ N = I β€’ N βŠ” J β€’ N := le_antisymm (smul_le.mpr fun mn hmn p hp ↦ by obtain ⟨m, hm, n, hn, rfl⟩ := mem_sup.mp hmn rw [add_smul]; exact add_mem_sup (smul_mem_smul hm hp) <| smul_mem_smul hn hp) (sup_le (smul_mono_left le_sup_left) <| smul_mono_left le_sup_right) protected theorem smul_assoc {B} [Semiring B] [Module R B] [Module A B] [Module B M] [IsScalarTower R A B] [IsScalarTower R B M] [IsScalarTower A B M] (I : Submodule R A) (J : Submodule R B) (N : Submodule R M) : (I β€’ J) β€’ N = I β€’ J β€’ N := le_antisymm (smul_le.2 fun _ hrsij t htn ↦ smul_induction_on hrsij (fun r hr s hs ↦ smul_assoc r s t β–Έ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y ↦ (add_smul x y t).symm β–Έ add_mem) (smul_le.2 fun r hr _ hsn ↦ smul_induction_on hsn (fun j hj n hn ↦ (smul_assoc r j n).symm β–Έ smul_mem_smul (smul_mem_smul hr hj) hn) fun m₁ mβ‚‚ ↦ (smul_add r m₁ mβ‚‚) β–Έ add_mem) theorem smul_iSup {ΞΉ : Sort*} {I : Submodule R A} {t : ΞΉ β†’ Submodule R M} : I β€’ (⨆ i, t i)= ⨆ i, I β€’ t i := toAddSubmonoid_injective <| by simp only [smul_toAddSubmonoid, iSup_toAddSubmonoid, AddSubmonoid.smul_iSup] theorem iSup_smul {ΞΉ : Sort*} {t : ΞΉ β†’ Submodule R A} {N : Submodule R M} : (⨆ i, t i) β€’ N = ⨆ i, t i β€’ N := le_antisymm (smul_le.mpr fun t ht s hs ↦ iSup_induction _ (motive := (Β· β€’ s ∈ _)) ht (fun i t ht ↦ mem_iSup_of_mem i <| smul_mem_smul ht hs) (by simp_rw [zero_smul]; apply zero_mem) fun x y ↦ by simp_rw [add_smul]; apply add_mem) (iSup_le fun i ↦ Submodule.smul_mono_left <| le_iSup _ i) protected theorem one_smul : (1 : Submodule R A) β€’ N = N := by refine le_antisymm (smul_le.mpr fun r hr m hm ↦ ?_) fun m hm ↦ ?_ Β· obtain ⟨r, rfl⟩ := hr rw [LinearMap.toSpanSingleton_apply, smul_one_smul]; exact N.smul_mem r hm Β· rw [← one_smul A m]; exact smul_mem_smul (one_le.mp le_rfl) hm theorem smul_subset_smul : (↑I : Set A) β€’ (↑N : Set M) βŠ† (↑(I β€’ N) : Set M) := AddSubmonoid.smul_subset_smul end variable [IsScalarTower R A A] /-- Multiplication of sub-R-modules of an R-module A that is also a semiring. The submodule `M * N` consists of finite sums of elements `m * n` for `m ∈ M` and `n ∈ N`. -/ instance mul : Mul (Submodule R A) where mul := (Β· β€’ Β·) variable (S T : Set A) {M N P Q : Submodule R A} {m n : A} theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := smul_mem_smul hm hn theorem mul_le : M * N ≀ P ↔ βˆ€ m ∈ M, βˆ€ n ∈ N, m * n ∈ P := smul_le theorem mul_toAddSubmonoid (M N : Submodule R A) : (M * N).toAddSubmonoid = M.toAddSubmonoid * N.toAddSubmonoid := rfl @[elab_as_elim] protected theorem mul_induction_on {C : A β†’ Prop} {r : A} (hr : r ∈ M * N) (hm : βˆ€ m ∈ M, βˆ€ n ∈ N, C (m * n)) (ha : βˆ€ x y, C x β†’ C y β†’ C (x + y)) : C r := smul_induction_on hr hm ha /-- A dependent version of `mul_induction_on`. -/ @[elab_as_elim] protected theorem mul_induction_on' {C : βˆ€ r, r ∈ M * N β†’ Prop} (mem_mul_mem : βˆ€ m (hm : m ∈ M) n (hn : n ∈ N), C (m * n) (mul_mem_mul hm hn)) (add : βˆ€ x hx y hy, C x hx β†’ C y hy β†’ C (x + y) (add_mem hx hy)) {r : A} (hr : r ∈ M * N) : C r hr := smul_induction_on' hr mem_mul_mem add variable (M) @[simp] theorem mul_bot : M * βŠ₯ = βŠ₯ := smul_bot _ @[simp] theorem bot_mul : βŠ₯ * M = βŠ₯ := bot_smul _ protected theorem one_mul : (1 : Submodule R A) * M = M := Submodule.one_smul _ variable {M} @[mono] theorem mul_le_mul (hmp : M ≀ P) (hnq : N ≀ Q) : M * N ≀ P * Q := smul_mono hmp hnq theorem mul_le_mul_left (h : M ≀ N) : M * P ≀ N * P := smul_mono_left h theorem mul_le_mul_right (h : N ≀ P) : M * N ≀ M * P := smul_mono_right _ h theorem mul_comm_of_commute (h : βˆ€ m ∈ M, βˆ€ n ∈ N, Commute m n) : M * N = N * M := toAddSubmonoid_injective <| AddSubmonoid.mul_comm_of_commute h variable (M N P) theorem mul_sup : M * (N βŠ” P) = M * N βŠ” M * P := smul_sup _ _ _ theorem sup_mul : (M βŠ” N) * P = M * P βŠ” N * P := sup_smul _ _ _ theorem mul_subset_mul : (↑M : Set A) * (↑N : Set A) βŠ† (↑(M * N) : Set A) := smul_subset_smul _ _ lemma restrictScalars_mul {A B C} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I J : Submodule B C} : (I * J).restrictScalars A = I.restrictScalars A * J.restrictScalars A := rfl variable {ΞΉ : Sort uΞΉ} theorem iSup_mul (s : ΞΉ β†’ Submodule R A) (t : Submodule R A) : (⨆ i, s i) * t = ⨆ i, s i * t := iSup_smul theorem mul_iSup (t : Submodule R A) (s : ΞΉ β†’ Submodule R A) : (t * ⨆ i, s i) = ⨆ i, t * s i := smul_iSup /-- Sub-`R`-modules of an `R`-module form an idempotent semiring. -/ instance : NonUnitalSemiring (Submodule R A) where __ := toAddSubmonoid_injective.semigroup _ mul_toAddSubmonoid zero_mul := bot_mul mul_zero := mul_bot left_distrib := mul_sup right_distrib := sup_mul instance : Pow (Submodule R A) β„• where pow s n := npowRec n s theorem pow_eq_npowRec {n : β„•} : M ^ n = npowRec n M := rfl protected theorem pow_zero : M ^ 0 = 1 := rfl protected theorem pow_succ {n : β„•} : M ^ (n + 1) = M ^ n * M := rfl protected theorem pow_add {m n : β„•} (h : n β‰  0) : M ^ (m + n) = M ^ m * M ^ n := npowRec_add m n h _ M.one_mul protected theorem pow_one : M ^ 1 = M := by rw [Submodule.pow_succ, Submodule.pow_zero, Submodule.one_mul] /-- `Submodule.pow_succ` with the right hand side commuted. -/ protected theorem pow_succ' {n : β„•} (h : n β‰  0) : M ^ (n + 1) = M * M ^ n := by rw [add_comm, M.pow_add h, Submodule.pow_one] theorem pow_toAddSubmonoid {n : β„•} (h : n β‰  0) : (M ^ n).toAddSubmonoid = M.toAddSubmonoid ^ n := by induction n with | zero => exact (h rfl).elim | succ n ih => rw [Submodule.pow_succ, pow_succ, mul_toAddSubmonoid] cases n with | zero => rw [Submodule.pow_zero, pow_zero, one_mul, ← mul_toAddSubmonoid, Submodule.one_mul] | succ n => rw [ih n.succ_ne_zero] theorem le_pow_toAddSubmonoid {n : β„•} : M.toAddSubmonoid ^ n ≀ (M ^ n).toAddSubmonoid := by obtain rfl | hn := Decidable.eq_or_ne n 0 Β· rw [Submodule.pow_zero, pow_zero] exact le_one_toAddSubmonoid Β· exact (pow_toAddSubmonoid M hn).ge theorem pow_subset_pow {n : β„•} : (↑M : Set A) ^ n βŠ† ↑(M ^ n : Submodule R A) := trans AddSubmonoid.pow_subset_pow (le_pow_toAddSubmonoid M) theorem pow_mem_pow {x : A} (hx : x ∈ M) (n : β„•) : x ^ n ∈ M ^ n := pow_subset_pow _ <| Set.pow_mem_pow hx lemma restrictScalars_pow {A B C : Type*} [Semiring A] [Semiring B] [Semiring C] [SMul A B] [Module A C] [Module B C] [IsScalarTower A C C] [IsScalarTower B C C] [IsScalarTower A B C] {I : Submodule B C} : βˆ€ {n : β„•}, (hn : n β‰  0) β†’ (I ^ n).restrictScalars A = I.restrictScalars A ^ n | 1, _ => by simp [Submodule.pow_one] | n + 2, _ => by simp [Submodule.pow_succ (n := n + 1), restrictScalars_mul, restrictScalars_pow n.succ_ne_zero] end Module
variable {ΞΉ : Sort uΞΉ} variable {R : Type u} [CommSemiring R] section AlgebraSemiring variable {A : Type v} [Semiring A] [Algebra R A] variable (S T : Set A) {M N P Q : Submodule R A} {m n : A}
Mathlib/Algebra/Algebra/Operations.lean
345
353
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.FinitePresentation import Mathlib.RingTheory.FiniteStability import Mathlib.RingTheory.Ideal.Cotangent import Mathlib.RingTheory.Ideal.Quotient.Nilpotent import Mathlib.RingTheory.Localization.Away.AdjoinRoot import Mathlib.RingTheory.Localization.Away.Basic import Mathlib.RingTheory.TensorProduct.Basic /-! # Smooth morphisms An `R`-algebra `A` is formally smooth if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B β§Έ I`, there exists at least one lift `A →ₐ[R] B`. It is smooth if it is formally smooth and of finite presentation. We show that the property of being formally smooth extends onto nilpotent ideals, and that it is stable under `R`-algebra homomorphisms and compositions. We show that smooth is stable under algebra isomorphisms, composition and localization at an element. -/ -- Porting note: added to make the syntax work below. open scoped TensorProduct universe u namespace Algebra section variable (R : Type u) [CommSemiring R] variable (A : Type u) [Semiring A] [Algebra R A] /-- An `R` algebra `A` is formally smooth if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B β§Έ I`, there exists at least one lift `A →ₐ[R] B`. -/ @[mk_iff, stacks 00TI] class FormallySmooth : Prop where comp_surjective : βˆ€ ⦃B : Type u⦄ [CommRing B], βˆ€ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = βŠ₯), Function.Surjective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) β†’ A →ₐ[R] B β§Έ I) end namespace FormallySmooth section variable {R : Type u} [CommSemiring R] variable {A : Type u} [Semiring A] [Algebra R A] variable {B : Type u} [CommRing B] [Algebra R B] theorem exists_lift {B : Type u} [CommRing B] [_RB : Algebra R B] [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B β§Έ I) : βˆƒ f : A →ₐ[R] B, (Ideal.Quotient.mkₐ R I).comp f = g := by revert g change Function.Surjective (Ideal.Quotient.mkₐ R I).comp revert _RB apply Ideal.IsNilpotent.induction_on (S := B) I hI Β· intro B _ I hI _; exact FormallySmooth.comp_surjective I hI Β· intro B _ I J hIJ h₁ hβ‚‚ _ g let this : ((B β§Έ I) β§Έ J.map (Ideal.Quotient.mk I)) ≃ₐ[R] B β§Έ J := { (DoubleQuot.quotQuotEquivQuotSup I J).trans (Ideal.quotEquivOfEq (sup_eq_right.mpr hIJ)) with commutes' := fun x => rfl } obtain ⟨g', e⟩ := hβ‚‚ (this.symm.toAlgHom.comp g) obtain ⟨g', rfl⟩ := h₁ g' replace e := congr_arg this.toAlgHom.comp e conv_rhs at e => rw [← AlgHom.comp_assoc, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.comp_symm, AlgHom.id_comp] exact ⟨g', e⟩ /-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B β§Έ I` with `I` square-zero, this is an arbitrary lift `A →ₐ[R] B`. -/ noncomputable def lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B β§Έ I) : A →ₐ[R] B := (FormallySmooth.exists_lift I hI g).choose @[simp] theorem comp_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B β§Έ I) : (Ideal.Quotient.mkₐ R I).comp (FormallySmooth.lift I hI g) = g := (FormallySmooth.exists_lift I hI g).choose_spec @[simp] theorem mk_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B β§Έ I) (x : A) : Ideal.Quotient.mk I (FormallySmooth.lift I hI g x) = g x := AlgHom.congr_fun (FormallySmooth.comp_lift I hI g :) x variable {C : Type u} [CommRing C] [Algebra R C] /-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B β§Έ I` with `I` nilpotent, this is an arbitrary lift `A →ₐ[R] B`. -/ noncomputable def liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B β†’+* C)) : A →ₐ[R] B := FormallySmooth.lift _ hg' ((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f) @[simp] theorem liftOfSurjective_apply [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker g) (x : A) : g (FormallySmooth.liftOfSurjective f g hg hg' x) = f x := by apply (Ideal.quotientKerAlgEquivOfSurjective hg).symm.injective conv_rhs => rw [← AlgHom.coe_coe, ← AlgHom.comp_apply, ← FormallySmooth.mk_lift (A := A) _ hg'] apply (Ideal.quotientKerAlgEquivOfSurjective hg).injective rw [AlgEquiv.apply_symm_apply, Ideal.quotientKerAlgEquivOfSurjective_apply] simp only [liftOfSurjective, ← RingHom.ker_coe_toRingHom g, RingHom.kerLift_mk, AlgEquiv.toAlgHom_eq_coe, RingHom.coe_coe] @[simp] theorem comp_liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B β†’+* C)) : g.comp (FormallySmooth.liftOfSurjective f g hg hg') = f := AlgHom.ext (FormallySmooth.liftOfSurjective_apply f g hg hg') end section OfEquiv variable {R : Type u} [CommSemiring R] variable {A B : Type u} [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] theorem of_equiv [FormallySmooth R A] (e : A ≃ₐ[R] B) : FormallySmooth R B := by constructor intro C _ _ I hI f use (FormallySmooth.lift I ⟨2, hI⟩ (f.comp e : A →ₐ[R] C β§Έ I)).comp e.symm rw [← AlgHom.comp_assoc, FormallySmooth.comp_lift, AlgHom.comp_assoc, AlgEquiv.comp_symm, AlgHom.comp_id] theorem iff_of_equiv (e : A ≃ₐ[R] B) : FormallySmooth R A ↔ FormallySmooth R B := ⟨fun _ ↦ of_equiv e, fun _ ↦ of_equiv e.symm⟩ end OfEquiv section Polynomial open scoped Polynomial
variable (R : Type u) [CommSemiring R] instance mvPolynomial (Οƒ : Type u) : FormallySmooth R (MvPolynomial Οƒ R) := by constructor intro C _ _ I _ f
Mathlib/RingTheory/Smooth/Basic.lean
148
153
/- Copyright (c) 2021 RΓ©my Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, SΓ©bastien GouΓ«zel, RΓ©my Degenne -/ import Mathlib.MeasureTheory.Integral.FinMeasAdditive /-! # Extension of a linear function from indicators to L1 Given `T : Set Ξ± β†’ E β†’L[ℝ] F` with `DominatedFinMeasAdditive ΞΌ T C`, we construct an extension of `T` to integrable simple functions, which are finite sums of indicators of measurable sets with finite measure, then to integrable functions, which are limits of integrable simple functions. The main result is a continuous linear map `(Ξ± →₁[ΞΌ] E) β†’L[ℝ] F`. This extension process is used to define the Bochner integral in the `Mathlib.MeasureTheory.Integral.Bochner.Basic` file and the conditional expectation of an integrable function in `Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1`. ## Main definitions - `setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) : (Ξ± →₁[ΞΌ] E) β†’L[ℝ] F`: the extension of `T` from indicators to L1. - `setToFun ΞΌ T (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β†’ E) : F`: a version of the extension which applies to functions (with value 0 if the function is not integrable). ## Properties For most properties of `setToFun`, we provide two lemmas. One version uses hypotheses valid on all sets, like `T = T'`, and a second version which uses a primed name uses hypotheses on measurable sets with finite measure, like `βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = T' s`. The lemmas listed here don't show all hypotheses. Refer to the actual lemmas for details. Linearity: - `setToFun_zero_left : setToFun ΞΌ 0 hT f = 0` - `setToFun_add_left : setToFun ΞΌ (T + T') _ f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f` - `setToFun_smul_left : setToFun ΞΌ (fun s ↦ c β€’ (T s)) (hT.smul c) f = c β€’ setToFun ΞΌ T hT f` - `setToFun_zero : setToFun ΞΌ T hT (0 : Ξ± β†’ E) = 0` - `setToFun_neg : setToFun ΞΌ T hT (-f) = - setToFun ΞΌ T hT f` If `f` and `g` are integrable: - `setToFun_add : setToFun ΞΌ T hT (f + g) = setToFun ΞΌ T hT f + setToFun ΞΌ T hT g` - `setToFun_sub : setToFun ΞΌ T hT (f - g) = setToFun ΞΌ T hT f - setToFun ΞΌ T hT g` If `T` is verifies `βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x`: - `setToFun_smul : setToFun ΞΌ T hT (c β€’ f) = c β€’ setToFun ΞΌ T hT f` Other: - `setToFun_congr_ae (h : f =ᡐ[ΞΌ] g) : setToFun ΞΌ T hT f = setToFun ΞΌ T hT g` - `setToFun_measure_zero (h : ΞΌ = 0) : setToFun ΞΌ T hT f = 0` If the space is also an ordered additive group with an order closed topology and `T` is such that `0 ≀ T s x` for `0 ≀ x`, we also prove order-related properties: - `setToFun_mono_left (h : βˆ€ s x, T s x ≀ T' s x) : setToFun ΞΌ T hT f ≀ setToFun ΞΌ T' hT' f` - `setToFun_nonneg (hf : 0 ≀ᡐ[ΞΌ] f) : 0 ≀ setToFun ΞΌ T hT f` - `setToFun_mono (hfg : f ≀ᡐ[ΞΌ] g) : setToFun ΞΌ T hT f ≀ setToFun ΞΌ T hT g` -/ noncomputable section open scoped Topology NNReal open Set Filter TopologicalSpace ENNReal namespace MeasureTheory variable {Ξ± E F F' G π•œ : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [NormedAddCommGroup F'] [NormedSpace ℝ F'] [NormedAddCommGroup G] {m : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} namespace L1 open AEEqFun Lp.simpleFunc Lp namespace SimpleFunc theorem norm_eq_sum_mul (f : Ξ± →₁ₛ[ΞΌ] G) : β€–fβ€– = βˆ‘ x ∈ (toSimpleFunc f).range, ΞΌ.real (toSimpleFunc f ⁻¹' {x}) * β€–xβ€– := by rw [norm_toSimpleFunc, eLpNorm_one_eq_lintegral_enorm] have h_eq := SimpleFunc.map_apply (β€–Β·β€–β‚‘) (toSimpleFunc f) simp_rw [← h_eq, measureReal_def] rw [SimpleFunc.lintegral_eq_lintegral, SimpleFunc.map_lintegral, ENNReal.toReal_sum] Β· congr ext1 x rw [ENNReal.toReal_mul, mul_comm, ← ofReal_norm_eq_enorm, ENNReal.toReal_ofReal (norm_nonneg _)] Β· intro x _ by_cases hx0 : x = 0 Β· rw [hx0]; simp Β· exact ENNReal.mul_ne_top ENNReal.coe_ne_top (SimpleFunc.measure_preimage_lt_top_of_integrable _ (SimpleFunc.integrable f) hx0).ne section SetToL1S variable [NormedField π•œ] [NormedSpace π•œ E] attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace /-- Extend `Set Ξ± β†’ (E β†’L[ℝ] F')` to `(Ξ± →₁ₛ[ΞΌ] E) β†’ F'`. -/ def setToL1S (T : Set Ξ± β†’ E β†’L[ℝ] F) (f : Ξ± →₁ₛ[ΞΌ] E) : F := (toSimpleFunc f).setToSimpleFunc T theorem setToL1S_eq_setToSimpleFunc (T : Set Ξ± β†’ E β†’L[ℝ] F) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T f = (toSimpleFunc f).setToSimpleFunc T := rfl @[simp] theorem setToL1S_zero_left (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S (0 : Set Ξ± β†’ E β†’L[ℝ] F) f = 0 := SimpleFunc.setToSimpleFunc_zero _ theorem setToL1S_zero_left' {T : Set Ξ± β†’ E β†’L[ℝ] F} (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = 0) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T f = 0 := SimpleFunc.setToSimpleFunc_zero' h_zero _ (SimpleFunc.integrable f) theorem setToL1S_congr (T : Set Ξ± β†’ E β†’L[ℝ] F) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) {f g : Ξ± →₁ₛ[ΞΌ] E} (h : toSimpleFunc f =ᡐ[ΞΌ] toSimpleFunc g) : setToL1S T f = setToL1S T g := SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) h theorem setToL1S_congr_left (T T' : Set Ξ± β†’ E β†’L[ℝ] F) (h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = T' s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T f = setToL1S T' f := SimpleFunc.setToSimpleFunc_congr_left T T' h (simpleFunc.toSimpleFunc f) (SimpleFunc.integrable f) /-- `setToL1S` does not change if we replace the measure `ΞΌ` by `ΞΌ'` with `ΞΌ β‰ͺ ΞΌ'`. The statement uses two functions `f` and `f'` because they have to belong to different types, but morally these are the same function (we have `f =ᡐ[ΞΌ] f'`). -/ theorem setToL1S_congr_measure {ΞΌ' : Measure Ξ±} (T : Set Ξ± β†’ E β†’L[ℝ] F) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (hΞΌ : ΞΌ β‰ͺ ΞΌ') (f : Ξ± →₁ₛ[ΞΌ] E) (f' : Ξ± →₁ₛ[ΞΌ'] E) (h : (f : Ξ± β†’ E) =ᡐ[ΞΌ] f') : setToL1S T f = setToL1S T f' := by refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable f) ?_ refine (toSimpleFunc_eq_toFun f).trans ?_ suffices (f' : Ξ± β†’ E) =ᡐ[ΞΌ] simpleFunc.toSimpleFunc f' from h.trans this have goal' : (f' : Ξ± β†’ E) =ᡐ[ΞΌ'] simpleFunc.toSimpleFunc f' := (toSimpleFunc_eq_toFun f').symm exact hΞΌ.ae_eq goal' theorem setToL1S_add_left (T T' : Set Ξ± β†’ E β†’L[ℝ] F) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S (T + T') f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left T T' theorem setToL1S_add_left' (T T' T'' : Set Ξ± β†’ E β†’L[ℝ] F) (h_add : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T'' s = T s + T' s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T'' f = setToL1S T f + setToL1S T' f := SimpleFunc.setToSimpleFunc_add_left' T T' T'' h_add (SimpleFunc.integrable f) theorem setToL1S_smul_left (T : Set Ξ± β†’ E β†’L[ℝ] F) (c : ℝ) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S (fun s => c β€’ T s) f = c β€’ setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left T c _ theorem setToL1S_smul_left' (T T' : Set Ξ± β†’ E β†’L[ℝ] F) (c : ℝ) (h_smul : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T' s = c β€’ T s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T' f = c β€’ setToL1S T f := SimpleFunc.setToSimpleFunc_smul_left' T T' c h_smul (SimpleFunc.integrable f) theorem setToL1S_add (T : Set Ξ± β†’ E β†’L[ℝ] F) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (f g : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T (f + g) = setToL1S T f + setToL1S T g := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_add T h_add (SimpleFunc.integrable f) (SimpleFunc.integrable g)] exact SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) (add_toSimpleFunc f g) theorem setToL1S_neg {T : Set Ξ± β†’ E β†’L[ℝ] F} (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T (-f) = -setToL1S T f := by simp_rw [setToL1S] have : simpleFunc.toSimpleFunc (-f) =ᡐ[ΞΌ] ⇑(-simpleFunc.toSimpleFunc f) := neg_toSimpleFunc f rw [SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) this] exact SimpleFunc.setToSimpleFunc_neg T h_add (SimpleFunc.integrable f) theorem setToL1S_sub {T : Set Ξ± β†’ E β†’L[ℝ] F} (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (f g : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T (f - g) = setToL1S T f - setToL1S T g := by rw [sub_eq_add_neg, setToL1S_add T h_zero h_add, setToL1S_neg h_zero h_add, sub_eq_add_neg] theorem setToL1S_smul_real (T : Set Ξ± β†’ E β†’L[ℝ] F) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (c : ℝ) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T (c β€’ f) = c β€’ setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul_real T h_add c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f theorem setToL1S_smul {E} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedSpace π•œ E] [DistribSMul π•œ F] (T : Set Ξ± β†’ E β†’L[ℝ] F) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) (c : π•œ) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T (c β€’ f) = c β€’ setToL1S T f := by simp_rw [setToL1S] rw [← SimpleFunc.setToSimpleFunc_smul T h_add h_smul c (SimpleFunc.integrable f)] refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact smul_toSimpleFunc c f theorem norm_setToL1S_le (T : Set Ξ± β†’ E β†’L[ℝ] F) {C : ℝ} (hT_norm : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ β€–T sβ€– ≀ C * ΞΌ.real s) (f : Ξ± →₁ₛ[ΞΌ] E) : β€–setToL1S T fβ€– ≀ C * β€–fβ€– := by rw [setToL1S, norm_eq_sum_mul f] exact SimpleFunc.norm_setToSimpleFunc_le_sum_mul_norm_of_integrable T hT_norm _ (SimpleFunc.integrable f) theorem setToL1S_indicatorConst {T : Set Ξ± β†’ E β†’L[ℝ] F} {s : Set Ξ±} (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (hs : MeasurableSet s) (hΞΌs : ΞΌ s < ∞) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 hs hΞΌs.ne x) = T s x := by have h_empty : T βˆ… = 0 := h_zero _ MeasurableSet.empty measure_empty rw [setToL1S_eq_setToSimpleFunc] refine Eq.trans ?_ (SimpleFunc.setToSimpleFunc_indicator T h_empty hs x) refine SimpleFunc.setToSimpleFunc_congr T h_zero h_add (SimpleFunc.integrable _) ?_ exact toSimpleFunc_indicatorConst hs hΞΌs.ne x theorem setToL1S_const [IsFiniteMeasure ΞΌ] {T : Set Ξ± β†’ E β†’L[ℝ] F} (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (x : E) : setToL1S T (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ΞΌ _) x) = T univ x := setToL1S_indicatorConst h_zero h_add MeasurableSet.univ (measure_lt_top _ _) x section Order variable {G'' G' : Type*} [NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G'] [NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] {T : Set Ξ± β†’ G'' β†’L[ℝ] G'} theorem setToL1S_mono_left {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} (hTT' : βˆ€ s x, T s x ≀ T' s x) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T f ≀ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ theorem setToL1S_mono_left' {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} (hTT' : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, T s x ≀ T' s x) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1S T f ≀ setToL1S T' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) omit [IsOrderedAddMonoid G''] in theorem setToL1S_nonneg (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f : Ξ± →₁ₛ[ΞΌ] G''} (hf : 0 ≀ f) : 0 ≀ setToL1S T f := by simp_rw [setToL1S] obtain ⟨f', hf', hff'⟩ := exists_simpleFunc_nonneg_ae_eq hf replace hff' : simpleFunc.toSimpleFunc f =ᡐ[ΞΌ] f' := (Lp.simpleFunc.toSimpleFunc_eq_toFun f).trans hff' rw [SimpleFunc.setToSimpleFunc_congr _ h_zero h_add (SimpleFunc.integrable _) hff'] exact SimpleFunc.setToSimpleFunc_nonneg' T hT_nonneg _ hf' ((SimpleFunc.integrable f).congr hff') theorem setToL1S_mono (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s = 0 β†’ T s = 0) (h_add : FinMeasAdditive ΞΌ T) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f g : Ξ± →₁ₛ[ΞΌ] G''} (hfg : f ≀ g) : setToL1S T f ≀ setToL1S T g := by rw [← sub_nonneg] at hfg ⊒ rw [← setToL1S_sub h_zero h_add] exact setToL1S_nonneg h_zero h_add hT_nonneg hfg end Order variable [NormedSpace π•œ F] variable (Ξ± E ΞΌ π•œ) /-- Extend `Set Ξ± β†’ E β†’L[ℝ] F` to `(Ξ± →₁ₛ[ΞΌ] E) β†’L[π•œ] F`. -/ def setToL1SCLM' {T : Set Ξ± β†’ E β†’L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) : (Ξ± →₁ₛ[ΞΌ] E) β†’L[π•œ] F := LinearMap.mkContinuous ⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul T (fun _ => hT.eq_zero_of_measure_zero) hT.1 h_smul⟩ C fun f => norm_setToL1S_le T hT.2 f /-- Extend `Set Ξ± β†’ E β†’L[ℝ] F` to `(Ξ± →₁ₛ[ΞΌ] E) β†’L[ℝ] F`. -/ def setToL1SCLM {T : Set Ξ± β†’ E β†’L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) : (Ξ± →₁ₛ[ΞΌ] E) β†’L[ℝ] F := LinearMap.mkContinuous ⟨⟨setToL1S T, setToL1S_add T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩, setToL1S_smul_real T (fun _ => hT.eq_zero_of_measure_zero) hT.1⟩ C fun f => norm_setToL1S_le T hT.2 f variable {Ξ± E ΞΌ π•œ} variable {T T' T'' : Set Ξ± β†’ E β†’L[ℝ] F} {C C' C'' : ℝ} @[simp] theorem setToL1SCLM_zero_left (hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β†’ E β†’L[ℝ] F) C) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = 0 := setToL1S_zero_left _ theorem setToL1SCLM_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = 0) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = 0 := setToL1S_zero_left' h_zero f theorem setToL1SCLM_congr_left (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T') (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ hT' f := setToL1S_congr_left T T' (fun _ _ _ => by rw [h]) f theorem setToL1SCLM_congr_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = T' s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ hT' f := setToL1S_congr_left T T' h f theorem setToL1SCLM_congr_measure {ΞΌ' : Measure Ξ±} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ' T C') (hΞΌ : ΞΌ β‰ͺ ΞΌ') (f : Ξ± →₁ₛ[ΞΌ] E) (f' : Ξ± →₁ₛ[ΞΌ'] E) (h : (f : Ξ± β†’ E) =ᡐ[ΞΌ] f') : setToL1SCLM Ξ± E ΞΌ hT f = setToL1SCLM Ξ± E ΞΌ' hT' f' := setToL1S_congr_measure T (fun _ => hT.eq_zero_of_measure_zero) hT.1 hΞΌ _ _ h theorem setToL1SCLM_add_left (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ (hT.add hT') f = setToL1SCLM Ξ± E ΞΌ hT f + setToL1SCLM Ξ± E ΞΌ hT' f := setToL1S_add_left T T' f theorem setToL1SCLM_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'') (h_add : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T'' s = T s + T' s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT'' f = setToL1SCLM Ξ± E ΞΌ hT f + setToL1SCLM Ξ± E ΞΌ hT' f := setToL1S_add_left' T T' T'' h_add f theorem setToL1SCLM_smul_left (c : ℝ) (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ (hT.smul c) f = c β€’ setToL1SCLM Ξ± E ΞΌ hT f := setToL1S_smul_left T c f theorem setToL1SCLM_smul_left' (c : ℝ) (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h_smul : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T' s = c β€’ T s) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT' f = c β€’ setToL1SCLM Ξ± E ΞΌ hT f := setToL1S_smul_left' T T' c h_smul f theorem norm_setToL1SCLM_le {T : Set Ξ± β†’ E β†’L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hC : 0 ≀ C) : β€–setToL1SCLM Ξ± E ΞΌ hTβ€– ≀ C := LinearMap.mkContinuous_norm_le _ hC _ theorem norm_setToL1SCLM_le' {T : Set Ξ± β†’ E β†’L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) : β€–setToL1SCLM Ξ± E ΞΌ hTβ€– ≀ max C 0 := LinearMap.mkContinuous_norm_le' _ _ theorem setToL1SCLM_const [IsFiniteMeasure ΞΌ] {T : Set Ξ± β†’ E β†’L[ℝ] F} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) : setToL1SCLM Ξ± E ΞΌ hT (simpleFunc.indicatorConst 1 MeasurableSet.univ (measure_ne_top ΞΌ _) x) = T univ x := setToL1S_const (fun _ => hT.eq_zero_of_measure_zero) hT.1 x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [NormedAddCommGroup G'] [PartialOrder G'] [IsOrderedAddMonoid G'] [NormedSpace ℝ G'] theorem setToL1SCLM_mono_left {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s x, T s x ≀ T' s x) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f ≀ setToL1SCLM Ξ± E ΞΌ hT' f := SimpleFunc.setToSimpleFunc_mono_left T T' hTT' _ theorem setToL1SCLM_mono_left' {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, T s x ≀ T' s x) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1SCLM Ξ± E ΞΌ hT f ≀ setToL1SCLM Ξ± E ΞΌ hT' f := SimpleFunc.setToSimpleFunc_mono_left' T T' hTT' _ (SimpleFunc.integrable f) omit [IsOrderedAddMonoid G'] in theorem setToL1SCLM_nonneg {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f : Ξ± →₁ₛ[ΞΌ] G'} (hf : 0 ≀ f) : 0 ≀ setToL1SCLM Ξ± G' ΞΌ hT f := setToL1S_nonneg (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hf theorem setToL1SCLM_mono {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f g : Ξ± →₁ₛ[ΞΌ] G'} (hfg : f ≀ g) : setToL1SCLM Ξ± G' ΞΌ hT f ≀ setToL1SCLM Ξ± G' ΞΌ hT g := setToL1S_mono (fun _ => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg hfg end Order end SetToL1S end SimpleFunc open SimpleFunc section SetToL1 attribute [local instance] Lp.simpleFunc.module attribute [local instance] Lp.simpleFunc.normedSpace variable (π•œ) [NontriviallyNormedField π•œ] [NormedSpace π•œ E] [NormedSpace π•œ F] [CompleteSpace F] {T T' T'' : Set Ξ± β†’ E β†’L[ℝ] F} {C C' C'' : ℝ} /-- Extend `Set Ξ± β†’ (E β†’L[ℝ] F)` to `(Ξ± →₁[ΞΌ] E) β†’L[π•œ] F`. -/ def setToL1' (hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) : (Ξ± →₁[ΞΌ] E) β†’L[π•œ] F := (setToL1SCLM' Ξ± E π•œ ΞΌ hT h_smul).extend (coeToLp Ξ± E π•œ) (simpleFunc.denseRange one_ne_top) simpleFunc.isUniformInducing variable {π•œ} /-- Extend `Set Ξ± β†’ E β†’L[ℝ] F` to `(Ξ± →₁[ΞΌ] E) β†’L[ℝ] F`. -/ def setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) : (Ξ± →₁[ΞΌ] E) β†’L[ℝ] F := (setToL1SCLM Ξ± E ΞΌ hT).extend (coeToLp Ξ± E ℝ) (simpleFunc.denseRange one_ne_top) simpleFunc.isUniformInducing theorem setToL1_eq_setToL1SCLM (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁ₛ[ΞΌ] E) : setToL1 hT f = setToL1SCLM Ξ± E ΞΌ hT f := uniformly_extend_of_ind simpleFunc.isUniformInducing (simpleFunc.denseRange one_ne_top) (setToL1SCLM Ξ± E ΞΌ hT).uniformContinuous _ theorem setToL1_eq_setToL1' (hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f = setToL1' π•œ hT h_smul f := rfl @[simp] theorem setToL1_zero_left (hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β†’ E β†’L[ℝ] F) C) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left hT f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] theorem setToL1_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = 0) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f = 0 := by suffices setToL1 hT = 0 by rw [this]; simp refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_ ext1 f rw [setToL1SCLM_zero_left' hT h_zero f, ContinuousLinearMap.zero_comp, ContinuousLinearMap.zero_apply] theorem setToL1_congr_left (T T' : Set Ξ± β†’ E β†’L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T') (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM] exact setToL1SCLM_congr_left hT' hT h.symm f theorem setToL1_congr_left' (T T' : Set Ξ± β†’ E β†’L[ℝ] F) {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = T' s) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f = setToL1 hT' f := by suffices setToL1 hT = setToL1 hT' by rw [this] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT) _ _ _ _ ?_ ext1 f suffices setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM] exact (setToL1SCLM_congr_left' hT hT' h f).symm theorem setToL1_add_left (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± →₁[ΞΌ] E) : setToL1 (hT.add hT') f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 (hT.add hT') = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ (hT.add hT')) _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ (hT.add hT') f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left hT hT'] theorem setToL1_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'') (h_add : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T'' s = T s + T' s) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT'' f = setToL1 hT f + setToL1 hT' f := by suffices setToL1 hT'' = setToL1 hT + setToL1 hT' by rw [this, ContinuousLinearMap.add_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT'') _ _ _ _ ?_ ext1 f suffices setToL1 hT f + setToL1 hT' f = setToL1SCLM Ξ± E ΞΌ hT'' f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1_eq_setToL1SCLM, setToL1SCLM_add_left' hT hT' hT'' h_add] theorem setToL1_smul_left (hT : DominatedFinMeasAdditive ΞΌ T C) (c : ℝ) (f : Ξ± →₁[ΞΌ] E) : setToL1 (hT.smul c) f = c β€’ setToL1 hT f := by suffices setToL1 (hT.smul c) = c β€’ setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ (hT.smul c)) _ _ _ _ ?_ ext1 f suffices c β€’ setToL1 hT f = setToL1SCLM Ξ± E ΞΌ (hT.smul c) f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left c hT] theorem setToL1_smul_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (c : ℝ) (h_smul : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T' s = c β€’ T s) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT' f = c β€’ setToL1 hT f := by suffices setToL1 hT' = c β€’ setToL1 hT by rw [this, ContinuousLinearMap.smul_apply] refine ContinuousLinearMap.extend_unique (setToL1SCLM Ξ± E ΞΌ hT') _ _ _ _ ?_ ext1 f suffices c β€’ setToL1 hT f = setToL1SCLM Ξ± E ΞΌ hT' f by rw [← this]; simp [coeToLp] rw [setToL1_eq_setToL1SCLM, setToL1SCLM_smul_left' c hT hT' h_smul] theorem setToL1_smul (hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) (c : π•œ) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT (c β€’ f) = c β€’ setToL1 hT f := by rw [setToL1_eq_setToL1' hT h_smul, setToL1_eq_setToL1' hT h_smul] exact ContinuousLinearMap.map_smul _ _ _ theorem setToL1_simpleFunc_indicatorConst (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±} (hs : MeasurableSet s) (hΞΌs : ΞΌ s < ∞) (x : E) : setToL1 hT (simpleFunc.indicatorConst 1 hs hΞΌs.ne x) = T s x := by rw [setToL1_eq_setToL1SCLM] exact setToL1S_indicatorConst (fun s => hT.eq_zero_of_measure_zero) hT.1 hs hΞΌs x theorem setToL1_indicatorConstLp (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±} (hs : MeasurableSet s) (hΞΌs : ΞΌ s β‰  ∞) (x : E) : setToL1 hT (indicatorConstLp 1 hs hΞΌs x) = T s x := by rw [← Lp.simpleFunc.coe_indicatorConst hs hΞΌs x] exact setToL1_simpleFunc_indicatorConst hT hs hΞΌs.lt_top x theorem setToL1_const [IsFiniteMeasure ΞΌ] (hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) : setToL1 hT (indicatorConstLp 1 MeasurableSet.univ (measure_ne_top _ _) x) = T univ x := setToL1_indicatorConstLp hT MeasurableSet.univ (measure_ne_top _ _) x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G'] theorem setToL1_mono_left' {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, T s x ≀ T' s x) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f ≀ setToL1 hT' f := by induction f using Lp.induction (hp_ne_top := one_ne_top) with | @indicatorConst c s hs hΞΌs => rw [setToL1_simpleFunc_indicatorConst hT hs hΞΌs, setToL1_simpleFunc_indicatorConst hT' hs hΞΌs] exact hTT' s hs hΞΌs c | @add f g hf hg _ hf_le hg_le => rw [(setToL1 hT).map_add, (setToL1 hT').map_add] exact add_le_add hf_le hg_le | isClosed => exact isClosed_le (setToL1 hT).continuous (setToL1 hT').continuous theorem setToL1_mono_left {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s x, T s x ≀ T' s x) (f : Ξ± →₁[ΞΌ] E) : setToL1 hT f ≀ setToL1 hT' f := setToL1_mono_left' hT hT' (fun s _ _ x => hTT' s x) f theorem setToL1_nonneg {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f : Ξ± →₁[ΞΌ] G'} (hf : 0 ≀ f) : 0 ≀ setToL1 hT f := by suffices βˆ€ f : { g : Ξ± →₁[ΞΌ] G' // 0 ≀ g }, 0 ≀ setToL1 hT f from this (⟨f, hf⟩ : { g : Ξ± →₁[ΞΌ] G' // 0 ≀ g }) refine fun g => @isClosed_property { g : Ξ± →₁ₛ[ΞΌ] G' // 0 ≀ g } { g : Ξ± →₁[ΞΌ] G' // 0 ≀ g } _ _ (fun g => 0 ≀ setToL1 hT g) (denseRange_coeSimpleFuncNonnegToLpNonneg 1 ΞΌ G' one_ne_top) ?_ ?_ g Β· exact isClosed_le continuous_zero ((setToL1 hT).continuous.comp continuous_induced_dom) Β· intro g have : (coeSimpleFuncNonnegToLpNonneg 1 ΞΌ G' g : Ξ± →₁[ΞΌ] G') = (g : Ξ± →₁ₛ[ΞΌ] G') := rfl rw [this, setToL1_eq_setToL1SCLM] exact setToL1S_nonneg (fun s => hT.eq_zero_of_measure_zero) hT.1 hT_nonneg g.2 theorem setToL1_mono [IsOrderedAddMonoid G'] {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f g : Ξ± →₁[ΞΌ] G'} (hfg : f ≀ g) : setToL1 hT f ≀ setToL1 hT g := by rw [← sub_nonneg] at hfg ⊒ rw [← (setToL1 hT).map_sub] exact setToL1_nonneg hT hT_nonneg hfg end Order theorem norm_setToL1_le_norm_setToL1SCLM (hT : DominatedFinMeasAdditive ΞΌ T C) : β€–setToL1 hTβ€– ≀ β€–setToL1SCLM Ξ± E ΞΌ hTβ€– := calc β€–setToL1 hTβ€– ≀ (1 : ℝβ‰₯0) * β€–setToL1SCLM Ξ± E ΞΌ hTβ€– := by refine ContinuousLinearMap.opNorm_extend_le (setToL1SCLM Ξ± E ΞΌ hT) (coeToLp Ξ± E ℝ) (simpleFunc.denseRange one_ne_top) fun x => le_of_eq ?_ rw [NNReal.coe_one, one_mul] simp [coeToLp] _ = β€–setToL1SCLM Ξ± E ΞΌ hTβ€– := by rw [NNReal.coe_one, one_mul] theorem norm_setToL1_le_mul_norm (hT : DominatedFinMeasAdditive ΞΌ T C) (hC : 0 ≀ C) (f : Ξ± →₁[ΞΌ] E) : β€–setToL1 hT fβ€– ≀ C * β€–fβ€– := calc β€–setToL1 hT fβ€– ≀ β€–setToL1SCLM Ξ± E ΞΌ hTβ€– * β€–fβ€– := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≀ C * β€–fβ€– := mul_le_mul (norm_setToL1SCLM_le hT hC) le_rfl (norm_nonneg _) hC theorem norm_setToL1_le_mul_norm' (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁[ΞΌ] E) : β€–setToL1 hT fβ€– ≀ max C 0 * β€–fβ€– := calc β€–setToL1 hT fβ€– ≀ β€–setToL1SCLM Ξ± E ΞΌ hTβ€– * β€–fβ€– := ContinuousLinearMap.le_of_opNorm_le _ (norm_setToL1_le_norm_setToL1SCLM hT) _ _ ≀ max C 0 * β€–fβ€– := mul_le_mul (norm_setToL1SCLM_le' hT) le_rfl (norm_nonneg _) (le_max_right _ _) theorem norm_setToL1_le (hT : DominatedFinMeasAdditive ΞΌ T C) (hC : 0 ≀ C) : β€–setToL1 hTβ€– ≀ C := ContinuousLinearMap.opNorm_le_bound _ hC (norm_setToL1_le_mul_norm hT hC) theorem norm_setToL1_le' (hT : DominatedFinMeasAdditive ΞΌ T C) : β€–setToL1 hTβ€– ≀ max C 0 := ContinuousLinearMap.opNorm_le_bound _ (le_max_right _ _) (norm_setToL1_le_mul_norm' hT) theorem setToL1_lipschitz (hT : DominatedFinMeasAdditive ΞΌ T C) : LipschitzWith (Real.toNNReal C) (setToL1 hT) := (setToL1 hT).lipschitz.weaken (norm_setToL1_le' hT) /-- If `fs i β†’ f` in `L1`, then `setToL1 hT (fs i) β†’ setToL1 hT f`. -/ theorem tendsto_setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁[ΞΌ] E) {ΞΉ} (fs : ΞΉ β†’ Ξ± →₁[ΞΌ] E) {l : Filter ΞΉ} (hfs : Tendsto fs l (𝓝 f)) : Tendsto (fun i => setToL1 hT (fs i)) l (𝓝 <| setToL1 hT f) := ((setToL1 hT).continuous.tendsto _).comp hfs end SetToL1 end L1 section Function variable [CompleteSpace F] {T T' T'' : Set Ξ± β†’ E β†’L[ℝ] F} {C C' C'' : ℝ} {f g : Ξ± β†’ E} variable (ΞΌ T) open Classical in /-- Extend `T : Set Ξ± β†’ E β†’L[ℝ] F` to `(Ξ± β†’ E) β†’ F` (for integrable functions `Ξ± β†’ E`). We set it to 0 if the function is not integrable. -/ def setToFun (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β†’ E) : F := if hf : Integrable f ΞΌ then L1.setToL1 hT (hf.toL1 f) else 0 variable {ΞΌ T} theorem setToFun_eq (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) : setToFun ΞΌ T hT f = L1.setToL1 hT (hf.toL1 f) := dif_pos hf theorem L1.setToFun_eq_setToL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁[ΞΌ] E) : setToFun ΞΌ T hT f = L1.setToL1 hT f := by rw [setToFun_eq hT (L1.integrable_coeFn f), Integrable.toL1_coeFn] theorem setToFun_undef (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Β¬Integrable f ΞΌ) : setToFun ΞΌ T hT f = 0 := dif_neg hf theorem setToFun_non_aestronglyMeasurable (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Β¬AEStronglyMeasurable f ΞΌ) : setToFun ΞΌ T hT f = 0 := setToFun_undef hT (not_and_of_not_left _ hf) @[deprecated (since := "2025-04-09")] alias setToFun_non_aEStronglyMeasurable := setToFun_non_aestronglyMeasurable theorem setToFun_congr_left (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : T = T') (f : Ξ± β†’ E) : setToFun ΞΌ T hT f = setToFun ΞΌ T' hT' f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left T T' hT hT' h] Β· simp_rw [setToFun_undef _ hf] theorem setToFun_congr_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = T' s) (f : Ξ± β†’ E) : setToFun ΞΌ T hT f = setToFun ΞΌ T' hT' f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_congr_left' T T' hT hT' h] Β· simp_rw [setToFun_undef _ hf] theorem setToFun_add_left (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (f : Ξ± β†’ E) : setToFun ΞΌ (T + T') (hT.add hT') f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left hT hT'] Β· simp_rw [setToFun_undef _ hf, add_zero] theorem setToFun_add_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hT'' : DominatedFinMeasAdditive ΞΌ T'' C'') (h_add : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T'' s = T s + T' s) (f : Ξ± β†’ E) : setToFun ΞΌ T'' hT'' f = setToFun ΞΌ T hT f + setToFun ΞΌ T' hT' f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_add_left' hT hT' hT'' h_add] Β· simp_rw [setToFun_undef _ hf, add_zero] theorem setToFun_smul_left (hT : DominatedFinMeasAdditive ΞΌ T C) (c : ℝ) (f : Ξ± β†’ E) : setToFun ΞΌ (fun s => c β€’ T s) (hT.smul c) f = c β€’ setToFun ΞΌ T hT f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left hT c] Β· simp_rw [setToFun_undef _ hf, smul_zero] theorem setToFun_smul_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (c : ℝ) (h_smul : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T' s = c β€’ T s) (f : Ξ± β†’ E) : setToFun ΞΌ T' hT' f = c β€’ setToFun ΞΌ T hT f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf, L1.setToL1_smul_left' hT hT' c h_smul] Β· simp_rw [setToFun_undef _ hf, smul_zero] @[simp] theorem setToFun_zero (hT : DominatedFinMeasAdditive ΞΌ T C) : setToFun ΞΌ T hT (0 : Ξ± β†’ E) = 0 := by rw [Pi.zero_def, setToFun_eq hT (integrable_zero _ _ _)] simp only [← Pi.zero_def] rw [Integrable.toL1_zero, ContinuousLinearMap.map_zero] @[simp] theorem setToFun_zero_left {hT : DominatedFinMeasAdditive ΞΌ (0 : Set Ξ± β†’ E β†’L[ℝ] F) C} : setToFun ΞΌ 0 hT f = 0 := by by_cases hf : Integrable f ΞΌ Β· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left hT _ Β· exact setToFun_undef hT hf theorem setToFun_zero_left' (hT : DominatedFinMeasAdditive ΞΌ T C) (h_zero : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = 0) : setToFun ΞΌ T hT f = 0 := by by_cases hf : Integrable f ΞΌ Β· rw [setToFun_eq hT hf]; exact L1.setToL1_zero_left' hT h_zero _ Β· exact setToFun_undef hT hf theorem setToFun_add (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) (hg : Integrable g ΞΌ) : setToFun ΞΌ T hT (f + g) = setToFun ΞΌ T hT f + setToFun ΞΌ T hT g := by rw [setToFun_eq hT (hf.add hg), setToFun_eq hT hf, setToFun_eq hT hg, Integrable.toL1_add, (L1.setToL1 hT).map_add] theorem setToFun_finset_sum' (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (s : Finset ΞΉ) {f : ΞΉ β†’ Ξ± β†’ E} (hf : βˆ€ i ∈ s, Integrable (f i) ΞΌ) : setToFun ΞΌ T hT (βˆ‘ i ∈ s, f i) = βˆ‘ i ∈ s, setToFun ΞΌ T hT (f i) := by classical revert hf refine Finset.induction_on s ?_ ?_ Β· intro _ simp only [setToFun_zero, Finset.sum_empty] Β· intro i s his ih hf simp only [his, Finset.sum_insert, not_false_iff] rw [setToFun_add hT (hf i (Finset.mem_insert_self i s)) _] Β· rw [ih fun i hi => hf i (Finset.mem_insert_of_mem hi)] Β· convert integrable_finset_sum s fun i hi => hf i (Finset.mem_insert_of_mem hi) with x simp theorem setToFun_finset_sum (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (s : Finset ΞΉ) {f : ΞΉ β†’ Ξ± β†’ E} (hf : βˆ€ i ∈ s, Integrable (f i) ΞΌ) : (setToFun ΞΌ T hT fun a => βˆ‘ i ∈ s, f i a) = βˆ‘ i ∈ s, setToFun ΞΌ T hT (f i) := by convert setToFun_finset_sum' hT s hf with a; simp theorem setToFun_neg (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β†’ E) : setToFun ΞΌ T hT (-f) = -setToFun ΞΌ T hT f := by by_cases hf : Integrable f ΞΌ Β· rw [setToFun_eq hT hf, setToFun_eq hT hf.neg, Integrable.toL1_neg, (L1.setToL1 hT).map_neg] Β· rw [setToFun_undef hT hf, setToFun_undef hT, neg_zero] rwa [← integrable_neg_iff] at hf theorem setToFun_sub (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) (hg : Integrable g ΞΌ) : setToFun ΞΌ T hT (f - g) = setToFun ΞΌ T hT f - setToFun ΞΌ T hT g := by rw [sub_eq_add_neg, sub_eq_add_neg, setToFun_add hT hf hg.neg, setToFun_neg hT g] theorem setToFun_smul [NontriviallyNormedField π•œ] [NormedSpace π•œ E] [NormedSpace π•œ F] (hT : DominatedFinMeasAdditive ΞΌ T C) (h_smul : βˆ€ c : π•œ, βˆ€ s x, T s (c β€’ x) = c β€’ T s x) (c : π•œ) (f : Ξ± β†’ E) : setToFun ΞΌ T hT (c β€’ f) = c β€’ setToFun ΞΌ T hT f := by by_cases hf : Integrable f ΞΌ Β· rw [setToFun_eq hT hf, setToFun_eq hT, Integrable.toL1_smul', L1.setToL1_smul hT h_smul c _] Β· by_cases hr : c = 0 Β· rw [hr]; simp Β· have hf' : Β¬Integrable (c β€’ f) ΞΌ := by rwa [integrable_smul_iff hr f] rw [setToFun_undef hT hf, setToFun_undef hT hf', smul_zero] theorem setToFun_congr_ae (hT : DominatedFinMeasAdditive ΞΌ T C) (h : f =ᡐ[ΞΌ] g) : setToFun ΞΌ T hT f = setToFun ΞΌ T hT g := by by_cases hfi : Integrable f ΞΌ Β· have hgi : Integrable g ΞΌ := hfi.congr h rw [setToFun_eq hT hfi, setToFun_eq hT hgi, (Integrable.toL1_eq_toL1_iff f g hfi hgi).2 h] Β· have hgi : Β¬Integrable g ΞΌ := by rw [integrable_congr h] at hfi; exact hfi rw [setToFun_undef hT hfi, setToFun_undef hT hgi] theorem setToFun_measure_zero (hT : DominatedFinMeasAdditive ΞΌ T C) (h : ΞΌ = 0) : setToFun ΞΌ T hT f = 0 := by have : f =ᡐ[ΞΌ] 0 := by simp [h, EventuallyEq] rw [setToFun_congr_ae hT this, setToFun_zero] theorem setToFun_measure_zero' (hT : DominatedFinMeasAdditive ΞΌ T C) (h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ ΞΌ s = 0) : setToFun ΞΌ T hT f = 0 := setToFun_zero_left' hT fun s hs hΞΌs => hT.eq_zero_of_measure_zero hs (h s hs hΞΌs) theorem setToFun_toL1 (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) : setToFun ΞΌ T hT (hf.toL1 f) = setToFun ΞΌ T hT f := setToFun_congr_ae hT hf.coeFn_toL1 theorem setToFun_indicator_const (hT : DominatedFinMeasAdditive ΞΌ T C) {s : Set Ξ±} (hs : MeasurableSet s) (hΞΌs : ΞΌ s β‰  ∞) (x : E) : setToFun ΞΌ T hT (s.indicator fun _ => x) = T s x := by rw [setToFun_congr_ae hT (@indicatorConstLp_coeFn _ _ _ 1 _ _ _ hs hΞΌs x).symm] rw [L1.setToFun_eq_setToL1 hT] exact L1.setToL1_indicatorConstLp hT hs hΞΌs x theorem setToFun_const [IsFiniteMeasure ΞΌ] (hT : DominatedFinMeasAdditive ΞΌ T C) (x : E) : (setToFun ΞΌ T hT fun _ => x) = T univ x := by have : (fun _ : Ξ± => x) = Set.indicator univ fun _ => x := (indicator_univ _).symm rw [this] exact setToFun_indicator_const hT MeasurableSet.univ (measure_ne_top _ _) x section Order variable {G' G'' : Type*} [NormedAddCommGroup G''] [PartialOrder G''] [OrderClosedTopology G''] [IsOrderedAddMonoid G''] [NormedSpace ℝ G''] [CompleteSpace G''] [NormedAddCommGroup G'] [PartialOrder G'] [NormedSpace ℝ G'] theorem setToFun_mono_left' {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, T s x ≀ T' s x) (f : Ξ± β†’ E) : setToFun ΞΌ T hT f ≀ setToFun ΞΌ T' hT' f := by by_cases hf : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hf]; exact L1.setToL1_mono_left' hT hT' hTT' _ Β· simp_rw [setToFun_undef _ hf, le_rfl] theorem setToFun_mono_left {T T' : Set Ξ± β†’ E β†’L[ℝ] G''} {C C' : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ T' C') (hTT' : βˆ€ s x, T s x ≀ T' s x) (f : Ξ± →₁[ΞΌ] E) : setToFun ΞΌ T hT f ≀ setToFun ΞΌ T' hT' f := setToFun_mono_left' hT hT' (fun s _ _ x => hTT' s x) f theorem setToFun_nonneg {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f : Ξ± β†’ G'} (hf : 0 ≀ᡐ[ΞΌ] f) : 0 ≀ setToFun ΞΌ T hT f := by by_cases hfi : Integrable f ΞΌ Β· simp_rw [setToFun_eq _ hfi] refine L1.setToL1_nonneg hT hT_nonneg ?_ rw [← Lp.coeFn_le] have h0 := Lp.coeFn_zero G' 1 ΞΌ have h := Integrable.coeFn_toL1 hfi filter_upwards [h0, h, hf] with _ h0a ha hfa rw [h0a, ha] exact hfa Β· simp_rw [setToFun_undef _ hfi, le_rfl] theorem setToFun_mono [IsOrderedAddMonoid G'] {T : Set Ξ± β†’ G' β†’L[ℝ] G''} {C : ℝ} (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_nonneg : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ βˆ€ x, 0 ≀ x β†’ 0 ≀ T s x) {f g : Ξ± β†’ G'} (hf : Integrable f ΞΌ) (hg : Integrable g ΞΌ) (hfg : f ≀ᡐ[ΞΌ] g) : setToFun ΞΌ T hT f ≀ setToFun ΞΌ T hT g := by rw [← sub_nonneg, ← setToFun_sub hT hg hf] refine setToFun_nonneg hT hT_nonneg (hfg.mono fun a ha => ?_) rw [Pi.sub_apply, Pi.zero_apply, sub_nonneg] exact ha end Order @[continuity] theorem continuous_setToFun (hT : DominatedFinMeasAdditive ΞΌ T C) : Continuous fun f : Ξ± →₁[ΞΌ] E => setToFun ΞΌ T hT f := by simp_rw [L1.setToFun_eq_setToL1 hT]; exact ContinuousLinearMap.continuous _ /-- If `F i β†’ f` in `L1`, then `setToFun ΞΌ T hT (F i) β†’ setToFun ΞΌ T hT f`. -/ theorem tendsto_setToFun_of_L1 (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} (f : Ξ± β†’ E) (hfi : Integrable f ΞΌ) {fs : ΞΉ β†’ Ξ± β†’ E} {l : Filter ΞΉ} (hfsi : βˆ€αΆ  i in l, Integrable (fs i) ΞΌ) (hfs : Tendsto (fun i => ∫⁻ x, β€–fs i x - f xβ€–β‚‘ βˆ‚ΞΌ) l (𝓝 0)) : Tendsto (fun i => setToFun ΞΌ T hT (fs i)) l (𝓝 <| setToFun ΞΌ T hT f) := by classical let f_lp := hfi.toL1 f let F_lp i := if hFi : Integrable (fs i) ΞΌ then hFi.toL1 (fs i) else 0 have tendsto_L1 : Tendsto F_lp l (𝓝 f_lp) := by rw [Lp.tendsto_Lp_iff_tendsto_eLpNorm'] simp_rw [eLpNorm_one_eq_lintegral_enorm, Pi.sub_apply] refine (tendsto_congr' ?_).mp hfs filter_upwards [hfsi] with i hi refine lintegral_congr_ae ?_ filter_upwards [hi.coeFn_toL1, hfi.coeFn_toL1] with x hxi hxf simp_rw [F_lp, dif_pos hi, hxi, f_lp, hxf] suffices Tendsto (fun i => setToFun ΞΌ T hT (F_lp i)) l (𝓝 (setToFun ΞΌ T hT f)) by refine (tendsto_congr' ?_).mp this filter_upwards [hfsi] with i hi suffices h_ae_eq : F_lp i =ᡐ[ΞΌ] fs i from setToFun_congr_ae hT h_ae_eq simp_rw [F_lp, dif_pos hi] exact hi.coeFn_toL1 rw [setToFun_congr_ae hT hfi.coeFn_toL1.symm] exact ((continuous_setToFun hT).tendsto f_lp).comp tendsto_L1 theorem tendsto_setToFun_approxOn_of_measurable (hT : DominatedFinMeasAdditive ΞΌ T C) [MeasurableSpace E] [BorelSpace E] {f : Ξ± β†’ E} {s : Set E} [SeparableSpace s] (hfi : Integrable f ΞΌ) (hfm : Measurable f) (hs : βˆ€α΅ x βˆ‚ΞΌ, f x ∈ closure s) {yβ‚€ : E} (hβ‚€ : yβ‚€ ∈ s) (hβ‚€i : Integrable (fun _ => yβ‚€) ΞΌ) : Tendsto (fun n => setToFun ΞΌ T hT (SimpleFunc.approxOn f hfm s yβ‚€ hβ‚€ n)) atTop (𝓝 <| setToFun ΞΌ T hT f) := tendsto_setToFun_of_L1 hT _ hfi (Eventually.of_forall (SimpleFunc.integrable_approxOn hfm hfi hβ‚€ hβ‚€i)) (SimpleFunc.tendsto_approxOn_L1_enorm hfm _ hs (hfi.sub hβ‚€i).2) theorem tendsto_setToFun_approxOn_of_measurable_of_range_subset (hT : DominatedFinMeasAdditive ΞΌ T C) [MeasurableSpace E] [BorelSpace E] {f : Ξ± β†’ E} (fmeas : Measurable f) (hf : Integrable f ΞΌ) (s : Set E) [SeparableSpace s] (hs : range f βˆͺ {0} βŠ† s) : Tendsto (fun n => setToFun ΞΌ T hT (SimpleFunc.approxOn f fmeas s 0 (hs <| by simp) n)) atTop (𝓝 <| setToFun ΞΌ T hT f) := by refine tendsto_setToFun_approxOn_of_measurable hT hf fmeas ?_ _ (integrable_zero _ _ _) exact Eventually.of_forall fun x => subset_closure (hs (Set.mem_union_left _ (mem_range_self _))) /-- Auxiliary lemma for `setToFun_congr_measure`: the function sending `f : Ξ± →₁[ΞΌ] G` to `f : Ξ± →₁[ΞΌ'] G` is continuous when `ΞΌ' ≀ c' β€’ ΞΌ` for `c' β‰  ∞`. -/ theorem continuous_L1_toL1 {ΞΌ' : Measure Ξ±} (c' : ℝβ‰₯0∞) (hc' : c' β‰  ∞) (hΞΌ'_le : ΞΌ' ≀ c' β€’ ΞΌ) : Continuous fun f : Ξ± →₁[ΞΌ] G => (Integrable.of_measure_le_smul hc' hΞΌ'_le (L1.integrable_coeFn f)).toL1 f := by by_cases hc'0 : c' = 0 Β· have hΞΌ'0 : ΞΌ' = 0 := by rw [← Measure.nonpos_iff_eq_zero']; refine hΞΌ'_le.trans ?_; simp [hc'0] have h_im_zero : (fun f : Ξ± →₁[ΞΌ] G => (Integrable.of_measure_le_smul hc' hΞΌ'_le (L1.integrable_coeFn f)).toL1 f) = 0 := by ext1 f; ext1; simp_rw [hΞΌ'0]; simp only [ae_zero, EventuallyEq, eventually_bot] rw [h_im_zero] exact continuous_zero rw [Metric.continuous_iff] intro f Ξ΅ hΞ΅_pos use Ξ΅ / 2 / c'.toReal refine ⟨div_pos (half_pos hΞ΅_pos) (toReal_pos hc'0 hc'), ?_⟩ intro g hfg rw [Lp.dist_def] at hfg ⊒ let h_int := fun f' : Ξ± →₁[ΞΌ] G => (L1.integrable_coeFn f').of_measure_le_smul hc' hΞΌ'_le have : eLpNorm (⇑(Integrable.toL1 g (h_int g)) - ⇑(Integrable.toL1 f (h_int f))) 1 ΞΌ' = eLpNorm (⇑g - ⇑f) 1 ΞΌ' := eLpNorm_congr_ae ((Integrable.coeFn_toL1 _).sub (Integrable.coeFn_toL1 _)) rw [this] have h_eLpNorm_ne_top : eLpNorm (⇑g - ⇑f) 1 ΞΌ β‰  ∞ := by rw [← eLpNorm_congr_ae (Lp.coeFn_sub _ _)]; exact Lp.eLpNorm_ne_top _ calc (eLpNorm (⇑g - ⇑f) 1 ΞΌ').toReal ≀ (c' * eLpNorm (⇑g - ⇑f) 1 ΞΌ).toReal := by refine toReal_mono (ENNReal.mul_ne_top hc' h_eLpNorm_ne_top) ?_ refine (eLpNorm_mono_measure (⇑g - ⇑f) hΞΌ'_le).trans_eq ?_ rw [eLpNorm_smul_measure_of_ne_zero hc'0, smul_eq_mul] simp _ = c'.toReal * (eLpNorm (⇑g - ⇑f) 1 ΞΌ).toReal := toReal_mul _ ≀ c'.toReal * (Ξ΅ / 2 / c'.toReal) := by gcongr _ = Ξ΅ / 2 := by refine mul_div_cancelβ‚€ (Ξ΅ / 2) ?_; rw [Ne, toReal_eq_zero_iff]; simp [hc', hc'0] _ < Ξ΅ := half_lt_self hΞ΅_pos theorem setToFun_congr_measure_of_integrable {ΞΌ' : Measure Ξ±} (c' : ℝβ‰₯0∞) (hc' : c' β‰  ∞) (hΞΌ'_le : ΞΌ' ≀ c' β€’ ΞΌ) (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ' T C') (f : Ξ± β†’ E) (hfΞΌ : Integrable f ΞΌ) : setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f := by -- integrability for `ΞΌ` implies integrability for `ΞΌ'`. have h_int : βˆ€ g : Ξ± β†’ E, Integrable g ΞΌ β†’ Integrable g ΞΌ' := fun g hg => Integrable.of_measure_le_smul hc' hΞΌ'_le hg -- We use `Integrable.induction` apply hfΞΌ.induction (P := fun f => setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f) Β· intro c s hs hΞΌs have hΞΌ's : ΞΌ' s β‰  ∞ := by refine ((hΞΌ'_le s).trans_lt ?_).ne rw [Measure.smul_apply, smul_eq_mul] exact ENNReal.mul_lt_top hc'.lt_top hΞΌs rw [setToFun_indicator_const hT hs hΞΌs.ne, setToFun_indicator_const hT' hs hΞΌ's] Β· intro fβ‚‚ gβ‚‚ _ hfβ‚‚ hgβ‚‚ h_eq_f h_eq_g rw [setToFun_add hT hfβ‚‚ hgβ‚‚, setToFun_add hT' (h_int fβ‚‚ hfβ‚‚) (h_int gβ‚‚ hgβ‚‚), h_eq_f, h_eq_g] Β· refine isClosed_eq (continuous_setToFun hT) ?_ have : (fun f : Ξ± →₁[ΞΌ] E => setToFun ΞΌ' T hT' f) = fun f : Ξ± →₁[ΞΌ] E => setToFun ΞΌ' T hT' ((h_int f (L1.integrable_coeFn f)).toL1 f) := by ext1 f; exact setToFun_congr_ae hT' (Integrable.coeFn_toL1 _).symm rw [this] exact (continuous_setToFun hT').comp (continuous_L1_toL1 c' hc' hΞΌ'_le) Β· intro fβ‚‚ gβ‚‚ hfg _ hf_eq have hfg' : fβ‚‚ =ᡐ[ΞΌ'] gβ‚‚ := (Measure.absolutelyContinuous_of_le_smul hΞΌ'_le).ae_eq hfg rw [← setToFun_congr_ae hT hfg, hf_eq, setToFun_congr_ae hT' hfg'] theorem setToFun_congr_measure {ΞΌ' : Measure Ξ±} (c c' : ℝβ‰₯0∞) (hc : c β‰  ∞) (hc' : c' β‰  ∞) (hΞΌ_le : ΞΌ ≀ c β€’ ΞΌ') (hΞΌ'_le : ΞΌ' ≀ c' β€’ ΞΌ) (hT : DominatedFinMeasAdditive ΞΌ T C) (hT' : DominatedFinMeasAdditive ΞΌ' T C') (f : Ξ± β†’ E) : setToFun ΞΌ T hT f = setToFun ΞΌ' T hT' f := by by_cases hf : Integrable f ΞΌ Β· exact setToFun_congr_measure_of_integrable c' hc' hΞΌ'_le hT hT' f hf Β· -- if `f` is not integrable, both `setToFun` are 0. have h_int : βˆ€ g : Ξ± β†’ E, Β¬Integrable g ΞΌ β†’ Β¬Integrable g ΞΌ' := fun g => mt fun h => h.of_measure_le_smul hc hΞΌ_le simp_rw [setToFun_undef _ hf, setToFun_undef _ (h_int f hf)] theorem setToFun_congr_measure_of_add_right {ΞΌ' : Measure Ξ±} (hT_add : DominatedFinMeasAdditive (ΞΌ + ΞΌ') T C') (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± β†’ E) (hf : Integrable f (ΞΌ + ΞΌ')) : setToFun (ΞΌ + ΞΌ') T hT_add f = setToFun ΞΌ T hT f := by refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf rw [one_smul] nth_rw 1 [← add_zero ΞΌ] exact add_le_add le_rfl bot_le theorem setToFun_congr_measure_of_add_left {ΞΌ' : Measure Ξ±} (hT_add : DominatedFinMeasAdditive (ΞΌ + ΞΌ') T C') (hT : DominatedFinMeasAdditive ΞΌ' T C) (f : Ξ± β†’ E) (hf : Integrable f (ΞΌ + ΞΌ')) : setToFun (ΞΌ + ΞΌ') T hT_add f = setToFun ΞΌ' T hT f := by refine setToFun_congr_measure_of_integrable 1 one_ne_top ?_ hT_add hT f hf rw [one_smul] nth_rw 1 [← zero_add ΞΌ'] exact add_le_add_right bot_le ΞΌ' theorem setToFun_top_smul_measure (hT : DominatedFinMeasAdditive (∞ β€’ ΞΌ) T C) (f : Ξ± β†’ E) : setToFun (∞ β€’ ΞΌ) T hT f = 0 := by refine setToFun_measure_zero' hT fun s _ hΞΌs => ?_ rw [lt_top_iff_ne_top] at hΞΌs simp only [true_and, Measure.smul_apply, ENNReal.mul_eq_top, eq_self_iff_true, top_ne_zero, Ne, not_false_iff, not_or, Classical.not_not, smul_eq_mul] at hΞΌs simp only [hΞΌs.right, Measure.smul_apply, mul_zero, smul_eq_mul] theorem setToFun_congr_smul_measure (c : ℝβ‰₯0∞) (hc_ne_top : c β‰  ∞) (hT : DominatedFinMeasAdditive ΞΌ T C) (hT_smul : DominatedFinMeasAdditive (c β€’ ΞΌ) T C') (f : Ξ± β†’ E) : setToFun ΞΌ T hT f = setToFun (c β€’ ΞΌ) T hT_smul f := by by_cases hc0 : c = 0 Β· simp [hc0] at hT_smul have h : βˆ€ s, MeasurableSet s β†’ ΞΌ s < ∞ β†’ T s = 0 := fun s hs _ => hT_smul.eq_zero hs rw [setToFun_zero_left' _ h, setToFun_measure_zero] simp [hc0] refine setToFun_congr_measure c⁻¹ c ?_ hc_ne_top (le_of_eq ?_) le_rfl hT hT_smul f Β· simp [hc0] Β· rw [smul_smul, ENNReal.inv_mul_cancel hc0 hc_ne_top, one_smul] theorem norm_setToFun_le_mul_norm (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁[ΞΌ] E) (hC : 0 ≀ C) : β€–setToFun ΞΌ T hT fβ€– ≀ C * β€–fβ€– := by rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm hT hC f theorem norm_setToFun_le_mul_norm' (hT : DominatedFinMeasAdditive ΞΌ T C) (f : Ξ± →₁[ΞΌ] E) : β€–setToFun ΞΌ T hT fβ€– ≀ max C 0 * β€–fβ€– := by rw [L1.setToFun_eq_setToL1]; exact L1.norm_setToL1_le_mul_norm' hT f theorem norm_setToFun_le (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) (hC : 0 ≀ C) : β€–setToFun ΞΌ T hT fβ€– ≀ C * β€–hf.toL1 fβ€– := by rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm hT hC _ theorem norm_setToFun_le' (hT : DominatedFinMeasAdditive ΞΌ T C) (hf : Integrable f ΞΌ) : β€–setToFun ΞΌ T hT fβ€– ≀ max C 0 * β€–hf.toL1 fβ€– := by rw [setToFun_eq hT hf]; exact L1.norm_setToL1_le_mul_norm' hT _ /-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their image by `setToFun`. We could weaken the condition `bound_integrable` to require `HasFiniteIntegral bound ΞΌ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_setToFun_of_dominated_convergence (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : β„• β†’ Ξ± β†’ E} {f : Ξ± β†’ E} (bound : Ξ± β†’ ℝ) (fs_measurable : βˆ€ n, AEStronglyMeasurable (fs n) ΞΌ) (bound_integrable : Integrable bound ΞΌ) (h_bound : βˆ€ n, βˆ€α΅ a βˆ‚ΞΌ, β€–fs n aβ€– ≀ bound a) (h_lim : βˆ€α΅ a βˆ‚ΞΌ, Tendsto (fun n => fs n a) atTop (𝓝 (f a))) : Tendsto (fun n => setToFun ΞΌ T hT (fs n)) atTop (𝓝 <| setToFun ΞΌ T hT f) := by -- `f` is a.e.-measurable, since it is the a.e.-pointwise limit of a.e.-measurable functions. have f_measurable : AEStronglyMeasurable f ΞΌ := aestronglyMeasurable_of_tendsto_ae _ fs_measurable h_lim -- all functions we consider are integrable have fs_int : βˆ€ n, Integrable (fs n) ΞΌ := fun n => bound_integrable.mono' (fs_measurable n) (h_bound _) have f_int : Integrable f ΞΌ := ⟨f_measurable, hasFiniteIntegral_of_dominated_convergence bound_integrable.hasFiniteIntegral h_bound h_lim⟩ -- it suffices to prove the result for the corresponding L1 functions suffices Tendsto (fun n => L1.setToL1 hT ((fs_int n).toL1 (fs n))) atTop (𝓝 (L1.setToL1 hT (f_int.toL1 f))) by convert this with n Β· exact setToFun_eq hT (fs_int n) Β· exact setToFun_eq hT f_int -- the convergence of setToL1 follows from the convergence of the L1 functions refine L1.tendsto_setToL1 hT _ _ ?_ -- up to some rewriting, what we need to prove is `h_lim` rw [tendsto_iff_norm_sub_tendsto_zero] have lintegral_norm_tendsto_zero : Tendsto (fun n => ENNReal.toReal <| ∫⁻ a, ENNReal.ofReal β€–fs n a - f aβ€– βˆ‚ΞΌ) atTop (𝓝 0) := (tendsto_toReal zero_ne_top).comp (tendsto_lintegral_norm_of_dominated_convergence fs_measurable bound_integrable.hasFiniteIntegral h_bound h_lim) convert lintegral_norm_tendsto_zero with n rw [L1.norm_def] congr 1 refine lintegral_congr_ae ?_ rw [← Integrable.toL1_sub] refine ((fs_int n).sub f_int).coeFn_toL1.mono fun x hx => ?_ dsimp only rw [hx, ofReal_norm_eq_enorm, Pi.sub_apply] /-- Lebesgue dominated convergence theorem for filters with a countable basis -/ theorem tendsto_setToFun_filter_of_dominated_convergence (hT : DominatedFinMeasAdditive ΞΌ T C) {ΞΉ} {l : Filter ΞΉ} [l.IsCountablyGenerated] {fs : ΞΉ β†’ Ξ± β†’ E} {f : Ξ± β†’ E} (bound : Ξ± β†’ ℝ) (hfs_meas : βˆ€αΆ  n in l, AEStronglyMeasurable (fs n) ΞΌ) (h_bound : βˆ€αΆ  n in l, βˆ€α΅ a βˆ‚ΞΌ, β€–fs n aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_lim : βˆ€α΅ a βˆ‚ΞΌ, Tendsto (fun n => fs n a) l (𝓝 (f a))) : Tendsto (fun n => setToFun ΞΌ T hT (fs n)) l (𝓝 <| setToFun ΞΌ T hT f) := by rw [tendsto_iff_seq_tendsto] intro x xl have hxl : βˆ€ s ∈ l, βˆƒ a, βˆ€ b β‰₯ a, x b ∈ s := by rwa [tendsto_atTop'] at xl have h : { x : ΞΉ | (fun n => AEStronglyMeasurable (fs n) ΞΌ) x } ∩ { x : ΞΉ | (fun n => βˆ€α΅ a βˆ‚ΞΌ, β€–fs n aβ€– ≀ bound a) x } ∈ l := inter_mem hfs_meas h_bound obtain ⟨k, h⟩ := hxl _ h rw [← tendsto_add_atTop_iff_nat k] refine tendsto_setToFun_of_dominated_convergence hT bound ?_ bound_integrable ?_ ?_ Β· exact fun n => (h _ (self_le_add_left _ _)).1 Β· exact fun n => (h _ (self_le_add_left _ _)).2 Β· filter_upwards [h_lim] refine fun a h_lin => @Tendsto.comp _ _ _ (fun n => x (n + k)) (fun n => fs n a) _ _ _ h_lin ?_ rwa [tendsto_add_atTop_iff_nat] variable {X : Type*} [TopologicalSpace X] [FirstCountableTopology X] theorem continuousWithinAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β†’ Ξ± β†’ E} {xβ‚€ : X} {bound : Ξ± β†’ ℝ} {s : Set X} (hfs_meas : βˆ€αΆ  x in 𝓝[s] xβ‚€, AEStronglyMeasurable (fs x) ΞΌ) (h_bound : βˆ€αΆ  x in 𝓝[s] xβ‚€, βˆ€α΅ a βˆ‚ΞΌ, β€–fs x aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_cont : βˆ€α΅ a βˆ‚ΞΌ, ContinuousWithinAt (fun x => fs x a) s xβ‚€) : ContinuousWithinAt (fun x => setToFun ΞΌ T hT (fs x)) s xβ‚€ := tendsto_setToFun_filter_of_dominated_convergence hT bound β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί theorem continuousAt_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β†’ Ξ± β†’ E} {xβ‚€ : X} {bound : Ξ± β†’ ℝ} (hfs_meas : βˆ€αΆ  x in 𝓝 xβ‚€, AEStronglyMeasurable (fs x) ΞΌ) (h_bound : βˆ€αΆ  x in 𝓝 xβ‚€, βˆ€α΅ a βˆ‚ΞΌ, β€–fs x aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_cont : βˆ€α΅ a βˆ‚ΞΌ, ContinuousAt (fun x => fs x a) xβ‚€) : ContinuousAt (fun x => setToFun ΞΌ T hT (fs x)) xβ‚€ := tendsto_setToFun_filter_of_dominated_convergence hT bound β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί β€Ή_β€Ί theorem continuousOn_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β†’ Ξ± β†’ E} {bound : Ξ± β†’ ℝ} {s : Set X} (hfs_meas : βˆ€ x ∈ s, AEStronglyMeasurable (fs x) ΞΌ) (h_bound : βˆ€ x ∈ s, βˆ€α΅ a βˆ‚ΞΌ, β€–fs x aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_cont : βˆ€α΅ a βˆ‚ΞΌ, ContinuousOn (fun x => fs x a) s) : ContinuousOn (fun x => setToFun ΞΌ T hT (fs x)) s := by intro x hx refine continuousWithinAt_setToFun_of_dominated hT ?_ ?_ bound_integrable ?_ Β· filter_upwards [self_mem_nhdsWithin] with x hx using hfs_meas x hx Β· filter_upwards [self_mem_nhdsWithin] with x hx using h_bound x hx Β· filter_upwards [h_cont] with a ha using ha x hx theorem continuous_setToFun_of_dominated (hT : DominatedFinMeasAdditive ΞΌ T C) {fs : X β†’ Ξ± β†’ E} {bound : Ξ± β†’ ℝ} (hfs_meas : βˆ€ x, AEStronglyMeasurable (fs x) ΞΌ) (h_bound : βˆ€ x, βˆ€α΅ a βˆ‚ΞΌ, β€–fs x aβ€– ≀ bound a) (bound_integrable : Integrable bound ΞΌ) (h_cont : βˆ€α΅ a βˆ‚ΞΌ, Continuous fun x => fs x a) : Continuous fun x => setToFun ΞΌ T hT (fs x) := continuous_iff_continuousAt.mpr fun _ => continuousAt_setToFun_of_dominated hT (Eventually.of_forall hfs_meas) (Eventually.of_forall h_bound) β€Ή_β€Ί <| h_cont.mono fun _ => Continuous.continuousAt end Function end MeasureTheory
Mathlib/MeasureTheory/Integral/SetToL1.lean
1,704
1,743
/- Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Data.Nat.EvenOddRec import Mathlib.Tactic.Linarith import Mathlib.Tactic.LinearCombination /-! # Elliptic divisibility sequences This file defines the type of an elliptic divisibility sequence (EDS) and a few examples. ## Mathematical background Let `R` be a commutative ring. An elliptic sequence is a sequence `W : β„€ β†’ R` satisfying `W(m + n)W(m - n)W(r)Β² = W(m + r)W(m - r)W(n)Β² - W(n + r)W(n - r)W(m)Β²` for any `m, n, r ∈ β„€`. A divisibility sequence is a sequence `W : β„€ β†’ R` satisfying `W(m) ∣ W(n)` for any `m, n ∈ β„€` such that `m ∣ n`. An elliptic divisibility sequence is simply a divisibility sequence that is elliptic. Some examples of EDSs include * the identity sequence, * certain terms of Lucas sequences, and * division polynomials of elliptic curves. ## Main definitions * `IsEllSequence`: a sequence indexed by integers is an elliptic sequence. * `IsDivSequence`: a sequence indexed by integers is a divisibility sequence. * `IsEllDivSequence`: a sequence indexed by integers is an EDS. * `preNormEDS'`: the auxiliary sequence for a normalised EDS indexed by `β„•`. * `preNormEDS`: the auxiliary sequence for a normalised EDS indexed by `β„€`. * `normEDS`: the canonical example of a normalised EDS indexed by `β„€`. ## Main statements * TODO: prove that `normEDS` satisfies `IsEllDivSequence`. * TODO: prove that a normalised sequence satisfying `IsEllDivSequence` can be given by `normEDS`. ## Implementation notes The normalised EDS `normEDS b c d n` is defined in terms of the auxiliary sequence `preNormEDS (b ^ 4) c d n`, which are equal when `n` is odd, and which differ by a factor of `b` when `n` is even. This coincides with the definition in the references since both agree for `normEDS b c d 2` and for `normEDS b c d 4`, and the correct factors of `b` are removed in `normEDS b c d (2 * (m + 2) + 1)` and in `normEDS b c d (2 * (m + 3))`. One reason is to avoid the necessity for ring division by `b` in the inductive definition of `normEDS b c d (2 * (m + 3))`. The idea is that, it can be shown that `normEDS b c d (2 * (m + 3))` always contains a factor of `b`, so it is possible to remove a factor of `b` *a posteriori*, but stating this lemma requires first defining `normEDS b c d (2 * (m + 3))`, which requires having this factor of `b` *a priori*. Another reason is to allow the definition of univariate `n`-division polynomials of elliptic curves, omitting a factor of the bivariate `2`-division polynomial. ## References M Ward, *Memoir on Elliptic Divisibility Sequences* ## Tags elliptic, divisibility, sequence -/ universe u v variable {R : Type u} [CommRing R] section IsEllDivSequence variable (W : β„€ β†’ R) /-- The proposition that a sequence indexed by integers is an elliptic sequence. -/ def IsEllSequence : Prop := βˆ€ m n r : β„€, W (m + n) * W (m - n) * W r ^ 2 = W (m + r) * W (m - r) * W n ^ 2 - W (n + r) * W (n - r) * W m ^ 2 /-- The proposition that a sequence indexed by integers is a divisibility sequence. -/ def IsDivSequence : Prop := βˆ€ m n : β„•, m ∣ n β†’ W m ∣ W n /-- The proposition that a sequence indexed by integers is an EDS. -/ def IsEllDivSequence : Prop := IsEllSequence W ∧ IsDivSequence W lemma isEllSequence_id : IsEllSequence id := fun _ _ _ => by simp only [id_eq]; ring1 lemma isDivSequence_id : IsDivSequence id := fun _ _ => Int.ofNat_dvd.mpr /-- The identity sequence is an EDS. -/ theorem isEllDivSequence_id : IsEllDivSequence id := ⟨isEllSequence_id, isDivSequence_id⟩ variable {W} lemma IsEllSequence.smul (h : IsEllSequence W) (x : R) : IsEllSequence (x β€’ W) := fun m n r => by linear_combination (norm := (simp only [Pi.smul_apply, smul_eq_mul]; ring1)) x ^ 4 * h m n r lemma IsDivSequence.smul (h : IsDivSequence W) (x : R) : IsDivSequence (x β€’ W) := fun m n r => mul_dvd_mul_left x <| h m n r lemma IsEllDivSequence.smul (h : IsEllDivSequence W) (x : R) : IsEllDivSequence (x β€’ W) := ⟨h.left.smul x, h.right.smul x⟩ end IsEllDivSequence /-- Strong recursion principle for a normalised EDS: if we have * `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`, * for all `m : β„•` we can prove `P (2 * (m + 3))` from `P k` for all `k < 2 * (m + 3)`, and * for all `m : β„•` we can prove `P (2 * (m + 2) + 1)` from `P k` for all `k < 2 * (m + 2) + 1`, then we have `P n` for all `n : β„•`. -/ @[elab_as_elim] noncomputable def normEDSRec' {P : β„• β†’ Sort u} (zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4) (even : βˆ€ m : β„•, (βˆ€ k < 2 * (m + 3), P k) β†’ P (2 * (m + 3))) (odd : βˆ€ m : β„•, (βˆ€ k < 2 * (m + 2) + 1, P k) β†’ P (2 * (m + 2) + 1)) (n : β„•) : P n := n.evenOddStrongRec (by rintro (_ | _ | _ | _) h; exacts [zero, two, four, even _ h]) (by rintro (_ | _ | _) h; exacts [one, three, odd _ h]) /-- Recursion principle for a normalised EDS: if we have * `P 0`, `P 1`, `P 2`, `P 3`, and `P 4`, * for all `m : β„•` we can prove `P (2 * (m + 3))` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`, `P (m + 4)`, and `P (m + 5)`, and * for all `m : β„•` we can prove `P (2 * (m + 2) + 1)` from `P (m + 1)`, `P (m + 2)`, `P (m + 3)`, and `P (m + 4)`, then we have `P n` for all `n : β„•`. -/ @[elab_as_elim] noncomputable def normEDSRec {P : β„• β†’ Sort u} (zero : P 0) (one : P 1) (two : P 2) (three : P 3) (four : P 4) (even : βˆ€ m : β„•, P (m + 1) β†’ P (m + 2) β†’ P (m + 3) β†’ P (m + 4) β†’ P (m + 5) β†’ P (2 * (m + 3))) (odd : βˆ€ m : β„•, P (m + 1) β†’ P (m + 2) β†’ P (m + 3) β†’ P (m + 4) β†’ P (2 * (m + 2) + 1)) (n : β„•) : P n := normEDSRec' zero one two three four (fun _ ih => by apply even <;> exact ih _ <| by linarith only) (fun _ ih => by apply odd <;> exact ih _ <| by linarith only) n variable (b c d : R) section PreNormEDS /-- The auxiliary sequence for a normalised EDS `W : β„• β†’ R`, with initial values
`W(0) = 0`, `W(1) = 1`, `W(2) = 1`, `W(3) = c`, and `W(4) = d` and extra parameter `b`. -/ def preNormEDS' (b c d : R) : β„• β†’ R | 0 => 0
Mathlib/NumberTheory/EllipticDivisibilitySequence.lean
145
147
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Johannes HΓΆlzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Data.Set.BooleanAlgebra /-! # The set lattice This file is a collection of results on the complete atomic boolean algebra structure of `Set Ξ±`. Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`. ## Main declarations * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `β‹‚β‚€ s = β‹‚ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set Ξ±` is a `CompleteAtomicBooleanAlgebra` with `≀ = βŠ†`, `< = βŠ‚`, `βŠ“ = ∩`, `βŠ” = βˆͺ`, `β¨… = β‹‚`, `⨆ = ⋃` and `\` as the set difference. See `Set.instBooleanAlgebra`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Ξ£ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `β‹‚ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnionβ‚‚`. This is an `iUnion` inside an `iUnion`. * `β‹‚ i j, s i j` is called `iInterβ‚‚`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnionβ‚‚` where `j : i ∈ s`. * `β‹‚ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInterβ‚‚` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `β‹‚`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `β‹‚β‚€`: `Set.sInter` -/ open Function Set universe u variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {ΞΉ ΞΉ' ΞΉβ‚‚ : Sort*} {ΞΊ κ₁ ΞΊβ‚‚ : ΞΉ β†’ Sort*} {ΞΊ' : ΞΉ' β†’ Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnionβ‚‚ {x : Ξ³} {s : βˆ€ i, ΞΊ i β†’ Set Ξ³} : (x ∈ ⋃ (i) (j), s i j) ↔ βˆƒ i j, x ∈ s i j := by simp_rw [mem_iUnion] theorem mem_iInterβ‚‚ {x : Ξ³} {s : βˆ€ i, ΞΊ i β†’ Set Ξ³} : (x ∈ β‹‚ (i) (j), s i j) ↔ βˆ€ i j, x ∈ s i j := by simp_rw [mem_iInter] theorem mem_iUnion_of_mem {s : ΞΉ β†’ Set Ξ±} {a : Ξ±} (i : ΞΉ) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ theorem mem_iUnionβ‚‚_of_mem {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {a : Ξ±} {i : ΞΉ} (j : ΞΊ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnionβ‚‚.2 ⟨i, j, ha⟩ theorem mem_iInter_of_mem {s : ΞΉ β†’ Set Ξ±} {a : Ξ±} (h : βˆ€ i, a ∈ s i) : a ∈ β‹‚ i, s i := mem_iInter.2 h theorem mem_iInterβ‚‚_of_mem {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {a : Ξ±} (h : βˆ€ i j, a ∈ s i j) : a ∈ β‹‚ (i) (j), s i j := mem_iInterβ‚‚.2 h /-! ### Union and intersection over an indexed family of sets -/ @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p β†’ Set Ξ±} {fβ‚‚ : q β†’ Set Ξ±} (pq : p ↔ q) (f : βˆ€ x, f₁ (pq.mpr x) = fβ‚‚ x) : iUnion f₁ = iUnion fβ‚‚ := iSup_congr_Prop pq f @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p β†’ Set Ξ±} {fβ‚‚ : q β†’ Set Ξ±} (pq : p ↔ q) (f : βˆ€ x, f₁ (pq.mpr x) = fβ‚‚ x) : iInter f₁ = iInter fβ‚‚ := iInf_congr_Prop pq f theorem iUnion_plift_up (f : PLift ΞΉ β†’ Set Ξ±) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ theorem iUnion_plift_down (f : ΞΉ β†’ Set Ξ±) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ theorem iInter_plift_up (f : PLift ΞΉ β†’ Set Ξ±) : β‹‚ i, f (PLift.up i) = β‹‚ i, f i := iInf_plift_up _ theorem iInter_plift_down (f : ΞΉ β†’ Set Ξ±) : β‹‚ i, f (PLift.down i) = β‹‚ i, f i := iInf_plift_down _ theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : ⋃ _ : p, s = if p then s else βˆ… := iSup_eq_if _ theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p β†’ Set Ξ±) : ⋃ h : p, s h = if h : p then s h else βˆ… := iSup_eq_dif _ theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set Ξ±) : β‹‚ _ : p, s = if p then s else univ := iInf_eq_if _ theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p β†’ Set Ξ±) : β‹‚ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ theorem exists_set_mem_of_union_eq_top {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β†’ Set Ξ²) (w : ⋃ i ∈ t, s i = ⊀) (x : Ξ²) : βˆƒ i ∈ t, x ∈ s i := by have p : x ∈ ⊀ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p theorem nonempty_of_union_eq_top_of_nonempty {ΞΉ : Type*} (t : Set ΞΉ) (s : ΞΉ β†’ Set Ξ±) (H : Nonempty Ξ±) (w : ⋃ i ∈ t, s i = ⊀) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ theorem nonempty_of_nonempty_iUnion {s : ΞΉ β†’ Set Ξ±} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ΞΉ := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ΞΉ β†’ Set Ξ±} [Nonempty Ξ±] (h_Union : ⋃ i, s i = univ) : Nonempty ΞΉ := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ΞΉ β†’ Ξ² β†’ Prop) : { x | βˆƒ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm theorem setOf_forall (p : ΞΉ β†’ Ξ² β†’ Prop) : { x | βˆ€ i, p i x } = β‹‚ i, { x | p i x } := ext fun _ => mem_iInter.symm theorem iUnion_subset {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} (h : βˆ€ i, s i βŠ† t) : ⋃ i, s i βŠ† t := iSup_le h theorem iUnionβ‚‚_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} (h : βˆ€ i j, s i j βŠ† t) : ⋃ (i) (j), s i j βŠ† t := iUnion_subset fun x => iUnion_subset (h x) theorem subset_iInter {t : Set Ξ²} {s : ΞΉ β†’ Set Ξ²} (h : βˆ€ i, t βŠ† s i) : t βŠ† β‹‚ i, s i := le_iInf h theorem subset_iInterβ‚‚ {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s βŠ† t i j) : s βŠ† β‹‚ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x @[simp] theorem iUnion_subset_iff {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} : ⋃ i, s i βŠ† t ↔ βˆ€ i, s i βŠ† t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ theorem iUnionβ‚‚_subset_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} : ⋃ (i) (j), s i j βŠ† t ↔ βˆ€ i j, s i j βŠ† t := by simp_rw [iUnion_subset_iff] @[simp] theorem subset_iInter_iff {s : Set Ξ±} {t : ΞΉ β†’ Set Ξ±} : (s βŠ† β‹‚ i, t i) ↔ βˆ€ i, s βŠ† t i := le_iInf_iff theorem subset_iInterβ‚‚_iff {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} : (s βŠ† β‹‚ (i) (j), t i j) ↔ βˆ€ i j, s βŠ† t i j := by simp_rw [subset_iInter_iff] theorem subset_iUnion : βˆ€ (s : ΞΉ β†’ Set Ξ²) (i : ΞΉ), s i βŠ† ⋃ i, s i := le_iSup theorem iInter_subset : βˆ€ (s : ΞΉ β†’ Set Ξ²) (i : ΞΉ), β‹‚ i, s i βŠ† s i := iInf_le lemma iInter_subset_iUnion [Nonempty ΞΉ] {s : ΞΉ β†’ Set Ξ±} : β‹‚ i, s i βŠ† ⋃ i, s i := iInf_le_iSup theorem subset_iUnionβ‚‚ {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : s i j βŠ† ⋃ (i') (j'), s i' j' := le_iSupβ‚‚ i j theorem iInterβ‚‚_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) : β‹‚ (i) (j), s i j βŠ† s i j := iInfβ‚‚_le i j /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set Ξ±} {t : ΞΉ β†’ Set Ξ±} (i : ΞΉ) (h : s βŠ† t i) : s βŠ† ⋃ i, t i := le_iSup_of_le i h /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ΞΉ β†’ Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (h : s i βŠ† t) : β‹‚ i, s i βŠ† t := iInf_le_of_le i h /-- This rather trivial consequence of `subset_iUnionβ‚‚` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnionβ‚‚_of_subset {s : Set Ξ±} {t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (i : ΞΉ) (j : ΞΊ i) (h : s βŠ† t i j) : s βŠ† ⋃ (i) (j), t i j := le_iSupβ‚‚_of_le i j h /-- This rather trivial consequence of `iInterβ‚‚_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInterβ‚‚_subset_of_subset {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : Set Ξ±} (i : ΞΉ) (j : ΞΊ i) (h : s i j βŠ† t) : β‹‚ (i) (j), s i j βŠ† t := iInfβ‚‚_le_of_le i j h theorem iUnion_mono {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : ⋃ i, s i βŠ† ⋃ i, t i := iSup_mono h @[gcongr] theorem iUnion_mono'' {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : iUnion s βŠ† iUnion t := iSup_mono h theorem iUnionβ‚‚_mono {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j βŠ† t i j) : ⋃ (i) (j), s i j βŠ† ⋃ (i) (j), t i j := iSupβ‚‚_mono h theorem iInter_mono {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : β‹‚ i, s i βŠ† β‹‚ i, t i := iInf_mono h @[gcongr] theorem iInter_mono'' {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i βŠ† t i) : iInter s βŠ† iInter t := iInf_mono h theorem iInterβ‚‚_mono {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j βŠ† t i j) : β‹‚ (i) (j), s i j βŠ† β‹‚ (i) (j), t i j := iInfβ‚‚_mono h theorem iUnion_mono' {s : ΞΉ β†’ Set Ξ±} {t : ΞΉβ‚‚ β†’ Set Ξ±} (h : βˆ€ i, βˆƒ j, s i βŠ† t j) : ⋃ i, s i βŠ† ⋃ i, t i := iSup_mono' h theorem iUnionβ‚‚_mono' {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : βˆ€ i', ΞΊ' i' β†’ Set Ξ±} (h : βˆ€ i j, βˆƒ i' j', s i j βŠ† t i' j') : ⋃ (i) (j), s i j βŠ† ⋃ (i') (j'), t i' j' := iSupβ‚‚_mono' h theorem iInter_mono' {s : ΞΉ β†’ Set Ξ±} {t : ΞΉ' β†’ Set Ξ±} (h : βˆ€ j, βˆƒ i, s i βŠ† t j) : β‹‚ i, s i βŠ† β‹‚ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi theorem iInterβ‚‚_mono' {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} {t : βˆ€ i', ΞΊ' i' β†’ Set Ξ±} (h : βˆ€ i' j', βˆƒ i j, s i j βŠ† t i' j') : β‹‚ (i) (j), s i j βŠ† β‹‚ (i') (j'), t i' j' := subset_iInterβ‚‚_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInterβ‚‚_subset _ _).trans hst theorem iUnionβ‚‚_subset_iUnion (ΞΊ : ΞΉ β†’ Sort*) (s : ΞΉ β†’ Set Ξ±) : ⋃ (i) (_ : ΞΊ i), s i βŠ† ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl theorem iInter_subset_iInterβ‚‚ (ΞΊ : ΞΉ β†’ Sort*) (s : ΞΉ β†’ Set Ξ±) : β‹‚ i, s i βŠ† β‹‚ (i) (_ : ΞΊ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl theorem iUnion_setOf (P : ΞΉ β†’ Ξ± β†’ Prop) : ⋃ i, { x : Ξ± | P i x } = { x : Ξ± | βˆƒ i, P i x } := by ext exact mem_iUnion theorem iInter_setOf (P : ΞΉ β†’ Ξ± β†’ Prop) : β‹‚ i, { x : Ξ± | P i x } = { x : Ξ± | βˆ€ i, P i x } := by ext exact mem_iInter theorem iUnion_congr_of_surjective {f : ΞΉ β†’ Set Ξ±} {g : ΞΉβ‚‚ β†’ Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : Surjective h) (h2 : βˆ€ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 theorem iInter_congr_of_surjective {f : ΞΉ β†’ Set Ξ±} {g : ΞΉβ‚‚ β†’ Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) (h1 : Surjective h) (h2 : βˆ€ x, g (h x) = f x) : β‹‚ x, f x = β‹‚ y, g y := h1.iInf_congr h h2 lemma iUnion_congr {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h lemma iInter_congr {s t : ΞΉ β†’ Set Ξ±} (h : βˆ€ i, s i = t i) : β‹‚ i, s i = β‹‚ i, t i := iInf_congr h lemma iUnionβ‚‚_congr {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i lemma iInterβ‚‚_congr {s t : βˆ€ i, ΞΊ i β†’ Set Ξ±} (h : βˆ€ i j, s i j = t i j) : β‹‚ (i) (j), s i j = β‹‚ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i section Nonempty variable [Nonempty ΞΉ] {f : ΞΉ β†’ Set Ξ±} {s : Set Ξ±} lemma iUnion_const (s : Set Ξ²) : ⋃ _ : ΞΉ, s = s := iSup_const lemma iInter_const (s : Set Ξ²) : β‹‚ _ : ΞΉ, s = s := iInf_const lemma iUnion_eq_const (hf : βˆ€ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ lemma iInter_eq_const (hf : βˆ€ i, f i = s) : β‹‚ i, f i = s := (iInter_congr hf).trans <| iInter_const _ end Nonempty @[simp] theorem compl_iUnion (s : ΞΉ β†’ Set Ξ²) : (⋃ i, s i)ᢜ = β‹‚ i, (s i)ᢜ := compl_iSup theorem compl_iUnionβ‚‚ (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (⋃ (i) (j), s i j)ᢜ = β‹‚ (i) (j), (s i j)ᢜ := by simp_rw [compl_iUnion] @[simp] theorem compl_iInter (s : ΞΉ β†’ Set Ξ²) : (β‹‚ i, s i)ᢜ = ⋃ i, (s i)ᢜ := compl_iInf theorem compl_iInterβ‚‚ (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (β‹‚ (i) (j), s i j)ᢜ = ⋃ (i) (j), (s i j)ᢜ := by simp_rw [compl_iInter] -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ΞΉ β†’ Set Ξ²) : ⋃ i, s i = (β‹‚ i, (s i)ᢜ)ᢜ := by simp only [compl_iInter, compl_compl] -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ΞΉ β†’ Set Ξ²) : β‹‚ i, s i = (⋃ i, (s i)ᢜ)ᢜ := by simp only [compl_iUnion, compl_compl] theorem inter_iUnion (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ theorem iUnion_inter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ theorem iUnion_union_distrib (s : ΞΉ β†’ Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : ⋃ i, s i βˆͺ t i = (⋃ i, s i) βˆͺ ⋃ i, t i := iSup_sup_eq theorem iInter_inter_distrib (s : ΞΉ β†’ Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : β‹‚ i, s i ∩ t i = (β‹‚ i, s i) ∩ β‹‚ i, t i := iInf_inf_eq theorem union_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s βˆͺ ⋃ i, t i) = ⋃ i, s βˆͺ t i := sup_iSup theorem iUnion_union [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) βˆͺ s = ⋃ i, t i βˆͺ s := iSup_sup theorem inter_iInter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s ∩ β‹‚ i, t i) = β‹‚ i, s ∩ t i := inf_iInf theorem iInter_inter [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (β‹‚ i, t i) ∩ s = β‹‚ i, t i ∩ s := iInf_inf theorem insert_iUnion [Nonempty ΞΉ] (x : Ξ²) (t : ΞΉ β†’ Set Ξ²) : insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by simp_rw [← union_singleton, iUnion_union] -- classical theorem union_iInter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s βˆͺ β‹‚ i, t i) = β‹‚ i, s βˆͺ t i := sup_iInf_eq _ _ theorem iInter_union (s : ΞΉ β†’ Set Ξ²) (t : Set Ξ²) : (β‹‚ i, s i) βˆͺ t = β‹‚ i, s i βˆͺ t := iInf_sup_eq _ _ theorem insert_iInter (x : Ξ²) (t : ΞΉ β†’ Set Ξ²) : insert x (β‹‚ i, t i) = β‹‚ i, insert x (t i) := by simp_rw [← union_singleton, iInter_union] theorem iUnion_diff (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ theorem diff_iUnion [Nonempty ΞΉ] (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s \ ⋃ i, t i) = β‹‚ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl theorem diff_iInter (s : Set Ξ²) (t : ΞΉ β†’ Set Ξ²) : (s \ β‹‚ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl theorem iUnion_inter_subset {ΞΉ Ξ±} {s t : ΞΉ β†’ Set Ξ±} : ⋃ i, s i ∩ t i βŠ† (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t theorem iUnion_inter_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· ≀ Β·)] {s t : ΞΉ β†’ Set Ξ±} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht theorem iUnion_inter_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· ≀ Β·))] {s t : ΞΉ β†’ Set Ξ±} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht theorem iInter_union_of_monotone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (swap (Β· ≀ Β·))] {s t : ΞΉ β†’ Set Ξ±} (hs : Monotone s) (ht : Monotone t) : β‹‚ i, s i βˆͺ t i = (β‹‚ i, s i) βˆͺ β‹‚ i, t i := iInf_sup_of_monotone hs ht theorem iInter_union_of_antitone {ΞΉ Ξ±} [Preorder ΞΉ] [IsDirected ΞΉ (Β· ≀ Β·)] {s t : ΞΉ β†’ Set Ξ±} (hs : Antitone s) (ht : Antitone t) : β‹‚ i, s i βˆͺ t i = (β‹‚ i, s i) βˆͺ β‹‚ i, t i := iInf_sup_of_antitone hs ht /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±} : (⋃ j, β‹‚ i, s i j) βŠ† β‹‚ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) theorem iUnion_option {ΞΉ} (s : Option ΞΉ β†’ Set Ξ±) : ⋃ o, s o = s none βˆͺ ⋃ i, s (some i) := iSup_option s theorem iInter_option {ΞΉ} (s : Option ΞΉ β†’ Set Ξ±) : β‹‚ o, s o = s none ∩ β‹‚ i, s (some i) := iInf_option s section variable (p : ΞΉ β†’ Prop) [DecidablePred p] theorem iUnion_dite (f : βˆ€ i, p i β†’ Set Ξ±) (g : βˆ€ i, Β¬p i β†’ Set Ξ±) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) βˆͺ ⋃ (i) (h : Β¬p i), g i h := iSup_dite _ _ _ theorem iUnion_ite (f g : ΞΉ β†’ Set Ξ±) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) βˆͺ ⋃ (i) (_ : Β¬p i), g i := iUnion_dite _ _ _ theorem iInter_dite (f : βˆ€ i, p i β†’ Set Ξ±) (g : βˆ€ i, Β¬p i β†’ Set Ξ±) : β‹‚ i, (if h : p i then f i h else g i h) = (β‹‚ (i) (h : p i), f i h) ∩ β‹‚ (i) (h : Β¬p i), g i h := iInf_dite _ _ _ theorem iInter_ite (f g : ΞΉ β†’ Set Ξ±) : β‹‚ i, (if p i then f i else g i) = (β‹‚ (i) (_ : p i), f i) ∩ β‹‚ (i) (_ : Β¬p i), g i := iInter_dite _ _ _ end /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False β†’ Set Ξ±} : iInter s = univ := iInf_false theorem iUnion_false {s : False β†’ Set Ξ±} : iUnion s = βˆ… := iSup_false @[simp] theorem iInter_true {s : True β†’ Set Ξ±} : iInter s = s trivial := iInf_true @[simp] theorem iUnion_true {s : True β†’ Set Ξ±} : iUnion s = s trivial := iSup_true @[simp] theorem iInter_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Set Ξ±} : β‹‚ x, f x = β‹‚ (i) (h : p i), f ⟨i, h⟩ := iInf_exists @[simp] theorem iUnion_exists {p : ΞΉ β†’ Prop} {f : Exists p β†’ Set Ξ±} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists @[simp] theorem iUnion_empty : (⋃ _ : ΞΉ, βˆ… : Set Ξ±) = βˆ… := iSup_bot @[simp] theorem iInter_univ : (β‹‚ _ : ΞΉ, univ : Set Ξ±) = univ := iInf_top section variable {s : ΞΉ β†’ Set Ξ±} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = βˆ… ↔ βˆ€ i, s i = βˆ… := iSup_eq_bot @[simp] theorem iInter_eq_univ : β‹‚ i, s i = univ ↔ βˆ€ i, s i = univ := iInf_eq_top @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ βˆƒ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] theorem nonempty_biUnion {t : Set Ξ±} {s : Ξ± β†’ Set Ξ²} : (⋃ i ∈ t, s i).Nonempty ↔ βˆƒ i ∈ t, (s i).Nonempty := by simp theorem iUnion_nonempty_index (s : Set Ξ±) (t : s.Nonempty β†’ Set Ξ²) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, β€Ή_β€ΊβŸ© := iSup_exists end @[simp] theorem iInter_iInter_eq_left {b : Ξ²} {s : βˆ€ x : Ξ², x = b β†’ Set Ξ±} : β‹‚ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left @[simp] theorem iInter_iInter_eq_right {b : Ξ²} {s : βˆ€ x : Ξ², b = x β†’ Set Ξ±} : β‹‚ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : Ξ²} {s : βˆ€ x : Ξ², x = b β†’ Set Ξ±} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : Ξ²} {s : βˆ€ x : Ξ², b = x β†’ Set Ξ±} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q β†’ Set Ξ±) : β‹‚ h, s h = (β‹‚ h : p, s (Or.inl h)) ∩ β‹‚ h : q, s (Or.inr h) := iInf_or theorem iUnion_or {p q : Prop} (s : p ∨ q β†’ Set Ξ±) : ⋃ h, s h = (⋃ i, s (Or.inl i)) βˆͺ ⋃ j, s (Or.inr j) := iSup_or theorem iUnion_and {p q : Prop} (s : p ∧ q β†’ Set Ξ±) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and theorem iInter_and {p q : Prop} (s : p ∧ q β†’ Set Ξ±) : β‹‚ h, s h = β‹‚ (hp) (hq), s ⟨hp, hq⟩ := iInf_and theorem iUnion_comm (s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm theorem iInter_comm (s : ΞΉ β†’ ΞΉ' β†’ Set Ξ±) : β‹‚ (i) (i'), s i i' = β‹‚ (i') (i), s i i' := iInf_comm theorem iUnion_sigma {Ξ³ : Ξ± β†’ Type*} (s : Sigma Ξ³ β†’ Set Ξ²) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma Ξ³, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {Ξ³ : Ξ± β†’ Type*} (s : Sigma Ξ³ β†’ Set Ξ²) : β‹‚ ia, s ia = β‹‚ i, β‹‚ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : β‹‚ i, β‹‚ a, s i a = β‹‚ ia : Sigma Ξ³, s ia.1 ia.2 := iInf_sigma' _ theorem iUnionβ‚‚_comm (s : βˆ€ i₁, κ₁ i₁ β†’ βˆ€ iβ‚‚, ΞΊβ‚‚ iβ‚‚ β†’ Set Ξ±) : ⋃ (i₁) (j₁) (iβ‚‚) (jβ‚‚), s i₁ j₁ iβ‚‚ jβ‚‚ = ⋃ (iβ‚‚) (jβ‚‚) (i₁) (j₁), s i₁ j₁ iβ‚‚ jβ‚‚ := iSupβ‚‚_comm _ theorem iInterβ‚‚_comm (s : βˆ€ i₁, κ₁ i₁ β†’ βˆ€ iβ‚‚, ΞΊβ‚‚ iβ‚‚ β†’ Set Ξ±) : β‹‚ (i₁) (j₁) (iβ‚‚) (jβ‚‚), s i₁ j₁ iβ‚‚ jβ‚‚ = β‹‚ (iβ‚‚) (jβ‚‚) (i₁) (j₁), s i₁ j₁ iβ‚‚ jβ‚‚ := iInfβ‚‚_comm _ @[simp] theorem biUnion_and (p : ΞΉ β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p x ∧ q x y β†’ Set Ξ±) : ⋃ (x : ΞΉ) (y : ΞΉ') (h : p x ∧ q x y), s x y h = ⋃ (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ΞΉ'] @[simp] theorem biUnion_and' (p : ΞΉ' β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p y ∧ q x y β†’ Set Ξ±) : ⋃ (x : ΞΉ) (y : ΞΉ') (h : p y ∧ q x y), s x y h = ⋃ (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ΞΉ] @[simp] theorem biInter_and (p : ΞΉ β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p x ∧ q x y β†’ Set Ξ±) : β‹‚ (x : ΞΉ) (y : ΞΉ') (h : p x ∧ q x y), s x y h = β‹‚ (x : ΞΉ) (hx : p x) (y : ΞΉ') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ΞΉ'] @[simp] theorem biInter_and' (p : ΞΉ' β†’ Prop) (q : ΞΉ β†’ ΞΉ' β†’ Prop) (s : βˆ€ x y, p y ∧ q x y β†’ Set Ξ±) : β‹‚ (x : ΞΉ) (y : ΞΉ') (h : p y ∧ q x y), s x y h = β‹‚ (y : ΞΉ') (hy : p y) (x : ΞΉ) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ΞΉ] @[simp] theorem iUnion_iUnion_eq_or_left {b : Ξ²} {p : Ξ² β†’ Prop} {s : βˆ€ x : Ξ², x = b ∨ p x β†’ Set Ξ±} : ⋃ (x) (h), s x h = s b (Or.inl rfl) βˆͺ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] @[simp] theorem iInter_iInter_eq_or_left {b : Ξ²} {p : Ξ² β†’ Prop} {s : βˆ€ x : Ξ², x = b ∨ p x β†’ Set Ξ±} : β‹‚ (x) (h), s x h = s b (Or.inl rfl) ∩ β‹‚ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] lemma iUnion_sum {s : Ξ± βŠ• Ξ² β†’ Set Ξ³} : ⋃ x, s x = (⋃ x, s (.inl x)) βˆͺ ⋃ x, s (.inr x) := iSup_sum lemma iInter_sum {s : Ξ± βŠ• Ξ² β†’ Set Ξ³} : β‹‚ x, s x = (β‹‚ x, s (.inl x)) ∩ β‹‚ x, s (.inr x) := iInf_sum theorem iUnion_psigma {Ξ³ : Ξ± β†’ Type*} (s : PSigma Ξ³ β†’ Set Ξ²) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_psigma _ /-- A reversed version of `iUnion_psigma` with a curried map. -/ theorem iUnion_psigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : ⋃ i, ⋃ a, s i a = ⋃ ia : PSigma Ξ³, s ia.1 ia.2 := iSup_psigma' _ theorem iInter_psigma {Ξ³ : Ξ± β†’ Type*} (s : PSigma Ξ³ β†’ Set Ξ²) : β‹‚ ia, s ia = β‹‚ i, β‹‚ a, s ⟨i, a⟩ := iInf_psigma _ /-- A reversed version of `iInter_psigma` with a curried map. -/ theorem iInter_psigma' {Ξ³ : Ξ± β†’ Type*} (s : βˆ€ i, Ξ³ i β†’ Set Ξ²) : β‹‚ i, β‹‚ a, s i a = β‹‚ ia : PSigma Ξ³, s ia.1 ia.2 := iInf_psigma' _ /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnionβ‚‚`. -/ theorem mem_biUnion {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {x : Ξ±} {y : Ξ²} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnionβ‚‚_of_mem xs ytx /-- A specialization of `mem_iInterβ‚‚`. -/ theorem mem_biInter {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {y : Ξ²} (h : βˆ€ x ∈ s, y ∈ t x) : y ∈ β‹‚ x ∈ s, t x := mem_iInterβ‚‚_of_mem h /-- A specialization of `subset_iUnionβ‚‚`. -/ theorem subset_biUnion_of_mem {s : Set Ξ±} {u : Ξ± β†’ Set Ξ²} {x : Ξ±} (xs : x ∈ s) : u x βŠ† ⋃ x ∈ s, u x := subset_iUnionβ‚‚ (s := fun i _ => u i) x xs /-- A specialization of `iInterβ‚‚_subset`. -/ theorem biInter_subset_of_mem {s : Set Ξ±} {t : Ξ± β†’ Set Ξ²} {x : Ξ±} (xs : x ∈ s) : β‹‚ x ∈ s, t x βŠ† t x := iInterβ‚‚_subset x xs lemma biInter_subset_biUnion {s : Set Ξ±} (hs : s.Nonempty) {t : Ξ± β†’ Set Ξ²} : β‹‚ x ∈ s, t x βŠ† ⋃ x ∈ s, t x := biInf_le_biSup hs theorem biUnion_subset_biUnion_left {s s' : Set Ξ±} {t : Ξ± β†’ Set Ξ²} (h : s βŠ† s') : ⋃ x ∈ s, t x βŠ† ⋃ x ∈ s', t x := iUnionβ‚‚_subset fun _ hx => subset_biUnion_of_mem <| h hx theorem biInter_subset_biInter_left {s s' : Set Ξ±} {t : Ξ± β†’ Set Ξ²} (h : s' βŠ† s) : β‹‚ x ∈ s, t x βŠ† β‹‚ x ∈ s', t x := subset_iInterβ‚‚ fun _ hx => biInter_subset_of_mem <| h hx theorem biUnion_mono {s s' : Set Ξ±} {t t' : Ξ± β†’ Set Ξ²} (hs : s' βŠ† s) (h : βˆ€ x ∈ s, t x βŠ† t' x) : ⋃ x ∈ s', t x βŠ† ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnionβ‚‚_mono h theorem biInter_mono {s s' : Set Ξ±} {t t' : Ξ± β†’ Set Ξ²} (hs : s βŠ† s') (h : βˆ€ x ∈ s, t x βŠ† t' x) : β‹‚ x ∈ s', t x βŠ† β‹‚ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInterβ‚‚_mono h theorem biUnion_eq_iUnion (s : Set Ξ±) (t : βˆ€ x ∈ s, Set Ξ²) : ⋃ x ∈ s, t x β€Ή_β€Ί = ⋃ x : s, t x x.2 := iSup_subtype' theorem biInter_eq_iInter (s : Set Ξ±) (t : βˆ€ x ∈ s, Set Ξ²) : β‹‚ x ∈ s, t x β€Ή_β€Ί = β‹‚ x : s, t x x.2 := iInf_subtype' @[simp] lemma biUnion_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : ⋃ a ∈ s, t = t := biSup_const hs @[simp] lemma biInter_const {s : Set Ξ±} (hs : s.Nonempty) (t : Set Ξ²) : β‹‚ a ∈ s, t = t := biInf_const hs theorem iUnion_subtype (p : Ξ± β†’ Prop) (s : { x // p x } β†’ Set Ξ²) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype theorem iInter_subtype (p : Ξ± β†’ Prop) (s : { x // p x } β†’ Set Ξ²) : β‹‚ x : { x // p x }, s x = β‹‚ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype theorem biInter_empty (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ (βˆ… : Set Ξ±), u x = univ := iInf_emptyset theorem biInter_univ (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ @univ Ξ±, u x = β‹‚ x, u x := iInf_univ @[simp] theorem biUnion_self (s : Set Ξ±) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnionβ‚‚_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx @[simp] theorem iUnion_nonempty_self (s : Set Ξ±) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] theorem biInter_singleton (a : Ξ±) (s : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ({a} : Set Ξ±), s x = s a := iInf_singleton theorem biInter_union (s t : Set Ξ±) (u : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ s βˆͺ t, u x = (β‹‚ x ∈ s, u x) ∩ β‹‚ x ∈ t, u x := iInf_union theorem biInter_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ insert a s, t x = t a ∩ β‹‚ x ∈ s, t x := by simp theorem biInter_pair (a b : Ξ±) (s : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ({a, b} : Set Ξ±), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] theorem biInter_inter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : β‹‚ i ∈ s, f i ∩ t = (β‹‚ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] theorem inter_biInter {ΞΉ Ξ± : Type*} {s : Set ΞΉ} (hs : s.Nonempty) (f : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : β‹‚ i ∈ s, t ∩ f i = t ∩ β‹‚ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] theorem biUnion_empty (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ (βˆ… : Set Ξ±), s x = βˆ… := iSup_emptyset theorem biUnion_univ (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ @univ Ξ±, s x = ⋃ x, s x := iSup_univ theorem biUnion_singleton (a : Ξ±) (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ({a} : Set Ξ±), s x = s a := iSup_singleton @[simp] theorem biUnion_of_singleton (s : Set Ξ±) : ⋃ x ∈ s, {x} = s := ext <| by simp theorem biUnion_union (s t : Set Ξ±) (u : Ξ± β†’ Set Ξ²) : ⋃ x ∈ s βˆͺ t, u x = (⋃ x ∈ s, u x) βˆͺ ⋃ x ∈ t, u x := iSup_union @[simp] theorem iUnion_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β†’ Set Ξ²) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, β€Ήi ∈ sβ€ΊβŸ© := iUnion_subtype _ _ @[simp] theorem iInter_coe_set {Ξ± Ξ² : Type*} (s : Set Ξ±) (f : s β†’ Set Ξ²) : β‹‚ i, f i = β‹‚ i ∈ s, f ⟨i, β€Ήi ∈ sβ€ΊβŸ© := iInter_subtype _ _ theorem biUnion_insert (a : Ξ±) (s : Set Ξ±) (t : Ξ± β†’ Set Ξ²) : ⋃ x ∈ insert a s, t x = t a βˆͺ ⋃ x ∈ s, t x := by simp theorem biUnion_pair (a b : Ξ±) (s : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ({a, b} : Set Ξ±), s x = s a βˆͺ s b := by simp theorem inter_iUnionβ‚‚ (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] theorem iUnionβ‚‚_inter (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] theorem union_iInterβ‚‚ (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s βˆͺ β‹‚ (i) (j), t i j) = β‹‚ (i) (j), s βˆͺ t i j := by simp_rw [union_iInter] theorem iInterβ‚‚_union (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ (i) (j), s i j) βˆͺ t = β‹‚ (i) (j), s i j βˆͺ t := by simp_rw [iInter_union] theorem mem_sUnion_of_mem {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀ S := ⟨t, ht, hx⟩ -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : Ξ±} {t : Set Ξ±} {S : Set (Set Ξ±)} (hx : x βˆ‰ ⋃₀ S) (ht : t ∈ S) : x βˆ‰ t := fun h => hx ⟨t, ht, h⟩ theorem sInter_subset_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t ∈ S) : β‹‚β‚€ S βŠ† t := sInf_le tS theorem subset_sUnion_of_mem {S : Set (Set Ξ±)} {t : Set Ξ±} (tS : t ∈ S) : t βŠ† ⋃₀ S := le_sSup tS theorem subset_sUnion_of_subset {s : Set Ξ±} (t : Set (Set Ξ±)) (u : Set Ξ±) (h₁ : s βŠ† u) (hβ‚‚ : u ∈ t) : s βŠ† ⋃₀ t := Subset.trans h₁ (subset_sUnion_of_mem hβ‚‚) theorem sUnion_subset {S : Set (Set Ξ±)} {t : Set Ξ±} (h : βˆ€ t' ∈ S, t' βŠ† t) : ⋃₀ S βŠ† t := sSup_le h @[simp] theorem sUnion_subset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : ⋃₀ s βŠ† t ↔ βˆ€ t' ∈ s, t' βŠ† t := sSup_le_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set Ξ±)} {f : Set Ξ± β†’ Set Ξ±} (hf : βˆ€ t : Set Ξ±, t βŠ† f t) : ⋃₀ s βŠ† ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set Ξ±)} {f : Set Ξ± β†’ Set Ξ±} (hf : βˆ€ t : Set Ξ±, f t βŠ† t) : ⋃₀ (f '' s) βŠ† ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set Ξ±. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut β–Έ hf u) hxt⟩ theorem subset_sInter {S : Set (Set Ξ±)} {t : Set Ξ±} (h : βˆ€ t' ∈ S, t βŠ† t') : t βŠ† β‹‚β‚€ S := le_sInf h @[simp] theorem subset_sInter_iff {S : Set (Set Ξ±)} {t : Set Ξ±} : t βŠ† β‹‚β‚€ S ↔ βˆ€ t' ∈ S, t βŠ† t' := le_sInf_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set Ξ±)} (h : S βŠ† T) : ⋃₀ S βŠ† ⋃₀ T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) @[gcongr] theorem sInter_subset_sInter {S T : Set (Set Ξ±)} (h : S βŠ† T) : β‹‚β‚€ T βŠ† β‹‚β‚€ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) @[simp] theorem sUnion_empty : ⋃₀ βˆ… = (βˆ… : Set Ξ±) := sSup_empty @[simp] theorem sInter_empty : β‹‚β‚€ βˆ… = (univ : Set Ξ±) := sInf_empty @[simp] theorem sUnion_singleton (s : Set Ξ±) : ⋃₀ {s} = s := sSup_singleton @[simp] theorem sInter_singleton (s : Set Ξ±) : β‹‚β‚€ {s} = s := sInf_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set Ξ±)} : ⋃₀ S = βˆ… ↔ βˆ€ s ∈ S, s = βˆ… := sSup_eq_bot @[simp] theorem sInter_eq_univ {S : Set (Set Ξ±)} : β‹‚β‚€ S = univ ↔ βˆ€ s ∈ S, s = univ := sInf_eq_top theorem subset_powerset_iff {s : Set (Set Ξ±)} {t : Set Ξ±} : s βŠ† 𝒫 t ↔ ⋃₀ s βŠ† t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ Β· : Set (Set Ξ±) β†’ Set Ξ±) (𝒫 Β· : Set Ξ± β†’ Set (Set Ξ±)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnionPowersetGI : GaloisInsertion (⋃₀ Β· : Set (Set Ξ±) β†’ Set Ξ±) (𝒫 Β· : Set Ξ± β†’ Set (Set Ξ±)) := gi_sSup_Iic @[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI /-- If all sets in a collection are either `βˆ…` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set Ξ±)} (h : S βŠ† {βˆ…, univ}) : ⋃₀ S ∈ ({βˆ…, univ} : Set (Set Ξ±)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set Ξ±)} : (⋃₀ S).Nonempty ↔ βˆƒ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] theorem Nonempty.of_sUnion {s : Set (Set Ξ±)} (h : (⋃₀ s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ theorem Nonempty.of_sUnion_eq_univ [Nonempty Ξ±] {s : Set (Set Ξ±)} (h : ⋃₀ s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm β–Έ univ_nonempty theorem sUnion_union (S T : Set (Set Ξ±)) : ⋃₀ (S βˆͺ T) = ⋃₀ S βˆͺ ⋃₀ T := sSup_union theorem sInter_union (S T : Set (Set Ξ±)) : β‹‚β‚€ (S βˆͺ T) = β‹‚β‚€ S ∩ β‹‚β‚€ T := sInf_union @[simp] theorem sUnion_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : ⋃₀ insert s T = s βˆͺ ⋃₀ T := sSup_insert @[simp] theorem sInter_insert (s : Set Ξ±) (T : Set (Set Ξ±)) : β‹‚β‚€ insert s T = s ∩ β‹‚β‚€ T := sInf_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set Ξ±)) : ⋃₀ (s \ {βˆ…}) = ⋃₀ s := sSup_diff_singleton_bot s @[simp] theorem sInter_diff_singleton_univ (s : Set (Set Ξ±)) : β‹‚β‚€ (s \ {univ}) = β‹‚β‚€ s := sInf_diff_singleton_top s theorem sUnion_pair (s t : Set Ξ±) : ⋃₀ {s, t} = s βˆͺ t := sSup_pair theorem sInter_pair (s t : Set Ξ±) : β‹‚β‚€ {s, t} = s ∩ t := sInf_pair @[simp] theorem sUnion_image (f : Ξ± β†’ Set Ξ²) (s : Set Ξ±) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a := sSup_image @[simp] theorem sInter_image (f : Ξ± β†’ Set Ξ²) (s : Set Ξ±) : β‹‚β‚€ (f '' s) = β‹‚ a ∈ s, f a := sInf_image @[simp] lemma sUnion_image2 (f : Ξ± β†’ Ξ² β†’ Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) : ⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2 @[simp] lemma sInter_image2 (f : Ξ± β†’ Ξ² β†’ Set Ξ³) (s : Set Ξ±) (t : Set Ξ²) : β‹‚β‚€ (image2 f s t) = β‹‚ (a ∈ s) (b ∈ t), f a b := sInf_image2 @[simp] theorem sUnion_range (f : ΞΉ β†’ Set Ξ²) : ⋃₀ range f = ⋃ x, f x := rfl @[simp] theorem sInter_range (f : ΞΉ β†’ Set Ξ²) : β‹‚β‚€ range f = β‹‚ x, f x := rfl theorem iUnion_eq_univ_iff {f : ΞΉ β†’ Set Ξ±} : ⋃ i, f i = univ ↔ βˆ€ x, βˆƒ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] theorem iUnionβ‚‚_eq_univ_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : ⋃ (i) (j), s i j = univ ↔ βˆ€ a, βˆƒ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] theorem sUnion_eq_univ_iff {c : Set (Set Ξ±)} : ⋃₀ c = univ ↔ βˆ€ a, βˆƒ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] -- classical theorem iInter_eq_empty_iff {f : ΞΉ β†’ Set Ξ±} : β‹‚ i, f i = βˆ… ↔ βˆ€ x, βˆƒ i, x βˆ‰ f i := by simp [Set.eq_empty_iff_forall_not_mem] -- classical theorem iInterβ‚‚_eq_empty_iff {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : β‹‚ (i) (j), s i j = βˆ… ↔ βˆ€ a, βˆƒ i j, a βˆ‰ s i j := by simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall] -- classical theorem sInter_eq_empty_iff {c : Set (Set Ξ±)} : β‹‚β‚€ c = βˆ… ↔ βˆ€ a, βˆƒ b ∈ c, a βˆ‰ b := by simp [Set.eq_empty_iff_forall_not_mem] -- classical @[simp] theorem nonempty_iInter {f : ΞΉ β†’ Set Ξ±} : (β‹‚ i, f i).Nonempty ↔ βˆƒ x, βˆ€ i, x ∈ f i := by simp [nonempty_iff_ne_empty, iInter_eq_empty_iff] -- classical theorem nonempty_iInterβ‚‚ {s : βˆ€ i, ΞΊ i β†’ Set Ξ±} : (β‹‚ (i) (j), s i j).Nonempty ↔ βˆƒ a, βˆ€ i j, a ∈ s i j := by simp -- classical @[simp] theorem nonempty_sInter {c : Set (Set Ξ±)} : (β‹‚β‚€ c).Nonempty ↔ βˆƒ a, βˆ€ b ∈ c, a ∈ b := by simp [nonempty_iff_ne_empty, sInter_eq_empty_iff] -- classical theorem compl_sUnion (S : Set (Set Ξ±)) : (⋃₀ S)ᢜ = β‹‚β‚€ (compl '' S) := ext fun x => by simp -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set Ξ±)) : ⋃₀ S = (β‹‚β‚€ (compl '' S))ᢜ := by rw [← compl_compl (⋃₀ S), compl_sUnion] -- classical theorem compl_sInter (S : Set (Set Ξ±)) : (β‹‚β‚€ S)ᢜ = ⋃₀ (compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set Ξ±)) : β‹‚β‚€ S = (⋃₀ (compl '' S))ᢜ := by rw [← compl_compl (β‹‚β‚€ S), compl_sInter] theorem inter_empty_of_inter_sUnion_empty {s t : Set Ξ±} {S : Set (Set Ξ±)} (hs : t ∈ S) (h : s ∩ ⋃₀ S = βˆ…) : s ∩ t = βˆ… := eq_empty_of_subset_empty <| by rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) theorem range_sigma_eq_iUnion_range {Ξ³ : Ξ± β†’ Type*} (f : Sigma Ξ³ β†’ Ξ²) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp theorem iUnion_eq_range_sigma (s : Ξ± β†’ Set Ξ²) : ⋃ i, s i = range fun a : Ξ£i, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_eq_range_psigma (s : ΞΉ β†’ Set Ξ²) : ⋃ i, s i = range fun a : Ξ£'i, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_image_preimage_sigma_mk_eq_self {ΞΉ : Type*} {Οƒ : ΞΉ β†’ Type*} (s : Set (Sigma Οƒ)) : ⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by ext x simp only [mem_iUnion, mem_image, mem_preimage] constructor Β· rintro ⟨i, a, h, rfl⟩ exact h Β· intro h obtain ⟨i, a⟩ := x exact ⟨i, a, h, rfl⟩ theorem Sigma.univ (X : Ξ± β†’ Type*) : (Set.univ : Set (Ξ£a, X a)) = ⋃ a, range (Sigma.mk a) := Set.ext fun x => iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩ alias sUnion_mono := sUnion_subset_sUnion alias sInter_mono := sInter_subset_sInter theorem iUnion_subset_iUnion_const {s : Set Ξ±} (h : ΞΉ β†’ ΞΉβ‚‚) : ⋃ _ : ΞΉ, s βŠ† ⋃ _ : ΞΉβ‚‚, s := iSup_const_mono (Ξ± := Set Ξ±) h @[simp] theorem iUnion_singleton_eq_range (f : Ξ± β†’ Ξ²) : ⋃ x : Ξ±, {f x} = range f := by ext x simp [@eq_comm _ x] theorem iUnion_insert_eq_range_union_iUnion {ΞΉ : Type*} (x : ΞΉ β†’ Ξ²) (t : ΞΉ β†’ Set Ξ²) : ⋃ i, insert (x i) (t i) = range x βˆͺ ⋃ i, t i := by simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range] theorem iUnion_of_singleton (Ξ± : Type*) : (⋃ x, {x} : Set Ξ±) = univ := by simp [Set.ext_iff] theorem iUnion_of_singleton_coe (s : Set Ξ±) : ⋃ i : s, ({(i : Ξ±)} : Set Ξ±) = s := by simp theorem sUnion_eq_biUnion {s : Set (Set Ξ±)} : ⋃₀ s = ⋃ (i : Set Ξ±) (_ : i ∈ s), i := by rw [← sUnion_image, image_id'] theorem sInter_eq_biInter {s : Set (Set Ξ±)} : β‹‚β‚€ s = β‹‚ (i : Set Ξ±) (_ : i ∈ s), i := by rw [← sInter_image, image_id'] theorem sUnion_eq_iUnion {s : Set (Set Ξ±)} : ⋃₀ s = ⋃ i : s, i := by simp only [← sUnion_range, Subtype.range_coe] theorem sInter_eq_iInter {s : Set (Set Ξ±)} : β‹‚β‚€ s = β‹‚ i : s, i := by simp only [← sInter_range, Subtype.range_coe] @[simp] theorem iUnion_of_empty [IsEmpty ΞΉ] (s : ΞΉ β†’ Set Ξ±) : ⋃ i, s i = βˆ… := iSup_of_empty _ @[simp] theorem iInter_of_empty [IsEmpty ΞΉ] (s : ΞΉ β†’ Set Ξ±) : β‹‚ i, s i = univ := iInf_of_empty _ theorem union_eq_iUnion {s₁ sβ‚‚ : Set Ξ±} : s₁ βˆͺ sβ‚‚ = ⋃ b : Bool, cond b s₁ sβ‚‚ := sup_eq_iSup s₁ sβ‚‚ theorem inter_eq_iInter {s₁ sβ‚‚ : Set Ξ±} : s₁ ∩ sβ‚‚ = β‹‚ b : Bool, cond b s₁ sβ‚‚ := inf_eq_iInf s₁ sβ‚‚ theorem sInter_union_sInter {S T : Set (Set Ξ±)} : β‹‚β‚€ S βˆͺ β‹‚β‚€ T = β‹‚ p ∈ S Γ—Λ’ T, (p : Set Ξ± Γ— Set Ξ±).1 βˆͺ p.2 := sInf_sup_sInf theorem sUnion_inter_sUnion {s t : Set (Set Ξ±)} : ⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s Γ—Λ’ t, (p : Set Ξ± Γ— Set Ξ±).1 ∩ p.2 := sSup_inf_sSup theorem biUnion_iUnion (s : ΞΉ β†’ Set Ξ±) (t : Ξ± β†’ Set Ξ²) : ⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ΞΉ] theorem biInter_iUnion (s : ΞΉ β†’ Set Ξ±) (t : Ξ± β†’ Set Ξ²) : β‹‚ x ∈ ⋃ i, s i, t x = β‹‚ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ΞΉ] theorem sUnion_iUnion (s : ΞΉ β†’ Set (Set Ξ±)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by simp only [sUnion_eq_biUnion, biUnion_iUnion] theorem sInter_iUnion (s : ΞΉ β†’ Set (Set Ξ±)) : β‹‚β‚€ ⋃ i, s i = β‹‚ i, β‹‚β‚€ s i := by simp only [sInter_eq_biInter, biInter_iUnion] theorem iUnion_range_eq_sUnion {Ξ± Ξ² : Type*} (C : Set (Set Ξ±)) {f : βˆ€ s : C, Ξ² β†’ (s : Type _)} (hf : βˆ€ s : C, Surjective (f s)) : ⋃ y : Ξ², range (fun s : C => (f s y).val) = ⋃₀ C := by ext x; constructor Β· rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩ refine ⟨_, hs, ?_⟩ exact (f ⟨s, hs⟩ y).2 Β· rintro ⟨s, hs, hx⟩ obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩ refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩ exact congr_arg Subtype.val hy theorem iUnion_range_eq_iUnion (C : ΞΉ β†’ Set Ξ±) {f : βˆ€ x : ΞΉ, Ξ² β†’ C x} (hf : βˆ€ x : ΞΉ, Surjective (f x)) : ⋃ y : Ξ², range (fun x : ΞΉ => (f x y).val) = ⋃ x, C x := by ext x; rw [mem_iUnion, mem_iUnion]; constructor Β· rintro ⟨y, i, rfl⟩ exact ⟨i, (f i y).2⟩ Β· rintro ⟨i, hx⟩ obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩ exact ⟨y, i, congr_arg Subtype.val hy⟩ theorem union_distrib_iInter_left (s : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : (t βˆͺ β‹‚ i, s i) = β‹‚ i, t βˆͺ s i := sup_iInf_eq _ _ theorem union_distrib_iInterβ‚‚_left (s : Set Ξ±) (t : βˆ€ i, ΞΊ i β†’ Set Ξ±) : (s βˆͺ β‹‚ (i) (j), t i j) = β‹‚ (i) (j), s βˆͺ t i j := by simp_rw [union_distrib_iInter_left] theorem union_distrib_iInter_right (s : ΞΉ β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ i, s i) βˆͺ t = β‹‚ i, s i βˆͺ t := iInf_sup_eq _ _ theorem union_distrib_iInterβ‚‚_right (s : βˆ€ i, ΞΊ i β†’ Set Ξ±) (t : Set Ξ±) : (β‹‚ (i) (j), s i j) βˆͺ t = β‹‚ (i) (j), s i j βˆͺ t := by simp_rw [union_distrib_iInter_right] lemma biUnion_lt_eq_iUnion [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup lemma biUnion_le_eq_iUnion [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m ≀ n), s m = ⋃ n, s n := biSup_le_eq_iSup lemma biInter_lt_eq_iInter [LT Ξ±] [NoMaxOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m < n), s m = β‹‚ (n), s n := biInf_lt_eq_iInf lemma biInter_le_eq_iInter [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m ≀ n), s m = β‹‚ (n), s n := biInf_le_eq_iInf lemma biUnion_gt_eq_iUnion [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup lemma biUnion_ge_eq_iUnion [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : ⋃ (n) (m β‰₯ n), s m = ⋃ n, s n := biSup_ge_eq_iSup lemma biInter_gt_eq_iInf [LT Ξ±] [NoMinOrder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m > n), s m = β‹‚ n, s n := biInf_gt_eq_iInf lemma biInter_ge_eq_iInf [Preorder Ξ±] {s : Ξ± β†’ Set Ξ²} : β‹‚ (n) (m β‰₯ n), s m = β‹‚ n, s n := biInf_ge_eq_iInf section le variable {ΞΉ : Type*} [PartialOrder ΞΉ] (s : ΞΉ β†’ Set Ξ±) (i : ΞΉ) theorem biUnion_le : (⋃ j ≀ i, s j) = (⋃ j < i, s j) βˆͺ s i := biSup_le_eq_sup s i theorem biInter_le : (β‹‚ j ≀ i, s j) = (β‹‚ j < i, s j) ∩ s i := biInf_le_eq_inf s i theorem biUnion_ge : (⋃ j β‰₯ i, s j) = s i βˆͺ ⋃ j > i, s j := biSup_ge_eq_sup s i theorem biInter_ge : (β‹‚ j β‰₯ i, s j) = s i ∩ β‹‚ j > i, s j := biInf_ge_eq_inf s i end le section Pi variable {Ο€ : Ξ± β†’ Type*} theorem pi_def (i : Set Ξ±) (s : βˆ€ a, Set (Ο€ a)) : pi i s = β‹‚ a ∈ i, eval a ⁻¹' s a := by ext simp theorem univ_pi_eq_iInter (t : βˆ€ i, Set (Ο€ i)) : pi univ t = β‹‚ i, eval i ⁻¹' t i := by simp only [pi_def, iInter_true, mem_univ] theorem pi_diff_pi_subset (i : Set Ξ±) (s t : βˆ€ a, Set (Ο€ a)) : pi i s \ pi i t βŠ† ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by refine diff_subset_comm.2 fun x hx a ha => ?_ simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not, eval_apply] at hx exact hx.2 _ ha (hx.1 _ ha) theorem iUnion_univ_pi {ΞΉ : Ξ± β†’ Type*} (t : (a : Ξ±) β†’ ΞΉ a β†’ Set (Ο€ a)) : ⋃ x : (a : Ξ±) β†’ ΞΉ a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ΞΉ a, t a j := by ext simp [Classical.skolem] end Pi section Directed theorem directedOn_iUnion {r} {f : ΞΉ β†’ Set Ξ±} (hd : Directed (Β· βŠ† Β·) f) (h : βˆ€ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp] exact fun a₁ b₁ fb₁ aβ‚‚ bβ‚‚ fbβ‚‚ => let ⟨z, zb₁, zbβ‚‚βŸ© := hd b₁ bβ‚‚ let ⟨x, xf, xa₁, xaβ‚‚βŸ© := h z a₁ (zb₁ fb₁) aβ‚‚ (zbβ‚‚ fbβ‚‚) ⟨x, ⟨z, xf⟩, xa₁, xaβ‚‚βŸ© theorem directedOn_sUnion {r} {S : Set (Set Ξ±)} (hd : DirectedOn (Β· βŠ† Β·) S) (h : βˆ€ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by rw [sUnion_eq_iUnion] exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2) theorem pairwise_iUnionβ‚‚ {S : Set (Set Ξ±)} (hd : DirectedOn (Β· βŠ† Β·) S) (r : Ξ± β†’ Ξ± β†’ Prop) (h : βˆ€ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp] intro x S hS hx y T hT hy hne obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT exact h U hU (hSU hx) (hTU hy) hne end Directed end Set namespace Function namespace Surjective theorem iUnion_comp {f : ΞΉ β†’ ΞΉβ‚‚} (hf : Surjective f) (g : ΞΉβ‚‚ β†’ Set Ξ±) : ⋃ x, g (f x) = ⋃ y, g y := hf.iSup_comp g theorem iInter_comp {f : ΞΉ β†’ ΞΉβ‚‚} (hf : Surjective f) (g : ΞΉβ‚‚ β†’ Set Ξ±) : β‹‚ x, g (f x) = β‹‚ y, g y := hf.iInf_comp g end Surjective end Function
/-! ### Disjoint sets
Mathlib/Data/Set/Lattice.lean
1,188
1,189
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel -/ import Mathlib.Topology.Bornology.Constructions import Mathlib.Topology.MetricSpace.Pseudo.Defs import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Products of pseudometric spaces and other constructions This file constructs the supremum distance on binary products of pseudometric spaces and provides instances for type synonyms. -/ open Bornology Filter Metric Set Topology open scoped NNReal variable {Ξ± Ξ² : Type*} [PseudoMetricSpace Ξ±] /-- Pseudometric space structure pulled back by a function. -/ abbrev PseudoMetricSpace.induced {Ξ± Ξ²} (f : Ξ± β†’ Ξ²) (m : PseudoMetricSpace Ξ²) : PseudoMetricSpace Ξ± where dist x y := dist (f x) (f y) dist_self _ := dist_self _ dist_comm _ _ := dist_comm _ _ dist_triangle _ _ _ := dist_triangle _ _ _ edist x y := edist (f x) (f y) edist_dist _ _ := edist_dist _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf toBornology := Bornology.induced f cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by simp only [← isBounded_def, isBounded_iff, forall_mem_image, mem_setOf] /-- Pull back a pseudometric space structure by an inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ def Topology.IsInducing.comapPseudoMetricSpace {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±] [m : PseudoMetricSpace Ξ²] {f : Ξ± β†’ Ξ²} (hf : IsInducing f) : PseudoMetricSpace Ξ± := .replaceTopology (.induced f m) hf.eq_induced @[deprecated (since := "2024-10-28")] alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace /-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ def IsUniformInducing.comapPseudoMetricSpace {Ξ± Ξ²} [UniformSpace Ξ±] [m : PseudoMetricSpace Ξ²] (f : Ξ± β†’ Ξ²) (h : IsUniformInducing f) : PseudoMetricSpace Ξ± := .replaceUniformity (.induced f m) h.comap_uniformity.symm instance Subtype.pseudoMetricSpace {p : Ξ± β†’ Prop} : PseudoMetricSpace (Subtype p) := PseudoMetricSpace.induced Subtype.val β€Ή_β€Ί lemma Subtype.dist_eq {p : Ξ± β†’ Prop} (x y : Subtype p) : dist x y = dist (x : Ξ±) y := rfl lemma Subtype.nndist_eq {p : Ξ± β†’ Prop} (x y : Subtype p) : nndist x y = nndist (x : Ξ±) y := rfl namespace MulOpposite @[to_additive] instance instPseudoMetricSpace : PseudoMetricSpace αᡐᡒᡖ := PseudoMetricSpace.induced MulOpposite.unop β€Ή_β€Ί @[to_additive (attr := simp)] lemma dist_unop (x y : αᡐᡒᡖ) : dist (unop x) (unop y) = dist x y := rfl @[to_additive (attr := simp)] lemma dist_op (x y : Ξ±) : dist (op x) (op y) = dist x y := rfl @[to_additive (attr := simp)] lemma nndist_unop (x y : αᡐᡒᡖ) : nndist (unop x) (unop y) = nndist x y := rfl @[to_additive (attr := simp)] lemma nndist_op (x y : Ξ±) : nndist (op x) (op y) = nndist x y := rfl end MulOpposite section NNReal instance : PseudoMetricSpace ℝβ‰₯0 := Subtype.pseudoMetricSpace lemma NNReal.dist_eq (a b : ℝβ‰₯0) : dist a b = |(a : ℝ) - b| := rfl lemma NNReal.nndist_eq (a b : ℝβ‰₯0) : nndist a b = max (a - b) (b - a) := eq_of_forall_ge_iff fun _ => by simp only [max_le_iff, tsub_le_iff_right (Ξ± := ℝβ‰₯0)] simp only [← NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff, tsub_le_iff_right, NNReal.coe_add] @[simp] lemma NNReal.nndist_zero_eq_val (z : ℝβ‰₯0) : nndist 0 z = z := by simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le'] @[simp] lemma NNReal.nndist_zero_eq_val' (z : ℝβ‰₯0) : nndist z 0 = z := by rw [nndist_comm] exact NNReal.nndist_zero_eq_val z lemma NNReal.le_add_nndist (a b : ℝβ‰₯0) : a ≀ b + nndist a b := by suffices (a : ℝ) ≀ (b : ℝ) + dist a b by rwa [← NNReal.coe_le_coe, NNReal.coe_add, coe_nndist] rw [← sub_le_iff_le_add'] exact le_of_abs_le (dist_eq a b).ge lemma NNReal.ball_zero_eq_Ico' (c : ℝβ‰₯0) : Metric.ball (0 : ℝβ‰₯0) c.toReal = Set.Ico 0 c := by ext x; simp lemma NNReal.ball_zero_eq_Ico (c : ℝ) : Metric.ball (0 : ℝβ‰₯0) c = Set.Ico 0 c.toNNReal := by by_cases c_pos : 0 < c Β· convert NNReal.ball_zero_eq_Ico' ⟨c, c_pos.le⟩ simp [Real.toNNReal, c_pos.le] simp [not_lt.mp c_pos] lemma NNReal.closedBall_zero_eq_Icc' (c : ℝβ‰₯0) : Metric.closedBall (0 : ℝβ‰₯0) c.toReal = Set.Icc 0 c := by ext x; simp lemma NNReal.closedBall_zero_eq_Icc {c : ℝ} (c_nn : 0 ≀ c) : Metric.closedBall (0 : ℝβ‰₯0) c = Set.Icc 0 c.toNNReal := by convert NNReal.closedBall_zero_eq_Icc' ⟨c, c_nn⟩ simp [Real.toNNReal, c_nn] end NNReal namespace ULift variable [PseudoMetricSpace Ξ²] instance : PseudoMetricSpace (ULift Ξ²) := PseudoMetricSpace.induced ULift.down β€Ή_β€Ί lemma dist_eq (x y : ULift Ξ²) : dist x y = dist x.down y.down := rfl lemma nndist_eq (x y : ULift Ξ²) : nndist x y = nndist x.down y.down := rfl @[simp] lemma dist_up_up (x y : Ξ²) : dist (ULift.up x) (ULift.up y) = dist x y := rfl @[simp] lemma nndist_up_up (x y : Ξ²) : nndist (ULift.up x) (ULift.up y) = nndist x y := rfl end ULift section Prod variable [PseudoMetricSpace Ξ²] instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (Ξ± Γ— Ξ²) := let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun x y : Ξ± Γ— Ξ² => dist x.1 y.1 βŠ” dist x.2 y.2) (fun _ _ => (max_lt (edist_lt_top _ _) (edist_lt_top _ _)).ne) fun x y => by simp only [dist_edist, ← ENNReal.toReal_max (edist_ne_top _ _) (edist_ne_top _ _), Prod.edist_eq] i.replaceBornology fun s => by simp only [← isBounded_image_fst_and_snd, isBounded_iff_eventually, forall_mem_image, ← eventually_and, ← forall_and, ← max_le_iff] rfl lemma Prod.dist_eq {x y : Ξ± Γ— Ξ²} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl @[simp] lemma dist_prod_same_left {x : Ξ±} {y₁ yβ‚‚ : Ξ²} : dist (x, y₁) (x, yβ‚‚) = dist y₁ yβ‚‚ := by simp [Prod.dist_eq, dist_nonneg] @[simp] lemma dist_prod_same_right {x₁ xβ‚‚ : Ξ±} {y : Ξ²} : dist (x₁, y) (xβ‚‚, y) = dist x₁ xβ‚‚ := by simp [Prod.dist_eq, dist_nonneg] lemma ball_prod_same (x : Ξ±) (y : Ξ²) (r : ℝ) : ball x r Γ—Λ’ ball y r = ball (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma closedBall_prod_same (x : Ξ±) (y : Ξ²) (r : ℝ) : closedBall x r Γ—Λ’ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma sphere_prod (x : Ξ± Γ— Ξ²) (r : ℝ) : sphere x r = sphere x.1 r Γ—Λ’ closedBall x.2 r βˆͺ closedBall x.1 r Γ—Λ’ sphere x.2 r := by obtain hr | rfl | hr := lt_trichotomy r 0 Β· simp [hr] Β· cases x simp_rw [← closedBall_eq_sphere_of_nonpos le_rfl, union_self, closedBall_prod_same] Β· ext ⟨x', y'⟩ simp_rw [Set.mem_union, Set.mem_prod, Metric.mem_closedBall, Metric.mem_sphere, Prod.dist_eq, max_eq_iff] refine or_congr (and_congr_right ?_) (and_comm.trans (and_congr_left ?_)) all_goals rintro rfl; rfl end Prod lemma uniformContinuous_dist : UniformContinuous fun p : Ξ± Γ— Ξ± => dist p.1 p.2 := Metric.uniformContinuous_iff.2 fun Ξ΅ Ξ΅0 => ⟨Ρ / 2, half_pos Ξ΅0, fun {a b} h => calc dist (dist a.1 a.2) (dist b.1 b.2) ≀ dist a.1 b.1 + dist a.2 b.2 :=
dist_dist_dist_le _ _ _ _ _ ≀ dist a b + dist a b := add_le_add (le_max_left _ _) (le_max_right _ _)
Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean
191
192
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Action.Pi import Mathlib.Algebra.Order.AbsoluteValue.Basic import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Ring.Pi import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Tactic.GCongr /-! # Cauchy sequences A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where applicable, lemmas that will be reused in other contexts have been stated in extra generality. There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology. This is a concrete implementation that is useful for simplicity and computability reasons. ## Important definitions * `IsCauSeq`: a predicate that says `f : β„• β†’ Ξ²` is Cauchy. * `CauSeq`: the type of Cauchy sequences valued in type `Ξ²` with respect to an absolute value function `abv`. ## Tags sequence, cauchy, abs val, absolute value -/ assert_not_exists Finset Module Submonoid FloorRing Module variable {Ξ± Ξ² : Type*} open IsAbsoluteValue section variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Ring Ξ²] (abv : Ξ² β†’ Ξ±) [IsAbsoluteValue abv] theorem rat_add_continuous_lemma {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) : βˆƒ Ξ΄ > 0, βˆ€ {a₁ aβ‚‚ b₁ bβ‚‚ : Ξ²}, abv (a₁ - b₁) < Ξ΄ β†’ abv (aβ‚‚ - bβ‚‚) < Ξ΄ β†’ abv (a₁ + aβ‚‚ - (b₁ + bβ‚‚)) < Ξ΅ := ⟨Ρ / 2, half_pos Ξ΅0, fun {a₁ aβ‚‚ b₁ bβ‚‚} h₁ hβ‚‚ => by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ hβ‚‚)⟩ theorem rat_mul_continuous_lemma {Ξ΅ K₁ Kβ‚‚ : Ξ±} (Ξ΅0 : 0 < Ξ΅) : βˆƒ Ξ΄ > 0, βˆ€ {a₁ aβ‚‚ b₁ bβ‚‚ : Ξ²}, abv a₁ < K₁ β†’ abv bβ‚‚ < Kβ‚‚ β†’ abv (a₁ - b₁) < Ξ΄ β†’ abv (aβ‚‚ - bβ‚‚) < Ξ΄ β†’ abv (a₁ * aβ‚‚ - b₁ * bβ‚‚) < Ξ΅ := by have K0 : (0 : Ξ±) < max 1 (max K₁ Kβ‚‚) := lt_of_lt_of_le zero_lt_one (le_max_left _ _) have Ξ΅K := div_pos (half_pos Ξ΅0) K0 refine ⟨_, Ξ΅K, fun {a₁ aβ‚‚ b₁ bβ‚‚} ha₁ hbβ‚‚ h₁ hβ‚‚ => ?_⟩ replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ Kβ‚‚) (le_max_right 1 _)) replace hbβ‚‚ := lt_of_lt_of_le hbβ‚‚ (le_trans (le_max_right K₁ _) (le_max_right 1 _)) set M := max 1 (max K₁ Kβ‚‚) have : abv (a₁ - b₁) * abv bβ‚‚ + abv (aβ‚‚ - bβ‚‚) * abv a₁ < Ξ΅ / 2 / M * M + Ξ΅ / 2 / M * M := by gcongr rw [← abv_mul abv, mul_comm, div_mul_cancelβ‚€ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using lt_of_le_of_lt (abv_add abv _ _) this theorem rat_inv_continuous_lemma {Ξ² : Type*} [DivisionRing Ξ²] (abv : Ξ² β†’ Ξ±) [IsAbsoluteValue abv] {Ξ΅ K : Ξ±} (Ξ΅0 : 0 < Ξ΅) (K0 : 0 < K) : βˆƒ Ξ΄ > 0, βˆ€ {a b : Ξ²}, K ≀ abv a β†’ K ≀ abv b β†’ abv (a - b) < Ξ΄ β†’ abv (a⁻¹ - b⁻¹) < Ξ΅ := by refine ⟨K * Ξ΅ * K, mul_pos (mul_pos K0 Ξ΅0) K0, fun {a b} ha hb h => ?_⟩ have a0 := K0.trans_le ha have b0 := K0.trans_le hb rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv, abv_inv abv, abv_sub abv] refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le rw [mul_assoc, inv_mul_cancel_rightβ‚€ b0.ne', ← mul_assoc, mul_inv_cancelβ‚€ a0.ne', one_mul] refine h.trans_le ?_ gcongr end /-- A sequence is Cauchy if the distance between its entries tends to zero. -/ @[nolint unusedArguments] def IsCauSeq {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {Ξ² : Type*} [Ring Ξ²] (abv : Ξ² β†’ Ξ±) (f : β„• β†’ Ξ²) : Prop := βˆ€ Ξ΅ > 0, βˆƒ i, βˆ€ j β‰₯ i, abv (f j - f i) < Ξ΅ namespace IsCauSeq variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [Ring Ξ²] {abv : Ξ² β†’ Ξ±} [IsAbsoluteValue abv] {f g : β„• β†’ Ξ²} -- see Note [nolint_ge] --@[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchyβ‚‚ (hf : IsCauSeq abv f) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) : βˆƒ i, βˆ€ j β‰₯ i, βˆ€ k β‰₯ i, abv (f j - f k) < Ξ΅ := by refine (hf _ (half_pos Ξ΅0)).imp fun i hi j ij k ik => ?_ rw [← add_halves Ξ΅] refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_) rw [abv_sub abv]; exact hi _ ik theorem cauchy₃ (hf : IsCauSeq abv f) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) : βˆƒ i, βˆ€ j β‰₯ i, βˆ€ k β‰₯ j, abv (f k - f j) < Ξ΅ := let ⟨i, H⟩ := hf.cauchyβ‚‚ Ξ΅0 ⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩ lemma bounded (hf : IsCauSeq abv f) : βˆƒ r, βˆ€ i, abv (f i) < r := by obtain ⟨i, h⟩ := hf _ zero_lt_one set R : β„• β†’ Ξ± := @Nat.rec (fun _ => Ξ±) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR have : βˆ€ i, βˆ€ j ≀ i, abv (f j) ≀ R i := by refine Nat.rec (by simp [hR]) ?_ rintro i hi j (rfl | hj) Β· simp [R] Β· exact (hi j hj).trans (le_max_left _ _) refine ⟨R i + 1, fun j ↦ ?_⟩ obtain hji | hij := le_total j i Β· exact (this i _ hji).trans_lt (lt_add_one _) Β· simpa using (abv_add abv _ _).trans_lt <| add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij) lemma bounded' (hf : IsCauSeq abv f) (x : Ξ±) : βˆƒ r > x, βˆ€ i, abv (f i) < r := let ⟨r, h⟩ := hf.bounded ⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _), fun i ↦ (h i).trans_le (le_max_left _ _)⟩ lemma const (x : Ξ²) : IsCauSeq abv fun _ ↦ x := fun Ξ΅ Ξ΅0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using Ξ΅0⟩ theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ Ξ΅0 => let ⟨_, Ξ΄0, Hδ⟩ := rat_add_continuous_lemma abv Ξ΅0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ Ξ΄0) (hg.cauchy₃ Ξ΄0) ⟨i, fun _ ij => let ⟨H₁, Hβ‚‚βŸ© := H _ le_rfl HΞ΄ (H₁ _ ij) (Hβ‚‚ _ ij)⟩ lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ Ξ΅0 => let ⟨_, _, hF⟩ := hf.bounded' 0 let ⟨_, _, hG⟩ := hg.bounded' 0 let ⟨_, Ξ΄0, Hδ⟩ := rat_mul_continuous_lemma abv Ξ΅0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ Ξ΄0) (hg.cauchy₃ Ξ΄0) ⟨i, fun j ij => let ⟨H₁, Hβ‚‚βŸ© := H _ le_rfl HΞ΄ (hF j) (hG i) (H₁ _ ij) (Hβ‚‚ _ ij)⟩ @[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg] protected alias ⟨of_neg, neg⟩ := isCauSeq_neg end IsCauSeq /-- `CauSeq Ξ² abv` is the type of `Ξ²`-valued Cauchy sequences, with respect to the absolute value function `abv`. -/ def CauSeq {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] (Ξ² : Type*) [Ring Ξ²] (abv : Ξ² β†’ Ξ±) : Type _ := { f : β„• β†’ Ξ² // IsCauSeq abv f } namespace CauSeq variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] section Ring variable [Ring Ξ²] {abv : Ξ² β†’ Ξ±} instance : CoeFun (CauSeq Ξ² abv) fun _ => β„• β†’ Ξ² := ⟨Subtype.val⟩ @[ext] theorem ext {f g : CauSeq Ξ² abv} (h : βˆ€ i, f i = g i) : f = g := Subtype.eq (funext h) theorem isCauSeq (f : CauSeq Ξ² abv) : IsCauSeq abv f := f.2 theorem cauchy (f : CauSeq Ξ² abv) : βˆ€ {Ξ΅}, 0 < Ξ΅ β†’ βˆƒ i, βˆ€ j β‰₯ i, abv (f j - f i) < Ξ΅ := @f.2 /-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with the same values as `f`. -/ def ofEq (f : CauSeq Ξ² abv) (g : β„• β†’ Ξ²) (e : βˆ€ i, f i = g i) : CauSeq Ξ² abv := ⟨g, fun Ξ΅ => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩ variable [IsAbsoluteValue abv] -- see Note [nolint_ge] -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchyβ‚‚ (f : CauSeq Ξ² abv) {Ξ΅} : 0 < Ξ΅ β†’ βˆƒ i, βˆ€ j β‰₯ i, βˆ€ k β‰₯ i, abv (f j - f k) < Ξ΅ := f.2.cauchyβ‚‚ theorem cauchy₃ (f : CauSeq Ξ² abv) {Ξ΅} : 0 < Ξ΅ β†’ βˆƒ i, βˆ€ j β‰₯ i, βˆ€ k β‰₯ j, abv (f k - f j) < Ξ΅ := f.2.cauchy₃ theorem bounded (f : CauSeq Ξ² abv) : βˆƒ r, βˆ€ i, abv (f i) < r := f.2.bounded theorem bounded' (f : CauSeq Ξ² abv) (x : Ξ±) : βˆƒ r > x, βˆ€ i, abv (f i) < r := f.2.bounded' x instance : Add (CauSeq Ξ² abv) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ @[simp, norm_cast] theorem coe_add (f g : CauSeq Ξ² abv) : ⇑(f + g) = (f : β„• β†’ Ξ²) + g := rfl @[simp, norm_cast] theorem add_apply (f g : CauSeq Ξ² abv) (i : β„•) : (f + g) i = f i + g i := rfl variable (abv) in /-- The constant Cauchy sequence. -/ def const (x : Ξ²) : CauSeq Ξ² abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩ /-- The constant Cauchy sequence -/ local notation "const" => const abv @[simp, norm_cast] theorem coe_const (x : Ξ²) : (const x : β„• β†’ Ξ²) = Function.const β„• x := rfl @[simp, norm_cast] theorem const_apply (x : Ξ²) (i : β„•) : (const x : β„• β†’ Ξ²) i = x := rfl theorem const_inj {x y : Ξ²} : (const x : CauSeq Ξ² abv) = const y ↔ x = y := ⟨fun h => congr_arg (fun f : CauSeq Ξ² abv => (f : β„• β†’ Ξ²) 0) h, congr_arg _⟩ instance : Zero (CauSeq Ξ² abv) := ⟨const 0⟩ instance : One (CauSeq Ξ² abv) := ⟨const 1⟩ instance : Inhabited (CauSeq Ξ² abv) := ⟨0⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CauSeq Ξ² abv) = 0 := rfl @[simp, norm_cast] theorem coe_one : ⇑(1 : CauSeq Ξ² abv) = 1 := rfl @[simp, norm_cast] theorem zero_apply (i) : (0 : CauSeq Ξ² abv) i = 0 := rfl @[simp, norm_cast] theorem one_apply (i) : (1 : CauSeq Ξ² abv) i = 1 := rfl @[simp] theorem const_zero : const 0 = 0 := rfl @[simp] theorem const_one : const 1 = 1 := rfl theorem const_add (x y : Ξ²) : const (x + y) = const x + const y := rfl instance : Mul (CauSeq Ξ² abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩ @[simp, norm_cast] theorem coe_mul (f g : CauSeq Ξ² abv) : ⇑(f * g) = (f : β„• β†’ Ξ²) * g := rfl @[simp, norm_cast] theorem mul_apply (f g : CauSeq Ξ² abv) (i : β„•) : (f * g) i = f i * g i := rfl theorem const_mul (x y : Ξ²) : const (x * y) = const x * const y := rfl instance : Neg (CauSeq Ξ² abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩ @[simp, norm_cast] theorem coe_neg (f : CauSeq Ξ² abv) : ⇑(-f) = -f := rfl @[simp, norm_cast] theorem neg_apply (f : CauSeq Ξ² abv) (i) : (-f) i = -f i := rfl theorem const_neg (x : Ξ²) : const (-x) = -const x := rfl instance : Sub (CauSeq Ξ² abv) := ⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩ @[simp, norm_cast] theorem coe_sub (f g : CauSeq Ξ² abv) : ⇑(f - g) = (f : β„• β†’ Ξ²) - g := rfl @[simp, norm_cast] theorem sub_apply (f g : CauSeq Ξ² abv) (i : β„•) : (f - g) i = f i - g i := rfl theorem const_sub (x y : Ξ²) : const (x - y) = const x - const y := rfl section SMul variable {G : Type*} [SMul G Ξ²] [IsScalarTower G Ξ² Ξ²] instance : SMul G (CauSeq Ξ² abv) := ⟨fun a f => (ofEq (const (a β€’ (1 : Ξ²)) * f) (a β€’ (f : β„• β†’ Ξ²))) fun _ => smul_one_mul _ _⟩ @[simp, norm_cast] theorem coe_smul (a : G) (f : CauSeq Ξ² abv) : ⇑(a β€’ f) = a β€’ (f : β„• β†’ Ξ²) := rfl @[simp, norm_cast] theorem smul_apply (a : G) (f : CauSeq Ξ² abv) (i : β„•) : (a β€’ f) i = a β€’ f i := rfl theorem const_smul (a : G) (x : Ξ²) : const (a β€’ x) = a β€’ const x := rfl instance : IsScalarTower G (CauSeq Ξ² abv) (CauSeq Ξ² abv) := ⟨fun a f g => Subtype.ext <| smul_assoc a (f : β„• β†’ Ξ²) (g : β„• β†’ Ξ²)⟩ end SMul instance addGroup : AddGroup (CauSeq Ξ² abv) := Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ instance instNatCast : NatCast (CauSeq Ξ² abv) := ⟨fun n => const n⟩ instance instIntCast : IntCast (CauSeq Ξ² abv) := ⟨fun n => const n⟩ instance addGroupWithOne : AddGroupWithOne (CauSeq Ξ² abv) := Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl coe_add coe_neg coe_sub (by intros; rfl) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance : Pow (CauSeq Ξ² abv) β„• := ⟨fun f n => (ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩ @[simp, norm_cast] theorem coe_pow (f : CauSeq Ξ² abv) (n : β„•) : ⇑(f ^ n) = (f : β„• β†’ Ξ²) ^ n := rfl @[simp, norm_cast] theorem pow_apply (f : CauSeq Ξ² abv) (n i : β„•) : (f ^ n) i = f i ^ n := rfl theorem const_pow (x : Ξ²) (n : β„•) : const (x ^ n) = const x ^ n := rfl instance ring : Ring (CauSeq Ξ² abv) := Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub (fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl instance {Ξ² : Type*} [CommRing Ξ²] {abv : Ξ² β†’ Ξ±} [IsAbsoluteValue abv] : CommRing (CauSeq Ξ² abv) := { CauSeq.ring with mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] } /-- `LimZero f` holds when `f` approaches 0. -/ def LimZero {abv : Ξ² β†’ Ξ±} (f : CauSeq Ξ² abv) : Prop := βˆ€ Ξ΅ > 0, βˆƒ i, βˆ€ j β‰₯ i, abv (f j) < Ξ΅ theorem add_limZero {f g : CauSeq Ξ² abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g) | Ξ΅, Ξ΅0 => (exists_forall_ge_and (hf _ <| half_pos Ξ΅0) (hg _ <| half_pos Ξ΅0)).imp fun _ H j ij => by let ⟨H₁, Hβ‚‚βŸ© := H _ ij simpa [add_halves Ξ΅] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ Hβ‚‚) theorem mul_limZero_right (f : CauSeq Ξ² abv) {g} (hg : LimZero g) : LimZero (f * g) | Ξ΅, Ξ΅0 => let ⟨F, F0, hF⟩ := f.bounded' 0 (hg _ <| div_pos Ξ΅0 F0).imp fun _ H j ij => by have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0 rwa [mul_comm F, div_mul_cancelβ‚€ _ (ne_of_gt F0), ← abv_mul] at this theorem mul_limZero_left {f} (g : CauSeq Ξ² abv) (hg : LimZero f) : LimZero (f * g) | Ξ΅, Ξ΅0 => let ⟨G, G0, hG⟩ := g.bounded' 0 (hg _ <| div_pos Ξ΅0 G0).imp fun _ H j ij => by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _) rwa [div_mul_cancelβ‚€ _ (ne_of_gt G0), ← abv_mul] at this theorem neg_limZero {f : CauSeq Ξ² abv} (hf : LimZero f) : LimZero (-f) := by rw [← neg_one_mul f] exact mul_limZero_right _ hf theorem sub_limZero {f g : CauSeq Ξ² abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg) theorem limZero_sub_rev {f g : CauSeq Ξ² abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by simpa using neg_limZero hfg theorem zero_limZero : LimZero (0 : CauSeq Ξ² abv) | Ξ΅, Ξ΅0 => ⟨0, fun j _ => by simpa [abv_zero abv] using Ξ΅0⟩ theorem const_limZero {x : Ξ²} : LimZero (const x) ↔ x = 0 := ⟨fun H => (abv_eq_zero abv).1 <| (eq_of_le_of_forall_lt_imp_le_of_dense (abv_nonneg abv _)) fun _ Ξ΅0 => let ⟨_, hi⟩ := H _ Ξ΅0 le_of_lt <| hi _ le_rfl, fun e => e.symm β–Έ zero_limZero⟩ instance equiv : Setoid (CauSeq Ξ² abv) := ⟨fun f g => LimZero (f - g), ⟨fun f => by simp [zero_limZero], fun f Ξ΅ hΞ΅ => by simpa using neg_limZero f Ξ΅ hΞ΅, fun fg gh => by simpa using add_limZero fg gh⟩⟩ theorem add_equiv_add {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β‰ˆ f2) (hg : g1 β‰ˆ g2) : f1 + g1 β‰ˆ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg theorem neg_equiv_neg {f g : CauSeq Ξ² abv} (hf : f β‰ˆ g) : -f β‰ˆ -g := by simpa only [neg_sub'] using neg_limZero hf theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β‰ˆ f2) (hg : g1 β‰ˆ g2) : f1 - g1 β‰ˆ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg) theorem equiv_def₃ {f g : CauSeq Ξ² abv} (h : f β‰ˆ g) {Ξ΅ : Ξ±} (Ξ΅0 : 0 < Ξ΅) : βˆƒ i, βˆ€ j β‰₯ i, βˆ€ k β‰₯ j, abv (f k - g j) < Ξ΅ := (exists_forall_ge_and (h _ <| half_pos Ξ΅0) (f.cauchy₃ <| half_pos Ξ΅0)).imp fun _ H j ij k jk => by let ⟨h₁, hβ‚‚βŸ© := H _ ij have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (hβ‚‚ _ jk)) rwa [sub_add_sub_cancel', add_halves] at this theorem limZero_congr {f g : CauSeq Ξ² abv} (h : f β‰ˆ g) : LimZero f ↔ LimZero g := ⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩ theorem abv_pos_of_not_limZero {f : CauSeq Ξ² abv} (hf : Β¬LimZero f) : βˆƒ K > 0, βˆƒ i, βˆ€ j β‰₯ i, K ≀ abv (f j) := by haveI := Classical.propDecidable by_contra nk refine hf fun Ξ΅ Ξ΅0 => ?_ simp? [not_forall] at nk says simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp, not_le] at nk obtain ⟨i, hi⟩ := f.cauchy₃ (half_pos Ξ΅0) rcases nk _ (half_pos Ξ΅0) i with ⟨j, ij, hj⟩ refine ⟨j, fun k jk => ?_⟩ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj) rwa [sub_add_cancel, add_halves] at this theorem of_near (f : β„• β†’ Ξ²) (g : CauSeq Ξ² abv) (h : βˆ€ Ξ΅ > 0, βˆƒ i, βˆ€ j β‰₯ i, abv (f j - g j) < Ξ΅) : IsCauSeq abv f | Ξ΅, Ξ΅0 => let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos Ξ΅0)) (g.cauchy₃ <| half_pos Ξ΅0) ⟨i, fun j ij => by obtain ⟨h₁, hβ‚‚βŸ© := hi _ le_rfl; rw [abv_sub abv] at h₁ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁) have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (hβ‚‚ _ ij)) rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at this⟩ theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : Β¬f β‰ˆ 0) : Β¬LimZero f := by intro h have : LimZero (f - 0) := by simp [h] exact hf this theorem mul_equiv_zero (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f β‰ˆ 0) : g * f β‰ˆ 0 := have : LimZero (f - 0) := hf have : LimZero (g * f) := mul_limZero_right _ <| by simpa show LimZero (g * f - 0) by simpa theorem mul_equiv_zero' (g : CauSeq _ abv) {f : CauSeq _ abv} (hf : f β‰ˆ 0) : f * g β‰ˆ 0 := have : LimZero (f - 0) := hf have : LimZero (f * g) := mul_limZero_left _ <| by simpa show LimZero (f * g - 0) by simpa theorem mul_not_equiv_zero {f g : CauSeq _ abv} (hf : Β¬f β‰ˆ 0) (hg : Β¬g β‰ˆ 0) : Β¬f * g β‰ˆ 0 := fun (this : LimZero (f * g - 0)) => by have hlz : LimZero (f * g) := by simpa have hf' : Β¬LimZero f := by simpa using show Β¬LimZero (f - 0) from hf have hg' : Β¬LimZero g := by simpa using show Β¬LimZero (g - 0) from hg rcases abv_pos_of_not_limZero hf' with ⟨a1, ha1, N1, hN1⟩ rcases abv_pos_of_not_limZero hg' with ⟨a2, ha2, N2, hN2⟩ have : 0 < a1 * a2 := mul_pos ha1 ha2 obtain ⟨N, hN⟩ := hlz _ this let i := max N (max N1 N2) have hN' := hN i (le_max_left _ _) have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _)) have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _)) apply not_le_of_lt hN' change _ ≀ abv (_ * _) rw [abv_mul abv] gcongr theorem const_equiv {x y : Ξ²} : const x β‰ˆ const y ↔ x = y := show LimZero _ ↔ _ by rw [← const_sub, const_limZero, sub_eq_zero] theorem mul_equiv_mul {f1 f2 g1 g2 : CauSeq Ξ² abv} (hf : f1 β‰ˆ f2) (hg : g1 β‰ˆ g2) : f1 * g1 β‰ˆ f2 * g2 := by simpa only [mul_sub, sub_mul, sub_add_sub_cancel] using add_limZero (mul_limZero_left g1 hf) (mul_limZero_right f2 hg) theorem smul_equiv_smul {G : Type*} [SMul G Ξ²] [IsScalarTower G Ξ² Ξ²] {f1 f2 : CauSeq Ξ² abv} (c : G) (hf : f1 β‰ˆ f2) : c β€’ f1 β‰ˆ c β€’ f2 := by simpa [const_smul, smul_one_mul _ _] using mul_equiv_mul (const_equiv.mpr <| Eq.refl <| c β€’ (1 : Ξ²)) hf theorem pow_equiv_pow {f1 f2 : CauSeq Ξ² abv} (hf : f1 β‰ˆ f2) (n : β„•) : f1 ^ n β‰ˆ f2 ^ n := by induction n with | zero => simp only [pow_zero, Setoid.refl] | succ n ih => simpa only [pow_succ'] using mul_equiv_mul hf ih end Ring section IsDomain variable [Ring Ξ²] [IsDomain Ξ²] (abv : Ξ² β†’ Ξ±) [IsAbsoluteValue abv] theorem one_not_equiv_zero : Β¬const abv 1 β‰ˆ const abv 0 := fun h => have : βˆ€ Ξ΅ > 0, βˆƒ i, βˆ€ k, i ≀ k β†’ abv (1 - 0) < Ξ΅ := h have h1 : abv 1 ≀ 0 := le_of_not_gt fun h2 : 0 < abv 1 => (Exists.elim (this _ h2)) fun i hi => lt_irrefl (abv 1) <| by simpa using hi _ le_rfl have h2 : 0 ≀ abv 1 := abv_nonneg abv _ have : abv 1 = 0 := le_antisymm h1 h2 have : (1 : Ξ²) = 0 := (abv_eq_zero abv).mp this absurd this one_ne_zero end IsDomain section DivisionRing variable [DivisionRing Ξ²] {abv : Ξ² β†’ Ξ±} [IsAbsoluteValue abv] theorem inv_aux {f : CauSeq Ξ² abv} (hf : Β¬LimZero f) : βˆ€ Ξ΅ > 0, βˆƒ i, βˆ€ j β‰₯ i, abv ((f j)⁻¹ - (f i)⁻¹) < Ξ΅ | _, Ξ΅0 => let ⟨_, K0, HK⟩ := abv_pos_of_not_limZero hf let ⟨_, Ξ΄0, Hδ⟩ := rat_inv_continuous_lemma abv Ξ΅0 K0 let ⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ Ξ΄0) ⟨i, fun _ ij => let ⟨iK, H'⟩ := H _ le_rfl HΞ΄ (H _ ij).1 iK (H' _ ij)⟩ /-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to the inverses of the values of `f`. -/ def inv (f : CauSeq Ξ² abv) (hf : Β¬LimZero f) : CauSeq Ξ² abv := ⟨_, inv_aux hf⟩ @[simp, norm_cast] theorem coe_inv {f : CauSeq Ξ² abv} (hf) : ⇑(inv f hf) = (f : β„• β†’ Ξ²)⁻¹ := rfl @[simp, norm_cast] theorem inv_apply {f : CauSeq Ξ² abv} (hf i) : inv f hf i = (f i)⁻¹ := rfl theorem inv_mul_cancel {f : CauSeq Ξ² abv} (hf) : inv f hf * f β‰ˆ 1 := fun Ξ΅ Ξ΅0 => let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf ⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using Ξ΅0⟩ theorem mul_inv_cancel {f : CauSeq Ξ² abv} (hf) : f * inv f hf β‰ˆ 1 := fun Ξ΅ Ξ΅0 => let ⟨K, K0, i, H⟩ := abv_pos_of_not_limZero hf ⟨i, fun j ij => by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)), abv_zero abv] using Ξ΅0⟩ theorem const_inv {x : Ξ²} (hx : x β‰  0) : const abv x⁻¹ = inv (const abv x) (by rwa [const_limZero]) := rfl end DivisionRing section Abs /-- The constant Cauchy sequence -/ local notation "const" => const abs /-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/ def Pos (f : CauSeq Ξ± abs) : Prop := βˆƒ K > 0, βˆƒ i, βˆ€ j β‰₯ i, K ≀ f j theorem not_limZero_of_pos {f : CauSeq Ξ± abs} : Pos f β†’ Β¬LimZero f | ⟨_, F0, hF⟩, H => let ⟨_, h⟩ := exists_forall_ge_and hF (H _ F0) let ⟨h₁, hβ‚‚βŸ© := h _ le_rfl not_lt_of_le h₁ (abs_lt.1 hβ‚‚).2 theorem const_pos {x : Ξ±} : Pos (const x) ↔ 0 < x := ⟨fun ⟨_, K0, _, h⟩ => lt_of_lt_of_le K0 (h _ le_rfl), fun h => ⟨x, h, 0, fun _ _ => le_rfl⟩⟩ theorem add_pos {f g : CauSeq Ξ± abs} : Pos f β†’ Pos g β†’ Pos (f + g) | ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ => let ⟨i, h⟩ := exists_forall_ge_and hF hG ⟨_, _root_.add_pos F0 G0, i, fun _ ij => let ⟨h₁, hβ‚‚βŸ© := h _ ij add_le_add h₁ hβ‚‚βŸ© theorem pos_add_limZero {f g : CauSeq Ξ± abs} : Pos f β†’ LimZero g β†’ Pos (f + g) | ⟨F, F0, hF⟩, H => let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0)) ⟨_, half_pos F0, i, fun j ij => by obtain ⟨h₁, hβ‚‚βŸ© := h j ij have := add_le_add h₁ (le_of_lt (abs_lt.1 hβ‚‚).1) rwa [← sub_eq_add_neg, sub_self_div_two] at this⟩ protected theorem mul_pos {f g : CauSeq Ξ± abs} : Pos f β†’ Pos g β†’ Pos (f * g) | ⟨_, F0, hF⟩, ⟨_, G0, hG⟩ => let ⟨i, h⟩ := exists_forall_ge_and hF hG ⟨_, mul_pos F0 G0, i, fun _ ij => let ⟨h₁, hβ‚‚βŸ© := h _ ij mul_le_mul h₁ hβ‚‚ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩ theorem trichotomy (f : CauSeq Ξ± abs) : Pos f ∨ LimZero f ∨ Pos (-f) := by rcases Classical.em (LimZero f) with h | h <;> simp [*] rcases abv_pos_of_not_limZero h with ⟨K, K0, hK⟩ rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩ refine (le_total 0 (f i)).imp ?_ ?_ <;> refine fun h => ⟨K, K0, i, fun j ij => ?_⟩ <;> have := (hi _ ij).1 <;> obtain ⟨h₁, hβ‚‚βŸ© := hi _ le_rfl Β· rwa [abs_of_nonneg] at this rw [abs_of_nonneg h] at h₁ exact (le_add_iff_nonneg_right _).1 (le_trans h₁ <| neg_le_sub_iff_le_add'.1 <| le_of_lt (abs_lt.1 <| hβ‚‚ _ ij).1) Β· rwa [abs_of_nonpos] at this rw [abs_of_nonpos h] at h₁ rw [← sub_le_sub_iff_right, zero_sub] exact le_trans (le_of_lt (abs_lt.1 <| hβ‚‚ _ ij).2) h₁ instance : LT (CauSeq Ξ± abs) := ⟨fun f g => Pos (g - f)⟩ instance : LE (CauSeq Ξ± abs) := ⟨fun f g => f < g ∨ f β‰ˆ g⟩ theorem lt_of_lt_of_eq {f g h : CauSeq Ξ± abs} (fg : f < g) (gh : g β‰ˆ h) : f < h := show Pos (h - f) by convert pos_add_limZero fg (neg_limZero gh) using 1 simp theorem lt_of_eq_of_lt {f g h : CauSeq Ξ± abs} (fg : f β‰ˆ g) (gh : g < h) : f < h := by have := pos_add_limZero gh (neg_limZero fg) rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this theorem lt_trans {f g h : CauSeq Ξ± abs} (fg : f < g) (gh : g < h) : f < h := show Pos (h - f) by convert add_pos fg gh using 1 simp theorem lt_irrefl {f : CauSeq Ξ± abs} : Β¬f < f | h => not_limZero_of_pos h (by simp [zero_limZero]) theorem le_of_eq_of_le {f g h : CauSeq Ξ± abs} (hfg : f β‰ˆ g) (hgh : g ≀ h) : f ≀ h := hgh.elim (Or.inl ∘ CauSeq.lt_of_eq_of_lt hfg) (Or.inr ∘ Setoid.trans hfg) theorem le_of_le_of_eq {f g h : CauSeq Ξ± abs} (hfg : f ≀ g) (hgh : g β‰ˆ h) : f ≀ h := hfg.elim (fun h => Or.inl (CauSeq.lt_of_lt_of_eq h hgh)) fun h => Or.inr (Setoid.trans h hgh) instance : Preorder (CauSeq Ξ± abs) where lt := (Β· < Β·) le f g := f < g ∨ f β‰ˆ g le_refl _ := Or.inr (Setoid.refl _) le_trans _ _ _ fg gh := match fg, gh with | Or.inl fg, Or.inl gh => Or.inl <| lt_trans fg gh | Or.inl fg, Or.inr gh => Or.inl <| lt_of_lt_of_eq fg gh | Or.inr fg, Or.inl gh => Or.inl <| lt_of_eq_of_lt fg gh | Or.inr fg, Or.inr gh => Or.inr <| Setoid.trans fg gh lt_iff_le_not_le _ _ := ⟨fun h => ⟨Or.inl h, not_or_intro (mt (lt_trans h) lt_irrefl) (not_limZero_of_pos h)⟩, fun ⟨h₁, hβ‚‚βŸ© => h₁.resolve_right (mt (fun h => Or.inr (Setoid.symm h)) hβ‚‚)⟩ theorem le_antisymm {f g : CauSeq Ξ± abs} (fg : f ≀ g) (gf : g ≀ f) : f β‰ˆ g := fg.resolve_left (not_lt_of_le gf) theorem lt_total (f g : CauSeq Ξ± abs) : f < g ∨ f β‰ˆ g ∨ g < f := (trichotomy (g - f)).imp_right fun h => h.imp (fun h => Setoid.symm h) fun h => by rwa [neg_sub] at h theorem le_total (f g : CauSeq Ξ± abs) : f ≀ g ∨ g ≀ f := (or_assoc.2 (lt_total f g)).imp_right Or.inl theorem const_lt {x y : Ξ±} : const x < const y ↔ x < y := show Pos _ ↔ _ by rw [← const_sub, const_pos, sub_pos] theorem const_le {x y : Ξ±} : const x ≀ const y ↔ x ≀ y := by rw [le_iff_lt_or_eq]; exact or_congr const_lt const_equiv theorem le_of_exists {f g : CauSeq Ξ± abs} (h : βˆƒ i, βˆ€ j β‰₯ i, f j ≀ g j) : f ≀ g := let ⟨i, hi⟩ := h (or_assoc.2 (CauSeq.lt_total f g)).elim id fun hgf => False.elim (let ⟨_, hK0, j, hKj⟩ := hgf not_lt_of_ge (hi (max i j) (le_max_left _ _)) (sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _))))) theorem exists_gt (f : CauSeq Ξ± abs) : βˆƒ a : Ξ±, f < const a := let ⟨K, H⟩ := f.bounded ⟨K + 1, 1, zero_lt_one, 0, fun i _ => by rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right] exact le_of_lt (abs_lt.1 (H _)).2⟩ theorem exists_lt (f : CauSeq Ξ± abs) : βˆƒ a : Ξ±, const a < f := let ⟨a, h⟩ := (-f).exists_gt ⟨-a, show Pos _ by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩ -- so named to match `rat_add_continuous_lemma` theorem rat_sup_continuous_lemma {Ξ΅ : Ξ±} {a₁ aβ‚‚ b₁ bβ‚‚ : Ξ±} : abs (a₁ - b₁) < Ξ΅ β†’ abs (aβ‚‚ - bβ‚‚) < Ξ΅ β†’ abs (a₁ βŠ” aβ‚‚ - b₁ βŠ” bβ‚‚) < Ξ΅ := fun h₁ hβ‚‚ => (abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt h₁ hβ‚‚) -- so named to match `rat_add_continuous_lemma` theorem rat_inf_continuous_lemma {Ξ΅ : Ξ±} {a₁ aβ‚‚ b₁ bβ‚‚ : Ξ±} : abs (a₁ - b₁) < Ξ΅ β†’ abs (aβ‚‚ - bβ‚‚) < Ξ΅ β†’ abs (a₁ βŠ“ aβ‚‚ - b₁ βŠ“ bβ‚‚) < Ξ΅ := fun h₁ hβ‚‚ => (abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt h₁ hβ‚‚) instance : Max (CauSeq Ξ± abs) := ⟨fun f g => ⟨f βŠ” g, fun _ Ξ΅0 => (exists_forall_ge_and (f.cauchy₃ Ξ΅0) (g.cauchy₃ Ξ΅0)).imp fun _ H _ ij => let ⟨H₁, Hβ‚‚βŸ© := H _ le_rfl rat_sup_continuous_lemma (H₁ _ ij) (Hβ‚‚ _ ij)⟩⟩ instance : Min (CauSeq Ξ± abs) := ⟨fun f g => ⟨f βŠ“ g, fun _ Ξ΅0 => (exists_forall_ge_and (f.cauchy₃ Ξ΅0) (g.cauchy₃ Ξ΅0)).imp fun _ H _ ij => let ⟨H₁, Hβ‚‚βŸ© := H _ le_rfl rat_inf_continuous_lemma (H₁ _ ij) (Hβ‚‚ _ ij)⟩⟩ @[simp, norm_cast] theorem coe_sup (f g : CauSeq Ξ± abs) : ⇑(f βŠ” g) = (f : β„• β†’ Ξ±) βŠ” g := rfl @[simp, norm_cast] theorem coe_inf (f g : CauSeq Ξ± abs) : ⇑(f βŠ“ g) = (f : β„• β†’ Ξ±) βŠ“ g := rfl theorem sup_limZero {f g : CauSeq Ξ± abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f βŠ” g) | Ξ΅, Ξ΅0 => (exists_forall_ge_and (hf _ Ξ΅0) (hg _ Ξ΅0)).imp fun _ H j ij => by let ⟨H₁, Hβ‚‚βŸ© := H _ ij rw [abs_lt] at H₁ Hβ‚‚ ⊒ exact ⟨lt_sup_iff.mpr (Or.inl H₁.1), sup_lt_iff.mpr ⟨H₁.2, Hβ‚‚.2⟩⟩ theorem inf_limZero {f g : CauSeq Ξ± abs} (hf : LimZero f) (hg : LimZero g) : LimZero (f βŠ“ g) | Ξ΅, Ξ΅0 => (exists_forall_ge_and (hf _ Ξ΅0) (hg _ Ξ΅0)).imp fun _ H j ij => by let ⟨H₁, Hβ‚‚βŸ© := H _ ij rw [abs_lt] at H₁ Hβ‚‚ ⊒ exact ⟨lt_inf_iff.mpr ⟨H₁.1, Hβ‚‚.1⟩, inf_lt_iff.mpr (Or.inl H₁.2)⟩ theorem sup_equiv_sup {a₁ b₁ aβ‚‚ bβ‚‚ : CauSeq Ξ± abs} (ha : a₁ β‰ˆ aβ‚‚) (hb : b₁ β‰ˆ bβ‚‚) : a₁ βŠ” b₁ β‰ˆ aβ‚‚ βŠ” bβ‚‚ := by intro Ξ΅ Ξ΅0 obtain ⟨ai, hai⟩ := ha Ξ΅ Ξ΅0 obtain ⟨bi, hbi⟩ := hb Ξ΅ Ξ΅0 exact ⟨ai βŠ” bi, fun i hi => (abs_max_sub_max_le_max (a₁ i) (b₁ i) (aβ‚‚ i) (bβ‚‚ i)).trans_lt (max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩ theorem inf_equiv_inf {a₁ b₁ aβ‚‚ bβ‚‚ : CauSeq Ξ± abs} (ha : a₁ β‰ˆ aβ‚‚) (hb : b₁ β‰ˆ bβ‚‚) : a₁ βŠ“ b₁ β‰ˆ aβ‚‚ βŠ“ bβ‚‚ := by intro Ξ΅ Ξ΅0 obtain ⟨ai, hai⟩ := ha Ξ΅ Ξ΅0 obtain ⟨bi, hbi⟩ := hb Ξ΅ Ξ΅0 exact ⟨ai βŠ” bi, fun i hi => (abs_min_sub_min_le_max (a₁ i) (b₁ i) (aβ‚‚ i) (bβ‚‚ i)).trans_lt (max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩ protected theorem sup_lt {a b c : CauSeq Ξ± abs} (ha : a < c) (hb : b < c) : a βŠ” b < c := by obtain ⟨⟨Ρa, Ξ΅a0, ia, ha⟩, ⟨Ρb, Ξ΅b0, ib, hb⟩⟩ := ha, hb refine ⟨Ρa βŠ“ Ξ΅b, lt_inf_iff.mpr ⟨Ρa0, Ξ΅b0⟩, ia βŠ” ib, fun i hi => ?_⟩ have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2) exact this.trans_eq (min_sub_sub_left _ _ _) protected theorem lt_inf {a b c : CauSeq Ξ± abs} (hb : a < b) (hc : a < c) : a < b βŠ“ c := by obtain ⟨⟨Ρb, Ξ΅b0, ib, hb⟩, ⟨Ρc, Ξ΅c0, ic, hc⟩⟩ := hb, hc refine ⟨Ρb βŠ“ Ξ΅c, lt_inf_iff.mpr ⟨Ρb0, Ξ΅c0⟩, ib βŠ” ic, fun i hi => ?_⟩ have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2) exact this.trans_eq (min_sub_sub_right _ _ _) @[simp] protected theorem sup_idem (a : CauSeq Ξ± abs) : a βŠ” a = a := Subtype.ext (sup_idem _) @[simp] protected theorem inf_idem (a : CauSeq Ξ± abs) : a βŠ“ a = a := Subtype.ext (inf_idem _) protected theorem sup_comm (a b : CauSeq Ξ± abs) : a βŠ” b = b βŠ” a := Subtype.ext (sup_comm _ _) protected theorem inf_comm (a b : CauSeq Ξ± abs) : a βŠ“ b = b βŠ“ a := Subtype.ext (inf_comm _ _) protected theorem sup_eq_right {a b : CauSeq Ξ± abs} (h : a ≀ b) : a βŠ” b β‰ˆ b := by obtain ⟨Ρ, Ξ΅0 : _ < _, i, h⟩ | h := h Β· intro _ _ refine ⟨i, fun j hj => ?_⟩ dsimp rw [← max_sub_sub_right] rwa [sub_self, max_eq_right, abs_zero] rw [sub_nonpos, ← sub_nonneg] exact Ξ΅0.le.trans (h _ hj) Β· refine Setoid.trans (sup_equiv_sup h (Setoid.refl _)) ?_ rw [CauSeq.sup_idem] protected theorem inf_eq_right {a b : CauSeq Ξ± abs} (h : b ≀ a) : a βŠ“ b β‰ˆ b := by obtain ⟨Ρ, Ξ΅0 : _ < _, i, h⟩ | h := h Β· intro _ _ refine ⟨i, fun j hj => ?_⟩ dsimp rw [← min_sub_sub_right] rwa [sub_self, min_eq_right, abs_zero] exact Ξ΅0.le.trans (h _ hj) Β· refine Setoid.trans (inf_equiv_inf (Setoid.symm h) (Setoid.refl _)) ?_ rw [CauSeq.inf_idem] protected theorem sup_eq_left {a b : CauSeq Ξ± abs} (h : b ≀ a) : a βŠ” b β‰ˆ a := by simpa only [CauSeq.sup_comm] using CauSeq.sup_eq_right h protected theorem inf_eq_left {a b : CauSeq Ξ± abs} (h : a ≀ b) : a βŠ“ b β‰ˆ a := by simpa only [CauSeq.inf_comm] using CauSeq.inf_eq_right h protected theorem le_sup_left {a b : CauSeq Ξ± abs} : a ≀ a βŠ” b := le_of_exists ⟨0, fun _ _ => le_sup_left⟩ protected theorem inf_le_left {a b : CauSeq Ξ± abs} : a βŠ“ b ≀ a := le_of_exists ⟨0, fun _ _ => inf_le_left⟩ protected theorem le_sup_right {a b : CauSeq Ξ± abs} : b ≀ a βŠ” b := le_of_exists ⟨0, fun _ _ => le_sup_right⟩ protected theorem inf_le_right {a b : CauSeq Ξ± abs} : a βŠ“ b ≀ b := le_of_exists ⟨0, fun _ _ => inf_le_right⟩ protected theorem sup_le {a b c : CauSeq Ξ± abs} (ha : a ≀ c) (hb : b ≀ c) : a βŠ” b ≀ c := by obtain ha | ha := ha Β· obtain hb | hb := hb Β· exact Or.inl (CauSeq.sup_lt ha hb) Β· replace ha := le_of_le_of_eq ha.le (Setoid.symm hb) refine le_of_le_of_eq (Or.inr ?_) hb exact CauSeq.sup_eq_right ha Β· replace hb := le_of_le_of_eq hb (Setoid.symm ha) refine le_of_le_of_eq (Or.inr ?_) ha exact CauSeq.sup_eq_left hb protected theorem le_inf {a b c : CauSeq Ξ± abs} (hb : a ≀ b) (hc : a ≀ c) : a ≀ b βŠ“ c := by obtain hb | hb := hb Β· obtain hc | hc := hc Β· exact Or.inl (CauSeq.lt_inf hb hc) Β· replace hb := le_of_eq_of_le (Setoid.symm hc) hb.le refine le_of_eq_of_le hc (Or.inr ?_) exact Setoid.symm (CauSeq.inf_eq_right hb) Β· replace hc := le_of_eq_of_le (Setoid.symm hb) hc refine le_of_eq_of_le hb (Or.inr ?_) exact Setoid.symm (CauSeq.inf_eq_left hc) /-! Note that `DistribLattice (CauSeq Ξ± abs)` is not true because there is no `PartialOrder`. -/ protected theorem sup_inf_distrib_left (a b c : CauSeq Ξ± abs) : a βŠ” b βŠ“ c = (a βŠ” b) βŠ“ (a βŠ” c) := ext fun _ ↦ max_min_distrib_left _ _ _ protected theorem sup_inf_distrib_right (a b c : CauSeq Ξ± abs) : a βŠ“ b βŠ” c = (a βŠ” c) βŠ“ (b βŠ” c) := ext fun _ ↦ max_min_distrib_right _ _ _ end Abs end CauSeq
Mathlib/Algebra/Order/CauSeq/Basic.lean
892
896
/- Copyright (c) 2020 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Algebra.Algebra.Spectrum.Basic import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.GeneralLinearGroup import Mathlib.RingTheory.Nilpotent.Basic import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.RingTheory.Nilpotent.Lemmas import Mathlib.Tactic.Peel /-! # Eigenvectors and eigenvalues This file defines eigenspaces, eigenvalues, and eigenvalues, as well as their generalized counterparts. We follow Axler's approach [axler2015] because it allows us to derive many properties without choosing a basis and without using matrices. An eigenspace of a linear map `f` for a scalar `ΞΌ` is the kernel of the map `(f - ΞΌ β€’ id)`. The nonzero elements of an eigenspace are eigenvectors `x`. They have the property `f x = ΞΌ β€’ x`. If there are eigenvectors for a scalar `ΞΌ`, the scalar `ΞΌ` is called an eigenvalue. There is no consensus in the literature whether `0` is an eigenvector. Our definition of `HasEigenvector` permits only nonzero vectors. For an eigenvector `x` that may also be `0`, we write `x ∈ f.eigenspace ΞΌ`. A generalized eigenspace of a linear map `f` for a natural number `k` and a scalar `ΞΌ` is the kernel of the map `(f - ΞΌ β€’ id) ^ k`. The nonzero elements of a generalized eigenspace are generalized eigenvectors `x`. If there are generalized eigenvectors for a natural number `k` and a scalar `ΞΌ`, the scalar `ΞΌ` is called a generalized eigenvalue. The fact that the eigenvalues are the roots of the minimal polynomial is proved in `LinearAlgebra.Eigenspace.Minpoly`. The existence of eigenvalues over an algebraically closed field (and the fact that the generalized eigenspaces then span) is deferred to `LinearAlgebra.Eigenspace.IsAlgClosed`. ## References * [Sheldon Axler, *Linear Algebra Done Right*][axler2015] * https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors ## Tags eigenspace, eigenvector, eigenvalue, eigen -/ universe u v w namespace Module namespace End open Module Set variable {K R : Type v} {V M : Type w} [CommRing R] [AddCommGroup M] [Module R M] [Field K] [AddCommGroup V] [Module K V] /-- The submodule `genEigenspace f ΞΌ k` for a linear map `f`, a scalar `ΞΌ`, and a number `k : β„•βˆž` is the kernel of `(f - ΞΌ β€’ id) ^ k` if `k` is a natural number (see Def 8.10 of [axler2015]), or the union of all these kernels if `k = ∞`. A generalized eigenspace for some exponent `k` is contained in the generalized eigenspace for exponents larger than `k`. -/ def genEigenspace (f : End R M) (ΞΌ : R) : β„•βˆž β†’o Submodule R M where toFun k := ⨆ l : β„•, ⨆ _ : l ≀ k, LinearMap.ker ((f - ΞΌ β€’ 1) ^ l) monotone' _ _ hkl := biSup_mono fun _ hi ↦ hi.trans hkl lemma mem_genEigenspace {f : End R M} {ΞΌ : R} {k : β„•βˆž} {x : M} : x ∈ f.genEigenspace ΞΌ k ↔ βˆƒ l : β„•, l ≀ k ∧ x ∈ LinearMap.ker ((f - ΞΌ β€’ 1) ^ l) := by have : Nonempty {l : β„• // l ≀ k} := ⟨⟨0, zero_le _⟩⟩ have : Directed (ΞΉ := { i : β„• // i ≀ k }) (Β· ≀ Β·) fun i ↦ LinearMap.ker ((f - ΞΌ β€’ 1) ^ (i : β„•)) := Monotone.directed_le fun m n h ↦ by simpa using (f - ΞΌ β€’ 1).iterateKer.monotone h simp_rw [genEigenspace, OrderHom.coe_mk, LinearMap.mem_ker, iSup_subtype', Submodule.mem_iSup_of_directed _ this, LinearMap.mem_ker, Subtype.exists, exists_prop] lemma genEigenspace_directed {f : End R M} {ΞΌ : R} {k : β„•βˆž} : Directed (Β· ≀ Β·) (fun l : {l : β„• // l ≀ k} ↦ f.genEigenspace ΞΌ l) := by have aux : Monotone ((↑) : {l : β„• // l ≀ k} β†’ β„•βˆž) := fun x y h ↦ by simpa using h exact ((genEigenspace f ΞΌ).monotone.comp aux).directed_le lemma mem_genEigenspace_nat {f : End R M} {ΞΌ : R} {k : β„•} {x : M} : x ∈ f.genEigenspace ΞΌ k ↔ x ∈ LinearMap.ker ((f - ΞΌ β€’ 1) ^ k) := by rw [mem_genEigenspace] constructor Β· rintro ⟨l, hl, hx⟩ simp only [Nat.cast_le] at hl exact (f - ΞΌ β€’ 1).iterateKer.monotone hl hx Β· intro hx exact ⟨k, le_rfl, hx⟩ lemma mem_genEigenspace_top {f : End R M} {ΞΌ : R} {x : M} : x ∈ f.genEigenspace ΞΌ ⊀ ↔ βˆƒ k : β„•, x ∈ LinearMap.ker ((f - ΞΌ β€’ 1) ^ k) := by simp [mem_genEigenspace] lemma genEigenspace_nat {f : End R M} {ΞΌ : R} {k : β„•} : f.genEigenspace ΞΌ k = LinearMap.ker ((f - ΞΌ β€’ 1) ^ k) := by ext; simp [mem_genEigenspace_nat] lemma genEigenspace_eq_iSup_genEigenspace_nat (f : End R M) (ΞΌ : R) (k : β„•βˆž) : f.genEigenspace ΞΌ k = ⨆ l : {l : β„• // l ≀ k}, f.genEigenspace ΞΌ l := by simp_rw [genEigenspace_nat, genEigenspace, OrderHom.coe_mk, iSup_subtype] lemma genEigenspace_top (f : End R M) (ΞΌ : R) : f.genEigenspace ΞΌ ⊀ = ⨆ k : β„•, f.genEigenspace ΞΌ k := by rw [genEigenspace_eq_iSup_genEigenspace_nat, iSup_subtype] simp only [le_top, iSup_pos, OrderHom.coe_mk] lemma genEigenspace_one {f : End R M} {ΞΌ : R} : f.genEigenspace ΞΌ 1 = LinearMap.ker (f - ΞΌ β€’ 1) := by rw [← Nat.cast_one, genEigenspace_nat, pow_one] @[simp] lemma mem_genEigenspace_one {f : End R M} {ΞΌ : R} {x : M} : x ∈ f.genEigenspace ΞΌ 1 ↔ f x = ΞΌ β€’ x := by rw [genEigenspace_one, LinearMap.mem_ker, LinearMap.sub_apply, sub_eq_zero, LinearMap.smul_apply, Module.End.one_apply] -- `simp` can prove this using `genEigenspace_zero` lemma mem_genEigenspace_zero {f : End R M} {ΞΌ : R} {x : M} : x ∈ f.genEigenspace ΞΌ 0 ↔ x = 0 := by rw [← Nat.cast_zero, mem_genEigenspace_nat, pow_zero, LinearMap.mem_ker, Module.End.one_apply] @[simp] lemma genEigenspace_zero {f : End R M} {ΞΌ : R} : f.genEigenspace ΞΌ 0 = βŠ₯ := by ext; apply mem_genEigenspace_zero @[simp] lemma genEigenspace_zero_nat (f : End R M) (k : β„•) : f.genEigenspace 0 k = LinearMap.ker (f ^ k) := by ext; simp [mem_genEigenspace_nat] /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`, and let `ΞΌ : R` and `k : β„•βˆž` be given. Then `x : M` satisfies `HasUnifEigenvector f ΞΌ k x` if `x ∈ f.genEigenspace ΞΌ k` and `x β‰  0`. For `k = 1`, this means that `x` is an eigenvector of `f` with eigenvalue `ΞΌ`. -/ def HasUnifEigenvector (f : End R M) (ΞΌ : R) (k : β„•βˆž) (x : M) : Prop := x ∈ f.genEigenspace ΞΌ k ∧ x β‰  0 /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`. Then `ΞΌ : R` and `k : β„•βˆž` satisfy `HasUnifEigenvalue f ΞΌ k` if `f.genEigenspace ΞΌ k β‰  βŠ₯`. For `k = 1`, this means that `ΞΌ` is an eigenvalue of `f`. -/ def HasUnifEigenvalue (f : End R M) (ΞΌ : R) (k : β„•βˆž) : Prop := f.genEigenspace ΞΌ k β‰  βŠ₯ /-- Let `M` be an `R`-module, and `f` an `R`-linear endomorphism of `M`. For `k : β„•βˆž`, we define `UnifEigenvalues f k` to be the type of all `ΞΌ : R` that satisfy `f.HasUnifEigenvalue ΞΌ k`. For `k = 1` this is the type of all eigenvalues of `f`. -/ def UnifEigenvalues (f : End R M) (k : β„•βˆž) : Type _ := { ΞΌ : R // f.HasUnifEigenvalue ΞΌ k } /-- The underlying value of a bundled eigenvalue. -/ @[coe] def UnifEigenvalues.val (f : Module.End R M) (k : β„•βˆž) : UnifEigenvalues f k β†’ R := Subtype.val instance UnifEigenvalues.instCoeOut {f : Module.End R M} (k : β„•βˆž) : CoeOut (UnifEigenvalues f k) R where coe := UnifEigenvalues.val f k instance UnivEigenvalues.instDecidableEq [DecidableEq R] (f : Module.End R M) (k : β„•βˆž) : DecidableEq (UnifEigenvalues f k) := inferInstanceAs (DecidableEq (Subtype (fun x : R ↦ f.HasUnifEigenvalue x k))) lemma HasUnifEigenvector.hasUnifEigenvalue {f : End R M} {ΞΌ : R} {k : β„•βˆž} {x : M} (h : f.HasUnifEigenvector ΞΌ k x) : f.HasUnifEigenvalue ΞΌ k := by rw [HasUnifEigenvalue, Submodule.ne_bot_iff] use x; exact h lemma HasUnifEigenvector.apply_eq_smul {f : End R M} {ΞΌ : R} {x : M} (hx : f.HasUnifEigenvector ΞΌ 1 x) : f x = ΞΌ β€’ x := mem_genEigenspace_one.mp hx.1 lemma HasUnifEigenvector.pow_apply {f : End R M} {ΞΌ : R} {v : M} (hv : f.HasUnifEigenvector ΞΌ 1 v) (n : β„•) : (f ^ n) v = ΞΌ ^ n β€’ v := by induction n <;> simp [*, pow_succ f, hv.apply_eq_smul, smul_smul, pow_succ' ΞΌ] theorem HasUnifEigenvalue.exists_hasUnifEigenvector {f : End R M} {ΞΌ : R} {k : β„•βˆž} (hΞΌ : f.HasUnifEigenvalue ΞΌ k) : βˆƒ v, f.HasUnifEigenvector ΞΌ k v := Submodule.exists_mem_ne_zero_of_ne_bot hΞΌ lemma HasUnifEigenvalue.pow {f : End R M} {ΞΌ : R} (h : f.HasUnifEigenvalue ΞΌ 1) (n : β„•) : (f ^ n).HasUnifEigenvalue (ΞΌ ^ n) 1 := by rw [HasUnifEigenvalue, Submodule.ne_bot_iff] obtain ⟨m : M, hm⟩ := h.exists_hasUnifEigenvector exact ⟨m, by simpa [mem_genEigenspace_one] using hm.pow_apply n, hm.2⟩ /-- A nilpotent endomorphism has nilpotent eigenvalues. See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/ lemma HasUnifEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M} (hfn : IsNilpotent f) {ΞΌ : R} (hf : f.HasUnifEigenvalue ΞΌ 1) : IsNilpotent ΞΌ := by obtain ⟨m : M, hm⟩ := hf.exists_hasUnifEigenvector obtain ⟨n : β„•, hn : f ^ n = 0⟩ := hfn exact ⟨n, by simpa [hn, hm.2, eq_comm (a := (0 : M))] using hm.pow_apply n⟩ lemma HasUnifEigenvalue.mem_spectrum {f : End R M} {ΞΌ : R} (hΞΌ : HasUnifEigenvalue f ΞΌ 1) : ΞΌ ∈ spectrum R f := by refine spectrum.mem_iff.mpr fun h_unit ↦ ?_ set f' := LinearMap.GeneralLinearGroup.toLinearEquiv h_unit.unit rcases hΞΌ.exists_hasUnifEigenvector with ⟨v, hv⟩ refine hv.2 ((LinearMap.ker_eq_bot'.mp f'.ker) v (?_ : ΞΌ β€’ v - f v = 0)) rw [hv.apply_eq_smul, sub_self] lemma hasUnifEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {ΞΌ : K} : f.HasUnifEigenvalue ΞΌ 1 ↔ ΞΌ ∈ spectrum K f := by rw [spectrum.mem_iff, IsUnit.sub_iff, LinearMap.isUnit_iff_ker_eq_bot, HasUnifEigenvalue, genEigenspace_one, ne_eq, not_iff_not] simp [Submodule.ext_iff, LinearMap.mem_ker] alias ⟨_, HasUnifEigenvalue.of_mem_spectrum⟩ := hasUnifEigenvalue_iff_mem_spectrum lemma genEigenspace_div (f : End K V) (a b : K) (hb : b β‰  0) : genEigenspace f (a / b) 1 = LinearMap.ker (b β€’ f - a β€’ 1) := calc genEigenspace f (a / b) 1 = genEigenspace f (b⁻¹ * a) 1 := by rw [div_eq_mul_inv, mul_comm] _ = LinearMap.ker (f - (b⁻¹ * a) β€’ 1) := by rw [genEigenspace_one] _ = LinearMap.ker (f - b⁻¹ β€’ a β€’ 1) := by rw [smul_smul] _ = LinearMap.ker (b β€’ (f - b⁻¹ β€’ a β€’ 1)) := by rw [LinearMap.ker_smul _ b hb] _ = LinearMap.ker (b β€’ f - a β€’ 1) := by rw [smul_sub, smul_inv_smulβ‚€ hb] /-- The generalized eigenrange for a linear map `f`, a scalar `ΞΌ`, and an exponent `k ∈ β„•βˆž` is the range of `(f - ΞΌ β€’ id) ^ k` if `k` is a natural number, or the infimum of these ranges if `k = ∞`. -/ def genEigenrange (f : End R M) (ΞΌ : R) (k : β„•βˆž) : Submodule R M := β¨… l : β„•, β¨… (_ : l ≀ k), LinearMap.range ((f - ΞΌ β€’ 1) ^ l) lemma genEigenrange_nat {f : End R M} {ΞΌ : R} {k : β„•} : f.genEigenrange ΞΌ k = LinearMap.range ((f - ΞΌ β€’ 1) ^ k) := by ext x simp only [genEigenrange, Nat.cast_le, Submodule.mem_iInf, LinearMap.mem_range] constructor Β· intro h exact h _ le_rfl Β· rintro ⟨x, rfl⟩ i hi have : k = i + (k - i) := by omega rw [this, pow_add] exact ⟨_, rfl⟩ /-- The exponent of a generalized eigenvalue is never 0. -/ lemma HasUnifEigenvalue.exp_ne_zero {f : End R M} {ΞΌ : R} {k : β„•} (h : f.HasUnifEigenvalue ΞΌ k) : k β‰  0 := by rintro rfl simp [HasUnifEigenvalue, Nat.cast_zero, genEigenspace_zero] at h /-- If there exists a natural number `k` such that the kernel of `(f - ΞΌ β€’ id) ^ k` is the maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not meaningful. -/ noncomputable def maxUnifEigenspaceIndex (f : End R M) (ΞΌ : R) := monotonicSequenceLimitIndex <| (f.genEigenspace ΞΌ).comp <| WithTop.coeOrderHom.toOrderHom /-- For an endomorphism of a Noetherian module, the maximal eigenspace is always of the form kernel `(f - ΞΌ β€’ id) ^ k` for some `k`. -/ lemma genEigenspace_top_eq_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (ΞΌ : R) : genEigenspace f ΞΌ ⊀ = f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) := by have := WellFoundedGT.iSup_eq_monotonicSequenceLimit <| (f.genEigenspace ΞΌ).comp <| WithTop.coeOrderHom.toOrderHom convert this using 1 simp only [genEigenspace, OrderHom.coe_mk, le_top, iSup_pos, OrderHom.comp_coe, Function.comp_def] rw [iSup_prod', iSup_subtype', ← sSup_range, ← sSup_range] congr aesop lemma genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex [IsNoetherian R M] (f : End R M) (ΞΌ : R) (k : β„•βˆž) : f.genEigenspace ΞΌ k ≀ f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) := by rw [← genEigenspace_top_eq_maxUnifEigenspaceIndex] exact (f.genEigenspace ΞΌ).monotone le_top /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/ theorem genEigenspace_eq_genEigenspace_maxUnifEigenspaceIndex_of_le [IsNoetherian R M] (f : End R M) (ΞΌ : R) {k : β„•} (hk : maxUnifEigenspaceIndex f ΞΌ ≀ k) : f.genEigenspace ΞΌ k = f.genEigenspace ΞΌ (maxUnifEigenspaceIndex f ΞΌ) := le_antisymm (genEigenspace_le_genEigenspace_maxUnifEigenspaceIndex _ _ _) ((f.genEigenspace ΞΌ).monotone <| by simpa using hk) /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for exponents larger than `k`. -/ lemma HasUnifEigenvalue.le {f : End R M} {ΞΌ : R} {k m : β„•βˆž} (hm : k ≀ m) (hk : f.HasUnifEigenvalue ΞΌ k) : f.HasUnifEigenvalue ΞΌ m := by unfold HasUnifEigenvalue at * contrapose! hk rw [← le_bot_iff, ← hk] exact (f.genEigenspace _).monotone hm /-- A generalized eigenvalue for some exponent `k` is also a generalized eigenvalue for positive exponents. -/ lemma HasUnifEigenvalue.lt {f : End R M} {ΞΌ : R} {k m : β„•βˆž} (hm : 0 < m) (hk : f.HasUnifEigenvalue ΞΌ k) : f.HasUnifEigenvalue ΞΌ m := by apply HasUnifEigenvalue.le (k := 1) (Order.one_le_iff_pos.mpr hm) intro contra; apply hk rw [genEigenspace_one, LinearMap.ker_eq_bot] at contra rw [eq_bot_iff] intro x hx rw [mem_genEigenspace] at hx rcases hx with ⟨l, -, hx⟩ rwa [LinearMap.ker_eq_bot.mpr] at hx rw [Module.End.coe_pow (f - ΞΌ β€’ 1) l] exact Function.Injective.iterate contra l /-- Generalized eigenvalues are actually just eigenvalues. -/ @[simp] lemma hasUnifEigenvalue_iff_hasUnifEigenvalue_one {f : End R M} {ΞΌ : R} {k : β„•βˆž} (hk : 0 < k) : f.HasUnifEigenvalue ΞΌ k ↔ f.HasUnifEigenvalue ΞΌ 1 := ⟨HasUnifEigenvalue.lt zero_lt_one, HasUnifEigenvalue.lt hk⟩ lemma maxUnifEigenspaceIndex_le_finrank [FiniteDimensional K V] (f : End K V) (ΞΌ : K) : maxUnifEigenspaceIndex f ΞΌ ≀ finrank K V := by apply Nat.sInf_le intro n hn apply le_antisymm Β· exact (f.genEigenspace ΞΌ).monotone <| WithTop.coeOrderHom.monotone hn Β· show (f.genEigenspace ΞΌ) n ≀ (f.genEigenspace ΞΌ) (finrank K V) rw [genEigenspace_nat, genEigenspace_nat] apply ker_pow_le_ker_pow_finrank /-- Every generalized eigenvector is a generalized eigenvector for exponent `finrank K V`. (Lemma 8.11 of [axler2015]) -/ lemma genEigenspace_le_genEigenspace_finrank [FiniteDimensional K V] (f : End K V) (ΞΌ : K) (k : β„•βˆž) : f.genEigenspace ΞΌ k ≀ f.genEigenspace ΞΌ (finrank K V) := by calc f.genEigenspace ΞΌ k ≀ f.genEigenspace ΞΌ ⊀ := (f.genEigenspace _).monotone le_top _ ≀ f.genEigenspace ΞΌ (finrank K V) := by rw [genEigenspace_top_eq_maxUnifEigenspaceIndex] exact (f.genEigenspace _).monotone <| by simpa using maxUnifEigenspaceIndex_le_finrank f ΞΌ /-- Generalized eigenspaces for exponents at least `finrank K V` are equal to each other. -/ theorem genEigenspace_eq_genEigenspace_finrank_of_le [FiniteDimensional K V] (f : End K V) (ΞΌ : K) {k : β„•} (hk : finrank K V ≀ k) : f.genEigenspace ΞΌ k = f.genEigenspace ΞΌ (finrank K V) := le_antisymm (genEigenspace_le_genEigenspace_finrank _ _ _) ((f.genEigenspace ΞΌ).monotone <| by simpa using hk) lemma mapsTo_genEigenspace_of_comm {f g : End R M} (h : Commute f g) (ΞΌ : R) (k : β„•βˆž) : MapsTo g (f.genEigenspace ΞΌ k) (f.genEigenspace ΞΌ k) := by intro x hx simp only [SetLike.mem_coe, mem_genEigenspace, LinearMap.mem_ker] at hx ⊒ rcases hx with ⟨l, hl, hx⟩ replace h : Commute ((f - ΞΌ β€’ (1 : End R M)) ^ l) g := (h.sub_left <| Algebra.commute_algebraMap_left ΞΌ g).pow_left l use l, hl rw [← LinearMap.comp_apply, ← Module.End.mul_eq_comp, h.eq, Module.End.mul_eq_comp, LinearMap.comp_apply, hx, map_zero] /-- The restriction of `f - ΞΌ β€’ 1` to the `k`-fold generalized `ΞΌ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_genEigenspace_nat (f : End R M) (ΞΌ : R) (k : β„•) (h : MapsTo (f - ΞΌ β€’ (1 : End R M)) (f.genEigenspace ΞΌ k) (f.genEigenspace ΞΌ k) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f ΞΌ) ΞΌ k) : IsNilpotent ((f - ΞΌ β€’ 1).restrict h) := by use k ext ⟨x, hx⟩ rw [mem_genEigenspace_nat] at hx rw [LinearMap.zero_apply, ZeroMemClass.coe_zero, ZeroMemClass.coe_eq_zero, Module.End.pow_restrict, LinearMap.restrict_apply] ext simpa /-- The restriction of `f - ΞΌ β€’ 1` to the generalized `ΞΌ`-eigenspace is nilpotent. -/ lemma isNilpotent_restrict_genEigenspace_top [IsNoetherian R M] (f : End R M) (ΞΌ : R) (h : MapsTo (f - ΞΌ β€’ (1 : End R M)) (f.genEigenspace ΞΌ ⊀) (f.genEigenspace ΞΌ ⊀) := mapsTo_genEigenspace_of_comm (Algebra.mul_sub_algebraMap_commutes f ΞΌ) ΞΌ _) : IsNilpotent ((f - ΞΌ β€’ 1).restrict h) := by apply isNilpotent_restrict_of_le on_goal 2 => apply isNilpotent_restrict_genEigenspace_nat f ΞΌ (maxUnifEigenspaceIndex f ΞΌ) rw [genEigenspace_top_eq_maxUnifEigenspaceIndex] /-- The submodule `eigenspace f ΞΌ` for a linear map `f` and a scalar `ΞΌ` consists of all vectors `x` such that `f x = ΞΌ β€’ x`. (Def 5.36 of [axler2015]). -/ abbrev eigenspace (f : End R M) (ΞΌ : R) : Submodule R M := f.genEigenspace ΞΌ 1 lemma eigenspace_def {f : End R M} {ΞΌ : R} : f.eigenspace ΞΌ = LinearMap.ker (f - ΞΌ β€’ 1) := by rw [eigenspace, genEigenspace_one] @[simp] theorem eigenspace_zero (f : End R M) : f.eigenspace 0 = LinearMap.ker f := by simp only [eigenspace, ← Nat.cast_one (R := β„•βˆž), genEigenspace_zero_nat, pow_one] /-- A nonzero element of an eigenspace is an eigenvector. (Def 5.7 of [axler2015]) -/ abbrev HasEigenvector (f : End R M) (ΞΌ : R) (x : M) : Prop := HasUnifEigenvector f ΞΌ 1 x lemma hasEigenvector_iff {f : End R M} {ΞΌ : R} {x : M} : f.HasEigenvector ΞΌ x ↔ x ∈ f.eigenspace ΞΌ ∧ x β‰  0 := Iff.rfl /-- A scalar `ΞΌ` is an eigenvalue for a linear map `f` if there are nonzero vectors `x` such that `f x = ΞΌ β€’ x`. (Def 5.5 of [axler2015]). -/ abbrev HasEigenvalue (f : End R M) (a : R) : Prop := HasUnifEigenvalue f a 1 lemma hasEigenvalue_iff {f : End R M} {ΞΌ : R} : f.HasEigenvalue ΞΌ ↔ f.eigenspace ΞΌ β‰  βŠ₯ := Iff.rfl /-- The eigenvalues of the endomorphism `f`, as a subtype of `R`. -/ abbrev Eigenvalues (f : End R M) : Type _ := UnifEigenvalues f 1 @[coe] abbrev Eigenvalues.val (f : Module.End R M) : Eigenvalues f β†’ R := UnifEigenvalues.val f 1 theorem hasEigenvalue_of_hasEigenvector {f : End R M} {ΞΌ : R} {x : M} (h : HasEigenvector f ΞΌ x) : HasEigenvalue f ΞΌ := h.hasUnifEigenvalue theorem mem_eigenspace_iff {f : End R M} {ΞΌ : R} {x : M} : x ∈ eigenspace f ΞΌ ↔ f x = ΞΌ β€’ x := mem_genEigenspace_one nonrec theorem HasEigenvector.apply_eq_smul {f : End R M} {ΞΌ : R} {x : M} (hx : f.HasEigenvector ΞΌ x) : f x = ΞΌ β€’ x := hx.apply_eq_smul nonrec theorem HasEigenvector.pow_apply {f : End R M} {ΞΌ : R} {v : M} (hv : f.HasEigenvector ΞΌ v) (n : β„•) : (f ^ n) v = ΞΌ ^ n β€’ v := hv.pow_apply n theorem HasEigenvalue.exists_hasEigenvector {f : End R M} {ΞΌ : R} (hΞΌ : f.HasEigenvalue ΞΌ) : βˆƒ v, f.HasEigenvector ΞΌ v := Submodule.exists_mem_ne_zero_of_ne_bot hΞΌ nonrec lemma HasEigenvalue.pow {f : End R M} {ΞΌ : R} (h : f.HasEigenvalue ΞΌ) (n : β„•) : (f ^ n).HasEigenvalue (ΞΌ ^ n) := h.pow n /-- A nilpotent endomorphism has nilpotent eigenvalues. See also `LinearMap.isNilpotent_trace_of_isNilpotent`. -/ nonrec lemma HasEigenvalue.isNilpotent_of_isNilpotent [NoZeroSMulDivisors R M] {f : End R M} (hfn : IsNilpotent f) {ΞΌ : R} (hf : f.HasEigenvalue ΞΌ) : IsNilpotent ΞΌ := hf.isNilpotent_of_isNilpotent hfn nonrec theorem HasEigenvalue.mem_spectrum {f : End R M} {ΞΌ : R} (hΞΌ : HasEigenvalue f ΞΌ) : ΞΌ ∈ spectrum R f := hΞΌ.mem_spectrum theorem hasEigenvalue_iff_mem_spectrum [FiniteDimensional K V] {f : End K V} {ΞΌ : K} : f.HasEigenvalue ΞΌ ↔ ΞΌ ∈ spectrum K f := hasUnifEigenvalue_iff_mem_spectrum alias ⟨_, HasEigenvalue.of_mem_spectrum⟩ := hasEigenvalue_iff_mem_spectrum theorem eigenspace_div (f : End K V) (a b : K) (hb : b β‰  0) : eigenspace f (a / b) = LinearMap.ker (b β€’ f - algebraMap K (End K V) a) := genEigenspace_div f a b hb @[deprecated genEigenspace_nat (since := "2024-10-28")] lemma genEigenspace_def (f : End R M) (ΞΌ : R) (k : β„•) : f.genEigenspace ΞΌ k = LinearMap.ker ((f - ΞΌ β€’ 1) ^ k) := genEigenspace_nat /-- A nonzero element of a generalized eigenspace is a generalized eigenvector. (Def 8.9 of [axler2015]) -/ abbrev HasGenEigenvector (f : End R M) (ΞΌ : R) (k : β„•) (x : M) : Prop := HasUnifEigenvector f ΞΌ k x lemma hasGenEigenvector_iff {f : End R M} {ΞΌ : R} {k : β„•} {x : M} : f.HasGenEigenvector ΞΌ k x ↔ x ∈ f.genEigenspace ΞΌ k ∧ x β‰  0 := Iff.rfl /-- A scalar `ΞΌ` is a generalized eigenvalue for a linear map `f` and an exponent `k ∈ β„•` if there are generalized eigenvectors for `f`, `k`, and `ΞΌ`. -/ abbrev HasGenEigenvalue (f : End R M) (ΞΌ : R) (k : β„•) : Prop := HasUnifEigenvalue f ΞΌ k lemma hasGenEigenvalue_iff {f : End R M} {ΞΌ : R} {k : β„•} : f.HasGenEigenvalue ΞΌ k ↔ f.genEigenspace ΞΌ k β‰  βŠ₯ := Iff.rfl @[deprecated genEigenrange_nat (since := "2024-10-28")] lemma genEigenrange_def {f : End R M} {ΞΌ : R} {k : β„•} : f.genEigenrange ΞΌ k = LinearMap.range ((f - ΞΌ β€’ 1) ^ k) := genEigenrange_nat /-- The exponent of a generalized eigenvalue is never 0. -/ theorem exp_ne_zero_of_hasGenEigenvalue {f : End R M} {ΞΌ : R} {k : β„•} (h : f.HasGenEigenvalue ΞΌ k) : k β‰  0 := HasUnifEigenvalue.exp_ne_zero h /-- The union of the kernels of `(f - ΞΌ β€’ id) ^ k` over all `k`. -/ abbrev maxGenEigenspace (f : End R M) (ΞΌ : R) : Submodule R M := genEigenspace f ΞΌ ⊀ lemma iSup_genEigenspace_eq (f : End R M) (ΞΌ : R) : ⨆ k : β„•, (f.genEigenspace ΞΌ) k = f.maxGenEigenspace ΞΌ := by simp_rw [maxGenEigenspace, genEigenspace_top] @[deprecated iSup_genEigenspace_eq (since := "2024-10-23")] lemma maxGenEigenspace_def (f : End R M) (ΞΌ : R) : f.maxGenEigenspace ΞΌ = ⨆ k : β„•, f.genEigenspace ΞΌ k := (iSup_genEigenspace_eq f ΞΌ).symm theorem genEigenspace_le_maximal (f : End R M) (ΞΌ : R) (k : β„•) : f.genEigenspace ΞΌ k ≀ f.maxGenEigenspace ΞΌ := (f.genEigenspace ΞΌ).monotone le_top @[simp] theorem mem_maxGenEigenspace (f : End R M) (ΞΌ : R) (m : M) : m ∈ f.maxGenEigenspace ΞΌ ↔ βˆƒ k : β„•, ((f - ΞΌ β€’ (1 : End R M)) ^ k) m = 0 :=
mem_genEigenspace_top /-- If there exists a natural number `k` such that the kernel of `(f - ΞΌ β€’ id) ^ k` is the maximal generalized eigenspace, then this value is the least such `k`. If not, this value is not meaningful. -/ noncomputable abbrev maxGenEigenspaceIndex (f : End R M) (ΞΌ : R) :=
Mathlib/LinearAlgebra/Eigenspace/Basic.lean
522
527
/- Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n β‰₯ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A Ξ± Ξ² : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : β„•} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * Β·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n β‰₯ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n β‰₯ 1` such that `n β€’ a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * Β·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {Ξ± : Type*} [AddMonoid Ξ±] {x : Ξ±} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ βˆƒ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ βˆƒ (n : β„€), n β‰  0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n β–Έ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h Β· rwa [h, zpow_natCast] at hn' Β· rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : β„• => x ^ n) : Β¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : β„•} : IsOfFinOrder a β†’ IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : β„•} (h : IsOfFinOrder (a ^ n)) (hn : n β‰  0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : β„•} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn Β· simp Β· exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x β†’ IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G β†’* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {Ξ· : Type*} {Gs : Ξ· β†’ Type*} [βˆ€ i, Monoid (Gs i)] {x : βˆ€ i, Gs i} (h : IsOfFinOrder x) : βˆ€ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n β‰₯ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n β‰₯ 1`, s.t. `n β€’ a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : β„• := minimalPeriod (x * Β·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {Ξ± : Type*} [AddMonoid Ξ±] (a : Ξ±) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * Β·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : Β¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ Β¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ βˆ€ n : β„•, 0 < n β†’ x ^ n β‰  1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ βˆ€ m, m < n β†’ 0 < m β†’ x ^ m β‰  1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 Β· classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl Β· rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid Ξ²] {y : Ξ²} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊒; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n β‰  0) (h : n < orderOf x) : x ^ n β‰  1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≀ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : β„•) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : β„•} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : β„•) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ Β·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * Β·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ Β·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ Β·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≑ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G β†’* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : βˆƒ m : β„•, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 Β· rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 Β· exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) β‰  1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x β‰  0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : βˆ€ p : β„•, p.Prime β†’ p ∣ n β†’ x ^ (n / p) β‰  1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : βˆƒ b : β„•, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] Β· exact Nat.minFac_dvd a Β· rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ βˆ€ n : β„•, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G β†’* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e.toMonoidHom e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G β†’* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : GΛ£} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive unit with inverse `(addOrderOf x - 1) β€’ x`. "] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : MΛ£ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ @[to_additive] lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n β‰  0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : β„•} (hn : n β‰  0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : β„•} (hx : orderOf x β‰  0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y Β· rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] Β· rw [m.coprime_zero_left.1 (orderOf_eq_zero hg β–Έ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≀ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 Β· rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : βˆ€ p : β„•, p.Prime β†’ p ∣ orderOf x β†’ p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] Β· exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : β„•} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x β‰  1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x β‰  1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : Β¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (βˆƒ k : β„•, orderOf x = p ^ k) ↔ βˆƒ m : β„•, x ^ (p : β„•) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i β€’ a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : β„•), ⟨n, rfl⟩⟩) ⟨fun ⟨_, hβ‚βŸ© ⟨_, hβ‚‚βŸ© ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ hβ‚‚ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟨x ^ (n : β„•), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : β„•) : (finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≑ m [MOD orderOf x] := by wlog hmn : m ≀ n generalizing m n Β· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : β„•} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : β„•} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≑ m [MOD orderOf x] := by wlog hmn : m ≀ n generalizing m n Β· rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : β„• ↦ x ^ n) ↔ Β¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : β„•} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : β„•} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : Β¬IsOfFinOrder x) : { y : G | Β¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : β„• => x ^ n have hs : s βŠ† { y : G | Β¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊒ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : Β¬Injective fun n : β„• => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : β„• ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ Β¬ IsOfFinOrder a := finite_powers.not /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a Β· exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp Β· have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : β„€} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : β„€) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ Β· rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] Β· rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] @[to_additive] theorem orderOf_dvd_sub_iff_zpow_eq_zpow {a b : β„€} : (orderOf x : β„€) ∣ a - b ↔ x ^ a = x ^ b := by rw [orderOf_dvd_iff_zpow_eq_one, zpow_sub, mul_inv_eq_one] namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : β„€) : x ^ (z % (orderOf x : β„€)) = x ^ z := calc x ^ (z % (orderOf x : β„€)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : β„€) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x Β· rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] Β· rw [orderOf_eq_zero h, _root_.pow_zero] @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : β„€} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ @[to_additive] theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow @[to_additive] theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h rw [orderOf_dvd_iff_pow_eq_one] exact zpow_pow_orderOf theorem smul_eq_self_of_mem_zpowers {Ξ± : Type*} [MulAction G Ξ±] (hx : x ∈ Subgroup.zpowers y) {a : Ξ±} (hs : y β€’ a = a) : x β€’ a = a := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx rw [← MulAction.toPerm_apply, ← MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k, MulAction.toPermHom_apply] exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact` theorem vadd_eq_self_of_mem_zmultiples {Ξ± G : Type*} [AddGroup G] [AddAction G Ξ±] {x y : G} (hx : x ∈ AddSubgroup.zmultiples y) {a : Ξ±} (hs : y +α΅₯ a = a) : x +α΅₯ a = a := @smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ Ξ± _ hx a hs attribute [to_additive existing] smul_eq_self_of_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) : y ∈ powers x ↔ y ∈ zpowers x := ⟨fun ⟨n, hn⟩ ↦ ⟨n, by simp_all⟩, fun ⟨i, hi⟩ ↦ ⟨(i % orderOf x).natAbs, by dsimp only rwa [← zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]⟩⟩ @[to_additive] lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x := Set.ext fun _ ↦ hx.mem_powers_iff_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ Β·) := hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf /-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `Subgroup.zmultiples a`, sending `i` to `i β€’ a`."] noncomputable def finEquivZPowers (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ zpowers x := (finEquivPowers hx).trans <| Equiv.setCongr hx.powers_eq_zpowers @[to_additive] lemma finEquivZPowers_apply (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivZPowers hx n = ⟨x ^ (n : β„•), n, zpow_natCast x n⟩ := rfl @[to_additive] lemma finEquivZPowers_symm_apply (hx : IsOfFinOrder x) (n : β„•) : (finEquivZPowers hx).symm ⟨x ^ n, ⟨n, by simp⟩⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply _ n end Group section CommMonoid variable [CommMonoid G] {x y : G} /-- Elements of finite order are closed under multiplication. -/ @[to_additive "Elements of finite additive order are closed under addition."] theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := (Commute.all x y).isOfFinOrder_mul hx hy end CommMonoid section FiniteMonoid variable [Monoid G] {x : G} {n : β„•} @[to_additive] theorem sum_card_orderOf_eq_card_pow_eq_one [Fintype G] [DecidableEq G] (hn : n β‰  0) : βˆ‘ m ∈ divisors n, #{x : G | orderOf x = m} = #{x : G | x ^ n = 1} := by refine (Finset.card_biUnion ?_).symm.trans ?_ Β· simp +contextual [Set.PairwiseDisjoint, Set.Pairwise, disjoint_iff, Finset.ext_iff] Β· congr; ext; simp [hn, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_le_card_univ [Fintype G] : orderOf x ≀ Fintype.card G := Finset.le_card_of_inj_on_range (x ^ Β·) (fun _ _ ↦ Finset.mem_univ _) pow_injOn_Iio_orderOf @[to_additive] theorem orderOf_le_card [Finite G] : orderOf x ≀ Nat.card G := by obtain ⟨⟩ := nonempty_fintype G simpa using orderOf_le_card_univ end FiniteMonoid section FiniteCancelMonoid variable [LeftCancelMonoid G] -- TODO: Of course everything also works for `RightCancelMonoid`. section Finite variable [Finite G] {x y : G} {n : β„•} -- TODO: Use this to show that a finite left cancellative monoid is a group. @[to_additive] lemma isOfFinOrder_of_finite (x : G) : IsOfFinOrder x := by by_contra h; exact infinite_not_isOfFinOrder h <| Set.toFinite _ /-- This is the same as `IsOfFinOrder.orderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative monoid. -/ @[to_additive "This is the same as `IsOfFinAddOrder.addOrderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative additive monoid."] lemma orderOf_pos (x : G) : 0 < orderOf x := (isOfFinOrder_of_finite x).orderOf_pos /-- This is the same as `orderOf_pow'` and `orderOf_pow''` but with one assumption less which is automatic in the case of a finite cancellative monoid. -/ @[to_additive "This is the same as `addOrderOf_nsmul'` and `addOrderOf_nsmul` but with one assumption less which is automatic in the case of a finite cancellative additive monoid."] theorem orderOf_pow (x : G) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := (isOfFinOrder_of_finite _).orderOf_pow .. @[to_additive] theorem mem_powers_iff_mem_range_orderOf [DecidableEq G] : y ∈ powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ Β·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' (orderOf_pos x) <| pow_mod_orderOf _ /-- The equivalence between `Submonoid.powers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Submonoid.multiples` of two elements `a, b` of the same additive order, mapping `i β€’ a` to `i β€’ b`."] noncomputable def powersEquivPowers (h : orderOf x = orderOf y) : powers x ≃ powers y := (finEquivPowers <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivPowers <| isOfFinOrder_of_finite _ @[to_additive (attr := simp)] theorem powersEquivPowers_apply (h : orderOf x = orderOf y) (n : β„•) : powersEquivPowers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ := by rw [powersEquivPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} @[to_additive] lemma orderOf_eq_card_powers : orderOf x = Fintype.card (powers x : Submonoid G) := (Fintype.card_fin (orderOf x)).symm.trans <| Fintype.card_eq.2 ⟨finEquivPowers <| isOfFinOrder_of_finite _⟩ end FiniteCancelMonoid section FiniteGroup variable [Group G] {x y : G} @[to_additive] theorem zpow_eq_one_iff_modEq {n : β„€} : x ^ n = 1 ↔ n ≑ 0 [ZMOD orderOf x] := by rw [Int.modEq_zero_iff_dvd, orderOf_dvd_iff_zpow_eq_one] @[to_additive] theorem zpow_eq_zpow_iff_modEq {m n : β„€} : x ^ m = x ^ n ↔ m ≑ n [ZMOD orderOf x] := by rw [← mul_inv_eq_one, ← zpow_sub, zpow_eq_one_iff_modEq, Int.modEq_iff_dvd, Int.modEq_iff_dvd, zero_sub, neg_sub] @[to_additive (attr := simp)] theorem injective_zpow_iff_not_isOfFinOrder : (Injective fun n : β„€ => x ^ n) ↔ Β¬IsOfFinOrder x := by refine ⟨?_, fun h n m hnm => ?_⟩ Β· simp_rw [isOfFinOrder_iff_pow_eq_one] rintro h ⟨n, hn, hx⟩ exact Nat.cast_ne_zero.2 hn.ne' (h <| by simpa using hx) rwa [zpow_eq_zpow_iff_modEq, orderOf_eq_zero_iff.2 h, Nat.cast_zero, Int.modEq_zero_iff] at hnm section Finite variable [Finite G] @[to_additive] theorem exists_zpow_eq_one (x : G) : βˆƒ (i : β„€) (_ : i β‰  0), x ^ (i : β„€) = 1 := by obtain ⟨w, hw1, hw2⟩ := isOfFinOrder_of_finite x refine ⟨w, Int.natCast_ne_zero.mpr (_root_.ne_of_gt hw1), ?_⟩ rw [zpow_natCast] exact (isPeriodicPt_mul_iff_pow_eq_one _).mp hw2 @[to_additive] lemma mem_powers_iff_mem_zpowers : y ∈ powers x ↔ y ∈ zpowers x := (isOfFinOrder_of_finite _).mem_powers_iff_mem_zpowers @[to_additive] lemma powers_eq_zpowers (x : G) : (powers x : Set G) = zpowers x := (isOfFinOrder_of_finite _).powers_eq_zpowers @[to_additive] lemma mem_zpowers_iff_mem_range_orderOf [DecidableEq G] : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ Β·) := (isOfFinOrder_of_finite _).mem_zpowers_iff_mem_range_orderOf /-- The equivalence between `Subgroup.zpowers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Subgroup.zmultiples` of two elements `a, b` of the same additive order, mapping `i β€’ a` to `i β€’ b`."] noncomputable def zpowersEquivZPowers (h : orderOf x = orderOf y) : Subgroup.zpowers x ≃ Subgroup.zpowers y := (finEquivZPowers <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivZPowers <| isOfFinOrder_of_finite _ @[to_additive (attr := simp) zmultiples_equiv_zmultiples_apply] theorem zpowersEquivZPowers_apply (h : orderOf x = orderOf y) (n : β„•) : zpowersEquivZPowers h ⟨x ^ n, n, zpow_natCast x n⟩ = ⟨y ^ n, n, zpow_natCast y n⟩ := by rw [zpowersEquivZPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivZPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivZPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} {n : β„•} /-- See also `Nat.card_zpowers`. -/ @[to_additive "See also `Nat.card_zmultiples`."] theorem Fintype.card_zpowers : Fintype.card (zpowers x) = orderOf x :=
(Fintype.card_eq.2 ⟨finEquivZPowers <| isOfFinOrder_of_finite _⟩).symm.trans <| Fintype.card_fin (orderOf x)
Mathlib/GroupTheory/OrderOfElement.lean
854
856
/- Copyright (c) 2018 Ellen Arlt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ellen Arlt, Blair Shi, Sean Leather, Mario Carneiro, Johan Commelin -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Composition import Mathlib.Data.Matrix.ConjTranspose /-! # Block Matrices ## Main definitions * `Matrix.fromBlocks`: build a block matrix out of 4 blocks * `Matrix.toBlocks₁₁`, `Matrix.toBlocks₁₂`, `Matrix.toBlocks₂₁`, `Matrix.toBlocksβ‚‚β‚‚`: extract each of the four blocks from `Matrix.fromBlocks`. * `Matrix.blockDiagonal`: block diagonal of equally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonalRingHom`. * `Matrix.blockDiag`: extract the blocks from the diagonal of a block diagonal matrix. * `Matrix.blockDiagonal'`: block diagonal of unequally sized blocks. On square blocks, this is a ring homomorphisms, `Matrix.blockDiagonal'RingHom`. * `Matrix.blockDiag'`: extract the blocks from the diagonal of a block diagonal matrix. -/ variable {l m n o p q : Type*} {m' n' p' : o β†’ Type*} variable {R : Type*} {S : Type*} {Ξ± : Type*} {Ξ² : Type*} open Matrix namespace Matrix theorem dotProduct_block [Fintype m] [Fintype n] [Mul Ξ±] [AddCommMonoid Ξ±] (v w : m βŠ• n β†’ Ξ±) : v ⬝α΅₯ w = v ∘ Sum.inl ⬝α΅₯ w ∘ Sum.inl + v ∘ Sum.inr ⬝α΅₯ w ∘ Sum.inr := Fintype.sum_sum_type _ section BlockMatrices /-- We can form a single large matrix by flattening smaller 'block' matrices of compatible dimensions. -/ @[pp_nodot] def fromBlocks (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : Matrix (n βŠ• o) (l βŠ• m) Ξ± := of <| Sum.elim (fun i => Sum.elim (A i) (B i)) (fun j => Sum.elim (C j) (D j)) @[simp] theorem fromBlocks_apply₁₁ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (i : n) (j : l) : fromBlocks A B C D (Sum.inl i) (Sum.inl j) = A i j := rfl @[simp] theorem fromBlocks_apply₁₂ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (i : n) (j : m) : fromBlocks A B C D (Sum.inl i) (Sum.inr j) = B i j := rfl @[simp] theorem fromBlocks_apply₂₁ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (i : o) (j : l) : fromBlocks A B C D (Sum.inr i) (Sum.inl j) = C i j := rfl @[simp] theorem fromBlocks_applyβ‚‚β‚‚ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (i : o) (j : m) : fromBlocks A B C D (Sum.inr i) (Sum.inr j) = D i j := rfl /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top left" submatrix. -/ def toBlocks₁₁ (M : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : Matrix n l Ξ± := of fun i j => M (Sum.inl i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "top right" submatrix. -/ def toBlocks₁₂ (M : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : Matrix n m Ξ± := of fun i j => M (Sum.inl i) (Sum.inr j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom left" submatrix. -/ def toBlocks₂₁ (M : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : Matrix o l Ξ± := of fun i j => M (Sum.inr i) (Sum.inl j) /-- Given a matrix whose row and column indexes are sum types, we can extract the corresponding "bottom right" submatrix. -/ def toBlocksβ‚‚β‚‚ (M : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : Matrix o m Ξ± := of fun i j => M (Sum.inr i) (Sum.inr j) theorem fromBlocks_toBlocks (M : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : fromBlocks M.toBlocks₁₁ M.toBlocks₁₂ M.toBlocks₂₁ M.toBlocksβ‚‚β‚‚ = M := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl @[simp] theorem toBlocks_fromBlocks₁₁ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocks₁₁ = A := rfl @[simp] theorem toBlocks_fromBlocks₁₂ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocks₁₂ = B := rfl @[simp] theorem toBlocks_fromBlocks₂₁ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocks₂₁ = C := rfl @[simp] theorem toBlocks_fromBlocksβ‚‚β‚‚ (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D).toBlocksβ‚‚β‚‚ = D := rfl /-- Two block matrices are equal if their blocks are equal. -/ theorem ext_iff_blocks {A B : Matrix (n βŠ• o) (l βŠ• m) Ξ±} : A = B ↔ A.toBlocks₁₁ = B.toBlocks₁₁ ∧ A.toBlocks₁₂ = B.toBlocks₁₂ ∧ A.toBlocks₂₁ = B.toBlocks₂₁ ∧ A.toBlocksβ‚‚β‚‚ = B.toBlocksβ‚‚β‚‚ := ⟨fun h => h β–Έ ⟨rfl, rfl, rfl, rfl⟩, fun ⟨h₁₁, h₁₂, h₂₁, hβ‚‚β‚‚βŸ© => by rw [← fromBlocks_toBlocks A, ← fromBlocks_toBlocks B, h₁₁, h₁₂, h₂₁, hβ‚‚β‚‚]⟩ @[simp] theorem fromBlocks_inj {A : Matrix n l Ξ±} {B : Matrix n m Ξ±} {C : Matrix o l Ξ±} {D : Matrix o m Ξ±} {A' : Matrix n l Ξ±} {B' : Matrix n m Ξ±} {C' : Matrix o l Ξ±} {D' : Matrix o m Ξ±} : fromBlocks A B C D = fromBlocks A' B' C' D' ↔ A = A' ∧ B = B' ∧ C = C' ∧ D = D' := ext_iff_blocks theorem fromBlocks_map (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (f : Ξ± β†’ Ξ²) : (fromBlocks A B C D).map f = fromBlocks (A.map f) (B.map f) (C.map f) (D.map f) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_transpose (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D)α΅€ = fromBlocks Aα΅€ Cα΅€ Bα΅€ Dα΅€ := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_conjTranspose [Star Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D)α΄΄ = fromBlocks Aα΄΄ Cα΄΄ Bα΄΄ Dα΄΄ := by simp only [conjTranspose, fromBlocks_transpose, fromBlocks_map] @[simp] theorem fromBlocks_submatrix_sum_swap_left (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (f : p β†’ l βŠ• m) : (fromBlocks A B C D).submatrix Sum.swap f = (fromBlocks C D A B).submatrix id f := by ext i j cases i <;> dsimp <;> cases f j <;> rfl @[simp] theorem fromBlocks_submatrix_sum_swap_right (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (f : p β†’ n βŠ• o) : (fromBlocks A B C D).submatrix f Sum.swap = (fromBlocks B A D C).submatrix f id := by ext i j cases j <;> dsimp <;> cases f i <;> rfl theorem fromBlocks_submatrix_sum_swap_sum_swap {l m n o Ξ± : Type*} (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : (fromBlocks A B C D).submatrix Sum.swap Sum.swap = fromBlocks D C B A := by simp /-- A 2x2 block matrix is block diagonal if the blocks outside of the diagonal vanish -/ def IsTwoBlockDiagonal [Zero Ξ±] (A : Matrix (n βŠ• o) (l βŠ• m) Ξ±) : Prop := toBlocks₁₂ A = 0 ∧ toBlocks₂₁ A = 0 /-- Let `p` pick out certain rows and `q` pick out certain columns of a matrix `M`. Then `toBlock M p q` is the corresponding block matrix. -/ def toBlock (M : Matrix m n Ξ±) (p : m β†’ Prop) (q : n β†’ Prop) : Matrix { a // p a } { a // q a } Ξ± := M.submatrix (↑) (↑) @[simp] theorem toBlock_apply (M : Matrix m n Ξ±) (p : m β†’ Prop) (q : n β†’ Prop) (i : { a // p a }) (j : { a // q a }) : toBlock M p q i j = M ↑i ↑j := rfl /-- Let `p` pick out certain rows and columns of a square matrix `M`. Then `toSquareBlockProp M p` is the corresponding block matrix. -/ def toSquareBlockProp (M : Matrix m m Ξ±) (p : m β†’ Prop) : Matrix { a // p a } { a // p a } Ξ± := toBlock M _ _ theorem toSquareBlockProp_def (M : Matrix m m Ξ±) (p : m β†’ Prop) : toSquareBlockProp M p = of (fun i j : { a // p a } => M ↑i ↑j) := rfl /-- Let `b` map rows and columns of a square matrix `M` to blocks. Then `toSquareBlock M b k` is the block `k` matrix. -/ def toSquareBlock (M : Matrix m m Ξ±) (b : m β†’ Ξ²) (k : Ξ²) : Matrix { a // b a = k } { a // b a = k } Ξ± := toSquareBlockProp M _ theorem toSquareBlock_def (M : Matrix m m Ξ±) (b : m β†’ Ξ²) (k : Ξ²) : toSquareBlock M b k = of (fun i j : { a // b a = k } => M ↑i ↑j) := rfl theorem fromBlocks_smul [SMul R Ξ±] (x : R) (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) : x β€’ fromBlocks A B C D = fromBlocks (x β€’ A) (x β€’ B) (x β€’ C) (x β€’ D) := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [fromBlocks] theorem fromBlocks_neg [Neg R] (A : Matrix n l R) (B : Matrix n m R) (C : Matrix o l R) (D : Matrix o m R) : -fromBlocks A B C D = fromBlocks (-A) (-B) (-C) (-D) := by ext i j cases i <;> cases j <;> simp [fromBlocks] @[simp] theorem fromBlocks_zero [Zero Ξ±] : fromBlocks (0 : Matrix n l Ξ±) 0 0 (0 : Matrix o m Ξ±) = 0 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_add [Add Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (A' : Matrix n l Ξ±) (B' : Matrix n m Ξ±) (C' : Matrix o l Ξ±) (D' : Matrix o m Ξ±) : fromBlocks A B C D + fromBlocks A' B' C' D' = fromBlocks (A + A') (B + B') (C + C') (D + D') := by ext i j; rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> rfl theorem fromBlocks_multiply [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (A' : Matrix l p Ξ±) (B' : Matrix l q Ξ±) (C' : Matrix m p Ξ±) (D' : Matrix m q Ξ±) : fromBlocks A B C D * fromBlocks A' B' C' D' = fromBlocks (A * A' + B * C') (A * B' + B * D') (C * A' + D * C') (C * B' + D * D') := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp only [fromBlocks, mul_apply, of_apply, Sum.elim_inr, Fintype.sum_sum_type, Sum.elim_inl, add_apply] theorem fromBlocks_mulVec [Fintype l] [Fintype m] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (x : l βŠ• m β†’ Ξ±) : (fromBlocks A B C D) *α΅₯ x = Sum.elim (A *α΅₯ (x ∘ Sum.inl) + B *α΅₯ (x ∘ Sum.inr)) (C *α΅₯ (x ∘ Sum.inl) + D *α΅₯ (x ∘ Sum.inr)) := by ext i cases i <;> simp [mulVec, dotProduct] theorem vecMul_fromBlocks [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring Ξ±] (A : Matrix n l Ξ±) (B : Matrix n m Ξ±) (C : Matrix o l Ξ±) (D : Matrix o m Ξ±) (x : n βŠ• o β†’ Ξ±) : x α΅₯* fromBlocks A B C D = Sum.elim ((x ∘ Sum.inl) α΅₯* A + (x ∘ Sum.inr) α΅₯* C) ((x ∘ Sum.inl) α΅₯* B + (x ∘ Sum.inr) α΅₯* D) := by ext i cases i <;> simp [vecMul, dotProduct] variable [DecidableEq l] [DecidableEq m] section Zero variable [Zero Ξ±] theorem toBlock_diagonal_self (d : m β†’ Ξ±) (p : m β†’ Prop) : Matrix.toBlock (diagonal d) p p = diagonal fun i : Subtype p => d ↑i := by ext i j by_cases h : i = j Β· simp [h] Β· simp [One.one, h, Subtype.val_injective.ne h] theorem toBlock_diagonal_disjoint (d : m β†’ Ξ±) {p q : m β†’ Prop} (hpq : Disjoint p q) : Matrix.toBlock (diagonal d) p q = 0 := by ext ⟨i, hi⟩ ⟨j, hj⟩ have : i β‰  j := fun heq => hpq.le_bot i ⟨hi, heq.symm β–Έ hj⟩ simp [diagonal_apply_ne d this] @[simp] theorem fromBlocks_diagonal (d₁ : l β†’ Ξ±) (dβ‚‚ : m β†’ Ξ±) : fromBlocks (diagonal d₁) 0 0 (diagonal dβ‚‚) = diagonal (Sum.elim d₁ dβ‚‚) := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [diagonal] @[simp] lemma toBlocks₁₁_diagonal (v : l βŠ• m β†’ Ξ±) : toBlocks₁₁ (diagonal v) = diagonal (fun i => v (Sum.inl i)) := by unfold toBlocks₁₁ funext i j simp only [ne_eq, Sum.inl.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocksβ‚‚β‚‚_diagonal (v : l βŠ• m β†’ Ξ±) : toBlocksβ‚‚β‚‚ (diagonal v) = diagonal (fun i => v (Sum.inr i)) := by unfold toBlocksβ‚‚β‚‚ funext i j simp only [ne_eq, Sum.inr.injEq, of_apply, diagonal_apply] @[simp] lemma toBlocks₁₂_diagonal (v : l βŠ• m β†’ Ξ±) : toBlocks₁₂ (diagonal v) = 0 := rfl @[simp] lemma toBlocks₂₁_diagonal (v : l βŠ• m β†’ Ξ±) : toBlocks₂₁ (diagonal v) = 0 := rfl end Zero section HasZeroHasOne variable [Zero Ξ±] [One Ξ±] @[simp] theorem fromBlocks_one : fromBlocks (1 : Matrix l l Ξ±) 0 0 (1 : Matrix m m Ξ±) = 1 := by ext i j rcases i with ⟨⟩ <;> rcases j with ⟨⟩ <;> simp [one_apply] @[simp] theorem toBlock_one_self (p : m β†’ Prop) : Matrix.toBlock (1 : Matrix m m Ξ±) p p = 1 := toBlock_diagonal_self _ p theorem toBlock_one_disjoint {p q : m β†’ Prop} (hpq : Disjoint p q) : Matrix.toBlock (1 : Matrix m m Ξ±) p q = 0 := toBlock_diagonal_disjoint _ hpq end HasZeroHasOne end BlockMatrices section BlockDiagonal variable [DecidableEq o] section Zero variable [Zero Ξ±] [Zero Ξ²] /-- `Matrix.blockDiagonal M` turns a homogeneously-indexed collection of matrices `M : o β†’ Matrix m n Ξ±'` into an `m Γ— o`-by-`n Γ— o` block matrix which has the entries of `M` along the diagonal and zero elsewhere. See also `Matrix.blockDiagonal'` if the matrices may not have the same size everywhere. -/ def blockDiagonal (M : o β†’ Matrix m n Ξ±) : Matrix (m Γ— o) (n Γ— o) Ξ± := of <| (fun ⟨i, k⟩ ⟨j, k'⟩ => if k = k' then M k i j else 0 : m Γ— o β†’ n Γ— o β†’ Ξ±) -- TODO: set as an equation lemma for `blockDiagonal`, see https://github.com/leanprover-community/mathlib4/pull/3024 theorem blockDiagonal_apply' (M : o β†’ Matrix m n Ξ±) (i k j k') : blockDiagonal M ⟨i, k⟩ ⟨j, k'⟩ = if k = k' then M k i j else 0 := rfl theorem blockDiagonal_apply (M : o β†’ Matrix m n Ξ±) (ik jk) : blockDiagonal M ik jk = if ik.2 = jk.2 then M ik.2 ik.1 jk.1 else 0 := by cases ik cases jk rfl @[simp] theorem blockDiagonal_apply_eq (M : o β†’ Matrix m n Ξ±) (i j k) : blockDiagonal M (i, k) (j, k) = M k i j := if_pos rfl theorem blockDiagonal_apply_ne (M : o β†’ Matrix m n Ξ±) (i j) {k k'} (h : k β‰  k') : blockDiagonal M (i, k) (j, k') = 0 := if_neg h theorem blockDiagonal_map (M : o β†’ Matrix m n Ξ±) (f : Ξ± β†’ Ξ²) (hf : f 0 = 0) : (blockDiagonal M).map f = blockDiagonal fun k => (M k).map f := by ext simp only [map_apply, blockDiagonal_apply, eq_comm] rw [apply_ite f, hf] @[simp] theorem blockDiagonal_transpose (M : o β†’ Matrix m n Ξ±) : (blockDiagonal M)α΅€ = blockDiagonal fun k => (M k)α΅€ := by ext simp only [transpose_apply, blockDiagonal_apply, eq_comm] split_ifs with h Β· rw [h] Β· rfl @[simp] theorem blockDiagonal_conjTranspose {Ξ± : Type*} [AddMonoid Ξ±] [StarAddMonoid Ξ±] (M : o β†’ Matrix m n Ξ±) : (blockDiagonal M)α΄΄ = blockDiagonal fun k => (M k)α΄΄ := by simp only [conjTranspose, blockDiagonal_transpose] rw [blockDiagonal_map _ star (star_zero Ξ±)] @[simp] theorem blockDiagonal_zero : blockDiagonal (0 : o β†’ Matrix m n Ξ±) = 0 := by ext simp [blockDiagonal_apply] @[simp] theorem blockDiagonal_diagonal [DecidableEq m] (d : o β†’ m β†’ Ξ±) : (blockDiagonal fun k => diagonal (d k)) = diagonal fun ik => d ik.2 ik.1 := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, diagonal_apply, Prod.mk_inj, ← ite_and] congr 1 rw [and_comm] @[simp] theorem blockDiagonal_one [DecidableEq m] [One Ξ±] : blockDiagonal (1 : o β†’ Matrix m m Ξ±) = 1 := show (blockDiagonal fun _ : o => diagonal fun _ : m => (1 : Ξ±)) = diagonal fun _ => 1 by rw [blockDiagonal_diagonal] end Zero @[simp] theorem blockDiagonal_add [AddZeroClass Ξ±] (M N : o β†’ Matrix m n Ξ±) : blockDiagonal (M + N) = blockDiagonal M + blockDiagonal N := by ext simp only [blockDiagonal_apply, Pi.add_apply, add_apply] split_ifs <;> simp section variable (o m n Ξ±) /-- `Matrix.blockDiagonal` as an `AddMonoidHom`. -/ @[simps] def blockDiagonalAddMonoidHom [AddZeroClass Ξ±] : (o β†’ Matrix m n Ξ±) β†’+ Matrix (m Γ— o) (n Γ— o) Ξ± where toFun := blockDiagonal map_zero' := blockDiagonal_zero map_add' := blockDiagonal_add end @[simp] theorem blockDiagonal_neg [AddGroup Ξ±] (M : o β†’ Matrix m n Ξ±) : blockDiagonal (-M) = -blockDiagonal M := map_neg (blockDiagonalAddMonoidHom m n o Ξ±) M @[simp] theorem blockDiagonal_sub [AddGroup Ξ±] (M N : o β†’ Matrix m n Ξ±) : blockDiagonal (M - N) = blockDiagonal M - blockDiagonal N := map_sub (blockDiagonalAddMonoidHom m n o Ξ±) M N @[simp] theorem blockDiagonal_mul [Fintype n] [Fintype o] [NonUnitalNonAssocSemiring Ξ±] (M : o β†’ Matrix m n Ξ±) (N : o β†’ Matrix n p Ξ±) : (blockDiagonal fun k => M k * N k) = blockDiagonal M * blockDiagonal N := by ext ⟨i, k⟩ ⟨j, k'⟩ simp only [blockDiagonal_apply, mul_apply, ← Finset.univ_product_univ, Finset.sum_product] split_ifs with h <;> simp [h] section
variable (Ξ± m o) /-- `Matrix.blockDiagonal` as a `RingHom`. -/ @[simps] def blockDiagonalRingHom [DecidableEq m] [Fintype o] [Fintype m] [NonAssocSemiring Ξ±] : (o β†’ Matrix m m Ξ±) β†’+* Matrix (m Γ— o) (m Γ— o) Ξ± :=
Mathlib/Data/Matrix/Block.lean
422
427
/- Copyright (c) 2020 RΓ©my Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: RΓ©my Degenne, SΓ©bastien GouΓ«zel -/ import Mathlib.Analysis.NormedSpace.IndicatorFunction import Mathlib.Data.Fintype.Order import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.LpSeminorm.Defs import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.Sub /-! # Basic theorems about β„’p space -/ noncomputable section open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology ComplexConjugate variable {Ξ± Ξ΅ Ξ΅' E F G : Type*} {m m0 : MeasurableSpace Ξ±} {p : ℝβ‰₯0∞} {q : ℝ} {ΞΌ Ξ½ : Measure Ξ±} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] [ENorm Ξ΅] [ENorm Ξ΅'] namespace MeasureTheory section Lp section Top theorem MemLp.eLpNorm_lt_top [TopologicalSpace Ξ΅] {f : Ξ± β†’ Ξ΅} (hfp : MemLp f p ΞΌ) : eLpNorm f p ΞΌ < ∞ := hfp.2 @[deprecated (since := "2025-02-21")] alias Memβ„’p.eLpNorm_lt_top := MemLp.eLpNorm_lt_top theorem MemLp.eLpNorm_ne_top [TopologicalSpace Ξ΅] {f : Ξ± β†’ Ξ΅} (hfp : MemLp f p ΞΌ) : eLpNorm f p ΞΌ β‰  ∞ := ne_of_lt hfp.2 @[deprecated (since := "2025-02-21")] alias Memβ„’p.eLpNorm_ne_top := MemLp.eLpNorm_ne_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top {f : Ξ± β†’ Ξ΅} (hq0_lt : 0 < q) (hfq : eLpNorm' f q ΞΌ < ∞) : ∫⁻ a, β€–f aβ€–β‚‘ ^ q βˆ‚ΞΌ < ∞ := by rw [lintegral_rpow_enorm_eq_rpow_eLpNorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm'_lt_top' := lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top theorem lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top {f : Ξ± β†’ Ξ΅} (hp_ne_zero : p β‰  0) (hp_ne_top : p β‰  ∞) (hfp : eLpNorm f p ΞΌ < ∞) : ∫⁻ a, β€–f aβ€–β‚‘ ^ p.toReal βˆ‚ΞΌ < ∞ := by apply lintegral_rpow_enorm_lt_top_of_eLpNorm'_lt_top Β· exact ENNReal.toReal_pos hp_ne_zero hp_ne_top Β· simpa [eLpNorm_eq_eLpNorm' hp_ne_zero hp_ne_top] using hfp @[deprecated (since := "2025-01-17")] alias lintegral_rpow_nnnorm_lt_top_of_eLpNorm_lt_top := lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top theorem eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top {f : Ξ± β†’ Ξ΅} (hp_ne_zero : p β‰  0) (hp_ne_top : p β‰  ∞) : eLpNorm f p ΞΌ < ∞ ↔ ∫⁻ a, (β€–f aβ€–β‚‘) ^ p.toReal βˆ‚ΞΌ < ∞ := ⟨lintegral_rpow_enorm_lt_top_of_eLpNorm_lt_top hp_ne_zero hp_ne_top, by intro h have hp' := ENNReal.toReal_pos hp_ne_zero hp_ne_top have : 0 < 1 / p.toReal := div_pos zero_lt_one hp' simpa [eLpNorm_eq_lintegral_rpow_enorm hp_ne_zero hp_ne_top] using ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩ @[deprecated (since := "2025-02-04")] alias eLpNorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top := eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top end Top section Zero @[simp] theorem eLpNorm'_exponent_zero {f : Ξ± β†’ Ξ΅} : eLpNorm' f 0 ΞΌ = 1 := by rw [eLpNorm', div_zero, ENNReal.rpow_zero] @[simp] theorem eLpNorm_exponent_zero {f : Ξ± β†’ Ξ΅} : eLpNorm f 0 ΞΌ = 0 := by simp [eLpNorm] @[simp] theorem memLp_zero_iff_aestronglyMeasurable [TopologicalSpace Ξ΅] {f : Ξ± β†’ Ξ΅} : MemLp f 0 ΞΌ ↔ AEStronglyMeasurable f ΞΌ := by simp [MemLp, eLpNorm_exponent_zero] @[deprecated (since := "2025-02-21")] alias memβ„’p_zero_iff_aestronglyMeasurable := memLp_zero_iff_aestronglyMeasurable section ENormedAddMonoid variable {Ξ΅ : Type*} [TopologicalSpace Ξ΅] [ENormedAddMonoid Ξ΅] @[simp] theorem eLpNorm'_zero (hp0_lt : 0 < q) : eLpNorm' (0 : Ξ± β†’ Ξ΅) q ΞΌ = 0 := by simp [eLpNorm'_eq_lintegral_enorm, hp0_lt] @[simp] theorem eLpNorm'_zero' (hq0_ne : q β‰  0) (hΞΌ : ΞΌ β‰  0) : eLpNorm' (0 : Ξ± β†’ Ξ΅) q ΞΌ = 0 := by rcases le_or_lt 0 q with hq0 | hq_neg Β· exact eLpNorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm) Β· simp [eLpNorm'_eq_lintegral_enorm, ENNReal.rpow_eq_zero_iff, hΞΌ, hq_neg] @[simp] theorem eLpNormEssSup_zero : eLpNormEssSup (0 : Ξ± β†’ Ξ΅) ΞΌ = 0 := by simp [eLpNormEssSup, ← bot_eq_zero', essSup_const_bot] @[simp] theorem eLpNorm_zero : eLpNorm (0 : Ξ± β†’ Ξ΅) p ΞΌ = 0 := by by_cases h0 : p = 0 Β· simp [h0] by_cases h_top : p = ∞ Β· simp only [h_top, eLpNorm_exponent_top, eLpNormEssSup_zero] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, ENNReal.toReal_pos h0 h_top] @[simp] theorem eLpNorm_zero' : eLpNorm (fun _ : Ξ± => (0 : Ξ΅)) p ΞΌ = 0 := eLpNorm_zero @[simp] lemma MemLp.zero : MemLp (0 : Ξ± β†’ Ξ΅) p ΞΌ := ⟨aestronglyMeasurable_zero, by rw [eLpNorm_zero]; exact ENNReal.coe_lt_top⟩ @[simp] lemma MemLp.zero' : MemLp (fun _ : Ξ± => (0 : Ξ΅)) p ΞΌ := MemLp.zero @[deprecated (since := "2025-02-21")] alias Memβ„’p.zero' := MemLp.zero' @[deprecated (since := "2025-01-21")] alias zero_memβ„’p := MemLp.zero @[deprecated (since := "2025-01-21")] alias zero_mem_β„’p := MemLp.zero' variable [MeasurableSpace Ξ±] theorem eLpNorm'_measure_zero_of_pos {f : Ξ± β†’ Ξ΅} (hq_pos : 0 < q) : eLpNorm' f q (0 : Measure Ξ±) = 0 := by simp [eLpNorm', hq_pos] theorem eLpNorm'_measure_zero_of_exponent_zero {f : Ξ± β†’ Ξ΅} : eLpNorm' f 0 (0 : Measure Ξ±) = 1 := by simp [eLpNorm'] theorem eLpNorm'_measure_zero_of_neg {f : Ξ± β†’ Ξ΅} (hq_neg : q < 0) : eLpNorm' f q (0 : Measure Ξ±) = ∞ := by simp [eLpNorm', hq_neg] end ENormedAddMonoid @[simp] theorem eLpNormEssSup_measure_zero {f : Ξ± β†’ Ξ΅} : eLpNormEssSup f (0 : Measure Ξ±) = 0 := by simp [eLpNormEssSup] @[simp] theorem eLpNorm_measure_zero {f : Ξ± β†’ Ξ΅} : eLpNorm f p (0 : Measure Ξ±) = 0 := by by_cases h0 : p = 0 Β· simp [h0] by_cases h_top : p = ∞ Β· simp [h_top] rw [← Ne] at h0 simp [eLpNorm_eq_eLpNorm' h0 h_top, eLpNorm', ENNReal.toReal_pos h0 h_top] section ContinuousENorm variable {Ξ΅ : Type*} [TopologicalSpace Ξ΅] [ContinuousENorm Ξ΅] @[simp] lemma memLp_measure_zero {f : Ξ± β†’ Ξ΅} : MemLp f p (0 : Measure Ξ±) := by simp [MemLp] @[deprecated (since := "2025-02-21")] alias memβ„’p_measure_zero := memLp_measure_zero end ContinuousENorm end Zero section Neg @[simp] theorem eLpNorm'_neg (f : Ξ± β†’ F) (q : ℝ) (ΞΌ : Measure Ξ±) : eLpNorm' (-f) q ΞΌ = eLpNorm' f q ΞΌ := by simp [eLpNorm'_eq_lintegral_enorm] @[simp] theorem eLpNorm_neg (f : Ξ± β†’ F) (p : ℝβ‰₯0∞) (ΞΌ : Measure Ξ±) : eLpNorm (-f) p ΞΌ = eLpNorm f p ΞΌ := by by_cases h0 : p = 0 Β· simp [h0] by_cases h_top : p = ∞ Β· simp [h_top, eLpNormEssSup_eq_essSup_enorm] simp [eLpNorm_eq_eLpNorm' h0 h_top] lemma eLpNorm_sub_comm (f g : Ξ± β†’ E) (p : ℝβ‰₯0∞) (ΞΌ : Measure Ξ±) : eLpNorm (f - g) p ΞΌ = eLpNorm (g - f) p ΞΌ := by simp [← eLpNorm_neg (f := f - g)] theorem MemLp.neg {f : Ξ± β†’ E} (hf : MemLp f p ΞΌ) : MemLp (-f) p ΞΌ := ⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩ @[deprecated (since := "2025-02-21")] alias Memβ„’p.neg := MemLp.neg
theorem memLp_neg_iff {f : Ξ± β†’ E} : MemLp (-f) p ΞΌ ↔ MemLp f p ΞΌ := ⟨fun h => neg_neg f β–Έ h.neg, MemLp.neg⟩
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
199
201
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.Basic import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} section LinearOrderedSemifield variable [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d e : Ξ±} {m n : β„€} /-! ### Relating two divisions. -/ @[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")] theorem div_le_div_right (hc : 0 < c) : a / c ≀ b / c ↔ a ≀ b := div_le_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")] theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")] theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := div_lt_div_iff_of_pos_left ha hb hc @[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")] theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≀ a / c ↔ c ≀ b := div_le_div_iff_of_pos_left ha hb hc @[deprecated div_lt_div_iffβ‚€ (since := "2024-11-12")] theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := div_lt_div_iffβ‚€ b0 d0 @[deprecated div_le_div_iffβ‚€ (since := "2024-11-12")] theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≀ c / d ↔ a * d ≀ c * b := div_le_div_iffβ‚€ b0 d0 @[deprecated div_le_divβ‚€ (since := "2024-11-12")] theorem div_le_div (hc : 0 ≀ c) (hac : a ≀ c) (hd : 0 < d) (hbd : d ≀ b) : a / b ≀ c / d := div_le_divβ‚€ hc hac hd hbd @[deprecated div_lt_divβ‚€ (since := "2024-11-12")] theorem div_lt_div (hac : a < c) (hbd : d ≀ b) (c0 : 0 ≀ c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€ hac hbd c0 d0 @[deprecated div_lt_divβ‚€' (since := "2024-11-12")] theorem div_lt_div' (hac : a ≀ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := div_lt_divβ‚€' hac hbd c0 d0 /-! ### Relating one division and involving `1` -/ @[bound] theorem div_le_self (ha : 0 ≀ a) (hb : 1 ≀ b) : a / b ≀ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb @[bound] theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb @[bound] theorem le_div_self (ha : 0 ≀ a) (hbβ‚€ : 0 < b) (hb₁ : b ≀ 1) : a ≀ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hbβ‚€ hb₁ theorem one_le_div (hb : 0 < b) : 1 ≀ a / b ↔ b ≀ a := by rw [le_div_iffβ‚€ hb, one_mul] theorem div_le_one (hb : 0 < b) : a / b ≀ 1 ↔ a ≀ b := by rw [div_le_iffβ‚€ hb, one_mul] theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iffβ‚€ hb, one_mul] theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iffβ‚€ hb, one_mul] theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≀ b ↔ 1 / b ≀ a := by simpa using inv_le_commβ‚€ ha hb theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_commβ‚€ ha hb theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≀ 1 / b ↔ b ≀ 1 / a := by simpa using le_inv_commβ‚€ ha hb theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_commβ‚€ ha hb @[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a β†’ 1 < a / b := (one_lt_div b0).mpr @[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b β†’ a / b < 1 := (div_lt_one b0).mpr /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≀ b) : 1 / b ≀ 1 / a := by simpa using inv_antiβ‚€ ha h theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iffβ‚€' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≀ 1 / b) : b ≀ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≀ 1 / b ↔ b ≀ a := div_le_div_iff_of_pos_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_iff_of_pos_left zero_lt_one ha hb theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one] theorem one_le_one_div (h1 : 0 < a) (h2 : a ≀ 1) : 1 ≀ 1 / a := by rwa [le_one_div (@zero_lt_one Ξ± _ _ _ _ _) h1, one_div_one] /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two theorem one_half_pos : (0 : Ξ±) < 1 / 2 := half_pos zero_lt_one @[simp] theorem half_le_self_iff : a / 2 ≀ a ↔ 0 ≀ a := by rw [div_le_iffβ‚€ (zero_lt_two' Ξ±), mul_two, le_add_iff_nonneg_left] @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iffβ‚€ (zero_lt_two' Ξ±), mul_two, lt_add_iff_pos_left] alias ⟨_, half_le_self⟩ := half_le_self_iff alias ⟨_, half_lt_self⟩ := half_lt_self_iff alias div_two_lt_of_pos := half_lt_self theorem one_half_lt_one : (1 / 2 : Ξ±) < 1 := half_lt_self zero_lt_one theorem two_inv_lt_one : (2⁻¹ : Ξ±) < 1 := (one_div _).symm.trans_lt one_half_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iffβ‚€, mul_two] theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iffβ‚€, mul_two] theorem add_thirds (a : Ξ±) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_leftβ‚€ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≀ d) (hc : 0 < c) : b * a ≀ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iffβ‚€ hc] theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≀ c / d) (he : 0 ≀ e) : a / (b * e) ≀ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) theorem exists_pos_mul_lt {a : Ξ±} (h : 0 < a) (b : Ξ±) : βˆƒ c : Ξ±, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iffβ‚€ this, div_div_cancelβ‚€ h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) theorem exists_pos_lt_mul {a : Ξ±} (h : 0 < a) (b : Ξ±) : βˆƒ c : Ξ±, 0 < c ∧ b < c * a := let ⟨c, hcβ‚€, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hcβ‚€, by rwa [← div_eq_inv_mul, lt_div_iffβ‚€ hcβ‚€]⟩ lemma monotone_div_right_of_nonneg (ha : 0 ≀ a) : Monotone (Β· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (Β· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : Monotone f) {c : Ξ±} (hc : 0 ≀ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf theorem StrictMono.div_const {Ξ² : Type*} [Preorder Ξ²] {f : Ξ² β†’ Ξ±} (hf : StrictMono f) {c : Ξ±} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered Ξ± where dense a₁ aβ‚‚ h := ⟨(a₁ + aβ‚‚) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + aβ‚‚) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + aβ‚‚) / 2 < (aβ‚‚ + aβ‚‚) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = aβ‚‚ := add_self_div_two aβ‚‚ ⟩ theorem min_div_div_right {c : Ξ±} (hc : 0 ≀ c) (a b : Ξ±) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm theorem max_div_div_right {c : Ξ±} (hc : 0 ≀ c) (a b : Ξ±) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm theorem one_div_strictAntiOn : StrictAntiOn (fun x : Ξ± => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≀ a) {m n : β„•} (mn : m ≀ n) : 1 / a ^ n ≀ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_right_monoβ‚€ a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : β„•} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_rightβ‚€ a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ theorem one_div_pow_anti (a1 : 1 ≀ a) : Antitone fun n : β„• => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β„• => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 theorem inv_strictAntiOn : StrictAntiOn (fun x : Ξ± => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_invβ‚€ hy hx).2 xy theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≀ a) {m n : β„•} (mn : m ≀ n) : (a ^ n)⁻¹ ≀ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : β„•} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp theorem inv_pow_anti (a1 : 1 ≀ a) : Antitone fun n : β„• => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : β„• => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 theorem le_iff_forall_one_lt_le_mulβ‚€ {Ξ± : Type*} [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b : Ξ±} (hb : 0 ≀ b) : a ≀ b ↔ βˆ€ Ξ΅, 1 < Ξ΅ β†’ a ≀ b * Ξ΅ := by refine ⟨fun h _ hΞ΅ ↦ h.trans <| le_mul_of_one_le_right hb hΞ΅.le, fun h ↦ ?_⟩ obtain rfl|hb := hb.eq_or_lt Β· simp_rw [zero_mul] at h exact h 2 one_lt_two refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_ convert h (x / b) ((one_lt_div hb).mpr hbx) rw [mul_div_cancelβ‚€ _ hb.ne'] /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) Β· exact (OrderIso.mulLeftβ‚€ _ ha).isGLB_image'.2 hs Β· simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton theorem IsGLB.mul_right {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha end LinearOrderedSemifield section variable [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b c d : Ξ±} {n : β„€} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] theorem div_nonneg_iff : 0 ≀ a / b ↔ 0 ≀ a ∧ 0 ≀ b ∨ a ≀ 0 ∧ b ≀ 0 := by simp [division_def, mul_nonneg_iff] theorem div_nonpos_iff : a / b ≀ 0 ↔ 0 ≀ a ∧ b ≀ 0 ∨ a ≀ 0 ∧ 0 ≀ b := by simp [division_def, mul_nonpos_iff] theorem div_nonneg_of_nonpos (ha : a ≀ 0) (hb : b ≀ 0) : 0 ≀ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≀ a ↔ a * c ≀ b := ⟨fun h => div_mul_cancelβ‚€ b (ne_of_lt hc) β–Έ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ β‰₯ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≀ a ↔ c * a ≀ b := by rw [mul_comm, div_le_iff_of_neg hc] theorem le_div_iff_of_neg (hc : c < 0) : a ≀ b / c ↔ b ≀ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iffβ‚€ (neg_pos.2 hc), neg_mul] theorem le_div_iff_of_neg' (hc : c < 0) : a ≀ b / c ↔ b ≀ c * a := by rw [mul_comm, le_div_iff_of_neg hc] theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] theorem div_le_one_of_ge (h : b ≀ a) (hb : b ≀ 0) : a / b ≀ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_leβ‚€ (neg_le_neg h) (neg_nonneg_of_nonpos hb) /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≀ b⁻¹ ↔ b ≀ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≀ b ↔ b⁻¹ ≀ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≀ b⁻¹ ↔ b ≀ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_invβ‚€ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≀ b Β· exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha Β· simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≀ b Β· exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha Β· simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi (Ξ± := Ξ±) exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio (Ξ± := Ξ±) exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x : Ξ± ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≀ 0) (h : b ≀ a) : a / c ≀ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≀ b / c ↔ b ≀ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≀ a / b ↔ a ≀ b := by rw [le_div_iff_of_neg hb, one_mul] theorem div_le_one_of_neg (hb : b < 0) : a / b ≀ 1 ↔ b ≀ a := by rw [div_le_iff_of_neg hb, one_mul] theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≀ b ↔ 1 / b ≀ a := by simpa using inv_le_of_neg ha hb theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≀ 1 / b ↔ b ≀ 1 / a := by simpa using le_inv_of_neg ha hb theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, one_lt_div_of_neg] Β· simp [lt_irrefl, zero_le_one] Β· simp [hb, hb.not_lt, one_lt_div] theorem one_le_div_iff : 1 ≀ a / b ↔ 0 < b ∧ b ≀ a ∨ b < 0 ∧ a ≀ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, one_le_div_of_neg] Β· simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] Β· simp [hb, hb.not_lt, one_le_div] theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] Β· simp [zero_lt_one] Β· simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] theorem div_le_one_iff : a / b ≀ 1 ↔ 0 < b ∧ a ≀ b ∨ b = 0 ∨ b < 0 ∧ b ≀ a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) Β· simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] Β· simp [zero_le_one] Β· simp [hb, hb.not_lt, div_le_one, hb.ne.symm] /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≀ b) : 1 / b ≀ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≀ 1 / b) : b ≀ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≀ 1 / b ↔ b ≀ a := by simpa [one_div] using inv_le_inv_of_neg ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha) theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 := suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_lt_one_div_of_neg_of_lt h1 h2 theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≀ a) : 1 / a ≀ -1 := suffices 1 / a ≀ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_le_one_div_of_neg_of_le h1 h2 /-! ### Results about halving -/ theorem sub_self_div_two (a : Ξ±) : a - a / 2 = a / 2 := by suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this rw [add_sub_cancel_right] theorem div_two_sub_self (a : Ξ±) : a / 2 - a = -(a / 2) := by suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this rw [sub_add_eq_sub_sub, sub_self, zero_sub] theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_iff_of_pos_right (zero_lt_two' Ξ±)] /-- An inequality involving `2`. -/ theorem sub_one_div_inv_le_two (a2 : 2 ≀ a) : (1 - 1 / a)⁻¹ ≀ 2 := by -- Take inverses on both sides to obtain `2⁻¹ ≀ 1 - 1 / a` refine (inv_antiβ‚€ (inv_pos.2 <| zero_lt_two' Ξ±) ?_).trans_eq (inv_inv (2 : Ξ±)) -- move `1 / a` to the left and `2⁻¹` to the right. rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le] -- take inverses on both sides and use the assumption `2 ≀ a`. convert (one_div a).le.trans (inv_antiβ‚€ zero_lt_two a2) using 1 -- show `1 - 1 / 2 = 1 / 2`. rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancelβ‚€ two_ne_zero] /-! ### Results about `IsLUB` -/ -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_left {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsLUB s b) : IsLUB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) Β· exact (OrderIso.mulLeftβ‚€ _ ha).isLUB_image'.2 hs Β· simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isLUB_singleton -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_right {s : Set Ξ±} (ha : 0 ≀ a) (hs : IsLUB s b) : IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha /-! ### Miscellaneous lemmas -/ theorem mul_sub_mul_div_mul_neg_iff (hc : c β‰  0) (hd : d β‰  0) : (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero] theorem mul_sub_mul_div_mul_nonpos_iff (hc : c β‰  0) (hd : d β‰  0) : (a * d - b * c) / (c * d) ≀ 0 ↔ a / c ≀ b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos] alias ⟨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_neg⟩ := mul_sub_mul_div_mul_neg_iff alias ⟨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonpos⟩ := mul_sub_mul_div_mul_nonpos_iff theorem exists_add_lt_and_pos_of_lt (h : b < a) : βˆƒ c, b + c < a ∧ 0 < c := ⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩ theorem le_of_forall_sub_le (h : βˆ€ Ξ΅ > 0, b - Ξ΅ ≀ a) : b ≀ a := by contrapose! h simpa only [@and_comm ((0 : Ξ±) < _), lt_sub_iff_add_lt, gt_iff_lt] using exists_add_lt_and_pos_of_lt h private lemma exists_lt_mul_left_of_nonneg {a b c : Ξ±} (ha : 0 ≀ a) (hc : 0 ≀ c) (h : c < a * b) : βˆƒ a' ∈ Set.Ico 0 a, c < a' * b := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha obtain ⟨a', ha', a_a'⟩ := exists_between ((div_lt_iffβ‚€ hb).2 h) exact ⟨a', ⟨(div_nonneg hc hb.le).trans ha'.le, a_a'⟩, (div_lt_iffβ‚€ hb).1 ha'⟩ private lemma exists_lt_mul_right_of_nonneg {a b c : Ξ±} (ha : 0 ≀ a) (hc : 0 ≀ c) (h : c < a * b) : βˆƒ b' ∈ Set.Ico 0 b, c < a * b' := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha simp_rw [mul_comm a] at h ⊒ exact exists_lt_mul_left_of_nonneg hb.le hc h private lemma exists_mul_left_ltβ‚€ {a b c : Ξ±} (hc : a * b < c) : βˆƒ a' > a, a' * b < c := by rcases le_or_lt b 0 with hb | hb Β· obtain ⟨a', ha'⟩ := exists_gt a exact ⟨a', ha', hc.trans_le' (antitone_mul_right hb ha'.le)⟩ Β· obtain ⟨a', ha', hc'⟩ := exists_between ((lt_div_iffβ‚€ hb).2 hc) exact ⟨a', ha', (lt_div_iffβ‚€ hb).1 hc'⟩ private lemma exists_mul_right_ltβ‚€ {a b c : Ξ±} (hc : a * b < c) : βˆƒ b' > b, a * b' < c := by simp_rw [mul_comm a] at hc ⊒; exact exists_mul_left_ltβ‚€ hc lemma le_mul_of_forall_ltβ‚€ {a b c : Ξ±} (h : βˆ€ a' > a, βˆ€ b' > b, c ≀ a' * b') : c ≀ a * b := by refine le_of_forall_gt_imp_ge_of_dense fun d hd ↦ ?_ obtain ⟨a', ha', hd⟩ := exists_mul_left_ltβ‚€ hd obtain ⟨b', hb', hd⟩ := exists_mul_right_ltβ‚€ hd exact (h a' ha' b' hb').trans hd.le lemma mul_le_of_forall_lt_of_nonneg {a b c : Ξ±} (ha : 0 ≀ a) (hc : 0 ≀ c) (h : βˆ€ a' β‰₯ 0, a' < a β†’ βˆ€ b' β‰₯ 0, b' < b β†’ a' * b' ≀ c) : a * b ≀ c := by refine le_of_forall_lt_imp_le_of_dense fun d d_ab ↦ ?_ rcases lt_or_le d 0 with hd | hd Β· exact hd.le.trans hc obtain ⟨a', ha', d_ab⟩ := exists_lt_mul_left_of_nonneg ha hd d_ab obtain ⟨b', hb', d_ab⟩ := exists_lt_mul_right_of_nonneg ha'.1 hd d_ab exact d_ab.le.trans (h a' ha'.1 ha'.2 b' hb'.1 hb'.2) theorem mul_self_inj_of_nonneg (a0 : 0 ≀ a) (b0 : 0 ≀ b) : a * a = b * b ↔ a = b := mul_self_eq_mul_self_iff.trans <| or_iff_left_of_imp fun h => by subst a have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0 rw [this, neg_zero] theorem min_div_div_right_of_nonpos (hc : c ≀ 0) (a b : Ξ±) : min (a / c) (b / c) = max a b / c := Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc theorem max_div_div_right_of_nonpos (hc : c ≀ 0) (a b : Ξ±) : max (a / c) (b / c) = min a b / c := Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc theorem abs_inv (a : Ξ±) : |a⁻¹| = |a|⁻¹ := map_invβ‚€ (absHom : Ξ± β†’*β‚€ Ξ±) a theorem abs_div (a b : Ξ±) : |a / b| = |a| / |b| := map_divβ‚€ (absHom : Ξ± β†’*β‚€ Ξ±) a b theorem abs_one_div (a : Ξ±) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one] theorem uniform_continuous_npow_on_bounded (B : Ξ±) {Ξ΅ : Ξ±} (hΞ΅ : 0 < Ξ΅) (n : β„•) : βˆƒ Ξ΄ > 0, βˆ€ q r : Ξ±, |r| ≀ B β†’ |q - r| ≀ Ξ΄ β†’ |q ^ n - r ^ n| < Ξ΅ := by wlog B_pos : 0 < B generalizing B Β· have ⟨δ, Ξ΄_pos, cont⟩ := this 1 zero_lt_one exact ⟨δ, Ξ΄_pos, fun q r hr ↦ cont q r (hr.trans ((le_of_not_lt B_pos).trans zero_le_one))⟩ have pos : 0 < 1 + ↑n * (B + 1) ^ (n - 1) := zero_lt_one.trans_le <| le_add_of_nonneg_right <| mul_nonneg n.cast_nonneg <| (pow_pos (B_pos.trans <| lt_add_of_pos_right _ zero_lt_one) _).le refine ⟨min 1 (Ξ΅ / (1 + n * (B + 1) ^ (n - 1))), lt_min zero_lt_one (div_pos hΞ΅ pos), fun q r hr hqr ↦ (abs_pow_sub_pow_le ..).trans_lt ?_⟩ rw [le_inf_iff, le_div_iffβ‚€ pos, mul_one_add, ← mul_assoc] at hqr obtain h | h := (abs_nonneg (q - r)).eq_or_lt Β· simpa only [← h, zero_mul] using hΞ΅ refine (lt_of_le_of_lt ?_ <| lt_add_of_pos_left _ h).trans_le hqr.2 refine mul_le_mul_of_nonneg_left (pow_le_pow_leftβ‚€ ((abs_nonneg _).trans le_sup_left) ?_ _) (mul_nonneg (abs_nonneg _) n.cast_nonneg) refine max_le ?_ (hr.trans <| le_add_of_nonneg_right zero_le_one) exact add_sub_cancel r q β–Έ (abs_add_le ..).trans (add_le_add hr hqr.1) end namespace Mathlib.Meta.Positivity open Lean Meta Qq Function section LinearOrderedSemifield variable {Ξ± : Type*} [Semifield Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] {a b : Ξ±} private lemma div_nonneg_of_pos_of_nonneg (ha : 0 < a) (hb : 0 ≀ b) : 0 ≀ a / b := div_nonneg ha.le hb private lemma div_nonneg_of_nonneg_of_pos (ha : 0 ≀ a) (hb : 0 < b) : 0 ≀ a / b := div_nonneg ha hb.le omit [IsStrictOrderedRing Ξ±] in private lemma div_ne_zero_of_pos_of_ne_zero (ha : 0 < a) (hb : b β‰  0) : a / b β‰  0 := div_ne_zero ha.ne' hb omit [IsStrictOrderedRing Ξ±] in private lemma div_ne_zero_of_ne_zero_of_pos (ha : a β‰  0) (hb : 0 < b) : a / b β‰  0 := div_ne_zero ha hb.ne' private lemma zpow_zero_pos (a : Ξ±) : 0 < a ^ (0 : β„€) := zero_lt_one.trans_eq (zpow_zero a).symm end LinearOrderedSemifield /-- The `positivity` extension which identifies expressions of the form `a / b`, such that `positivity` successfully recognises both `a` and `b`. -/ @[positivity _ / _] def evalDiv : PositivityExt where eval {u Ξ±} zΞ± pΞ± e := do let .app (.app (f : Q($Ξ± β†’ $Ξ± β†’ $Ξ±)) (a : Q($Ξ±))) (b : Q($Ξ±)) ← withReducible (whnf e) | throwError "not /" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(Semifield $Ξ±) let _a ← synthInstanceQ q(LinearOrder $Ξ±) let _a ← synthInstanceQ q(IsStrictOrderedRing $Ξ±) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HDiv.hDiv) let ra ← core zΞ± pΞ± a; let rb ← core zΞ± pΞ± b match ra, rb with | .positive pa, .positive pb => pure (.positive q(div_pos $pa $pb)) | .positive pa, .nonnegative pb => pure (.nonnegative q(div_nonneg_of_pos_of_nonneg $pa $pb)) | .nonnegative pa, .positive pb => pure (.nonnegative q(div_nonneg_of_nonneg_of_pos $pa $pb)) | .nonnegative pa, .nonnegative pb => pure (.nonnegative q(div_nonneg $pa $pb)) | .positive pa, .nonzero pb => pure (.nonzero q(div_ne_zero_of_pos_of_ne_zero $pa $pb)) | .nonzero pa, .positive pb => pure (.nonzero q(div_ne_zero_of_ne_zero_of_pos $pa $pb)) | .nonzero pa, .nonzero pb => pure (.nonzero q(div_ne_zero $pa $pb)) | _, _ => pure .none /-- The `positivity` extension which identifies expressions of the form `a⁻¹`, such that `positivity` successfully recognises `a`. -/ @[positivity _⁻¹] def evalInv : PositivityExt where eval {u Ξ±} zΞ± pΞ± e := do let .app (f : Q($Ξ± β†’ $Ξ±)) (a : Q($Ξ±)) ← withReducible (whnf e) | throwError "not ⁻¹" let _e_eq : $e =Q $f $a := ⟨⟩ let _a ← synthInstanceQ q(Semifield $Ξ±) let _a ← synthInstanceQ q(LinearOrder $Ξ±) let _a ← synthInstanceQ q(IsStrictOrderedRing $Ξ±) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(Inv.inv) let ra ← core zΞ± pΞ± a match ra with | .positive pa => pure (.positive q(inv_pos_of_pos $pa)) | .nonnegative pa => pure (.nonnegative q(inv_nonneg_of_nonneg $pa)) | .nonzero pa => pure (.nonzero q(inv_ne_zero $pa)) | .none => pure .none /-- The `positivity` extension which identifies expressions of the form `a ^ (0:β„€)`. -/ @[positivity _ ^ (0 : β„€), Pow.pow _ (0 : β„€)] def evalPowZeroInt : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do let .app (.app _ (a : Q($Ξ±))) _ ← withReducible (whnf e) | throwError "not ^" let _a ← synthInstanceQ q(Semifield $Ξ±) let _a ← synthInstanceQ q(LinearOrder $Ξ±) let _a ← synthInstanceQ q(IsStrictOrderedRing $Ξ±) assumeInstancesCommute let ⟨_a⟩ ← Qq.assertDefEqQ q($e) q($a ^ (0 : β„€)) pure (.positive q(zpow_zero_pos $a)) end Mathlib.Meta.Positivity
Mathlib/Algebra/Order/Field/Basic.lean
951
953
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, YaΓ«l Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) βŠ” (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) βŠ“ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a βˆ† b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ assert_not_exists RelIso open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} {Ο€ : ΞΉ β†’ Type*} /-- The symmetric difference operator on a type with `βŠ”` and `\` is `(A \ B) βŠ” (B \ A)`. -/ def symmDiff [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : Ξ± := a \ b βŠ” b \ a /-- The Heyting bi-implication is `(b ⇨ a) βŠ“ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : Ξ± := (b ⇨ a) βŠ“ (a ⇨ b) /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " βˆ† " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : a βˆ† b = a \ b βŠ” b \ a := rfl theorem bihimp_def [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : a ⇔ b = (b ⇨ a) βŠ“ (a ⇨ b) := rfl theorem symmDiff_eq_Xor' (p q : Prop) : p βˆ† q = Xor' p q := rfl @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := iff_iff_implies_and_implies.symm.trans Iff.comm @[simp] theorem Bool.symmDiff_eq_xor : βˆ€ p q : Bool, p βˆ† q = xor p q := by decide section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_symmDiff : toDual (a βˆ† b) = toDual a ⇔ toDual b := rfl @[simp] theorem ofDual_bihimp (a b : Ξ±α΅’α΅ˆ) : ofDual (a ⇔ b) = ofDual a βˆ† ofDual b := rfl theorem symmDiff_comm : a βˆ† b = b βˆ† a := by simp only [symmDiff, sup_comm] instance symmDiff_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· βˆ† Β·) := ⟨symmDiff_comm⟩ @[simp] theorem symmDiff_self : a βˆ† a = βŠ₯ := by rw [symmDiff, sup_idem, sdiff_self] @[simp] theorem symmDiff_bot : a βˆ† βŠ₯ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] @[simp] theorem bot_symmDiff : βŠ₯ βˆ† a = a := by rw [symmDiff_comm, symmDiff_bot] @[simp] theorem symmDiff_eq_bot {a b : Ξ±} : a βˆ† b = βŠ₯ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] theorem symmDiff_of_le {a b : Ξ±} (h : a ≀ b) : a βˆ† b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] theorem symmDiff_of_ge {a b : Ξ±} (h : b ≀ a) : a βˆ† b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] theorem symmDiff_le {a b c : Ξ±} (ha : a ≀ b βŠ” c) (hb : b ≀ a βŠ” c) : a βˆ† b ≀ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb theorem symmDiff_le_iff {a b c : Ξ±} : a βˆ† b ≀ c ↔ a ≀ b βŠ” c ∧ b ≀ a βŠ” c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] @[simp] theorem symmDiff_le_sup {a b : Ξ±} : a βˆ† b ≀ a βŠ” b := sup_le_sup sdiff_le sdiff_le theorem symmDiff_eq_sup_sdiff_inf : a βˆ† b = (a βŠ” b) \ (a βŠ“ b) := by simp [sup_sdiff, symmDiff] theorem Disjoint.symmDiff_eq_sup {a b : Ξ±} (h : Disjoint a b) : a βˆ† b = a βŠ” b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] theorem symmDiff_sdiff : a βˆ† b \ c = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] @[simp] theorem symmDiff_sdiff_inf : a βˆ† b \ (a βŠ“ b) = a βˆ† b := by rw [symmDiff_sdiff] simp [symmDiff] @[simp] theorem symmDiff_sdiff_eq_sup : a βˆ† (b \ a) = a βŠ” b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) βˆ† b = a βŠ” b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] @[simp] theorem symmDiff_sup_inf : a βˆ† b βŠ” a βŠ“ b = a βŠ” b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) Β· rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup Β· rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup @[simp] theorem inf_sup_symmDiff : a βŠ“ b βŠ” a βˆ† b = a βŠ” b := by rw [sup_comm, symmDiff_sup_inf] @[simp] theorem symmDiff_symmDiff_inf : a βˆ† b βˆ† (a βŠ“ b) = a βŠ” b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] @[simp] theorem inf_symmDiff_symmDiff : (a βŠ“ b) βˆ† (a βˆ† b) = a βŠ” b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] theorem symmDiff_triangle : a βˆ† c ≀ a βˆ† b βŠ” b βˆ† c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] theorem le_symmDiff_sup_right (a b : Ξ±) : a ≀ (a βˆ† b) βŠ” b := by convert symmDiff_triangle a b βŠ₯ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : Ξ±) : b ≀ (a βˆ† b) βŠ” a := symmDiff_comm a b β–Έ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a βˆ† toDual b := rfl @[simp] theorem ofDual_symmDiff (a b : Ξ±α΅’α΅ˆ) : ofDual (a βˆ† b) = ofDual a ⇔ ofDual b := rfl theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(Β· ⇔ Β·), inf_comm] instance bihimp_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· ⇔ Β·) := ⟨bihimp_comm⟩ @[simp] theorem bihimp_self : a ⇔ a = ⊀ := by rw [bihimp, inf_idem, himp_self] @[simp] theorem bihimp_top : a ⇔ ⊀ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] @[simp] theorem top_bihimp : ⊀ ⇔ a = a := by rw [bihimp_comm, bihimp_top] @[simp] theorem bihimp_eq_top {a b : Ξ±} : a ⇔ b = ⊀ ↔ a = b := @symmDiff_eq_bot Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_of_le {a b : Ξ±} (h : a ≀ b) : a ⇔ b = b ⇨ a := by rw [bihimp, himp_eq_top_iff.2 h, inf_top_eq] theorem bihimp_of_ge {a b : Ξ±} (h : b ≀ a) : a ⇔ b = a ⇨ b := by rw [bihimp, himp_eq_top_iff.2 h, top_inf_eq] theorem le_bihimp {a b c : Ξ±} (hb : a βŠ“ b ≀ c) (hc : a βŠ“ c ≀ b) : a ≀ b ⇔ c := le_inf (le_himp_iff.2 hc) <| le_himp_iff.2 hb theorem le_bihimp_iff {a b c : Ξ±} : a ≀ b ⇔ c ↔ a βŠ“ b ≀ c ∧ a βŠ“ c ≀ b := by simp_rw [bihimp, le_inf_iff, le_himp_iff, and_comm] @[simp] theorem inf_le_bihimp {a b : Ξ±} : a βŠ“ b ≀ a ⇔ b := inf_le_inf le_himp le_himp theorem bihimp_eq_inf_himp_inf : a ⇔ b = a βŠ” b ⇨ a βŠ“ b := by simp [himp_inf_distrib, bihimp] theorem Codisjoint.bihimp_eq_inf {a b : Ξ±} (h : Codisjoint a b) : a ⇔ b = a βŠ“ b := by rw [bihimp, h.himp_eq_left, h.himp_eq_right] theorem himp_bihimp : a ⇨ b ⇔ c = (a βŠ“ c ⇨ b) βŠ“ (a βŠ“ b ⇨ c) := by rw [bihimp, himp_inf_distrib, himp_himp, himp_himp] @[simp] theorem sup_himp_bihimp : a βŠ” b ⇨ a ⇔ b = a ⇔ b := by rw [himp_bihimp] simp [bihimp] @[simp] theorem bihimp_himp_eq_inf : a ⇔ (a ⇨ b) = a βŠ“ b := @symmDiff_sdiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_eq_inf : (b ⇨ a) ⇔ b = a βŠ“ b := @sdiff_symmDiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_inf_sup : a ⇔ b βŠ“ (a βŠ” b) = a βŠ“ b := @symmDiff_sup_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem sup_inf_bihimp : (a βŠ” b) βŠ“ a ⇔ b = a βŠ“ b := @inf_sup_symmDiff Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_bihimp_sup : a ⇔ b ⇔ (a βŠ” b) = a βŠ“ b := @symmDiff_symmDiff_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem sup_bihimp_bihimp : (a βŠ” b) ⇔ (a ⇔ b) = a βŠ“ b := @inf_symmDiff_symmDiff Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_triangle : a ⇔ b βŠ“ b ⇔ c ≀ a ⇔ c := @symmDiff_triangle Ξ±α΅’α΅ˆ _ _ _ _ end GeneralizedHeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra Ξ±] (a : Ξ±) @[simp] theorem symmDiff_top' : a βˆ† ⊀ = οΏ’a := by simp [symmDiff] @[simp] theorem top_symmDiff' : ⊀ βˆ† a = οΏ’a := by simp [symmDiff] @[simp] theorem hnot_symmDiff_self : (οΏ’a) βˆ† a = ⊀ := by rw [eq_top_iff, symmDiff, hnot_sdiff, sup_sdiff_self] exact Codisjoint.top_le codisjoint_hnot_left @[simp] theorem symmDiff_hnot_self : a βˆ† (οΏ’a) = ⊀ := by rw [symmDiff_comm, hnot_symmDiff_self] theorem IsCompl.symmDiff_eq_top {a b : Ξ±} (h : IsCompl a b) : a βˆ† b = ⊀ := by rw [h.eq_hnot, hnot_symmDiff_self] end CoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra Ξ±] (a : Ξ±) @[simp] theorem bihimp_bot : a ⇔ βŠ₯ = aᢜ := by simp [bihimp] @[simp] theorem bot_bihimp : βŠ₯ ⇔ a = aᢜ := by simp [bihimp] @[simp] theorem compl_bihimp_self : aᢜ ⇔ a = βŠ₯ := @hnot_symmDiff_self Ξ±α΅’α΅ˆ _ _ @[simp] theorem bihimp_hnot_self : a ⇔ aᢜ = βŠ₯ := @symmDiff_hnot_self Ξ±α΅’α΅ˆ _ _ theorem IsCompl.bihimp_eq_bot {a b : Ξ±} (h : IsCompl a b) : a ⇔ b = βŠ₯ := by rw [h.eq_compl, compl_bihimp_self] end HeytingAlgebra section GeneralizedBooleanAlgebra variable [GeneralizedBooleanAlgebra Ξ±] (a b c d : Ξ±) @[simp] theorem sup_sdiff_symmDiff : (a βŠ” b) \ a βˆ† b = a βŠ“ b := sdiff_eq_symm inf_le_sup (by rw [symmDiff_eq_sup_sdiff_inf]) theorem disjoint_symmDiff_inf : Disjoint (a βˆ† b) (a βŠ“ b) := by rw [symmDiff_eq_sup_sdiff_inf] exact disjoint_sdiff_self_left theorem inf_symmDiff_distrib_left : a βŠ“ b βˆ† c = (a βŠ“ b) βˆ† (a βŠ“ c) := by rw [symmDiff_eq_sup_sdiff_inf, inf_sdiff_distrib_left, inf_sup_left, inf_inf_distrib_left, symmDiff_eq_sup_sdiff_inf] theorem inf_symmDiff_distrib_right : a βˆ† b βŠ“ c = (a βŠ“ c) βˆ† (b βŠ“ c) := by simp_rw [inf_comm _ c, inf_symmDiff_distrib_left] theorem sdiff_symmDiff : c \ a βˆ† b = c βŠ“ a βŠ“ b βŠ” c \ a βŠ“ c \ b := by simp only [(Β· βˆ† Β·), sdiff_sdiff_sup_sdiff'] theorem sdiff_symmDiff' : c \ a βˆ† b = c βŠ“ a βŠ“ b βŠ” c \ (a βŠ” b) := by rw [sdiff_symmDiff, sdiff_sup] @[simp] theorem symmDiff_sdiff_left : a βˆ† b \ a = b \ a := by rw [symmDiff_def, sup_sdiff, sdiff_idem, sdiff_sdiff_self, bot_sup_eq] @[simp] theorem symmDiff_sdiff_right : a βˆ† b \ b = a \ b := by rw [symmDiff_comm, symmDiff_sdiff_left] @[simp] theorem sdiff_symmDiff_left : a \ a βˆ† b = a βŠ“ b := by simp [sdiff_symmDiff] @[simp] theorem sdiff_symmDiff_right : b \ a βˆ† b = a βŠ“ b := by rw [symmDiff_comm, inf_comm, sdiff_symmDiff_left] theorem symmDiff_eq_sup : a βˆ† b = a βŠ” b ↔ Disjoint a b := by refine ⟨fun h => ?_, Disjoint.symmDiff_eq_sup⟩ rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq_self_iff_disjoint] at h exact h.of_disjoint_inf_of_le le_sup_left @[simp] theorem le_symmDiff_iff_left : a ≀ a βˆ† b ↔ Disjoint a b := by refine ⟨fun h => ?_, fun h => h.symmDiff_eq_sup.symm β–Έ le_sup_left⟩ rw [symmDiff_eq_sup_sdiff_inf] at h exact disjoint_iff_inf_le.mpr (le_sdiff_right.1 <| inf_le_of_left_le h).le @[simp] theorem le_symmDiff_iff_right : b ≀ a βˆ† b ↔ Disjoint a b := by rw [symmDiff_comm, le_symmDiff_iff_left, disjoint_comm] theorem symmDiff_symmDiff_left : a βˆ† b βˆ† c = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := calc a βˆ† b βˆ† c = a βˆ† b \ c βŠ” c \ a βˆ† b := symmDiff_def _ _ _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” (c \ (a βŠ” b) βŠ” c βŠ“ a βŠ“ b) := by { rw [sdiff_symmDiff', sup_comm (c βŠ“ a βŠ“ b), symmDiff_sdiff] } _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := by ac_rfl theorem symmDiff_symmDiff_right : a βˆ† (b βˆ† c) = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := calc a βˆ† (b βˆ† c) = a \ b βˆ† c βŠ” b βˆ† c \ a := symmDiff_def _ _ _ = a \ (b βŠ” c) βŠ” a βŠ“ b βŠ“ c βŠ” (b \ (c βŠ” a) βŠ” c \ (b βŠ” a)) := by { rw [sdiff_symmDiff', sup_comm (a βŠ“ b βŠ“ c), symmDiff_sdiff] } _ = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) βŠ” c \ (a βŠ” b) βŠ” a βŠ“ b βŠ“ c := by ac_rfl theorem symmDiff_assoc : a βˆ† b βˆ† c = a βˆ† (b βˆ† c) := by rw [symmDiff_symmDiff_left, symmDiff_symmDiff_right] instance symmDiff_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· βˆ† Β·) := ⟨symmDiff_assoc⟩ theorem symmDiff_left_comm : a βˆ† (b βˆ† c) = b βˆ† (a βˆ† c) := by simp_rw [← symmDiff_assoc, symmDiff_comm] theorem symmDiff_right_comm : a βˆ† b βˆ† c = a βˆ† c βˆ† b := by simp_rw [symmDiff_assoc, symmDiff_comm] theorem symmDiff_symmDiff_symmDiff_comm : a βˆ† b βˆ† (c βˆ† d) = a βˆ† c βˆ† (b βˆ† d) := by simp_rw [symmDiff_assoc, symmDiff_left_comm] @[simp] theorem symmDiff_symmDiff_cancel_left : a βˆ† (a βˆ† b) = b := by simp [← symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_cancel_right : b βˆ† a βˆ† a = b := by simp [symmDiff_assoc] @[simp] theorem symmDiff_symmDiff_self' : a βˆ† b βˆ† a = b := by rw [symmDiff_comm, symmDiff_symmDiff_cancel_left] theorem symmDiff_left_involutive (a : Ξ±) : Involutive (Β· βˆ† a) := symmDiff_symmDiff_cancel_right _ theorem symmDiff_right_involutive (a : Ξ±) : Involutive (a βˆ† Β·) := symmDiff_symmDiff_cancel_left _ theorem symmDiff_left_injective (a : Ξ±) : Injective (Β· βˆ† a) := Function.Involutive.injective (symmDiff_left_involutive a) theorem symmDiff_right_injective (a : Ξ±) : Injective (a βˆ† Β·) := Function.Involutive.injective (symmDiff_right_involutive _) theorem symmDiff_left_surjective (a : Ξ±) : Surjective (Β· βˆ† a) := Function.Involutive.surjective (symmDiff_left_involutive _) theorem symmDiff_right_surjective (a : Ξ±) : Surjective (a βˆ† Β·) := Function.Involutive.surjective (symmDiff_right_involutive _) variable {a b c} @[simp] theorem symmDiff_left_inj : a βˆ† b = c βˆ† b ↔ a = c := (symmDiff_left_injective _).eq_iff @[simp] theorem symmDiff_right_inj : a βˆ† b = a βˆ† c ↔ b = c := (symmDiff_right_injective _).eq_iff @[simp] theorem symmDiff_eq_left : a βˆ† b = a ↔ b = βŠ₯ := calc a βˆ† b = a ↔ a βˆ† b = a βˆ† βŠ₯ := by rw [symmDiff_bot] _ ↔ b = βŠ₯ := by rw [symmDiff_right_inj] @[simp] theorem symmDiff_eq_right : a βˆ† b = b ↔ a = βŠ₯ := by rw [symmDiff_comm, symmDiff_eq_left] protected theorem Disjoint.symmDiff_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a βˆ† b) c := by rw [symmDiff_eq_sup_sdiff_inf] exact (ha.sup_left hb).disjoint_sdiff_left protected theorem Disjoint.symmDiff_right (ha : Disjoint a b) (hb : Disjoint a c) : Disjoint a (b βˆ† c) := (ha.symm.symmDiff_left hb.symm).symm theorem symmDiff_eq_iff_sdiff_eq (ha : a ≀ c) : a βˆ† b = c ↔ c \ a = b := by rw [← symmDiff_of_le ha] exact ((symmDiff_right_involutive a).toPerm _).apply_eq_iff_eq_symm_apply.trans eq_comm end GeneralizedBooleanAlgebra section BooleanAlgebra variable [BooleanAlgebra Ξ±] (a b c d : Ξ±) /-! `CogeneralizedBooleanAlgebra` isn't actually a typeclass, but the lemmas in here are dual to the `GeneralizedBooleanAlgebra` ones -/ section CogeneralizedBooleanAlgebra @[simp] theorem inf_himp_bihimp : a ⇔ b ⇨ a βŠ“ b = a βŠ” b := @sup_sdiff_symmDiff Ξ±α΅’α΅ˆ _ _ _ theorem codisjoint_bihimp_sup : Codisjoint (a ⇔ b) (a βŠ” b) := @disjoint_symmDiff_inf Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_left : a ⇨ a ⇔ b = a ⇨ b := @symmDiff_sdiff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem himp_bihimp_right : b ⇨ a ⇔ b = b ⇨ a := @symmDiff_sdiff_right Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_himp_left : a ⇔ b ⇨ a = a βŠ” b := @sdiff_symmDiff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_himp_right : a ⇔ b ⇨ b = a βŠ” b := @sdiff_symmDiff_right Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_eq_inf : a ⇔ b = a βŠ“ b ↔ Codisjoint a b := @symmDiff_eq_sup Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_le_iff_left : a ⇔ b ≀ a ↔ Codisjoint a b := @le_symmDiff_iff_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_le_iff_right : a ⇔ b ≀ b ↔ Codisjoint a b := @le_symmDiff_iff_right Ξ±α΅’α΅ˆ _ _ _ theorem bihimp_assoc : a ⇔ b ⇔ c = a ⇔ (b ⇔ c) := @symmDiff_assoc Ξ±α΅’α΅ˆ _ _ _ _ instance bihimp_isAssociative : Std.Associative (Ξ± := Ξ±) (Β· ⇔ Β·) := ⟨bihimp_assoc⟩ theorem bihimp_left_comm : a ⇔ (b ⇔ c) = b ⇔ (a ⇔ c) := by simp_rw [← bihimp_assoc, bihimp_comm] theorem bihimp_right_comm : a ⇔ b ⇔ c = a ⇔ c ⇔ b := by simp_rw [bihimp_assoc, bihimp_comm] theorem bihimp_bihimp_bihimp_comm : a ⇔ b ⇔ (c ⇔ d) = a ⇔ c ⇔ (b ⇔ d) := by simp_rw [bihimp_assoc, bihimp_left_comm] @[simp] theorem bihimp_bihimp_cancel_left : a ⇔ (a ⇔ b) = b := by simp [← bihimp_assoc] @[simp] theorem bihimp_bihimp_cancel_right : b ⇔ a ⇔ a = b := by simp [bihimp_assoc] @[simp] theorem bihimp_bihimp_self : a ⇔ b ⇔ a = b := by rw [bihimp_comm, bihimp_bihimp_cancel_left] theorem bihimp_left_involutive (a : Ξ±) : Involutive (Β· ⇔ a) := bihimp_bihimp_cancel_right _ theorem bihimp_right_involutive (a : Ξ±) : Involutive (a ⇔ Β·) := bihimp_bihimp_cancel_left _ theorem bihimp_left_injective (a : Ξ±) : Injective (Β· ⇔ a) := @symmDiff_left_injective Ξ±α΅’α΅ˆ _ _ theorem bihimp_right_injective (a : Ξ±) : Injective (a ⇔ Β·) := @symmDiff_right_injective Ξ±α΅’α΅ˆ _ _ theorem bihimp_left_surjective (a : Ξ±) : Surjective (Β· ⇔ a) := @symmDiff_left_surjective Ξ±α΅’α΅ˆ _ _ theorem bihimp_right_surjective (a : Ξ±) : Surjective (a ⇔ Β·) := @symmDiff_right_surjective Ξ±α΅’α΅ˆ _ _ variable {a b c} @[simp] theorem bihimp_left_inj : a ⇔ b = c ⇔ b ↔ a = c := (bihimp_left_injective _).eq_iff @[simp] theorem bihimp_right_inj : a ⇔ b = a ⇔ c ↔ b = c := (bihimp_right_injective _).eq_iff @[simp] theorem bihimp_eq_left : a ⇔ b = a ↔ b = ⊀ := @symmDiff_eq_left Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem bihimp_eq_right : a ⇔ b = b ↔ a = ⊀ := @symmDiff_eq_right Ξ±α΅’α΅ˆ _ _ _ protected theorem Codisjoint.bihimp_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a ⇔ b) c := (ha.inf_left hb).mono_left inf_le_bihimp protected theorem Codisjoint.bihimp_right (ha : Codisjoint a b) (hb : Codisjoint a c) : Codisjoint a (b ⇔ c) := (ha.inf_right hb).mono_right inf_le_bihimp end CogeneralizedBooleanAlgebra theorem symmDiff_eq : a βˆ† b = a βŠ“ bᢜ βŠ” b βŠ“ aᢜ := by simp only [(Β· βˆ† Β·), sdiff_eq] theorem bihimp_eq : a ⇔ b = (a βŠ” bᢜ) βŠ“ (b βŠ” aᢜ) := by simp only [(Β· ⇔ Β·), himp_eq] theorem symmDiff_eq' : a βˆ† b = (a βŠ” b) βŠ“ (aᢜ βŠ” bᢜ) := by rw [symmDiff_eq_sup_sdiff_inf, sdiff_eq, compl_inf] theorem bihimp_eq' : a ⇔ b = a βŠ“ b βŠ” aᢜ βŠ“ bᢜ := @symmDiff_eq' Ξ±α΅’α΅ˆ _ _ _ theorem symmDiff_top : a βˆ† ⊀ = aᢜ := symmDiff_top' _ theorem top_symmDiff : ⊀ βˆ† a = aᢜ := top_symmDiff' _ @[simp] theorem compl_symmDiff : (a βˆ† b)ᢜ = a ⇔ b := by simp_rw [symmDiff, compl_sup_distrib, compl_sdiff, bihimp, inf_comm] @[simp] theorem compl_bihimp : (a ⇔ b)ᢜ = a βˆ† b := @compl_symmDiff Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem compl_symmDiff_compl : aᢜ βˆ† bᢜ = a βˆ† b := (sup_comm _ _).trans <| by simp_rw [compl_sdiff_compl, sdiff_eq, symmDiff_eq] @[simp] theorem compl_bihimp_compl : aᢜ ⇔ bᢜ = a ⇔ b := @compl_symmDiff_compl Ξ±α΅’α΅ˆ _ _ _ @[simp] theorem symmDiff_eq_top : a βˆ† b = ⊀ ↔ IsCompl a b := by rw [symmDiff_eq', ← compl_inf, inf_eq_top_iff, compl_eq_top, isCompl_iff, disjoint_iff, codisjoint_iff, and_comm] @[simp] theorem bihimp_eq_bot : a ⇔ b = βŠ₯ ↔ IsCompl a b := by rw [bihimp_eq', ← compl_sup, sup_eq_bot_iff, compl_eq_bot, isCompl_iff, disjoint_iff, codisjoint_iff] @[simp] theorem compl_symmDiff_self : aᢜ βˆ† a = ⊀ := hnot_symmDiff_self _ @[simp] theorem symmDiff_compl_self : a βˆ† aᢜ = ⊀ := symmDiff_hnot_self _ theorem symmDiff_symmDiff_right' : a βˆ† (b βˆ† c) = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” aᢜ βŠ“ b βŠ“ cᢜ βŠ” aᢜ βŠ“ bᢜ βŠ“ c := calc a βˆ† (b βˆ† c) = a βŠ“ (b βŠ“ c βŠ” bᢜ βŠ“ cᢜ) βŠ” (b βŠ“ cᢜ βŠ” c βŠ“ bᢜ) βŠ“ aᢜ := by { rw [symmDiff_eq, compl_symmDiff, bihimp_eq', symmDiff_eq] } _ = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” b βŠ“ cᢜ βŠ“ aᢜ βŠ” c βŠ“ bᢜ βŠ“ aᢜ := by { rw [inf_sup_left, inf_sup_right, ← sup_assoc, ← inf_assoc, ← inf_assoc] } _ = a βŠ“ b βŠ“ c βŠ” a βŠ“ bᢜ βŠ“ cᢜ βŠ” aᢜ βŠ“ b βŠ“ cᢜ βŠ” aᢜ βŠ“ bᢜ βŠ“ c := (by congr 1 Β· congr 1 rw [inf_comm, inf_assoc] Β· apply inf_left_right_swap) variable {a b c} theorem Disjoint.le_symmDiff_sup_symmDiff_left (h : Disjoint a b) : c ≀ a βˆ† c βŠ” b βˆ† c := by trans c \ (a βŠ“ b) Β· rw [h.eq_bot, sdiff_bot] Β· rw [sdiff_inf] exact sup_le_sup le_sup_right le_sup_right theorem Disjoint.le_symmDiff_sup_symmDiff_right (h : Disjoint b c) : a ≀ a βˆ† b βŠ” a βˆ† c := by simp_rw [symmDiff_comm a] exact h.le_symmDiff_sup_symmDiff_left theorem Codisjoint.bihimp_inf_bihimp_le_left (h : Codisjoint a b) : a ⇔ c βŠ“ b ⇔ c ≀ c := h.dual.le_symmDiff_sup_symmDiff_left theorem Codisjoint.bihimp_inf_bihimp_le_right (h : Codisjoint b c) : a ⇔ b βŠ“ a ⇔ c ≀ a := h.dual.le_symmDiff_sup_symmDiff_right end BooleanAlgebra /-! ### Prod -/ section Prod @[simp] theorem symmDiff_fst [GeneralizedCoheytingAlgebra Ξ±] [GeneralizedCoheytingAlgebra Ξ²] (a b : Ξ± Γ— Ξ²) : (a βˆ† b).1 = a.1 βˆ† b.1 := rfl @[simp] theorem symmDiff_snd [GeneralizedCoheytingAlgebra Ξ±] [GeneralizedCoheytingAlgebra Ξ²] (a b : Ξ± Γ— Ξ²) : (a βˆ† b).2 = a.2 βˆ† b.2 := rfl @[simp] theorem bihimp_fst [GeneralizedHeytingAlgebra Ξ±] [GeneralizedHeytingAlgebra Ξ²] (a b : Ξ± Γ— Ξ²) : (a ⇔ b).1 = a.1 ⇔ b.1 := rfl @[simp] theorem bihimp_snd [GeneralizedHeytingAlgebra Ξ±] [GeneralizedHeytingAlgebra Ξ²] (a b : Ξ± Γ— Ξ²) : (a ⇔ b).2 = a.2 ⇔ b.2 := rfl end Prod /-! ### Pi -/ namespace Pi theorem symmDiff_def [βˆ€ i, GeneralizedCoheytingAlgebra (Ο€ i)] (a b : βˆ€ i, Ο€ i) : a βˆ† b = fun i => a i βˆ† b i := rfl theorem bihimp_def [βˆ€ i, GeneralizedHeytingAlgebra (Ο€ i)] (a b : βˆ€ i, Ο€ i) : a ⇔ b = fun i => a i ⇔ b i := rfl @[simp] theorem symmDiff_apply [βˆ€ i, GeneralizedCoheytingAlgebra (Ο€ i)] (a b : βˆ€ i, Ο€ i) (i : ΞΉ) : (a βˆ† b) i = a i βˆ† b i := rfl @[simp] theorem bihimp_apply [βˆ€ i, GeneralizedHeytingAlgebra (Ο€ i)] (a b : βˆ€ i, Ο€ i) (i : ΞΉ) : (a ⇔ b) i = a i ⇔ b i := rfl end Pi
Mathlib/Order/SymmDiff.lean
749
750
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Order.CauSeq.BigOperators import Mathlib.Algebra.Order.Star.Basic import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Complex.Norm import Mathlib.Data.Nat.Choose.Sum /-! # Exponential Function This file contains the definitions of the real and complex exponential function. ## Main definitions * `Complex.exp`: The complex exponential function, defined via its Taylor series * `Real.exp`: The real exponential function, defined as the real part of the complex exponential -/ open CauSeq Finset IsAbsoluteValue open scoped ComplexConjugate namespace Complex theorem isCauSeq_norm_exp (z : β„‚) : IsCauSeq abs fun n => βˆ‘ m ∈ range n, β€–z ^ m / m.factorialβ€– := let ⟨n, hn⟩ := exists_nat_gt β€–zβ€– have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (norm_nonneg _) hn IsCauSeq.series_ratio_test n (β€–zβ€– / n) (div_nonneg (norm_nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iffβ‚€ hn0, one_mul]) fun m hm => by rw [abs_norm, abs_norm, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, Complex.norm_mul, Complex.norm_div, norm_natCast] gcongr exact le_trans hm (Nat.le_succ _) @[deprecated (since := "2025-02-16")] alias isCauSeq_abs_exp := isCauSeq_norm_exp noncomputable section theorem isCauSeq_exp (z : β„‚) : IsCauSeq (β€–Β·β€–) fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial := (isCauSeq_norm_exp z).of_abv /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ @[pp_nodot] def exp' (z : β„‚) : CauSeq β„‚ (β€–Β·β€–) := ⟨fun n => βˆ‘ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ /-- The complex exponential function, defined via its Taylor series -/ @[pp_nodot] def exp (z : β„‚) : β„‚ := CauSeq.lim (exp' z) /-- scoped notation for the complex exponential function -/ scoped notation "cexp" => Complex.exp end end Complex namespace Real open Complex noncomputable section /-- The real exponential function, defined as the real part of the complex exponential -/ @[pp_nodot] nonrec def exp (x : ℝ) : ℝ := (exp x).re /-- scoped notation for the real exponential function -/ scoped notation "rexp" => Real.exp end end Real namespace Complex variable (x y : β„‚) @[simp] theorem exp_zero : exp 0 = 1 := by rw [exp] refine lim_eq_of_equiv_const fun Ξ΅ Ξ΅0 => ⟨1, fun j hj => ?_⟩ convert (config := .unfoldSameFun) Ξ΅0 -- Ξ΅0 : Ξ΅ > 0 but goal is _ < Ξ΅ rcases j with - | j Β· exact absurd hj (not_le_of_gt zero_lt_one) Β· dsimp [exp'] induction' j with j ih Β· dsimp [exp']; simp [show Nat.succ 0 = 1 from rfl] Β· rw [← ih (by simp [Nat.succ_le_succ])] simp only [sum_range_succ, pow_succ] simp theorem exp_add : exp (x + y) = exp x * exp y := by have hj : βˆ€ j : β„•, (βˆ‘ m ∈ range j, (x + y) ^ m / m.factorial) = βˆ‘ i ∈ range j, βˆ‘ k ∈ range (i + 1), x ^ k / k.factorial * (y ^ (i - k) / (i - k).factorial) := by intro j refine Finset.sum_congr rfl fun m _ => ?_ rw [add_pow, div_eq_mul_inv, sum_mul] refine Finset.sum_congr rfl fun I hi => ?_ have h₁ : (m.choose I : β„‚) β‰  0 := Nat.cast_ne_zero.2 (pos_iff_ne_zero.1 (Nat.choose_pos (Nat.le_of_lt_succ (mem_range.1 hi)))) have hβ‚‚ := Nat.choose_mul_factorial_mul_factorial (Nat.le_of_lt_succ <| Finset.mem_range.1 hi) rw [← hβ‚‚, Nat.cast_mul, Nat.cast_mul, mul_inv, mul_inv] simp only [mul_left_comm (m.choose I : β„‚), mul_assoc, mul_left_comm (m.choose I : β„‚)⁻¹, mul_comm (m.choose I : β„‚)] rw [inv_mul_cancelβ‚€ h₁] simp [div_eq_mul_inv, mul_comm, mul_assoc, mul_left_comm] simp_rw [exp, exp', lim_mul_lim] apply (lim_eq_lim_of_equiv _).symm simp only [hj] exact cauchy_product (isCauSeq_norm_exp x) (isCauSeq_exp y) /-- the exponential function as a monoid hom from `Multiplicative β„‚` to `β„‚` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative β„‚) β„‚ := { toFun := fun z => exp z.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List β„‚) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative β„‚) expMonoidHom l theorem exp_multiset_sum (s : Multiset β„‚) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative β„‚) β„‚ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ β„‚) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative β„‚) expMonoidHom f s lemma exp_nsmul (x : β„‚) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative β„‚) β„‚ _ _ expMonoidHom _ _ theorem exp_nat_mul (x : β„‚) : βˆ€ n : β„•, exp (n * x) = exp x ^ n | 0 => by rw [Nat.cast_zero, zero_mul, exp_zero, pow_zero] | Nat.succ n => by rw [pow_succ, Nat.cast_add_one, add_mul, exp_add, ← exp_nat_mul _ n, one_mul] @[simp] theorem exp_ne_zero : exp x β‰  0 := fun h => zero_ne_one (Ξ± := β„‚) <| by rw [← exp_zero, ← add_neg_cancel x, exp_add, h]; simp theorem exp_neg : exp (-x) = (exp x)⁻¹ := by rw [← mul_right_inj' (exp_ne_zero x), ← exp_add]; simp [mul_inv_cancelβ‚€ (exp_ne_zero x)] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] theorem exp_int_mul (z : β„‚) (n : β„€) : Complex.exp (n * z) = Complex.exp z ^ n := by cases n Β· simp [exp_nat_mul] Β· simp [exp_add, add_mul, pow_add, exp_neg, exp_nat_mul] @[simp] theorem exp_conj : exp (conj x) = conj (exp x) := by dsimp [exp] rw [← lim_conj] refine congr_arg CauSeq.lim (CauSeq.ext fun _ => ?_) dsimp [exp', Function.comp_def, cauSeqConj] rw [map_sum (starRingEnd _)] refine sum_congr rfl fun n _ => ?_ rw [map_divβ‚€, map_pow, ← ofReal_natCast, conj_ofReal] @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : β„‚) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : β„‚) = exp x := ofReal_exp_ofReal_re _ @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ @[simps] noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp x.toAdd, map_one' := by simp, map_mul' := by simp [exp_add] } theorem exp_list_sum (l : List ℝ) : exp l.sum = (l.map exp).prod := map_list_prod (M := Multiplicative ℝ) expMonoidHom l theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s theorem exp_sum {Ξ± : Type*} (s : Finset Ξ±) (f : Ξ± β†’ ℝ) : exp (βˆ‘ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (Ξ² := Multiplicative ℝ) expMonoidHom f s lemma exp_nsmul (x : ℝ) (n : β„•) : exp (n β€’ x) = exp x ^ n := @MonoidHom.map_pow (Multiplicative ℝ) ℝ _ _ expMonoidHom _ _ nonrec theorem exp_nat_mul (x : ℝ) (n : β„•) : exp (n * x) = exp x ^ n := ofReal_injective (by simp [exp_nat_mul]) @[simp] nonrec theorem exp_ne_zero : exp x β‰  0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] theorem exp_sub : exp (x - y) = exp x / exp y := by simp [sub_eq_add_neg, exp_add, exp_neg, div_eq_mul_inv] open IsAbsoluteValue Nat theorem sum_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) (n : β„•) : βˆ‘ i ∈ range n, x ^ i / i ! ≀ exp x := calc βˆ‘ i ∈ range n, x ^ i / i ! ≀ lim (⟨_, isCauSeq_re (exp' x)⟩ : CauSeq ℝ abs) := by refine le_lim (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp only [exp', const_apply, re_sum] norm_cast refine sum_le_sum_of_subset_of_nonneg (range_mono hj) fun _ _ _ ↦ ?_ positivity _ = exp x := by rw [exp, Complex.exp, ← cauSeqRe, lim_re] lemma pow_div_factorial_le_exp (hx : 0 ≀ x) (n : β„•) : x ^ n / n ! ≀ exp x := calc x ^ n / n ! ≀ βˆ‘ k ∈ range (n + 1), x ^ k / k ! := single_le_sum (f := fun k ↦ x ^ k / k !) (fun k _ ↦ by positivity) (self_mem_range_succ n) _ ≀ exp x := sum_le_exp_of_nonneg hx _ theorem quadratic_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : 1 + x + x ^ 2 / 2 ≀ exp x := calc 1 + x + x ^ 2 / 2 = βˆ‘ i ∈ range 3, x ^ i / i ! := by simp only [sum_range_succ, range_one, sum_singleton, _root_.pow_zero, factorial, cast_one, ne_eq, one_ne_zero, not_false_eq_true, div_self, pow_one, mul_one, div_one, Nat.mul_one, cast_succ, add_right_inj] ring_nf _ ≀ exp x := sum_le_exp_of_nonneg hx 3 private theorem add_one_lt_exp_of_pos {x : ℝ} (hx : 0 < x) : x + 1 < exp x := (by nlinarith : x + 1 < 1 + x + x ^ 2 / 2).trans_le (quadratic_le_exp_of_nonneg hx.le) private theorem add_one_le_exp_of_nonneg {x : ℝ} (hx : 0 ≀ x) : x + 1 ≀ exp x := by rcases eq_or_lt_of_le hx with (rfl | h) Β· simp exact (add_one_lt_exp_of_pos h).le theorem one_le_exp {x : ℝ} (hx : 0 ≀ x) : 1 ≀ exp x := by linarith [add_one_le_exp_of_nonneg hx] @[bound] theorem exp_pos (x : ℝ) : 0 < exp x := (le_total 0 x).elim (lt_of_lt_of_le zero_lt_one ∘ one_le_exp) fun h => by rw [← neg_neg x, Real.exp_neg] exact inv_pos.2 (lt_of_lt_of_le zero_lt_one (one_le_exp (neg_nonneg.2 h))) @[bound] lemma exp_nonneg (x : ℝ) : 0 ≀ exp x := x.exp_pos.le @[simp] theorem abs_exp (x : ℝ) : |exp x| = exp x := abs_of_pos (exp_pos _) lemma exp_abs_le (x : ℝ) : exp |x| ≀ exp x + exp (-x) := by cases le_total x 0 <;> simp [abs_of_nonpos, abs_of_nonneg, exp_nonneg, *] @[mono] theorem exp_strictMono : StrictMono exp := fun x y h => by rw [← sub_add_cancel y x, Real.exp_add] exact (lt_mul_iff_one_lt_left (exp_pos _)).2 (lt_of_lt_of_le (by linarith) (add_one_le_exp_of_nonneg (by linarith))) @[gcongr] theorem exp_lt_exp_of_lt {x y : ℝ} (h : x < y) : exp x < exp y := exp_strictMono h @[mono] theorem exp_monotone : Monotone exp := exp_strictMono.monotone @[gcongr, bound] theorem exp_le_exp_of_le {x y : ℝ} (h : x ≀ y) : exp x ≀ exp y := exp_monotone h @[simp] theorem exp_lt_exp {x y : ℝ} : exp x < exp y ↔ x < y := exp_strictMono.lt_iff_lt @[simp] theorem exp_le_exp {x y : ℝ} : exp x ≀ exp y ↔ x ≀ y := exp_strictMono.le_iff_le theorem exp_injective : Function.Injective exp := exp_strictMono.injective @[simp] theorem exp_eq_exp {x y : ℝ} : exp x = exp y ↔ x = y := exp_injective.eq_iff @[simp] theorem exp_eq_one_iff : exp x = 1 ↔ x = 0 := exp_injective.eq_iff' exp_zero @[simp] theorem one_lt_exp_iff {x : ℝ} : 1 < exp x ↔ 0 < x := by rw [← exp_zero, exp_lt_exp] @[bound] private alias ⟨_, Bound.one_lt_exp_of_pos⟩ := one_lt_exp_iff @[simp] theorem exp_lt_one_iff {x : ℝ} : exp x < 1 ↔ x < 0 := by rw [← exp_zero, exp_lt_exp] @[simp] theorem exp_le_one_iff {x : ℝ} : exp x ≀ 1 ↔ x ≀ 0 := exp_zero β–Έ exp_le_exp @[simp] theorem one_le_exp_iff {x : ℝ} : 1 ≀ exp x ↔ 0 ≀ x := exp_zero β–Έ exp_le_exp end Real namespace Complex theorem sum_div_factorial_le {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] (n j : β„•) (hn : 0 < n) : (βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : Ξ±)) ≀ n.succ / (n.factorial * n) := calc (βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : Ξ±)) = βˆ‘ m ∈ range (j - n), (1 / ((m + n).factorial : Ξ±)) := by refine sum_nbij' (Β· - n) (Β· + n) ?_ ?_ ?_ ?_ ?_ <;> simp +contextual [lt_tsub_iff_right, tsub_add_cancel_of_le] _ ≀ βˆ‘ m ∈ range (j - n), ((n.factorial : Ξ±) * (n.succ : Ξ±) ^ m)⁻¹ := by simp_rw [one_div] gcongr rw [← Nat.cast_pow, ← Nat.cast_mul, Nat.cast_le, add_comm] exact Nat.factorial_mul_pow_le_factorial _ = (n.factorial : Ξ±)⁻¹ * βˆ‘ m ∈ range (j - n), (n.succ : Ξ±)⁻¹ ^ m := by simp [mul_inv, ← mul_sum, ← sum_mul, mul_comm, inv_pow] _ = ((n.succ : Ξ±) - n.succ * (n.succ : Ξ±)⁻¹ ^ (j - n)) / (n.factorial * n) := by have h₁ : (n.succ : Ξ±) β‰  1 := @Nat.cast_one Ξ± _ β–Έ mt Nat.cast_inj.1 (mt Nat.succ.inj (pos_iff_ne_zero.1 hn)) have hβ‚‚ : (n.succ : Ξ±) β‰  0 := by positivity have h₃ : (n.factorial * n : Ξ±) β‰  0 := by positivity have hβ‚„ : (n.succ - 1 : Ξ±) = n := by simp rw [geom_sum_inv h₁ hβ‚‚, eq_div_iff_mul_eq h₃, mul_comm _ (n.factorial * n : Ξ±), ← mul_assoc (n.factorial⁻¹ : Ξ±), ← mul_inv_rev, hβ‚„, ← mul_assoc (n.factorial * n : Ξ±), mul_comm (n : Ξ±) n.factorial, mul_inv_cancelβ‚€ h₃, one_mul, mul_comm] _ ≀ n.succ / (n.factorial * n : Ξ±) := by gcongr; apply sub_le_self; positivity theorem exp_bound {x : β„‚} (hx : β€–xβ€– ≀ 1) {n : β„•} (hn : 0 < n) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) := by rw [← lim_const (abv := norm) (βˆ‘ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n * ((n.succ : ℝ) * (n.factorial * n : ℝ)⁻¹) rw [sum_range_sub_sum_range hj] calc β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ m / m.factorial : β„‚)β€– = β€–βˆ‘ m ∈ range j with n ≀ m, (x ^ n * (x ^ (m - n) / m.factorial) : β„‚)β€– := by refine congr_arg norm (sum_congr rfl fun m hm => ?_) rw [mem_filter, mem_range] at hm rw [← mul_div_assoc, ← pow_add, add_tsub_cancel_of_le hm.2] _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–x ^ n * (x ^ (m - n) / m.factorial)β€– := IsAbsoluteValue.abv_sum norm .. _ ≀ βˆ‘ m ∈ range j with n ≀ m, β€–xβ€– ^ n * (1 / m.factorial) := by simp_rw [Complex.norm_mul, Complex.norm_pow, Complex.norm_div, norm_natCast] gcongr rw [Complex.norm_pow] exact pow_le_oneβ‚€ (norm_nonneg _) hx _ = β€–xβ€– ^ n * βˆ‘ m ∈ range j with n ≀ m, (1 / m.factorial : ℝ) := by simp [abs_mul, abv_pow abs, abs_div, ← mul_sum] _ ≀ β€–xβ€– ^ n * (n.succ * (n.factorial * n : ℝ)⁻¹) := by gcongr exact sum_div_factorial_le _ _ hn theorem exp_bound' {x : β„‚} {n : β„•} (hx : β€–xβ€– / n.succ ≀ 1 / 2) : β€–exp x - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n / n.factorial * 2 := by rw [← lim_const (abv := norm) (βˆ‘ m ∈ range n, _), exp, sub_eq_add_neg, ← lim_neg, lim_add, ← lim_norm] refine lim_le (CauSeq.le_of_exists ⟨n, fun j hj => ?_⟩) simp_rw [← sub_eq_add_neg] show β€–(βˆ‘ m ∈ range j, x ^ m / m.factorial) - βˆ‘ m ∈ range n, x ^ m / m.factorialβ€– ≀ β€–xβ€– ^ n / n.factorial * 2 let k := j - n have hj : j = n + k := (add_tsub_cancel_of_le hj).symm rw [hj, sum_range_add_sub_sum_range]
calc
Mathlib/Data/Complex/Exponential.lean
409
409
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Tape import Mathlib.Data.Fintype.Option import Mathlib.Data.Fintype.Prod import Mathlib.Data.Fintype.Pi import Mathlib.Data.PFun import Mathlib.Computability.PostTuringMachine /-! # Turing machines The files `PostTuringMachine.lean` and `TuringMachine.lean` define a sequence of simple machine languages, starting with Turing machines and working up to more complex languages based on Wang B-machines. `PostTuringMachine.lean` covers the TM0 model and TM1 model; `TuringMachine.lean` adds the TM2 model. ## Naming conventions Each model of computation in this file shares a naming convention for the elements of a model of computation. These are the parameters for the language: * `Ξ“` is the alphabet on the tape. * `Ξ›` is the set of labels, or internal machine states. * `Οƒ` is the type of internal memory, not on the tape. This does not exist in the TM0 model, and later models achieve this by mixing it into `Ξ›`. * `K` is used in the TM2 model, which has multiple stacks, and denotes the number of such stacks. All of these variables denote "essentially finite" types, but for technical reasons it is convenient to allow them to be infinite anyway. When using an infinite type, we will be interested to prove that only finitely many values of the type are ever interacted with. Given these parameters, there are a few common structures for the model that arise: * `Stmt` is the set of all actions that can be performed in one step. For the TM0 model this set is finite, and for later models it is an infinite inductive type representing "possible program texts". * `Cfg` is the set of instantaneous configurations, that is, the state of the machine together with its environment. * `Machine` is the set of all machines in the model. Usually this is approximately a function `Ξ› β†’ Stmt`, although different models have different ways of halting and other actions. * `step : Cfg β†’ Option Cfg` is the function that describes how the state evolves over one step. If `step c = none`, then `c` is a terminal state, and the result of the computation is read off from `c`. Because of the type of `step`, these models are all deterministic by construction. * `init : Input β†’ Cfg` sets up the initial state. The type `Input` depends on the model; in most cases it is `List Ξ“`. * `eval : Machine β†’ Input β†’ Part Output`, given a machine `M` and input `i`, starts from `init i`, runs `step` until it reaches an output, and then applies a function `Cfg β†’ Output` to the final state to obtain the result. The type `Output` depends on the model. * `Supports : Machine β†’ Finset Ξ› β†’ Prop` asserts that a machine `M` starts in `S : Finset Ξ›`, and can only ever jump to other states inside `S`. This implies that the behavior of `M` on any input cannot depend on its values outside `S`. We use this to allow `Ξ›` to be an infinite set when convenient, and prove that only finitely many of these states are actually accessible. This formalizes "essentially finite" mentioned above. -/ assert_not_exists MonoidWithZero open List (Vector) open Relation open Nat (iterate) open Function (update iterate_succ iterate_succ_apply iterate_succ' iterate_succ_apply' iterate_zero_apply) namespace Turing /-! ## The TM2 model The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks, each with elements of different types (the alphabet of stack `k : K` is `Ξ“ k`). The statements are: * `push k (f : Οƒ β†’ Ξ“ k) q` puts `f a` on the `k`-th stack, then does `q`. * `pop k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, and removes this element from the stack, then does `q`. * `peek k (f : Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) q` changes the state to `f a (S k).head`, where `S k` is the value of the `k`-th stack, then does `q`. * `load (f : Οƒ β†’ Οƒ) q` reads nothing but applies `f` to the internal state, then does `q`. * `branch (f : Οƒ β†’ Bool) qtrue qfalse` does `qtrue` or `qfalse` according to `f a`. * `goto (f : Οƒ β†’ Ξ›)` jumps to label `f a`. * `halt` halts on the next step. The configuration is a tuple `(l, var, stk)` where `l : Option Ξ›` is the current label to run or `none` for the halting state, `var : Οƒ` is the (finite) internal state, and `stk : βˆ€ k, List (Ξ“ k)` is the collection of stacks. (Note that unlike the `TM0` and `TM1` models, these are not `ListBlank`s, they have definite ends that can be detected by the `pop` command.) Given a designated stack `k` and a value `L : List (Ξ“ k)`, the initial configuration has all the stacks empty except the designated "input" stack; in `eval` this designated stack also functions as the output stack. -/ namespace TM2 variable {K : Type*} -- Index type of stacks variable (Ξ“ : K β†’ Type*) -- Type of stack elements variable (Ξ› : Type*) -- Type of function labels variable (Οƒ : Type*) -- Type of variable settings /-- The TM2 model removes the tape entirely from the TM1 model, replacing it with an arbitrary (finite) collection of stacks. The operation `push` puts an element on one of the stacks, and `pop` removes an element from a stack (and modifying the internal state based on the result). `peek` modifies the internal state but does not remove an element. -/ inductive Stmt | push : βˆ€ k, (Οƒ β†’ Ξ“ k) β†’ Stmt β†’ Stmt | peek : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | pop : βˆ€ k, (Οƒ β†’ Option (Ξ“ k) β†’ Οƒ) β†’ Stmt β†’ Stmt | load : (Οƒ β†’ Οƒ) β†’ Stmt β†’ Stmt | branch : (Οƒ β†’ Bool) β†’ Stmt β†’ Stmt β†’ Stmt | goto : (Οƒ β†’ Ξ›) β†’ Stmt | halt : Stmt open Stmt instance Stmt.inhabited : Inhabited (Stmt Ξ“ Ξ› Οƒ) := ⟨halt⟩ /-- A configuration in the TM2 model is a label (or `none` for the halt state), the state of local variables, and the stacks. (Note that the stacks are not `ListBlank`s, they have a definite size.) -/ structure Cfg where /-- The current label to run (or `none` for the halting state) -/ l : Option Ξ› /-- The internal state -/ var : Οƒ /-- The (finite) collection of internal stacks -/ stk : βˆ€ k, List (Ξ“ k) instance Cfg.inhabited [Inhabited Οƒ] : Inhabited (Cfg Ξ“ Ξ› Οƒ) := ⟨⟨default, default, default⟩⟩ variable {Ξ“ Ξ› Οƒ} section variable [DecidableEq K] /-- The step function for the TM2 model. -/ def stepAux : Stmt Ξ“ Ξ› Οƒ β†’ Οƒ β†’ (βˆ€ k, List (Ξ“ k)) β†’ Cfg Ξ“ Ξ› Οƒ | push k f q, v, S => stepAux q v (update S k (f v :: S k)) | peek k f q, v, S => stepAux q (f v (S k).head?) S | pop k f q, v, S => stepAux q (f v (S k).head?) (update S k (S k).tail) | load a q, v, S => stepAux q (a v) S | branch f q₁ qβ‚‚, v, S => cond (f v) (stepAux q₁ v S) (stepAux qβ‚‚ v S) | goto f, v, S => ⟨some (f v), v, S⟩ | halt, v, S => ⟨none, v, S⟩ /-- The step function for the TM2 model. -/ def step (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Option (Cfg Ξ“ Ξ› Οƒ) | ⟨none, _, _⟩ => none | ⟨some l, v, S⟩ => some (stepAux (M l) v S) attribute [simp] stepAux.eq_1 stepAux.eq_2 stepAux.eq_3 stepAux.eq_4 stepAux.eq_5 stepAux.eq_6 stepAux.eq_7 step.eq_1 step.eq_2 /-- The (reflexive) reachability relation for the TM2 model. -/ def Reaches (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) : Cfg Ξ“ Ξ› Οƒ β†’ Cfg Ξ“ Ξ› Οƒ β†’ Prop := ReflTransGen fun a b ↦ b ∈ step M a end /-- Given a set `S` of states, `SupportsStmt S q` means that `q` only jumps to states in `S`. -/ def SupportsStmt (S : Finset Ξ›) : Stmt Ξ“ Ξ› Οƒ β†’ Prop | push _ _ q => SupportsStmt S q | peek _ _ q => SupportsStmt S q | pop _ _ q => SupportsStmt S q | load _ q => SupportsStmt S q | branch _ q₁ qβ‚‚ => SupportsStmt S q₁ ∧ SupportsStmt S qβ‚‚ | goto l => βˆ€ v, l v ∈ S | halt => True section open scoped Classical in /-- The set of subtree statements in a statement. -/ noncomputable def stmts₁ : Stmt Ξ“ Ξ› Οƒ β†’ Finset (Stmt Ξ“ Ξ› Οƒ) | Q@(push _ _ q) => insert Q (stmts₁ q) | Q@(peek _ _ q) => insert Q (stmts₁ q) | Q@(pop _ _ q) => insert Q (stmts₁ q) | Q@(load _ q) => insert Q (stmts₁ q) | Q@(branch _ q₁ qβ‚‚) => insert Q (stmts₁ q₁ βˆͺ stmts₁ qβ‚‚) | Q@(goto _) => {Q} | Q@halt => {Q} theorem stmts₁_self {q : Stmt Ξ“ Ξ› Οƒ} : q ∈ stmts₁ q := by cases q <;> simp only [Finset.mem_insert_self, Finset.mem_singleton_self, stmts₁] theorem stmts₁_trans {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} : q₁ ∈ stmts₁ qβ‚‚ β†’ stmts₁ q₁ βŠ† stmts₁ qβ‚‚ := by classical intro h₁₂ qβ‚€ h₀₁ induction qβ‚‚ with ( simp only [stmts₁] at h₁₂ ⊒ simp only [Finset.mem_insert, Finset.mem_singleton, Finset.mem_union] at h₁₂) | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h₁₂ with (rfl | h₁₂ | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (Finset.mem_union_left _ (IH₁ h₁₂)) Β· exact Finset.mem_insert_of_mem (Finset.mem_union_right _ (IHβ‚‚ h₁₂)) | goto l => subst h₁₂; exact h₀₁ | halt => subst h₁₂; exact h₀₁ | load _ q IH | _ _ _ q IH => rcases h₁₂ with (rfl | h₁₂) Β· unfold stmts₁ at h₀₁ exact h₀₁ Β· exact Finset.mem_insert_of_mem (IH h₁₂) theorem stmts₁_supportsStmt_mono {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h : q₁ ∈ stmts₁ qβ‚‚) (hs : SupportsStmt S qβ‚‚) : SupportsStmt S q₁ := by induction qβ‚‚ with simp only [stmts₁, SupportsStmt, Finset.mem_insert, Finset.mem_union, Finset.mem_singleton] at h hs | branch f q₁ qβ‚‚ IH₁ IHβ‚‚ => rcases h with (rfl | h | h); exacts [hs, IH₁ h hs.1, IHβ‚‚ h hs.2] | goto l => subst h; exact hs | halt => subst h; trivial | load _ _ IH | _ _ _ _ IH => rcases h with (rfl | h) <;> [exact hs; exact IH h hs] open scoped Classical in /-- The set of statements accessible from initial set `S` of labels. -/ noncomputable def stmts (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) : Finset (Option (Stmt Ξ“ Ξ› Οƒ)) := Finset.insertNone (S.biUnion fun q ↦ stmts₁ (M q)) theorem stmts_trans {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q₁ qβ‚‚ : Stmt Ξ“ Ξ› Οƒ} (h₁ : q₁ ∈ stmts₁ qβ‚‚) : some qβ‚‚ ∈ stmts M S β†’ some q₁ ∈ stmts M S := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls hβ‚‚ ↦ ⟨_, ls, stmts₁_trans hβ‚‚ hβ‚βŸ© end variable [Inhabited Ξ›] /-- Given a TM2 machine `M` and a set `S` of states, `Supports M S` means that all states in `S` jump only to other states in `S`. -/ def Supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (S : Finset Ξ›) := default ∈ S ∧ βˆ€ q ∈ S, SupportsStmt S (M q) theorem stmts_supportsStmt {M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ} {S : Finset Ξ›} {q : Stmt Ξ“ Ξ› Οƒ} (ss : Supports M S) : some q ∈ stmts M S β†’ SupportsStmt S q := by simp only [stmts, Finset.mem_insertNone, Finset.mem_biUnion, Option.mem_def, Option.some.injEq, forall_eq', exists_imp, and_imp] exact fun l ls h ↦ stmts₁_supportsStmt_mono h (ss.2 _ ls) variable [DecidableEq K] theorem step_supports (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) {S : Finset Ξ›} (ss : Supports M S) : βˆ€ {c c' : Cfg Ξ“ Ξ› Οƒ}, c' ∈ step M c β†’ c.l ∈ Finset.insertNone S β†’ c'.l ∈ Finset.insertNone S | ⟨some l₁, v, T⟩, c', h₁, hβ‚‚ => by replace hβ‚‚ := ss.2 _ (Finset.some_mem_insertNone.1 hβ‚‚) simp only [step, Option.mem_def, Option.some.injEq] at h₁; subst c' revert hβ‚‚; induction M l₁ generalizing v T with intro hs | branch p q₁' qβ‚‚' IH₁ IHβ‚‚ => unfold stepAux; cases p v Β· exact IHβ‚‚ _ _ hs.2 Β· exact IH₁ _ _ hs.1 | goto => exact Finset.some_mem_insertNone.2 (hs _) | halt => apply Multiset.mem_cons_self | load _ _ IH | _ _ _ _ IH => exact IH _ _ hs variable [Inhabited Οƒ] /-- The initial state of the TM2 model. The input is provided on a designated stack. -/ def init (k : K) (L : List (Ξ“ k)) : Cfg Ξ“ Ξ› Οƒ := ⟨some default, default, update (fun _ ↦ []) k L⟩ /-- Evaluates a TM2 program to completion, with the output on the same stack as the input. -/ def eval (M : Ξ› β†’ Stmt Ξ“ Ξ› Οƒ) (k : K) (L : List (Ξ“ k)) : Part (List (Ξ“ k)) := (Turing.eval (step M) (init k L)).map fun c ↦ c.stk k end TM2 /-! ## TM2 emulator in TM1 To prove that TM2 computable functions are TM1 computable, we need to reduce each TM2 program to a TM1 program. So suppose a TM2 program is given. This program has to maintain a whole collection of stacks, but we have only one tape, so we must "multiplex" them all together. Pictorially, if stack 1 contains `[a, b]` and stack 2 contains `[c, d, e, f]` then the tape looks like this: ``` bottom: ... | _ | T | _ | _ | _ | _ | ... stack 1: ... | _ | b | a | _ | _ | _ | ... stack 2: ... | _ | f | e | d | c | _ | ... ``` where a tape element is a vertical slice through the diagram. Here the alphabet is `Ξ“' := Bool Γ— βˆ€ k, Option (Ξ“ k)`, where: * `bottom : Bool` is marked only in one place, the initial position of the TM, and represents the tail of all stacks. It is never modified. * `stk k : Option (Ξ“ k)` is the value of the `k`-th stack, if in range, otherwise `none` (which is the blank value). Note that the head of the stack is at the far end; this is so that push and pop don't have to do any shifting. In "resting" position, the TM is sitting at the position marked `bottom`. For non-stack actions, it operates in place, but for the stack actions `push`, `peek`, and `pop`, it must shuttle to the end of the appropriate stack, make its changes, and then return to the bottom. So the states are: * `normal (l : Ξ›)`: waiting at `bottom` to execute function `l` * `go k (s : StAct k) (q : Stmtβ‚‚)`: travelling to the right to get to the end of stack `k` in order to perform stack action `s`, and later continue with executing `q` * `ret (q : Stmtβ‚‚)`: travelling to the left after having performed a stack action, and executing `q` once we arrive Because of the shuttling, emulation overhead is `O(n)`, where `n` is the current maximum of the length of all stacks. Therefore a program that takes `k` steps to run in TM2 takes `O((m+k)k)` steps to run when emulated in TM1, where `m` is the length of the input. -/ namespace TM2to1 -- A displaced lemma proved in unnecessary generality theorem stk_nth_val {K : Type*} {Ξ“ : K β†’ Type*} {L : ListBlank (βˆ€ k, Option (Ξ“ k))} {k S} (n) (hL : ListBlank.map (proj k) L = ListBlank.mk (List.map some S).reverse) : L.nth n k = S.reverse[n]? := by rw [← proj_map_nth, hL, ← List.map_reverse, ListBlank.nth_mk, List.getI_eq_iget_getElem?, List.getElem?_map] cases S.reverse[n]? <;> rfl variable (K : Type*) variable (Ξ“ : K β†’ Type*) variable {Ξ› Οƒ : Type*} /-- The alphabet of the TM2 simulator on TM1 is a marker for the stack bottom, plus a vector of stack elements for each stack, or none if the stack does not extend this far. -/ def Ξ“' :=
Bool Γ— βˆ€ k, Option (Ξ“ k) variable {K Ξ“} instance Ξ“'.inhabited : Inhabited (Ξ“' K Ξ“) := ⟨⟨false, fun _ ↦ none⟩⟩ instance Ξ“'.fintype [DecidableEq K] [Fintype K] [βˆ€ k, Fintype (Ξ“ k)] : Fintype (Ξ“' K Ξ“) := instFintypeProd _ _
Mathlib/Computability/TuringMachine.lean
346
354
/- Copyright (c) 2021 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel -/ import Mathlib.MeasureTheory.Integral.Bochner.VitaliCaratheodory deprecated_module (since := "2025-04-06")
Mathlib/MeasureTheory/Integral/VitaliCaratheodory.lean
93
152
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.TwoDim import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic /-! # Oriented angles. This file defines oriented angles in real inner product spaces. ## Main definitions * `Orientation.oangle` is the oriented angle between two vectors with respect to an orientation. ## Implementation notes The definitions here use the `Real.angle` type, angles modulo `2 * Ο€`. For some purposes, angles modulo `Ο€` are more convenient, because results are true for such angles with less configuration dependence. Results that are only equalities modulo `Ο€` can be represented modulo `2 * Ο€` as equalities of `(2 : β„€) β€’ ΞΈ`. ## References * Evan Chen, Euclidean Geometry in Mathematical Olympiads. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "Ο‰" => o.areaForm /-- The oriented angle from `x` to `y`, modulo `2 * Ο€`. If either vector is 0, this is 0. See `InnerProductGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (x y : V) : Real.Angle := Complex.arg (o.kahler x y) /-- Oriented angles are continuous when the vectors involved are nonzero. -/ @[fun_prop] theorem continuousAt_oangle {x : V Γ— V} (hx1 : x.1 β‰  0) (hx2 : x.2 β‰  0) : ContinuousAt (fun y : V Γ— V => o.oangle y.1 y.2) x := by refine (Complex.continuousAt_arg_coe_angle ?_).comp ?_ Β· exact o.kahler_ne_zero hx1 hx2 exact ((continuous_ofReal.comp continuous_inner).add ((continuous_ofReal.comp o.areaForm'.continuousβ‚‚).mul continuous_const)).continuousAt /-- If the first vector passed to `oangle` is 0, the result is 0. -/ @[simp] theorem oangle_zero_left (x : V) : o.oangle 0 x = 0 := by simp [oangle] /-- If the second vector passed to `oangle` is 0, the result is 0. -/
@[simp]
Mathlib/Geometry/Euclidean/Angle/Oriented/Basic.lean
68
68
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.RingTheory.WittVector.InitTail /-! # Truncated Witt vectors The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors. It retains the first `n` coefficients of each Witt vector. In this file, we set up the basic quotient API for this ring. The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors. ## Main declarations - `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors - `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors - `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector, to obtain a truncated Witt vector - `TruncatedWittVector.truncate`: the homomorphism that truncates a truncated Witt vector of length `n` to one of length `m` (for some `m ≀ n`) - `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors that is compatible with a family of ring homomorphisms to the truncated Witt vectors: this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ open Function (Injective Surjective) noncomputable section variable {p : β„•} (n : β„•) (R : Type*) local notation "π•Ž" => WittVector p -- type as `\bbW` /-- A truncated Witt vector over `R` is a vector of elements of `R`, i.e., the first `n` coefficients of a Witt vector. We will define operations on this type that are compatible with the (untruncated) Witt vector operations. `TruncatedWittVector p n R` takes a parameter `p : β„•` that is not used in the definition. In practice, this number `p` is assumed to be a prime number, and under this assumption we construct a ring structure on `TruncatedWittVector p n R`. (`TruncatedWittVector p₁ n R` and `TruncatedWittVector pβ‚‚ n R` are definitionally equal as types but will have different ring operations.) -/ @[nolint unusedArguments] def TruncatedWittVector (_ : β„•) (n : β„•) (R : Type*) := Fin n β†’ R instance (p n : β„•) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) := ⟨fun _ => default⟩ variable {n R} namespace TruncatedWittVector variable (p) in /-- Create a `TruncatedWittVector` from a vector `x`. -/ def mk (x : Fin n β†’ R) : TruncatedWittVector p n R := x /-- `x.coeff i` is the `i`th entry of `x`. -/ def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R := x i @[ext] theorem ext {x y : TruncatedWittVector p n R} (h : βˆ€ i, x.coeff i = y.coeff i) : x = y := funext h @[simp] theorem coeff_mk (x : Fin n β†’ R) (i : Fin n) : (mk p x).coeff i = x i := rfl @[simp] theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by ext i; rw [coeff_mk] variable [CommRing R] /-- We can turn a truncated Witt vector `x` into a Witt vector by setting all coefficients after `x` to be 0. -/ def out (x : TruncatedWittVector p n R) : π•Ž R := @WittVector.mk' p _ fun i => if h : i < n then x.coeff ⟨i, h⟩ else 0 @[simp] theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta] theorem out_injective : Injective (@out p n R _) := by intro x y h ext i rw [WittVector.ext_iff] at h simpa only [coeff_out] using h ↑i end TruncatedWittVector namespace WittVector variable (n) section /-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`, which has the same base `p` as `x`. This function is bundled into a ring homomorphism in `WittVector.truncate` -/ def truncateFun (x : π•Ž R) : TruncatedWittVector p n R := TruncatedWittVector.mk p fun i => x.coeff i end variable {n} @[simp] theorem coeff_truncateFun (x : π•Ž R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by rw [truncateFun, TruncatedWittVector.coeff_mk] variable [CommRing R] @[simp] theorem out_truncateFun (x : π•Ž R) : (truncateFun n x).out = init n x := by ext i dsimp [TruncatedWittVector.out, init, select, coeff_mk] split_ifs with hi; swap; Β· rfl rw [coeff_truncateFun, Fin.val_mk] end WittVector namespace TruncatedWittVector variable [CommRing R] @[simp] theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by simp only [WittVector.truncateFun, coeff_out, mk_coeff] open WittVector variable (p n R) variable [Fact p.Prime] instance : Zero (TruncatedWittVector p n R) := ⟨truncateFun n 0⟩ instance : One (TruncatedWittVector p n R) := ⟨truncateFun n 1⟩ instance : NatCast (TruncatedWittVector p n R) := ⟨fun i => truncateFun n i⟩ instance : IntCast (TruncatedWittVector p n R) := ⟨fun i => truncateFun n i⟩ instance : Add (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out + y.out)⟩ instance : Mul (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out * y.out)⟩ instance : Neg (TruncatedWittVector p n R) := ⟨fun x => truncateFun n (-x.out)⟩ instance : Sub (TruncatedWittVector p n R) := ⟨fun x y => truncateFun n (x.out - y.out)⟩ instance hasNatScalar : SMul β„• (TruncatedWittVector p n R) := ⟨fun m x => truncateFun n (m β€’ x.out)⟩ instance hasIntScalar : SMul β„€ (TruncatedWittVector p n R) := ⟨fun m x => truncateFun n (m β€’ x.out)⟩ instance hasNatPow : Pow (TruncatedWittVector p n R) β„• := ⟨fun x m => truncateFun n (x.out ^ m)⟩ @[simp] theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by show coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0 rw [coeff_truncateFun, WittVector.zero_coeff] end TruncatedWittVector /-- A macro tactic used to prove that `truncateFun` respects ring operations. -/ macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic => `(tactic| { show _ = WittVector.truncateFun n _ apply TruncatedWittVector.out_injective iterate rw [WittVector.out_truncateFun] first | rw [WittVector.init_add] | rw [WittVector.init_mul] | rw [WittVector.init_neg] | rw [WittVector.init_sub] | rw [WittVector.init_nsmul] | rw [WittVector.init_zsmul] | rw [WittVector.init_pow]}) namespace WittVector variable (p n R) variable [CommRing R] theorem truncateFun_surjective : Surjective (@truncateFun p n R) := Function.RightInverse.surjective TruncatedWittVector.truncateFun_out variable [Fact p.Prime] @[simp] theorem truncateFun_zero : truncateFun n (0 : π•Ž R) = 0 := rfl @[simp] theorem truncateFun_one : truncateFun n (1 : π•Ž R) = 1 := rfl variable {p R} @[simp] theorem truncateFun_add (x y : π•Ž R) : truncateFun n (x + y) = truncateFun n x + truncateFun n y := by witt_truncateFun_tac @[simp] theorem truncateFun_mul (x y : π•Ž R) : truncateFun n (x * y) = truncateFun n x * truncateFun n y := by witt_truncateFun_tac theorem truncateFun_neg (x : π•Ž R) : truncateFun n (-x) = -truncateFun n x := by witt_truncateFun_tac theorem truncateFun_sub (x y : π•Ž R) : truncateFun n (x - y) = truncateFun n x - truncateFun n y := by witt_truncateFun_tac theorem truncateFun_nsmul (m : β„•) (x : π•Ž R) : truncateFun n (m β€’ x) = m β€’ truncateFun n x := by witt_truncateFun_tac theorem truncateFun_zsmul (m : β„€) (x : π•Ž R) : truncateFun n (m β€’ x) = m β€’ truncateFun n x := by witt_truncateFun_tac theorem truncateFun_pow (x : π•Ž R) (m : β„•) : truncateFun n (x ^ m) = truncateFun n x ^ m := by witt_truncateFun_tac theorem truncateFun_natCast (m : β„•) : truncateFun n (m : π•Ž R) = m := rfl theorem truncateFun_intCast (m : β„€) : truncateFun n (m : π•Ž R) = m := rfl end WittVector namespace TruncatedWittVector open WittVector variable (p n R) variable [CommRing R] variable [Fact p.Prime] instance instCommRing : CommRing (TruncatedWittVector p n R) := (truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R) (truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n) (truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n) (truncateFun_intCast n) end TruncatedWittVector namespace WittVector open TruncatedWittVector
variable (n)
Mathlib/RingTheory/WittVector/Truncated.lean
277
278
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Index /-! # Complements In this file we define the complement of a subgroup. ## Main definitions - `Subgroup.IsComplement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be written uniquely as a product `s * t` for `s ∈ S`, `t ∈ T`. - `H.LeftTransversal` where `H` is a subgroup of `G` is the type of all left-complements of `H`, i.e. the set of all `S : Set G` that contain exactly one element of each left coset of `H`. - `H.RightTransversal` where `H` is a subgroup of `G` is the set of all right-complements of `H`, i.e. the set of all `T : Set G` that contain exactly one element of each right coset of `H`. ## Main results - `isComplement'_of_coprime` : Subgroups of coprime order are complements. -/ open Function Set open scoped Pointwise namespace Subgroup variable {G : Type*} [Group G] (H K : Subgroup G) (S T : Set G) /-- `S` and `T` are complements if `(*) : S Γ— T β†’ G` is a bijection. This notion generalizes left transversals, right transversals, and complementary subgroups. -/ @[to_additive "`S` and `T` are complements if `(+) : S Γ— T β†’ G` is a bijection"] def IsComplement : Prop := Function.Bijective fun x : S Γ— T => x.1.1 * x.2.1 /-- `H` and `K` are complements if `(*) : H Γ— K β†’ G` is a bijection -/ @[to_additive "`H` and `K` are complements if `(+) : H Γ— K β†’ G` is a bijection"] abbrev IsComplement' := IsComplement (H : Set G) (K : Set G) /-- The set of left-complements of `T : Set G` -/ @[to_additive (attr := deprecated IsComplement (since := "2024-12-18")) "The set of left-complements of `T : Set G`"] def leftTransversals : Set (Set G) := { S : Set G | IsComplement S T } /-- The set of right-complements of `S : Set G` -/ @[to_additive (attr := deprecated IsComplement (since := "2024-12-18")) "The set of right-complements of `S : Set G`"] def rightTransversals : Set (Set G) := { T : Set G | IsComplement S T } variable {H K S T} @[to_additive] theorem isComplement'_def : IsComplement' H K ↔ IsComplement (H : Set G) (K : Set G) := Iff.rfl @[to_additive] theorem isComplement_iff_existsUnique : IsComplement S T ↔ βˆ€ g : G, βˆƒ! x : S Γ— T, x.1.1 * x.2.1 = g := Function.bijective_iff_existsUnique _ @[to_additive] theorem IsComplement.existsUnique (h : IsComplement S T) (g : G) : βˆƒ! x : S Γ— T, x.1.1 * x.2.1 = g := isComplement_iff_existsUnique.mp h g @[to_additive] theorem IsComplement'.symm (h : IsComplement' H K) : IsComplement' K H := by let Ο• : H Γ— K ≃ K Γ— H := Equiv.mk (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => Prod.ext (inv_inv _) (inv_inv _)) fun x => Prod.ext (inv_inv _) (inv_inv _) let ψ : G ≃ G := Equiv.mk (fun g : G => g⁻¹) (fun g : G => g⁻¹) inv_inv inv_inv suffices hf : (ψ ∘ fun x : H Γ— K => x.1.1 * x.2.1) = (fun x : K Γ— H => x.1.1 * x.2.1) ∘ Ο• by rw [isComplement'_def, IsComplement, ← Equiv.bijective_comp Ο•] apply (congr_arg Function.Bijective hf).mp -- Porting note: This was a `rw` in mathlib3 rwa [ψ.comp_bijective] exact funext fun x => mul_inv_rev _ _ @[to_additive] theorem isComplement'_comm : IsComplement' H K ↔ IsComplement' K H := ⟨IsComplement'.symm, IsComplement'.symm⟩ @[to_additive] theorem isComplement_univ_singleton {g : G} : IsComplement (univ : Set G) {g} := ⟨fun ⟨_, _, rfl⟩ ⟨_, _, rfl⟩ h => Prod.ext (Subtype.ext (mul_right_cancel h)) rfl, fun x => ⟨⟨⟨x * g⁻¹, ⟨⟩⟩, g, rfl⟩, inv_mul_cancel_right x g⟩⟩ @[to_additive] theorem isComplement_singleton_univ {g : G} : IsComplement ({g} : Set G) univ := ⟨fun ⟨⟨_, rfl⟩, _⟩ ⟨⟨_, rfl⟩, _⟩ h => Prod.ext rfl (Subtype.ext (mul_left_cancel h)), fun x => ⟨⟨⟨g, rfl⟩, g⁻¹ * x, ⟨⟩⟩, mul_inv_cancel_left g x⟩⟩ @[to_additive] theorem isComplement_singleton_left {g : G} : IsComplement {g} S ↔ S = univ := by refine ⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => (congr_arg _ h).mpr isComplement_singleton_univ⟩ obtain ⟨⟨⟨z, rfl : z = g⟩, y, _⟩, hy⟩ := h.2 (g * x) rwa [← mul_left_cancel hy] @[to_additive] theorem isComplement_singleton_right {g : G} : IsComplement S {g} ↔ S = univ := by refine ⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => h β–Έ isComplement_univ_singleton⟩ obtain ⟨y, hy⟩ := h.2 (x * g) conv_rhs at hy => rw [← show y.2.1 = g from y.2.2] rw [← mul_right_cancel hy] exact y.1.2 @[to_additive] theorem isComplement_univ_left : IsComplement univ S ↔ βˆƒ g : G, S = {g} := by refine ⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩ Β· obtain ⟨a, _⟩ := h.2 1 exact ⟨a.2.1, a.2.2⟩ Β· have : (⟨⟨_, mem_top a⁻¹⟩, ⟨a, ha⟩⟩ : (⊀ : Set G) Γ— S) = ⟨⟨_, mem_top b⁻¹⟩, ⟨b, hb⟩⟩ := h.1 ((inv_mul_cancel a).trans (inv_mul_cancel b).symm) exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).2 Β· rintro ⟨g, rfl⟩ exact isComplement_univ_singleton @[to_additive] theorem isComplement_univ_right : IsComplement S univ ↔ βˆƒ g : G, S = {g} := by refine ⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩ Β· obtain ⟨a, _⟩ := h.2 1 exact ⟨a.1.1, a.1.2⟩ Β· have : (⟨⟨a, ha⟩, ⟨_, mem_top a⁻¹⟩⟩ : S Γ— (⊀ : Set G)) = ⟨⟨b, hb⟩, ⟨_, mem_top b⁻¹⟩⟩ := h.1 ((mul_inv_cancel a).trans (mul_inv_cancel b).symm) exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).1 Β· rintro ⟨g, rfl⟩ exact isComplement_singleton_univ @[to_additive] lemma IsComplement.mul_eq (h : IsComplement S T) : S * T = univ := eq_univ_of_forall fun x ↦ by simpa [mem_mul] using (h.existsUnique x).exists @[to_additive (attr := simp)] lemma not_isComplement_empty_left : Β¬ IsComplement βˆ… T := fun h ↦ by simpa [eq_comm (a := βˆ…)] using h.mul_eq @[to_additive (attr := simp)] lemma not_isComplement_empty_right : Β¬ IsComplement S βˆ… := fun h ↦ by simpa [eq_comm (a := βˆ…)] using h.mul_eq @[to_additive] lemma IsComplement.nonempty_left (hst : IsComplement S T) : S.Nonempty := by contrapose! hst; simp [hst] @[to_additive] lemma IsComplement.nonempty_right (hst : IsComplement S T) : T.Nonempty := by contrapose! hst; simp [hst] @[to_additive] lemma IsComplement.pairwiseDisjoint_smul (hst : IsComplement S T) : S.PairwiseDisjoint (Β· β€’ T) := fun a ha b hb hab ↦ disjoint_iff_forall_ne.2 <| by rintro _ ⟨c, hc, rfl⟩ _ ⟨d, hd, rfl⟩ exact hst.1.ne (a₁ := (⟨a, ha⟩, ⟨c, hc⟩)) (aβ‚‚:= (⟨b, hb⟩, ⟨d, hd⟩)) (by simp [hab]) @[to_additive AddSubgroup.IsComplement.card_mul_card] lemma IsComplement.card_mul_card (h : IsComplement S T) : Nat.card S * Nat.card T = Nat.card G := (Nat.card_prod _ _).symm.trans <| Nat.card_congr <| Equiv.ofBijective _ h @[to_additive] theorem isComplement'_top_bot : IsComplement' (⊀ : Subgroup G) βŠ₯ := isComplement_univ_singleton @[to_additive] theorem isComplement'_bot_top : IsComplement' (βŠ₯ : Subgroup G) ⊀ := isComplement_singleton_univ @[to_additive (attr := simp)] theorem isComplement'_bot_left : IsComplement' βŠ₯ H ↔ H = ⊀ := isComplement_singleton_left.trans coe_eq_univ @[to_additive (attr := simp)] theorem isComplement'_bot_right : IsComplement' H βŠ₯ ↔ H = ⊀ := isComplement_singleton_right.trans coe_eq_univ @[to_additive (attr := simp)] theorem isComplement'_top_left : IsComplement' ⊀ H ↔ H = βŠ₯ := isComplement_univ_left.trans coe_eq_singleton @[to_additive (attr := simp)] theorem isComplement'_top_right : IsComplement' H ⊀ ↔ H = βŠ₯ := isComplement_univ_right.trans coe_eq_singleton @[to_additive] lemma isComplement_iff_existsUnique_inv_mul_mem : IsComplement S T ↔ βˆ€ g, βˆƒ! s : S, (s : G)⁻¹ * g ∈ T := by convert isComplement_iff_existsUnique with g constructor <;> rintro ⟨x, hx, hx'⟩ Β· exact ⟨(x, ⟨_, hx⟩), by simp, by aesop⟩ Β· exact ⟨x.1, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (y, ⟨_, hy⟩)).1⟩ set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_iff_existsUnique_inv_mul_mem (since := "2024-12-18"))] theorem mem_leftTransversals_iff_existsUnique_inv_mul_mem : S ∈ leftTransversals T ↔ βˆ€ g : G, βˆƒ! s : S, (s : G)⁻¹ * g ∈ T := by rw [leftTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique] refine ⟨fun h g => ?_, fun h g => ?_⟩ Β· obtain ⟨x, h1, h2⟩ := h g exact ⟨x.1, (congr_arg (Β· ∈ T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, fun y hy => (Prod.ext_iff.mp (h2 ⟨y, (↑y)⁻¹ * g, hy⟩ (mul_inv_cancel_left ↑y g))).1⟩ Β· obtain ⟨x, h1, h2⟩ := h g refine ⟨⟨x, (↑x)⁻¹ * g, h1⟩, mul_inv_cancel_left (↑x) g, fun y hy => ?_⟩ have hf := h2 y.1 ((congr_arg (Β· ∈ T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2) exact Prod.ext hf (Subtype.ext (eq_inv_mul_of_mul_eq (hf β–Έ hy))) @[to_additive] lemma isComplement_iff_existsUnique_mul_inv_mem : IsComplement S T ↔ βˆ€ g, βˆƒ! t : T, g * (t : G)⁻¹ ∈ S := by convert isComplement_iff_existsUnique with g constructor <;> rintro ⟨x, hx, hx'⟩ Β· exact ⟨(⟨_, hx⟩, x), by simp, by aesop⟩ Β· exact ⟨x.2, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (⟨_, hy⟩, y)).2⟩ set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_iff_existsUnique_mul_inv_mem (since := "2024-12-18"))] theorem mem_rightTransversals_iff_existsUnique_mul_inv_mem : S ∈ rightTransversals T ↔ βˆ€ g : G, βˆƒ! s : S, g * (s : G)⁻¹ ∈ T := by rw [rightTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique] refine ⟨fun h g => ?_, fun h g => ?_⟩ Β· obtain ⟨x, h1, h2⟩ := h g exact ⟨x.2, (congr_arg (Β· ∈ T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, fun y hy => (Prod.ext_iff.mp (h2 ⟨⟨g * (↑y)⁻¹, hy⟩, y⟩ (inv_mul_cancel_right g y))).2⟩ Β· obtain ⟨x, h1, h2⟩ := h g refine ⟨⟨⟨g * (↑x)⁻¹, h1⟩, x⟩, inv_mul_cancel_right g x, fun y hy => ?_⟩ have hf := h2 y.2 ((congr_arg (Β· ∈ T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2) exact Prod.ext (Subtype.ext (eq_mul_inv_of_mul_eq (hf β–Έ hy))) hf @[to_additive] lemma isComplement_subgroup_right_iff_existsUnique_quotientGroupMk : IsComplement S H ↔ βˆ€ q : G β§Έ H, βˆƒ! s : S, QuotientGroup.mk s.1 = q := by simp_rw [isComplement_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq, QuotientGroup.forall_mk] set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_right_iff_existsUnique_quotientGroupMk (since := "2024-12-18"))] theorem mem_leftTransversals_iff_existsUnique_quotient_mk''_eq : S ∈ leftTransversals (H : Set G) ↔ βˆ€ q : Quotient (QuotientGroup.leftRel H), βˆƒ! s : S, Quotient.mk'' s.1 = q := by simp_rw [mem_leftTransversals_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq] exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩ set_option linter.docPrime false in @[to_additive] lemma isComplement_subgroup_left_iff_existsUnique_quotientMk'' : IsComplement H T ↔ βˆ€ q : Quotient (QuotientGroup.rightRel H), βˆƒ! t : T, Quotient.mk'' t.1 = q := by simp_rw [isComplement_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ← QuotientGroup.rightRel_apply, ← Quotient.eq'', Quotient.forall] set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_left_iff_existsUnique_quotientMk'' (since := "2024-12-18"))] theorem mem_rightTransversals_iff_existsUnique_quotient_mk''_eq : S ∈ rightTransversals (H : Set G) ↔ βˆ€ q : Quotient (QuotientGroup.rightRel H), βˆƒ! s : S, Quotient.mk'' s.1 = q := by simp_rw [mem_rightTransversals_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ← QuotientGroup.rightRel_apply, ← Quotient.eq''] exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩ @[to_additive] lemma isComplement_subgroup_right_iff_bijective : IsComplement S H ↔ Bijective (S.restrict (QuotientGroup.mk : G β†’ G β§Έ H)) := isComplement_subgroup_right_iff_existsUnique_quotientGroupMk.trans (bijective_iff_existsUnique (S.restrict QuotientGroup.mk)).symm set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_right_iff_bijective (since := "2024-12-18"))] theorem mem_leftTransversals_iff_bijective : S ∈ leftTransversals (H : Set G) ↔ Function.Bijective (S.restrict (Quotient.mk'' : G β†’ Quotient (QuotientGroup.leftRel H))) := mem_leftTransversals_iff_existsUnique_quotient_mk''_eq.trans (Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm @[to_additive] lemma isComplement_subgroup_left_iff_bijective : IsComplement H T ↔ Bijective (T.restrict (Quotient.mk'' : G β†’ Quotient (QuotientGroup.rightRel H))) := isComplement_subgroup_left_iff_existsUnique_quotientMk''.trans (bijective_iff_existsUnique (T.restrict Quotient.mk'')).symm set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_left_iff_bijective (since := "2024-12-18"))] theorem mem_rightTransversals_iff_bijective : S ∈ rightTransversals (H : Set G) ↔ Function.Bijective (S.restrict (Quotient.mk'' : G β†’ Quotient (QuotientGroup.rightRel H))) := mem_rightTransversals_iff_existsUnique_quotient_mk''_eq.trans (Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm @[to_additive] lemma IsComplement.card_left (h : IsComplement S H) : Nat.card S = H.index := Nat.card_congr <| .ofBijective _ <| isComplement_subgroup_right_iff_bijective.mp h set_option linter.deprecated false in @[to_additive (attr := deprecated IsComplement.card_left (since := "2024-12-18"))] theorem card_left_transversal (h : S ∈ leftTransversals (H : Set G)) : Nat.card S = H.index := Nat.card_congr <| Equiv.ofBijective _ <| mem_leftTransversals_iff_bijective.mp h @[to_additive] lemma IsComplement.card_right (h : IsComplement H T) : Nat.card T = H.index := Nat.card_congr <| (Equiv.ofBijective _ <| isComplement_subgroup_left_iff_bijective.mp h).trans <| QuotientGroup.quotientRightRelEquivQuotientLeftRel H set_option linter.deprecated false in @[to_additive (attr := deprecated IsComplement.card_right (since := "2024-12-18"))] theorem card_right_transversal (h : S ∈ rightTransversals (H : Set G)) : Nat.card S = H.index := Nat.card_congr <| (Equiv.ofBijective _ <| mem_rightTransversals_iff_bijective.mp h).trans <| QuotientGroup.quotientRightRelEquivQuotientLeftRel H @[to_additive] lemma isComplement_range_left {f : G β§Έ H β†’ G} (hf : βˆ€ q, ↑(f q) = q) : IsComplement (range f) H := by rw [isComplement_subgroup_right_iff_bijective] refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩ rintro ⟨-, q₁, rfl⟩ ⟨-, qβ‚‚, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf qβ‚‚) set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_range_left (since := "2024-12-18"))] theorem range_mem_leftTransversals {f : G β§Έ H β†’ G} (hf : βˆ€ q, ↑(f q) = q) : Set.range f ∈ leftTransversals (H : Set G) := mem_leftTransversals_iff_bijective.mpr ⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, qβ‚‚, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf qβ‚‚), fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩ @[to_additive] lemma isComplement_range_right {f : Quotient (QuotientGroup.rightRel H) β†’ G} (hf : βˆ€ q, Quotient.mk'' (f q) = q) : IsComplement H (range f) := by rw [isComplement_subgroup_left_iff_bijective] refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩ rintro ⟨-, q₁, rfl⟩ ⟨-, qβ‚‚, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf qβ‚‚) set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_range_right (since := "2024-12-18"))] theorem range_mem_rightTransversals {f : Quotient (QuotientGroup.rightRel H) β†’ G} (hf : βˆ€ q, Quotient.mk'' (f q) = q) : Set.range f ∈ rightTransversals (H : Set G) := mem_rightTransversals_iff_bijective.mpr ⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, qβ‚‚, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf qβ‚‚), fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩ @[to_additive] lemma exists_isComplement_left (H : Subgroup G) (g : G) : βˆƒ S, IsComplement S H ∧ g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_left fun q ↦ ?_, QuotientGroup.mk g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g Β· exact hq.symm β–Έ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) Β· refine Function.update_of_ne ?_ g Quotient.out β–Έ q.out_eq' exact hq set_option linter.deprecated false in @[to_additive (attr := deprecated exists_isComplement_left (since := "2024-12-18"))] lemma exists_left_transversal (H : Subgroup G) (g : G) : βˆƒ S ∈ leftTransversals (H : Set G), g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), range_mem_leftTransversals fun q => ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g Β· exact hq.symm β–Έ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) Β· refine (Function.update_of_ne ?_ g Quotient.out) β–Έ q.out_eq' exact hq @[to_additive] lemma exists_isComplement_right (H : Subgroup G) (g : G) : βˆƒ T, IsComplement H T ∧ g ∈ T := by classical refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_right fun q ↦ ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g Β· exact hq.symm β–Έ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) Β· refine Function.update_of_ne ?_ g Quotient.out β–Έ q.out_eq' exact hq set_option linter.deprecated false in @[to_additive (attr := deprecated exists_isComplement_right (since := "2024-12-18"))] lemma exists_right_transversal (H : Subgroup G) (g : G) : βˆƒ S ∈ rightTransversals (H : Set G), g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), range_mem_rightTransversals fun q => ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g Β· exact hq.symm β–Έ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) Β· exact Eq.trans (congr_arg _ (Function.update_of_ne hq g Quotient.out)) q.out_eq' /-- Given two subgroups `H' βŠ† H`, there exists a left transversal to `H'` inside `H`. -/ @[to_additive "Given two subgroups `H' βŠ† H`, there exists a transversal to `H'` inside `H`"] lemma exists_left_transversal_of_le {H' H : Subgroup G} (h : H' ≀ H) : βˆƒ S : Set G, S * H' = H ∧ Nat.card S * Nat.card H' = Nat.card H := by let H'' : Subgroup H := H'.comap H.subtype have : H' = H''.map H.subtype := by simp [H'', h] rw [this] obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_left 1 refine ⟨H.subtype '' S, ?_, ?_⟩ Β· have : H.subtype '' (S * H'') = H.subtype '' S * H''.map H.subtype := image_mul H.subtype rw [← this, cmem.mul_eq] simp [Set.ext_iff] Β· rw [← cmem.card_mul_card] refine congr_argβ‚‚ (Β· * Β·) ?_ ?_ <;> exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm /-- Given two subgroups `H' βŠ† H`, there exists a right transversal to `H'` inside `H`. -/ @[to_additive "Given two subgroups `H' βŠ† H`, there exists a transversal to `H'` inside `H`"] lemma exists_right_transversal_of_le {H' H : Subgroup G} (h : H' ≀ H) : βˆƒ S : Set G, H' * S = H ∧ Nat.card H' * Nat.card S = Nat.card H := by let H'' : Subgroup H := H'.comap H.subtype have : H' = H''.map H.subtype := by simp [H'', h] rw [this] obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_right 1 refine ⟨H.subtype '' S, ?_, ?_⟩ Β· have : H.subtype '' (H'' * S) = H''.map H.subtype * H.subtype '' S := image_mul H.subtype rw [← this, cmem.mul_eq] simp [Set.ext_iff] Β· have : Nat.card H'' * Nat.card S = Nat.card H := cmem.card_mul_card rw [← this] refine congr_argβ‚‚ (Β· * Β·) ?_ ?_ <;> exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm namespace IsComplement /-- The equivalence `G ≃ S Γ— T`, such that the inverse is `(*) : S Γ— T β†’ G` -/ noncomputable def equiv {S T : Set G} (hST : IsComplement S T) : G ≃ S Γ— T := (Equiv.ofBijective (fun x : S Γ— T => x.1.1 * x.2.1) hST).symm variable (hST : IsComplement S T) (hHT : IsComplement H T) (hSK : IsComplement S K) @[simp] theorem equiv_symm_apply (x : S Γ— T) : (hST.equiv.symm x : G) = x.1.1 * x.2.1 := rfl @[simp] theorem equiv_fst_mul_equiv_snd (g : G) : ↑(hST.equiv g).fst * (hST.equiv g).snd = g := (Equiv.ofBijective (fun x : S Γ— T => x.1.1 * x.2.1) hST).right_inv g theorem equiv_fst_eq_mul_inv (g : G) : ↑(hST.equiv g).fst = g * ((hST.equiv g).snd : G)⁻¹ := eq_mul_inv_of_mul_eq (hST.equiv_fst_mul_equiv_snd g) theorem equiv_snd_eq_inv_mul (g : G) : ↑(hST.equiv g).snd = ((hST.equiv g).fst : G)⁻¹ * g := eq_inv_mul_of_mul_eq (hST.equiv_fst_mul_equiv_snd g) theorem equiv_fst_eq_iff_leftCosetEquivalence {g₁ gβ‚‚ : G} : (hSK.equiv g₁).fst = (hSK.equiv gβ‚‚).fst ↔ LeftCosetEquivalence K g₁ gβ‚‚ := by rw [LeftCosetEquivalence, leftCoset_eq_iff] constructor Β· intro h rw [← hSK.equiv_fst_mul_equiv_snd gβ‚‚, ← hSK.equiv_fst_mul_equiv_snd g₁, ← h, mul_inv_rev, ← mul_assoc, inv_mul_cancel_right, ← coe_inv, ← coe_mul] exact Subtype.property _ Β· intro h apply (isComplement_iff_existsUnique_inv_mul_mem.1 hSK g₁).unique Β· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_fst_eq_mul_inv]; simp Β· rw [SetLike.mem_coe, ← mul_mem_cancel_right h] -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_fst_eq_mul_inv]; simp [equiv_fst_eq_mul_inv, ← mul_assoc] theorem equiv_snd_eq_iff_rightCosetEquivalence {g₁ gβ‚‚ : G} : (hHT.equiv g₁).snd = (hHT.equiv gβ‚‚).snd ↔ RightCosetEquivalence H g₁ gβ‚‚ := by rw [RightCosetEquivalence, rightCoset_eq_iff] constructor Β· intro h rw [← hHT.equiv_fst_mul_equiv_snd gβ‚‚, ← hHT.equiv_fst_mul_equiv_snd g₁, ← h, mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← coe_inv, ← coe_mul] exact Subtype.property _ Β· intro h apply (isComplement_iff_existsUnique_mul_inv_mem.1 hHT g₁).unique Β· -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_snd_eq_inv_mul]; simp Β· rw [SetLike.mem_coe, ← mul_mem_cancel_left h] -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_snd_eq_inv_mul, mul_assoc]; simp theorem leftCosetEquivalence_equiv_fst (g : G) : LeftCosetEquivalence K g ((hSK.equiv g).fst : G) := by -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_fst_eq_mul_inv]; simp [LeftCosetEquivalence, leftCoset_eq_iff] theorem rightCosetEquivalence_equiv_snd (g : G) : RightCosetEquivalence H g ((hHT.equiv g).snd : G) := by -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [RightCosetEquivalence, rightCoset_eq_iff, equiv_snd_eq_inv_mul]; simp theorem equiv_fst_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) : (hST.equiv g).fst = ⟨g, hg⟩ := by have : hST.equiv.symm (⟨g, hg⟩, ⟨1, h1⟩) = g := by rw [equiv, Equiv.ofBijective]; simp conv_lhs => rw [← this, Equiv.apply_symm_apply] theorem equiv_snd_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) : (hST.equiv g).snd = ⟨g, hg⟩ := by have : hST.equiv.symm (⟨1, h1⟩, ⟨g, hg⟩) = g := by rw [equiv, Equiv.ofBijective]; simp conv_lhs => rw [← this, Equiv.apply_symm_apply] theorem equiv_snd_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) : (hST.equiv g).snd = ⟨1, h1⟩ := by ext rw [equiv_snd_eq_inv_mul, equiv_fst_eq_self_of_mem_of_one_mem _ h1 hg, inv_mul_cancel] theorem equiv_fst_eq_one_of_mem_of_one_mem {g : G} (h1 : 1 ∈ S) (hg : g ∈ T) : (hST.equiv g).fst = ⟨1, h1⟩ := by ext rw [equiv_fst_eq_mul_inv, equiv_snd_eq_self_of_mem_of_one_mem _ h1 hg, mul_inv_cancel] theorem equiv_mul_right (g : G) (k : K) : hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * k) := by have : (hSK.equiv (g * k)).fst = (hSK.equiv g).fst := hSK.equiv_fst_eq_iff_leftCosetEquivalence.2 (by simp [LeftCosetEquivalence, leftCoset_eq_iff]) ext Β· rw [this] Β· rw [coe_mul, equiv_snd_eq_inv_mul, this, equiv_snd_eq_inv_mul, mul_assoc] theorem equiv_mul_right_of_mem {g k : G} (h : k ∈ K) : hSK.equiv (g * k) = ((hSK.equiv g).fst, (hSK.equiv g).snd * ⟨k, h⟩) := equiv_mul_right _ g ⟨k, h⟩ theorem equiv_mul_left (h : H) (g : G) : hHT.equiv (h * g) = (h * (hHT.equiv g).fst, (hHT.equiv g).snd) := by have : (hHT.equiv (h * g)).2 = (hHT.equiv g).2 := hHT.equiv_snd_eq_iff_rightCosetEquivalence.2 ?_ Β· ext Β· rw [coe_mul, equiv_fst_eq_mul_inv, this, equiv_fst_eq_mul_inv, mul_assoc] Β· rw [this] Β· simp [RightCosetEquivalence, ← smul_smul] theorem equiv_mul_left_of_mem {h g : G} (hh : h ∈ H) : hHT.equiv (h * g) = (⟨h, hh⟩ * (hHT.equiv g).fst, (hHT.equiv g).snd) := equiv_mul_left _ ⟨h, hh⟩ g theorem equiv_one (hs1 : 1 ∈ S) (ht1 : 1 ∈ T) : hST.equiv 1 = (⟨1, hs1⟩, ⟨1, ht1⟩) := by rw [Equiv.apply_eq_iff_eq_symm_apply]; simp [equiv] theorem equiv_fst_eq_self_iff_mem {g : G} (h1 : 1 ∈ T) : ((hST.equiv g).fst : G) = g ↔ g ∈ S := by constructor Β· intro h rw [← h] exact Subtype.prop _ Β· intro h rw [hST.equiv_fst_eq_self_of_mem_of_one_mem h1 h] theorem equiv_snd_eq_self_iff_mem {g : G} (h1 : 1 ∈ S) : ((hST.equiv g).snd : G) = g ↔ g ∈ T := by constructor Β· intro h rw [← h] exact Subtype.prop _ Β· intro h rw [hST.equiv_snd_eq_self_of_mem_of_one_mem h1 h] theorem coe_equiv_fst_eq_one_iff_mem {g : G} (h1 : 1 ∈ S) : ((hST.equiv g).fst : G) = 1 ↔ g ∈ T := by rw [equiv_fst_eq_mul_inv, mul_inv_eq_one, eq_comm, equiv_snd_eq_self_iff_mem _ h1] theorem coe_equiv_snd_eq_one_iff_mem {g : G} (h1 : 1 ∈ T) : ((hST.equiv g).snd : G) = 1 ↔ g ∈ S := by rw [equiv_snd_eq_inv_mul, inv_mul_eq_one, equiv_fst_eq_self_iff_mem _ h1] /-- A left transversal is in bijection with left cosets. -/ @[to_additive "A left transversal is in bijection with left cosets."] noncomputable def leftQuotientEquiv (hS : IsComplement S H) : G β§Έ H ≃ S := (Equiv.ofBijective _ (isComplement_subgroup_right_iff_bijective.mp hS)).symm @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.toEquiv := leftQuotientEquiv /-- A left transversal is finite iff the subgroup has finite index. -/ @[to_additive "A left transversal is finite iff the subgroup has finite index."] theorem finite_left_iff (h : IsComplement S H) : Finite S ↔ H.FiniteIndex := by rw [← h.leftQuotientEquiv.finite_iff] exact ⟨fun _ ↦ finiteIndex_of_finite_quotient, fun _ ↦ finite_quotient_of_finiteIndex⟩ @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.finite_iff := finite_left_iff @[to_additive] lemma finite_left [H.FiniteIndex] (hS : IsComplement S H) : S.Finite := hS.finite_left_iff.2 β€Ή_β€Ί @[to_additive] theorem quotientGroupMk_leftQuotientEquiv (hS : IsComplement S H) (q : G β§Έ H) : Quotient.mk'' (leftQuotientEquiv hS q : G) = q := hS.leftQuotientEquiv.symm_apply_apply q @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.mk''_toEquiv := quotientGroupMk_leftQuotientEquiv @[to_additive] theorem leftQuotientEquiv_apply {f : G β§Έ H β†’ G} (hf : βˆ€ q, (f q : G β§Έ H) = q) (q : G β§Έ H) : (leftQuotientEquiv (isComplement_range_left hf) q : G) = f q := by refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) ⟨q, rfl⟩) exact (leftQuotientEquiv (isComplement_range_left hf)).apply_eq_iff_eq_symm_apply.mpr (hf q).symm @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.toEquiv_apply := leftQuotientEquiv_apply /-- A left transversal can be viewed as a function mapping each element of the group to the chosen representative from that left coset. -/ @[to_additive "A left transversal can be viewed as a function mapping each element of the group to the chosen representative from that left coset."] noncomputable def toLeftFun (hS : IsComplement S H) : G β†’ S := leftQuotientEquiv hS ∘ Quotient.mk'' @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.toFun := toLeftFun @[to_additive] theorem inv_toLeftFun_mul_mem (hS : IsComplement S H) (g : G) : (toLeftFun hS g : G)⁻¹ * g ∈ H := QuotientGroup.leftRel_apply.mp <| Quotient.exact' <| quotientGroupMk_leftQuotientEquiv _ _ @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.inv_toFun_mul_mem := inv_toLeftFun_mul_mem @[to_additive] theorem inv_mul_toLeftFun_mem (hS : IsComplement S H) (g : G) : g⁻¹ * toLeftFun hS g ∈ H := (congr_arg (Β· ∈ H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (inv_toLeftFun_mul_mem hS g)) @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemLeftTransversals.inv_mul_toFun_mem := inv_mul_toLeftFun_mem /-- A right transversal is in bijection with right cosets. -/ @[to_additive "A right transversal is in bijection with right cosets."] noncomputable def rightQuotientEquiv (hT : IsComplement H T) : Quotient (QuotientGroup.rightRel H) ≃ T := (Equiv.ofBijective _ (isComplement_subgroup_left_iff_bijective.mp hT)).symm @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRightTransversals.toEquiv := rightQuotientEquiv /-- A right transversal is finite iff the subgroup has finite index. -/ @[to_additive "A right transversal is finite iff the subgroup has finite index."] theorem finite_right_iff (h : IsComplement H T) : Finite T ↔ H.FiniteIndex := by rw [← h.rightQuotientEquiv.finite_iff, (QuotientGroup.quotientRightRelEquivQuotientLeftRel H).finite_iff] exact ⟨fun _ ↦ finiteIndex_of_finite_quotient, fun _ ↦ finite_quotient_of_finiteIndex⟩ @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRightTransversals.finite_iff := finite_right_iff @[to_additive] lemma finite_right [H.FiniteIndex] (hT : IsComplement H T) : T.Finite := hT.finite_right_iff.2 β€Ή_β€Ί @[to_additive] theorem mk''_rightQuotientEquiv (hT : IsComplement H T) (q : Quotient (QuotientGroup.rightRel H)) : Quotient.mk'' (rightQuotientEquiv hT q : G) = q := (rightQuotientEquiv hT).symm_apply_apply q @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRightTransversals.mk''_toEquiv := mk''_rightQuotientEquiv @[to_additive] theorem rightQuotientEquiv_apply {f : Quotient (QuotientGroup.rightRel H) β†’ G} (hf : βˆ€ q, Quotient.mk'' (f q) = q) (q : Quotient (QuotientGroup.rightRel H)) : (rightQuotientEquiv (isComplement_range_right hf) q : G) = f q := by refine (Subtype.ext_iff.mp ?_).trans (Subtype.coe_mk (f q) ⟨q, rfl⟩) exact (rightQuotientEquiv (isComplement_range_right hf)).apply_eq_iff_eq_symm_apply.2 (hf q).symm @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRightTransversals.toEquiv_apply := rightQuotientEquiv_apply /-- A right transversal can be viewed as a function mapping each element of the group to the chosen representative from that right coset. -/ @[to_additive "A right transversal can be viewed as a function mapping each element of the group to the chosen representative from that right coset."] noncomputable def toRightFun (hT : IsComplement H T) : G β†’ T := rightQuotientEquiv hT ∘ .mk'' @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRightTransversals.toFun := toRightFun @[to_additive] theorem mul_inv_toRightFun_mem (hT : IsComplement H T) (g : G) : g * (toRightFun hT g : G)⁻¹ ∈ H := QuotientGroup.rightRel_apply.mp <| Quotient.exact' <| mk''_rightQuotientEquiv _ _ @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRighTransversals.mul_inv_toFun_mem := mul_inv_toRightFun_mem @[to_additive] theorem toRightFun_mul_inv_mem (hT : IsComplement H T) (g : G) : (toRightFun hT g : G) * g⁻¹ ∈ H := (congr_arg (Β· ∈ H) (by rw [mul_inv_rev, inv_inv])).mp (H.inv_mem (mul_inv_toRightFun_mem hT g)) @[deprecated (since := "2024-12-28")] alias _root_.Subgroup.MemRighTransversals.toFun_mul_inv_mem := toRightFun_mul_inv_mem end IsComplement section Action open Pointwise MulAction MemLeftTransversals
/-- The collection of left transversals of a subgroup -/ @[to_additive "The collection of left transversals of a subgroup."] abbrev LeftTransversal (H : Subgroup G) := {S : Set G // IsComplement S H} /-- The collection of right transversals of a subgroup -/
Mathlib/GroupTheory/Complement.lean
713
717
/- Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Instances.RealVectorSpace import Mathlib.Topology.LocallyConstant.Basic /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≀ B x` or `β€–f xβ€– ≀ B x` from upper estimates on `f'` or `β€–f'β€–`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `β€–f xβ€– = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `β€–f x - f aβ€– ≀ C * β€–x - aβ€–`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by change Icc a b βŠ† { x | f x ≀ B x } set s := { x | f x ≀ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prodMk hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≀ B x, xab⟩ y hy rcases hxB.lt_or_eq with hxB | hxB Β· -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsGT hy)) have : βˆ€αΆ  x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : βˆ€αΆ  x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsGT_of_mem xab) this exact this.mono fun y => le_of_lt Β· rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : βˆ€αΆ  z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : βˆƒ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := hf'.and_eventually (HB.and (Ioc_mem_nhdsGT hy)) |>.exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_iff_of_pos_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≀ B' x` (bound : βˆ€ x ∈ Ico a b, βˆ€ r, B' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope f x z < r) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := by have Hr : βˆ€ x ∈ Icc a b, βˆ€ r > 0, f x ≀ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound Β· rwa [sub_self, mul_zero, add_zero] Β· exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) Β· intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) Β· intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, f x = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≀ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≀ B' x` on `[a, b)`. Then `f x ≀ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ β†’ ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : f a ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, f' x ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ f x ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) /-! ### Vector-valued functions `f : ℝ β†’ E` -/ section variable {f : ℝ β†’ E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(β€–f zβ€– - β€–f xβ€–) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ β†’ E} {f' : ℝ β†’ ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (β€–f zβ€– - β€–f xβ€–) / (z - x) ≀ f' x` (hf' : βˆ€ x ∈ Ico a b, βˆ€ r, f' x < r β†’ βˆƒαΆ  z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ f' x < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `β€–f xβ€– = B x`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f xβ€– = B x β†’ β€–f' xβ€– < B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : ContinuousOn B (Icc a b)) (hB' : βˆ€ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `β€–f aβ€– ≀ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `β€–f' xβ€– ≀ B x` everywhere on `[a, b)`. Then `β€–f xβ€– ≀ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ β†’ E} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ β†’ ℝ} (ha : β€–f aβ€– ≀ B a) (hB : βˆ€ x, HasDerivAt B (B' x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ B' x) : βˆ€ ⦃x⦄, x ∈ Icc a b β†’ β€–f xβ€– ≀ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ β†’ E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simp [g, hf' x hx] let B x := C * (x - a) have hB : βˆ€ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : βˆ€ x ∈ Ico a b, β€–f' xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hx) /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `β€–f x - f aβ€– ≀ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ C) : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ β†’ E} {C : ℝ} (hf : βˆ€ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–f' xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `β€–f 1 - f 0β€– ≀ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : βˆ€ x ∈ Ico (0 : ℝ) 1, β€–derivWithin f (Icc (0 : ℝ) 1) xβ€– ≀ C) : β€–f 1 - f 0β€– ≀ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : βˆ€ x ∈ Icc a b, f x = f a := by have : βˆ€ x ∈ Icc a b, β€–f x - f aβ€– ≀ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : βˆ€ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : βˆ€ x ∈ Icc a b, f x = f a := by have H : βˆ€ x ∈ Ico a b, β€–derivWithin f (Icc a b) xβ€– ≀ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx variable {f' g : ℝ β†’ E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : βˆ€ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : βˆ€ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊒ exact hi β–Έ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : βˆ€ y ∈ Icc a b, f y = g y := by have A : βˆ€ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) have B : βˆ€ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem_nhdsWithin (Icc_mem_nhdsGE_of_mem hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm β–Έ B y hy) fdiff.continuousOn gdiff.continuousOn hi end /-! ### Vector-valued functions `f : E β†’ G` Theorems in this section work both for real and complex differentiable functions. We use assumptions `[NontriviallyNormedField π•œ] [IsRCLikeNormedField π•œ] [NormedSpace π•œ E] [NormedSpace π•œ G]` to achieve this result. For the domain `E` we also assume `[NormedSpace ℝ E]` to have a notion of a `Convex` set. -/ section namespace Convex variable {π•œ G : Type*} [NontriviallyNormedField π•œ] [IsRCLikeNormedField π•œ] [NormedSpace π•œ E] [NormedAddCommGroup G] [NormedSpace π•œ G] {f g : E β†’ G} {C : ℝ} {s : Set E} {x y : E} {f' g' : E β†’ E β†’L[π•œ] G} {Ο† : E β†’L[π•œ] G} instance (priority := 100) : PathConnectedSpace π•œ := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ infer_instance /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ letI : NormedSpace ℝ G := RestrictScalars.normedSpace ℝ π•œ G /- By composition with `AffineMap.lineMap x y`, we reduce to a statement for functions defined on `[0,1]`, for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`. We just have to check the differentiability of the composition and bounds on its derivative, which is straightforward but tedious for lack of automation. -/ set g := (AffineMap.lineMap x y : ℝ β†’ E) have segm : MapsTo g (Icc 0 1 : Set ℝ) s := hs.mapsTo_lineMap xs ys have hD : βˆ€ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt (f ∘ g) (f' (g t) (y - x)) (Icc 0 1) t := fun t ht => by simpa using ((hf (g t) (segm ht)).restrictScalars ℝ).comp_hasDerivWithinAt _ AffineMap.hasDerivWithinAt_lineMap segm have bound : βˆ€ t ∈ Ico (0 : ℝ) 1, β€–f' (g t) (y - x)β€– ≀ C * β€–y - xβ€– := fun t ht => le_of_opNorm_le _ (bound _ <| segm <| Ico_subset_Icc_self ht) _ simpa [g] using norm_image_sub_le_of_norm_deriv_le_segment_01' hD bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `HasFDerivWithinAt` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_hasFDerivWithin_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := by rw [lipschitzOnWith_iff_norm_sub_le] intro x x_in y y_in exact hs.norm_image_sub_le_of_norm_hasFDerivWithin_le hf bound y_in x_in /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is `K`-Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt` for a version that claims existence of `K` instead of an explicit estimate. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) (K : ℝβ‰₯0) (hK : β€–f' xβ€–β‚Š < K) : βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := by obtain ⟨Ρ, Ξ΅0, hΡ⟩ : βˆƒ Ξ΅ > 0, ball x Ξ΅ ∩ s βŠ† { y | HasFDerivWithinAt f (f' y) s y ∧ β€–f' yβ€–β‚Š < K } := mem_nhdsWithin_iff.1 (hder.and <| hcont.nnnorm.eventually (gt_mem_nhds hK)) rw [inter_comm] at hΞ΅ refine ⟨s ∩ ball x Ξ΅, inter_mem_nhdsWithin _ (ball_mem_nhds _ Ξ΅0), ?_⟩ exact (hs.inter (convex_ball _ _)).lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun y hy => (hΞ΅ hy).1.mono inter_subset_left) fun y hy => (hΞ΅ hy).2.le /-- Let `s` be a convex set in a real normed vector space `E`, let `f : E β†’ G` be a function differentiable within `s` in a neighborhood of `x : E` with derivative `f'`. Suppose that `f'` is continuous within `s` at `x`. Then for any number `K : ℝβ‰₯0` larger than `β€–f' xβ€–β‚Š`, `f` is Lipschitz on some neighborhood of `x` within `s`. See also `Convex.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt` for a version with an explicit estimate on the Lipschitz constant. -/ theorem exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt (hs : Convex ℝ s) {f : E β†’ G} (hder : βˆ€αΆ  y in 𝓝[s] x, HasFDerivWithinAt f (f' y) s y) (hcont : ContinuousWithinAt f' s x) : βˆƒ K, βˆƒ t ∈ 𝓝[s] x, LipschitzOnWith K f t := (exists_gt _).imp <| hs.exists_nhdsWithin_lipschitzOnWith_of_hasFDerivWithinAt_of_nnnorm_lt hder hcont /-- The mean value theorem on a convex set: if the derivative of a function within this set is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderivWithin` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderivWithin_le {C : ℝβ‰₯0} (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivWithinAt) bound /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f xβ€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- The mean value theorem on a convex set: if the derivative of a function is bounded by `C` on `s`, then the function is `C`-Lipschitz on `s`. Version with `fderiv` and `LipschitzOnWith`. -/ theorem lipschitzOnWith_of_nnnorm_fderiv_le {C : ℝβ‰₯0} (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f xβ€–β‚Š ≀ C) (hs : Convex ℝ s) : LipschitzOnWith C f s := hs.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound /-- The mean value theorem: if the derivative of a function is bounded by `C`, then the function is `C`-Lipschitz. Version with `fderiv` and `LipschitzWith`. -/ theorem _root_.lipschitzWith_of_nnnorm_fderiv_le {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} {C : ℝβ‰₯0} (hf : Differentiable π•œ f) (bound : βˆ€ x, β€–fderiv π•œ f xβ€–β‚Š ≀ C) : LipschitzWith C f := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E rw [← lipschitzOnWith_univ] exact lipschitzOnWith_of_nnnorm_fderiv_le (fun x _ ↦ hf x) (fun x _ ↦ bound x) convex_univ /-- Variant of the mean value inequality on a convex set, using a bound on the difference between the derivative and a fixed linear map, rather than a bound on the derivative itself. Version with `HasFDerivWithinAt`. -/ theorem norm_image_sub_le_of_norm_hasFDerivWithin_le' (hf : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (bound : βˆ€ x ∈ s, β€–f' x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := by /- We subtract `Ο†` to define a new function `g` for which `g' = 0`, for which the previous theorem applies, `Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le`. Then, we just need to glue together the pieces, expressing back `f` in terms of `g`. -/ let g y := f y - Ο† y have hg : βˆ€ x ∈ s, HasFDerivWithinAt g (f' x - Ο†) s x := fun x xs => (hf x xs).sub Ο†.hasFDerivWithinAt calc β€–f y - f x - Ο† (y - x)β€– = β€–f y - f x - (Ο† y - Ο† x)β€– := by simp _ = β€–f y - Ο† y - (f x - Ο† x)β€– := by congr 1; abel _ = β€–g y - g xβ€– := by simp [g] _ ≀ C * β€–y - xβ€– := Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le hg bound hs xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderivWithin`. -/ theorem norm_image_sub_le_of_norm_fderivWithin_le' (hf : DifferentiableOn π•œ f s) (bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivWithinAt) bound xs ys /-- Variant of the mean value inequality on a convex set. Version with `fderiv`. -/ theorem norm_image_sub_le_of_norm_fderiv_le' (hf : βˆ€ x ∈ s, DifferentiableAt π•œ f x) (bound : βˆ€ x ∈ s, β€–fderiv π•œ f x - Ο†β€– ≀ C) (hs : Convex ℝ s) (xs : x ∈ s) (ys : y ∈ s) : β€–f y - f x - Ο† (y - x)β€– ≀ C * β€–y - xβ€– := hs.norm_image_sub_le_of_norm_hasFDerivWithin_le' (fun x hx => (hf x hx).hasFDerivAt.hasFDerivWithinAt) bound xs ys /-- If a function has zero FrΓ©chet derivative at every point of a convex set, then it is a constant on this set. -/ theorem is_const_of_fderivWithin_eq_zero (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hf' : βˆ€ x ∈ s, fderivWithin π•œ f s x = 0) (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by have bound : βˆ€ x ∈ s, β€–fderivWithin π•œ f s xβ€– ≀ 0 := fun x hx => by simp only [hf' x hx, norm_zero, le_rfl] simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm] using hs.norm_image_sub_le_of_norm_fderivWithin_le hf bound hx hy theorem _root_.is_const_of_fderiv_eq_zero {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f : E β†’ G} (hf : Differentiable π•œ f) (hf' : βˆ€ x, fderiv π•œ f x = 0) (x y : E) : f x = f y := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E exact convex_univ.is_const_of_fderivWithin_eq_zero hf.differentiableOn (fun x _ => by rw [fderivWithin_univ]; exact hf' x) trivial trivial /-- If two functions have equal FrΓ©chet derivatives at every point of a convex set, and are equal at one point in that set, then they are equal on that set. -/ theorem eqOn_of_fderivWithin_eq (hs : Convex ℝ s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hs' : UniqueDiffOn π•œ s) (hf' : s.EqOn (fderivWithin π•œ f s) (fderivWithin π•œ g s)) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := fun y hy => by suffices f x - g x = f y - g y by rwa [hfgx, sub_self, eq_comm, sub_eq_zero] at this refine hs.is_const_of_fderivWithin_eq_zero (hf.sub hg) (fun z hz => ?_) hx hy rw [fderivWithin_sub (hs' _ hz) (hf _ hz) (hg _ hz), sub_eq_zero, hf' hz] /-- If `f` has zero derivative on an open set, then `f` is locally constant on `s`. -/ -- TODO: change the spelling once we have `IsLocallyConstantOn`. theorem _root_.IsOpen.isOpen_inter_preimage_of_fderiv_eq_zero (hs : IsOpen s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) (t : Set G) : IsOpen (s ∩ f ⁻¹' t) := by refine Metric.isOpen_iff.mpr fun y ⟨hy, hy'⟩ ↦ ?_ obtain ⟨r, hr, h⟩ := Metric.isOpen_iff.mp hs y hy refine ⟨r, hr, Set.subset_inter h fun x hx ↦ ?_⟩ have := (convex_ball y r).is_const_of_fderivWithin_eq_zero (hf.mono h) ?_ hx (mem_ball_self hr) Β· simpa [this] Β· intro z hz simpa only [fderivWithin_of_isOpen Metric.isOpen_ball hz] using hf' (h hz) theorem _root_.isLocallyConstant_of_fderiv_eq_zero (h₁ : Differentiable π•œ f) (hβ‚‚ : βˆ€ x, fderiv π•œ f x = 0) : IsLocallyConstant f := by simpa using isOpen_univ.isOpen_inter_preimage_of_fderiv_eq_zero h₁.differentiableOn fun _ _ ↦ hβ‚‚ _ /-- If `f` has zero derivative on a connected open set, then `f` is constant on `s`. -/ theorem _root_.IsOpen.exists_is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) : βˆƒ a, βˆ€ x ∈ s, f x = a := by obtain (rfl|⟨y, hy⟩) := s.eq_empty_or_nonempty Β· exact ⟨0, by simp⟩ Β· refine ⟨f y, fun x hx ↦ ?_⟩ have h₁ := hs.isOpen_inter_preimage_of_fderiv_eq_zero hf hf' {f y} have hβ‚‚ := hf.continuousOn.comp_continuous continuous_subtype_val (fun x ↦ x.2) by_contra h₃ obtain ⟨t, ht, ht'⟩ := (isClosed_singleton (x := f y)).preimage hβ‚‚ have ht'' : βˆ€ a ∈ s, a ∈ t ↔ f a β‰  f y := by simpa [Set.ext_iff] using ht' obtain ⟨z, H₁, Hβ‚‚, Hβ‚ƒβŸ© := hs' _ _ h₁ ht (fun x h ↦ by simp [h, ht'', eq_or_ne]) ⟨y, by simpa⟩ ⟨x, by simp [ht'' _ hx, hx, h₃]⟩ exact (ht'' _ H₁).mp H₃ Hβ‚‚.2 theorem _root_.IsOpen.is_const_of_fderiv_eq_zero (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hf' : s.EqOn (fderiv π•œ f) 0) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : f x = f y := by obtain ⟨a, ha⟩ := hs.exists_is_const_of_fderiv_eq_zero hs' hf hf' rw [ha x hx, ha y hy] theorem _root_.IsOpen.exists_eq_add_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hf' : s.EqOn (fderiv π•œ f) (fderiv π•œ g)) : βˆƒ a, s.EqOn f (g Β· + a) := by simp_rw [Set.EqOn, ← sub_eq_iff_eq_add'] refine hs.exists_is_const_of_fderiv_eq_zero hs' (hf.sub hg) fun x hx ↦ ?_ rw [fderiv_sub (hf.differentiableAt (hs.mem_nhds hx)) (hg.differentiableAt (hs.mem_nhds hx)), hf' hx, sub_self, Pi.zero_apply] /-- If two functions have equal FrΓ©chet derivatives at every point of a connected open set, and are equal at one point in that set, then they are equal on that set. -/ theorem _root_.IsOpen.eqOn_of_fderiv_eq (hs : IsOpen s) (hs' : IsPreconnected s) (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) (hf' : βˆ€ x ∈ s, fderiv π•œ f x = fderiv π•œ g x) (hx : x ∈ s) (hfgx : f x = g x) : s.EqOn f g := by obtain ⟨a, ha⟩ := hs.exists_eq_add_of_fderiv_eq hs' hf hg hf' obtain rfl := left_eq_add.mp (hfgx.symm.trans (ha hx)) simpa using ha theorem _root_.eq_of_fderiv_eq {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] {f g : E β†’ G} (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) (hf' : βˆ€ x, fderiv π•œ f x = fderiv π•œ g x) (x : E) (hfgx : f x = g x) : f = g := by letI : RCLike π•œ := IsRCLikeNormedField.rclike π•œ let A : NormedSpace ℝ E := RestrictScalars.normedSpace ℝ π•œ E suffices Set.univ.EqOn f g from funext fun x => this <| mem_univ x exact convex_univ.eqOn_of_fderivWithin_eq hf.differentiableOn hg.differentiableOn uniqueDiffOn_univ (fun x _ => by simpa using hf' _) (mem_univ _) hfgx lemma isLittleO_pow_succ {xβ‚€ : E} {n : β„•} (hs : Convex ℝ s) (hxβ‚€s : xβ‚€ ∈ s) (hff' : βˆ€ x ∈ s, HasFDerivWithinAt f (f' x) s x) (hf' : f' =o[𝓝[s] xβ‚€] fun x ↦ β€–x - xβ‚€β€– ^ n) : (fun x ↦ f x - f xβ‚€) =o[𝓝[s] xβ‚€] fun x ↦ β€–x - xβ‚€β€– ^ (n + 1) := by rw [Asymptotics.isLittleO_iff] at hf' ⊒ intro c hc simp_rw [norm_pow, pow_succ, ← mul_assoc, norm_norm] simp_rw [norm_pow, norm_norm] at hf'
have : βˆ€αΆ  x in 𝓝[s] xβ‚€, segment ℝ xβ‚€ x βŠ† s ∧ βˆ€ y ∈ segment ℝ xβ‚€ x, β€–f' yβ€– ≀ c * β€–x - xβ‚€β€– ^ n := by have h1 : βˆ€αΆ  x in 𝓝[s] xβ‚€, x ∈ s := eventually_mem_nhdsWithin filter_upwards [h1, hs.eventually_nhdsWithin_segment hxβ‚€s (hf' hc)] with x hxs h refine ⟨hs.segment_subset hxβ‚€s hxs, fun y hy ↦ (h y hy).trans ?_⟩ gcongr
Mathlib/Analysis/Calculus/MeanValue.lean
655
659