Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2014 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Group.Support import Mathlib.Algebra.Order.Monoid.WithTop import Mathlib.Data.Nat.Cast.Field #align_import algebra.char_zero.lemmas from "leanprover-community/mathlib"@"acee671f47b8e7972a1eb6f4eed74b4b3abce829" /-! # Characteristic zero (additional theorems) A ring `R` is called of characteristic zero if every natural number `n` is non-zero when considered as an element of `R`. Since this definition doesn't mention the multiplicative structure of `R` except for the existence of `1` in this file characteristic zero is defined for additive monoids with `1`. ## Main statements * Characteristic zero implies that the additive monoid is infinite. -/ open Function Set namespace Nat variable {R : Type*} [AddMonoidWithOne R] [CharZero R] /-- `Nat.cast` as an embedding into monoids of characteristic `0`. -/ @[simps] def castEmbedding : ℕ ↪ R := ⟨Nat.cast, cast_injective⟩ #align nat.cast_embedding Nat.castEmbedding #align nat.cast_embedding_apply Nat.castEmbedding_apply @[simp] theorem cast_pow_eq_one {R : Type*} [Semiring R] [CharZero R] (q : ℕ) (n : ℕ) (hn : n ≠ 0) : (q : R) ^ n = 1 ↔ q = 1 := by rw [← cast_pow, cast_eq_one] exact pow_eq_one_iff hn #align nat.cast_pow_eq_one Nat.cast_pow_eq_one @[simp, norm_cast] theorem cast_div_charZero {k : Type*} [DivisionSemiring k] [CharZero k] {m n : ℕ} (n_dvd : n ∣ m) : ((m / n : ℕ) : k) = m / n := by rcases eq_or_ne n 0 with (rfl | hn) · simp · exact cast_div n_dvd (cast_ne_zero.2 hn) #align nat.cast_div_char_zero Nat.cast_div_charZero end Nat section AddMonoidWithOne variable {α M : Type*} [AddMonoidWithOne M] [CharZero M] {n : ℕ} instance CharZero.NeZero.two : NeZero (2 : M) := ⟨by have : ((2 : ℕ) : M) ≠ 0 := Nat.cast_ne_zero.2 (by decide) rwa [Nat.cast_two] at this⟩ #align char_zero.ne_zero.two CharZero.NeZero.two namespace Function lemma support_natCast (hn : n ≠ 0) : support (n : α → M) = univ := support_const <| Nat.cast_ne_zero.2 hn #align function.support_nat_cast Function.support_natCast @[deprecated (since := "2024-04-17")] alias support_nat_cast := support_natCast lemma mulSupport_natCast (hn : n ≠ 1) : mulSupport (n : α → M) = univ := mulSupport_const <| Nat.cast_ne_one.2 hn #align function.mul_support_nat_cast Function.mulSupport_natCast @[deprecated (since := "2024-04-17")] alias mulSupport_nat_cast := mulSupport_natCast end Function end AddMonoidWithOne section variable {R : Type*} [NonAssocSemiring R] [NoZeroDivisors R] [CharZero R] {a : R} @[simp] theorem add_self_eq_zero {a : R} : a + a = 0 ↔ a = 0 := by simp only [(two_mul a).symm, mul_eq_zero, two_ne_zero, false_or_iff] #align add_self_eq_zero add_self_eq_zero set_option linter.deprecated false @[simp] theorem bit0_eq_zero {a : R} : bit0 a = 0 ↔ a = 0 := add_self_eq_zero #align bit0_eq_zero bit0_eq_zero @[simp] theorem zero_eq_bit0 {a : R} : 0 = bit0 a ↔ a = 0 := by rw [eq_comm] exact bit0_eq_zero #align zero_eq_bit0 zero_eq_bit0 theorem bit0_ne_zero : bit0 a ≠ 0 ↔ a ≠ 0 := bit0_eq_zero.not #align bit0_ne_zero bit0_ne_zero theorem zero_ne_bit0 : 0 ≠ bit0 a ↔ a ≠ 0 := zero_eq_bit0.not #align zero_ne_bit0 zero_ne_bit0 end section variable {R : Type*} [NonAssocRing R] [NoZeroDivisors R] [CharZero R] @[simp] theorem neg_eq_self_iff {a : R} : -a = a ↔ a = 0 := neg_eq_iff_add_eq_zero.trans add_self_eq_zero #align neg_eq_self_iff neg_eq_self_iff @[simp] theorem eq_neg_self_iff {a : R} : a = -a ↔ a = 0 := eq_neg_iff_add_eq_zero.trans add_self_eq_zero #align eq_neg_self_iff eq_neg_self_iff theorem nat_mul_inj {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) : n = 0 ∨ a = b := by rw [← sub_eq_zero, ← mul_sub, mul_eq_zero, sub_eq_zero] at h exact mod_cast h #align nat_mul_inj nat_mul_inj theorem nat_mul_inj' {n : ℕ} {a b : R} (h : (n : R) * a = (n : R) * b) (w : n ≠ 0) : a = b := by simpa [w] using nat_mul_inj h #align nat_mul_inj' nat_mul_inj' set_option linter.deprecated false theorem bit0_injective : Function.Injective (bit0 : R → R) := fun a b h => by dsimp [bit0] at h simp only [(two_mul a).symm, (two_mul b).symm] at h refine nat_mul_inj' ?_ two_ne_zero exact mod_cast h #align bit0_injective bit0_injective theorem bit1_injective : Function.Injective (bit1 : R → R) := fun a b h => by simp only [bit1, add_left_inj] at h exact bit0_injective h #align bit1_injective bit1_injective @[simp] theorem bit0_eq_bit0 {a b : R} : bit0 a = bit0 b ↔ a = b := bit0_injective.eq_iff #align bit0_eq_bit0 bit0_eq_bit0 @[simp] theorem bit1_eq_bit1 {a b : R} : bit1 a = bit1 b ↔ a = b := bit1_injective.eq_iff #align bit1_eq_bit1 bit1_eq_bit1 @[simp] theorem bit1_eq_one {a : R} : bit1 a = 1 ↔ a = 0 := by rw [show (1 : R) = bit1 0 by simp, bit1_eq_bit1] #align bit1_eq_one bit1_eq_one @[simp] theorem one_eq_bit1 {a : R} : 1 = bit1 a ↔ a = 0 := by rw [eq_comm] exact bit1_eq_one #align one_eq_bit1 one_eq_bit1 end section variable {R : Type*} [DivisionRing R] [CharZero R] @[simp] lemma half_add_self (a : R) : (a + a) / 2 = a := by rw [← mul_two, mul_div_cancel_right₀ a two_ne_zero] #align half_add_self half_add_self @[simp]
Mathlib/Algebra/CharZero/Lemmas.lean
182
182
theorem add_halves' (a : R) : a / 2 + a / 2 = a := by
rw [← add_div, half_add_self]
/- 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.Init.Control.Combinators import Mathlib.Data.Option.Defs import Mathlib.Logic.IsEmpty import Mathlib.Logic.Relator import Mathlib.Util.CompileInductive import Aesop #align_import data.option.basic from "leanprover-community/mathlib"@"f340f229b1f461aa1c8ee11e0a172d0a3b301a4a" /-! # Option of a type This file develops the basic theory of option types. If `α` is a type, then `Option α` can be understood as the type with one more element than `α`. `Option α` has terms `some a`, where `a : α`, and `none`, which is the added element. This is useful in multiple ways: * It is the prototype of addition of terms to a type. See for example `WithBot α` which uses `none` as an element smaller than all others. * It can be used to define failsafe partial functions, which return `some the_result_we_expect` if we can find `the_result_we_expect`, and `none` if there is no meaningful result. This forces any subsequent use of the partial function to explicitly deal with the exceptions that make it return `none`. * `Option` is a monad. We love monads. `Part` is an alternative to `Option` that can be seen as the type of `True`/`False` values along with a term `a : α` if the value is `True`. -/ universe u namespace Option variable {α β γ δ : Type*} theorem coe_def : (fun a ↦ ↑a : α → Option α) = some := rfl #align option.coe_def Option.coe_def theorem mem_map {f : α → β} {y : β} {o : Option α} : y ∈ o.map f ↔ ∃ x ∈ o, f x = y := by simp #align option.mem_map Option.mem_map -- The simpNF linter says that the LHS can be simplified via `Option.mem_def`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Function.Injective f) {a : α} {o : Option α} : f a ∈ o.map f ↔ a ∈ o := by aesop theorem forall_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∀ y ∈ o.map f, p y) ↔ ∀ x ∈ o, p (f x) := by simp #align option.forall_mem_map Option.forall_mem_map theorem exists_mem_map {f : α → β} {o : Option α} {p : β → Prop} : (∃ y ∈ o.map f, p y) ↔ ∃ x ∈ o, p (f x) := by simp #align option.exists_mem_map Option.exists_mem_map theorem coe_get {o : Option α} (h : o.isSome) : ((Option.get _ h : α) : Option α) = o := Option.some_get h #align option.coe_get Option.coe_get theorem eq_of_mem_of_mem {a : α} {o1 o2 : Option α} (h1 : a ∈ o1) (h2 : a ∈ o2) : o1 = o2 := h1.trans h2.symm #align option.eq_of_mem_of_mem Option.eq_of_mem_of_mem theorem Mem.leftUnique : Relator.LeftUnique ((· ∈ ·) : α → Option α → Prop) := fun _ _ _=> mem_unique #align option.mem.left_unique Option.Mem.leftUnique theorem some_injective (α : Type*) : Function.Injective (@some α) := fun _ _ ↦ some_inj.mp #align option.some_injective Option.some_injective /-- `Option.map f` is injective if `f` is injective. -/ theorem map_injective {f : α → β} (Hf : Function.Injective f) : Function.Injective (Option.map f) | none, none, _ => rfl | some a₁, some a₂, H => by rw [Hf (Option.some.inj H)] #align option.map_injective Option.map_injective @[simp] theorem map_comp_some (f : α → β) : Option.map f ∘ some = some ∘ f := rfl #align option.map_comp_some Option.map_comp_some @[simp] theorem none_bind' (f : α → Option β) : none.bind f = none := rfl #align option.none_bind' Option.none_bind' @[simp] theorem some_bind' (a : α) (f : α → Option β) : (some a).bind f = f a := rfl #align option.some_bind' Option.some_bind' theorem bind_eq_some' {x : Option α} {f : α → Option β} {b : β} : x.bind f = some b ↔ ∃ a, x = some a ∧ f a = some b := by cases x <;> simp #align option.bind_eq_some' Option.bind_eq_some' #align option.bind_eq_none' Option.bind_eq_none' theorem bind_congr {f g : α → Option β} {x : Option α} (h : ∀ a ∈ x, f a = g a) : x.bind f = x.bind g := by cases x <;> simp only [some_bind, none_bind, mem_def, h] @[congr] theorem bind_congr' {f g : α → Option β} {x y : Option α} (hx : x = y) (hf : ∀ a ∈ y, f a = g a) : x.bind f = y.bind g := hx.symm ▸ bind_congr hf theorem joinM_eq_join : joinM = @join α := funext fun _ ↦ rfl #align option.join_eq_join Option.joinM_eq_join theorem bind_eq_bind' {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f := rfl #align option.bind_eq_bind Option.bind_eq_bind' theorem map_coe {α β} {a : α} {f : α → β} : f <$> (a : Option α) = ↑(f a) := rfl #align option.map_coe Option.map_coe @[simp] theorem map_coe' {a : α} {f : α → β} : Option.map f (a : Option α) = ↑(f a) := rfl #align option.map_coe' Option.map_coe' /-- `Option.map` as a function between functions is injective. -/ theorem map_injective' : Function.Injective (@Option.map α β) := fun f g h ↦ funext fun x ↦ some_injective _ <| by simp only [← map_some', h] #align option.map_injective' Option.map_injective' @[simp] theorem map_inj {f g : α → β} : Option.map f = Option.map g ↔ f = g := map_injective'.eq_iff #align option.map_inj Option.map_inj attribute [simp] map_id @[simp] theorem map_eq_id {f : α → α} : Option.map f = id ↔ f = id := map_injective'.eq_iff' map_id #align option.map_eq_id Option.map_eq_id theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ} (h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : (Option.map f₁ a).map g₁ = (Option.map f₂ a).map g₂ := by rw [map_map, h, ← map_map] #align option.map_comm Option.map_comm section pmap variable {p : α → Prop} (f : ∀ a : α, p a → β) (x : Option α) -- Porting note: Can't simp tag this anymore because `pbind` simplifies -- @[simp] theorem pbind_eq_bind (f : α → Option β) (x : Option α) : (x.pbind fun a _ ↦ f a) = x.bind f := by cases x <;> simp only [pbind, none_bind', some_bind'] #align option.pbind_eq_bind Option.pbind_eq_bind theorem map_bind {α β γ} (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x >>= g) = x >>= fun a ↦ Option.map f (g a) := by simp only [← map_eq_map, ← bind_pure_comp, LawfulMonad.bind_assoc] #align option.map_bind Option.map_bind theorem map_bind' (f : β → γ) (x : Option α) (g : α → Option β) : Option.map f (x.bind g) = x.bind fun a ↦ Option.map f (g a) := by cases x <;> simp #align option.map_bind' Option.map_bind' theorem map_pbind (f : β → γ) (x : Option α) (g : ∀ a, a ∈ x → Option β) : Option.map f (x.pbind g) = x.pbind fun a H ↦ Option.map f (g a H) := by cases x <;> simp only [pbind, map_none'] #align option.map_pbind Option.map_pbind theorem pbind_map (f : α → β) (x : Option α) (g : ∀ b : β, b ∈ x.map f → Option γ) : pbind (Option.map f x) g = x.pbind fun a h ↦ g (f a) (mem_map_of_mem _ h) := by cases x <;> rfl #align option.pbind_map Option.pbind_map @[simp] theorem pmap_none (f : ∀ a : α, p a → β) {H} : pmap f (@none α) H = none := rfl #align option.pmap_none Option.pmap_none @[simp] theorem pmap_some (f : ∀ a : α, p a → β) {x : α} (h : p x) : pmap f (some x) = fun _ ↦ some (f x h) := rfl #align option.pmap_some Option.pmap_some theorem mem_pmem {a : α} (h : ∀ a ∈ x, p a) (ha : a ∈ x) : f a (h a ha) ∈ pmap f x h := by rw [mem_def] at ha ⊢ subst ha rfl #align option.mem_pmem Option.mem_pmem theorem pmap_map (g : γ → α) (x : Option γ) (H) : pmap f (x.map g) H = pmap (fun a h ↦ f (g a) h) x fun a h ↦ H _ (mem_map_of_mem _ h) := by cases x <;> simp only [map_none', map_some', pmap] #align option.pmap_map Option.pmap_map theorem map_pmap (g : β → γ) (f : ∀ a, p a → β) (x H) : Option.map g (pmap f x H) = pmap (fun a h ↦ g (f a h)) x H := by cases x <;> simp only [map_none', map_some', pmap] #align option.map_pmap Option.map_pmap -- Porting note: Can't simp tag this anymore because `pmap` simplifies -- @[simp] theorem pmap_eq_map (p : α → Prop) (f : α → β) (x H) : @pmap _ _ p (fun a _ ↦ f a) x H = Option.map f x := by cases x <;> simp only [map_none', map_some', pmap] #align option.pmap_eq_map Option.pmap_eq_map theorem pmap_bind {α β γ} {x : Option α} {g : α → Option β} {p : β → Prop} {f : ∀ b, p b → γ} (H) (H' : ∀ (a : α), ∀ b ∈ g a, b ∈ x >>= g) : pmap f (x >>= g) H = x >>= fun a ↦ pmap f (g a) fun b h ↦ H _ (H' a _ h) := by cases x <;> simp only [pmap, bind_eq_bind, none_bind, some_bind] #align option.pmap_bind Option.pmap_bind theorem bind_pmap {α β γ} {p : α → Prop} (f : ∀ a, p a → β) (x : Option α) (g : β → Option γ) (H) : pmap f x H >>= g = x.pbind fun a h ↦ g (f a (H _ h)) := by cases x <;> simp only [pmap, bind_eq_bind, none_bind, some_bind, pbind] #align option.bind_pmap Option.bind_pmap variable {f x} theorem pbind_eq_none {f : ∀ a : α, a ∈ x → Option β} (h' : ∀ a (H : a ∈ x), f a H = none → x = none) : x.pbind f = none ↔ x = none := by cases x · simp · simp only [pbind, iff_false] intro h cases h' _ rfl h #align option.pbind_eq_none Option.pbind_eq_none theorem pbind_eq_some {f : ∀ a : α, a ∈ x → Option β} {y : β} : x.pbind f = some y ↔ ∃ (z : α) (H : z ∈ x), f z H = some y := by rcases x with (_|x) · simp only [pbind, false_iff, not_exists] intro z h simp at h · simp only [pbind] refine ⟨fun h ↦ ⟨x, rfl, h⟩, ?_⟩ rintro ⟨z, H, hz⟩ simp only [mem_def, Option.some_inj] at H simpa [H] using hz #align option.pbind_eq_some Option.pbind_eq_some -- Porting note: Can't simp tag this anymore because `pmap` simplifies -- @[simp] theorem pmap_eq_none_iff {h} : pmap f x h = none ↔ x = none := by cases x <;> simp #align option.pmap_eq_none_iff Option.pmap_eq_none_iff -- Porting note: Can't simp tag this anymore because `pmap` simplifies -- @[simp] theorem pmap_eq_some_iff {hf} {y : β} : pmap f x hf = some y ↔ ∃ (a : α) (H : x = some a), f a (hf a H) = y := by rcases x with (_|x) · simp only [not_mem_none, exists_false, pmap, not_false_iff, exists_prop_of_false] · constructor · intro h simp only [pmap, Option.some_inj] at h exact ⟨x, rfl, h⟩ · rintro ⟨a, H, rfl⟩ simp only [mem_def, Option.some_inj] at H simp only [H, pmap] #align option.pmap_eq_some_iff Option.pmap_eq_some_iff -- Porting note: Can't simp tag this anymore because `join` and `pmap` simplify -- @[simp] theorem join_pmap_eq_pmap_join {f : ∀ a, p a → β} {x : Option (Option α)} (H) : (pmap (pmap f) x H).join = pmap f x.join fun a h ↦ H (some a) (mem_of_mem_join h) _ rfl := by rcases x with (_ | _ | x) <;> simp #align option.join_pmap_eq_pmap_join Option.join_pmap_eq_pmap_join end pmap @[simp] theorem seq_some {α β} {a : α} {f : α → β} : some f <*> some a = some (f a) := rfl #align option.seq_some Option.seq_some @[simp] theorem some_orElse' (a : α) (x : Option α) : (some a).orElse (fun _ ↦ x) = some a := rfl #align option.some_orelse' Option.some_orElse' #align option.some_orelse Option.some_orElse @[simp] theorem none_orElse' (x : Option α) : none.orElse (fun _ ↦ x) = x := by cases x <;> rfl #align option.none_orelse' Option.none_orElse' #align option.none_orelse Option.none_orElse @[simp] theorem orElse_none' (x : Option α) : x.orElse (fun _ ↦ none) = x := by cases x <;> rfl #align option.orelse_none' Option.orElse_none' #align option.orelse_none Option.orElse_none #align option.is_some_none Option.isSome_none #align option.is_some_some Option.isSome_some #align option.is_some_iff_exists Option.isSome_iff_exists #align option.is_none_none Option.isNone_none #align option.is_none_some Option.isNone_some #align option.not_is_some Option.not_isSome #align option.not_is_some_iff_eq_none Option.not_isSome_iff_eq_none #align option.ne_none_iff_is_some Option.ne_none_iff_isSome theorem exists_ne_none {p : Option α → Prop} : (∃ x ≠ none, p x) ↔ (∃ x : α, p x) := by simp only [← exists_prop, bex_ne_none] @[simp] theorem isSome_map (f : α → β) (o : Option α) : isSome (o.map f) = isSome o := by cases o <;> rfl @[simp] theorem get_map (f : α → β) {o : Option α} (h : isSome (o.map f)) : (o.map f).get h = f (o.get (by rwa [← isSome_map])) := by cases o <;> [simp at h; rfl] theorem iget_mem [Inhabited α] : ∀ {o : Option α}, isSome o → o.iget ∈ o | some _, _ => rfl #align option.iget_mem Option.iget_mem theorem iget_of_mem [Inhabited α] {a : α} : ∀ {o : Option α}, a ∈ o → o.iget = a | _, rfl => rfl #align option.iget_of_mem Option.iget_of_mem theorem getD_default_eq_iget [Inhabited α] (o : Option α) : o.getD default = o.iget := by cases o <;> rfl #align option.get_or_else_default_eq_iget Option.getD_default_eq_iget @[simp] theorem guard_eq_some' {p : Prop} [Decidable p] (u) : _root_.guard p = some u ↔ p := by cases u by_cases h : p <;> simp [_root_.guard, h] #align option.guard_eq_some' Option.guard_eq_some' theorem liftOrGet_choice {f : α → α → α} (h : ∀ a b, f a b = a ∨ f a b = b) : ∀ o₁ o₂, liftOrGet f o₁ o₂ = o₁ ∨ liftOrGet f o₁ o₂ = o₂ | none, none => Or.inl rfl | some a, none => Or.inl rfl | none, some b => Or.inr rfl | some a, some b => by simpa [liftOrGet] using h a b #align option.lift_or_get_choice Option.liftOrGet_choice #align option.lift_or_get_none_left Option.liftOrGet_none_left #align option.lift_or_get_none_right Option.liftOrGet_none_right #align option.lift_or_get_some_some Option.liftOrGet_some_some /-- Given an element of `a : Option α`, a default element `b : β` and a function `α → β`, apply this function to `a` if it comes from `α`, and return `b` otherwise. -/ def casesOn' : Option α → β → (α → β) → β | none, n, _ => n | some a, _, s => s a #align option.cases_on' Option.casesOn' @[simp] theorem casesOn'_none (x : β) (f : α → β) : casesOn' none x f = x := rfl #align option.cases_on'_none Option.casesOn'_none @[simp] theorem casesOn'_some (x : β) (f : α → β) (a : α) : casesOn' (some a) x f = f a := rfl #align option.cases_on'_some Option.casesOn'_some @[simp] theorem casesOn'_coe (x : β) (f : α → β) (a : α) : casesOn' (a : Option α) x f = f a := rfl #align option.cases_on'_coe Option.casesOn'_coe -- Porting note: Left-hand side does not simplify. -- @[simp] theorem casesOn'_none_coe (f : Option α → β) (o : Option α) : casesOn' o (f none) (f ∘ (fun a ↦ ↑a)) = f o := by cases o <;> rfl #align option.cases_on'_none_coe Option.casesOn'_none_coe lemma casesOn'_eq_elim (b : β) (f : α → β) (a : Option α) : Option.casesOn' a b f = Option.elim a b f := by cases a <;> rfl -- porting note: workaround for leanprover/lean4#2049 compile_inductive% Option theorem orElse_eq_some (o o' : Option α) (x : α) : (o <|> o') = some x ↔ o = some x ∨ o = none ∧ o' = some x := by cases o · simp only [true_and, false_or, eq_self_iff_true, none_orElse] · simp only [some_orElse, or_false, false_and] #align option.orelse_eq_some Option.orElse_eq_some theorem orElse_eq_some' (o o' : Option α) (x : α) : o.orElse (fun _ ↦ o') = some x ↔ o = some x ∨ o = none ∧ o' = some x := Option.orElse_eq_some o o' x #align option.orelse_eq_some' Option.orElse_eq_some' @[simp] theorem orElse_eq_none (o o' : Option α) : (o <|> o') = none ↔ o = none ∧ o' = none := by cases o · simp only [true_and, none_orElse, eq_self_iff_true] · simp only [some_orElse, false_and] #align option.orelse_eq_none Option.orElse_eq_none @[simp] theorem orElse_eq_none' (o o' : Option α) : o.orElse (fun _ ↦ o') = none ↔ o = none ∧ o' = none := Option.orElse_eq_none o o' #align option.orelse_eq_none' Option.orElse_eq_none' section open scoped Classical theorem choice_eq_none (α : Type*) [IsEmpty α] : choice α = none := dif_neg (not_nonempty_iff_imp_false.mpr isEmptyElim) #align option.choice_eq_none Option.choice_eq_none #align option.choice_is_some_iff_nonempty Option.choice_isSome_iff_nonempty end -- Porting note: Can't simp tag this anymore because `elim` simplifies -- @[simp] theorem elim_none_some (f : Option α → β) : (fun x ↦ Option.elim x (f none) (f ∘ some)) = f := funext fun o ↦ by cases o <;> rfl #align option.elim_none_some Option.elim_none_some theorem elim_comp (h : α → β) {f : γ → α} {x : α} {i : Option γ} : (i.elim (h x) fun j => h (f j)) = h (i.elim x f) := by cases i <;> rfl
Mathlib/Data/Option/Basic.lean
446
448
theorem elim_comp₂ (h : α → β → γ) {f : γ → α} {x : α} {g : γ → β} {y : β} {i : Option γ} : (i.elim (h x y) fun j => h (f j) (g j)) = h (i.elim x f) (i.elim y g) := by
cases i <;> rfl
/- 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, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). 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 pre-game is built inductively from two families of pre-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. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right
Mathlib/SetTheory/Game/PGame.lean
952
957
theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by
constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.MeasureTheory.Measure.ProbabilityMeasure import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Layercake import Mathlib.MeasureTheory.Integral.BoundedContinuousFunction #align_import measure_theory.measure.portmanteau from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # Characterizations of weak convergence of finite measures and probability measures This file will provide portmanteau characterizations of the weak convergence of finite measures and of probability measures, i.e., the standard characterizations of convergence in distribution. ## Main definitions The topologies of weak convergence on the types of finite measures and probability measures are already defined in their corresponding files; no substantial new definitions are introduced here. ## Main results The main result will be the portmanteau theorem providing various characterizations of the weak convergence of measures (probability measures or finite measures). Given measures μs and μ on a topological space Ω, the conditions that will be proven equivalent (under quite general hypotheses) are: (T) The measures μs tend to the measure μ weakly. (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). The separate implications are: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` is the implication (T) → (C). * `MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge` is the equivalence (C) ↔ (O). * `MeasureTheory.tendsto_measure_of_null_frontier` is the implication (O) → (B). * `MeasureTheory.limsup_measure_closed_le_of_forall_tendsto_measure` is the implication (B) → (C). * `MeasureTheory.tendsto_of_forall_isOpen_le_liminf` gives the implication (O) → (T) for any sequence of Borel probability measures. ## Implementation notes Many of the characterizations of weak convergence hold for finite measures and are proven in that generality and then specialized to probability measures. Some implications hold with slightly more general assumptions than in the usual statement of portmanteau theorem. The full portmanteau theorem, however, is most convenient for probability measures on pseudo-emetrizable spaces with their Borel sigma algebras. Some specific considerations on the assumptions in the different implications: * `MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto` assumes `PseudoEMetricSpace`. The only reason is to have bounded continuous pointwise approximations to the indicator function of a closed set. Clearly for example metrizability or pseudo-emetrizability would be sufficient assumptions. The typeclass assumptions should be later adjusted in a way that takes into account use cases, but the proof will presumably remain essentially the same. * Where formulations are currently only provided for probability measures, one can obtain the finite measure formulations using the characterization of convergence of finite measures by their total masses and their probability-normalized versions, i.e., by `MeasureTheory.FiniteMeasure.tendsto_normalize_iff_tendsto`. ## References * [Billingsley, *Convergence of probability measures*][billingsley1999] ## Tags weak convergence of measures, convergence in distribution, convergence in law, finite measure, probability measure -/ noncomputable section open MeasureTheory Set Filter BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction namespace MeasureTheory section LimsupClosedLEAndLELiminfOpen /-! ### Portmanteau: limsup condition for closed sets iff liminf condition for open sets In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, the following two conditions are equivalent: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). Either of these will later be shown to be equivalent to the weak convergence of the sequence of measures. -/ variable {Ω : Type*} [MeasurableSpace Ω] /-- **Portmanteau theorem** -/ theorem le_measure_compl_liminf_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i E) ≤ μ E) : μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [liminf_bot, le_top] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] have obs : (L.liminf fun i : ι => 1 - μs i E) = L.liminf ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl rw [obs] have := antitone_const_tsub.map_limsup_of_continuousAt (F := L) (fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simp_rw [← this] exact antitone_const_tsub h #align measure_theory.le_measure_compl_liminf_of_limsup_measure_le MeasureTheory.le_measure_compl_liminf_of_limsup_measure_le theorem le_measure_liminf_of_limsup_measure_compl_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : (L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ) : μ E ≤ L.liminf fun i => μs i E := compl_compl E ▸ le_measure_compl_liminf_of_limsup_measure_le (MeasurableSet.compl E_mble) h #align measure_theory.le_measure_liminf_of_limsup_measure_compl_le MeasureTheory.le_measure_liminf_of_limsup_measure_compl_le theorem limsup_measure_compl_le_of_le_liminf_measure {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ E ≤ L.liminf fun i => μs i E) : (L.limsup fun i => μs i Eᶜ) ≤ μ Eᶜ := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] have meas_Ec : μ Eᶜ = 1 - μ E := by simpa only [measure_univ] using measure_compl E_mble (measure_lt_top μ E).ne have meas_i_Ec : ∀ i, μs i Eᶜ = 1 - μs i E := by intro i simpa only [measure_univ] using measure_compl E_mble (measure_lt_top (μs i) E).ne simp_rw [meas_Ec, meas_i_Ec] have obs : (L.limsup fun i : ι => 1 - μs i E) = L.limsup ((fun x => 1 - x) ∘ fun i : ι => μs i E) := rfl rw [obs] have := antitone_const_tsub.map_liminf_of_continuousAt (F := L) (fun i => μs i E) (ENNReal.continuous_sub_left ENNReal.one_ne_top).continuousAt simp_rw [← this] exact antitone_const_tsub h #align measure_theory.limsup_measure_compl_le_of_le_liminf_measure MeasureTheory.limsup_measure_compl_le_of_le_liminf_measure theorem limsup_measure_le_of_le_liminf_measure_compl {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] {E : Set Ω} (E_mble : MeasurableSet E) (h : μ Eᶜ ≤ L.liminf fun i => μs i Eᶜ) : (L.limsup fun i => μs i E) ≤ μ E := compl_compl E ▸ limsup_measure_compl_le_of_le_liminf_measure (MeasurableSet.compl E_mble) h #align measure_theory.limsup_measure_le_of_le_liminf_measure_compl MeasureTheory.limsup_measure_le_of_le_liminf_measure_compl variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One pair of implications of the portmanteau theorem: For a sequence of Borel probability measures, the following two are equivalent: (C) The limsup of the measures of any closed set is at most the measure of the closed set under a candidate limit measure. (O) The liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure. -/ theorem limsup_measure_closed_le_iff_liminf_measure_open_ge {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] : (∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F) ↔ ∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G := by constructor · intro h G G_open exact le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h Gᶜ (isClosed_compl_iff.mpr G_open)) · intro h F F_closed exact limsup_measure_le_of_le_liminf_measure_compl F_closed.measurableSet (h Fᶜ (isOpen_compl_iff.mpr F_closed)) #align measure_theory.limsup_measure_closed_le_iff_liminf_measure_open_ge MeasureTheory.limsup_measure_closed_le_iff_liminf_measure_open_ge end LimsupClosedLEAndLELiminfOpen -- section section TendstoOfNullFrontier /-! ### Portmanteau: limit of measures of Borel sets whose boundary carries no mass in the limit In this section we prove that for a sequence of Borel probability measures on a topological space and its candidate limit measure, either of the following equivalent conditions: (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F); (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G). implies that (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ variable {Ω : Type*} [MeasurableSpace Ω] theorem tendsto_measure_of_le_liminf_measure_of_limsup_measure_le {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} {E₀ E E₁ : Set Ω} (E₀_subset : E₀ ⊆ E) (subset_E₁ : E ⊆ E₁) (nulldiff : μ (E₁ \ E₀) = 0) (h_E₀ : μ E₀ ≤ L.liminf fun i => μs i E₀) (h_E₁ : (L.limsup fun i => μs i E₁) ≤ μ E₁) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) := by apply tendsto_of_le_liminf_of_limsup_le · have E₀_ae_eq_E : E₀ =ᵐ[μ] E := EventuallyLE.antisymm E₀_subset.eventuallyLE (subset_E₁.eventuallyLE.trans (ae_le_set.mpr nulldiff)) calc μ E = μ E₀ := measure_congr E₀_ae_eq_E.symm _ ≤ L.liminf fun i => μs i E₀ := h_E₀ _ ≤ L.liminf fun i => μs i E := liminf_le_liminf (eventually_of_forall fun _ => measure_mono E₀_subset) · have E_ae_eq_E₁ : E =ᵐ[μ] E₁ := EventuallyLE.antisymm subset_E₁.eventuallyLE ((ae_le_set.mpr nulldiff).trans E₀_subset.eventuallyLE) calc (L.limsup fun i => μs i E) ≤ L.limsup fun i => μs i E₁ := limsup_le_limsup (eventually_of_forall fun _ => measure_mono subset_E₁) _ ≤ μ E₁ := h_E₁ _ = μ E := measure_congr E_ae_eq_E₁.symm · infer_param · infer_param #align measure_theory.tendsto_measure_of_le_liminf_measure_of_limsup_measure_le MeasureTheory.tendsto_measure_of_le_liminf_measure_of_limsup_measure_le variable [TopologicalSpace Ω] [OpensMeasurableSpace Ω] /-- One implication of the portmanteau theorem: For a sequence of Borel probability measures, if the liminf of the measures of any open set is at least the measure of the open set under a candidate limit measure, then for any set whose boundary carries no probability mass under the candidate limit measure, then its measures under the sequence converge to its measure under the candidate limit measure. -/ theorem tendsto_measure_of_null_frontier {ι : Type*} {L : Filter ι} {μ : Measure Ω} {μs : ι → Measure Ω} [IsProbabilityMeasure μ] [∀ i, IsProbabilityMeasure (μs i)] (h_opens : ∀ G, IsOpen G → μ G ≤ L.liminf fun i => μs i G) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : L.Tendsto (fun i => μs i E) (𝓝 (μ E)) := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i => μs i F) ≤ μ F := limsup_measure_closed_le_iff_liminf_measure_open_ge.mpr h_opens tendsto_measure_of_le_liminf_measure_of_limsup_measure_le interior_subset subset_closure E_nullbdry (h_opens _ isOpen_interior) (h_closeds _ isClosed_closure) #align measure_theory.tendsto_measure_of_null_frontier MeasureTheory.tendsto_measure_of_null_frontier end TendstoOfNullFrontier --section section ConvergenceImpliesLimsupClosedLE /-! ### Portmanteau implication: weak convergence implies a limsup condition for closed sets In this section we prove, under the assumption that the underlying topological space `Ω` is pseudo-emetrizable, that (T) The measures μs tend to the measure μ weakly implies (C) For any closed set F, the limsup of the measures of F under μs is at most the measure of F under μ, i.e., limsupᵢ μsᵢ(F) ≤ μ(F). Combining with a earlier proven implications, we get that (T) implies also both (O) For any open set G, the liminf of the measures of G under μs is at least the measure of G under μ, i.e., μ(G) ≤ liminfᵢ μsᵢ(G); (B) For any Borel set B whose boundary carries no mass under μ, i.e. μ(∂B) = 0, the measures of B under μs tend to the measure of B under μ, i.e., limᵢ μsᵢ(B) = μ(B). -/ /-- One implication of the portmanteau theorem: Weak convergence of finite measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit measure. -/ theorem FiniteMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [HasOuterApproxClosed Ω] [OpensMeasurableSpace Ω] {μ : FiniteMeasure Ω} {μs : ι → FiniteMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by rcases L.eq_or_neBot with rfl | hne · simp only [limsup_bot, bot_le] apply ENNReal.le_of_forall_pos_le_add intro ε ε_pos _ let fs := F_closed.apprSeq have key₁ : Tendsto (fun n ↦ ∫⁻ ω, (fs n ω : ℝ≥0∞) ∂μ) atTop (𝓝 ((μ : Measure Ω) F)) := HasOuterApproxClosed.tendsto_lintegral_apprSeq F_closed (μ : Measure Ω) have room₁ : (μ : Measure Ω) F < (μ : Measure Ω) F + ε / 2 := by apply ENNReal.lt_add_right (measure_lt_top (μ : Measure Ω) F).ne (ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm rcases eventually_atTop.mp (eventually_lt_of_tendsto_lt room₁ key₁) with ⟨M, hM⟩ have key₂ := FiniteMeasure.tendsto_iff_forall_lintegral_tendsto.mp μs_lim (fs M) have room₂ : (lintegral (μ : Measure Ω) fun a => fs M a) < (lintegral (μ : Measure Ω) fun a => fs M a) + ε / 2 := by apply ENNReal.lt_add_right (ne_of_lt ?_) (ENNReal.div_pos_iff.mpr ⟨(ENNReal.coe_pos.mpr ε_pos).ne.symm, ENNReal.two_ne_top⟩).ne.symm apply BoundedContinuousFunction.lintegral_lt_top_of_nnreal have ev_near := Eventually.mono (eventually_lt_of_tendsto_lt room₂ key₂) fun n => le_of_lt have ev_near' := Eventually.mono ev_near (fun n ↦ le_trans (HasOuterApproxClosed.measure_le_lintegral F_closed (μs n) M)) apply (Filter.limsup_le_limsup ev_near').trans rw [limsup_const] apply le_trans (add_le_add (hM M rfl.le).le (le_refl (ε / 2 : ℝ≥0∞))) simp only [add_assoc, ENNReal.add_halves, le_refl] #align measure_theory.finite_measure.limsup_measure_closed_le_of_tendsto MeasureTheory.FiniteMeasure.limsup_measure_closed_le_of_tendsto /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the limsup of the measures of any closed set is at most the measure of the closed set under the limit probability measure. -/ theorem ProbabilityMeasure.limsup_measure_closed_le_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [TopologicalSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {F : Set Ω} (F_closed : IsClosed F) : (L.limsup fun i => (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := by apply FiniteMeasure.limsup_measure_closed_le_of_tendsto ((ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds L).mp μs_lim) F_closed #align measure_theory.probability_measure.limsup_measure_closed_le_of_tendsto MeasureTheory.ProbabilityMeasure.limsup_measure_closed_le_of_tendsto /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that the liminf of the measures of any open set is at least the measure of the open set under the limit probability measure. -/ theorem ProbabilityMeasure.le_liminf_measure_open_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {G : Set Ω} (G_open : IsOpen G) : (μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G := haveI h_closeds : ∀ F, IsClosed F → (L.limsup fun i ↦ (μs i : Measure Ω) F) ≤ (μ : Measure Ω) F := fun _ F_closed => ProbabilityMeasure.limsup_measure_closed_le_of_tendsto μs_lim F_closed le_measure_liminf_of_limsup_measure_compl_le G_open.measurableSet (h_closeds _ (isClosed_compl_iff.mpr G_open)) #align measure_theory.probability_measure.le_liminf_measure_open_of_tendsto MeasureTheory.ProbabilityMeasure.le_liminf_measure_open_of_tendsto theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : (μ : Measure Ω) (frontier E) = 0) : Tendsto (fun i => (μs i : Measure Ω) E) L (𝓝 ((μ : Measure Ω) E)) := haveI h_opens : ∀ G, IsOpen G → (μ : Measure Ω) G ≤ L.liminf fun i => (μs i : Measure Ω) G := fun _ G_open => ProbabilityMeasure.le_liminf_measure_open_of_tendsto μs_lim G_open tendsto_measure_of_null_frontier h_opens E_nullbdry #align measure_theory.probability_measure.tendsto_measure_of_null_frontier_of_tendsto' MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' /-- One implication of the portmanteau theorem: Weak convergence of probability measures implies that if the boundary of a Borel set carries no probability mass under the limit measure, then the limit of the measures of the set equals the measure of the set under the limit probability measure. A version with coercions to ordinary `ℝ≥0∞`-valued measures is `MeasureTheory.ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto'`. -/
Mathlib/MeasureTheory/Measure/Portmanteau.lean
360
367
theorem ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto {Ω ι : Type*} {L : Filter ι} [MeasurableSpace Ω] [PseudoEMetricSpace Ω] [OpensMeasurableSpace Ω] [HasOuterApproxClosed Ω] {μ : ProbabilityMeasure Ω} {μs : ι → ProbabilityMeasure Ω} (μs_lim : Tendsto μs L (𝓝 μ)) {E : Set Ω} (E_nullbdry : μ (frontier E) = 0) : Tendsto (fun i => μs i E) L (𝓝 (μ E)) := by
have E_nullbdry' : (μ : Measure Ω) (frontier E) = 0 := by rw [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure, E_nullbdry, ENNReal.coe_zero] have key := ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' μs_lim E_nullbdry' exact (ENNReal.tendsto_toNNReal (measure_ne_top (↑μ) E)).comp key
/- 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.Topology.MetricSpace.HausdorffDistance #align_import topology.metric_space.pi_nat from "leanprover-community/mathlib"@"49b7f94aab3a3bdca1f9f34c5d818afb253b3993" /-! # Topological study of spaces `Π (n : ℕ), E n` When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space (with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure. However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one can put a noncanonical metric space structure (or rather, several of them). This is done in this file. ## Main definitions and results One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows: * `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`. * `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`. * `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology. * `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an instance. This space is a complete metric space. * `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an instance * `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance. These results are used to construct continuous functions on `Π n, E n`: * `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s` restricting to the identity on `s`. * `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto this space. One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete in general), and `ι` is countable. * `PiCountable.dist` is the distance on `Π i, E i` given by `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. * `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that the uniformity is definitionally the product uniformity. Not registered as an instance. -/ noncomputable section open scoped Classical open Topology Filter open TopologicalSpace Set Metric Filter Function attribute [local simp] pow_le_pow_iff_right one_lt_two inv_le_inv zero_le_two zero_lt_two variable {E : ℕ → Type*} namespace PiNat /-! ### The firstDiff function -/ /-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y` differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/ irreducible_def firstDiff (x y : ∀ n, E n) : ℕ := if h : x ≠ y then Nat.find (ne_iff.1 h) else 0 #align pi_nat.first_diff PiNat.firstDiff theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) : x (firstDiff x y) ≠ y (firstDiff x y) := by rw [firstDiff_def, dif_pos h] exact Nat.find_spec (ne_iff.1 h) #align pi_nat.apply_first_diff_ne PiNat.apply_firstDiff_ne theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by rw [firstDiff_def] at hn split_ifs at hn with h · convert Nat.find_min (ne_iff.1 h) hn simp · exact (not_lt_zero' hn).elim #align pi_nat.apply_eq_of_lt_first_diff PiNat.apply_eq_of_lt_firstDiff theorem firstDiff_comm (x y : ∀ n, E n) : firstDiff x y = firstDiff y x := by simp only [firstDiff_def, ne_comm] #align pi_nat.first_diff_comm PiNat.firstDiff_comm theorem min_firstDiff_le (x y z : ∀ n, E n) (h : x ≠ z) : min (firstDiff x y) (firstDiff y z) ≤ firstDiff x z := by by_contra! H rw [lt_min_iff] at H refine apply_firstDiff_ne h ?_ calc x (firstDiff x z) = y (firstDiff x z) := apply_eq_of_lt_firstDiff H.1 _ = z (firstDiff x z) := apply_eq_of_lt_firstDiff H.2 #align pi_nat.min_first_diff_le PiNat.min_firstDiff_le /-! ### Cylinders -/ /-- In a product space `Π n, E n`, the cylinder set of length `n` around `x`, denoted `cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e., such that `y i = x i` for all `i < n`. -/ def cylinder (x : ∀ n, E n) (n : ℕ) : Set (∀ n, E n) := { y | ∀ i, i < n → y i = x i } #align pi_nat.cylinder PiNat.cylinder theorem cylinder_eq_pi (x : ∀ n, E n) (n : ℕ) : cylinder x n = Set.pi (Finset.range n : Set ℕ) fun i : ℕ => {x i} := by ext y simp [cylinder] #align pi_nat.cylinder_eq_pi PiNat.cylinder_eq_pi @[simp] theorem cylinder_zero (x : ∀ n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi] #align pi_nat.cylinder_zero PiNat.cylinder_zero theorem cylinder_anti (x : ∀ n, E n) {m n : ℕ} (h : m ≤ n) : cylinder x n ⊆ cylinder x m := fun _y hy i hi => hy i (hi.trans_le h) #align pi_nat.cylinder_anti PiNat.cylinder_anti @[simp] theorem mem_cylinder_iff {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ ∀ i < n, y i = x i := Iff.rfl #align pi_nat.mem_cylinder_iff PiNat.mem_cylinder_iff theorem self_mem_cylinder (x : ∀ n, E n) (n : ℕ) : x ∈ cylinder x n := by simp #align pi_nat.self_mem_cylinder PiNat.self_mem_cylinder theorem mem_cylinder_iff_eq {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ cylinder y n = cylinder x n := by constructor · intro hy apply Subset.antisymm · intro z hz i hi rw [← hy i hi] exact hz i hi · intro z hz i hi rw [hy i hi] exact hz i hi · intro h rw [← h] exact self_mem_cylinder _ _ #align pi_nat.mem_cylinder_iff_eq PiNat.mem_cylinder_iff_eq theorem mem_cylinder_comm (x y : ∀ n, E n) (n : ℕ) : y ∈ cylinder x n ↔ x ∈ cylinder y n := by simp [mem_cylinder_iff_eq, eq_comm] #align pi_nat.mem_cylinder_comm PiNat.mem_cylinder_comm theorem mem_cylinder_iff_le_firstDiff {x y : ∀ n, E n} (hne : x ≠ y) (i : ℕ) : x ∈ cylinder y i ↔ i ≤ firstDiff x y := by constructor · intro h by_contra! exact apply_firstDiff_ne hne (h _ this) · intro hi j hj exact apply_eq_of_lt_firstDiff (hj.trans_le hi) #align pi_nat.mem_cylinder_iff_le_first_diff PiNat.mem_cylinder_iff_le_firstDiff theorem mem_cylinder_firstDiff (x y : ∀ n, E n) : x ∈ cylinder y (firstDiff x y) := fun _i hi => apply_eq_of_lt_firstDiff hi #align pi_nat.mem_cylinder_first_diff PiNat.mem_cylinder_firstDiff theorem cylinder_eq_cylinder_of_le_firstDiff (x y : ∀ n, E n) {n : ℕ} (hn : n ≤ firstDiff x y) : cylinder x n = cylinder y n := by rw [← mem_cylinder_iff_eq] intro i hi exact apply_eq_of_lt_firstDiff (hi.trans_le hn) #align pi_nat.cylinder_eq_cylinder_of_le_first_diff PiNat.cylinder_eq_cylinder_of_le_firstDiff
Mathlib/Topology/MetricSpace/PiNat.lean
175
186
theorem iUnion_cylinder_update (x : ∀ n, E n) (n : ℕ) : ⋃ k, cylinder (update x n k) (n + 1) = cylinder x n := by
ext y simp only [mem_cylinder_iff, mem_iUnion] constructor · rintro ⟨k, hk⟩ i hi simpa [hi.ne] using hk i (Nat.lt_succ_of_lt hi) · intro H refine ⟨y n, fun i hi => ?_⟩ rcases Nat.lt_succ_iff_lt_or_eq.1 hi with (h'i | rfl) · simp [H i h'i, h'i.ne] · simp
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Halting import Mathlib.Computability.TuringMachine import Mathlib.Data.Num.Lemmas import Mathlib.Tactic.DeriveFintype #align_import computability.tm_to_partrec from "leanprover-community/mathlib"@"6155d4351090a6fad236e3d2e4e0e4e7342668e8" /-! # Modelling partial recursive functions using Turing machines This file defines a simplified basis for partial recursive functions, and a `Turing.TM2` model Turing machine for evaluating these functions. This amounts to a constructive proof that every `Partrec` function can be evaluated by a Turing machine. ## Main definitions * `ToPartrec.Code`: a simplified basis for partial recursive functions, valued in `List ℕ →. List ℕ`. * `ToPartrec.Code.eval`: semantics for a `ToPartrec.Code` program * `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs -/ open Function (update) open Relation namespace Turing /-! ## A simplified basis for partrec This section constructs the type `Code`, which is a data type of programs with `List ℕ` input and output, with enough expressivity to write any partial recursive function. The primitives are: * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) This basis is convenient because it is closer to the Turing machine model - the key operations are splitting and merging of lists of unknown length, while the messy `n`-ary composition operation from the traditional basis for partial recursive functions is absent - but it retains a compositional semantics. The first step in transitioning to Turing machines is to make a sequential evaluator for this basis, which we take up in the next section. -/ namespace ToPartrec /-- The type of codes for primitive recursive functions. Unlike `Nat.Partrec.Code`, this uses a set of operations on `List ℕ`. See `Code.eval` for a description of the behavior of the primitives. -/ inductive Code | zero' | succ | tail | cons : Code → Code → Code | comp : Code → Code → Code | case : Code → Code → Code | fix : Code → Code deriving DecidableEq, Inhabited #align turing.to_partrec.code Turing.ToPartrec.Code #align turing.to_partrec.code.zero' Turing.ToPartrec.Code.zero' #align turing.to_partrec.code.succ Turing.ToPartrec.Code.succ #align turing.to_partrec.code.tail Turing.ToPartrec.Code.tail #align turing.to_partrec.code.cons Turing.ToPartrec.Code.cons #align turing.to_partrec.code.comp Turing.ToPartrec.Code.comp #align turing.to_partrec.code.case Turing.ToPartrec.Code.case #align turing.to_partrec.code.fix Turing.ToPartrec.Code.fix /-- The semantics of the `Code` primitives, as partial functions `List ℕ →. List ℕ`. By convention we functions that return a single result return a singleton `[n]`, or in some cases `n :: v` where `v` will be ignored by a subsequent function. * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) -/ def Code.eval : Code → List ℕ →. List ℕ | Code.zero' => fun v => pure (0 :: v) | Code.succ => fun v => pure [v.headI.succ] | Code.tail => fun v => pure v.tail | Code.cons f fs => fun v => do let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) | Code.comp f g => fun v => g.eval v >>= f.eval | Code.case f g => fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) | Code.fix f => PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail #align turing.to_partrec.code.eval Turing.ToPartrec.Code.eval namespace Code /- Porting note: The equation lemma of `eval` is too strong; it simplifies terms like the LHS of `pred_eval`. Even `eqns` can't fix this. We removed `simp` attr from `eval` and prepare new simp lemmas for `eval`. -/ @[simp] theorem zero'_eval : zero'.eval = fun v => pure (0 :: v) := by simp [eval] @[simp] theorem succ_eval : succ.eval = fun v => pure [v.headI.succ] := by simp [eval] @[simp] theorem tail_eval : tail.eval = fun v => pure v.tail := by simp [eval] @[simp] theorem cons_eval (f fs) : (cons f fs).eval = fun v => do { let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) } := by simp [eval] @[simp] theorem comp_eval (f g) : (comp f g).eval = fun v => g.eval v >>= f.eval := by simp [eval] @[simp] theorem case_eval (f g) : (case f g).eval = fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) := by simp [eval] @[simp] theorem fix_eval (f) : (fix f).eval = PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail := by simp [eval] /-- `nil` is the constant nil function: `nil v = []`. -/ def nil : Code := tail.comp succ #align turing.to_partrec.code.nil Turing.ToPartrec.Code.nil @[simp] theorem nil_eval (v) : nil.eval v = pure [] := by simp [nil] #align turing.to_partrec.code.nil_eval Turing.ToPartrec.Code.nil_eval /-- `id` is the identity function: `id v = v`. -/ def id : Code := tail.comp zero' #align turing.to_partrec.code.id Turing.ToPartrec.Code.id @[simp] theorem id_eval (v) : id.eval v = pure v := by simp [id] #align turing.to_partrec.code.id_eval Turing.ToPartrec.Code.id_eval /-- `head` gets the head of the input list: `head [] = [0]`, `head (n :: v) = [n]`. -/ def head : Code := cons id nil #align turing.to_partrec.code.head Turing.ToPartrec.Code.head @[simp] theorem head_eval (v) : head.eval v = pure [v.headI] := by simp [head] #align turing.to_partrec.code.head_eval Turing.ToPartrec.Code.head_eval /-- `zero` is the constant zero function: `zero v = [0]`. -/ def zero : Code := cons zero' nil #align turing.to_partrec.code.zero Turing.ToPartrec.Code.zero @[simp] theorem zero_eval (v) : zero.eval v = pure [0] := by simp [zero] #align turing.to_partrec.code.zero_eval Turing.ToPartrec.Code.zero_eval /-- `pred` returns the predecessor of the head of the input: `pred [] = [0]`, `pred (0 :: v) = [0]`, `pred (n+1 :: v) = [n]`. -/ def pred : Code := case zero head #align turing.to_partrec.code.pred Turing.ToPartrec.Code.pred @[simp] theorem pred_eval (v) : pred.eval v = pure [v.headI.pred] := by simp [pred]; cases v.headI <;> simp #align turing.to_partrec.code.pred_eval Turing.ToPartrec.Code.pred_eval /-- `rfind f` performs the function of the `rfind` primitive of partial recursive functions. `rfind f v` returns the smallest `n` such that `(f (n :: v)).head = 0`. It is implemented as: rfind f v = pred (fix (fun (n::v) => f (n::v) :: n+1 :: v) (0 :: v)) The idea is that the initial state is `0 :: v`, and the `fix` keeps `n :: v` as its internal state; it calls `f (n :: v)` as the exit test and `n+1 :: v` as the next state. At the end we get `n+1 :: v` where `n` is the desired output, and `pred (n+1 :: v) = [n]` returns the result. -/ def rfind (f : Code) : Code := comp pred <| comp (fix <| cons f <| cons succ tail) zero' #align turing.to_partrec.code.rfind Turing.ToPartrec.Code.rfind /-- `prec f g` implements the `prec` (primitive recursion) operation of partial recursive functions. `prec f g` evaluates as: * `prec f g [] = [f []]` * `prec f g (0 :: v) = [f v]` * `prec f g (n+1 :: v) = [g (n :: prec f g (n :: v) :: v)]` It is implemented as: G (a :: b :: IH :: v) = (b :: a+1 :: b-1 :: g (a :: IH :: v) :: v) F (0 :: f_v :: v) = (f_v :: v) F (n+1 :: f_v :: v) = (fix G (0 :: n :: f_v :: v)).tail.tail prec f g (a :: v) = [(F (a :: f v :: v)).head] Because `fix` always evaluates its body at least once, we must special case the `0` case to avoid calling `g` more times than necessary (which could be bad if `g` diverges). If the input is `0 :: v`, then `F (0 :: f v :: v) = (f v :: v)` so we return `[f v]`. If the input is `n+1 :: v`, we evaluate the function from the bottom up, with initial state `0 :: n :: f v :: v`. The first number counts up, providing arguments for the applications to `g`, while the second number counts down, providing the exit condition (this is the initial `b` in the return value of `G`, which is stripped by `fix`). After the `fix` is complete, the final state is `n :: 0 :: res :: v` where `res` is the desired result, and the rest reduces this to `[res]`. -/ def prec (f g : Code) : Code := let G := cons tail <| cons succ <| cons (comp pred tail) <| cons (comp g <| cons id <| comp tail tail) <| comp tail <| comp tail tail let F := case id <| comp (comp (comp tail tail) (fix G)) zero' cons (comp F (cons head <| cons (comp f tail) tail)) nil #align turing.to_partrec.code.prec Turing.ToPartrec.Code.prec attribute [-simp] Part.bind_eq_bind Part.map_eq_map Part.pure_eq_some theorem exists_code.comp {m n} {f : Vector ℕ n →. ℕ} {g : Fin n → Vector ℕ m →. ℕ} (hf : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v) (hg : ∀ i, ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> g i v) : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> ((Vector.mOfFn fun i => g i v) >>= f) := by rsuffices ⟨cg, hg⟩ : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = Subtype.val <$> Vector.mOfFn fun i => g i v · obtain ⟨cf, hf⟩ := hf exact ⟨cf.comp cg, fun v => by simp [hg, hf, map_bind, seq_bind_eq, Function.comp] rfl⟩ clear hf f; induction' n with n IH · exact ⟨nil, fun v => by simp [Vector.mOfFn, Bind.bind]; rfl⟩ · obtain ⟨cg, hg₁⟩ := hg 0 obtain ⟨cl, hl⟩ := IH fun i => hg i.succ exact ⟨cons cg cl, fun v => by simp [Vector.mOfFn, hg₁, map_bind, seq_bind_eq, bind_assoc, (· ∘ ·), hl] rfl⟩ #align turing.to_partrec.code.exists_code.comp Turing.ToPartrec.Code.exists_code.comp theorem exists_code {n} {f : Vector ℕ n →. ℕ} (hf : Nat.Partrec' f) : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v := by induction hf with | prim hf => induction hf with | zero => exact ⟨zero', fun ⟨[], _⟩ => rfl⟩ | succ => exact ⟨succ, fun ⟨[v], _⟩ => rfl⟩ | get i => refine Fin.succRec (fun n => ?_) (fun n i IH => ?_) i · exact ⟨head, fun ⟨List.cons a as, _⟩ => by simp [Bind.bind]; rfl⟩ · obtain ⟨c, h⟩ := IH exact ⟨c.comp tail, fun v => by simpa [← Vector.get_tail, Bind.bind] using h v.tail⟩ | comp g hf hg IHf IHg => simpa [Part.bind_eq_bind] using exists_code.comp IHf IHg | @prec n f g _ _ IHf IHg => obtain ⟨cf, hf⟩ := IHf obtain ⟨cg, hg⟩ := IHg simp only [Part.map_eq_map, Part.map_some, PFun.coe_val] at hf hg refine ⟨prec cf cg, fun v => ?_⟩ rw [← v.cons_head_tail] specialize hf v.tail replace hg := fun a b => hg (a ::ᵥ b ::ᵥ v.tail) simp only [Vector.cons_val, Vector.tail_val] at hf hg simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, Vector.tail_cons, Vector.head_cons, PFun.coe_val, Vector.tail_val] simp only [← Part.pure_eq_some] at hf hg ⊢ induction' v.head with n _ <;> simp [prec, hf, Part.bind_assoc, ← Part.bind_some_eq_map, Part.bind_some, show ∀ x, pure x = [x] from fun _ => rfl, Bind.bind, Functor.map] suffices ∀ a b, a + b = n → (n.succ :: 0 :: g (n ::ᵥ Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) n ::ᵥ v.tail) :: v.val.tail : List ℕ) ∈ PFun.fix (fun v : List ℕ => Part.bind (cg.eval (v.headI :: v.tail.tail)) (fun x => Part.some (if v.tail.headI = 0 then Sum.inl (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail : List ℕ) else Sum.inr (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail)))) (a :: b :: Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) a :: v.val.tail) by erw [Part.eq_some_iff.2 (this 0 n (zero_add n))] simp only [List.headI, Part.bind_some, List.tail_cons] intro a b e induction' b with b IH generalizing a · refine PFun.mem_fix_iff.2 (Or.inl <| Part.eq_some_iff.1 ?_) simp only [hg, ← e, Part.bind_some, List.tail_cons, pure] rfl · refine PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, IH (a + 1) (by rwa [add_right_comm])⟩) simp only [hg, eval, Part.bind_some, Nat.rec_add_one, List.tail_nil, List.tail_cons, pure] exact Part.mem_some_iff.2 rfl | comp g _ _ IHf IHg => exact exists_code.comp IHf IHg | @rfind n f _ IHf => obtain ⟨cf, hf⟩ := IHf; refine ⟨rfind cf, fun v => ?_⟩ replace hf := fun a => hf (a ::ᵥ v) simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, PFun.coe_val, show ∀ x, pure x = [x] from fun _ => rfl] at hf ⊢ refine Part.ext fun x => ?_ simp only [rfind, Part.bind_eq_bind, Part.pure_eq_some, Part.map_eq_map, Part.bind_some, exists_prop, cons_eval, comp_eval, fix_eval, tail_eval, succ_eval, zero'_eval, List.headI_nil, List.headI_cons, pred_eval, Part.map_some, false_eq_decide_iff, Part.mem_bind_iff, List.length, Part.mem_map_iff, Nat.mem_rfind, List.tail_nil, List.tail_cons, true_eq_decide_iff, Part.mem_some_iff, Part.map_bind] constructor · rintro ⟨v', h1, rfl⟩ suffices ∀ v₁ : List ℕ, v' ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) v₁ → ∀ n, (v₁ = n :: v.val) → (∀ m < n, ¬f (m ::ᵥ v) = 0) → ∃ a : ℕ, (f (a ::ᵥ v) = 0 ∧ ∀ {m : ℕ}, m < a → ¬f (m ::ᵥ v) = 0) ∧ [a] = [v'.headI.pred] by exact this _ h1 0 rfl (by rintro _ ⟨⟩) clear h1 intro v₀ h1 refine PFun.fixInduction h1 fun v₁ h2 IH => ?_ clear h1 rintro n rfl hm have := PFun.mem_fix_iff.1 h2 simp only [hf, Part.bind_some] at this split_ifs at this with h · simp only [List.headI_nil, List.headI_cons, exists_false, or_false_iff, Part.mem_some_iff, List.tail_cons, false_and_iff, Sum.inl.injEq] at this subst this exact ⟨_, ⟨h, @(hm)⟩, rfl⟩ · refine IH (n.succ::v.val) (by simp_all) _ rfl fun m h' => ?_ obtain h | rfl := Nat.lt_succ_iff_lt_or_eq.1 h' exacts [hm _ h, h] · rintro ⟨n, ⟨hn, hm⟩, rfl⟩ refine ⟨n.succ::v.1, ?_, rfl⟩ have : (n.succ::v.1 : List ℕ) ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) (n::v.val) := PFun.mem_fix_iff.2 (Or.inl (by simp [hf, hn])) generalize (n.succ :: v.1 : List ℕ) = w at this ⊢ clear hn induction' n with n IH · exact this refine IH (fun {m} h' => hm (Nat.lt_succ_of_lt h')) (PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, this⟩)) simp only [hf, hm n.lt_succ_self, Part.bind_some, List.headI, eq_self_iff_true, if_false, Part.mem_some_iff, and_self_iff, List.tail_cons] #align turing.to_partrec.code.exists_code Turing.ToPartrec.Code.exists_code end Code /-! ## From compositional semantics to sequential semantics Our initial sequential model is designed to be as similar as possible to the compositional semantics in terms of its primitives, but it is a sequential semantics, meaning that rather than defining an `eval c : List ℕ →. List ℕ` function for each program, defined by recursion on programs, we have a type `Cfg` with a step function `step : Cfg → Option cfg` that provides a deterministic evaluation order. In order to do this, we introduce the notion of a *continuation*, which can be viewed as a `Code` with a hole in it where evaluation is currently taking place. Continuations can be assigned a `List ℕ →. List ℕ` semantics as well, with the interpretation being that given a `List ℕ` result returned from the code in the hole, the remainder of the program will evaluate to a `List ℕ` final value. The continuations are: * `halt`: the empty continuation: the hole is the whole program, whatever is returned is the final result. In our notation this is just `_`. * `cons₁ fs v k`: evaluating the first part of a `cons`, that is `k (_ :: fs v)`, where `k` is the outer continuation. * `cons₂ ns k`: evaluating the second part of a `cons`: `k (ns.headI :: _)`. (Technically we don't need to hold on to all of `ns` here since we are already committed to taking the head, but this is more regular.) * `comp f k`: evaluating the first part of a composition: `k (f _)`. * `fix f k`: waiting for the result of `f` in a `fix f` expression: `k (if _.headI = 0 then _.tail else fix f (_.tail))` The type `Cfg` of evaluation states is: * `ret k v`: we have received a result, and are now evaluating the continuation `k` with result `v`; that is, `k v` where `k` is ready to evaluate. * `halt v`: we are done and the result is `v`. The main theorem of this section is that for each code `c`, the state `stepNormal c halt v` steps to `v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ /-- The type of continuations, built up during evaluation of a `Code` expression. -/ inductive Cont | halt | cons₁ : Code → List ℕ → Cont → Cont | cons₂ : List ℕ → Cont → Cont | comp : Code → Cont → Cont | fix : Code → Cont → Cont deriving Inhabited #align turing.to_partrec.cont Turing.ToPartrec.Cont #align turing.to_partrec.cont.halt Turing.ToPartrec.Cont.halt #align turing.to_partrec.cont.cons₁ Turing.ToPartrec.Cont.cons₁ #align turing.to_partrec.cont.cons₂ Turing.ToPartrec.Cont.cons₂ #align turing.to_partrec.cont.comp Turing.ToPartrec.Cont.comp #align turing.to_partrec.cont.fix Turing.ToPartrec.Cont.fix /-- The semantics of a continuation. -/ def Cont.eval : Cont → List ℕ →. List ℕ | Cont.halt => pure | Cont.cons₁ fs as k => fun v => do let ns ← Code.eval fs as Cont.eval k (v.headI :: ns) | Cont.cons₂ ns k => fun v => Cont.eval k (ns.headI :: v) | Cont.comp f k => fun v => Code.eval f v >>= Cont.eval k | Cont.fix f k => fun v => if v.headI = 0 then k.eval v.tail else f.fix.eval v.tail >>= k.eval #align turing.to_partrec.cont.eval Turing.ToPartrec.Cont.eval /-- The set of configurations of the machine: * `halt v`: The machine is about to stop and `v : List ℕ` is the result. * `ret k v`: The machine is about to pass `v : List ℕ` to continuation `k : cont`. We don't have a state corresponding to normal evaluation because these are evaluated immediately to a `ret` "in zero steps" using the `stepNormal` function. -/ inductive Cfg | halt : List ℕ → Cfg | ret : Cont → List ℕ → Cfg deriving Inhabited #align turing.to_partrec.cfg Turing.ToPartrec.Cfg #align turing.to_partrec.cfg.halt Turing.ToPartrec.Cfg.halt #align turing.to_partrec.cfg.ret Turing.ToPartrec.Cfg.ret /-- Evaluating `c : Code` in a continuation `k : Cont` and input `v : List ℕ`. This goes by recursion on `c`, building an augmented continuation and a value to pass to it. * `zero' v = 0 :: v` evaluates immediately, so we return it to the parent continuation * `succ v = [v.headI.succ]` evaluates immediately, so we return it to the parent continuation * `tail v = v.tail` evaluates immediately, so we return it to the parent continuation * `cons f fs v = (f v).headI :: fs v` requires two sub-evaluations, so we evaluate `f v` in the continuation `k (_.headI :: fs v)` (called `Cont.cons₁ fs v k`) * `comp f g v = f (g v)` requires two sub-evaluations, so we evaluate `g v` in the continuation `k (f _)` (called `Cont.comp f k`) * `case f g v = v.head.casesOn (f v.tail) (fun n => g (n :: v.tail))` has the information needed to evaluate the case statement, so we do that and transition to either `f v` or `g (n :: v.tail)`. * `fix f v = let v' := f v; if v'.headI = 0 then k v'.tail else fix f v'.tail` needs to first evaluate `f v`, so we do that and leave the rest for the continuation (called `Cont.fix f k`) -/ def stepNormal : Code → Cont → List ℕ → Cfg | Code.zero' => fun k v => Cfg.ret k (0::v) | Code.succ => fun k v => Cfg.ret k [v.headI.succ] | Code.tail => fun k v => Cfg.ret k v.tail | Code.cons f fs => fun k v => stepNormal f (Cont.cons₁ fs v k) v | Code.comp f g => fun k v => stepNormal g (Cont.comp f k) v | Code.case f g => fun k v => v.headI.rec (stepNormal f k v.tail) fun y _ => stepNormal g k (y::v.tail) | Code.fix f => fun k v => stepNormal f (Cont.fix f k) v #align turing.to_partrec.step_normal Turing.ToPartrec.stepNormal /-- Evaluating a continuation `k : Cont` on input `v : List ℕ`. This is the second part of evaluation, when we receive results from continuations built by `stepNormal`. * `Cont.halt v = v`, so we are done and transition to the `Cfg.halt v` state * `Cont.cons₁ fs as k v = k (v.headI :: fs as)`, so we evaluate `fs as` now with the continuation `k (v.headI :: _)` (called `cons₂ v k`). * `Cont.cons₂ ns k v = k (ns.headI :: v)`, where we now have everything we need to evaluate `ns.headI :: v`, so we return it to `k`. * `Cont.comp f k v = k (f v)`, so we call `f v` with `k` as the continuation. * `Cont.fix f k v = k (if v.headI = 0 then k v.tail else fix f v.tail)`, where `v` is a value, so we evaluate the if statement and either call `k` with `v.tail`, or call `fix f v` with `k` as the continuation (which immediately calls `f` with `Cont.fix f k` as the continuation). -/ def stepRet : Cont → List ℕ → Cfg | Cont.halt, v => Cfg.halt v | Cont.cons₁ fs as k, v => stepNormal fs (Cont.cons₂ v k) as | Cont.cons₂ ns k, v => stepRet k (ns.headI :: v) | Cont.comp f k, v => stepNormal f k v | Cont.fix f k, v => if v.headI = 0 then stepRet k v.tail else stepNormal f (Cont.fix f k) v.tail #align turing.to_partrec.step_ret Turing.ToPartrec.stepRet /-- If we are not done (in `Cfg.halt` state), then we must be still stuck on a continuation, so this main loop calls `stepRet` with the new continuation. The overall `step` function transitions from one `Cfg` to another, only halting at the `Cfg.halt` state. -/ def step : Cfg → Option Cfg | Cfg.halt _ => none | Cfg.ret k v => some (stepRet k v) #align turing.to_partrec.step Turing.ToPartrec.step /-- In order to extract a compositional semantics from the sequential execution behavior of configurations, we observe that continuations have a monoid structure, with `Cont.halt` as the unit and `Cont.then` as the multiplication. `Cont.then k₁ k₂` runs `k₁` until it halts, and then takes the result of `k₁` and passes it to `k₂`. We will not prove it is associative (although it is), but we are instead interested in the associativity law `k₂ (eval c k₁) = eval c (k₁.then k₂)`. This holds at both the sequential and compositional levels, and allows us to express running a machine without the ambient continuation and relate it to the original machine's evaluation steps. In the literature this is usually where one uses Turing machines embedded inside other Turing machines, but this approach allows us to avoid changing the ambient type `Cfg` in the middle of the recursion. -/ def Cont.then : Cont → Cont → Cont | Cont.halt => fun k' => k' | Cont.cons₁ fs as k => fun k' => Cont.cons₁ fs as (k.then k') | Cont.cons₂ ns k => fun k' => Cont.cons₂ ns (k.then k') | Cont.comp f k => fun k' => Cont.comp f (k.then k') | Cont.fix f k => fun k' => Cont.fix f (k.then k') #align turing.to_partrec.cont.then Turing.ToPartrec.Cont.then theorem Cont.then_eval {k k' : Cont} {v} : (k.then k').eval v = k.eval v >>= k'.eval := by induction' k with _ _ _ _ _ _ _ _ _ k_ih _ _ k_ih generalizing v <;> simp only [Cont.eval, Cont.then, bind_assoc, pure_bind, *] · simp only [← k_ih] · split_ifs <;> [rfl; simp only [← k_ih, bind_assoc]] #align turing.to_partrec.cont.then_eval Turing.ToPartrec.Cont.then_eval /-- The `then k` function is a "configuration homomorphism". Its operation on states is to append `k` to the continuation of a `Cfg.ret` state, and to run `k` on `v` if we are in the `Cfg.halt v` state. -/ def Cfg.then : Cfg → Cont → Cfg | Cfg.halt v => fun k' => stepRet k' v | Cfg.ret k v => fun k' => Cfg.ret (k.then k') v #align turing.to_partrec.cfg.then Turing.ToPartrec.Cfg.then /-- The `stepNormal` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepNormal_then (c) (k k' : Cont) (v) : stepNormal c (k.then k') v = (stepNormal c k v).then k' := by induction c generalizing k v with simp only [Cont.then, stepNormal, *] | cons c c' ih _ => rw [← ih, Cont.then] | comp c c' _ ih' => rw [← ih', Cont.then] | case => cases v.headI <;> simp only [Nat.rec_zero] | fix c ih => rw [← ih, Cont.then] | _ => simp only [Cfg.then] #align turing.to_partrec.step_normal_then Turing.ToPartrec.stepNormal_then /-- The `stepRet` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepRet_then {k k' : Cont} {v} : stepRet (k.then k') v = (stepRet k v).then k' := by induction k generalizing v with simp only [Cont.then, stepRet, *] | cons₁ => rw [← stepNormal_then] rfl | comp => rw [← stepNormal_then] | fix _ _ k_ih => split_ifs · rw [← k_ih] · rw [← stepNormal_then] rfl | _ => simp only [Cfg.then] #align turing.to_partrec.step_ret_then Turing.ToPartrec.stepRet_then /-- This is a temporary definition, because we will prove in `code_is_ok` that it always holds. It asserts that `c` is semantically correct; that is, for any `k` and `v`, `eval (stepNormal c k v) = eval (Cfg.ret k (Code.eval c v))`, as an equality of partial values (so one diverges iff the other does). In particular, we can let `k = Cont.halt`, and then this asserts that `stepNormal c Cont.halt v` evaluates to `Cfg.halt (Code.eval c v)`. -/ def Code.Ok (c : Code) := ∀ k v, Turing.eval step (stepNormal c k v) = Code.eval c v >>= fun v => Turing.eval step (Cfg.ret k v) #align turing.to_partrec.code.ok Turing.ToPartrec.Code.Ok theorem Code.Ok.zero {c} (h : Code.Ok c) {v} : Turing.eval step (stepNormal c Cont.halt v) = Cfg.halt <$> Code.eval c v := by rw [h, ← bind_pure_comp]; congr; funext v exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.single rfl, rfl⟩) #align turing.to_partrec.code.ok.zero Turing.ToPartrec.Code.Ok.zero theorem stepNormal.is_ret (c k v) : ∃ k' v', stepNormal c k v = Cfg.ret k' v' := by induction c generalizing k v with | cons _f fs IHf _IHfs => apply IHf | comp f _g _IHf IHg => apply IHg | case f g IHf IHg => rw [stepNormal] simp only [] cases v.headI <;> [apply IHf; apply IHg] | fix f IHf => apply IHf | _ => exact ⟨_, _, rfl⟩ #align turing.to_partrec.step_normal.is_ret Turing.ToPartrec.stepNormal.is_ret theorem cont_eval_fix {f k v} (fok : Code.Ok f) : Turing.eval step (stepNormal f (Cont.fix f k) v) = f.fix.eval v >>= fun v => Turing.eval step (Cfg.ret k v) := by refine Part.ext fun x => ?_ simp only [Part.bind_eq_bind, Part.mem_bind_iff] constructor · suffices ∀ c, x ∈ eval step c → ∀ v c', c = Cfg.then c' (Cont.fix f k) → Reaches step (stepNormal f Cont.halt v) c' → ∃ v₁ ∈ f.eval v, ∃ v₂ ∈ if List.headI v₁ = 0 then pure v₁.tail else f.fix.eval v₁.tail, x ∈ eval step (Cfg.ret k v₂) by intro h obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := this _ h _ _ (stepNormal_then _ Cont.halt _ _) ReflTransGen.refl refine ⟨v₂, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some] split_ifs at hv₂ ⊢ · rw [Part.mem_some_iff.1 hv₂] exact Or.inl (Part.mem_some _) · exact Or.inr ⟨_, Part.mem_some _, hv₂⟩ refine fun c he => evalInduction he fun y h IH => ?_ rintro v (⟨v'⟩ | ⟨k', v'⟩) rfl hr <;> rw [Cfg.then] at h IH <;> simp only [] at h IH · have := mem_eval.2 ⟨hr, rfl⟩ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] at this obtain ⟨v'', h₁, h₂⟩ := this rw [reaches_eval] at h₂ swap · exact ReflTransGen.single rfl cases Part.mem_unique h₂ (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) refine ⟨v', h₁, ?_⟩ rw [stepRet] at h revert h by_cases he : v'.headI = 0 <;> simp only [exists_prop, if_pos, if_false, he] <;> intro h · refine ⟨_, Part.mem_some _, ?_⟩ rw [reaches_eval] · exact h exact ReflTransGen.single rfl · obtain ⟨k₀, v₀, e₀⟩ := stepNormal.is_ret f Cont.halt v'.tail have e₁ := stepNormal_then f Cont.halt (Cont.fix f k) v'.tail rw [e₀, Cont.then, Cfg.then] at e₁ simp only [] at e₁ obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := IH (stepRet (k₀.then (Cont.fix f k)) v₀) (by rw [stepRet, if_neg he, e₁]; rfl) v'.tail _ stepRet_then (by apply ReflTransGen.single; rw [e₀]; rfl) refine ⟨_, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some, Part.mem_some_iff] split_ifs at hv₂ ⊢ <;> [exact Or.inl (congr_arg Sum.inl (Part.mem_some_iff.1 hv₂)); exact Or.inr ⟨_, rfl, hv₂⟩] · exact IH _ rfl _ _ stepRet_then (ReflTransGen.tail hr rfl) · rintro ⟨v', he, hr⟩ rw [reaches_eval] at hr swap · exact ReflTransGen.single rfl refine PFun.fixInduction he fun v (he : v' ∈ f.fix.eval v) IH => ?_ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] obtain he | ⟨v'', he₁', _⟩ := PFun.mem_fix_iff.1 he · obtain ⟨v', he₁, he₂⟩ := (Part.mem_map_iff _).1 he split_ifs at he₂ with h; cases he₂ refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rwa [stepRet, if_pos h] · obtain ⟨v₁, he₁, he₂⟩ := (Part.mem_map_iff _).1 he₁' split_ifs at he₂ with h; cases he₂ clear he₁' refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rw [stepRet, if_neg h] exact IH v₁.tail ((Part.mem_map_iff _).2 ⟨_, he₁, if_neg h⟩) #align turing.to_partrec.cont_eval_fix Turing.ToPartrec.cont_eval_fix theorem code_is_ok (c) : Code.Ok c := by induction c with (intro k v; rw [stepNormal]) | cons f fs IHf IHfs => rw [Code.eval, IHf] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHfs]; congr; funext v' refine Eq.trans (b := eval step (stepRet (Cont.cons₂ v k) v')) ?_ (Eq.symm ?_) <;> exact reaches_eval (ReflTransGen.single rfl) | comp f g IHf IHg => rw [Code.eval, IHg] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHf] | case f g IHf IHg => simp only [Code.eval] cases v.headI <;> simp only [Nat.rec_zero, Part.bind_eq_bind] <;> [apply IHf; apply IHg] | fix f IHf => rw [cont_eval_fix IHf] | _ => simp only [Code.eval, pure_bind] #align turing.to_partrec.code_is_ok Turing.ToPartrec.code_is_ok theorem stepNormal_eval (c v) : eval step (stepNormal c Cont.halt v) = Cfg.halt <$> c.eval v := (code_is_ok c).zero #align turing.to_partrec.step_normal_eval Turing.ToPartrec.stepNormal_eval theorem stepRet_eval {k v} : eval step (stepRet k v) = Cfg.halt <$> k.eval v := by induction k generalizing v with | halt => simp only [mem_eval, Cont.eval, map_pure] exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) | cons₁ fs as k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IH, bind_pure_comp] | cons₂ ns k IH => rw [Cont.eval, stepRet]; exact IH | comp f k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [IH, bind_pure_comp] | fix f k IH => rw [Cont.eval, stepRet]; simp only [bind_pure_comp] split_ifs; · exact IH simp only [← bind_pure_comp, bind_assoc, cont_eval_fix (code_is_ok _)] congr; funext; rw [bind_pure_comp, ← IH] exact reaches_eval (ReflTransGen.single rfl) #align turing.to_partrec.step_ret_eval Turing.ToPartrec.stepRet_eval end ToPartrec /-! ## Simulating sequentialized partial recursive functions in TM2 At this point we have a sequential model of partial recursive functions: the `Cfg` type and `step : Cfg → Option Cfg` function from the previous section. The key feature of this model is that it does a finite amount of computation (in fact, an amount which is statically bounded by the size of the program) between each step, and no individual step can diverge (unlike the compositional semantics, where every sub-part of the computation is potentially divergent). So we can utilize the same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that each step corresponds to a finite number of steps in a lower level model. (We don't prove it here, but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.) The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage, with programs selected from a potentially infinite (but finitely accessible) set of program positions, or labels `Λ`, each of which executes a finite sequence of basic stack commands. For this program we will need four stacks, each on an alphabet `Γ'` like so: inductive Γ' | consₗ | cons | bit0 | bit1 We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and lists of lists of natural numbers by putting `consₗ` after each list. For example: 0 ~> [] 1 ~> [bit1] 6 ~> [bit0, bit1, bit1] [1, 2] ~> [bit1, cons, bit0, bit1, cons] [[], [1, 2]] ~> [consₗ, bit1, cons, bit0, bit1, cons, consₗ] The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the current program (a `List ℕ`) and `stack` contains data (a `List (List ℕ)`) associated to the current continuation, and in `ret` mode `main` contains the value that is being passed to the continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `cons₁` evaluation. The only local store we need is `Option Γ'`, which stores the result of the last pop operation. (Most of our working data are natural numbers, which are too large to fit in the local store.) The continuations from the previous section are data-carrying, containing all the values that have been computed and are awaiting other arguments. In order to have only a finite number of continuations appear in the program so that they can be used in machine states, we separate the data part (anything with type `List ℕ`) from the `Cont` type, producing a `Cont'` type that lacks this information. The data is kept on the `stack` stack. Because we want to have subroutines for e.g. moving an entire stack to another place, we use an infinite inductive type `Λ'` so that we can execute a program and then return to do something else without having to define too many different kinds of intermediate states. (We must nevertheless prove that only finitely many labels are accessible.) The labels are: * `move p k₁ k₂ q`: move elements from stack `k₁` to `k₂` while `p` holds of the value being moved. The last element, that fails `p`, is placed in neither stack but left in the local store. At the end of the operation, `k₂` will have the elements of `k₁` in reverse order. Then do `q`. * `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is left in the local storage. Then do `q`. * `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order), then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`. * `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine just for this purpose we can build up programs to execute inside a `goto` statement, where we have the flexibility to be general recursive. * `read (f : Option Γ' → Λ')`: go to state `f s` where `s` is the local store. Again this is only here for convenience. * `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before, `[n+1]` will be on main after. This implements successor for binary natural numbers. * `pred q₁ q₂`: perform a predecessor operation or `case` statement. If `[]` is encoded on `main` before, then we transition to `q₁` with `[]` on main; if `(0 :: v)` is on `main` before then `v` will be on `main` after and we transition to `q₁`; and if `(n+1 :: v)` is on `main` before then `n :: v` will be on `main` after and we transition to `q₂`. * `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in `stack` and sets up the data for the next continuation. * `ret (cons₁ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects `v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two reversals. * `ret (cons₂ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put `ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine. * `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and if so, remove it and call `k`, otherwise `clear` the first value and call `f`. * `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt. In addition to these basic states, we define some additional subroutines that are used in the above: * `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply inputs and outputs. * `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as a cleanup operation in several functions. * `moveExcl p k₁ k₂ q`: same as `move` but pushes the last value read back onto the source stack. * `move₂ p k₁ k₂ q`: double `move`, so that the result comes out in the right order at the target stack. Implemented as `moveExcl p k rev; move false rev k₂`. Assumes that neither `k₁` nor `k₂` is `rev` and `rev` is initially empty. * `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]` will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on `main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on `main`. * `trNormal` is the main entry point, defining states that perform a given `code` computation. It mostly just dispatches to functions written above. The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`, the state `init c v` steps to `halt v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ set_option linter.uppercaseLean3 false namespace PartrecToTM2 section open ToPartrec /-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `ℕ` values as lists of binary digits, `cons` is used to separate `List ℕ` values, and `consₗ` is used to separate `List (List ℕ)` values. See the section documentation. -/ inductive Γ' | consₗ | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype #align turing.partrec_to_TM2.Γ' Turing.PartrecToTM2.Γ' #align turing.partrec_to_TM2.Γ'.Cons Turing.PartrecToTM2.Γ'.consₗ #align turing.partrec_to_TM2.Γ'.cons Turing.PartrecToTM2.Γ'.cons #align turing.partrec_to_TM2.Γ'.bit0 Turing.PartrecToTM2.Γ'.bit0 #align turing.partrec_to_TM2.Γ'.bit1 Turing.PartrecToTM2.Γ'.bit1 /-- The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Λ'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. See the section documentation. -/ inductive K' | main | rev | aux | stack deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.K' Turing.PartrecToTM2.K' #align turing.partrec_to_TM2.K'.main Turing.PartrecToTM2.K'.main #align turing.partrec_to_TM2.K'.rev Turing.PartrecToTM2.K'.rev #align turing.partrec_to_TM2.K'.aux Turing.PartrecToTM2.K'.aux #align turing.partrec_to_TM2.K'.stack Turing.PartrecToTM2.K'.stack open K' /-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values during execution. -/ inductive Cont' | halt | cons₁ : Code → Cont' → Cont' | cons₂ : Cont' → Cont' | comp : Code → Cont' → Cont' | fix : Code → Cont' → Cont' deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.cont' Turing.PartrecToTM2.Cont' #align turing.partrec_to_TM2.cont'.halt Turing.PartrecToTM2.Cont'.halt #align turing.partrec_to_TM2.cont'.cons₁ Turing.PartrecToTM2.Cont'.cons₁ #align turing.partrec_to_TM2.cont'.cons₂ Turing.PartrecToTM2.Cont'.cons₂ #align turing.partrec_to_TM2.cont'.comp Turing.PartrecToTM2.Cont'.comp #align turing.partrec_to_TM2.cont'.fix Turing.PartrecToTM2.Cont'.fix /-- The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are careful to be non-recursive (although loops are okay). See the section documentation for a description of all the programs. -/ inductive Λ' | move (p : Γ' → Bool) (k₁ k₂ : K') (q : Λ') | clear (p : Γ' → Bool) (k : K') (q : Λ') | copy (q : Λ') | push (k : K') (s : Option Γ' → Option Γ') (q : Λ') | read (f : Option Γ' → Λ') | succ (q : Λ') | pred (q₁ q₂ : Λ') | ret (k : Cont') #align turing.partrec_to_TM2.Λ' Turing.PartrecToTM2.Λ' #align turing.partrec_to_TM2.Λ'.move Turing.PartrecToTM2.Λ'.move #align turing.partrec_to_TM2.Λ'.clear Turing.PartrecToTM2.Λ'.clear #align turing.partrec_to_TM2.Λ'.copy Turing.PartrecToTM2.Λ'.copy #align turing.partrec_to_TM2.Λ'.push Turing.PartrecToTM2.Λ'.push #align turing.partrec_to_TM2.Λ'.read Turing.PartrecToTM2.Λ'.read #align turing.partrec_to_TM2.Λ'.succ Turing.PartrecToTM2.Λ'.succ #align turing.partrec_to_TM2.Λ'.pred Turing.PartrecToTM2.Λ'.pred #align turing.partrec_to_TM2.Λ'.ret Turing.PartrecToTM2.Λ'.ret -- Porting note: `Turing.PartrecToTM2.Λ'.rec` is noncomputable in Lean4, so we make it computable. compile_inductive% Code compile_inductive% Cont' compile_inductive% K' compile_inductive% Λ' instance Λ'.instInhabited : Inhabited Λ' := ⟨Λ'.ret Cont'.halt⟩ #align turing.partrec_to_TM2.Λ'.inhabited Turing.PartrecToTM2.Λ'.instInhabited instance Λ'.instDecidableEq : DecidableEq Λ' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [Function.funext_iff]; rfl) #align turing.partrec_to_TM2.Λ'.decidable_eq Turing.PartrecToTM2.Λ'.instDecidableEq /-- The type of TM2 statements used by this machine. -/ def Stmt' := TM2.Stmt (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.stmt' Turing.PartrecToTM2.Stmt' /-- The type of TM2 configurations used by this machine. -/ def Cfg' := TM2.Cfg (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.cfg' Turing.PartrecToTM2.Cfg' open TM2.Stmt /-- A predicate that detects the end of a natural number, either `Γ'.cons` or `Γ'.consₗ` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/ @[simp] def natEnd : Γ' → Bool | Γ'.consₗ => true | Γ'.cons => true | _ => false #align turing.partrec_to_TM2.nat_end Turing.PartrecToTM2.natEnd /-- Pop a value from the stack and place the result in local store. -/ @[simp] def pop' (k : K') : Stmt' → Stmt' := pop k fun _ v => v #align turing.partrec_to_TM2.pop' Turing.PartrecToTM2.pop' /-- Peek a value from the stack and place the result in local store. -/ @[simp] def peek' (k : K') : Stmt' → Stmt' := peek k fun _ v => v #align turing.partrec_to_TM2.peek' Turing.PartrecToTM2.peek' /-- Push the value in the local store to the given stack. -/ @[simp] def push' (k : K') : Stmt' → Stmt' := push k fun x => x.iget #align turing.partrec_to_TM2.push' Turing.PartrecToTM2.push' /-- Move everything from the `rev` stack to the `main` stack (reversed). -/ def unrev := Λ'.move (fun _ => false) rev main #align turing.partrec_to_TM2.unrev Turing.PartrecToTM2.unrev /-- Move elements from `k₁` to `k₂` while `p` holds, with the last element being left on `k₁`. -/ def moveExcl (p k₁ k₂ q) := Λ'.move p k₁ k₂ <| Λ'.push k₁ id q #align turing.partrec_to_TM2.move_excl Turing.PartrecToTM2.moveExcl /-- Move elements from `k₁` to `k₂` without reversion, by performing a double move via the `rev` stack. -/ def move₂ (p k₁ k₂ q) := moveExcl p k₁ rev <| Λ'.move (fun _ => false) rev k₂ q #align turing.partrec_to_TM2.move₂ Turing.PartrecToTM2.move₂ /-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation. -/ def head (k : K') (q : Λ') : Λ' := Λ'.move natEnd k rev <| (Λ'.push rev fun _ => some Γ'.cons) <| Λ'.read fun s => (if s = some Γ'.consₗ then id else Λ'.clear (fun x => x = Γ'.consₗ) k) <| unrev q #align turing.partrec_to_TM2.head Turing.PartrecToTM2.head /-- The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details. -/ @[simp] def trNormal : Code → Cont' → Λ' | Code.zero', k => (Λ'.push main fun _ => some Γ'.cons) <| Λ'.ret k | Code.succ, k => head main <| Λ'.succ <| Λ'.ret k | Code.tail, k => Λ'.clear natEnd main <| Λ'.ret k | Code.cons f fs, k => (Λ'.push stack fun _ => some Γ'.consₗ) <| Λ'.move (fun _ => false) main rev <| Λ'.copy <| trNormal f (Cont'.cons₁ fs k) | Code.comp f g, k => trNormal g (Cont'.comp f k) | Code.case f g, k => Λ'.pred (trNormal f k) (trNormal g k) | Code.fix f, k => trNormal f (Cont'.fix f k) #align turing.partrec_to_TM2.tr_normal Turing.PartrecToTM2.trNormal /-- The main program. See the section documentation for details. -/ def tr : Λ' → Stmt' | Λ'.move p k₁ k₂ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q) | Λ'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Λ'.read q => goto q | Λ'.clear p k q => pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q) | Λ'.copy q => pop' rev <| branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q) | Λ'.succ q => pop' main <| branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) | Λ'.pred q₁ q₂ => pop' main <| branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂)) | Λ'.ret (Cont'.cons₁ fs k) => goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) | Λ'.ret (Cont'.cons₂ k) => goto fun _ => head stack <| Λ'.ret k | Λ'.ret (Cont'.comp f k) => goto fun _ => trNormal f k | Λ'.ret (Cont'.fix f k) => pop' main <| goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k) | Λ'.ret Cont'.halt => (load fun _ => none) <| halt #align turing.partrec_to_TM2.tr Turing.PartrecToTM2.tr /- Porting note: The equation lemma of `tr` simplifies to `match` structures. To prevent this, we replace equation lemmas of `tr`. -/ theorem tr_move (p k₁ k₂ q) : tr (Λ'.move p k₁ k₂ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q)) := rfl theorem tr_push (k f q) : tr (Λ'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl theorem tr_read (q) : tr (Λ'.read q) = goto q := rfl theorem tr_clear (p k q) : tr (Λ'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q)) := rfl theorem tr_copy (q) : tr (Λ'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q)) := rfl theorem tr_succ (q) : tr (Λ'.succ q) = pop' main (branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q)) := rfl theorem tr_pred (q₁ q₂) : tr (Λ'.pred q₁ q₂) = pop' main (branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂))) := rfl theorem tr_ret_cons₁ (fs k) : tr (Λ'.ret (Cont'.cons₁ fs k)) = goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) := rfl theorem tr_ret_cons₂ (k) : tr (Λ'.ret (Cont'.cons₂ k)) = goto fun _ => head stack <| Λ'.ret k := rfl theorem tr_ret_comp (f k) : tr (Λ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl theorem tr_ret_fix (f k) : tr (Λ'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl theorem tr_ret_halt : tr (Λ'.ret Cont'.halt) = (load fun _ => none) halt := rfl attribute [eqns tr_move tr_push tr_read tr_clear tr_copy tr_succ tr_pred tr_ret_cons₁ tr_ret_cons₂ tr_ret_comp tr_ret_fix tr_ret_halt] tr attribute [simp] tr /-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration. -/ def trCont : Cont → Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.cons₂ _ k => Cont'.cons₂ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k) #align turing.partrec_to_TM2.tr_cont Turing.PartrecToTM2.trCont /-- We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/ def trPosNum : PosNum → List Γ' | PosNum.one => [Γ'.bit1] | PosNum.bit0 n => Γ'.bit0 :: trPosNum n | PosNum.bit1 n => Γ'.bit1 :: trPosNum n #align turing.partrec_to_TM2.tr_pos_num Turing.PartrecToTM2.trPosNum /-- We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] -/ def trNum : Num → List Γ' | Num.zero => [] | Num.pos n => trPosNum n #align turing.partrec_to_TM2.tr_num Turing.PartrecToTM2.trNum /-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.) -/ def trNat (n : ℕ) : List Γ' := trNum n #align turing.partrec_to_TM2.tr_nat Turing.PartrecToTM2.trNat @[simp] theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl #align turing.partrec_to_TM2.tr_nat_zero Turing.PartrecToTM2.trNat_zero theorem trNat_default : trNat default = [] := trNat_zero #align turing.partrec_to_TM2.tr_nat_default Turing.PartrecToTM2.trNat_default /-- Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons] -/ @[simp] def trList : List ℕ → List Γ' | [] => [] | n::ns => trNat n ++ Γ'.cons :: trList ns #align turing.partrec_to_TM2.tr_list Turing.PartrecToTM2.trList /-- Lists of lists are translated with a `consₗ` after each encoded list. For example: [] = [] [[]] = [consₗ] [[], []] = [consₗ, consₗ] [[0]] = [cons, consₗ] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consₗ, cons, consₗ] -/ @[simp] def trLList : List (List ℕ) → List Γ' | [] => [] | l::ls => trList l ++ Γ'.consₗ :: trLList ls #align turing.partrec_to_TM2.tr_llist Turing.PartrecToTM2.trLList /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ @[simp] def contStack : Cont → List (List ℕ) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.cons₂ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k #align turing.partrec_to_TM2.cont_stack Turing.PartrecToTM2.contStack /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ def trContStack (k : Cont) := trLList (contStack k) #align turing.partrec_to_TM2.tr_cont_stack Turing.PartrecToTM2.trContStack /-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' → List Γ'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the components. -/ def K'.elim (a b c d : List Γ') : K' → List Γ' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d #align turing.partrec_to_TM2.K'.elim Turing.PartrecToTM2.K'.elim -- The equation lemma of `elim` simplifies to `match` structures. theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp] theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_main Turing.PartrecToTM2.K'.elim_update_main @[simp] theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_rev Turing.PartrecToTM2.K'.elim_update_rev @[simp] theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_aux Turing.PartrecToTM2.K'.elim_update_aux @[simp] theorem K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_stack Turing.PartrecToTM2.K'.elim_update_stack /-- The halting state corresponding to a `List ℕ` output value. -/ def halt (v : List ℕ) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩ #align turing.partrec_to_TM2.halt Turing.PartrecToTM2.halt /-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`. -/ def TrCfg : Cfg → Cfg' → Prop | Cfg.ret k v, c' => ∃ s, c' = ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v #align turing.partrec_to_TM2.tr_cfg Turing.PartrecToTM2.TrCfg /-- This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: l₂` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, l₂)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/ def splitAtPred {α} (p : α → Bool) : List α → List α × Option α × List α | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, l₂⟩ := splitAtPred p as ⟨a::l₁, o, l₂⟩ #align turing.partrec_to_TM2.split_at_pred Turing.PartrecToTM2.splitAtPred theorem splitAtPred_eq {α} (p : α → Bool) : ∀ L l₁ o l₂, (∀ x ∈ l₁, p x = false) → Option.elim' (L = l₁ ∧ l₂ = []) (fun a => p a = true ∧ L = l₁ ++ a::l₂) o → splitAtPred p L = (l₁, o, l₂) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, l₂, _, ⟨_, h₃⟩ => by simp at h₃ | a :: L, l₁, o, l₂, h₁, h₂ => by rw [splitAtPred] have IH := splitAtPred_eq p L cases' o with o · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨⟨⟩, rfl⟩ rw [h₁ a (List.Mem.head _), cond, IH L none [] _ ⟨rfl, rfl⟩] exact fun x h => h₁ x (List.Mem.tail _ h) · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨h₂, ⟨⟩⟩ · rw [h₂, cond] rw [h₁ a (List.Mem.head _), cond, IH l₁ (some o) l₂ _ ⟨h₂, _⟩] <;> try rfl exact fun x h => h₁ x (List.Mem.tail _ h) #align turing.partrec_to_TM2.split_at_pred_eq Turing.PartrecToTM2.splitAtPred_eq theorem splitAtPred_false {α} (L : List α) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩ #align turing.partrec_to_TM2.split_at_pred_ff Turing.PartrecToTM2.splitAtPred_false theorem move_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ k₂) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.move p k₁ k₂ q), s, S⟩ ⟨some q, o, update (update S k₁ L₂) k₂ (L₁.reverseAux (S k₂))⟩ := by induction' L₁ with a L₁ IH generalizing S s · rw [(_ : [].reverseAux _ = _), Function.update_eq_self] swap · rw [Function.update_noteq h₁.symm, List.reverseAux_nil] refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq] revert e; cases' S k₁ with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ simp only [e] rfl · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq, List.reverseAux_cons] cases' e₁ : S k₁ with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, ne_eq, cond_false] convert @IH _ (update (update S k₁ Sk) k₂ (a :: S k₂)) _ using 2 <;> simp [Function.update_noteq, h₁, h₁.symm, e₃, List.reverseAux] simp [Function.update_comm h₁.symm] #align turing.partrec_to_TM2.move_ok Turing.PartrecToTM2.move_ok theorem unrev_ok {q s} {S : K' → List Γ'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _ #align turing.partrec_to_TM2.unrev_ok Turing.PartrecToTM2.unrev_ok theorem move₂_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ rev ∧ k₂ ≠ rev ∧ k₁ ≠ k₂) (h₂ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (move₂ p k₁ k₂ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons L₂)) k₂ (L₁ ++ S k₂)⟩ := by refine (move_ok h₁.1 e).trans (TransGen.head rfl ?_) simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim] cases o <;> simp only [Option.elim, id] · simp only [TM2.stepAux, Option.isSome, cond_false] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [Function.update_comm h₁.1, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_noteq h₁.1.symm, List.reverseAux_eq, h₂, Function.update_same, List.append_nil, List.reverse_reverse] · simp only [TM2.stepAux, Option.isSome, cond_true] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [h₂, Function.update_comm h₁.1, List.reverseAux_eq, Function.update_same, List.append_nil, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.1.symm, Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_same, List.reverse_reverse] #align turing.partrec_to_TM2.move₂_ok Turing.PartrecToTM2.move₂_ok theorem clear_ok {p k q s L₁ o L₂} {S : K' → List Γ'} (e : splitAtPred p (S k) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.clear p k q), s, S⟩ ⟨some q, o, update S k L₂⟩ := by induction' L₁ with a L₁ IH generalizing S s · refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] revert e; cases' S k with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ rcases e with ⟨e₁, e₂⟩ rw [e₁, e₂] · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] cases' e₁ : S k with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, cond_false] convert @IH _ (update S k Sk) _ using 2 <;> simp [e₃] #align turing.partrec_to_TM2.clear_ok Turing.PartrecToTM2.clear_ok theorem copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Λ'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction' b with x b IH generalizing a d s · refine TransGen.single ?_ simp refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some, List.tail_cons, elim_update_rev, ne_eq, Function.update_noteq, elim_main, elim_update_main, elim_stack, elim_update_stack, cond_true, List.reverseAux_cons] exact IH _ _ _ #align turing.partrec_to_TM2.copy_ok Turing.PartrecToTM2.copy_ok theorem trPosNum_natEnd : ∀ (n), ∀ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h #align turing.partrec_to_TM2.tr_pos_num_nat_end Turing.PartrecToTM2.trPosNum_natEnd theorem trNum_natEnd : ∀ (n), ∀ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h #align turing.partrec_to_TM2.tr_num_nat_end Turing.PartrecToTM2.trNum_natEnd theorem trNat_natEnd (n) : ∀ x ∈ trNat n, natEnd x = false := trNum_natEnd _ #align turing.partrec_to_TM2.tr_nat_nat_end Turing.PartrecToTM2.trNat_natEnd theorem trList_ne_consₗ : ∀ (l), ∀ x ∈ trList l, x ≠ Γ'.consₗ | a :: l, x, h => by simp [trList] at h obtain h | rfl | h := h · rintro rfl cases trNat_natEnd _ _ h · rintro ⟨⟩ · exact trList_ne_consₗ l _ h #align turing.partrec_to_TM2.tr_list_ne_Cons Turing.PartrecToTM2.trList_ne_consₗ theorem head_main_ok {q s L} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩ ⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by let o : Option Γ' := List.casesOn L none fun _ _ => some Γ'.cons refine (move_ok (by decide) (splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans (TransGen.head rfl (TransGen.head rfl ?_)) · cases L <;> simp [o] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev, Function.update_same, trList] rw [if_neg (show o ≠ some Γ'.consₗ by cases L <;> simp [o])] refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_ · exact fun x h => Bool.decide_false (trList_ne_consₗ _ _ h) convert unrev_ok using 2; simp [List.reverseAux_eq] #align turing.partrec_to_TM2.head_main_ok Turing.PartrecToTM2.head_main_ok theorem head_stack_ok {q s L₁ L₂ L₃} : Reaches₁ (TM2.step tr) ⟨some (head stack q), s, K'.elim (trList L₁) [] [] (trList L₂ ++ Γ'.consₗ :: L₃)⟩ ⟨some q, none, K'.elim (trList (L₂.headI :: L₁)) [] [] L₃⟩ := by cases' L₂ with a L₂ · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ [] (some Γ'.consₗ) L₃ (by rintro _ ⟨⟩) ⟨rfl, rfl⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_true, id_eq, trList, List.nil_append, elim_update_stack, elim_rev, List.reverseAux_nil, elim_update_rev, Function.update_same, List.headI_nil, trNat_default] convert unrev_ok using 2 simp · refine TransGen.trans (move_ok (by decide) (splitAtPred_eq _ _ (trNat a) (some Γ'.cons) (trList L₂ ++ Γ'.consₗ :: L₃) (trNat_natEnd _) ⟨rfl, by simp⟩)) (TransGen.head rfl (TransGen.head rfl ?_)) simp only [TM2.step, Option.mem_def, TM2.stepAux, ite_false, trList, List.append_assoc, List.cons_append, elim_update_stack, elim_rev, elim_update_rev, Function.update_same, List.headI_cons] refine TransGen.trans (clear_ok (splitAtPred_eq _ _ (trList L₂) (some Γ'.consₗ) L₃ (fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, by simp⟩)) ?_ convert unrev_ok using 2 simp [List.reverseAux_eq] #align turing.partrec_to_TM2.head_stack_ok Turing.PartrecToTM2.head_stack_ok theorem succ_ok {q s n} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (Λ'.succ q), s, K'.elim (trList [n]) [] c d⟩ ⟨some q, none, K'.elim (trList [n.succ]) [] c d⟩ := by simp only [TM2.step, trList, trNat.eq_1, Nat.cast_succ, Num.add_one] cases' (n : Num) with a · refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, decide_False, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, decide_True, Function.update_same, cond_true, cond_false] convert unrev_ok using 1 simp only [elim_update_rev, elim_rev, elim_main, List.reverseAux_nil, elim_update_main] rfl simp only [trNum, Num.succ, Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a.succ) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some q.succ, s, K'.elim (trPosNum a ++ [Γ'.cons]) l₁ c d⟩ ⟨some (unrev q), s', K'.elim (l₂' ++ [Γ'.cons]) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp? [List.reverseAux] at e says simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m _ generalizing s <;> intro l₁ · refine ⟨Γ'.bit0 :: l₁, [Γ'.bit1], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (Γ'.bit0 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp [PosNum.succ, trPosNum] rfl · refine ⟨l₁, _, some Γ'.bit0, rfl, TransGen.single ?_⟩ simp only [TM2.step, TM2.stepAux, elim_main, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, Function.update_same, Option.mem_def, Option.some.injEq] rfl #align turing.partrec_to_TM2.succ_ok Turing.PartrecToTM2.succ_ok theorem pred_ok (q₁ q₂ s v) (c d : List Γ') : ∃ s', Reaches₁ (TM2.step tr) ⟨some (Λ'.pred q₁ q₂), s, K'.elim (trList v) [] c d⟩ (v.headI.rec ⟨some q₁, s', K'.elim (trList v.tail) [] c d⟩ fun n _ => ⟨some q₂, s', K'.elim (trList (n::v.tail)) [] c d⟩) := by rcases v with (_ | ⟨_ | n, v⟩) · refine ⟨none, TransGen.single ?_⟩ simp · refine ⟨some Γ'.cons, TransGen.single ?_⟩ simp refine ⟨none, ?_⟩ simp only [TM2.step, trList, trNat.eq_1, trNum, Nat.cast_succ, Num.add_one, Num.succ, List.tail_cons, List.headI_cons] cases' (n : Num) with a · simp [trPosNum, trNum, show Num.zero.succ' = PosNum.one from rfl] refine TransGen.head rfl ?_ simp only [Option.mem_def, TM2.stepAux, elim_main, List.head?_cons, Option.some.injEq, decide_False, List.tail_cons, elim_update_main, ne_eq, Function.update_noteq, elim_rev, elim_update_rev, natEnd, Function.update_same, cond_true, cond_false] convert unrev_ok using 2 simp simp only [Num.succ'] suffices ∀ l₁, ∃ l₁' l₂' s', List.reverseAux l₁ (trPosNum a) = List.reverseAux l₁' l₂' ∧ Reaches₁ (TM2.step tr) ⟨some (q₁.pred q₂), s, K'.elim (trPosNum a.succ ++ Γ'.cons :: trList v) l₁ c d⟩ ⟨some (unrev q₂), s', K'.elim (l₂' ++ Γ'.cons :: trList v) l₁' c d⟩ by obtain ⟨l₁', l₂', s', e, h⟩ := this [] simp only [List.reverseAux] at e refine h.trans ?_ convert unrev_ok using 2 simp [e, List.reverseAux_eq] induction' a with m IH m IH generalizing s <;> intro l₁ · refine ⟨Γ'.bit1::l₁, [], some Γ'.cons, rfl, TransGen.head rfl (TransGen.single ?_)⟩ simp [trPosNum, show PosNum.one.succ = PosNum.one.bit0 from rfl] · obtain ⟨l₁', l₂', s', e, h⟩ := IH (some Γ'.bit0) (Γ'.bit1 :: l₁) refine ⟨l₁', l₂', s', e, TransGen.head ?_ h⟩ simp rfl · obtain ⟨a, l, e, h⟩ : ∃ a l, (trPosNum m = a::l) ∧ natEnd a = false := by cases m <;> refine ⟨_, _, rfl, rfl⟩ refine ⟨Γ'.bit0 :: l₁, _, some a, rfl, TransGen.single ?_⟩ simp [trPosNum, PosNum.succ, e, h, show some Γ'.bit1 ≠ some Γ'.bit0 by decide, Option.iget, -natEnd] rfl #align turing.partrec_to_TM2.pred_ok Turing.PartrecToTM2.pred_ok theorem trNormal_respects (c k v s) : ∃ b₂, TrCfg (stepNormal c k v) b₂ ∧ Reaches₁ (TM2.step tr) ⟨some (trNormal c (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by induction c generalizing k v s with | zero' => refine ⟨_, ⟨s, rfl⟩, TransGen.single ?_⟩; simp | succ => refine ⟨_, ⟨none, rfl⟩, head_main_ok.trans succ_ok⟩ | tail => let o : Option Γ' := List.casesOn v none fun _ _ => some Γ'.cons refine ⟨_, ⟨o, rfl⟩, ?_⟩; convert clear_ok _ using 2 · simp; rfl swap refine splitAtPred_eq _ _ (trNat v.headI) _ _ (trNat_natEnd _) ?_ cases v <;> simp [o] | cons f fs IHf _ => obtain ⟨c, h₁, h₂⟩ := IHf (Cont.cons₁ fs v k) v none refine ⟨c, h₁, TransGen.head rfl <| (move_ok (by decide) (splitAtPred_false _)).trans ?_⟩ simp only [TM2.step, Option.mem_def, elim_stack, elim_update_stack, elim_update_main, ne_eq, Function.update_noteq, elim_main, elim_rev, elim_update_rev] refine (copy_ok _ none [] (trList v).reverse _ _).trans ?_ convert h₂ using 2 simp [List.reverseAux_eq, trContStack] | comp f _ _ IHg => exact IHg (Cont.comp f k) v s | case f g IHf IHg => rw [stepNormal] simp only obtain ⟨s', h⟩ := pred_ok _ _ s v _ _ revert h; cases' v.headI with n <;> intro h · obtain ⟨c, h₁, h₂⟩ := IHf k _ s' exact ⟨_, h₁, h.trans h₂⟩ · obtain ⟨c, h₁, h₂⟩ := IHg k _ s' exact ⟨_, h₁, h.trans h₂⟩ | fix f IH => apply IH #align turing.partrec_to_TM2.tr_normal_respects Turing.PartrecToTM2.trNormal_respects theorem tr_ret_respects (k v s) : ∃ b₂, TrCfg (stepRet k v) b₂ ∧ Reaches₁ (TM2.step tr) ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ b₂ := by induction k generalizing v s with | halt => exact ⟨_, rfl, TransGen.single rfl⟩ | cons₁ fs as k _ => obtain ⟨s', h₁, h₂⟩ := trNormal_respects fs (Cont.cons₂ v k) as none refine ⟨s', h₁, TransGen.head rfl ?_⟩; simp refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl simp only [TM2.step, Option.mem_def, Option.elim, id_eq, elim_update_main, elim_main, elim_aux, List.append_nil, elim_update_aux] refine (move₂_ok (L₁ := ?_) (o := ?_) (L₂ := ?_) (by decide) rfl ?_).trans ?_ pick_goal 4 · exact splitAtPred_eq _ _ _ (some Γ'.consₗ) _ (fun x h => Bool.decide_false (trList_ne_consₗ _ _ h)) ⟨rfl, rfl⟩ refine (move₂_ok (by decide) ?_ (splitAtPred_false _)).trans ?_; · rfl simp only [TM2.step, Option.mem_def, Option.elim, elim_update_stack, elim_main, List.append_nil, elim_update_main, id_eq, elim_update_aux, ne_eq, Function.update_noteq, elim_aux, elim_stack] exact h₂ | cons₂ ns k IH => obtain ⟨c, h₁, h₂⟩ := IH (ns.headI :: v) none exact ⟨c, h₁, TransGen.head rfl <| head_stack_ok.trans h₂⟩ | comp f k _ => obtain ⟨s', h₁, h₂⟩ := trNormal_respects f k v s exact ⟨_, h₁, TransGen.head rfl h₂⟩ | fix f k IH => rw [stepRet] have : if v.headI = 0 then natEnd (trList v).head?.iget = true ∧ (trList v).tail = trList v.tail else natEnd (trList v).head?.iget = false ∧ (trList v).tail = (trNat v.headI).tail ++ Γ'.cons :: trList v.tail := by cases' v with n · exact ⟨rfl, rfl⟩ cases' n with n · simp rw [trList, List.headI, trNat, Nat.cast_succ, Num.add_one, Num.succ, List.tail] cases (n : Num).succ' <;> exact ⟨rfl, rfl⟩ by_cases h : v.headI = 0 <;> simp only [h, ite_true, ite_false] at this ⊢ · obtain ⟨c, h₁, h₂⟩ := IH v.tail (trList v).head? refine ⟨c, h₁, TransGen.head rfl ?_⟩ simp only [Option.mem_def, TM2.stepAux, trContStack, contStack, elim_main, this, cond_true, elim_update_main] exact h₂ · obtain ⟨s', h₁, h₂⟩ := trNormal_respects f (Cont.fix f k) v.tail (some Γ'.cons) refine ⟨_, h₁, TransGen.head rfl <| TransGen.trans ?_ h₂⟩ simp only [Option.mem_def, TM2.stepAux, elim_main, this.1, cond_false, elim_update_main, trCont] convert clear_ok (splitAtPred_eq _ _ (trNat v.headI).tail (some Γ'.cons) _ _ _) using 2 · simp convert rfl · exact fun x h => trNat_natEnd _ _ (List.tail_subset _ h) · exact ⟨rfl, this.2⟩ #align turing.partrec_to_TM2.tr_ret_respects Turing.PartrecToTM2.tr_ret_respects theorem tr_respects : Respects step (TM2.step tr) TrCfg | Cfg.ret _ _, _, ⟨_, rfl⟩ => tr_ret_respects _ _ _ | Cfg.halt _, _, rfl => rfl #align turing.partrec_to_TM2.tr_respects Turing.PartrecToTM2.tr_respects /-- The initial state, evaluating function `c` on input `v`. -/ def init (c : Code) (v : List ℕ) : Cfg' := ⟨some (trNormal c Cont'.halt), none, K'.elim (trList v) [] [] []⟩ #align turing.partrec_to_TM2.init Turing.PartrecToTM2.init theorem tr_init (c v) : ∃ b, TrCfg (stepNormal c Cont.halt v) b ∧ Reaches₁ (TM2.step tr) (init c v) b := trNormal_respects _ _ _ _ #align turing.partrec_to_TM2.tr_init Turing.PartrecToTM2.tr_init theorem tr_eval (c v) : eval (TM2.step tr) (init c v) = halt <$> Code.eval c v := by obtain ⟨i, h₁, h₂⟩ := tr_init c v refine Part.ext fun x => ?_ rw [reaches_eval h₂.to_reflTransGen]; simp [-TM2.step] refine ⟨fun h => ?_, ?_⟩ · obtain ⟨c, hc₁, hc₂⟩ := tr_eval_rev tr_respects h₁ h simp [stepNormal_eval] at hc₂ obtain ⟨v', hv, rfl⟩ := hc₂ exact ⟨_, hv, hc₁.symm⟩ · rintro ⟨v', hv, rfl⟩ have := Turing.tr_eval (b₁ := Cfg.halt v') tr_respects h₁ simp only [stepNormal_eval, Part.map_eq_map, Part.mem_map_iff, Cfg.halt.injEq, exists_eq_right] at this obtain ⟨_, ⟨⟩, h⟩ := this hv exact h #align turing.partrec_to_TM2.tr_eval Turing.PartrecToTM2.tr_eval /-- The set of machine states reachable via downward label jumps, discounting jumps via `ret`. -/ def trStmts₁ : Λ' → Finset Λ' | Q@(Λ'.move _ _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.push _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.read q) => insert Q <| Finset.univ.biUnion fun s => trStmts₁ (q s) | Q@(Λ'.clear _ _ q) => insert Q <| trStmts₁ q | Q@(Λ'.copy q) => insert Q <| trStmts₁ q | Q@(Λ'.succ q) => insert Q <| insert (unrev q) <| trStmts₁ q | Q@(Λ'.pred q₁ q₂) => insert Q <| trStmts₁ q₁ ∪ insert (unrev q₂) (trStmts₁ q₂) | Q@(Λ'.ret _) => {Q} #align turing.partrec_to_TM2.tr_stmts₁ Turing.PartrecToTM2.trStmts₁ theorem trStmts₁_trans {q q'} : q' ∈ trStmts₁ q → trStmts₁ q' ⊆ trStmts₁ q := by induction' q with _ _ _ q q_ih _ _ q q_ih q q_ih _ _ q q_ih q q_ih q q_ih q₁ q₂ q₁_ih q₂_ih _ <;> simp (config := { contextual := true }) only [trStmts₁, Finset.mem_insert, Finset.mem_union, or_imp, Finset.mem_singleton, Finset.Subset.refl, imp_true_iff, true_and_iff] repeat exact fun h => Finset.Subset.trans (q_ih h) (Finset.subset_insert _ _) · simp intro s h x h' simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_insert] exact Or.inr ⟨_, q_ih s h h'⟩ · constructor · rintro rfl apply Finset.subset_insert · intro h x h' simp only [Finset.mem_insert] exact Or.inr (Or.inr <| q_ih h h') · refine ⟨fun h x h' => ?_, fun _ x h' => ?_, fun h x h' => ?_⟩ <;> simp · exact Or.inr (Or.inr <| Or.inl <| q₁_ih h h') · cases' Finset.mem_insert.1 h' with h' h' <;> simp [h', unrev] · exact Or.inr (Or.inr <| Or.inr <| q₂_ih h h') #align turing.partrec_to_TM2.tr_stmts₁_trans Turing.PartrecToTM2.trStmts₁_trans theorem trStmts₁_self (q) : q ∈ trStmts₁ q := by induction q <;> · first |apply Finset.mem_singleton_self|apply Finset.mem_insert_self #align turing.partrec_to_TM2.tr_stmts₁_self Turing.PartrecToTM2.trStmts₁_self /-- The (finite!) set of machine states visited during the course of evaluation of `c`, including the state `ret k` but not any states after that (that is, the states visited while evaluating `k`). -/ def codeSupp' : Code → Cont' → Finset Λ' | c@Code.zero', k => trStmts₁ (trNormal c k) | c@Code.succ, k => trStmts₁ (trNormal c k) | c@Code.tail, k => trStmts₁ (trNormal c k) | c@(Code.cons f fs), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f (Cont'.cons₁ fs k) ∪ (trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ (codeSupp' fs (Cont'.cons₂ k) ∪ trStmts₁ (head stack <| Λ'.ret k)))) | c@(Code.comp f g), k => trStmts₁ (trNormal c k) ∪ (codeSupp' g (Cont'.comp f k) ∪ (trStmts₁ (trNormal f k) ∪ codeSupp' f k)) | c@(Code.case f g), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f k ∪ codeSupp' g k) | c@(Code.fix f), k => trStmts₁ (trNormal c k) ∪ (codeSupp' f (Cont'.fix f k) ∪ (trStmts₁ (Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) ∪ {Λ'.ret k})) #align turing.partrec_to_TM2.code_supp' Turing.PartrecToTM2.codeSupp' @[simp] theorem codeSupp'_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp' c k := by cases c <;> first | rfl | exact Finset.union_subset_left (fun _ a ↦ a) #align turing.partrec_to_TM2.code_supp'_self Turing.PartrecToTM2.codeSupp'_self /-- The (finite!) set of machine states visited during the course of evaluation of a continuation `k`, not including the initial state `ret k`. -/ def contSupp : Cont' → Finset Λ' | Cont'.cons₁ fs k => trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ (codeSupp' fs (Cont'.cons₂ k) ∪ (trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k)) | Cont'.cons₂ k => trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k | Cont'.comp f k => codeSupp' f k ∪ contSupp k | Cont'.fix f k => codeSupp' (Code.fix f) k ∪ contSupp k | Cont'.halt => ∅ #align turing.partrec_to_TM2.cont_supp Turing.PartrecToTM2.contSupp /-- The (finite!) set of machine states visited during the course of evaluation of `c` in continuation `k`. This is actually closed under forward simulation (see `tr_supports`), and the existence of this set means that the machine constructed in this section is in fact a proper Turing machine, with a finite set of states. -/ def codeSupp (c : Code) (k : Cont') : Finset Λ' := codeSupp' c k ∪ contSupp k #align turing.partrec_to_TM2.code_supp Turing.PartrecToTM2.codeSupp @[simp] theorem codeSupp_self (c k) : trStmts₁ (trNormal c k) ⊆ codeSupp c k := Finset.Subset.trans (codeSupp'_self _ _) (Finset.union_subset_left fun _ a ↦ a) #align turing.partrec_to_TM2.code_supp_self Turing.PartrecToTM2.codeSupp_self @[simp] theorem codeSupp_zero (k) : codeSupp Code.zero' k = trStmts₁ (trNormal Code.zero' k) ∪ contSupp k := rfl #align turing.partrec_to_TM2.code_supp_zero Turing.PartrecToTM2.codeSupp_zero @[simp] theorem codeSupp_succ (k) : codeSupp Code.succ k = trStmts₁ (trNormal Code.succ k) ∪ contSupp k := rfl #align turing.partrec_to_TM2.code_supp_succ Turing.PartrecToTM2.codeSupp_succ @[simp] theorem codeSupp_tail (k) : codeSupp Code.tail k = trStmts₁ (trNormal Code.tail k) ∪ contSupp k := rfl #align turing.partrec_to_TM2.code_supp_tail Turing.PartrecToTM2.codeSupp_tail @[simp] theorem codeSupp_cons (f fs k) : codeSupp (Code.cons f fs) k = trStmts₁ (trNormal (Code.cons f fs) k) ∪ codeSupp f (Cont'.cons₁ fs k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] #align turing.partrec_to_TM2.code_supp_cons Turing.PartrecToTM2.codeSupp_cons @[simp] theorem codeSupp_comp (f g k) : codeSupp (Code.comp f g) k = trStmts₁ (trNormal (Code.comp f g) k) ∪ codeSupp g (Cont'.comp f k) := by simp only [codeSupp, codeSupp', trNormal, Finset.union_assoc, contSupp] rw [← Finset.union_assoc _ _ (contSupp k), Finset.union_eq_right.2 (codeSupp'_self _ _)] #align turing.partrec_to_TM2.code_supp_comp Turing.PartrecToTM2.codeSupp_comp @[simp] theorem codeSupp_case (f g k) : codeSupp (Code.case f g) k = trStmts₁ (trNormal (Code.case f g) k) ∪ (codeSupp f k ∪ codeSupp g k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm] #align turing.partrec_to_TM2.code_supp_case Turing.PartrecToTM2.codeSupp_case @[simp] theorem codeSupp_fix (f k) : codeSupp (Code.fix f) k = trStmts₁ (trNormal (Code.fix f) k) ∪ codeSupp f (Cont'.fix f k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.union_left_comm, Finset.union_left_idem] #align turing.partrec_to_TM2.code_supp_fix Turing.PartrecToTM2.codeSupp_fix @[simp] theorem contSupp_cons₁ (fs k) : contSupp (Cont'.cons₁ fs k) = trStmts₁ (move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k)) ∪ codeSupp fs (Cont'.cons₂ k) := by simp [codeSupp, codeSupp', contSupp, Finset.union_assoc] #align turing.partrec_to_TM2.cont_supp_cons₁ Turing.PartrecToTM2.contSupp_cons₁ @[simp] theorem contSupp_cons₂ (k) : contSupp (Cont'.cons₂ k) = trStmts₁ (head stack <| Λ'.ret k) ∪ contSupp k := rfl #align turing.partrec_to_TM2.cont_supp_cons₂ Turing.PartrecToTM2.contSupp_cons₂ @[simp] theorem contSupp_comp (f k) : contSupp (Cont'.comp f k) = codeSupp f k := rfl #align turing.partrec_to_TM2.cont_supp_comp Turing.PartrecToTM2.contSupp_comp theorem contSupp_fix (f k) : contSupp (Cont'.fix f k) = codeSupp f (Cont'.fix f k) := by simp (config := { contextual := true }) [codeSupp, codeSupp', contSupp, Finset.union_assoc, Finset.subset_iff] #align turing.partrec_to_TM2.cont_supp_fix Turing.PartrecToTM2.contSupp_fix @[simp] theorem contSupp_halt : contSupp Cont'.halt = ∅ := rfl #align turing.partrec_to_TM2.cont_supp_halt Turing.PartrecToTM2.contSupp_halt /-- The statement `Λ'.Supports S q` means that `contSupp k ⊆ S` for any `ret k` reachable from `q`. (This is a technical condition used in the proof that the machine is supported.) -/ def Λ'.Supports (S : Finset Λ') : Λ' → Prop | Λ'.move _ _ _ q => Λ'.Supports S q | Λ'.push _ _ q => Λ'.Supports S q | Λ'.read q => ∀ s, Λ'.Supports S (q s) | Λ'.clear _ _ q => Λ'.Supports S q | Λ'.copy q => Λ'.Supports S q | Λ'.succ q => Λ'.Supports S q | Λ'.pred q₁ q₂ => Λ'.Supports S q₁ ∧ Λ'.Supports S q₂ | Λ'.ret k => contSupp k ⊆ S #align turing.partrec_to_TM2.Λ'.supports Turing.PartrecToTM2.Λ'.Supports /-- A shorthand for the predicate that we are proving in the main theorems `trStmts₁_supports`, `codeSupp'_supports`, `contSupp_supports`, `codeSupp_supports`. The set `S` is fixed throughout the proof, and denotes the full set of states in the machine, while `K` is a subset that we are currently proving a property about. The predicate asserts that every state in `K` is closed in `S` under forward simulation, i.e. stepping forward through evaluation starting from any state in `K` stays entirely within `S`. -/ def Supports (K S : Finset Λ') := ∀ q ∈ K, TM2.SupportsStmt S (tr q) #align turing.partrec_to_TM2.supports Turing.PartrecToTM2.Supports theorem supports_insert {K S q} : Supports (insert q K) S ↔ TM2.SupportsStmt S (tr q) ∧ Supports K S := by simp [Supports] #align turing.partrec_to_TM2.supports_insert Turing.PartrecToTM2.supports_insert theorem supports_singleton {S q} : Supports {q} S ↔ TM2.SupportsStmt S (tr q) := by simp [Supports] #align turing.partrec_to_TM2.supports_singleton Turing.PartrecToTM2.supports_singleton theorem supports_union {K₁ K₂ S} : Supports (K₁ ∪ K₂) S ↔ Supports K₁ S ∧ Supports K₂ S := by simp [Supports, or_imp, forall_and] #align turing.partrec_to_TM2.supports_union Turing.PartrecToTM2.supports_union theorem supports_biUnion {K : Option Γ' → Finset Λ'} {S} : Supports (Finset.univ.biUnion K) S ↔ ∀ a, Supports (K a) S := by simp [Supports]; apply forall_swap #align turing.partrec_to_TM2.supports_bUnion Turing.PartrecToTM2.supports_biUnion theorem head_supports {S k q} (H : (q : Λ').Supports S) : (head k q).Supports S := fun _ => by dsimp only; split_ifs <;> exact H #align turing.partrec_to_TM2.head_supports Turing.PartrecToTM2.head_supports theorem ret_supports {S k} (H₁ : contSupp k ⊆ S) : TM2.SupportsStmt S (tr (Λ'.ret k)) := by have W := fun {q} => trStmts₁_self q cases k with | halt => trivial | cons₁ => rw [contSupp_cons₁, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | cons₂ => rw [contSupp_cons₂, Finset.union_subset_iff] at H₁; exact fun _ => H₁.1 W | comp => rw [contSupp_comp] at H₁; exact fun _ => H₁ (codeSupp_self _ _ W) | fix => rw [contSupp_fix] at H₁ have L := @Finset.mem_union_left; have R := @Finset.mem_union_right intro s; dsimp only; cases natEnd s.iget · refine H₁ (R _ <| L _ <| R _ <| R _ <| L _ W) · exact H₁ (R _ <| L _ <| R _ <| R _ <| R _ <| Finset.mem_singleton_self _) #align turing.partrec_to_TM2.ret_supports Turing.PartrecToTM2.ret_supports theorem trStmts₁_supports {S q} (H₁ : (q : Λ').Supports S) (HS₁ : trStmts₁ q ⊆ S) : Supports (trStmts₁ q) S := by have W := fun {q} => trStmts₁_self q induction' q with _ _ _ q q_ih _ _ q q_ih q q_ih _ _ q q_ih q q_ih q q_ih q₁ q₂ q₁_ih q₂_ih _ <;> simp [trStmts₁, -Finset.singleton_subset_iff] at HS₁ ⊢ any_goals cases' Finset.insert_subset_iff.1 HS₁ with h₁ h₂ first | have h₃ := h₂ W | try simp [Finset.subset_iff] at h₂ · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- move · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₁⟩, q_ih H₁ h₂⟩ -- clear · exact supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- copy · exact supports_insert.2 ⟨⟨fun _ => h₃, fun _ => h₃⟩, q_ih H₁ h₂⟩ -- push · refine supports_insert.2 ⟨fun _ => h₂ _ W, ?_⟩ -- read exact supports_biUnion.2 fun _ => q_ih _ (H₁ _) fun _ h => h₂ _ h · refine supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩ -- succ exact supports_insert.2 ⟨⟨fun _ => h₂.2 _ W, fun _ => h₂.1⟩, q_ih H₁ h₂.2⟩ · refine -- pred supports_insert.2 ⟨⟨fun _ => h₁, fun _ => h₂.2 _ (Or.inl W), fun _ => h₂.1, fun _ => h₂.1⟩, ?_⟩ refine supports_insert.2 ⟨⟨fun _ => h₂.2 _ (Or.inr W), fun _ => h₂.1⟩, ?_⟩ refine supports_union.2 ⟨?_, ?_⟩ · exact q₁_ih H₁.1 fun _ h => h₂.2 _ (Or.inl h) · exact q₂_ih H₁.2 fun _ h => h₂.2 _ (Or.inr h) · exact supports_singleton.2 (ret_supports H₁) -- ret #align turing.partrec_to_TM2.tr_stmts₁_supports Turing.PartrecToTM2.trStmts₁_supports theorem trStmts₁_supports' {S q K} (H₁ : (q : Λ').Supports S) (H₂ : trStmts₁ q ∪ K ⊆ S) (H₃ : K ⊆ S → Supports K S) : Supports (trStmts₁ q ∪ K) S := by simp only [Finset.union_subset_iff] at H₂ exact supports_union.2 ⟨trStmts₁_supports H₁ H₂.1, H₃ H₂.2⟩ #align turing.partrec_to_TM2.tr_stmts₁_supports' Turing.PartrecToTM2.trStmts₁_supports'
Mathlib/Computability/TMToPartrec.lean
1,979
1,992
theorem trNormal_supports {S c k} (Hk : codeSupp c k ⊆ S) : (trNormal c k).Supports S := by
induction c generalizing k with simp [Λ'.Supports, head] | zero' => exact Finset.union_subset_right Hk | succ => intro; split_ifs <;> exact Finset.union_subset_right Hk | tail => exact Finset.union_subset_right Hk | cons f fs IHf _ => apply IHf rw [codeSupp_cons] at Hk exact Finset.union_subset_right Hk | comp f g _ IHg => apply IHg; rw [codeSupp_comp] at Hk; exact Finset.union_subset_right Hk | case f g IHf IHg => simp only [codeSupp_case, Finset.union_subset_iff] at Hk exact ⟨IHf Hk.2.1, IHg Hk.2.2⟩ | fix f IHf => apply IHf; rw [codeSupp_fix] at Hk; exact Finset.union_subset_right Hk
/- Copyright (c) 2021 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Quasispectrum import Mathlib.FieldTheory.IsAlgClosed.Spectrum import Mathlib.Analysis.Complex.Liouville import Mathlib.Analysis.Complex.Polynomial import Mathlib.Analysis.Analytic.RadiusLiminf import Mathlib.Topology.Algebra.Module.CharacterSpace import Mathlib.Analysis.NormedSpace.Exponential import Mathlib.Analysis.NormedSpace.UnitizationL1 #align_import analysis.normed_space.spectrum from "leanprover-community/mathlib"@"d608fc5d4e69d4cc21885913fb573a88b0deb521" /-! # The spectrum of elements in a complete normed algebra This file contains the basic theory for the resolvent and spectrum of a Banach algebra. ## Main definitions * `spectralRadius : ℝ≥0∞`: supremum of `‖k‖₊` for all `k ∈ spectrum 𝕜 a` * `NormedRing.algEquivComplexOfComplete`: **Gelfand-Mazur theorem** For a complex Banach division algebra, the natural `algebraMap ℂ A` is an algebra isomorphism whose inverse is given by selecting the (unique) element of `spectrum ℂ a` ## Main statements * `spectrum.isOpen_resolventSet`: the resolvent set is open. * `spectrum.isClosed`: the spectrum is closed. * `spectrum.subset_closedBall_norm`: the spectrum is a subset of closed disk of radius equal to the norm. * `spectrum.isCompact`: the spectrum is compact. * `spectrum.spectralRadius_le_nnnorm`: the spectral radius is bounded above by the norm. * `spectrum.hasDerivAt_resolvent`: the resolvent function is differentiable on the resolvent set. * `spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius`: Gelfand's formula for the spectral radius in Banach algebras over `ℂ`. * `spectrum.nonempty`: the spectrum of any element in a complex Banach algebra is nonempty. ## TODO * compute all derivatives of `resolvent a`. -/ open scoped ENNReal NNReal open NormedSpace -- For `NormedSpace.exp`. /-- The *spectral radius* is the supremum of the `nnnorm` (`‖·‖₊`) of elements in the spectrum, coerced into an element of `ℝ≥0∞`. Note that it is possible for `spectrum 𝕜 a = ∅`. In this case, `spectralRadius a = 0`. It is also possible that `spectrum 𝕜 a` be unbounded (though not for Banach algebras, see `spectrum.isBounded`, below). In this case, `spectralRadius a = ∞`. -/ noncomputable def spectralRadius (𝕜 : Type*) {A : Type*} [NormedField 𝕜] [Ring A] [Algebra 𝕜 A] (a : A) : ℝ≥0∞ := ⨆ k ∈ spectrum 𝕜 a, ‖k‖₊ #align spectral_radius spectralRadius variable {𝕜 : Type*} {A : Type*} namespace spectrum section SpectrumCompact open Filter variable [NormedField 𝕜] [NormedRing A] [NormedAlgebra 𝕜 A] local notation "σ" => spectrum 𝕜 local notation "ρ" => resolventSet 𝕜 local notation "↑ₐ" => algebraMap 𝕜 A @[simp]
Mathlib/Analysis/NormedSpace/Spectrum.lean
79
80
theorem SpectralRadius.of_subsingleton [Subsingleton A] (a : A) : spectralRadius 𝕜 a = 0 := by
simp [spectralRadius]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Scott Morrison -/ import Mathlib.Tactic.NormNum import Mathlib.Tactic.TryThis import Mathlib.Util.AtomM /-! # The `abel` tactic Evaluate expressions in the language of additive, commutative monoids and groups. -/ set_option autoImplicit true namespace Mathlib.Tactic.Abel open Lean Elab Meta Tactic Qq initialize registerTraceClass `abel initialize registerTraceClass `abel.detail /-- The `Context` for a call to `abel`. Stores a few options for this call, and caches some common subexpressions such as typeclass instances and `0 : α`. -/ structure Context where /-- The type of the ambient additive commutative group or monoid. -/ α : Expr /-- The universe level for `α`. -/ univ : Level /-- The expression representing `0 : α`. -/ α0 : Expr /-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/ isGroup : Bool /-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/ inst : Expr /-- Populate a `context` object for evaluating `e`. -/ def mkContext (e : Expr) : MetaM Context := do let α ← inferType e let c ← synthInstance (← mkAppM ``AddCommMonoid #[α]) let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α]) let u ← mkFreshLevelMVar _ ← isDefEq (.sort (.succ u)) (← inferType α) let α0 ← Expr.ofNat α 0 match cg with | some cg => return ⟨α, u, α0, true, cg⟩ | _ => return ⟨α, u, α0, false, c⟩ /-- The monad for `Abel` contains, in addition to the `AtomM` state, some information about the current type we are working over, so that we can consistently use group lemmas or monoid lemmas as appropriate. -/ abbrev M := ReaderT Context AtomM /-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the implicit parameters in the context, and the given list of arguments. -/ def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr := mkAppN (((@Expr.const n [c.univ]).app c.α).app inst) /-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the context, and the given list of arguments. Compared to `context.app`, this takes the name of the typeclass, rather than an inferred typeclass instance. -/ def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l /-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`. This is used to choose between declarations taking `AddCommMonoid` and those taking `AddCommGroup` instances. -/ def addG : Name → Name | .str p s => .str p (s ++ "g") | n => n /-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments. Will use the `AddComm{Monoid,Group}` instance that has been cached in the context. -/ def iapp (n : Name) (xs : Array Expr) : M Expr := do let c ← read return c.app (if c.isGroup then addG n else n) c.inst xs /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/ def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a /-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/ def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a /-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/ def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a] /-- Interpret an integer as a coefficient to a term. -/ def intToExpr (n : ℤ) : M Expr := do Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n /-- A normal form for `abel`. Expressions are represented as a list of terms of the form `e = n • x`, where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group. We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed, for efficiency. -/ inductive NormalExpr : Type | zero (e : Expr) : NormalExpr | nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr deriving Inhabited /-- Extract the expression from a normal form. -/ def NormalExpr.e : NormalExpr → Expr | .zero e => e | .nterm e .. => e instance : Coe NormalExpr Expr where coe := NormalExpr.e /-- Construct the normal form representing a single term. -/ def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr := return .nterm (← mkTerm n.1 x.2 a) n x a /-- Construct the normal form representing zero. -/ def NormalExpr.zero' : M NormalExpr := return NormalExpr.zero (← read).α0 open NormalExpr theorem const_add_term {α} [AddCommMonoid α] (k n x a a') (h : k + a = a') : k + @term α _ n x a = term n x a' := by simp [h.symm, term, add_comm, add_assoc] theorem const_add_termg {α} [AddCommGroup α] (k n x a a') (h : k + a = a') : k + @termg α _ n x a = termg n x a' := by simp [h.symm, termg, add_comm, add_assoc] theorem term_add_const {α} [AddCommMonoid α] (n x a k a') (h : a + k = a') : @term α _ n x a + k = term n x a' := by simp [h.symm, term, add_assoc] theorem term_add_constg {α} [AddCommGroup α] (n x a k a') (h : a + k = a') : @termg α _ n x a + k = termg n x a' := by simp [h.symm, termg, add_assoc]
Mathlib/Tactic/Abel.lean
144
146
theorem term_add_term {α} [AddCommMonoid α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') : @term α _ n₁ x a₁ + @term α _ n₂ x a₂ = term n' x a' := by
simp [h₁.symm, h₂.symm, term, add_nsmul, add_assoc, add_left_comm]
/- Copyright (c) 2021 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.CategoryTheory.Monoidal.Free.Coherence import Mathlib.Tactic.CategoryTheory.Coherence import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.Tactic.ApplyFun #align_import category_theory.monoidal.rigid.basic from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042" /-! # Rigid (autonomous) monoidal categories This file defines rigid (autonomous) monoidal categories and the necessary theory about exact pairings and duals. ## Main definitions * `ExactPairing` of two objects of a monoidal category * Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists * The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y` * The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory` ## Main statements * `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of adjoint mates. ## Notations * `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing. * `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint mate of a morphism. ## Future work * Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing. * Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself. * Simplify constructions in the case where a symmetry or braiding is present. * Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`. * Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`). ## Notes Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`, this is not a bijective correspondence. I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are module endofunctors of `C` as a right `C` module category, and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action. ## References * <https://ncatlab.org/nlab/show/rigid+monoidal+category> ## Tags rigid category, monoidal category -/ open CategoryTheory MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- An exact pairing is a pair of objects `X Y : C` which admit a coevaluation and evaluation morphism which fulfill two triangle equalities. -/ class ExactPairing (X Y : C) where /-- Coevaluation of an exact pairing. Do not use directly. Use `ExactPairing.coevaluation` instead. -/ coevaluation' : 𝟙_ C ⟶ X ⊗ Y /-- Evaluation of an exact pairing. Do not use directly. Use `ExactPairing.evaluation` instead. -/ evaluation' : Y ⊗ X ⟶ 𝟙_ C coevaluation_evaluation' : Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by aesop_cat evaluation_coevaluation' : coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by aesop_cat #align category_theory.exact_pairing CategoryTheory.ExactPairing namespace ExactPairing -- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make -- arguments for class fields explicit, -- we now repeat all the fields without primes. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit variable (X Y : C) variable [ExactPairing X Y] /-- Coevaluation of an exact pairing. -/ def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _ /-- Evaluation of an exact pairing. -/ def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _ @[inherit_doc] notation "η_" => ExactPairing.coevaluation @[inherit_doc] notation "ε_" => ExactPairing.evaluation lemma coevaluation_evaluation : Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := coevaluation_evaluation' lemma evaluation_coevaluation : η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv := evaluation_coevaluation' lemma coevaluation_evaluation'' : Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙 := by convert coevaluation_evaluation X Y <;> simp [monoidalComp] lemma evaluation_coevaluation'' : η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙 := by convert evaluation_coevaluation X Y <;> simp [monoidalComp] end ExactPairing attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where coevaluation' := (ρ_ _).inv evaluation' := (ρ_ _).hom coevaluation_evaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence evaluation_coevaluation' := by rw [← id_tensorHom, ← tensorHom_id]; coherence #align category_theory.exact_pairing_unit CategoryTheory.exactPairingUnit /-- A class of objects which have a right dual. -/ class HasRightDual (X : C) where /-- The right dual of the object `X`. -/ rightDual : C [exact : ExactPairing X rightDual] #align category_theory.has_right_dual CategoryTheory.HasRightDual /-- A class of objects which have a left dual. -/ class HasLeftDual (Y : C) where /-- The left dual of the object `X`. -/ leftDual : C [exact : ExactPairing leftDual Y] #align category_theory.has_left_dual CategoryTheory.HasLeftDual attribute [instance] HasRightDual.exact attribute [instance] HasLeftDual.exact open ExactPairing HasRightDual HasLeftDual MonoidalCategory @[inherit_doc] prefix:1024 "ᘁ" => leftDual @[inherit_doc] postfix:1024 "ᘁ" => rightDual instance hasRightDualUnit : HasRightDual (𝟙_ C) where rightDual := 𝟙_ C #align category_theory.has_right_dual_unit CategoryTheory.hasRightDualUnit instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where leftDual := 𝟙_ C #align category_theory.has_left_dual_unit CategoryTheory.hasLeftDualUnit instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where rightDual := X #align category_theory.has_right_dual_left_dual CategoryTheory.hasRightDualLeftDual instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where leftDual := X #align category_theory.has_left_dual_right_dual CategoryTheory.hasLeftDualRightDual @[simp] theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X := rfl #align category_theory.left_dual_right_dual CategoryTheory.leftDual_rightDual @[simp] theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X := rfl #align category_theory.right_dual_left_dual CategoryTheory.rightDual_leftDual /-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/ def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom #align category_theory.right_adjoint_mate CategoryTheory.rightAdjointMate /-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/ def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX := (λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom #align category_theory.left_adjoint_mate CategoryTheory.leftAdjointMate @[inherit_doc] notation f "ᘁ" => rightAdjointMate f @[inherit_doc] notation "ᘁ" f => leftAdjointMate f @[simp] theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by simp [rightAdjointMate] #align category_theory.right_adjoint_mate_id CategoryTheory.rightAdjointMate_id @[simp] theorem leftAdjointMate_id {X : C} [HasLeftDual X] : (ᘁ(𝟙 X)) = 𝟙 (ᘁX) := by simp [leftAdjointMate] #align category_theory.left_adjoint_mate_id CategoryTheory.leftAdjointMate_id theorem rightAdjointMate_comp {X Y Z : C} [HasRightDual X] [HasRightDual Y] {f : X ⟶ Y} {g : Xᘁ ⟶ Z} : fᘁ ≫ g = (ρ_ (Yᘁ)).inv ≫ _ ◁ η_ X (Xᘁ) ≫ _ ◁ (f ⊗ g) ≫ (α_ (Yᘁ) Y Z).inv ≫ ε_ Y (Yᘁ) ▷ _ ≫ (λ_ Z).hom := calc _ = 𝟙 _ ⊗≫ Yᘁ ◁ η_ X Xᘁ ≫ Yᘁ ◁ f ▷ Xᘁ ⊗≫ (ε_ Y Yᘁ ▷ Xᘁ ≫ 𝟙_ C ◁ g) ⊗≫ 𝟙 _ := by dsimp only [rightAdjointMate]; coherence _ = _ := by rw [← whisker_exchange, tensorHom_def]; coherence #align category_theory.right_adjoint_mate_comp CategoryTheory.rightAdjointMate_comp theorem leftAdjointMate_comp {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] {f : X ⟶ Y} {g : (ᘁX) ⟶ Z} : (ᘁf) ≫ g = (λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (g ⊗ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom := calc _ = 𝟙 _ ⊗≫ η_ (ᘁX) X ▷ (ᘁY) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ⊗≫ ((ᘁX) ◁ ε_ (ᘁY) Y ≫ g ▷ 𝟙_ C) ⊗≫ 𝟙 _ := by dsimp only [leftAdjointMate]; coherence _ = _ := by rw [whisker_exchange, tensorHom_def']; coherence #align category_theory.left_adjoint_mate_comp CategoryTheory.leftAdjointMate_comp /-- The composition of right adjoint mates is the adjoint mate of the composition. -/ @[reassoc] theorem comp_rightAdjointMate {X Y Z : C} [HasRightDual X] [HasRightDual Y] [HasRightDual Z] {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g)ᘁ = gᘁ ≫ fᘁ := by rw [rightAdjointMate_comp] simp only [rightAdjointMate, comp_whiskerRight] simp only [← Category.assoc]; congr 3; simp only [Category.assoc] simp only [← MonoidalCategory.whiskerLeft_comp]; congr 2 symm calc _ = 𝟙 _ ⊗≫ (η_ Y Yᘁ ▷ 𝟙_ C ≫ (Y ⊗ Yᘁ) ◁ η_ X Xᘁ) ⊗≫ Y ◁ Yᘁ ◁ f ▷ Xᘁ ⊗≫ Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [tensorHom_def']; coherence _ = η_ X Xᘁ ⊗≫ (η_ Y Yᘁ ▷ (X ⊗ Xᘁ) ≫ (Y ⊗ Yᘁ) ◁ f ▷ Xᘁ) ⊗≫ Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = η_ X Xᘁ ⊗≫ f ▷ Xᘁ ⊗≫ (η_ Y Yᘁ ▷ Y ⊗≫ Y ◁ ε_ Y Yᘁ) ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = η_ X Xᘁ ≫ f ▷ Xᘁ ≫ g ▷ Xᘁ := by rw [evaluation_coevaluation'']; coherence #align category_theory.comp_right_adjoint_mate CategoryTheory.comp_rightAdjointMate /-- The composition of left adjoint mates is the adjoint mate of the composition. -/ @[reassoc] theorem comp_leftAdjointMate {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] [HasLeftDual Z] {f : X ⟶ Y} {g : Y ⟶ Z} : (ᘁf ≫ g) = (ᘁg) ≫ ᘁf := by rw [leftAdjointMate_comp] simp only [leftAdjointMate, MonoidalCategory.whiskerLeft_comp] simp only [← Category.assoc]; congr 3; simp only [Category.assoc] simp only [← comp_whiskerRight]; congr 2 symm calc _ = 𝟙 _ ⊗≫ ((𝟙_ C) ◁ η_ (ᘁY) Y ≫ η_ (ᘁX) X ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ▷ Y ⊗≫ (ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by rw [tensorHom_def]; coherence _ = η_ (ᘁX) X ⊗≫ (((ᘁX) ⊗ X) ◁ η_ (ᘁY) Y ≫ ((ᘁX) ◁ f) ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by rw [whisker_exchange]; coherence _ = η_ (ᘁX) X ⊗≫ ((ᘁX) ◁ f) ⊗≫ (ᘁX) ◁ (Y ◁ η_ (ᘁY) Y ⊗≫ ε_ (ᘁY) Y ▷ Y) ⊗≫ (ᘁX) ◁ g := by rw [whisker_exchange]; coherence _ = η_ (ᘁX) X ≫ (ᘁX) ◁ f ≫ (ᘁX) ◁ g := by rw [coevaluation_evaluation'']; coherence #align category_theory.comp_left_adjoint_mate CategoryTheory.comp_leftAdjointMate /-- Given an exact pairing on `Y Y'`, we get a bijection on hom-sets `(Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z)` by "pulling the string on the left" up or down. This gives the adjunction `tensorLeftAdjunction Y Y' : tensorLeft Y' ⊣ tensorLeft Y`. This adjunction is often referred to as "Frobenius reciprocity" in the fusion categories / planar algebras / subfactors literature. -/ def tensorLeftHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z) where toFun f := (λ_ _).inv ≫ η_ _ _ ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ f invFun f := Y' ◁ f ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom left_inv f := by calc _ = 𝟙 _ ⊗≫ Y' ◁ η_ Y Y' ▷ X ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ▷ X ⊗≫ f := by rw [whisker_exchange]; coherence _ = f := by rw [coevaluation_evaluation'']; coherence right_inv f := by calc _ = 𝟙 _ ⊗≫ (η_ Y Y' ▷ X ≫ (Y ⊗ Y') ◁ f) ⊗≫ Y ◁ ε_ Y Y' ▷ Z ⊗≫ 𝟙 _ := by coherence _ = f ⊗≫ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ▷ Z ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = f := by rw [evaluation_coevaluation'']; coherence #align category_theory.tensor_left_hom_equiv CategoryTheory.tensorLeftHomEquiv /-- Given an exact pairing on `Y Y'`, we get a bijection on hom-sets `(X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y')` by "pulling the string on the right" up or down. -/ def tensorRightHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y') where toFun f := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ f ▷ _ invFun f := f ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom left_inv f := by calc _ = 𝟙 _ ⊗≫ X ◁ η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X ◁ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by rw [← whisker_exchange]; coherence _ = f := by rw [evaluation_coevaluation'']; coherence right_inv f := by calc _ = 𝟙 _ ⊗≫ (X ◁ η_ Y Y' ≫ f ▷ (Y ⊗ Y')) ⊗≫ Z ◁ ε_ Y Y' ▷ Y' ⊗≫ 𝟙 _ := by coherence _ = f ⊗≫ Z ◁ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ 𝟙 _ := by rw [whisker_exchange]; coherence _ = f := by rw [coevaluation_evaluation'']; coherence #align category_theory.tensor_right_hom_equiv CategoryTheory.tensorRightHomEquiv theorem tensorLeftHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : Y' ⊗ X ⟶ Z) (g : Z ⟶ Z') : (tensorLeftHomEquiv X Y Y' Z') (f ≫ g) = (tensorLeftHomEquiv X Y Y' Z) f ≫ Y ◁ g := by simp [tensorLeftHomEquiv] #align category_theory.tensor_left_hom_equiv_naturality CategoryTheory.tensorLeftHomEquiv_naturality theorem tensorLeftHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X') (g : X' ⟶ Y ⊗ Z) : (tensorLeftHomEquiv X Y Y' Z).symm (f ≫ g) = _ ◁ f ≫ (tensorLeftHomEquiv X' Y Y' Z).symm g := by simp [tensorLeftHomEquiv] #align category_theory.tensor_left_hom_equiv_symm_naturality CategoryTheory.tensorLeftHomEquiv_symm_naturality theorem tensorRightHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⊗ Y ⟶ Z) (g : Z ⟶ Z') : (tensorRightHomEquiv X Y Y' Z') (f ≫ g) = (tensorRightHomEquiv X Y Y' Z) f ≫ g ▷ Y' := by simp [tensorRightHomEquiv] #align category_theory.tensor_right_hom_equiv_naturality CategoryTheory.tensorRightHomEquiv_naturality theorem tensorRightHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X') (g : X' ⟶ Z ⊗ Y') : (tensorRightHomEquiv X Y Y' Z).symm (f ≫ g) = f ▷ Y ≫ (tensorRightHomEquiv X' Y Y' Z).symm g := by simp [tensorRightHomEquiv] #align category_theory.tensor_right_hom_equiv_symm_naturality CategoryTheory.tensorRightHomEquiv_symm_naturality /-- If `Y Y'` have an exact pairing, then the functor `tensorLeft Y'` is left adjoint to `tensorLeft Y`. -/ def tensorLeftAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorLeft Y' ⊣ tensorLeft Y := Adjunction.mkOfHomEquiv { homEquiv := fun X Z => tensorLeftHomEquiv X Y Y' Z homEquiv_naturality_left_symm := fun f g => tensorLeftHomEquiv_symm_naturality f g homEquiv_naturality_right := fun f g => tensorLeftHomEquiv_naturality f g } #align category_theory.tensor_left_adjunction CategoryTheory.tensorLeftAdjunction /-- If `Y Y'` have an exact pairing, then the functor `tensor_right Y` is left adjoint to `tensor_right Y'`. -/ def tensorRightAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorRight Y ⊣ tensorRight Y' := Adjunction.mkOfHomEquiv { homEquiv := fun X Z => tensorRightHomEquiv X Y Y' Z homEquiv_naturality_left_symm := fun f g => tensorRightHomEquiv_symm_naturality f g homEquiv_naturality_right := fun f g => tensorRightHomEquiv_naturality f g } #align category_theory.tensor_right_adjunction CategoryTheory.tensorRightAdjunction /-- If `Y` has a left dual `ᘁY`, then it is a closed object, with the internal hom functor `Y ⟶[C] -` given by left tensoring by `ᘁY`. This has to be a definition rather than an instance to avoid diamonds, for example between `category_theory.monoidal_closed.functor_closed` and `CategoryTheory.Monoidal.functorHasLeftDual`. Moreover, in concrete applications there is often a more useful definition of the internal hom object than `ᘁY ⊗ X`, in which case the closed structure shouldn't come from `has_left_dual` (e.g. in the category `FinVect k`, it is more convenient to define the internal hom as `Y →ₗ[k] X` rather than `ᘁY ⊗ X` even though these are naturally isomorphic). -/ def closedOfHasLeftDual (Y : C) [HasLeftDual Y] : Closed Y where adj := tensorLeftAdjunction (ᘁY) Y #align category_theory.closed_of_has_left_dual CategoryTheory.closedOfHasLeftDual /-- `tensorLeftHomEquiv` commutes with tensoring on the right -/ theorem tensorLeftHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Y ⊗ Z) (g : X' ⟶ Z') : (tensorLeftHomEquiv (X ⊗ X') Y Y' (Z ⊗ Z')).symm ((f ⊗ g) ≫ (α_ _ _ _).hom) = (α_ _ _ _).inv ≫ ((tensorLeftHomEquiv X Y Y' Z).symm f ⊗ g) := by simp [tensorLeftHomEquiv, tensorHom_def'] #align category_theory.tensor_left_hom_equiv_tensor CategoryTheory.tensorLeftHomEquiv_tensor /-- `tensorRightHomEquiv` commutes with tensoring on the left -/ theorem tensorRightHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Z ⊗ Y') (g : X' ⟶ Z') : (tensorRightHomEquiv (X' ⊗ X) Y Y' (Z' ⊗ Z)).symm ((g ⊗ f) ≫ (α_ _ _ _).inv) = (α_ _ _ _).hom ≫ (g ⊗ (tensorRightHomEquiv X Y Y' Z).symm f) := by simp [tensorRightHomEquiv, tensorHom_def] #align category_theory.tensor_right_hom_equiv_tensor CategoryTheory.tensorRightHomEquiv_tensor @[simp] theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerLeft {Y Y' Z : C} [ExactPairing Y Y'] (f : Y' ⟶ Z) : (tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ Y ◁ f) = (ρ_ _).hom ≫ f := by calc _ = Y' ◁ η_ Y Y' ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by dsimp [tensorLeftHomEquiv]; coherence _ = (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ f := by rw [whisker_exchange]; coherence _ = _ := by rw [coevaluation_evaluation'']; coherence #align category_theory.tensor_left_hom_equiv_symm_coevaluation_comp_id_tensor CategoryTheory.tensorLeftHomEquiv_symm_coevaluation_comp_whiskerLeft @[simp] theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerRight {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ f ▷ (Xᘁ)) = (ρ_ _).hom ≫ fᘁ := by dsimp [tensorLeftHomEquiv, rightAdjointMate] simp #align category_theory.tensor_left_hom_equiv_symm_coevaluation_comp_tensor_id CategoryTheory.tensorLeftHomEquiv_symm_coevaluation_comp_whiskerRight @[simp] theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerLeft {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : (tensorRightHomEquiv _ (ᘁY) _ _).symm (η_ (ᘁX) X ≫ (ᘁX) ◁ f) = (λ_ _).hom ≫ ᘁf := by dsimp [tensorRightHomEquiv, leftAdjointMate] simp #align category_theory.tensor_right_hom_equiv_symm_coevaluation_comp_id_tensor CategoryTheory.tensorRightHomEquiv_symm_coevaluation_comp_whiskerLeft @[simp] theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerRight {Y Y' Z : C} [ExactPairing Y Y'] (f : Y ⟶ Z) : (tensorRightHomEquiv _ Y _ _).symm (η_ Y Y' ≫ f ▷ Y') = (λ_ _).hom ≫ f := calc _ = η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by dsimp [tensorRightHomEquiv]; coherence _ = (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by rw [← whisker_exchange]; coherence _ = _ := by rw [evaluation_coevaluation'']; coherence #align category_theory.tensor_right_hom_equiv_symm_coevaluation_comp_tensor_id CategoryTheory.tensorRightHomEquiv_symm_coevaluation_comp_whiskerRight @[simp] theorem tensorLeftHomEquiv_whiskerLeft_comp_evaluation {Y Z : C} [HasLeftDual Z] (f : Y ⟶ ᘁZ) : (tensorLeftHomEquiv _ _ _ _) (Z ◁ f ≫ ε_ _ _) = f ≫ (ρ_ _).inv := calc _ = 𝟙 _ ⊗≫ (η_ (ᘁZ) Z ▷ Y ≫ ((ᘁZ) ⊗ Z) ◁ f) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z := by dsimp [tensorLeftHomEquiv]; coherence _ = f ⊗≫ (η_ (ᘁZ) Z ▷ (ᘁZ) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z) := by rw [← whisker_exchange]; coherence _ = _ := by rw [evaluation_coevaluation'']; coherence #align category_theory.tensor_left_hom_equiv_id_tensor_comp_evaluation CategoryTheory.tensorLeftHomEquiv_whiskerLeft_comp_evaluation @[simp] theorem tensorLeftHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : (tensorLeftHomEquiv _ _ _ _) (f ▷ _ ≫ ε_ _ _) = (ᘁf) ≫ (ρ_ _).inv := by dsimp [tensorLeftHomEquiv, leftAdjointMate] simp #align category_theory.tensor_left_hom_equiv_tensor_id_comp_evaluation CategoryTheory.tensorLeftHomEquiv_whiskerRight_comp_evaluation @[simp] theorem tensorRightHomEquiv_whiskerLeft_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (tensorRightHomEquiv _ _ _ _) ((Yᘁ) ◁ f ≫ ε_ _ _) = fᘁ ≫ (λ_ _).inv := by dsimp [tensorRightHomEquiv, rightAdjointMate] simp #align category_theory.tensor_right_hom_equiv_id_tensor_comp_evaluation CategoryTheory.tensorRightHomEquiv_whiskerLeft_comp_evaluation @[simp] theorem tensorRightHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasRightDual X] (f : Y ⟶ Xᘁ) : (tensorRightHomEquiv _ _ _ _) (f ▷ X ≫ ε_ X (Xᘁ)) = f ≫ (λ_ _).inv := calc _ = 𝟙 _ ⊗≫ (Y ◁ η_ X Xᘁ ≫ f ▷ (X ⊗ Xᘁ)) ⊗≫ ε_ X Xᘁ ▷ Xᘁ := by dsimp [tensorRightHomEquiv]; coherence _ = f ⊗≫ (Xᘁ ◁ η_ X Xᘁ ⊗≫ ε_ X Xᘁ ▷ Xᘁ) := by rw [whisker_exchange]; coherence _ = _ := by rw [coevaluation_evaluation'']; coherence #align category_theory.tensor_right_hom_equiv_tensor_id_comp_evaluation CategoryTheory.tensorRightHomEquiv_whiskerRight_comp_evaluation -- Next four lemmas passing `fᘁ` or `ᘁf` through (co)evaluations. @[reassoc] theorem coevaluation_comp_rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : η_ Y (Yᘁ) ≫ _ ◁ (fᘁ) = η_ _ _ ≫ f ▷ _ := by apply_fun (tensorLeftHomEquiv _ Y (Yᘁ) _).symm simp #align category_theory.coevaluation_comp_right_adjoint_mate CategoryTheory.coevaluation_comp_rightAdjointMate @[reassoc] theorem leftAdjointMate_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : X ◁ (ᘁf) ≫ ε_ _ _ = f ▷ _ ≫ ε_ _ _ := by apply_fun tensorLeftHomEquiv _ (ᘁX) X _ simp #align category_theory.left_adjoint_mate_comp_evaluation CategoryTheory.leftAdjointMate_comp_evaluation @[reassoc] theorem coevaluation_comp_leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : η_ (ᘁY) Y ≫ (ᘁf) ▷ Y = η_ (ᘁX) X ≫ (ᘁX) ◁ f := by apply_fun (tensorRightHomEquiv _ (ᘁY) Y _).symm simp #align category_theory.coevaluation_comp_left_adjoint_mate CategoryTheory.coevaluation_comp_leftAdjointMate @[reassoc] theorem rightAdjointMate_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (fᘁ ▷ X) ≫ ε_ X (Xᘁ) = ((Yᘁ) ◁ f) ≫ ε_ Y (Yᘁ) := by apply_fun tensorRightHomEquiv _ X (Xᘁ) _ simp #align category_theory.right_adjoint_mate_comp_evaluation CategoryTheory.rightAdjointMate_comp_evaluation /-- Transport an exact pairing across an isomorphism in the first argument. -/ def exactPairingCongrLeft {X X' Y : C} [ExactPairing X' Y] (i : X ≅ X') : ExactPairing X Y where evaluation' := Y ◁ i.hom ≫ ε_ _ _ coevaluation' := η_ _ _ ≫ i.inv ▷ Y evaluation_coevaluation' := calc _ = η_ X' Y ▷ X ⊗≫ (i.inv ▷ (Y ⊗ X) ≫ X ◁ (Y ◁ i.hom)) ⊗≫ X ◁ ε_ X' Y := by coherence _ = 𝟙 _ ⊗≫ (η_ X' Y ▷ X ≫ (X' ⊗ Y) ◁ i.hom) ⊗≫ (i.inv ▷ (Y ⊗ X') ≫ X ◁ ε_ X' Y) ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; coherence _ = 𝟙 _ ⊗≫ i.hom ⊗≫ (η_ X' Y ▷ X' ⊗≫ X' ◁ ε_ X' Y) ⊗≫ i.inv ⊗≫ 𝟙 _ := by rw [← whisker_exchange, ← whisker_exchange]; coherence _ = 𝟙 _ ⊗≫ (i.hom ≫ i.inv) ⊗≫ 𝟙 _ := by rw [evaluation_coevaluation'']; coherence _ = (λ_ X).hom ≫ (ρ_ X).inv := by rw [Iso.hom_inv_id] -- coherence failed simp [monoidalComp] coevaluation_evaluation' := by calc _ = Y ◁ η_ X' Y ≫ Y ◁ (i.inv ≫ i.hom) ▷ Y ⊗≫ ε_ X' Y ▷ Y := by coherence _ = Y ◁ η_ X' Y ⊗≫ ε_ X' Y ▷ Y := by rw [Iso.inv_hom_id]; coherence _ = _ := by rw [coevaluation_evaluation''] -- coherence failed simp [monoidalComp] #align category_theory.exact_pairing_congr_left CategoryTheory.exactPairingCongrLeft /-- Transport an exact pairing across an isomorphism in the second argument. -/ def exactPairingCongrRight {X Y Y' : C} [ExactPairing X Y'] (i : Y ≅ Y') : ExactPairing X Y where evaluation' := i.hom ▷ X ≫ ε_ _ _ coevaluation' := η_ _ _ ≫ X ◁ i.inv evaluation_coevaluation' := by calc _ = η_ X Y' ▷ X ⊗≫ X ◁ (i.inv ≫ i.hom) ▷ X ≫ X ◁ ε_ X Y' := by coherence _ = η_ X Y' ▷ X ⊗≫ X ◁ ε_ X Y' := by rw [Iso.inv_hom_id]; coherence _ = _ := by rw [evaluation_coevaluation''] -- coherence failed simp [monoidalComp] coevaluation_evaluation' := calc _ = Y ◁ η_ X Y' ⊗≫ (Y ◁ (X ◁ i.inv) ≫ i.hom ▷ (X ⊗ Y)) ⊗≫ ε_ X Y' ▷ Y := by coherence _ = 𝟙 _ ⊗≫ (Y ◁ η_ X Y' ≫ i.hom ▷ (X ⊗ Y')) ⊗≫ ((Y' ⊗ X) ◁ i.inv ≫ ε_ X Y' ▷ Y) ⊗≫ 𝟙 _ := by rw [whisker_exchange]; coherence _ = 𝟙 _ ⊗≫ i.hom ⊗≫ (Y' ◁ η_ X Y' ⊗≫ ε_ X Y' ▷ Y') ⊗≫ i.inv ⊗≫ 𝟙 _ := by rw [whisker_exchange, whisker_exchange]; coherence _ = 𝟙 _ ⊗≫ (i.hom ≫ i.inv) ⊗≫ 𝟙 _ := by rw [coevaluation_evaluation'']; coherence _ = (ρ_ Y).hom ≫ (λ_ Y).inv := by rw [Iso.hom_inv_id] -- coherence failed simp [monoidalComp] #align category_theory.exact_pairing_congr_right CategoryTheory.exactPairingCongrRight /-- Transport an exact pairing across isomorphisms. -/ def exactPairingCongr {X X' Y Y' : C} [ExactPairing X' Y'] (i : X ≅ X') (j : Y ≅ Y') : ExactPairing X Y := haveI : ExactPairing X' Y := exactPairingCongrRight j exactPairingCongrLeft i #align category_theory.exact_pairing_congr CategoryTheory.exactPairingCongr /-- Right duals are isomorphic. -/ def rightDualIso {X Y₁ Y₂ : C} (p₁ : ExactPairing X Y₁) (p₂ : ExactPairing X Y₂) : Y₁ ≅ Y₂ where hom := @rightAdjointMate C _ _ X X ⟨Y₂⟩ ⟨Y₁⟩ (𝟙 X) inv := @rightAdjointMate C _ _ X X ⟨Y₁⟩ ⟨Y₂⟩ (𝟙 X) -- Porting note: no implicit arguments were required below: hom_inv_id := by rw [← @comp_rightAdjointMate C _ _ X X X ⟨Y₁⟩ ⟨Y₂⟩ ⟨Y₁⟩, Category.comp_id, @rightAdjointMate_id _ _ _ _ ⟨Y₁⟩] rfl inv_hom_id := by rw [← @comp_rightAdjointMate C _ _ X X X ⟨Y₂⟩ ⟨Y₁⟩ ⟨Y₂⟩, Category.comp_id, @rightAdjointMate_id _ _ _ _ ⟨Y₂⟩] rfl #align category_theory.right_dual_iso CategoryTheory.rightDualIso /-- Left duals are isomorphic. -/ def leftDualIso {X₁ X₂ Y : C} (p₁ : ExactPairing X₁ Y) (p₂ : ExactPairing X₂ Y) : X₁ ≅ X₂ where hom := @leftAdjointMate C _ _ Y Y ⟨X₂⟩ ⟨X₁⟩ (𝟙 Y) inv := @leftAdjointMate C _ _ Y Y ⟨X₁⟩ ⟨X₂⟩ (𝟙 Y) -- Porting note: no implicit arguments were required below: hom_inv_id := by rw [← @comp_leftAdjointMate C _ _ Y Y Y ⟨X₁⟩ ⟨X₂⟩ ⟨X₁⟩, Category.comp_id, @leftAdjointMate_id _ _ _ _ ⟨X₁⟩] rfl inv_hom_id := by rw [← @comp_leftAdjointMate C _ _ Y Y Y ⟨X₂⟩ ⟨X₁⟩ ⟨X₂⟩, Category.comp_id, @leftAdjointMate_id _ _ _ _ ⟨X₂⟩] rfl #align category_theory.left_dual_iso CategoryTheory.leftDualIso @[simp] theorem rightDualIso_id {X Y : C} (p : ExactPairing X Y) : rightDualIso p p = Iso.refl Y := by ext simp only [rightDualIso, Iso.refl_hom, @rightAdjointMate_id _ _ _ _ ⟨Y⟩] #align category_theory.right_dual_iso_id CategoryTheory.rightDualIso_id @[simp]
Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean
622
624
theorem leftDualIso_id {X Y : C} (p : ExactPairing X Y) : leftDualIso p p = Iso.refl X := by
ext simp only [leftDualIso, Iso.refl_hom, @leftAdjointMate_id _ _ _ _ ⟨X⟩]
/- 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.Topology.UniformSpace.Compact import Mathlib.Init.Data.Bool.Lemmas #align_import analysis.box_integral.basic from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # 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 Classical 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)) #align box_integral.integral_sum BoxIntegral.integralSum 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'] #align box_integral.integral_sum_bUnion_tagged BoxIntegral.integralSum_biUnionTagged 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) #align box_integral.integral_sum_bUnion_partition BoxIntegral.integralSum_biUnion_partition 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) #align box_integral.integral_sum_inf_partition BoxIntegral.integralSum_inf_partition 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) #align box_integral.integral_sum_fiberwise BoxIntegral.integralSum_fiberwise 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] #align box_integral.integral_sum_sub_partitions BoxIntegral.integralSum_sub_partitions @[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] #align box_integral.integral_sum_disj_union BoxIntegral.integralSum_disjUnion @[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] #align box_integral.integral_sum_add BoxIntegral.integralSum_add @[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] #align box_integral.integral_sum_neg BoxIntegral.integralSum_neg @[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] #align box_integral.integral_sum_smul BoxIntegral.integralSum_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) #align box_integral.has_integral BoxIntegral.HasIntegral /-- 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 #align box_integral.integrable BoxIntegral.Integrable /-- 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 #align box_integral.integral BoxIntegral.integral -- 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 #align box_integral.has_integral.tendsto BoxIntegral.HasIntegral.tendsto /-- 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)] #align box_integral.has_integral_iff BoxIntegral.hasIntegral_iff /-- 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⟩ #align box_integral.has_integral_of_mul BoxIntegral.HasIntegral.of_mul 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 #align box_integral.integrable_iff_cauchy BoxIntegral.integrable_iff_cauchy /-- 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, prod_mk_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₂⟩ #align box_integral.integrable_iff_cauchy_basis BoxIntegral.integrable_iff_cauchy_basis 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 _ #align box_integral.has_integral.mono BoxIntegral.HasIntegral.mono 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 #align box_integral.integrable.has_integral BoxIntegral.Integrable.hasIntegral theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≤ l) : Integrable I l' f vol := ⟨_, h.hasIntegral.mono hle⟩ #align box_integral.integrable.mono BoxIntegral.Integrable.mono theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' #align box_integral.has_integral.unique BoxIntegral.HasIntegral.unique theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟨_, h⟩ #align box_integral.has_integral.integrable BoxIntegral.HasIntegral.integrable theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h #align box_integral.has_integral.integral_eq BoxIntegral.HasIntegral.integral_eq 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' #align box_integral.has_integral.add BoxIntegral.HasIntegral.add 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 #align box_integral.integrable.add BoxIntegral.Integrable.add 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 #align box_integral.integral_add BoxIntegral.integral_add 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 #align box_integral.has_integral.neg BoxIntegral.HasIntegral.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable #align box_integral.integrable.neg BoxIntegral.Integrable.neg theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f ▸ hf.neg #align box_integral.integrable.of_neg BoxIntegral.Integrable.of_neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟨fun h => h.of_neg, fun h => h.neg⟩ #align box_integral.integrable_neg BoxIntegral.integrable_neg @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := 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] #align box_integral.integral_neg BoxIntegral.integral_neg 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 #align box_integral.has_integral.sub BoxIntegral.HasIntegral.sub 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 #align box_integral.integrable.sub BoxIntegral.Integrable.sub 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 #align box_integral.integral_sub BoxIntegral.integral_sub 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π #align box_integral.has_integral_const BoxIntegral.hasIntegral_const @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq #align box_integral.integral_const BoxIntegral.integral_const theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟨_, hasIntegral_const c⟩ #align box_integral.integrable_const BoxIntegral.integrable_const theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) #align box_integral.has_integral_zero BoxIntegral.hasIntegral_zero theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟨0, hasIntegral_zero⟩ #align box_integral.integrable_zero BoxIntegral.integrable_zero theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq #align box_integral.integral_zero BoxIntegral.integral_zero 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 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) #align box_integral.has_integral_sum BoxIntegral.HasIntegral.sum 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 #align box_integral.has_integral.smul BoxIntegral.HasIntegral.smul theorem Integrable.smul (hf : Integrable I l f vol) (c : ℝ) : Integrable I l (c • f) vol := (hf.hasIntegral.smul c).integrable #align box_integral.integrable.smul BoxIntegral.Integrable.smul 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⁻¹ #align box_integral.integrable.of_smul BoxIntegral.Integrable.of_smul @[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] #align box_integral.integral_smul BoxIntegral.integral_smul 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] #align box_integral.integral_nonneg BoxIntegral.integral_nonneg /-- 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 ENNReal.toReal_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)) μ #align box_integral.norm_integral_le_of_norm_le BoxIntegral.norm_integral_le_of_norm_le 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)‖ ≤ (μ I).toReal * c := by simpa only [integral_const] using norm_integral_le_of_norm_le hc μ (integrable_const c) #align box_integral.norm_integral_le_of_le_const BoxIntegral.norm_integral_le_of_le_const /-! # 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⟩ #align box_integral.integrable.convergence_r BoxIntegral.Integrable.convergenceR 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] #align box_integral.integrable.convergence_r_cond BoxIntegral.Integrable.convergenceR_cond
Mathlib/Analysis/BoxIntegral/Basic.lean
455
459
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
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot, Eric Wieser, Yaël Dillies -/ import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Topology.Algebra.Module.Basic #align_import analysis.normed_space.basic from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Basic facts about real (semi)normed spaces In this file we prove some theorems about (semi)normed spaces over real numberes. ## Main results - `closure_ball`, `frontier_ball`, `interior_closedBall`, `frontier_closedBall`, `interior_sphere`, `frontier_sphere`: formulas for the closure/interior/frontier of nontrivial balls and spheres in a real seminormed space; - `interior_closedBall'`, `frontier_closedBall'`, `interior_sphere'`, `frontier_sphere'`: similar lemmas assuming that the ambient space is separated and nontrivial instead of `r ≠ 0`. -/ open Metric Set Function Filter open scoped NNReal Topology /-- If `E` is a nontrivial topological module over `ℝ`, then `E` has no isolated points. This is a particular case of `Module.punctured_nhds_neBot`. -/ instance Real.punctured_nhds_module_neBot {E : Type*} [AddCommGroup E] [TopologicalSpace E] [ContinuousAdd E] [Nontrivial E] [Module ℝ E] [ContinuousSMul ℝ E] (x : E) : NeBot (𝓝[≠] x) := Module.punctured_nhds_neBot ℝ E x #align real.punctured_nhds_module_ne_bot Real.punctured_nhds_module_neBot section Seminormed variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] theorem inv_norm_smul_mem_closed_unit_ball (x : E) : ‖x‖⁻¹ • x ∈ closedBall (0 : E) 1 := by simp only [mem_closedBall_zero_iff, norm_smul, norm_inv, norm_norm, ← div_eq_inv_mul, div_self_le_one] #align inv_norm_smul_mem_closed_unit_ball inv_norm_smul_mem_closed_unit_ball theorem norm_smul_of_nonneg {t : ℝ} (ht : 0 ≤ t) (x : E) : ‖t • x‖ = t * ‖x‖ := by rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg ht] #align norm_smul_of_nonneg norm_smul_of_nonneg theorem dist_smul_add_one_sub_smul_le {r : ℝ} {x y : E} (h : r ∈ Icc 0 1) : dist (r • x + (1 - r) • y) x ≤ dist y x := calc dist (r • x + (1 - r) • y) x = ‖1 - r‖ * ‖x - y‖ := by simp_rw [dist_eq_norm', ← norm_smul, sub_smul, one_smul, smul_sub, ← sub_sub, ← sub_add, sub_right_comm] _ = (1 - r) * dist y x := by rw [Real.norm_eq_abs, abs_eq_self.mpr (sub_nonneg.mpr h.2), dist_eq_norm'] _ ≤ (1 - 0) * dist y x := by gcongr; exact h.1 _ = dist y x := by rw [sub_zero, one_mul] theorem closure_ball (x : E) {r : ℝ} (hr : r ≠ 0) : closure (ball x r) = closedBall x r := by refine Subset.antisymm closure_ball_subset_closedBall fun y hy => ?_ have : ContinuousWithinAt (fun c : ℝ => c • (y - x) + x) (Ico 0 1) 1 := ((continuous_id.smul continuous_const).add continuous_const).continuousWithinAt convert this.mem_closure _ _ · rw [one_smul, sub_add_cancel] · simp [closure_Ico zero_ne_one, zero_le_one] · rintro c ⟨hc0, hc1⟩ rw [mem_ball, dist_eq_norm, add_sub_cancel_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg hc0, mul_comm, ← mul_one r] rw [mem_closedBall, dist_eq_norm] at hy replace hr : 0 < r := ((norm_nonneg _).trans hy).lt_of_ne hr.symm apply mul_lt_mul' <;> assumption #align closure_ball closure_ball theorem frontier_ball (x : E) {r : ℝ} (hr : r ≠ 0) : frontier (ball x r) = sphere x r := by rw [frontier, closure_ball x hr, isOpen_ball.interior_eq, closedBall_diff_ball] #align frontier_ball frontier_ball theorem interior_closedBall (x : E) {r : ℝ} (hr : r ≠ 0) : interior (closedBall x r) = ball x r := by cases' hr.lt_or_lt with hr hr · rw [closedBall_eq_empty.2 hr, ball_eq_empty.2 hr.le, interior_empty] refine Subset.antisymm ?_ ball_subset_interior_closedBall intro y hy rcases (mem_closedBall.1 <| interior_subset hy).lt_or_eq with (hr | rfl) · exact hr set f : ℝ → E := fun c : ℝ => c • (y - x) + x suffices f ⁻¹' closedBall x (dist y x) ⊆ Icc (-1) 1 by have hfc : Continuous f := (continuous_id.smul continuous_const).add continuous_const have hf1 : (1 : ℝ) ∈ f ⁻¹' interior (closedBall x <| dist y x) := by simpa [f] have h1 : (1 : ℝ) ∈ interior (Icc (-1 : ℝ) 1) := interior_mono this (preimage_interior_subset_interior_preimage hfc hf1) simp at h1 intro c hc rw [mem_Icc, ← abs_le, ← Real.norm_eq_abs, ← mul_le_mul_right hr] simpa [f, dist_eq_norm, norm_smul] using hc #align interior_closed_ball interior_closedBall theorem frontier_closedBall (x : E) {r : ℝ} (hr : r ≠ 0) : frontier (closedBall x r) = sphere x r := by rw [frontier, closure_closedBall, interior_closedBall x hr, closedBall_diff_ball] #align frontier_closed_ball frontier_closedBall theorem interior_sphere (x : E) {r : ℝ} (hr : r ≠ 0) : interior (sphere x r) = ∅ := by rw [← frontier_closedBall x hr, interior_frontier isClosed_ball] #align interior_sphere interior_sphere theorem frontier_sphere (x : E) {r : ℝ} (hr : r ≠ 0) : frontier (sphere x r) = sphere x r := by rw [isClosed_sphere.frontier_eq, interior_sphere x hr, diff_empty] #align frontier_sphere frontier_sphere end Seminormed section Normed variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [Nontrivial E] section Surj variable (E)
Mathlib/Analysis/NormedSpace/Real.lean
124
128
theorem exists_norm_eq {c : ℝ} (hc : 0 ≤ c) : ∃ x : E, ‖x‖ = c := by
rcases exists_ne (0 : E) with ⟨x, hx⟩ rw [← norm_ne_zero_iff] at hx use c • ‖x‖⁻¹ • x simp [norm_smul, Real.norm_of_nonneg hc, abs_of_nonneg hc, inv_mul_cancel hx]
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Data.List.Count import Mathlib.Data.List.Dedup import Mathlib.Data.List.InsertNth import Mathlib.Data.List.Lattice import Mathlib.Data.List.Permutation import Mathlib.Data.Nat.Factorial.Basic #align_import data.list.perm from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # List Permutations This file introduces the `List.Perm` relation, which is true if two lists are permutations of one another. ## Notation The notation `~` is used for permutation equivalence. -/ -- Make sure we don't import algebra assert_not_exists Monoid open Nat namespace List variable {α β : Type*} {l l₁ l₂ : List α} {a : α} #align list.perm List.Perm instance : Trans (@List.Perm α) (@List.Perm α) List.Perm where trans := @List.Perm.trans α open Perm (swap) attribute [refl] Perm.refl #align list.perm.refl List.Perm.refl lemma perm_rfl : l ~ l := Perm.refl _ -- Porting note: used rec_on in mathlib3; lean4 eqn compiler still doesn't like it attribute [symm] Perm.symm #align list.perm.symm List.Perm.symm #align list.perm_comm List.perm_comm #align list.perm.swap' List.Perm.swap' attribute [trans] Perm.trans #align list.perm.eqv List.Perm.eqv #align list.is_setoid List.isSetoid #align list.perm.mem_iff List.Perm.mem_iff #align list.perm.subset List.Perm.subset theorem Perm.subset_congr_left {l₁ l₂ l₃ : List α} (h : l₁ ~ l₂) : l₁ ⊆ l₃ ↔ l₂ ⊆ l₃ := ⟨h.symm.subset.trans, h.subset.trans⟩ #align list.perm.subset_congr_left List.Perm.subset_congr_left theorem Perm.subset_congr_right {l₁ l₂ l₃ : List α} (h : l₁ ~ l₂) : l₃ ⊆ l₁ ↔ l₃ ⊆ l₂ := ⟨fun h' => h'.trans h.subset, fun h' => h'.trans h.symm.subset⟩ #align list.perm.subset_congr_right List.Perm.subset_congr_right #align list.perm.append_right List.Perm.append_right #align list.perm.append_left List.Perm.append_left #align list.perm.append List.Perm.append #align list.perm.append_cons List.Perm.append_cons #align list.perm_middle List.perm_middle #align list.perm_append_singleton List.perm_append_singleton #align list.perm_append_comm List.perm_append_comm #align list.concat_perm List.concat_perm #align list.perm.length_eq List.Perm.length_eq #align list.perm.eq_nil List.Perm.eq_nil #align list.perm.nil_eq List.Perm.nil_eq #align list.perm_nil List.perm_nil #align list.nil_perm List.nil_perm #align list.not_perm_nil_cons List.not_perm_nil_cons #align list.reverse_perm List.reverse_perm #align list.perm_cons_append_cons List.perm_cons_append_cons #align list.perm_replicate List.perm_replicate #align list.replicate_perm List.replicate_perm #align list.perm_singleton List.perm_singleton #align list.singleton_perm List.singleton_perm #align list.singleton_perm_singleton List.singleton_perm_singleton #align list.perm_cons_erase List.perm_cons_erase #align list.perm_induction_on List.Perm.recOnSwap' -- Porting note: used to be @[congr] #align list.perm.filter_map List.Perm.filterMap -- Porting note: used to be @[congr] #align list.perm.map List.Perm.map #align list.perm.pmap List.Perm.pmap #align list.perm.filter List.Perm.filter #align list.filter_append_perm List.filter_append_perm #align list.exists_perm_sublist List.exists_perm_sublist #align list.perm.sizeof_eq_sizeof List.Perm.sizeOf_eq_sizeOf section Rel open Relator variable {γ : Type*} {δ : Type*} {r : α → β → Prop} {p : γ → δ → Prop} local infixr:80 " ∘r " => Relation.Comp theorem perm_comp_perm : (Perm ∘r Perm : List α → List α → Prop) = Perm := by funext a c; apply propext constructor · exact fun ⟨b, hab, hba⟩ => Perm.trans hab hba · exact fun h => ⟨a, Perm.refl a, h⟩ #align list.perm_comp_perm List.perm_comp_perm theorem perm_comp_forall₂ {l u v} (hlu : Perm l u) (huv : Forall₂ r u v) : (Forall₂ r ∘r Perm) l v := by induction hlu generalizing v with | nil => cases huv; exact ⟨[], Forall₂.nil, Perm.nil⟩ | cons u _hlu ih => cases' huv with _ b _ v hab huv' rcases ih huv' with ⟨l₂, h₁₂, h₂₃⟩ exact ⟨b :: l₂, Forall₂.cons hab h₁₂, h₂₃.cons _⟩ | swap a₁ a₂ h₂₃ => cases' huv with _ b₁ _ l₂ h₁ hr₂₃ cases' hr₂₃ with _ b₂ _ l₂ h₂ h₁₂ exact ⟨b₂ :: b₁ :: l₂, Forall₂.cons h₂ (Forall₂.cons h₁ h₁₂), Perm.swap _ _ _⟩ | trans _ _ ih₁ ih₂ => rcases ih₂ huv with ⟨lb₂, hab₂, h₂₃⟩ rcases ih₁ hab₂ with ⟨lb₁, hab₁, h₁₂⟩ exact ⟨lb₁, hab₁, Perm.trans h₁₂ h₂₃⟩ #align list.perm_comp_forall₂ List.perm_comp_forall₂ theorem forall₂_comp_perm_eq_perm_comp_forall₂ : Forall₂ r ∘r Perm = Perm ∘r Forall₂ r := by funext l₁ l₃; apply propext constructor · intro h rcases h with ⟨l₂, h₁₂, h₂₃⟩ have : Forall₂ (flip r) l₂ l₁ := h₁₂.flip rcases perm_comp_forall₂ h₂₃.symm this with ⟨l', h₁, h₂⟩ exact ⟨l', h₂.symm, h₁.flip⟩ · exact fun ⟨l₂, h₁₂, h₂₃⟩ => perm_comp_forall₂ h₁₂ h₂₃ #align list.forall₂_comp_perm_eq_perm_comp_forall₂ List.forall₂_comp_perm_eq_perm_comp_forall₂ theorem rel_perm_imp (hr : RightUnique r) : (Forall₂ r ⇒ Forall₂ r ⇒ (· → ·)) Perm Perm := fun a b h₁ c d h₂ h => have : (flip (Forall₂ r) ∘r Perm ∘r Forall₂ r) b d := ⟨a, h₁, c, h, h₂⟩ have : ((flip (Forall₂ r) ∘r Forall₂ r) ∘r Perm) b d := by rwa [← forall₂_comp_perm_eq_perm_comp_forall₂, ← Relation.comp_assoc] at this let ⟨b', ⟨c', hbc, hcb⟩, hbd⟩ := this have : b' = b := right_unique_forall₂' hr hcb hbc this ▸ hbd #align list.rel_perm_imp List.rel_perm_imp theorem rel_perm (hr : BiUnique r) : (Forall₂ r ⇒ Forall₂ r ⇒ (· ↔ ·)) Perm Perm := fun _a _b hab _c _d hcd => Iff.intro (rel_perm_imp hr.2 hab hcd) (rel_perm_imp hr.left.flip hab.flip hcd.flip) #align list.rel_perm List.rel_perm end Rel section Subperm #align list.nil_subperm List.nil_subperm #align list.perm.subperm_left List.Perm.subperm_left #align list.perm.subperm_right List.Perm.subperm_right #align list.sublist.subperm List.Sublist.subperm #align list.perm.subperm List.Perm.subperm attribute [refl] Subperm.refl #align list.subperm.refl List.Subperm.refl attribute [trans] Subperm.trans #align list.subperm.trans List.Subperm.trans #align list.subperm.length_le List.Subperm.length_le #align list.subperm.perm_of_length_le List.Subperm.perm_of_length_le #align list.subperm.antisymm List.Subperm.antisymm #align list.subperm.subset List.Subperm.subset #align list.subperm.filter List.Subperm.filter end Subperm #align list.sublist.exists_perm_append List.Sublist.exists_perm_append lemma subperm_iff : l₁ <+~ l₂ ↔ ∃ l, l ~ l₂ ∧ l₁ <+ l := by refine ⟨?_, fun ⟨l, h₁, h₂⟩ ↦ h₂.subperm.trans h₁.subperm⟩ rintro ⟨l, h₁, h₂⟩ obtain ⟨l', h₂⟩ := h₂.exists_perm_append exact ⟨l₁ ++ l', (h₂.trans (h₁.append_right _)).symm, (prefix_append _ _).sublist⟩ #align list.subperm_singleton_iff List.singleton_subperm_iff @[simp] lemma subperm_singleton_iff : l <+~ [a] ↔ l = [] ∨ l = [a] := by constructor · rw [subperm_iff] rintro ⟨s, hla, h⟩ rwa [perm_singleton.mp hla, sublist_singleton] at h · rintro (rfl | rfl) exacts [nil_subperm, Subperm.refl _] attribute [simp] nil_subperm @[simp] theorem subperm_nil : List.Subperm l [] ↔ l = [] := match l with | [] => by simp | head :: tail => by simp only [iff_false] intro h have := h.length_le simp only [List.length_cons, List.length_nil, Nat.succ_ne_zero, ← Nat.not_lt, Nat.zero_lt_succ, not_true_eq_false] at this #align list.perm.countp_eq List.Perm.countP_eq #align list.subperm.countp_le List.Subperm.countP_le #align list.perm.countp_congr List.Perm.countP_congr #align list.countp_eq_countp_filter_add List.countP_eq_countP_filter_add lemma count_eq_count_filter_add [DecidableEq α] (P : α → Prop) [DecidablePred P] (l : List α) (a : α) : count a l = count a (l.filter P) + count a (l.filter (¬ P ·)) := by convert countP_eq_countP_filter_add l _ P simp only [decide_not] #align list.perm.count_eq List.Perm.count_eq #align list.subperm.count_le List.Subperm.count_le #align list.perm.foldl_eq' List.Perm.foldl_eq' theorem Perm.foldl_eq {f : β → α → β} {l₁ l₂ : List α} (rcomm : RightCommutative f) (p : l₁ ~ l₂) : ∀ b, foldl f b l₁ = foldl f b l₂ := p.foldl_eq' fun x _hx y _hy z => rcomm z x y #align list.perm.foldl_eq List.Perm.foldl_eq theorem Perm.foldr_eq {f : α → β → β} {l₁ l₂ : List α} (lcomm : LeftCommutative f) (p : l₁ ~ l₂) : ∀ b, foldr f b l₁ = foldr f b l₂ := by intro b induction p using Perm.recOnSwap' generalizing b with | nil => rfl | cons _ _ r => simp; rw [r b] | swap' _ _ _ r => simp; rw [lcomm, r b] | trans _ _ r₁ r₂ => exact Eq.trans (r₁ b) (r₂ b) #align list.perm.foldr_eq List.Perm.foldr_eq #align list.perm.rec_heq List.Perm.rec_heq section variable {op : α → α → α} [IA : Std.Associative op] [IC : Std.Commutative op] local notation a " * " b => op a b local notation l " <*> " a => foldl op a l theorem Perm.fold_op_eq {l₁ l₂ : List α} {a : α} (h : l₁ ~ l₂) : (l₁ <*> a) = l₂ <*> a := h.foldl_eq (right_comm _ IC.comm IA.assoc) _ #align list.perm.fold_op_eq List.Perm.fold_op_eq end #align list.perm_inv_core List.perm_inv_core #align list.perm.cons_inv List.Perm.cons_inv #align list.perm_cons List.perm_cons #align list.perm_append_left_iff List.perm_append_left_iff #align list.perm_append_right_iff List.perm_append_right_iff
Mathlib/Data/List/Perm.lean
318
323
theorem perm_option_to_list {o₁ o₂ : Option α} : o₁.toList ~ o₂.toList ↔ o₁ = o₂ := by
refine ⟨fun p => ?_, fun e => e ▸ Perm.refl _⟩ cases' o₁ with a <;> cases' o₂ with b; · rfl · cases p.length_eq · cases p.length_eq · exact Option.mem_toList.1 (p.symm.subset <| by simp)
/- 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.QuotientNilpotent import Mathlib.RingTheory.Smooth.Basic import Mathlib.RingTheory.Unramified.Basic #align_import ring_theory.etale from "leanprover-community/mathlib"@"73f96237417835f148a1f7bc1ff55f67119b7166" /-! # Etale morphisms An `R`-algebra `A` is formally étale if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists exactly one lift `A →ₐ[R] B`. It is étale if it is formally étale and of finite presentation. We show that the property extends onto nilpotent ideals, and that these properties are stable under `R`-algebra homomorphisms and compositions. We show that étale is stable under algebra isomorphisms, composition and localization at an element. ## TODO: - Show that étale is stable under base change. -/ -- 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 étale if for every `R`-algebra, every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists exactly one lift `A →ₐ[R] B`. -/ @[mk_iff] class FormallyEtale : Prop where comp_bijective : ∀ ⦃B : Type u⦄ [CommRing B], ∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥), Function.Bijective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I) #align algebra.formally_etale Algebra.FormallyEtale end namespace FormallyEtale 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] (I : Ideal B)
Mathlib/RingTheory/Etale/Basic.lean
66
69
theorem iff_unramified_and_smooth : FormallyEtale R A ↔ FormallyUnramified R A ∧ FormallySmooth R A := by
rw [formallyUnramified_iff, formallySmooth_iff, formallyEtale_iff] simp_rw [← forall_and, Function.Bijective]
/- 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.Topology.UniformSpace.Compact import Mathlib.Init.Data.Bool.Lemmas #align_import analysis.box_integral.basic from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # 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 Classical 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)) #align box_integral.integral_sum BoxIntegral.integralSum 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'] #align box_integral.integral_sum_bUnion_tagged BoxIntegral.integralSum_biUnionTagged 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) #align box_integral.integral_sum_bUnion_partition BoxIntegral.integralSum_biUnion_partition 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) #align box_integral.integral_sum_inf_partition BoxIntegral.integralSum_inf_partition 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) #align box_integral.integral_sum_fiberwise BoxIntegral.integralSum_fiberwise 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] #align box_integral.integral_sum_sub_partitions BoxIntegral.integralSum_sub_partitions @[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] #align box_integral.integral_sum_disj_union BoxIntegral.integralSum_disjUnion @[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] #align box_integral.integral_sum_add BoxIntegral.integralSum_add @[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] #align box_integral.integral_sum_neg BoxIntegral.integralSum_neg @[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] #align box_integral.integral_sum_smul BoxIntegral.integralSum_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) #align box_integral.has_integral BoxIntegral.HasIntegral /-- 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 #align box_integral.integrable BoxIntegral.Integrable /-- 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 #align box_integral.integral BoxIntegral.integral -- 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 #align box_integral.has_integral.tendsto BoxIntegral.HasIntegral.tendsto /-- 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)] #align box_integral.has_integral_iff BoxIntegral.hasIntegral_iff /-- 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⟩ #align box_integral.has_integral_of_mul BoxIntegral.HasIntegral.of_mul 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 #align box_integral.integrable_iff_cauchy BoxIntegral.integrable_iff_cauchy /-- 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, prod_mk_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₂⟩ #align box_integral.integrable_iff_cauchy_basis BoxIntegral.integrable_iff_cauchy_basis 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 _ #align box_integral.has_integral.mono BoxIntegral.HasIntegral.mono 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 #align box_integral.integrable.has_integral BoxIntegral.Integrable.hasIntegral theorem Integrable.mono {l'} (h : Integrable I l f vol) (hle : l' ≤ l) : Integrable I l' f vol := ⟨_, h.hasIntegral.mono hle⟩ #align box_integral.integrable.mono BoxIntegral.Integrable.mono theorem HasIntegral.unique (h : HasIntegral I l f vol y) (h' : HasIntegral I l f vol y') : y = y' := tendsto_nhds_unique h h' #align box_integral.has_integral.unique BoxIntegral.HasIntegral.unique theorem HasIntegral.integrable (h : HasIntegral I l f vol y) : Integrable I l f vol := ⟨_, h⟩ #align box_integral.has_integral.integrable BoxIntegral.HasIntegral.integrable theorem HasIntegral.integral_eq (h : HasIntegral I l f vol y) : integral I l f vol = y := h.integrable.hasIntegral.unique h #align box_integral.has_integral.integral_eq BoxIntegral.HasIntegral.integral_eq 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' #align box_integral.has_integral.add BoxIntegral.HasIntegral.add 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 #align box_integral.integrable.add BoxIntegral.Integrable.add 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 #align box_integral.integral_add BoxIntegral.integral_add 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 #align box_integral.has_integral.neg BoxIntegral.HasIntegral.neg theorem Integrable.neg (hf : Integrable I l f vol) : Integrable I l (-f) vol := hf.hasIntegral.neg.integrable #align box_integral.integrable.neg BoxIntegral.Integrable.neg theorem Integrable.of_neg (hf : Integrable I l (-f) vol) : Integrable I l f vol := neg_neg f ▸ hf.neg #align box_integral.integrable.of_neg BoxIntegral.Integrable.of_neg @[simp] theorem integrable_neg : Integrable I l (-f) vol ↔ Integrable I l f vol := ⟨fun h => h.of_neg, fun h => h.neg⟩ #align box_integral.integrable_neg BoxIntegral.integrable_neg @[simp] theorem integral_neg : integral I l (-f) vol = -integral I l f vol := 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] #align box_integral.integral_neg BoxIntegral.integral_neg 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 #align box_integral.has_integral.sub BoxIntegral.HasIntegral.sub 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 #align box_integral.integrable.sub BoxIntegral.Integrable.sub 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 #align box_integral.integral_sub BoxIntegral.integral_sub 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π #align box_integral.has_integral_const BoxIntegral.hasIntegral_const @[simp] theorem integral_const (c : E) : integral I l (fun _ => c) vol = vol I c := (hasIntegral_const c).integral_eq #align box_integral.integral_const BoxIntegral.integral_const theorem integrable_const (c : E) : Integrable I l (fun _ => c) vol := ⟨_, hasIntegral_const c⟩ #align box_integral.integrable_const BoxIntegral.integrable_const theorem hasIntegral_zero : HasIntegral I l (fun _ => (0 : E)) vol 0 := by simpa only [← (vol I).map_zero] using hasIntegral_const (0 : E) #align box_integral.has_integral_zero BoxIntegral.hasIntegral_zero theorem integrable_zero : Integrable I l (fun _ => (0 : E)) vol := ⟨0, hasIntegral_zero⟩ #align box_integral.integrable_zero BoxIntegral.integrable_zero theorem integral_zero : integral I l (fun _ => (0 : E)) vol = 0 := hasIntegral_zero.integral_eq #align box_integral.integral_zero BoxIntegral.integral_zero 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 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) #align box_integral.has_integral_sum BoxIntegral.HasIntegral.sum
Mathlib/Analysis/BoxIntegral/Basic.lean
348
351
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
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.Order.Interval.Finset import Mathlib.Combinatorics.Additive.FreimanHom import Mathlib.Data.Set.Pointwise.SMul import Mathlib.Order.Interval.Finset.Fin #align_import combinatorics.additive.salem_spencer from "leanprover-community/mathlib"@"acf5258c81d0bc7cb254ed026c1352e685df306c" /-! # Sets without arithmetic progressions of length three and Roth numbers This file defines sets without arithmetic progressions of length three, aka 3AP-free sets, and the Roth number of a set. The corresponding notion, sets without geometric progressions of length three, are called 3GP-free sets. The Roth number of a finset is the size of its biggest 3AP-free subset. This is a more general definition than the one often found in mathematical literature, where the `n`-th Roth number is the size of the biggest 3AP-free subset of `{0, ..., n - 1}`. ## Main declarations * `ThreeGPFree`: Predicate for a set to be 3GP-free. * `ThreeAPFree`: Predicate for a set to be 3AP-free. * `mulRothNumber`: The multiplicative Roth number of a finset. * `addRothNumber`: The additive Roth number of a finset. * `rothNumberNat`: The Roth number of a natural, namely `addRothNumber (Finset.range n)`. ## TODO * Can `threeAPFree_iff_eq_right` be made more general? * Generalize `ThreeGPFree.image` to Freiman homs ## References * [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/Salem–Spencer_set) ## Tags 3AP-free, Salem-Spencer, Roth, arithmetic progression, average, three-free -/ open Finset Function Nat open scoped Pointwise variable {F α β 𝕜 E : Type*} section ThreeAPFree open Set section Monoid variable [Monoid α] [Monoid β] (s t : Set α) /-- A set is **3GP-free** if it does not contain any non-trivial geometric progression of length three. -/ @[to_additive "A set is **3AP-free** if it does not contain any non-trivial arithmetic progression of length three. This is also sometimes called a **non averaging set** or **Salem-Spencer set**."] def ThreeGPFree : Prop := ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → ∀ ⦃c⦄, c ∈ s → a * c = b * b → a = b #align mul_salem_spencer ThreeGPFree #align add_salem_spencer ThreeAPFree /-- Whether a given finset is 3GP-free is decidable. -/ @[to_additive "Whether a given finset is 3AP-free is decidable."] instance ThreeGPFree.instDecidable [DecidableEq α] {s : Finset α} : Decidable (ThreeGPFree (s : Set α)) := decidable_of_iff (∀ a ∈ s, ∀ b ∈ s, ∀ c ∈ s, a * c = b * b → a = b) Iff.rfl variable {s t} @[to_additive] theorem ThreeGPFree.mono (h : t ⊆ s) (hs : ThreeGPFree s) : ThreeGPFree t := fun _ ha _ hb _ hc ↦ hs (h ha) (h hb) (h hc) #align mul_salem_spencer.mono ThreeGPFree.mono #align add_salem_spencer.mono ThreeAPFree.mono @[to_additive (attr := simp)] theorem threeGPFree_empty : ThreeGPFree (∅ : Set α) := fun _ _ _ ha => ha.elim #align mul_salem_spencer_empty threeGPFree_empty #align add_salem_spencer_empty threeAPFree_empty @[to_additive] theorem Set.Subsingleton.threeGPFree (hs : s.Subsingleton) : ThreeGPFree s := fun _ ha _ hb _ _ _ ↦ hs ha hb #align set.subsingleton.mul_salem_spencer Set.Subsingleton.threeGPFree #align set.subsingleton.add_salem_spencer Set.Subsingleton.threeAPFree @[to_additive (attr := simp)] theorem threeGPFree_singleton (a : α) : ThreeGPFree ({a} : Set α) := subsingleton_singleton.threeGPFree #align mul_salem_spencer_singleton threeGPFree_singleton #align add_salem_spencer_singleton threeAPFree_singleton @[to_additive ThreeAPFree.prod] theorem ThreeGPFree.prod {t : Set β} (hs : ThreeGPFree s) (ht : ThreeGPFree t) : ThreeGPFree (s ×ˢ t) := fun _ ha _ hb _ hc h ↦ Prod.ext (hs ha.1 hb.1 hc.1 (Prod.ext_iff.1 h).1) (ht ha.2 hb.2 hc.2 (Prod.ext_iff.1 h).2) #align mul_salem_spencer.prod ThreeGPFree.prod #align add_salem_spencer.prod ThreeAPFree.prod @[to_additive] theorem threeGPFree_pi {ι : Type*} {α : ι → Type*} [∀ i, Monoid (α i)] {s : ∀ i, Set (α i)} (hs : ∀ i, ThreeGPFree (s i)) : ThreeGPFree ((univ : Set ι).pi s) := fun _ ha _ hb _ hc h ↦ funext fun i => hs i (ha i trivial) (hb i trivial) (hc i trivial) <| congr_fun h i #align mul_salem_spencer_pi threeGPFree_pi #align add_salem_spencer_pi threeAPFree_pi end Monoid section CommMonoid variable [CommMonoid α] [CommMonoid β] {s A : Set α} {t B : Set β} {f : α → β} {a : α} /-- Arithmetic progressions of length three are preserved under `2`-Freiman homomorphisms. -/ @[to_additive "Arithmetic progressions of length three are preserved under `2`-Freiman homomorphisms."] lemma ThreeGPFree.of_image (hf : IsMulFreimanHom 2 s t f) (hf' : s.InjOn f) (hAs : A ⊆ s) (hA : ThreeGPFree (f '' A)) : ThreeGPFree A := fun _ ha _ hb _ hc habc ↦ hf' (hAs ha) (hAs hb) <| hA (mem_image_of_mem _ ha) (mem_image_of_mem _ hb) (mem_image_of_mem _ hc) <| hf.mul_eq_mul (hAs ha) (hAs hc) (hAs hb) (hAs hb) habc #align mul_salem_spencer.of_image ThreeGPFree.of_image #align add_salem_spencer.of_image ThreeAPFree.of_image /-- Arithmetic progressions of length three are preserved under `2`-Freiman isomorphisms. -/ @[to_additive "Arithmetic progressions of length three are preserved under `2`-Freiman isomorphisms."] lemma threeGPFree_image (hf : IsMulFreimanIso 2 s t f) (hAs : A ⊆ s) : ThreeGPFree (f '' A) ↔ ThreeGPFree A := by rw [ThreeGPFree, ThreeGPFree] have := (hf.bijOn.injOn.mono hAs).bijOn_image (f := f) simp (config := { contextual := true }) only [((hf.bijOn.injOn.mono hAs).bijOn_image (f := f)).forall, hf.mul_eq_mul (hAs _) (hAs _) (hAs _) (hAs _), this.injOn.eq_iff] @[to_additive] alias ⟨_, ThreeGPFree.image⟩ := threeGPFree_image #align mul_salem_spencer.image ThreeGPFree.image #align add_salem_spencer.image ThreeAPFree.image /-- Arithmetic progressions of length three are preserved under `2`-Freiman homomorphisms. -/ @[to_additive] lemma IsMulFreimanHom.threeGPFree (hf : IsMulFreimanHom 2 s t f) (hf' : s.InjOn f) (ht : ThreeGPFree t) : ThreeGPFree s := fun _ ha _ hb _ hc habc ↦ hf' ha hb <| ht (hf.mapsTo ha) (hf.mapsTo hb) (hf.mapsTo hc) <| hf.mul_eq_mul ha hc hb hb habc /-- Arithmetic progressions of length three are preserved under `2`-Freiman isomorphisms. -/ @[to_additive] lemma IsMulFreimanIso.threeGPFree_congr (hf : IsMulFreimanIso 2 s t f) : ThreeGPFree s ↔ ThreeGPFree t where mpr := hf.isMulFreimanHom.threeGPFree hf.bijOn.injOn mp hs a hfa b hfb c hfc habc := by obtain ⟨a, ha, rfl⟩ := hf.bijOn.surjOn hfa obtain ⟨b, hb, rfl⟩ := hf.bijOn.surjOn hfb obtain ⟨c, hc, rfl⟩ := hf.bijOn.surjOn hfc exact congr_arg f $ hs ha hb hc $ (hf.mul_eq_mul ha hc hb hb).1 habc @[to_additive] theorem ThreeGPFree.image' [FunLike F α β] [MulHomClass F α β] (f : F) (hf : (s * s).InjOn f) (h : ThreeGPFree s) : ThreeGPFree (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ _ ⟨c, hc, rfl⟩ habc rw [h ha hb hc (hf (mul_mem_mul ha hc) (mul_mem_mul hb hb) <| by rwa [map_mul, map_mul])] end CommMonoid section CancelCommMonoid variable [CancelCommMonoid α] {s : Set α} {a : α} lemma ThreeGPFree.eq_right (hs : ThreeGPFree s) : ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ s → ∀ ⦃c⦄, c ∈ s → a * c = b * b → b = c := by rintro a ha b hb c hc habc obtain rfl := hs ha hb hc habc simpa using habc.symm @[to_additive] lemma threeGPFree_insert : ThreeGPFree (insert a s) ↔ ThreeGPFree s ∧ (∀ ⦃b⦄, b ∈ s → ∀ ⦃c⦄, c ∈ s → a * c = b * b → a = b) ∧ ∀ ⦃b⦄, b ∈ s → ∀ ⦃c⦄, c ∈ s → b * c = a * a → b = a := by refine ⟨fun hs ↦ ⟨hs.mono (subset_insert _ _), fun b hb c hc ↦ hs (Or.inl rfl) (Or.inr hb) (Or.inr hc), fun b hb c hc ↦ hs (Or.inr hb) (Or.inl rfl) (Or.inr hc)⟩, ?_⟩ rintro ⟨hs, ha, ha'⟩ b hb c hc d hd h rw [mem_insert_iff] at hb hc hd obtain rfl | hb := hb <;> obtain rfl | hc := hc · rfl all_goals obtain rfl | hd := hd · exact (ha' hc hc h.symm).symm · exact ha hc hd h · exact mul_right_cancel h · exact ha' hb hd h · obtain rfl := ha hc hb ((mul_comm _ _).trans h) exact ha' hb hc h · exact hs hb hc hd h #align mul_salem_spencer_insert threeGPFree_insert #align add_salem_spencer_insert threeAPFree_insert @[to_additive]
Mathlib/Combinatorics/Additive/AP/Three/Defs.lean
207
209
theorem ThreeGPFree.smul_set (hs : ThreeGPFree s) : ThreeGPFree (a • s) := by
rintro _ ⟨b, hb, rfl⟩ _ ⟨c, hc, rfl⟩ _ ⟨d, hd, rfl⟩ h exact congr_arg (a • ·) $ hs hb hc hd $ by simpa [mul_mul_mul_comm _ _ a] using h
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas #align_import ring_theory.ideal.operations from "leanprover-community/mathlib"@"e7f0ddbf65bd7181a85edb74b64bdc35ba4bdc74" /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` assert_not_exists Submodule.hasQuotient -- See `RingTheory.Ideal.QuotientOperations` universe u v w x open Pointwise namespace Submodule variable {R : Type u} {M : Type v} {M' F G : Type*} section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise instance hasSMul' : SMul (Ideal R) (Submodule R M) := ⟨Submodule.map₂ (LinearMap.lsmul R M)⟩ #align submodule.has_smul' Submodule.hasSMul' /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl #align ideal.smul_eq_mul Ideal.smul_eq_mul variable (R M) in /-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/ def _root_.Module.annihilator : Ideal R := LinearMap.ker (LinearMap.lsmul R M) theorem _root_.Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 := ⟨fun h ↦ (congr($h ·)), (LinearMap.ext ·)⟩ theorem _root_.LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) : Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero]) theorem _root_.LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M') (hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by rw [Module.mem_annihilator] at h ⊢ intro m; obtain ⟨m, rfl⟩ := hf m rw [← map_smul, h, f.map_zero] theorem _root_.LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') : Module.annihilator R M = Module.annihilator R M' := (e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective) /-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/ abbrev annihilator (N : Submodule R M) : Ideal R := Module.annihilator R N #align submodule.annihilator Submodule.annihilator theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M := topEquiv.annihilator_eq variable {I J : Ideal R} {N P : Submodule R M} theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl #align submodule.mem_annihilator Submodule.mem_annihilator theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ := mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩ #align submodule.mem_annihilator' Submodule.mem_annihilator' theorem mem_annihilator_span (s : Set M) (r : R) : r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by rw [Submodule.mem_annihilator] constructor · intro h n exact h _ (Submodule.subset_span n.prop) · intro h n hn refine Submodule.span_induction hn ?_ ?_ ?_ ?_ · intro x hx exact h ⟨x, hx⟩ · exact smul_zero _ · intro x y hx hy rw [smul_add, hx, hy, zero_add] · intro a x hx rw [smul_comm, hx, smul_zero] #align submodule.mem_annihilator_span Submodule.mem_annihilator_span theorem mem_annihilator_span_singleton (g : M) (r : R) : r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span] #align submodule.mem_annihilator_span_singleton Submodule.mem_annihilator_span_singleton theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ := (Ideal.eq_top_iff_one _).2 <| mem_annihilator'.2 bot_le #align submodule.annihilator_bot Submodule.annihilator_bot theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := ⟨fun H => eq_bot_iff.2 fun (n : M) hn => (mem_bot R).2 <| one_smul R n ▸ mem_annihilator.1 ((Ideal.eq_top_iff_one _).1 H) n hn, fun H => H.symm ▸ annihilator_bot⟩ #align submodule.annihilator_eq_top_iff Submodule.annihilator_eq_top_iff theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp => mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn #align submodule.annihilator_mono Submodule.annihilator_mono theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) : annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) := le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun _ H => mem_annihilator'.2 <| iSup_le fun i => have := (mem_iInf _).1 H i mem_annihilator'.1 this #align submodule.annihilator_supr Submodule.annihilator_iSup theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N := apply_mem_map₂ _ hr hn #align submodule.smul_mem_smul Submodule.smul_mem_smul theorem smul_le {P : Submodule R M} : I • N ≤ P ↔ ∀ r ∈ I, ∀ n ∈ N, r • n ∈ P := map₂_le #align submodule.smul_le Submodule.smul_le @[simp, norm_cast] lemma coe_set_smul : (I : Set R) • N = I • N := Submodule.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 := by have H0 : p 0 := by simpa only [zero_smul] using smul 0 I.zero_mem 0 N.zero_mem refine Submodule.iSup_induction (x := x) _ H ?_ H0 add rintro ⟨i, hi⟩ m ⟨j, hj, hj'⟩ rw [← hj'] exact smul _ hi _ hj #align submodule.smul_induction_on Submodule.smul_induction_on /-- 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 : R) (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) (Submodule.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⟩ #align submodule.smul_induction_on' Submodule.smul_induction_on' theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri n hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨y, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ #align submodule.mem_smul_span_singleton Submodule.mem_smul_span_singleton theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ => N.smul_mem r #align submodule.smul_le_right Submodule.smul_le_right theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P := map₂_le_map₂ hij hnp #align submodule.smul_mono Submodule.smul_mono theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N := map₂_le_map₂_left h #align submodule.smul_mono_left Submodule.smul_mono_left instance : CovariantClass (Ideal R) (Submodule R M) HSMul.hSMul LE.le := ⟨fun _ _ => map₂_le_map₂_right⟩ @[deprecated smul_mono_right (since := "2024-03-31")] protected theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P := _root_.smul_mono_right I h #align submodule.smul_mono_right Submodule.smul_mono_right theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top #align submodule.map_le_smul_top Submodule.map_le_smul_top @[simp] theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ := eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1) #align submodule.annihilator_smul Submodule.annihilator_smul @[simp] theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ := annihilator_smul I #align submodule.annihilator_mul Submodule.annihilator_mul @[simp] theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul] #align submodule.mul_annihilator Submodule.mul_annihilator variable (I J N P) @[simp] theorem smul_bot : I • (⊥ : Submodule R M) = ⊥ := map₂_bot_right _ _ #align submodule.smul_bot Submodule.smul_bot @[simp] theorem bot_smul : (⊥ : Ideal R) • N = ⊥ := map₂_bot_left _ _ #align submodule.bot_smul Submodule.bot_smul @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri #align submodule.top_smul Submodule.top_smul theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P := map₂_sup_right _ _ _ _ #align submodule.smul_sup Submodule.smul_sup theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N := map₂_sup_left _ _ _ _ #align submodule.sup_smul Submodule.sup_smul protected theorem smul_assoc : (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_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn)) fun x y => (add_smul x y t).symm ▸ Submodule.add_mem _) (smul_le.2 fun r hr _ hsn => suffices J • N ≤ Submodule.comap (r • (LinearMap.id : M →ₗ[R] M)) ((I • J) • N) from this hsn smul_le.2 fun s hs n hn => show r • s • n ∈ (I • J) • N from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn) #align submodule.smul_assoc Submodule.smul_assoc @[deprecated smul_inf_le (since := "2024-03-31")] protected theorem smul_inf_le (M₁ M₂ : Submodule R M) : I • (M₁ ⊓ M₂) ≤ I • M₁ ⊓ I • M₂ := smul_inf_le _ _ _ #align submodule.smul_inf_le Submodule.smul_inf_le theorem smul_iSup {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iSup t = ⨆ i, I • t i := map₂_iSup_right _ _ _ #align submodule.smul_supr Submodule.smul_iSup @[deprecated smul_iInf_le (since := "2024-03-31")] protected theorem smul_iInf_le {ι : Sort*} {I : Ideal R} {t : ι → Submodule R M} : I • iInf t ≤ ⨅ i, I • t i := smul_iInf_le #align submodule.smul_infi_le Submodule.smul_iInf_le variable (S : Set R) (T : Set M) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ #align submodule.span_smul_span Submodule.span_smul_span theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa #align submodule.ideal_span_singleton_smul Submodule.ideal_span_singleton_smul theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices (⊤ : Ideal R) • span R ({x} : Set M) ≤ M' by rw [top_smul] at this exact this (subset_span (Set.mem_singleton x)) rw [← hs, span_smul_span, span_le] simpa using H #align submodule.mem_of_span_top_of_smul_mem Submodule.mem_of_span_top_of_smul_mem /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by obtain ⟨s', hs₁, hs₂⟩ := (Ideal.span_eq_top_iff_finite _).mp hs replace H : ∀ r : s', ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M' := fun r => H ⟨_, hs₁ r.2⟩ choose n₁ n₂ using H let N := s'.attach.sup n₁ have hs' := Ideal.span_pow_eq_top (s' : Set R) hs₂ N apply M'.mem_of_span_top_of_smul_mem _ hs' rintro ⟨_, r, hr, rfl⟩ convert M'.smul_mem (r ^ (N - n₁ ⟨r, hr⟩)) (n₂ ⟨r, hr⟩) using 1 simp only [Subtype.coe_mk, smul_smul, ← pow_add] rw [tsub_add_cancel_of_le (Finset.le_sup (s'.mem_attach _) : n₁ ⟨r, hr⟩ ≤ N)] #align submodule.mem_of_span_eq_top_of_smul_pow_mem Submodule.mem_of_span_eq_top_of_smul_pow_mem variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) #align submodule.map_smul'' Submodule.map_smul'' open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] variable {I} theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] rfl #align submodule.mem_smul_span Submodule.mem_smul_span variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction (mem_smul_span.mp hx) ?_ ?_ ?_ ?_ · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] #align submodule.mem_ideal_smul_span_iff_exists_sum Submodule.mem_ideal_smul_span_iff_exists_sum theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] #align submodule.mem_ideal_smul_span_iff_exists_sum' Submodule.mem_ideal_smul_span_iff_exists_sum' theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by change _ ↔ N.subtype x ∈ I • N have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] rw [← this] exact (Function.Injective.mem_set_image N.injective_subtype).symm #align submodule.mem_smul_top_iff Submodule.mem_smul_top_iff @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx #align submodule.smul_comap_le_comap_smul Submodule.smul_comap_le_comap_smul end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl #align ideal.add_eq_sup Ideal.add_eq_sup @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl #align ideal.zero_eq_bot Ideal.zero_eq_bot @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl #align ideal.sum_eq_sup Ideal.sum_eq_sup end Add section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} instance : Mul (Ideal R) := ⟨(· • ·)⟩ @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by erw [Submodule.one_eq_range, LinearMap.range_id] #align ideal.one_eq_top Ideal.one_eq_top theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs #align ideal.mul_mem_mul Ideal.mul_mem_mul theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs #align ideal.mul_mem_mul_rev Ideal.mul_mem_mul_rev theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ #align ideal.pow_mem_pow Ideal.pow_mem_pow theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) #align ideal.prod_mem_prod Ideal.prod_mem_prod theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le #align ideal.mul_le Ideal.mul_le theorem mul_le_left : I * J ≤ J := Ideal.mul_le.2 fun _ _ _ => J.mul_mem_left _ #align ideal.mul_le_left Ideal.mul_le_left theorem mul_le_right : I * J ≤ I := Ideal.mul_le.2 fun _ hr _ _ => I.mul_mem_right _ hr #align ideal.mul_le_right Ideal.mul_le_right @[simp] theorem sup_mul_right_self : I ⊔ I * J = I := sup_eq_left.2 Ideal.mul_le_right #align ideal.sup_mul_right_self Ideal.sup_mul_right_self @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 Ideal.mul_le_left #align ideal.sup_mul_left_self Ideal.sup_mul_left_self @[simp] theorem mul_right_self_sup : I * J ⊔ I = I := sup_eq_right.2 Ideal.mul_le_right #align ideal.mul_right_self_sup Ideal.mul_right_self_sup @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 Ideal.mul_le_left #align ideal.mul_left_self_sup Ideal.mul_left_self_sup variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) #align ideal.mul_comm Ideal.mul_comm protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K #align ideal.mul_assoc Ideal.mul_assoc theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T #align ideal.span_mul_span Ideal.span_mul_span variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] #align ideal.span_mul_span' Ideal.span_mul_span' theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] #align ideal.span_singleton_mul_span_singleton Ideal.span_singleton_mul_span_singleton theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] #align ideal.span_singleton_pow Ideal.span_singleton_pow theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton #align ideal.mem_mul_span_singleton Ideal.mem_mul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] #align ideal.mem_span_singleton_mul Ideal.mem_span_singleton_mul theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] #align ideal.le_span_singleton_mul_iff Ideal.le_span_singleton_mul_iff theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) #align ideal.span_singleton_mul_le_iff Ideal.span_singleton_mul_le_iff theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_le_span_singleton_mul Ideal.span_singleton_mul_le_span_singleton_mul theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] #align ideal.span_singleton_mul_right_mono Ideal.span_singleton_mul_right_mono theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx #align ideal.span_singleton_mul_left_mono Ideal.span_singleton_mul_left_mono theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] #align ideal.span_singleton_mul_right_inj Ideal.span_singleton_mul_right_inj theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] #align ideal.span_singleton_mul_left_inj Ideal.span_singleton_mul_left_inj theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp #align ideal.span_singleton_mul_right_injective Ideal.span_singleton_mul_right_injective theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp #align ideal.span_singleton_mul_left_injective Ideal.span_singleton_mul_left_injective theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] #align ideal.eq_span_singleton_mul Ideal.eq_span_singleton_mul theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] #align ideal.span_singleton_mul_eq_span_singleton_mul Ideal.span_singleton_mul_eq_span_singleton_mul theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I #align ideal.prod_span Ideal.prod_span theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I #align ideal.prod_span_singleton Ideal.prod_span_singleton @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] #align ideal.multiset_prod_span_singleton Ideal.multiset_prod_span_singleton theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ #align ideal.finset_inf_span_singleton Ideal.finset_inf_span_singleton theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] #align ideal.infi_span_singleton Ideal.iInf_span_singleton theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ #align ideal.sup_eq_top_iff_is_coprime Ideal.sup_eq_top_iff_isCoprime theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ #align ideal.mul_le_inf Ideal.mul_le_inf theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) #align ideal.multiset_prod_le_inf Ideal.multiset_prod_le_inf theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf #align ideal.prod_le_inf Ideal.prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) #align ideal.mul_eq_inf_of_coprime Ideal.mul_eq_inf_of_coprime theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] #align ideal.sup_mul_eq_of_coprime_left Ideal.sup_mul_eq_of_coprime_left theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h #align ideal.sup_mul_eq_of_coprime_right Ideal.sup_mul_eq_of_coprime_right theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm] #align ideal.mul_sup_eq_of_coprime_left Ideal.mul_sup_eq_of_coprime_left theorem mul_sup_eq_of_coprime_right (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm] #align ideal.mul_sup_eq_of_coprime_right Ideal.mul_sup_eq_of_coprime_right theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ∏ i ∈ s, J i) = ⊤ := Finset.prod_induction _ (fun J => I ⊔ J = ⊤) (fun J K hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK) (by simp_rw [one_eq_top, sup_top_eq]) h #align ideal.sup_prod_eq_top Ideal.sup_prod_eq_top theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ⨅ i ∈ s, J i) = ⊤ := eq_top_iff.mpr <| le_of_eq_of_le (sup_prod_eq_top h).symm <| sup_le_sup_left (le_of_le_of_eq prod_le_inf <| Finset.inf_eq_iInf _ _) _ #align ideal.sup_infi_eq_top Ideal.sup_iInf_eq_top theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi] #align ideal.prod_sup_eq_top Ideal.prod_sup_eq_top theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (⨅ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi] #align ideal.infi_sup_eq_top Ideal.iInf_sup_eq_top theorem sup_pow_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact sup_prod_eq_top fun _ _ => h #align ideal.sup_pow_eq_top Ideal.sup_pow_eq_top theorem pow_sup_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact prod_sup_eq_top fun _ _ => h #align ideal.pow_sup_eq_top Ideal.pow_sup_eq_top theorem pow_sup_pow_eq_top {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ := sup_pow_eq_top (pow_sup_eq_top h) #align ideal.pow_sup_pow_eq_top Ideal.pow_sup_pow_eq_top variable (I) -- @[simp] -- Porting note (#10618): simp can prove this theorem mul_bot : I * ⊥ = ⊥ := by simp #align ideal.mul_bot Ideal.mul_bot -- @[simp] -- Porting note (#10618): simp can prove thisrove this theorem bot_mul : ⊥ * I = ⊥ := by simp #align ideal.bot_mul Ideal.bot_mul @[simp] theorem mul_top : I * ⊤ = I := Ideal.mul_comm ⊤ I ▸ Submodule.top_smul I #align ideal.mul_top Ideal.mul_top @[simp] theorem top_mul : ⊤ * I = I := Submodule.top_smul I #align ideal.top_mul Ideal.top_mul variable {I} theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := Submodule.smul_mono hik hjl #align ideal.mul_mono Ideal.mul_mono theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K := Submodule.smul_mono_left h #align ideal.mul_mono_left Ideal.mul_mono_left theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K := smul_mono_right _ h #align ideal.mul_mono_right Ideal.mul_mono_right variable (I J K) theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K := Submodule.smul_sup I J K #align ideal.mul_sup Ideal.mul_sup theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K := Submodule.sup_smul I J K #align ideal.sup_mul Ideal.sup_mul variable {I J K}
Mathlib/RingTheory/Ideal/Operations.lean
776
779
theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by
cases' Nat.exists_eq_add_of_le h with k hk rw [hk, pow_add] exact le_trans mul_le_inf inf_le_left
/- Copyright (c) 2021 Paul Lezeau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.Algebra.IsPrimePow import Mathlib.Algebra.Squarefree.Basic import Mathlib.Order.Hom.Bounded import Mathlib.Algebra.GCDMonoid.Basic #align_import ring_theory.chain_of_divisors from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Chains of divisors The results in this file show that in the monoid `Associates M` of a `UniqueFactorizationMonoid` `M`, an element `a` is an n-th prime power iff its set of divisors is a strictly increasing chain of length `n + 1`, meaning that we can find a strictly increasing bijection between `Fin (n + 1)` and the set of factors of `a`. ## Main results - `DivisorChain.exists_chain_of_prime_pow` : existence of a chain for prime powers. - `DivisorChain.is_prime_pow_of_has_chain` : elements that have a chain are prime powers. - `multiplicity_prime_eq_multiplicity_image_by_factor_orderIso` : if there is a monotone bijection `d` between the set of factors of `a : Associates M` and the set of factors of `b : Associates N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b`. - `multiplicity_eq_multiplicity_factor_dvd_iso_of_mem_normalizedFactors` : if there is a bijection between the set of factors of `a : M` and `b : N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b` ## Todo - Create a structure for chains of divisors. - Simplify proof of `mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors` using `mem_normalizedFactors_factor_order_iso_of_mem_normalizedFactors` or vice versa. -/ variable {M : Type*} [CancelCommMonoidWithZero M] theorem Associates.isAtom_iff {p : Associates M} (h₁ : p ≠ 0) : IsAtom p ↔ Irreducible p := ⟨fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one] using hp.1, fun a b h => (hp.le_iff.mp ⟨_, h⟩).casesOn (fun ha => Or.inl (a.isUnit_iff_eq_one.mpr ha)) fun ha => Or.inr (show IsUnit b by rw [ha] at h apply isUnit_of_associated_mul (show Associated (p * b) p by conv_rhs => rw [h]) h₁)⟩, fun hp => ⟨by simpa only [Associates.isUnit_iff_eq_one, Associates.bot_eq_one] using hp.1, fun b ⟨⟨a, hab⟩, hb⟩ => (hp.isUnit_or_isUnit hab).casesOn (fun hb => show b = ⊥ by rwa [Associates.isUnit_iff_eq_one, ← Associates.bot_eq_one] at hb) fun ha => absurd (show p ∣ b from ⟨(ha.unit⁻¹ : Units _), by rw [hab, mul_assoc, IsUnit.mul_val_inv ha, mul_one]⟩) hb⟩⟩ #align associates.is_atom_iff Associates.isAtom_iff open UniqueFactorizationMonoid multiplicity Irreducible Associates namespace DivisorChain theorem exists_chain_of_prime_pow {p : Associates M} {n : ℕ} (hn : n ≠ 0) (hp : Prime p) : ∃ c : Fin (n + 1) → Associates M, c 1 = p ∧ StrictMono c ∧ ∀ {r : Associates M}, r ≤ p ^ n ↔ ∃ i, r = c i := by refine ⟨fun i => p ^ (i : ℕ), ?_, fun n m h => ?_, @fun y => ⟨fun h => ?_, ?_⟩⟩ · dsimp only rw [Fin.val_one', Nat.mod_eq_of_lt, pow_one] exact Nat.lt_succ_of_le (Nat.one_le_iff_ne_zero.mpr hn) · exact Associates.dvdNotUnit_iff_lt.mp ⟨pow_ne_zero n hp.ne_zero, p ^ (m - n : ℕ), not_isUnit_of_not_isUnit_dvd hp.not_unit (dvd_pow dvd_rfl (Nat.sub_pos_of_lt h).ne'), (pow_mul_pow_sub p h.le).symm⟩ · obtain ⟨i, i_le, hi⟩ := (dvd_prime_pow hp n).1 h rw [associated_iff_eq] at hi exact ⟨⟨i, Nat.lt_succ_of_le i_le⟩, hi⟩ · rintro ⟨i, rfl⟩ exact ⟨p ^ (n - i : ℕ), (pow_mul_pow_sub p (Nat.succ_le_succ_iff.mp i.2)).symm⟩ #align divisor_chain.exists_chain_of_prime_pow DivisorChain.exists_chain_of_prime_pow theorem element_of_chain_not_isUnit_of_index_ne_zero {n : ℕ} {i : Fin (n + 1)} (i_pos : i ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) : ¬IsUnit (c i) := DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ <| show (0 : Fin (n + 1)) < i from Fin.pos_iff_ne_zero.mpr i_pos)) #align divisor_chain.element_of_chain_not_is_unit_of_index_ne_zero DivisorChain.element_of_chain_not_isUnit_of_index_ne_zero theorem first_of_chain_isUnit {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) : IsUnit (c 0) := by obtain ⟨i, hr⟩ := h₂.mp Associates.one_le rw [Associates.isUnit_iff_eq_one, ← Associates.le_one_iff, hr] exact h₁.monotone (Fin.zero_le i) #align divisor_chain.first_of_chain_is_unit DivisorChain.first_of_chain_isUnit /-- The second element of a chain is irreducible. -/ theorem second_of_chain_is_irreducible {q : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : Irreducible (c 1) := by cases' n with n; · contradiction refine (Associates.isAtom_iff (ne_zero_of_dvd_ne_zero hq (h₂.2 ⟨1, rfl⟩))).mp ⟨?_, fun b hb => ?_⟩ · exact ne_bot_of_gt (h₁ (show (0 : Fin (n + 2)) < 1 from Fin.one_pos)) obtain ⟨⟨i, hi⟩, rfl⟩ := h₂.1 (hb.le.trans (h₂.2 ⟨1, rfl⟩)) cases i · exact (Associates.isUnit_iff_eq_one _).mp (first_of_chain_isUnit h₁ @h₂) · simpa [Fin.lt_iff_val_lt_val] using h₁.lt_iff_lt.mp hb #align divisor_chain.second_of_chain_is_irreducible DivisorChain.second_of_chain_is_irreducible
Mathlib/RingTheory/ChainOfDivisors.lean
111
132
theorem eq_second_of_chain_of_prime_dvd {p q r : Associates M} {n : ℕ} (hn : n ≠ 0) {c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hp : Prime p) (hr : r ∣ q) (hp' : p ∣ r) : p = c 1 := by
cases' n with n · contradiction obtain ⟨i, rfl⟩ := h₂.1 (dvd_trans hp' hr) refine congr_arg c (eq_of_ge_of_not_gt ?_ fun hi => ?_) · rw [Fin.le_iff_val_le_val, Fin.val_one, Nat.succ_le_iff, ← Fin.val_zero' (n.succ + 1), ← Fin.lt_iff_val_lt_val, Fin.pos_iff_ne_zero] rintro rfl exact hp.not_unit (first_of_chain_isUnit h₁ @h₂) obtain rfl | ⟨j, rfl⟩ := i.eq_zero_or_eq_succ · cases hi refine not_irreducible_of_not_unit_dvdNotUnit (DvdNotUnit.not_unit (Associates.dvdNotUnit_iff_lt.2 (h₁ (show (0 : Fin (n + 2)) < j from ?_)))) ?_ hp.irreducible · simpa [Fin.succ_lt_succ_iff, Fin.lt_iff_val_lt_val] using hi · refine Associates.dvdNotUnit_iff_lt.2 (h₁ ?_) simpa only [Fin.coe_eq_castSucc] using Fin.lt_succ
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Justus Springer -/ import Mathlib.Topology.Category.TopCat.OpenNhds import Mathlib.Topology.Sheaves.Presheaf import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing import Mathlib.CategoryTheory.Adjunction.Evaluation import Mathlib.CategoryTheory.Limits.Types import Mathlib.CategoryTheory.Limits.Preserves.Filtered import Mathlib.CategoryTheory.Limits.Final import Mathlib.Tactic.CategoryTheory.Elementwise import Mathlib.Algebra.Category.Ring.Colimits import Mathlib.CategoryTheory.Sites.Pullback #align_import topology.sheaves.stalks from "leanprover-community/mathlib"@"5dc6092d09e5e489106865241986f7f2ad28d4c8" /-! # Stalks For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F` at the point `x : X` is defined as the colimit of the composition of the inclusion of categories `(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`. For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the canonical morphism into this colimit. Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`, sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between topological spaces, we define `stalkPushforward` as the induced map on the stalks `(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`. Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic property of forgetful functors of categories of algebraic structures (like `MonCat`, `CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits, this ensures that the stalks of presheaves valued in these categories behave exactly as for `Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every element of the stalk is the germ of a section. Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as is the case for most algebraic structures), we have access to the unique gluing API and can prove further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are isomorphisms. See also the definition of "algebraic structures" in the stacks project: https://stacks.math.columbia.edu/tag/007L -/ noncomputable section universe v u v' u' open CategoryTheory open TopCat open CategoryTheory.Limits open TopologicalSpace open Opposite variable {C : Type u} [Category.{v} C] variable [HasColimits.{v} C] variable {X Y Z : TopCat.{v}} namespace TopCat.Presheaf variable (C) /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalkFunctor (x : X) : X.Presheaf C ⥤ C := (whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor TopCat.Presheaf.stalkFunctor variable {C} /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.Presheaf C) (x : X) : C := (stalkFunctor C x).obj ℱ set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk TopCat.Presheaf.stalk -- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ) @[simp] theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x := rfl set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_obj TopCat.Presheaf.stalkFunctor_obj /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ (F : X.Presheaf C) {U : Opens X} (x : U) : F.obj (op U) ⟶ stalk F x := colimit.ι ((OpenNhds.inclusion x.1).op ⋙ F) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.germ TopCat.Presheaf.germ theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) : F.map i.op ≫ germ F x = germ F (i x : V) := let i' : (⟨U, x.2⟩ : OpenNhds x.1) ⟶ ⟨V, (i x : V).2⟩ := i colimit.w ((OpenNhds.inclusion x.1).op ⋙ F) i'.op set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res TopCat.Presheaf.germ_res -- Porting note: `@[elementwise]` did not generate the best lemma when applied to `germ_res` attribute [local instance] ConcreteCategory.instFunLike in theorem germ_res_apply (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : U) [ConcreteCategory C] (s) : germ F x (F.map i.op s) = germ F (i x) s := by rw [← comp_apply, germ_res] set_option linter.uppercaseLean3 false in #align Top.presheaf.germ_res_apply TopCat.Presheaf.germ_res_apply /-- A morphism from the stalk of `F` at `x` to some object `Y` is completely determined by its composition with the `germ` morphisms. -/ @[ext] theorem stalk_hom_ext (F : X.Presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y} (ih : ∀ (U : Opens X) (hxU : x ∈ U), F.germ ⟨x, hxU⟩ ≫ f₁ = F.germ ⟨x, hxU⟩ ≫ f₂) : f₁ = f₂ := colimit.hom_ext fun U => by induction' U using Opposite.rec with U; cases' U with U hxU; exact ih U hxU set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_hom_ext TopCat.Presheaf.stalk_hom_ext @[reassoc (attr := simp), elementwise (attr := simp)] theorem stalkFunctor_map_germ {F G : X.Presheaf C} (U : Opens X) (x : U) (f : F ⟶ G) : germ F x ≫ (stalkFunctor C x.1).map f = f.app (op U) ≫ germ G x := colimit.ι_map (whiskerLeft (OpenNhds.inclusion x.1).op f) (op ⟨U, x.2⟩) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_functor_map_germ TopCat.Presheaf.stalkFunctor_map_germ variable (C) /-- For a presheaf `F` on a space `X`, a continuous map `f : X ⟶ Y` induces a morphisms between the stalk of `f _ * F` at `f x` and the stalk of `F` at `x`. -/ def stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) (x : X) : (f _* F).stalk (f x) ⟶ F.stalk x := by -- This is a hack; Lean doesn't like to elaborate the term written directly. -- Porting note: The original proof was `trans; swap`, but `trans` does nothing. refine ?_ ≫ colimit.pre _ (OpenNhds.map f x).op exact colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) F) set_option linter.uppercaseLean3 false in #align Top.presheaf.stalk_pushforward TopCat.Presheaf.stalkPushforward @[reassoc (attr := simp), elementwise (attr := simp)]
Mathlib/Topology/Sheaves/Stalks.lean
150
153
theorem stalkPushforward_germ (f : X ⟶ Y) (F : X.Presheaf C) (U : Opens Y) (x : (Opens.map f).obj U) : (f _* F).germ ⟨(f : X → Y) (x : X), x.2⟩ ≫ F.stalkPushforward C f x = F.germ x := by
simp [germ, stalkPushforward]
/- 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 import Mathlib.MeasureTheory.Group.Pointwise import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.MeasureTheory.Measure.Haar.Basic import Mathlib.MeasureTheory.Measure.Doubling import Mathlib.MeasureTheory.Constructions.BorelSpace.Metric #align_import measure_theory.measure.lebesgue.eq_haar from "leanprover-community/mathlib"@"fd5edc43dc4f10b85abfe544b88f82cf13c5f844" /-! # 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] #align topological_space.positive_compacts.Icc01 TopologicalSpace.PositiveCompacts.Icc01 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] #align topological_space.positive_compacts.pi_Icc01 TopologicalSpace.PositiveCompacts.piIcc01 /-- 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 #align basis.parallelepiped_basis_fun Basis.parallelepiped_basisFun /-- 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 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 FiniteDimensional /-! ### 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] #align measure_theory.add_haar_measure_eq_volume MeasureTheory.addHaarMeasure_eq_volume /-- 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] #align measure_theory.add_haar_measure_eq_volume_pi MeasureTheory.addHaarMeasure_eq_volume_pi -- Porting note (#11215): TODO: remove this instance? instance isAddHaarMeasure_volume_pi (ι : Type*) [Fintype ι] : IsAddHaarMeasure (volume : Measure (ι → ℝ)) := inferInstance #align measure_theory.is_add_haar_measure_volume_pi MeasureTheory.isAddHaarMeasure_volume_pi namespace Measure /-! ### Strict subspaces have zero measure -/ /-- 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 #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates_aux MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates_aux /-- 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 #align measure_theory.measure.add_haar_eq_zero_of_disjoint_translates MeasureTheory.Measure.addHaar_eq_zero_of_disjoint_translates /-- 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 #align measure_theory.measure.add_haar_submodule MeasureTheory.Measure.addHaar_submodule /-- 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 #align measure_theory.measure.add_haar_affine_subspace MeasureTheory.Measure.addHaar_affineSubspace /-! ### 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] #align measure_theory.measure.map_linear_map_add_haar_pi_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_addHaar_pi_eq_smul_addHaar variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] (μ : Measure E) [IsAddHaarMeasure μ] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] 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] #align measure_theory.measure.map_linear_map_add_haar_eq_smul_add_haar MeasureTheory.Measure.map_linearMap_addHaar_eq_smul_addHaar /-- 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 #align measure_theory.measure.add_haar_preimage_linear_map MeasureTheory.Measure.addHaar_preimage_linearMap /-- 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 #align measure_theory.measure.add_haar_preimage_continuous_linear_map MeasureTheory.Measure.addHaar_preimage_continuousLinearMap /-- 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] #align measure_theory.measure.add_haar_preimage_linear_equiv MeasureTheory.Measure.addHaar_preimage_linearEquiv /-- 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 #align measure_theory.measure.add_haar_preimage_continuous_linear_equiv MeasureTheory.Measure.addHaar_preimage_continuousLinearEquiv /-- 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 _) #align measure_theory.measure.add_haar_image_linear_map MeasureTheory.Measure.addHaar_image_linearMap /-- 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 #align measure_theory.measure.add_haar_image_continuous_linear_map MeasureTheory.Measure.addHaar_image_continuousLinearMap /-- 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 #align measure_theory.measure.add_haar_image_continuous_linear_equiv MeasureTheory.Measure.addHaar_image_continuousLinearEquiv 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] #align measure_theory.measure.map_add_haar_smul MeasureTheory.Measure.map_addHaar_smul 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] #align measure_theory.measure.add_haar_preimage_smul MeasureTheory.Measure.addHaar_preimage_smul /-- 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] #align measure_theory.measure.add_haar_smul MeasureTheory.Measure.addHaar_smul 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] #align measure_theory.measure.add_haar_smul_of_nonneg MeasureTheory.Measure.addHaar_smul_of_nonneg 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] #align measure_theory.measure.null_measurable_set.const_smul MeasureTheory.Measure.NullMeasurableSet.const_smul 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] #align measure_theory.measure.add_haar_image_homothety MeasureTheory.Measure.addHaar_image_homothety /-! 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] #align measure_theory.measure.add_haar_ball_center MeasureTheory.Measure.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] #align measure_theory.measure.add_haar_closed_ball_center MeasureTheory.Measure.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] #align measure_theory.measure.add_haar_ball_mul_of_pos MeasureTheory.Measure.addHaar_ball_mul_of_pos 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] #align measure_theory.measure.add_haar_ball_of_pos MeasureTheory.Measure.addHaar_ball_of_pos 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 #align measure_theory.measure.add_haar_ball_mul MeasureTheory.Measure.addHaar_ball_mul 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] #align measure_theory.measure.add_haar_ball MeasureTheory.Measure.addHaar_ball 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] simp only [this, addHaar_smul, abs_of_nonneg hr.le, addHaar_closedBall_center, abs_pow] #align measure_theory.measure.add_haar_closed_ball_mul_of_pos MeasureTheory.Measure.addHaar_closedBall_mul_of_pos theorem addHaar_closedBall_mul (x : E) {r : ℝ} (hr : 0 ≤ r) {s : ℝ} (hs : 0 ≤ 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 r (0 : E) hs, abs_of_nonneg hr] simp only [this, addHaar_smul, abs_of_nonneg hr, addHaar_closedBall_center, abs_pow] #align measure_theory.measure.add_haar_closed_ball_mul MeasureTheory.Measure.addHaar_closedBall_mul /-- The measure of a closed ball can be expressed in terms of the measure of the closed unit ball. Use instead `addHaar_closedBall`, which uses the measure of the open unit ball as a standard form. -/ theorem addHaar_closedBall' (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall 0 1) := by rw [← addHaar_closedBall_mul μ x hr zero_le_one, mul_one] #align measure_theory.measure.add_haar_closed_ball' MeasureTheory.Measure.addHaar_closedBall' theorem addHaar_closed_unit_ball_eq_addHaar_unit_ball : μ (closedBall (0 : E) 1) = μ (ball 0 1) := by apply le_antisymm _ (measure_mono ball_subset_closedBall) have A : Tendsto (fun r : ℝ => ENNReal.ofReal (r ^ finrank ℝ E) * μ (closedBall (0 : E) 1)) (𝓝[<] 1) (𝓝 (ENNReal.ofReal ((1 : ℝ) ^ finrank ℝ E) * μ (closedBall (0 : E) 1))) := by refine ENNReal.Tendsto.mul ?_ (by simp) tendsto_const_nhds (by simp) exact ENNReal.tendsto_ofReal ((tendsto_id'.2 nhdsWithin_le_nhds).pow _) simp only [one_pow, one_mul, ENNReal.ofReal_one] at A refine le_of_tendsto A ?_ refine mem_nhdsWithin_Iio_iff_exists_Ioo_subset.2 ⟨(0 : ℝ), by simp, fun r hr => ?_⟩ dsimp rw [← addHaar_closedBall' μ (0 : E) hr.1.le] exact measure_mono (closedBall_subset_ball hr.2) #align measure_theory.measure.add_haar_closed_unit_ball_eq_add_haar_unit_ball MeasureTheory.Measure.addHaar_closed_unit_ball_eq_addHaar_unit_ball theorem addHaar_closedBall (x : E) {r : ℝ} (hr : 0 ≤ r) : μ (closedBall x r) = ENNReal.ofReal (r ^ finrank ℝ E) * μ (ball 0 1) := by rw [addHaar_closedBall' μ x hr, addHaar_closed_unit_ball_eq_addHaar_unit_ball] #align measure_theory.measure.add_haar_closed_ball MeasureTheory.Measure.addHaar_closedBall theorem addHaar_closedBall_eq_addHaar_ball [Nontrivial E] (x : E) (r : ℝ) : μ (closedBall x r) = μ (ball x r) := by by_cases h : r < 0 · rw [Metric.closedBall_eq_empty.mpr h, Metric.ball_eq_empty.mpr h.le] push_neg at h rw [addHaar_closedBall μ x h, addHaar_ball μ x h] #align measure_theory.measure.add_haar_closed_ball_eq_add_haar_ball MeasureTheory.Measure.addHaar_closedBall_eq_addHaar_ball theorem addHaar_sphere_of_ne_zero (x : E) {r : ℝ} (hr : r ≠ 0) : μ (sphere x r) = 0 := by rcases hr.lt_or_lt with (h | h) · simp only [empty_diff, measure_empty, ← closedBall_diff_ball, closedBall_eq_empty.2 h] · rw [← closedBall_diff_ball, measure_diff ball_subset_closedBall measurableSet_ball measure_ball_lt_top.ne, addHaar_ball_of_pos μ _ h, addHaar_closedBall μ _ h.le, tsub_self] #align measure_theory.measure.add_haar_sphere_of_ne_zero MeasureTheory.Measure.addHaar_sphere_of_ne_zero theorem addHaar_sphere [Nontrivial E] (x : E) (r : ℝ) : μ (sphere x r) = 0 := by rcases eq_or_ne r 0 with (rfl | h) · rw [sphere_zero, measure_singleton] · exact addHaar_sphere_of_ne_zero μ x h #align measure_theory.measure.add_haar_sphere MeasureTheory.Measure.addHaar_sphere theorem addHaar_singleton_add_smul_div_singleton_add_smul {r : ℝ} (hr : r ≠ 0) (x y : E) (s t : Set E) : μ ({x} + r • s) / μ ({y} + r • t) = μ s / μ t := calc μ ({x} + r • s) / μ ({y} + r • t) = ENNReal.ofReal (|r| ^ finrank ℝ E) * μ s * (ENNReal.ofReal (|r| ^ finrank ℝ E) * μ t)⁻¹ := by simp only [div_eq_mul_inv, addHaar_smul, image_add_left, measure_preimage_add, abs_pow, singleton_add] _ = ENNReal.ofReal (|r| ^ finrank ℝ E) * (ENNReal.ofReal (|r| ^ finrank ℝ E))⁻¹ * (μ s * (μ t)⁻¹) := by rw [ENNReal.mul_inv] · ring · simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne, true_or_iff] · simp only [ENNReal.ofReal_ne_top, true_or_iff, Ne, not_false_iff] _ = μ s / μ t := by rw [ENNReal.mul_inv_cancel, one_mul, div_eq_mul_inv] · simp only [pow_pos (abs_pos.mpr hr), ENNReal.ofReal_eq_zero, not_le, Ne] · simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff] #align measure_theory.measure.add_haar_singleton_add_smul_div_singleton_add_smul MeasureTheory.Measure.addHaar_singleton_add_smul_div_singleton_add_smul instance (priority := 100) isUnifLocDoublingMeasureOfIsAddHaarMeasure : IsUnifLocDoublingMeasure μ := by refine ⟨⟨(2 : ℝ≥0) ^ finrank ℝ E, ?_⟩⟩ filter_upwards [self_mem_nhdsWithin] with r hr x rw [addHaar_closedBall_mul μ x zero_le_two (le_of_lt hr), addHaar_closedBall_center μ x, ENNReal.ofReal, Real.toNNReal_pow zero_le_two] simp only [Real.toNNReal_ofNat, le_refl] #align measure_theory.measure.is_unif_loc_doubling_measure_of_is_add_haar_measure MeasureTheory.Measure.isUnifLocDoublingMeasureOfIsAddHaarMeasure section /-! ### The Lebesgue measure associated to an alternating map -/ variable {ι G : Type*} [Fintype ι] [DecidableEq ι] [NormedAddCommGroup G] [NormedSpace ℝ G] [MeasurableSpace G] [BorelSpace G] theorem addHaar_parallelepiped (b : Basis ι ℝ G) (v : ι → G) : b.addHaar (parallelepiped v) = ENNReal.ofReal |b.det v| := by have : FiniteDimensional ℝ G := FiniteDimensional.of_fintype_basis b have A : parallelepiped v = b.constr ℕ v '' parallelepiped b := by rw [image_parallelepiped] -- Porting note: was `congr 1 with i` but Lean 4 `congr` applies `ext` first refine congr_arg _ <| funext fun i ↦ ?_ exact (b.constr_basis ℕ v i).symm rw [A, addHaar_image_linearMap, b.addHaar_self, mul_one, ← LinearMap.det_toMatrix b, ← Basis.toMatrix_eq_toMatrix_constr, Basis.det_apply] #align measure_theory.measure.add_haar_parallelepiped MeasureTheory.Measure.addHaar_parallelepiped variable [FiniteDimensional ℝ G] {n : ℕ} [_i : Fact (finrank ℝ G = n)] /-- The Lebesgue measure associated to an alternating map. It gives measure `|ω v|` to the parallelepiped spanned by the vectors `v₁, ..., vₙ`. Note that it is not always a Haar measure, as it can be zero, but it is always locally finite and translation invariant. -/ noncomputable irreducible_def _root_.AlternatingMap.measure (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) : Measure G := ‖ω (finBasisOfFinrankEq ℝ G _i.out)‖₊ • (finBasisOfFinrankEq ℝ G _i.out).addHaar #align alternating_map.measure AlternatingMap.measure
Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean
603
608
theorem _root_.AlternatingMap.measure_parallelepiped (ω : G [⋀^Fin n]→ₗ[ℝ] ℝ) (v : Fin n → G) : ω.measure (parallelepiped v) = ENNReal.ofReal |ω v| := by
conv_rhs => rw [ω.eq_smul_basis_det (finBasisOfFinrankEq ℝ G _i.out)] simp only [addHaar_parallelepiped, AlternatingMap.measure, coe_nnreal_smul_apply, AlternatingMap.smul_apply, Algebra.id.smul_eq_mul, abs_mul, ENNReal.ofReal_mul (abs_nonneg _), Real.ennnorm_eq_ofReal_abs]
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Subalgebra import Mathlib.RingTheory.Noetherian import Mathlib.RingTheory.Artinian #align_import algebra.lie.submodule from "leanprover-community/mathlib"@"9822b65bfc4ac74537d77ae318d27df1df662471" /-! # Lie submodules of a Lie algebra In this file we define Lie submodules and Lie ideals, we construct the lattice structure on Lie submodules and we use it to define various important operations, notably the Lie span of a subset of a Lie module. ## Main definitions * `LieSubmodule` * `LieSubmodule.wellFounded_of_noetherian` * `LieSubmodule.lieSpan` * `LieSubmodule.map` * `LieSubmodule.comap` * `LieIdeal` * `LieIdeal.map` * `LieIdeal.comap` ## Tags lie algebra, lie submodule, lie ideal, lattice structure -/ universe u v w w₁ w₂ section LieSubmodule variable (R : Type u) (L : Type v) (M : Type w) variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] /-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket. This is a sufficient condition for the subset itself to form a Lie module. -/ structure LieSubmodule extends Submodule R M where lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier #align lie_submodule LieSubmodule attribute [nolint docBlame] LieSubmodule.toSubmodule attribute [coe] LieSubmodule.toSubmodule namespace LieSubmodule variable {R L M} variable (N N' : LieSubmodule R L M) instance : SetLike (LieSubmodule R L M) M where coe s := s.carrier coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h instance : AddSubgroupClass (LieSubmodule R L M) M where add_mem {N} _ _ := N.add_mem' zero_mem N := N.zero_mem' neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where smul_mem {s} c _ h := s.smul_mem' c h /-- The zero module is a Lie submodule of any Lie module. -/ instance : Zero (LieSubmodule R L M) := ⟨{ (0 : Submodule R M) with lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩ instance : Inhabited (LieSubmodule R L M) := ⟨0⟩ instance coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) := ⟨toSubmodule⟩ #align lie_submodule.coe_submodule LieSubmodule.coeSubmodule -- Syntactic tautology #noalign lie_submodule.to_submodule_eq_coe @[norm_cast] theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N := rfl #align lie_submodule.coe_to_submodule LieSubmodule.coe_toSubmodule -- Porting note (#10618): `simp` can prove this after `mem_coeSubmodule` is added to the simp set, -- but `dsimp` can't. @[simp, nolint simpNF] theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) := Iff.rfl #align lie_submodule.mem_carrier LieSubmodule.mem_carrier theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} : x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S := Iff.rfl #align lie_submodule.mem_mk_iff LieSubmodule.mem_mk_iff @[simp] theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} : x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p := Iff.rfl @[simp] theorem mem_coeSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N := Iff.rfl #align lie_submodule.mem_coe_submodule LieSubmodule.mem_coeSubmodule theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N := Iff.rfl #align lie_submodule.mem_coe LieSubmodule.mem_coe @[simp] protected theorem zero_mem : (0 : M) ∈ N := zero_mem N #align lie_submodule.zero_mem LieSubmodule.zero_mem -- Porting note (#10618): @[simp] can prove this theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 := Subtype.ext_iff_val #align lie_submodule.mk_eq_zero LieSubmodule.mk_eq_zero @[simp] theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) : ((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S := rfl #align lie_submodule.coe_to_set_mk LieSubmodule.coe_toSet_mk theorem coe_toSubmodule_mk (p : Submodule R M) (h) : (({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl #align lie_submodule.coe_to_submodule_mk LieSubmodule.coe_toSubmodule_mk theorem coeSubmodule_injective : Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by cases x; cases y; congr #align lie_submodule.coe_submodule_injective LieSubmodule.coeSubmodule_injective @[ext] theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' := SetLike.ext h #align lie_submodule.ext LieSubmodule.ext @[simp] theorem coe_toSubmodule_eq_iff : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' := coeSubmodule_injective.eq_iff #align lie_submodule.coe_to_submodule_eq_iff LieSubmodule.coe_toSubmodule_eq_iff /-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where carrier := s -- Porting note: all the proofs below were in term mode zero_mem' := by exact hs.symm ▸ N.zero_mem' add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y smul_mem' := by exact hs.symm ▸ N.smul_mem' lie_mem := by exact hs.symm ▸ N.lie_mem #align lie_submodule.copy LieSubmodule.copy @[simp] theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s := rfl #align lie_submodule.coe_copy LieSubmodule.coe_copy theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align lie_submodule.copy_eq LieSubmodule.copy_eq instance : LieRingModule L N where bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩ add_lie := by intro x y m; apply SetCoe.ext; apply add_lie lie_add := by intro x m n; apply SetCoe.ext; apply lie_add leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie instance module' {S : Type*} [Semiring S] [SMul S R] [Module S M] [IsScalarTower S R M] : Module S N := N.toSubmodule.module' #align lie_submodule.module' LieSubmodule.module' instance : Module R N := N.toSubmodule.module instance {S : Type*} [Semiring S] [SMul S R] [SMul Sᵐᵒᵖ R] [Module S M] [Module Sᵐᵒᵖ M] [IsScalarTower S R M] [IsScalarTower Sᵐᵒᵖ R M] [IsCentralScalar S M] : IsCentralScalar S N := N.toSubmodule.isCentralScalar instance instLieModule : LieModule R L N where lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie @[simp, norm_cast] theorem coe_zero : ((0 : N) : M) = (0 : M) := rfl #align lie_submodule.coe_zero LieSubmodule.coe_zero @[simp, norm_cast] theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) := rfl #align lie_submodule.coe_add LieSubmodule.coe_add @[simp, norm_cast] theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) := rfl #align lie_submodule.coe_neg LieSubmodule.coe_neg @[simp, norm_cast] theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) := rfl #align lie_submodule.coe_sub LieSubmodule.coe_sub @[simp, norm_cast] theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) := rfl #align lie_submodule.coe_smul LieSubmodule.coe_smul @[simp, norm_cast] theorem coe_bracket (x : L) (m : N) : (↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ := rfl #align lie_submodule.coe_bracket LieSubmodule.coe_bracket instance [Subsingleton M] : Unique (LieSubmodule R L M) := ⟨⟨0⟩, fun _ ↦ (coe_toSubmodule_eq_iff _ _).mp (Subsingleton.elim _ _)⟩ end LieSubmodule section LieIdeal /-- An ideal of a Lie algebra is a Lie submodule of the Lie algebra as a Lie module over itself. -/ abbrev LieIdeal := LieSubmodule R L L #align lie_ideal LieIdeal theorem lie_mem_right (I : LieIdeal R L) (x y : L) (h : y ∈ I) : ⁅x, y⁆ ∈ I := I.lie_mem h #align lie_mem_right lie_mem_right theorem lie_mem_left (I : LieIdeal R L) (x y : L) (h : x ∈ I) : ⁅x, y⁆ ∈ I := by rw [← lie_skew, ← neg_lie]; apply lie_mem_right; assumption #align lie_mem_left lie_mem_left /-- An ideal of a Lie algebra is a Lie subalgebra. -/ def lieIdealSubalgebra (I : LieIdeal R L) : LieSubalgebra R L := { I.toSubmodule with lie_mem' := by intro x y _ hy; apply lie_mem_right; exact hy } #align lie_ideal_subalgebra lieIdealSubalgebra instance : Coe (LieIdeal R L) (LieSubalgebra R L) := ⟨lieIdealSubalgebra R L⟩ @[simp] theorem LieIdeal.coe_toSubalgebra (I : LieIdeal R L) : ((I : LieSubalgebra R L) : Set L) = I := rfl #align lie_ideal.coe_to_subalgebra LieIdeal.coe_toSubalgebra @[simp] theorem LieIdeal.coe_to_lieSubalgebra_to_submodule (I : LieIdeal R L) : ((I : LieSubalgebra R L) : Submodule R L) = LieSubmodule.toSubmodule I := rfl #align lie_ideal.coe_to_lie_subalgebra_to_submodule LieIdeal.coe_to_lieSubalgebra_to_submodule /-- An ideal of `L` is a Lie subalgebra of `L`, so it is a Lie ring. -/ instance LieIdeal.lieRing (I : LieIdeal R L) : LieRing I := LieSubalgebra.lieRing R L ↑I #align lie_ideal.lie_ring LieIdeal.lieRing /-- Transfer the `LieAlgebra` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieAlgebra (I : LieIdeal R L) : LieAlgebra R I := LieSubalgebra.lieAlgebra R L ↑I #align lie_ideal.lie_algebra LieIdeal.lieAlgebra /-- Transfer the `LieRingModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieRingModule {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [LieRingModule L M] : LieRingModule I M := LieSubalgebra.lieRingModule (I : LieSubalgebra R L) #align lie_ideal.lie_ring_module LieIdeal.lieRingModule @[simp] theorem LieIdeal.coe_bracket_of_module {R L : Type*} [CommRing R] [LieRing L] [LieAlgebra R L] (I : LieIdeal R L) [LieRingModule L M] (x : I) (m : M) : ⁅x, m⁆ = ⁅(↑x : L), m⁆ := LieSubalgebra.coe_bracket_of_module (I : LieSubalgebra R L) x m #align lie_ideal.coe_bracket_of_module LieIdeal.coe_bracket_of_module /-- Transfer the `LieModule` instance from the coercion `LieIdeal → LieSubalgebra`. -/ instance LieIdeal.lieModule (I : LieIdeal R L) : LieModule R I M := LieSubalgebra.lieModule (I : LieSubalgebra R L) #align lie_ideal.lie_module LieIdeal.lieModule end LieIdeal variable {R M} theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) : (∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by constructor · rintro ⟨N, rfl⟩ _ _; exact N.lie_mem · intro h; use { p with lie_mem := @h } #align submodule.exists_lie_submodule_coe_eq_iff Submodule.exists_lieSubmodule_coe_eq_iff namespace LieSubalgebra variable {L} variable (K : LieSubalgebra R L) /-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains a distinguished Lie submodule for the action of `K`, namely `K` itself. -/ def toLieSubmodule : LieSubmodule R K L := { (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy } #align lie_subalgebra.to_lie_submodule LieSubalgebra.toLieSubmodule @[simp] theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl #align lie_subalgebra.coe_to_lie_submodule LieSubalgebra.coe_toLieSubmodule variable {K} @[simp] theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K := Iff.rfl #align lie_subalgebra.mem_to_lie_submodule LieSubalgebra.mem_toLieSubmodule theorem exists_lieIdeal_coe_eq_iff : (∃ I : LieIdeal R L, ↑I = K) ↔ ∀ x y : L, y ∈ K → ⁅x, y⁆ ∈ K := by simp only [← coe_to_submodule_eq_iff, LieIdeal.coe_to_lieSubalgebra_to_submodule, Submodule.exists_lieSubmodule_coe_eq_iff L] exact Iff.rfl #align lie_subalgebra.exists_lie_ideal_coe_eq_iff LieSubalgebra.exists_lieIdeal_coe_eq_iff theorem exists_nested_lieIdeal_coe_eq_iff {K' : LieSubalgebra R L} (h : K ≤ K') : (∃ I : LieIdeal R K', ↑I = ofLe h) ↔ ∀ x y : L, x ∈ K' → y ∈ K → ⁅x, y⁆ ∈ K := by simp only [exists_lieIdeal_coe_eq_iff, coe_bracket, mem_ofLe] constructor · intro h' x y hx hy; exact h' ⟨x, hx⟩ ⟨y, h hy⟩ hy · rintro h' ⟨x, hx⟩ ⟨y, hy⟩ hy'; exact h' x y hx hy' #align lie_subalgebra.exists_nested_lie_ideal_coe_eq_iff LieSubalgebra.exists_nested_lieIdeal_coe_eq_iff end LieSubalgebra end LieSubmodule namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] [LieModule R L M] variable (N N' : LieSubmodule R L M) (I J : LieIdeal R L) section LatticeStructure open Set theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) := SetLike.coe_injective #align lie_submodule.coe_injective LieSubmodule.coe_injective @[simp, norm_cast] theorem coeSubmodule_le_coeSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' := Iff.rfl #align lie_submodule.coe_submodule_le_coe_submodule LieSubmodule.coeSubmodule_le_coeSubmodule instance : Bot (LieSubmodule R L M) := ⟨0⟩ @[simp] theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} := rfl #align lie_submodule.bot_coe LieSubmodule.bot_coe @[simp] theorem bot_coeSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ := rfl #align lie_submodule.bot_coe_submodule LieSubmodule.bot_coeSubmodule @[simp] theorem coeSubmodule_eq_bot_iff : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by rw [← coe_toSubmodule_eq_iff, bot_coeSubmodule] @[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by rw [← coe_toSubmodule_eq_iff, bot_coeSubmodule] @[simp] theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 := mem_singleton_iff #align lie_submodule.mem_bot LieSubmodule.mem_bot instance : Top (LieSubmodule R L M) := ⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩ @[simp] theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ := rfl #align lie_submodule.top_coe LieSubmodule.top_coe @[simp] theorem top_coeSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ := rfl #align lie_submodule.top_coe_submodule LieSubmodule.top_coeSubmodule @[simp] theorem coeSubmodule_eq_top_iff : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by rw [← coe_toSubmodule_eq_iff, top_coeSubmodule] @[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} : (⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by rw [← coe_toSubmodule_eq_iff, top_coeSubmodule] @[simp] theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) := mem_univ x #align lie_submodule.mem_top LieSubmodule.mem_top instance : Inf (LieSubmodule R L M) := ⟨fun N N' ↦ { (N ⊓ N' : Submodule R M) with lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩ instance : InfSet (LieSubmodule R L M) := ⟨fun S ↦ { toSubmodule := sInf {(s : Submodule R M) | s ∈ S} lie_mem := fun {x m} h ↦ by simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq, forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢ intro N hN; apply N.lie_mem (h N hN) }⟩ @[simp] theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' := rfl #align lie_submodule.inf_coe LieSubmodule.inf_coe @[norm_cast, simp] theorem inf_coe_toSubmodule : (↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) := rfl #align lie_submodule.inf_coe_to_submodule LieSubmodule.inf_coe_toSubmodule @[simp] theorem sInf_coe_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} := rfl #align lie_submodule.Inf_coe_to_submodule LieSubmodule.sInf_coe_toSubmodule theorem sInf_coe_toSubmodule' (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by rw [sInf_coe_toSubmodule, ← Set.image, sInf_image] @[simp] theorem iInf_coe_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by rw [iInf, sInf_coe_toSubmodule]; ext; simp @[simp] theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by rw [← LieSubmodule.coe_toSubmodule, sInf_coe_toSubmodule, Submodule.sInf_coe] ext m simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp, and_imp, SetLike.mem_coe, mem_coeSubmodule] #align lie_submodule.Inf_coe LieSubmodule.sInf_coe @[simp] theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq'] @[simp] theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl instance : Sup (LieSubmodule R L M) where sup N N' := { toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M) lie_mem := by rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)) change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M) rw [Submodule.mem_sup] at hm ⊢ obtain ⟨y, hy, z, hz, rfl⟩ := hm exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ } instance : SupSet (LieSubmodule R L M) where sSup S := { toSubmodule := sSup {(p : Submodule R M) | p ∈ S} lie_mem := by intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S}) change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S} obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm clear hm classical induction' s using Finset.induction_on with q t hqt ih generalizing m · replace hsm : m = 0 := by simpa using hsm simp [hsm] · rw [Finset.iSup_insert] at hsm obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm rw [lie_add] refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu) obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t) suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm') exact le_sSup ⟨p, hp, rfl⟩ } @[norm_cast, simp] theorem sup_coe_toSubmodule : (↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by rfl #align lie_submodule.sup_coe_to_submodule LieSubmodule.sup_coe_toSubmodule @[simp] theorem sSup_coe_toSubmodule (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} := rfl theorem sSup_coe_toSubmodule' (S : Set (LieSubmodule R L M)) : (↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by rw [sSup_coe_toSubmodule, ← Set.image, sSup_image] @[simp] theorem iSup_coe_toSubmodule {ι} (p : ι → LieSubmodule R L M) : (↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by rw [iSup, sSup_coe_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup] /-- The set of Lie submodules of a Lie module form a complete lattice. -/ instance : CompleteLattice (LieSubmodule R L M) := { coeSubmodule_injective.completeLattice toSubmodule sup_coe_toSubmodule inf_coe_toSubmodule sSup_coe_toSubmodule' sInf_coe_toSubmodule' rfl rfl with toPartialOrder := SetLike.instPartialOrder } theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) : b ∈ ⨆ i, N i := (le_iSup N i) h lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {C : M → Prop} {x : M} (hx : x ∈ ⨆ i, N i) (hN : ∀ i, ∀ y ∈ N i, C y) (h0 : C 0) (hadd : ∀ y z, C y → C z → C (y + z)) : C x := by rw [← LieSubmodule.mem_coeSubmodule, LieSubmodule.iSup_coe_toSubmodule] at hx exact Submodule.iSup_induction (C := C) (fun i ↦ (N i : Submodule R M)) hx hN h0 hadd @[elab_as_elim] theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {C : (x : M) → (x ∈ ⨆ i, N i) → Prop} (hN : ∀ (i) (x) (hx : x ∈ N i), C x (mem_iSup_of_mem i hx)) (h0 : C 0 (zero_mem _)) (hadd : ∀ x y hx hy, C x hx → C y hy → C (x + y) (add_mem ‹_› ‹_›)) {x : M} (hx : x ∈ ⨆ i, N i) : C x hx := by refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : C x hx) => hc refine iSup_induction N (C := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), C x hx) hx (fun i x hx => ?_) ?_ fun x y => ?_ · exact ⟨_, hN _ _ hx⟩ · exact ⟨_, h0⟩ · rintro ⟨_, Cx⟩ ⟨_, Cy⟩ exact ⟨_, hadd _ _ _ _ Cx Cy⟩ theorem disjoint_iff_coe_toSubmodule : Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := by rw [disjoint_iff, disjoint_iff, ← coe_toSubmodule_eq_iff, inf_coe_toSubmodule, bot_coeSubmodule, ← disjoint_iff] theorem codisjoint_iff_coe_toSubmodule : Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) := by rw [codisjoint_iff, codisjoint_iff, ← coe_toSubmodule_eq_iff, sup_coe_toSubmodule, top_coeSubmodule, ← codisjoint_iff] theorem isCompl_iff_coe_toSubmodule : IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := by simp only [isCompl_iff, disjoint_iff_coe_toSubmodule, codisjoint_iff_coe_toSubmodule] theorem independent_iff_coe_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} : CompleteLattice.Independent N ↔ CompleteLattice.Independent fun i ↦ (N i : Submodule R M) := by simp [CompleteLattice.independent_def, disjoint_iff_coe_toSubmodule] theorem iSup_eq_top_iff_coe_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} : ⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := by rw [← iSup_coe_toSubmodule, ← top_coeSubmodule (L := L), coe_toSubmodule_eq_iff] instance : Add (LieSubmodule R L M) where add := Sup.sup instance : Zero (LieSubmodule R L M) where zero := ⊥ instance : AddCommMonoid (LieSubmodule R L M) where add_assoc := sup_assoc zero_add := bot_sup_eq add_zero := sup_bot_eq add_comm := sup_comm nsmul := nsmulRec @[simp] theorem add_eq_sup : N + N' = N ⊔ N' := rfl #align lie_submodule.add_eq_sup LieSubmodule.add_eq_sup @[simp] theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by rw [← mem_coeSubmodule, ← mem_coeSubmodule, ← mem_coeSubmodule, inf_coe_toSubmodule, Submodule.mem_inf] #align lie_submodule.mem_inf LieSubmodule.mem_inf theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by rw [← mem_coeSubmodule, sup_coe_toSubmodule, Submodule.mem_sup]; exact Iff.rfl #align lie_submodule.mem_sup LieSubmodule.mem_sup nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl #align lie_submodule.eq_bot_iff LieSubmodule.eq_bot_iff instance subsingleton_of_bot : Subsingleton (LieSubmodule R L ↑(⊥ : LieSubmodule R L M)) := by apply subsingleton_of_bot_eq_top ext ⟨x, hx⟩; change x ∈ ⊥ at hx; rw [Submodule.mem_bot] at hx; subst hx simp only [true_iff_iff, eq_self_iff_true, Submodule.mk_eq_zero, LieSubmodule.mem_bot, mem_top] #align lie_submodule.subsingleton_of_bot LieSubmodule.subsingleton_of_bot instance : IsModularLattice (LieSubmodule R L M) where sup_inf_le_assoc_of_le _ _ := by simp only [← coeSubmodule_le_coeSubmodule, sup_coe_toSubmodule, inf_coe_toSubmodule] exact IsModularLattice.sup_inf_le_assoc_of_le _ variable (R L M) /-- The natural functor that forgets the action of `L` as an order embedding. -/ @[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M := { toFun := (↑) inj' := coeSubmodule_injective map_rel_iff' := Iff.rfl } theorem wellFounded_of_noetherian [IsNoetherian R M] : WellFounded ((· > ·) : LieSubmodule R L M → LieSubmodule R L M → Prop) := RelHomClass.wellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding <| isNoetherian_iff_wellFounded.mp inferInstance #align lie_submodule.well_founded_of_noetherian LieSubmodule.wellFounded_of_noetherian theorem wellFounded_of_isArtinian [IsArtinian R M] : WellFounded ((· < ·) : LieSubmodule R L M → LieSubmodule R L M → Prop) := RelHomClass.wellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding <| IsArtinian.wellFounded_submodule_lt R M instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) := isAtomic_of_orderBot_wellFounded_lt <| wellFounded_of_isArtinian R L M @[simp] theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M := have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← coe_toSubmodule_eq_iff, top_coeSubmodule, bot_coeSubmodule] h.trans <| Submodule.subsingleton_iff R #align lie_submodule.subsingleton_iff LieSubmodule.subsingleton_iff @[simp] theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M := not_iff_not.mp ((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans not_nontrivial_iff_subsingleton.symm) #align lie_submodule.nontrivial_iff LieSubmodule.nontrivial_iff instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) := (nontrivial_iff R L M).mpr ‹_› theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by constructor <;> contrapose! · rintro rfl ⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩ simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂ · rw [not_nontrivial_iff_subsingleton, LieSubmodule.eq_bot_iff] rintro ⟨h⟩ m hm simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩ #align lie_submodule.nontrivial_iff_ne_bot LieSubmodule.nontrivial_iff_ne_bot variable {R L M} section InclusionMaps /-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/ def incl : N →ₗ⁅R,L⁆ M := { Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl } #align lie_submodule.incl LieSubmodule.incl @[simp] theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype := rfl #align lie_submodule.incl_coe LieSubmodule.incl_coe @[simp] theorem incl_apply (m : N) : N.incl m = m := rfl #align lie_submodule.incl_apply LieSubmodule.incl_apply theorem incl_eq_val : (N.incl : N → M) = Subtype.val := rfl #align lie_submodule.incl_eq_val LieSubmodule.incl_eq_val theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective variable {N N'} (h : N ≤ N') /-- Given two nested Lie submodules `N ⊆ N'`, the inclusion `N ↪ N'` is a morphism of Lie modules. -/ def inclusion : N →ₗ⁅R,L⁆ N' where __ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h) map_lie' := rfl #align lie_submodule.hom_of_le LieSubmodule.inclusion @[simp] theorem coe_inclusion (m : N) : (inclusion h m : M) = m := rfl #align lie_submodule.coe_hom_of_le LieSubmodule.coe_inclusion theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.2⟩ := rfl #align lie_submodule.hom_of_le_apply LieSubmodule.inclusion_apply theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe] #align lie_submodule.hom_of_le_injective LieSubmodule.inclusion_injective end InclusionMaps section LieSpan variable (R L) (s : Set M) /-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/ def lieSpan : LieSubmodule R L M := sInf { N | s ⊆ N } #align lie_submodule.lie_span LieSubmodule.lieSpan variable {R L s} theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by change x ∈ (lieSpan R L s : Set M) ↔ _; erw [sInf_coe]; exact mem_iInter₂ #align lie_submodule.mem_lie_span LieSubmodule.mem_lieSpan theorem subset_lieSpan : s ⊆ lieSpan R L s := by intro m hm erw [mem_lieSpan] intro N hN exact hN hm #align lie_submodule.subset_lie_span LieSubmodule.subset_lieSpan theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by rw [Submodule.span_le] apply subset_lieSpan #align lie_submodule.submodule_span_le_lie_span LieSubmodule.submodule_span_le_lieSpan @[simp] theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by constructor · exact Subset.trans subset_lieSpan · intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs #align lie_submodule.lie_span_le LieSubmodule.lieSpan_le theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by rw [lieSpan_le] exact Subset.trans h subset_lieSpan #align lie_submodule.lie_span_mono LieSubmodule.lieSpan_mono theorem lieSpan_eq : lieSpan R L (N : Set M) = N := le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan #align lie_submodule.lie_span_eq LieSubmodule.lieSpan_eq theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} : (lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by rw [p.exists_lieSubmodule_coe_eq_iff L]; constructor <;> intro h · intro x m hm; rw [← h, mem_coeSubmodule]; exact lie_mem _ (subset_lieSpan hm) · rw [← coe_toSubmodule_mk p @h, coe_toSubmodule, coe_toSubmodule_eq_iff, lieSpan_eq] #align lie_submodule.coe_lie_span_submodule_eq_iff LieSubmodule.coe_lieSpan_submodule_eq_iff variable (R L M) /-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/ protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) where choice s _ := lieSpan R L s gc _ _ := lieSpan_le le_l_u _ := subset_lieSpan choice_eq _ _ := rfl #align lie_submodule.gi LieSubmodule.gi @[simp] theorem span_empty : lieSpan R L (∅ : Set M) = ⊥ := (LieSubmodule.gi R L M).gc.l_bot #align lie_submodule.span_empty LieSubmodule.span_empty @[simp] theorem span_univ : lieSpan R L (Set.univ : Set M) = ⊤ := eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan #align lie_submodule.span_univ LieSubmodule.span_univ theorem lieSpan_eq_bot_iff : lieSpan R L s = ⊥ ↔ ∀ m ∈ s, m = (0 : M) := by rw [_root_.eq_bot_iff, lieSpan_le, bot_coe, subset_singleton_iff] #align lie_submodule.lie_span_eq_bot_iff LieSubmodule.lieSpan_eq_bot_iff variable {M} theorem span_union (s t : Set M) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t := (LieSubmodule.gi R L M).gc.l_sup #align lie_submodule.span_union LieSubmodule.span_union theorem span_iUnion {ι} (s : ι → Set M) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) := (LieSubmodule.gi R L M).gc.l_iSup #align lie_submodule.span_Union LieSubmodule.span_iUnion lemma isCompactElement_lieSpan_singleton (m : M) : CompleteLattice.IsCompactElement (lieSpan R L {m}) := by rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le] intro s hne hdir hsup replace hsup : m ∈ (↑(sSup s) : Set M) := (SetLike.le_def.mp hsup) (subset_lieSpan rfl) suffices (↑(sSup s) : Set M) = ⋃ N ∈ s, ↑N by obtain ⟨N : LieSubmodule R L M, hN : N ∈ s, hN' : m ∈ N⟩ := by simp_rw [this, Set.mem_iUnion, SetLike.mem_coe, exists_prop] at hsup; assumption exact ⟨N, hN, by simpa⟩ replace hne : Nonempty s := Set.nonempty_coe_sort.mpr hne have := Submodule.coe_iSup_of_directed _ hdir.directed_val simp_rw [← iSup_coe_toSubmodule, Set.iUnion_coe_set, coe_toSubmodule] at this rw [← this, SetLike.coe_set_eq, sSup_eq_iSup, iSup_subtype] @[simp] lemma sSup_image_lieSpan_singleton : sSup ((fun x ↦ lieSpan R L {x}) '' N) = N := by refine le_antisymm (sSup_le <| by simp) ?_ simp_rw [← coeSubmodule_le_coeSubmodule, sSup_coe_toSubmodule, Set.mem_image, SetLike.mem_coe] refine fun m hm ↦ Submodule.mem_sSup.mpr fun N' hN' ↦ ?_ replace hN' : ∀ m ∈ N, lieSpan R L {m} ≤ N' := by simpa using hN' exact hN' _ hm (subset_lieSpan rfl) instance instIsCompactlyGenerated : IsCompactlyGenerated (LieSubmodule R L M) := ⟨fun N ↦ ⟨(fun x ↦ lieSpan R L {x}) '' N, fun _ ⟨m, _, hm⟩ ↦ hm ▸ isCompactElement_lieSpan_singleton R L m, N.sSup_image_lieSpan_singleton⟩⟩ end LieSpan end LatticeStructure end LieSubmodule section LieSubmoduleMapAndComap variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] [LieModule R L M'] namespace LieSubmodule variable (f : M →ₗ⁅R,L⁆ M') (N N₂ : LieSubmodule R L M) (N' : LieSubmodule R L M') /-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules of `M'`. -/ def map : LieSubmodule R L M' := { (N : Submodule R M).map (f : M →ₗ[R] M') with lie_mem := fun {x m'} h ↦ by rcases h with ⟨m, hm, hfm⟩; use ⁅x, m⁆; constructor · apply N.lie_mem hm · norm_cast at hfm; simp [hfm] } #align lie_submodule.map LieSubmodule.map @[simp] theorem coe_map : (N.map f : Set M') = f '' N := rfl @[simp] theorem coeSubmodule_map : (N.map f : Submodule R M') = (N : Submodule R M).map (f : M →ₗ[R] M') := rfl #align lie_submodule.coe_submodule_map LieSubmodule.coeSubmodule_map /-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of `M`. -/ def comap : LieSubmodule R L M := { (N' : Submodule R M').comap (f : M →ₗ[R] M') with lie_mem := fun {x m} h ↦ by suffices ⁅x, f m⁆ ∈ N' by simp [this] apply N'.lie_mem h } #align lie_submodule.comap LieSubmodule.comap @[simp] theorem coeSubmodule_comap : (N'.comap f : Submodule R M) = (N' : Submodule R M').comap (f : M →ₗ[R] M') := rfl #align lie_submodule.coe_submodule_comap LieSubmodule.coeSubmodule_comap variable {f N N₂ N'} theorem map_le_iff_le_comap : map f N ≤ N' ↔ N ≤ comap f N' := Set.image_subset_iff #align lie_submodule.map_le_iff_le_comap LieSubmodule.map_le_iff_le_comap variable (f) theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap #align lie_submodule.gc_map_comap LieSubmodule.gc_map_comap variable {f} theorem map_inf_le : (N ⊓ N₂).map f ≤ N.map f ⊓ N₂.map f := Set.image_inter_subset f N N₂ theorem map_inf (hf : Function.Injective f) : (N ⊓ N₂).map f = N.map f ⊓ N₂.map f := SetLike.coe_injective <| Set.image_inter hf @[simp] theorem map_sup : (N ⊔ N₂).map f = N.map f ⊔ N₂.map f := (gc_map_comap f).l_sup #align lie_submodule.map_sup LieSubmodule.map_sup @[simp] theorem comap_inf {N₂' : LieSubmodule R L M'} : (N' ⊓ N₂').comap f = N'.comap f ⊓ N₂'.comap f := rfl @[simp] theorem map_iSup {ι : Sort*} (N : ι → LieSubmodule R L M) : (⨆ i, N i).map f = ⨆ i, (N i).map f := (gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup @[simp] theorem mem_map (m' : M') : m' ∈ N.map f ↔ ∃ m, m ∈ N ∧ f m = m' := Submodule.mem_map #align lie_submodule.mem_map LieSubmodule.mem_map theorem mem_map_of_mem {m : M} (h : m ∈ N) : f m ∈ N.map f := Set.mem_image_of_mem _ h @[simp] theorem mem_comap {m : M} : m ∈ comap f N' ↔ f m ∈ N' := Iff.rfl #align lie_submodule.mem_comap LieSubmodule.mem_comap theorem comap_incl_eq_top : N₂.comap N.incl = ⊤ ↔ N ≤ N₂ := by rw [← LieSubmodule.coe_toSubmodule_eq_iff, LieSubmodule.coeSubmodule_comap, LieSubmodule.incl_coe, LieSubmodule.top_coeSubmodule, Submodule.comap_subtype_eq_top, coeSubmodule_le_coeSubmodule] #align lie_submodule.comap_incl_eq_top LieSubmodule.comap_incl_eq_top theorem comap_incl_eq_bot : N₂.comap N.incl = ⊥ ↔ N ⊓ N₂ = ⊥ := by simp only [← LieSubmodule.coe_toSubmodule_eq_iff, LieSubmodule.coeSubmodule_comap, LieSubmodule.incl_coe, LieSubmodule.bot_coeSubmodule, ← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff, inf_coe_toSubmodule] #align lie_submodule.comap_incl_eq_bot LieSubmodule.comap_incl_eq_bot @[mono] theorem map_mono (h : N ≤ N₂) : N.map f ≤ N₂.map f := Set.image_subset _ h theorem map_comp {M'' : Type*} [AddCommGroup M''] [Module R M''] [LieRingModule L M''] {g : M' →ₗ⁅R,L⁆ M''} : N.map (g.comp f) = (N.map f).map g := SetLike.coe_injective <| by simp only [← Set.image_comp, coe_map, LinearMap.coe_comp, LieModuleHom.coe_comp] @[simp] theorem map_id : N.map LieModuleHom.id = N := by ext; simp @[simp] theorem map_bot : (⊥ : LieSubmodule R L M).map f = ⊥ := by ext m; simp [eq_comm] lemma map_le_map_iff (hf : Function.Injective f) : N.map f ≤ N₂.map f ↔ N ≤ N₂ := Set.image_subset_image_iff hf lemma map_injective_of_injective (hf : Function.Injective f) : Function.Injective (map f) := fun {N N'} h ↦ SetLike.coe_injective <| hf.image_injective <| by simp only [← coe_map, h] /-- An injective morphism of Lie modules embeds the lattice of submodules of the domain into that of the target. -/ @[simps] def mapOrderEmbedding {f : M →ₗ⁅R,L⁆ M'} (hf : Function.Injective f) : LieSubmodule R L M ↪o LieSubmodule R L M' where toFun := LieSubmodule.map f inj' := map_injective_of_injective hf map_rel_iff' := Set.image_subset_image_iff hf variable (N) in /-- For an injective morphism of Lie modules, any Lie submodule is equivalent to its image. -/ noncomputable def equivMapOfInjective (hf : Function.Injective f) : N ≃ₗ⁅R,L⁆ N.map f := { Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N with -- Note: #8386 had to specify `invFun` explicitly this way, otherwise we'd get a type mismatch invFun := by exact DFunLike.coe (Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N).symm map_lie' := by rintro x ⟨m, hm : m ∈ N⟩; ext; exact f.map_lie x m } /-- An equivalence of Lie modules yields an order-preserving equivalence of their lattices of Lie Submodules. -/ @[simps] def orderIsoMapComap (e : M ≃ₗ⁅R,L⁆ M') : LieSubmodule R L M ≃o LieSubmodule R L M' where toFun := map e invFun := comap e left_inv := fun N ↦ by ext; simp right_inv := fun N ↦ by ext; simp [e.apply_eq_iff_eq_symm_apply] map_rel_iff' := fun {N N'} ↦ Set.image_subset_image_iff e.injective end LieSubmodule namespace LieIdeal variable (f : L →ₗ⁅R⁆ L') (I I₂ : LieIdeal R L) (J : LieIdeal R L') @[simp] theorem top_coe_lieSubalgebra : ((⊤ : LieIdeal R L) : LieSubalgebra R L) = ⊤ := rfl #align lie_ideal.top_coe_lie_subalgebra LieIdeal.top_coe_lieSubalgebra /-- A morphism of Lie algebras `f : L → L'` pushes forward Lie ideals of `L` to Lie ideals of `L'`. Note that unlike `LieSubmodule.map`, we must take the `lieSpan` of the image. Mathematically this is because although `f` makes `L'` into a Lie module over `L`, in general the `L` submodules of `L'` are not the same as the ideals of `L'`. -/ def map : LieIdeal R L' := LieSubmodule.lieSpan R L' <| (I : Submodule R L).map (f : L →ₗ[R] L') #align lie_ideal.map LieIdeal.map /-- A morphism of Lie algebras `f : L → L'` pulls back Lie ideals of `L'` to Lie ideals of `L`. Note that `f` makes `L'` into a Lie module over `L` (turning `f` into a morphism of Lie modules) and so this is a special case of `LieSubmodule.comap` but we do not exploit this fact. -/ def comap : LieIdeal R L := { (J : Submodule R L').comap (f : L →ₗ[R] L') with lie_mem := fun {x y} h ↦ by suffices ⁅f x, f y⁆ ∈ J by simp only [AddSubsemigroup.mem_carrier, AddSubmonoid.mem_toSubsemigroup, Submodule.mem_toAddSubmonoid, Submodule.mem_comap, LieHom.coe_toLinearMap, LieHom.map_lie, LieSubalgebra.mem_coe_submodule] exact this apply J.lie_mem h } #align lie_ideal.comap LieIdeal.comap @[simp] theorem map_coeSubmodule (h : ↑(map f I) = f '' I) : LieSubmodule.toSubmodule (map f I) = (LieSubmodule.toSubmodule I).map (f : L →ₗ[R] L') := by rw [SetLike.ext'_iff, LieSubmodule.coe_toSubmodule, h, Submodule.map_coe]; rfl #align lie_ideal.map_coe_submodule LieIdeal.map_coeSubmodule @[simp] theorem comap_coeSubmodule : (LieSubmodule.toSubmodule (comap f J)) = (LieSubmodule.toSubmodule J).comap (f : L →ₗ[R] L') := rfl #align lie_ideal.comap_coe_submodule LieIdeal.comap_coeSubmodule theorem map_le : map f I ≤ J ↔ f '' I ⊆ J := LieSubmodule.lieSpan_le #align lie_ideal.map_le LieIdeal.map_le variable {f I I₂ J} theorem mem_map {x : L} (hx : x ∈ I) : f x ∈ map f I := by apply LieSubmodule.subset_lieSpan use x exact ⟨hx, rfl⟩ #align lie_ideal.mem_map LieIdeal.mem_map @[simp] theorem mem_comap {x : L} : x ∈ comap f J ↔ f x ∈ J := Iff.rfl #align lie_ideal.mem_comap LieIdeal.mem_comap theorem map_le_iff_le_comap : map f I ≤ J ↔ I ≤ comap f J := by rw [map_le] exact Set.image_subset_iff #align lie_ideal.map_le_iff_le_comap LieIdeal.map_le_iff_le_comap variable (f) theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap #align lie_ideal.gc_map_comap LieIdeal.gc_map_comap variable {f} @[simp] theorem map_sup : (I ⊔ I₂).map f = I.map f ⊔ I₂.map f := (gc_map_comap f).l_sup #align lie_ideal.map_sup LieIdeal.map_sup theorem map_comap_le : map f (comap f J) ≤ J := by rw [map_le_iff_le_comap] #align lie_ideal.map_comap_le LieIdeal.map_comap_le /-- See also `LieIdeal.map_comap_eq`. -/ theorem comap_map_le : I ≤ comap f (map f I) := by rw [← map_le_iff_le_comap] #align lie_ideal.comap_map_le LieIdeal.comap_map_le @[mono] theorem map_mono : Monotone (map f) := fun I₁ I₂ h ↦ by rw [SetLike.le_def] at h apply LieSubmodule.lieSpan_mono (Set.image_subset (⇑f) h) #align lie_ideal.map_mono LieIdeal.map_mono @[mono] theorem comap_mono : Monotone (comap f) := fun J₁ J₂ h ↦ by rw [← SetLike.coe_subset_coe] at h ⊢ dsimp only [SetLike.coe] exact Set.preimage_mono h #align lie_ideal.comap_mono LieIdeal.comap_mono
Mathlib/Algebra/Lie/Submodule.lean
1,079
1,082
theorem map_of_image (h : f '' I = J) : I.map f = J := by
apply le_antisymm · erw [LieSubmodule.lieSpan_le, Submodule.map_coe, h] · rw [← SetLike.coe_subset_coe, ← h]; exact LieSubmodule.subset_lieSpan
/- Copyright (c) 2022 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.Algebra.Polynomial.Mirror import Mathlib.Analysis.Complex.Polynomial #align_import data.polynomial.unit_trinomial from "leanprover-community/mathlib"@"302eab4f46abb63de520828de78c04cb0f9b5836" /-! # Unit Trinomials This file defines irreducible trinomials and proves an irreducibility criterion. ## Main definitions - `Polynomial.IsUnitTrinomial` ## Main results - `Polynomial.IsUnitTrinomial.irreducible_of_coprime`: An irreducibility criterion for unit trinomials. -/ namespace Polynomial open scoped Polynomial open Finset section Semiring variable {R : Type*} [Semiring R] (k m n : ℕ) (u v w : R) /-- Shorthand for a trinomial -/ noncomputable def trinomial := C u * X ^ k + C v * X ^ m + C w * X ^ n #align polynomial.trinomial Polynomial.trinomial theorem trinomial_def : trinomial k m n u v w = C u * X ^ k + C v * X ^ m + C w * X ^ n := rfl #align polynomial.trinomial_def Polynomial.trinomial_def variable {k m n u v w} theorem trinomial_leading_coeff' (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff n = w := by rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_neg (hkm.trans hmn).ne', if_neg hmn.ne', if_pos rfl, zero_add, zero_add] #align polynomial.trinomial_leading_coeff' Polynomial.trinomial_leading_coeff' theorem trinomial_middle_coeff (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff m = v := by rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_neg hkm.ne', if_pos rfl, if_neg hmn.ne, zero_add, add_zero] #align polynomial.trinomial_middle_coeff Polynomial.trinomial_middle_coeff
Mathlib/Algebra/Polynomial/UnitTrinomial.lean
61
64
theorem trinomial_trailing_coeff' (hkm : k < m) (hmn : m < n) : (trinomial k m n u v w).coeff k = u := by
rw [trinomial_def, coeff_add, coeff_add, coeff_C_mul_X_pow, coeff_C_mul_X_pow, coeff_C_mul_X_pow, if_pos rfl, if_neg hkm.ne, if_neg (hkm.trans hmn).ne, add_zero, add_zero]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yaël Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs #align_import data.finset.locally_finite from "leanprover-community/mathlib"@"442a83d738cb208d3600056c489be16900ba701d" /-! # 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 assert_not_exists Finset.sum open Function OrderDual open FinsetInterval variable {ι α : Type*} namespace Finset section Preorder variable [Preorder α] section LocallyFiniteOrder variable [LocallyFiniteOrder α] {a a₁ a₂ b b₁ b₂ c x : α} @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] #align finset.nonempty_Icc Finset.nonempty_Icc @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] #align finset.nonempty_Ico Finset.nonempty_Ico @[simp, aesop safe apply (rule_sets := [finsetNonempty])] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] #align finset.nonempty_Ioc Finset.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] #align finset.nonempty_Ioo Finset.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] #align finset.Icc_eq_empty_iff Finset.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] #align finset.Ico_eq_empty_iff Finset.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] #align finset.Ioc_eq_empty_iff Finset.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] #align finset.Ioo_eq_empty_iff Finset.Ioo_eq_empty_iff alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff #align finset.Icc_eq_empty Finset.Icc_eq_empty alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff #align finset.Ico_eq_empty Finset.Ico_eq_empty alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff #align finset.Ioc_eq_empty Finset.Ioc_eq_empty @[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) #align finset.Ioo_eq_empty Finset.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align finset.Icc_eq_empty_of_lt Finset.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align finset.Ico_eq_empty_of_le Finset.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align finset.Ioc_eq_empty_of_le Finset.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align finset.Ioo_eq_empty_of_le Finset.Ioo_eq_empty_of_le -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and_iff, le_rfl] #align finset.left_mem_Icc Finset.left_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and_iff, le_refl] #align finset.left_mem_Ico Finset.left_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true_iff, le_rfl] #align finset.right_mem_Icc Finset.right_mem_Icc -- porting note (#10618): simp can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true_iff, le_rfl] #align finset.right_mem_Ioc Finset.right_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioc : a ∉ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 #align finset.left_not_mem_Ioc Finset.left_not_mem_Ioc -- porting note (#10618): simp can prove this -- @[simp] theorem left_not_mem_Ioo : a ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 #align finset.left_not_mem_Ioo Finset.left_not_mem_Ioo -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ico : b ∉ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 #align finset.right_not_mem_Ico Finset.right_not_mem_Ico -- porting note (#10618): simp can prove this -- @[simp] theorem right_not_mem_Ioo : b ∉ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 #align finset.right_not_mem_Ioo Finset.right_not_mem_Ioo 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 #align finset.Icc_subset_Icc Finset.Icc_subset_Icc 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 #align finset.Ico_subset_Ico Finset.Ico_subset_Ico 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 #align finset.Ioc_subset_Ioc Finset.Ioc_subset_Ioc 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 #align finset.Ioo_subset_Ioo Finset.Ioo_subset_Ioo theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align finset.Icc_subset_Icc_left Finset.Icc_subset_Icc_left theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align finset.Ico_subset_Ico_left Finset.Ico_subset_Ico_left theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align finset.Ioc_subset_Ioc_left Finset.Ioc_subset_Ioc_left theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align finset.Ioo_subset_Ioo_left Finset.Ioo_subset_Ioo_left theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align finset.Icc_subset_Icc_right Finset.Icc_subset_Icc_right theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align finset.Ico_subset_Ico_right Finset.Ico_subset_Ico_right theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align finset.Ioc_subset_Ioc_right Finset.Ioc_subset_Ioc_right theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align finset.Ioo_subset_Ioo_right Finset.Ioo_subset_Ioo_right 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 #align finset.Ico_subset_Ioo_left Finset.Ico_subset_Ioo_left 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 #align finset.Ioc_subset_Ioo_right Finset.Ioc_subset_Ioo_right 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 #align finset.Icc_subset_Ico_right Finset.Icc_subset_Ico_right 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 #align finset.Ioo_subset_Ico_self Finset.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 #align finset.Ioo_subset_Ioc_self Finset.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 #align finset.Ico_subset_Icc_self Finset.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 #align finset.Ioc_subset_Icc_self Finset.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self #align finset.Ioo_subset_Icc_self Finset.Ioo_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₁] #align finset.Icc_subset_Icc_iff Finset.Icc_subset_Icc_iff 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₁] #align finset.Icc_subset_Ioo_iff Finset.Icc_subset_Ioo_iff 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₁] #align finset.Icc_subset_Ico_iff Finset.Icc_subset_Ico_iff 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 #align finset.Icc_subset_Ioc_iff Finset.Icc_subset_Ioc_iff --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 #align finset.Icc_ssubset_Icc_left Finset.Icc_ssubset_Icc_left 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 #align finset.Icc_ssubset_Icc_right Finset.Icc_ssubset_Icc_right variable (a) -- porting note (#10618): simp can prove this -- @[simp] theorem Ico_self : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align finset.Ico_self Finset.Ico_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioc_self : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align finset.Ioc_self Finset.Ioc_self -- porting note (#10618): simp can prove this -- @[simp] theorem Ioo_self : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align finset.Ioo_self Finset.Ioo_self 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⟩ #align set.fintype_of_mem_bounds Set.fintypeOfMemBounds section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (· < c)] (hca : c ≤ a) : (Ico a b).filter (· < c) = ∅ := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt #align finset.Ico_filter_lt_of_le_left Finset.Ico_filter_lt_of_le_left theorem Ico_filter_lt_of_right_le [DecidablePred (· < c)] (hbc : b ≤ c) : (Ico a b).filter (· < c) = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc #align finset.Ico_filter_lt_of_right_le Finset.Ico_filter_lt_of_right_le theorem Ico_filter_lt_of_le_right [DecidablePred (· < c)] (hcb : c ≤ b) : (Ico a b).filter (· < 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 #align finset.Ico_filter_lt_of_le_right Finset.Ico_filter_lt_of_le_right theorem Ico_filter_le_of_le_left {a b c : α} [DecidablePred (c ≤ ·)] (hca : c ≤ a) : (Ico a b).filter (c ≤ ·) = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 #align finset.Ico_filter_le_of_le_left Finset.Ico_filter_le_of_le_left theorem Ico_filter_le_of_right_le {a b : α} [DecidablePred (b ≤ ·)] : (Ico a b).filter (b ≤ ·) = ∅ := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le #align finset.Ico_filter_le_of_right_le Finset.Ico_filter_le_of_right_le theorem Ico_filter_le_of_left_le {a b c : α} [DecidablePred (c ≤ ·)] (hac : a ≤ c) : (Ico a b).filter (c ≤ ·) = 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 #align finset.Ico_filter_le_of_left_le Finset.Ico_filter_le_of_left_le theorem Icc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Icc a b).filter (· < c) = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h #align finset.Icc_filter_lt_of_lt_right Finset.Icc_filter_lt_of_lt_right theorem Ioc_filter_lt_of_lt_right {a b c : α} [DecidablePred (· < c)] (h : b < c) : (Ioc a b).filter (· < c) = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h #align finset.Ioc_filter_lt_of_lt_right Finset.Ioc_filter_lt_of_lt_right theorem Iic_filter_lt_of_lt_right {α} [Preorder α] [LocallyFiniteOrderBot α] {a c : α} [DecidablePred (· < c)] (h : a < c) : (Iic a).filter (· < c) = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h #align finset.Iic_filter_lt_of_lt_right Finset.Iic_filter_lt_of_lt_right variable (a b) [Fintype α] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : (univ.filter fun j => a < j ∧ j < b) = Ioo a b := by ext simp #align finset.filter_lt_lt_eq_Ioo Finset.filter_lt_lt_eq_Ioo theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≤ b] : (univ.filter fun j => a < j ∧ j ≤ b) = Ioc a b := by ext simp #align finset.filter_lt_le_eq_Ioc Finset.filter_lt_le_eq_Ioc theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≤ j ∧ j < b] : (univ.filter fun j => a ≤ j ∧ j < b) = Ico a b := by ext simp #align finset.filter_le_lt_eq_Ico Finset.filter_le_lt_eq_Ico theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≤ j ∧ j ≤ b] : (univ.filter fun j => a ≤ j ∧ j ≤ b) = Icc a b := by ext simp #align finset.filter_le_le_eq_Icc Finset.filter_le_le_eq_Icc end Filter section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ioi : (Ioi a).Nonempty ↔ ¬ IsMax a := by simp [Finset.Nonempty] theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self #align finset.Icc_subset_Ici_self Finset.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self #align finset.Ico_subset_Ici_self Finset.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self #align finset.Ioc_subset_Ioi_self Finset.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self #align finset.Ioo_subset_Ioi_self Finset.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self #align finset.Ioc_subset_Ici_self Finset.Ioc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self #align finset.Ioo_subset_Ici_self Finset.Ioo_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot α] @[simp] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ @[simp] lemma nonempty_Iio : (Iio a).Nonempty ↔ ¬ IsMin a := by simp [Finset.Nonempty] theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self #align finset.Icc_subset_Iic_self Finset.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self #align finset.Ioc_subset_Iic_self Finset.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self #align finset.Ico_subset_Iio_self Finset.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self #align finset.Ioo_subset_Iio_self Finset.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self #align finset.Ico_subset_Iic_self Finset.Ico_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self #align finset.Ioo_subset_Iic_self Finset.Ioo_subset_Iic_self end LocallyFiniteOrderBot end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop α] {a : α} theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self #align finset.Ioi_subset_Ici_self Finset.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 #align bdd_below.finite BddBelow.finite theorem _root_.Set.Infinite.not_bddBelow {s : Set α} : s.Infinite → ¬BddBelow s := mt BddBelow.finite #align set.infinite.not_bdd_below Set.Infinite.not_bddBelow variable [Fintype α] theorem filter_lt_eq_Ioi [DecidablePred (a < ·)] : univ.filter (a < ·) = Ioi a := by ext simp #align finset.filter_lt_eq_Ioi Finset.filter_lt_eq_Ioi theorem filter_le_eq_Ici [DecidablePred (a ≤ ·)] : univ.filter (a ≤ ·) = Ici a := by ext simp #align finset.filter_le_eq_Ici Finset.filter_le_eq_Ici 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 #align finset.Iio_subset_Iic_self Finset.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set α} (hs : BddAbove s) : s.Finite := hs.dual.finite #align bdd_above.finite BddAbove.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set α} : s.Infinite → ¬BddAbove s := mt BddAbove.finite #align set.infinite.not_bdd_above Set.Infinite.not_bddAbove variable [Fintype α] theorem filter_gt_eq_Iio [DecidablePred (· < a)] : univ.filter (· < a) = Iio a := by ext simp #align finset.filter_gt_eq_Iio Finset.filter_gt_eq_Iio theorem filter_ge_eq_Iic [DecidablePred (· ≤ a)] : univ.filter (· ≤ a) = Iic a := by ext simp #align finset.filter_ge_eq_Iic Finset.filter_ge_eq_Iic end LocallyFiniteOrderBot 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 #align finset.disjoint_Ioi_Iio Finset.disjoint_Ioi_Iio 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] #align finset.Icc_self Finset.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] #align finset.Icc_eq_singleton_iff Finset.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 #align finset.Ico_disjoint_Ico_consecutive Finset.Ico_disjoint_Ico_consecutive section DecidableEq variable [DecidableEq α] @[simp] theorem Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] #align finset.Icc_erase_left Finset.Icc_erase_left @[simp] theorem Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] #align finset.Icc_erase_right Finset.Icc_erase_right @[simp] theorem Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] #align finset.Ico_erase_left Finset.Ico_erase_left @[simp] theorem Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] #align finset.Ioc_erase_right Finset.Ioc_erase_right @[simp] theorem Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] #align finset.Icc_diff_both Finset.Icc_diff_both @[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] #align finset.Ico_insert_right Finset.Ico_insert_right @[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] #align finset.Ioc_insert_left Finset.Ioc_insert_left @[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] #align finset.Ioo_insert_left Finset.Ioo_insert_left @[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] #align finset.Ioo_insert_right Finset.Ioo_insert_right @[simp] theorem Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] #align finset.Icc_diff_Ico_self Finset.Icc_diff_Ico_self @[simp] theorem Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] #align finset.Icc_diff_Ioc_self Finset.Icc_diff_Ioc_self @[simp] theorem Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] #align finset.Icc_diff_Ioo_self Finset.Icc_diff_Ioo_self @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] #align finset.Ico_diff_Ioo_self Finset.Ico_diff_Ioo_self @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] #align finset.Ioc_diff_Ioo_self Finset.Ioc_diff_Ioo_self @[simp] theorem Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot #align finset.Ico_inter_Ico_consecutive Finset.Ico_inter_Ico_consecutive end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] #align finset.Icc_eq_cons_Ico Finset.Icc_eq_cons_Ico /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] #align finset.Icc_eq_cons_Ioc Finset.Icc_eq_cons_Ioc /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] #align finset.Ioc_eq_cons_Ioo Finset.Ioc_eq_cons_Ioo /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] #align finset.Ico_eq_cons_Ioo Finset.Ico_eq_cons_Ioo theorem Ico_filter_le_left {a b : α} [DecidablePred (· ≤ a)] (hab : a < b) : ((Ico a b).filter fun x => x ≤ a) = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab #align finset.Ico_filter_le_left Finset.Ico_filter_le_left theorem card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 := by classical by_cases h : a ≤ b · rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] #align finset.card_Ico_eq_card_Icc_sub_one Finset.card_Ico_eq_card_Icc_sub_one theorem card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ #align finset.card_Ioc_eq_card_Icc_sub_one Finset.card_Ioc_eq_card_Icc_sub_one theorem card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 := by classical by_cases h : a < b · rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm · rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] #align finset.card_Ioo_eq_card_Ico_sub_one Finset.card_Ioo_eq_card_Ico_sub_one theorem card_Ioo_eq_card_Ioc_sub_one (a b : α) : (Ioo a b).card = (Ioc a b).card - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ #align finset.card_Ioo_eq_card_Ioc_sub_one Finset.card_Ioo_eq_card_Ioc_sub_one
Mathlib/Order/Interval/Finset/Basic.lean
675
677
theorem card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 := by
rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl
/- 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, Floris van Doorn -/ import Mathlib.Geometry.Manifold.MFDeriv.Defs #align_import geometry.manifold.mfderiv from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Basic properties of the manifold Fréchet derivative In this file, we show various properties of the manifold Fréchet derivative, mimicking the API for Fréchet derivatives. - basic properties of unique differentiability sets - various general lemmas about the manifold Fréchet derivative - deducing differentiability from smoothness, - deriving continuity from differentiability on manifolds, - congruence lemmas for derivatives on manifolds - composition lemmas and the chain rule -/ noncomputable section open scoped Topology Manifold open Set Bundle section DerivativesProperties /-! ### Unique differentiability sets in manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f f₀ f₁ : M → M'} {x : M} {s t : Set M} {g : M' → M''} {u : Set M'} theorem uniqueMDiffWithinAt_univ : UniqueMDiffWithinAt I univ x := by unfold UniqueMDiffWithinAt simp only [preimage_univ, univ_inter] exact I.unique_diff _ (mem_range_self _) #align unique_mdiff_within_at_univ uniqueMDiffWithinAt_univ variable {I} theorem uniqueMDiffWithinAt_iff {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ (extChartAt I x).target) ((extChartAt I x) x) := by apply uniqueDiffWithinAt_congr rw [nhdsWithin_inter, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] #align unique_mdiff_within_at_iff uniqueMDiffWithinAt_iff nonrec theorem UniqueMDiffWithinAt.mono_nhds {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : 𝓝[s] x ≤ 𝓝[t] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds <| by simpa only [← map_extChartAt_nhdsWithin] using Filter.map_mono ht theorem UniqueMDiffWithinAt.mono_of_mem {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds (nhdsWithin_le_iff.2 ht) theorem UniqueMDiffWithinAt.mono (h : UniqueMDiffWithinAt I s x) (st : s ⊆ t) : UniqueMDiffWithinAt I t x := UniqueDiffWithinAt.mono h <| inter_subset_inter (preimage_mono st) (Subset.refl _) #align unique_mdiff_within_at.mono UniqueMDiffWithinAt.mono theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.mono_of_mem (Filter.inter_mem self_mem_nhdsWithin ht) #align unique_mdiff_within_at.inter' UniqueMDiffWithinAt.inter' theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.inter' (nhdsWithin_le_nhds ht) #align unique_mdiff_within_at.inter UniqueMDiffWithinAt.inter theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x := (uniqueMDiffWithinAt_univ I).mono_of_mem <| nhdsWithin_le_nhds <| hs.mem_nhds xs #align is_open.unique_mdiff_within_at IsOpen.uniqueMDiffWithinAt theorem UniqueMDiffOn.inter (hs : UniqueMDiffOn I s) (ht : IsOpen t) : UniqueMDiffOn I (s ∩ t) := fun _x hx => UniqueMDiffWithinAt.inter (hs _ hx.1) (ht.mem_nhds hx.2) #align unique_mdiff_on.inter UniqueMDiffOn.inter theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s := fun _x hx => hs.uniqueMDiffWithinAt hx #align is_open.unique_mdiff_on IsOpen.uniqueMDiffOn theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) := isOpen_univ.uniqueMDiffOn #align unique_mdiff_on_univ uniqueMDiffOn_univ /- We name the typeclass variables related to `SmoothManifoldWithCorners` structure as they are necessary in lemmas mentioning the derivative, but not in lemmas about differentiability, so we want to include them or omit them when necessary. -/ variable [Is : SmoothManifoldWithCorners I M] [I's : SmoothManifoldWithCorners I' M'] [I''s : SmoothManifoldWithCorners I'' M''] {f' f₀' f₁' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} {g' : TangentSpace I' (f x) →L[𝕜] TangentSpace I'' (g (f x))} /-- `UniqueMDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ nonrec theorem UniqueMDiffWithinAt.eq (U : UniqueMDiffWithinAt I s x) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := by -- Porting note: didn't need `convert` because of finding instances by unification convert U.eq h.2 h₁.2 #align unique_mdiff_within_at.eq UniqueMDiffWithinAt.eq theorem UniqueMDiffOn.eq (U : UniqueMDiffOn I s) (hx : x ∈ s) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := UniqueMDiffWithinAt.eq (U _ hx) h h₁ #align unique_mdiff_on.eq UniqueMDiffOn.eq nonrec theorem UniqueMDiffWithinAt.prod {x : M} {y : M'} {s t} (hs : UniqueMDiffWithinAt I s x) (ht : UniqueMDiffWithinAt I' t y) : UniqueMDiffWithinAt (I.prod I') (s ×ˢ t) (x, y) := by refine (hs.prod ht).mono ?_ rw [ModelWithCorners.range_prod, ← prod_inter_prod] rfl theorem UniqueMDiffOn.prod {s : Set M} {t : Set M'} (hs : UniqueMDiffOn I s) (ht : UniqueMDiffOn I' t) : UniqueMDiffOn (I.prod I') (s ×ˢ t) := fun x h ↦ (hs x.1 h.1).prod (ht x.2 h.2) /-! ### General lemmas on derivatives of functions between manifolds We mimick the API for functions between vector spaces -/ theorem mdifferentiableWithinAt_iff {f : M → M'} {s : Set M} {x : M} : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ((extChartAt I x) x) := by rw [mdifferentiableWithinAt_iff'] refine and_congr Iff.rfl (exists_congr fun f' => ?_) rw [inter_comm] simp only [HasFDerivWithinAt, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] #align mdifferentiable_within_at_iff mdifferentiableWithinAt_iff /-- One can reformulate differentiability within a set at a point as continuity within this set at this point, and differentiability in any chart containing that point. -/ theorem mdifferentiableWithinAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ Set.range I) ((extChartAt I x) x') := (differentiable_within_at_localInvariantProp I I').liftPropWithinAt_indep_chart (StructureGroupoid.chart_mem_maximalAtlas _ x) hx (StructureGroupoid.chart_mem_maximalAtlas _ y) hy #align mdifferentiable_within_at_iff_of_mem_source mdifferentiableWithinAt_iff_of_mem_source theorem mfderivWithin_zero_of_not_mdifferentiableWithinAt (h : ¬MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = 0 := by simp only [mfderivWithin, h, if_neg, not_false_iff] #align mfderiv_within_zero_of_not_mdifferentiable_within_at mfderivWithin_zero_of_not_mdifferentiableWithinAt theorem mfderiv_zero_of_not_mdifferentiableAt (h : ¬MDifferentiableAt I I' f x) : mfderiv I I' f x = 0 := by simp only [mfderiv, h, if_neg, not_false_iff] #align mfderiv_zero_of_not_mdifferentiable_at mfderiv_zero_of_not_mdifferentiableAt theorem HasMFDerivWithinAt.mono (h : HasMFDerivWithinAt I I' f t x f') (hst : s ⊆ t) : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousWithinAt.mono h.1 hst, HasFDerivWithinAt.mono h.2 (inter_subset_inter (preimage_mono hst) (Subset.refl _))⟩ #align has_mfderiv_within_at.mono HasMFDerivWithinAt.mono theorem HasMFDerivAt.hasMFDerivWithinAt (h : HasMFDerivAt I I' f x f') : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousAt.continuousWithinAt h.1, HasFDerivWithinAt.mono h.2 inter_subset_right⟩ #align has_mfderiv_at.has_mfderiv_within_at HasMFDerivAt.hasMFDerivWithinAt theorem HasMFDerivWithinAt.mdifferentiableWithinAt (h : HasMFDerivWithinAt I I' f s x f') : MDifferentiableWithinAt I I' f s x := ⟨h.1, ⟨f', h.2⟩⟩ #align has_mfderiv_within_at.mdifferentiable_within_at HasMFDerivWithinAt.mdifferentiableWithinAt theorem HasMFDerivAt.mdifferentiableAt (h : HasMFDerivAt I I' f x f') : MDifferentiableAt I I' f x := by rw [mdifferentiableAt_iff] exact ⟨h.1, ⟨f', h.2⟩⟩ #align has_mfderiv_at.mdifferentiable_at HasMFDerivAt.mdifferentiableAt @[simp, mfld_simps] theorem hasMFDerivWithinAt_univ : HasMFDerivWithinAt I I' f univ x f' ↔ HasMFDerivAt I I' f x f' := by simp only [HasMFDerivWithinAt, HasMFDerivAt, continuousWithinAt_univ, mfld_simps] #align has_mfderiv_within_at_univ hasMFDerivWithinAt_univ theorem hasMFDerivAt_unique (h₀ : HasMFDerivAt I I' f x f₀') (h₁ : HasMFDerivAt I I' f x f₁') : f₀' = f₁' := by rw [← hasMFDerivWithinAt_univ] at h₀ h₁ exact (uniqueMDiffWithinAt_univ I).eq h₀ h₁ #align has_mfderiv_at_unique hasMFDerivAt_unique theorem hasMFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter', continuousWithinAt_inter' h] exact extChartAt_preimage_mem_nhdsWithin I h #align has_mfderiv_within_at_inter' hasMFDerivWithinAt_inter' theorem hasMFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter, continuousWithinAt_inter h] exact extChartAt_preimage_mem_nhds I h #align has_mfderiv_within_at_inter hasMFDerivWithinAt_inter theorem HasMFDerivWithinAt.union (hs : HasMFDerivWithinAt I I' f s x f') (ht : HasMFDerivWithinAt I I' f t x f') : HasMFDerivWithinAt I I' f (s ∪ t) x f' := by constructor · exact ContinuousWithinAt.union hs.1 ht.1 · convert HasFDerivWithinAt.union hs.2 ht.2 using 1 simp only [union_inter_distrib_right, preimage_union] #align has_mfderiv_within_at.union HasMFDerivWithinAt.union theorem HasMFDerivWithinAt.mono_of_mem (h : HasMFDerivWithinAt I I' f s x f') (ht : s ∈ 𝓝[t] x) : HasMFDerivWithinAt I I' f t x f' := (hasMFDerivWithinAt_inter' ht).1 (h.mono inter_subset_right) #align has_mfderiv_within_at.nhds_within HasMFDerivWithinAt.mono_of_mem theorem HasMFDerivWithinAt.hasMFDerivAt (h : HasMFDerivWithinAt I I' f s x f') (hs : s ∈ 𝓝 x) : HasMFDerivAt I I' f x f' := by rwa [← univ_inter s, hasMFDerivWithinAt_inter hs, hasMFDerivWithinAt_univ] at h #align has_mfderiv_within_at.has_mfderiv_at HasMFDerivWithinAt.hasMFDerivAt theorem MDifferentiableWithinAt.hasMFDerivWithinAt (h : MDifferentiableWithinAt I I' f s x) : HasMFDerivWithinAt I I' f s x (mfderivWithin I I' f s x) := by refine ⟨h.1, ?_⟩ simp only [mfderivWithin, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.2 #align mdifferentiable_within_at.has_mfderiv_within_at MDifferentiableWithinAt.hasMFDerivWithinAt protected theorem MDifferentiableWithinAt.mfderivWithin (h : MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f : _) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by simp only [mfderivWithin, h, if_pos] #align mdifferentiable_within_at.mfderiv_within MDifferentiableWithinAt.mfderivWithin theorem MDifferentiableAt.hasMFDerivAt (h : MDifferentiableAt I I' f x) : HasMFDerivAt I I' f x (mfderiv I I' f x) := by refine ⟨h.continuousAt, ?_⟩ simp only [mfderiv, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.differentiableWithinAt_writtenInExtChartAt #align mdifferentiable_at.has_mfderiv_at MDifferentiableAt.hasMFDerivAt protected theorem MDifferentiableAt.mfderiv (h : MDifferentiableAt I I' f x) : mfderiv I I' f x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f : _) (range I) ((extChartAt I x) x) := by simp only [mfderiv, h, if_pos] #align mdifferentiable_at.mfderiv MDifferentiableAt.mfderiv protected theorem HasMFDerivAt.mfderiv (h : HasMFDerivAt I I' f x f') : mfderiv I I' f x = f' := (hasMFDerivAt_unique h h.mdifferentiableAt.hasMFDerivAt).symm #align has_mfderiv_at.mfderiv HasMFDerivAt.mfderiv theorem HasMFDerivWithinAt.mfderivWithin (h : HasMFDerivWithinAt I I' f s x f') (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = f' := by ext rw [hxs.eq h h.mdifferentiableWithinAt.hasMFDerivWithinAt] #align has_mfderiv_within_at.mfderiv_within HasMFDerivWithinAt.mfderivWithin theorem MDifferentiable.mfderivWithin (h : MDifferentiableAt I I' f x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = mfderiv I I' f x := by apply HasMFDerivWithinAt.mfderivWithin _ hxs exact h.hasMFDerivAt.hasMFDerivWithinAt #align mdifferentiable.mfderiv_within MDifferentiable.mfderivWithin theorem mfderivWithin_subset (st : s ⊆ t) (hs : UniqueMDiffWithinAt I s x) (h : MDifferentiableWithinAt I I' f t x) : mfderivWithin I I' f s x = mfderivWithin I I' f t x := ((MDifferentiableWithinAt.hasMFDerivWithinAt h).mono st).mfderivWithin hs #align mfderiv_within_subset mfderivWithin_subset theorem MDifferentiableWithinAt.mono (hst : s ⊆ t) (h : MDifferentiableWithinAt I I' f t x) : MDifferentiableWithinAt I I' f s x := ⟨ContinuousWithinAt.mono h.1 hst, DifferentiableWithinAt.mono h.differentiableWithinAt_writtenInExtChartAt (inter_subset_inter_left _ (preimage_mono hst))⟩ #align mdifferentiable_within_at.mono MDifferentiableWithinAt.mono theorem mdifferentiableWithinAt_univ : MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt] #align mdifferentiable_within_at_univ mdifferentiableWithinAt_univ theorem mdifferentiableWithinAt_inter (ht : t ∈ 𝓝 x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, (differentiable_within_at_localInvariantProp I I').liftPropWithinAt_inter ht] #align mdifferentiable_within_at_inter mdifferentiableWithinAt_inter theorem mdifferentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, (differentiable_within_at_localInvariantProp I I').liftPropWithinAt_inter' ht] #align mdifferentiable_within_at_inter' mdifferentiableWithinAt_inter' theorem MDifferentiableAt.mdifferentiableWithinAt (h : MDifferentiableAt I I' f x) : MDifferentiableWithinAt I I' f s x := MDifferentiableWithinAt.mono (subset_univ _) (mdifferentiableWithinAt_univ.2 h) #align mdifferentiable_at.mdifferentiable_within_at MDifferentiableAt.mdifferentiableWithinAt theorem MDifferentiableWithinAt.mdifferentiableAt (h : MDifferentiableWithinAt I I' f s x) (hs : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := by have : s = univ ∩ s := by rw [univ_inter] rwa [this, mdifferentiableWithinAt_inter hs, mdifferentiableWithinAt_univ] at h #align mdifferentiable_within_at.mdifferentiable_at MDifferentiableWithinAt.mdifferentiableAt theorem MDifferentiableOn.mdifferentiableAt (h : MDifferentiableOn I I' f s) (hx : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := (h x (mem_of_mem_nhds hx)).mdifferentiableAt hx theorem MDifferentiableOn.mono (h : MDifferentiableOn I I' f t) (st : s ⊆ t) : MDifferentiableOn I I' f s := fun x hx => (h x (st hx)).mono st #align mdifferentiable_on.mono MDifferentiableOn.mono theorem mdifferentiableOn_univ : MDifferentiableOn I I' f univ ↔ MDifferentiable I I' f := by simp only [MDifferentiableOn, mdifferentiableWithinAt_univ, mfld_simps]; rfl #align mdifferentiable_on_univ mdifferentiableOn_univ theorem MDifferentiable.mdifferentiableOn (h : MDifferentiable I I' f) : MDifferentiableOn I I' f s := (mdifferentiableOn_univ.2 h).mono (subset_univ _) #align mdifferentiable.mdifferentiable_on MDifferentiable.mdifferentiableOn
Mathlib/Geometry/Manifold/MFDeriv/Basic.lean
337
342
theorem mdifferentiableOn_of_locally_mdifferentiableOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ MDifferentiableOn I I' f (s ∩ u)) : MDifferentiableOn I I' f s := by
intro x xs rcases h x xs with ⟨t, t_open, xt, ht⟩ exact (mdifferentiableWithinAt_inter (t_open.mem_nhds xt)).1 (ht x ⟨xs, xt⟩)
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Submodule #align_import algebra.lie.ideal_operations from "leanprover-community/mathlib"@"8983bec7cdf6cb2dd1f21315c8a34ab00d7b2f6d" /-! # Ideal operations for Lie algebras Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L` on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this provides a pairing of Lie ideals which is especially important. For example, it can be used to define solvability / nilpotency of a Lie algebra via the derived / lower-central series. ## Main definitions * `LieSubmodule.hasBracket` * `LieSubmodule.lieIdeal_oper_eq_linear_span` * `LieIdeal.map_bracket_le` * `LieIdeal.comap_bracket_le` ## Notation Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to the action defined in this file. ## Tags lie algebra, ideal operation -/ universe u v w w₁ w₂ namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} {M₂ : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (N N' : LieSubmodule R L M) (I J : LieIdeal R L) (N₂ : LieSubmodule R L M₂) section LieIdealOperations /-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set of submodules of `M`. -/ instance hasBracket : Bracket (LieIdeal R L) (LieSubmodule R L M) := ⟨fun I N => lieSpan R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m }⟩ #align lie_submodule.has_bracket LieSubmodule.hasBracket theorem lieIdeal_oper_eq_span : ⁅I, N⁆ = lieSpan R L { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } := rfl #align lie_submodule.lie_ideal_oper_eq_span LieSubmodule.lieIdeal_oper_eq_span /-- See also `LieSubmodule.lieIdeal_oper_eq_linear_span'` and `LieSubmodule.lieIdeal_oper_eq_tensor_map_range`. -/ theorem lieIdeal_oper_eq_linear_span : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { m | ∃ (x : I) (n : N), ⁅(x : L), (n : M)⁆ = m } := by apply le_antisymm · let s := { m : M | ∃ (x : ↥I) (n : ↥N), ⁅(x : L), (n : M)⁆ = m } have aux : ∀ (y : L), ∀ m' ∈ Submodule.span R s, ⁅y, m'⁆ ∈ Submodule.span R s := by intro y m' hm' refine Submodule.span_induction (R := R) (M := M) (s := s) (p := fun m' ↦ ⁅y, m'⁆ ∈ Submodule.span R s) hm' ?_ ?_ ?_ ?_ · rintro m'' ⟨x, n, hm''⟩; rw [← hm'', leibniz_lie] refine Submodule.add_mem _ ?_ ?_ <;> apply Submodule.subset_span · use ⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n · use x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩ · simp only [lie_zero, Submodule.zero_mem] · intro m₁ m₂ hm₁ hm₂; rw [lie_add]; exact Submodule.add_mem _ hm₁ hm₂ · intro t m'' hm''; rw [lie_smul]; exact Submodule.smul_mem _ t hm'' change _ ≤ ({ Submodule.span R s with lie_mem := fun hm' => aux _ _ hm' } : LieSubmodule R L M) rw [lieIdeal_oper_eq_span, lieSpan_le] exact Submodule.subset_span · rw [lieIdeal_oper_eq_span]; apply submodule_span_le_lieSpan #align lie_submodule.lie_ideal_oper_eq_linear_span LieSubmodule.lieIdeal_oper_eq_linear_span theorem lieIdeal_oper_eq_linear_span' : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { m | ∃ x ∈ I, ∃ n ∈ N, ⁅x, n⁆ = m } := by rw [lieIdeal_oper_eq_linear_span] congr ext m constructor · rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ exact ⟨x, hx, n, hn, rfl⟩ · rintro ⟨x, hx, n, hn, rfl⟩ exact ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ #align lie_submodule.lie_ideal_oper_eq_linear_span' LieSubmodule.lieIdeal_oper_eq_linear_span' theorem lie_le_iff : ⁅I, N⁆ ≤ N' ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅x, m⁆ ∈ N' := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] refine ⟨fun h x hx m hm => h ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h _ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩ exact h x hx m hm #align lie_submodule.lie_le_iff LieSubmodule.lie_le_iff theorem lie_coe_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ := by rw [lieIdeal_oper_eq_span]; apply subset_lieSpan; use x, m #align lie_submodule.lie_coe_mem_lie LieSubmodule.lie_coe_mem_lie theorem lie_mem_lie {x : L} {m : M} (hx : x ∈ I) (hm : m ∈ N) : ⁅x, m⁆ ∈ ⁅I, N⁆ := N.lie_coe_mem_lie I ⟨x, hx⟩ ⟨m, hm⟩ #align lie_submodule.lie_mem_lie LieSubmodule.lie_mem_lie theorem lie_comm : ⁅I, J⁆ = ⁅J, I⁆ := by suffices ∀ I J : LieIdeal R L, ⁅I, J⁆ ≤ ⁅J, I⁆ by exact le_antisymm (this I J) (this J I) clear! I J; intro I J rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro x ⟨y, z, h⟩; rw [← h] rw [← lie_skew, ← lie_neg, ← LieSubmodule.coe_neg] apply lie_coe_mem_lie #align lie_submodule.lie_comm LieSubmodule.lie_comm theorem lie_le_right : ⁅I, N⁆ ≤ N := by rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn] exact N.lie_mem n.property #align lie_submodule.lie_le_right LieSubmodule.lie_le_right theorem lie_le_left : ⁅I, J⁆ ≤ I := by rw [lie_comm]; exact lie_le_right I J #align lie_submodule.lie_le_left LieSubmodule.lie_le_left theorem lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J := by rw [le_inf_iff]; exact ⟨lie_le_left I J, lie_le_right J I⟩ #align lie_submodule.lie_le_inf LieSubmodule.lie_le_inf @[simp] theorem lie_bot : ⁅I, (⊥ : LieSubmodule R L M)⁆ = ⊥ := by rw [eq_bot_iff]; apply lie_le_right #align lie_submodule.lie_bot LieSubmodule.lie_bot @[simp] theorem bot_lie : ⁅(⊥ : LieIdeal R L), N⁆ = ⊥ := by suffices ⁅(⊥ : LieIdeal R L), N⁆ ≤ ⊥ by exact le_bot_iff.mp this rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨⟨x, hx⟩, n, hn⟩; rw [← hn] change x ∈ (⊥ : LieIdeal R L) at hx; rw [mem_bot] at hx; simp [hx] #align lie_submodule.bot_lie LieSubmodule.bot_lie theorem lie_eq_bot_iff : ⁅I, N⁆ = ⊥ ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅(x : L), m⁆ = 0 := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_eq_bot_iff] refine ⟨fun h x hx m hm => h ⁅x, m⁆ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h - ⟨⟨x, hx⟩, ⟨⟨n, hn⟩, rfl⟩⟩ exact h x hx n hn #align lie_submodule.lie_eq_bot_iff LieSubmodule.lie_eq_bot_iff theorem mono_lie (h₁ : I ≤ J) (h₂ : N ≤ N') : ⁅I, N⁆ ≤ ⁅J, N'⁆ := by intro m h rw [lieIdeal_oper_eq_span, mem_lieSpan] at h; rw [lieIdeal_oper_eq_span, mem_lieSpan] intro N hN; apply h; rintro m' ⟨⟨x, hx⟩, ⟨n, hn⟩, hm⟩; rw [← hm]; apply hN use ⟨x, h₁ hx⟩, ⟨n, h₂ hn⟩ #align lie_submodule.mono_lie LieSubmodule.mono_lie theorem mono_lie_left (h : I ≤ J) : ⁅I, N⁆ ≤ ⁅J, N⁆ := mono_lie _ _ _ _ h (le_refl N) #align lie_submodule.mono_lie_left LieSubmodule.mono_lie_left theorem mono_lie_right (h : N ≤ N') : ⁅I, N⁆ ≤ ⁅I, N'⁆ := mono_lie _ _ _ _ (le_refl I) h #align lie_submodule.mono_lie_right LieSubmodule.mono_lie_right @[simp] theorem lie_sup : ⁅I, N ⊔ N'⁆ = ⁅I, N⁆ ⊔ ⁅I, N'⁆ := by have h : ⁅I, N⁆ ⊔ ⁅I, N'⁆ ≤ ⁅I, N ⊔ N'⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_right <;> [exact le_sup_left; exact le_sup_right] suffices ⁅I, N ⊔ N'⁆ ≤ ⁅I, N⁆ ⊔ ⁅I, N'⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨x, ⟨n, hn⟩, h⟩; erw [LieSubmodule.mem_sup] erw [LieSubmodule.mem_sup] at hn; rcases hn with ⟨n₁, hn₁, n₂, hn₂, hn'⟩ use ⁅(x : L), (⟨n₁, hn₁⟩ : N)⁆; constructor; · apply lie_coe_mem_lie use ⁅(x : L), (⟨n₂, hn₂⟩ : N')⁆; constructor; · apply lie_coe_mem_lie simp [← h, ← hn'] #align lie_submodule.lie_sup LieSubmodule.lie_sup @[simp] theorem sup_lie : ⁅I ⊔ J, N⁆ = ⁅I, N⁆ ⊔ ⁅J, N⁆ := by have h : ⁅I, N⁆ ⊔ ⁅J, N⁆ ≤ ⁅I ⊔ J, N⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_left <;> [exact le_sup_left; exact le_sup_right] suffices ⁅I ⊔ J, N⁆ ≤ ⁅I, N⁆ ⊔ ⁅J, N⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨⟨x, hx⟩, n, h⟩; erw [LieSubmodule.mem_sup] erw [LieSubmodule.mem_sup] at hx; rcases hx with ⟨x₁, hx₁, x₂, hx₂, hx'⟩ use ⁅((⟨x₁, hx₁⟩ : I) : L), (n : N)⁆; constructor; · apply lie_coe_mem_lie use ⁅((⟨x₂, hx₂⟩ : J) : L), (n : N)⁆; constructor; · apply lie_coe_mem_lie simp [← h, ← hx'] #align lie_submodule.sup_lie LieSubmodule.sup_lie -- @[simp] -- Porting note: not in simpNF theorem lie_inf : ⁅I, N ⊓ N'⁆ ≤ ⁅I, N⁆ ⊓ ⁅I, N'⁆ := by rw [le_inf_iff]; constructor <;> apply mono_lie_right <;> [exact inf_le_left; exact inf_le_right] #align lie_submodule.lie_inf LieSubmodule.lie_inf -- @[simp] -- Porting note: not in simpNF theorem inf_lie : ⁅I ⊓ J, N⁆ ≤ ⁅I, N⁆ ⊓ ⁅J, N⁆ := by rw [le_inf_iff]; constructor <;> apply mono_lie_left <;> [exact inf_le_left; exact inf_le_right] #align lie_submodule.inf_lie LieSubmodule.inf_lie variable (f : M →ₗ⁅R,L⁆ M₂) theorem map_bracket_eq : map f ⁅I, N⁆ = ⁅I, map f N⁆ := by rw [← coe_toSubmodule_eq_iff, coeSubmodule_map, lieIdeal_oper_eq_linear_span, lieIdeal_oper_eq_linear_span, Submodule.map_span] congr ext m constructor · rintro ⟨-, ⟨⟨x, ⟨n, hn⟩, rfl⟩, hm⟩⟩ simp only [LieModuleHom.coe_toLinearMap, LieModuleHom.map_lie] at hm exact ⟨x, ⟨f n, (mem_map (f n)).mpr ⟨n, hn, rfl⟩⟩, hm⟩ · rintro ⟨x, ⟨m₂, hm₂ : m₂ ∈ map f N⟩, rfl⟩ obtain ⟨n, hn, rfl⟩ := (mem_map m₂).mp hm₂ exact ⟨⁅x, n⁆, ⟨x, ⟨n, hn⟩, rfl⟩, by simp⟩ #align lie_submodule.map_bracket_eq LieSubmodule.map_bracket_eq theorem map_comap_le : map f (comap f N₂) ≤ N₂ := (N₂ : Set M₂).image_preimage_subset f #align lie_submodule.map_comap_le LieSubmodule.map_comap_le
Mathlib/Algebra/Lie/IdealOperations.lean
221
223
theorem map_comap_eq (hf : N₂ ≤ f.range) : map f (comap f N₂) = N₂ := by
rw [SetLike.ext'_iff] exact Set.image_preimage_eq_of_subset hf
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.LinearAlgebra.Finsupp import Mathlib.LinearAlgebra.Prod import Mathlib.SetTheory.Cardinal.Basic import Mathlib.Tactic.FinCases import Mathlib.Tactic.LinearCombination import Mathlib.Lean.Expr.ExtraRecognizers import Mathlib.Data.Set.Subsingleton #align_import linear_algebra.linear_independent from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Linear independence This file defines linear independence in a module or vector space. It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light. We define `LinearIndependent R v` as `ker (Finsupp.total ι M R v) = ⊥`. Here `Finsupp.total` is the linear map sending a function `f : ι →₀ R` with finite support to the linear combination of vectors from `v` with these coefficients. Then we prove that several other statements are equivalent to this one, including injectivity of `Finsupp.total ι M R v` and some versions with explicitly written linear combinations. ## Main definitions All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or vector space and `ι : Type*` is an arbitrary indexing type. * `LinearIndependent R v` states that the elements of the family `v` are linearly independent. * `LinearIndependent.repr hv x` returns the linear combination representing `x : span R (range v)` on the linearly independent vectors `v`, given `hv : LinearIndependent R v` (using classical choice). `LinearIndependent.repr hv` is provided as a linear map. ## Main statements We prove several specialized tests for linear independence of families of vectors and of sets of vectors. * `Fintype.linearIndependent_iff`: if `ι` is a finite type, then any function `f : ι → R` has finite support, so we can reformulate the statement using `∑ i : ι, f i • v i` instead of a sum over an auxiliary `s : Finset ι`; * `linearIndependent_empty_type`: a family indexed by an empty type is linearly independent; * `linearIndependent_unique_iff`: if `ι` is a singleton, then `LinearIndependent K v` is equivalent to `v default ≠ 0`; * `linearIndependent_option`, `linearIndependent_sum`, `linearIndependent_fin_cons`, `linearIndependent_fin_succ`: type-specific tests for linear independence of families of vector fields; * `linearIndependent_insert`, `linearIndependent_union`, `linearIndependent_pair`, `linearIndependent_singleton`: linear independence tests for set operations. In many cases we additionally provide dot-style operations (e.g., `LinearIndependent.union`) to make the linear independence tests usable as `hv.insert ha` etc. We also prove that, when working over a division ring, any family of vectors includes a linear independent subfamily spanning the same subspace. ## Implementation notes We use families instead of sets because it allows us to say that two identical vectors are linearly dependent. If you want to use sets, use the family `(fun x ↦ x : s → M)` given a set `s : Set M`. The lemmas `LinearIndependent.to_subtype_range` and `LinearIndependent.of_subtype_range` connect those two worlds. ## Tags linearly dependent, linear dependence, linearly independent, linear independence -/ noncomputable section open Function Set Submodule open Cardinal universe u' u variable {ι : Type u'} {ι' : Type*} {R : Type*} {K : Type*} variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*} section Module variable {v : ι → M} variable [Semiring R] [AddCommMonoid M] [AddCommMonoid M'] [AddCommMonoid M''] variable [Module R M] [Module R M'] [Module R M''] variable {a b : R} {x y : M} variable (R) (v) /-- `LinearIndependent R v` states the family of vectors `v` is linearly independent over `R`. -/ def LinearIndependent : Prop := LinearMap.ker (Finsupp.total ι M R v) = ⊥ #align linear_independent LinearIndependent open Lean PrettyPrinter.Delaborator SubExpr in /-- Delaborator for `LinearIndependent` that suggests pretty printing with type hints in case the family of vectors is over a `Set`. Type hints look like `LinearIndependent fun (v : ↑s) => ↑v` or `LinearIndependent (ι := ↑s) f`, depending on whether the family is a lambda expression or not. -/ @[delab app.LinearIndependent] def delabLinearIndependent : Delab := whenPPOption getPPNotation <| whenNotPPOption getPPAnalysisSkip <| withOptionAtCurrPos `pp.analysis.skip true do let e ← getExpr guard <| e.isAppOfArity ``LinearIndependent 7 let some _ := (e.getArg! 0).coeTypeSet? | failure let optionsPerPos ← if (e.getArg! 3).isLambda then withNaryArg 3 do return (← read).optionsPerPos.setBool (← getPos) pp.funBinderTypes.name true else withNaryArg 0 do return (← read).optionsPerPos.setBool (← getPos) `pp.analysis.namedArg true withTheReader Context ({· with optionsPerPos}) delab variable {R} {v} theorem linearIndependent_iff : LinearIndependent R v ↔ ∀ l, Finsupp.total ι M R v l = 0 → l = 0 := by simp [LinearIndependent, LinearMap.ker_eq_bot'] #align linear_independent_iff linearIndependent_iff theorem linearIndependent_iff' : LinearIndependent R v ↔ ∀ s : Finset ι, ∀ g : ι → R, ∑ i ∈ s, g i • v i = 0 → ∀ i ∈ s, g i = 0 := linearIndependent_iff.trans ⟨fun hf s g hg i his => have h := hf (∑ i ∈ s, Finsupp.single i (g i)) <| by simpa only [map_sum, Finsupp.total_single] using hg calc g i = (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single i (g i)) := by { rw [Finsupp.lapply_apply, Finsupp.single_eq_same] } _ = ∑ j ∈ s, (Finsupp.lapply i : (ι →₀ R) →ₗ[R] R) (Finsupp.single j (g j)) := Eq.symm <| Finset.sum_eq_single i (fun j _hjs hji => by rw [Finsupp.lapply_apply, Finsupp.single_eq_of_ne hji]) fun hnis => hnis.elim his _ = (∑ j ∈ s, Finsupp.single j (g j)) i := (map_sum ..).symm _ = 0 := DFunLike.ext_iff.1 h i, fun hf l hl => Finsupp.ext fun i => _root_.by_contradiction fun hni => hni <| hf _ _ hl _ <| Finsupp.mem_support_iff.2 hni⟩ #align linear_independent_iff' linearIndependent_iff' theorem linearIndependent_iff'' : LinearIndependent R v ↔ ∀ (s : Finset ι) (g : ι → R), (∀ i ∉ s, g i = 0) → ∑ i ∈ s, g i • v i = 0 → ∀ i, g i = 0 := by classical exact linearIndependent_iff'.trans ⟨fun H s g hg hv i => if his : i ∈ s then H s g hv i his else hg i his, fun H s g hg i hi => by convert H s (fun j => if j ∈ s then g j else 0) (fun j hj => if_neg hj) (by simp_rw [ite_smul, zero_smul, Finset.sum_extend_by_zero, hg]) i exact (if_pos hi).symm⟩ #align linear_independent_iff'' linearIndependent_iff'' theorem not_linearIndependent_iff : ¬LinearIndependent R v ↔ ∃ s : Finset ι, ∃ g : ι → R, ∑ i ∈ s, g i • v i = 0 ∧ ∃ i ∈ s, g i ≠ 0 := by rw [linearIndependent_iff'] simp only [exists_prop, not_forall] #align not_linear_independent_iff not_linearIndependent_iff theorem Fintype.linearIndependent_iff [Fintype ι] : LinearIndependent R v ↔ ∀ g : ι → R, ∑ i, g i • v i = 0 → ∀ i, g i = 0 := by refine ⟨fun H g => by simpa using linearIndependent_iff'.1 H Finset.univ g, fun H => linearIndependent_iff''.2 fun s g hg hs i => H _ ?_ _⟩ rw [← hs] refine (Finset.sum_subset (Finset.subset_univ _) fun i _ hi => ?_).symm rw [hg i hi, zero_smul] #align fintype.linear_independent_iff Fintype.linearIndependent_iff /-- A finite family of vectors `v i` is linear independent iff the linear map that sends `c : ι → R` to `∑ i, c i • v i` has the trivial kernel. -/ theorem Fintype.linearIndependent_iff' [Fintype ι] [DecidableEq ι] : LinearIndependent R v ↔ LinearMap.ker (LinearMap.lsum R (fun _ ↦ R) ℕ fun i ↦ LinearMap.id.smulRight (v i)) = ⊥ := by simp [Fintype.linearIndependent_iff, LinearMap.ker_eq_bot', funext_iff] #align fintype.linear_independent_iff' Fintype.linearIndependent_iff' theorem Fintype.not_linearIndependent_iff [Fintype ι] : ¬LinearIndependent R v ↔ ∃ g : ι → R, ∑ i, g i • v i = 0 ∧ ∃ i, g i ≠ 0 := by simpa using not_iff_not.2 Fintype.linearIndependent_iff #align fintype.not_linear_independent_iff Fintype.not_linearIndependent_iff theorem linearIndependent_empty_type [IsEmpty ι] : LinearIndependent R v := linearIndependent_iff.mpr fun v _hv => Subsingleton.elim v 0 #align linear_independent_empty_type linearIndependent_empty_type theorem LinearIndependent.ne_zero [Nontrivial R] (i : ι) (hv : LinearIndependent R v) : v i ≠ 0 := fun h => zero_ne_one' R <| Eq.symm (by suffices (Finsupp.single i 1 : ι →₀ R) i = 0 by simpa rw [linearIndependent_iff.1 hv (Finsupp.single i 1)] · simp · simp [h]) #align linear_independent.ne_zero LinearIndependent.ne_zero lemma LinearIndependent.eq_zero_of_pair {x y : M} (h : LinearIndependent R ![x, y]) {s t : R} (h' : s • x + t • y = 0) : s = 0 ∧ t = 0 := by have := linearIndependent_iff'.1 h Finset.univ ![s, t] simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons, h', Finset.mem_univ, forall_true_left] at this exact ⟨this 0, this 1⟩ /-- Also see `LinearIndependent.pair_iff'` for a simpler version over fields. -/ lemma LinearIndependent.pair_iff {x y : M} : LinearIndependent R ![x, y] ↔ ∀ (s t : R), s • x + t • y = 0 → s = 0 ∧ t = 0 := by refine ⟨fun h s t hst ↦ h.eq_zero_of_pair hst, fun h ↦ ?_⟩ apply Fintype.linearIndependent_iff.2 intro g hg simp only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, Matrix.head_cons] at hg intro i fin_cases i exacts [(h _ _ hg).1, (h _ _ hg).2] /-- A subfamily of a linearly independent family (i.e., a composition with an injective map) is a linearly independent family. -/ theorem LinearIndependent.comp (h : LinearIndependent R v) (f : ι' → ι) (hf : Injective f) : LinearIndependent R (v ∘ f) := by rw [linearIndependent_iff, Finsupp.total_comp] intro l hl have h_map_domain : ∀ x, (Finsupp.mapDomain f l) (f x) = 0 := by rw [linearIndependent_iff.1 h (Finsupp.mapDomain f l) hl]; simp ext x convert h_map_domain x rw [Finsupp.mapDomain_apply hf] #align linear_independent.comp LinearIndependent.comp /-- A family is linearly independent if and only if all of its finite subfamily is linearly independent. -/ theorem linearIndependent_iff_finset_linearIndependent : LinearIndependent R v ↔ ∀ (s : Finset ι), LinearIndependent R (v ∘ (Subtype.val : s → ι)) := ⟨fun H _ ↦ H.comp _ Subtype.val_injective, fun H ↦ linearIndependent_iff'.2 fun s g hg i hi ↦ Fintype.linearIndependent_iff.1 (H s) (g ∘ Subtype.val) (hg ▸ Finset.sum_attach s fun j ↦ g j • v j) ⟨i, hi⟩⟩ theorem LinearIndependent.coe_range (i : LinearIndependent R v) : LinearIndependent R ((↑) : range v → M) := by simpa using i.comp _ (rangeSplitting_injective v) #align linear_independent.coe_range LinearIndependent.coe_range /-- If `v` is a linearly independent family of vectors and the kernel of a linear map `f` is disjoint with the submodule spanned by the vectors of `v`, then `f ∘ v` is a linearly independent family of vectors. See also `LinearIndependent.map'` for a special case assuming `ker f = ⊥`. -/ theorem LinearIndependent.map (hv : LinearIndependent R v) {f : M →ₗ[R] M'} (hf_inj : Disjoint (span R (range v)) (LinearMap.ker f)) : LinearIndependent R (f ∘ v) := by rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, map_le_iff_le_comap, comap_bot, Finsupp.supported_univ, top_inf_eq] at hf_inj unfold LinearIndependent at hv ⊢ rw [hv, le_bot_iff] at hf_inj haveI : Inhabited M := ⟨0⟩ rw [Finsupp.total_comp, Finsupp.lmapDomain_total _ _ f, LinearMap.ker_comp, hf_inj] exact fun _ => rfl #align linear_independent.map LinearIndependent.map /-- If `v` is an injective family of vectors such that `f ∘ v` is linearly independent, then `v` spans a submodule disjoint from the kernel of `f` -/ theorem Submodule.range_ker_disjoint {f : M →ₗ[R] M'} (hv : LinearIndependent R (f ∘ v)) : Disjoint (span R (range v)) (LinearMap.ker f) := by rw [LinearIndependent, Finsupp.total_comp, Finsupp.lmapDomain_total R _ f (fun _ ↦ rfl), LinearMap.ker_comp] at hv rw [disjoint_iff_inf_le, ← Set.image_univ, Finsupp.span_image_eq_map_total, map_inf_eq_map_inf_comap, hv, inf_bot_eq, map_bot] /-- An injective linear map sends linearly independent families of vectors to linearly independent families of vectors. See also `LinearIndependent.map` for a more general statement. -/ theorem LinearIndependent.map' (hv : LinearIndependent R v) (f : M →ₗ[R] M') (hf_inj : LinearMap.ker f = ⊥) : LinearIndependent R (f ∘ v) := hv.map <| by simp [hf_inj] #align linear_independent.map' LinearIndependent.map' /-- If `M / R` and `M' / R'` are modules, `i : R' → R` is a map, `j : M →+ M'` is a monoid map, such that they send non-zero elements to non-zero elements, and compatible with the scalar multiplications on `M` and `M'`, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/ theorem LinearIndependent.map_of_injective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : R' → R) (j : M →+ M') (hi : ∀ r, i r = 0 → r = 0) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R') (m : M), j (i r • m) = r • j m) : LinearIndependent R' (j ∘ v) := by rw [linearIndependent_iff'] at hv ⊢ intro S r' H s hs simp_rw [comp_apply, ← hc, ← map_sum] at H exact hi _ <| hv _ _ (hj _ H) s hs /-- If `M / R` and `M' / R'` are modules, `i : R → R'` is a surjective map which maps zero to zero, `j : M →+ M'` is a monoid map which sends non-zero elements to non-zero elements, such that the scalar multiplications on `M` and `M'` are compatible, then `j` sends linearly independent families of vectors to linearly independent families of vectors. As a special case, taking `R = R'` it is `LinearIndependent.map'`. -/
Mathlib/LinearAlgebra/LinearIndependent.lean
307
315
theorem LinearIndependent.map_of_surjective_injective {R' : Type*} {M' : Type*} [Semiring R'] [AddCommMonoid M'] [Module R' M'] (hv : LinearIndependent R v) (i : ZeroHom R R') (j : M →+ M') (hi : Surjective i) (hj : ∀ m, j m = 0 → m = 0) (hc : ∀ (r : R) (m : M), j (r • m) = i r • j m) : LinearIndependent R' (j ∘ v) := by
obtain ⟨i', hi'⟩ := hi.hasRightInverse refine hv.map_of_injective_injective i' j (fun _ h ↦ ?_) hj fun r m ↦ ?_ · apply_fun i at h rwa [hi', i.map_zero] at h rw [hc (i' r) m, hi']
/- 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.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FormalMultilinearSeries #align_import analysis.calculus.cont_diff_def from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iteratedFDeriv 𝕜 n f x` where `𝕜` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iteratedFDerivWithin` relative to a domain, as well as predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `HasFTaylorSeriesUpTo n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `HasFTaylorSeriesUpToOn n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iteratedFDerivWithin 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iteratedFDerivWithin 𝕜 (n-1) f s` if one exists, and `0` otherwise. * `iteratedFDeriv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iteratedFDeriv 𝕜 (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naïve direct definition, the `n`-th derivative of a function belongs to the space `E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iteratedFDeriv 𝕜 (n + 1) f x = iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only work if `F` and `E →L[𝕜] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical open NNReal Topology Filter local notation "∞" => (⊤ : ℕ∞) /- Porting note: These lines are not required in Mathlib4. attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid -/ open Set Fin Filter Function universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Functions with a Taylor series on a domain -/ /-- `HasFTaylorSeriesUpToOn n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivWithinAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an additional `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpToOn (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) (s : Set E) : Prop where zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x protected fderivWithin : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x ∈ s, HasFDerivWithinAt (p · m) (p x m.succ).curryLeft s x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (p · m) s #align has_ftaylor_series_up_to_on HasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpToOn.zero_eq' (h : HasFTaylorSeriesUpToOn n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x hx] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to_on.zero_eq' HasFTaylorSeriesUpToOn.zero_eq' /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ theorem HasFTaylorSeriesUpToOn.congr (h : HasFTaylorSeriesUpToOn n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) : HasFTaylorSeriesUpToOn n f₁ p s := by refine ⟨fun x hx => ?_, h.fderivWithin, h.cont⟩ rw [h₁ x hx] exact h.zero_eq x hx #align has_ftaylor_series_up_to_on.congr HasFTaylorSeriesUpToOn.congr theorem HasFTaylorSeriesUpToOn.mono (h : HasFTaylorSeriesUpToOn n f p s) {t : Set E} (hst : t ⊆ s) : HasFTaylorSeriesUpToOn n f p t := ⟨fun x hx => h.zero_eq x (hst hx), fun m hm x hx => (h.fderivWithin m hm x (hst hx)).mono hst, fun m hm => (h.cont m hm).mono hst⟩ #align has_ftaylor_series_up_to_on.mono HasFTaylorSeriesUpToOn.mono theorem HasFTaylorSeriesUpToOn.of_le (h : HasFTaylorSeriesUpToOn n f p s) (hmn : m ≤ n) : HasFTaylorSeriesUpToOn m f p s := ⟨h.zero_eq, fun k hk x hx => h.fderivWithin k (lt_of_lt_of_le hk hmn) x hx, fun k hk => h.cont k (le_trans hk hmn)⟩ #align has_ftaylor_series_up_to_on.of_le HasFTaylorSeriesUpToOn.of_le theorem HasFTaylorSeriesUpToOn.continuousOn (h : HasFTaylorSeriesUpToOn n f p s) : ContinuousOn f s := by have := (h.cont 0 bot_le).congr fun x hx => (h.zero_eq' hx).symm rwa [← (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_continuousOn_iff] #align has_ftaylor_series_up_to_on.continuous_on HasFTaylorSeriesUpToOn.continuousOn theorem hasFTaylorSeriesUpToOn_zero_iff : HasFTaylorSeriesUpToOn 0 f p s ↔ ContinuousOn f s ∧ ∀ x ∈ s, (p x 0).uncurry0 = f x := by refine ⟨fun H => ⟨H.continuousOn, H.zero_eq⟩, fun H => ⟨H.2, fun m hm => False.elim (not_le.2 hm bot_le), fun m hm ↦ ?_⟩⟩ obtain rfl : m = 0 := mod_cast hm.antisymm (zero_le _) have : EqOn (p · 0) ((continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f) s := fun x hx ↦ (continuousMultilinearCurryFin0 𝕜 E F).eq_symm_apply.2 (H.2 x hx) rw [continuousOn_congr this, LinearIsometryEquiv.comp_continuousOn_iff] exact H.1 #align has_ftaylor_series_up_to_on_zero_iff hasFTaylorSeriesUpToOn_zero_iff theorem hasFTaylorSeriesUpToOn_top_iff : HasFTaylorSeriesUpToOn ∞ f p s ↔ ∀ n : ℕ, HasFTaylorSeriesUpToOn n f p s := by constructor · intro H n; exact H.of_le le_top · intro H constructor · exact (H 0).zero_eq · intro m _ apply (H m.succ).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) · intro m _ apply (H m).cont m le_rfl #align has_ftaylor_series_up_to_on_top_iff hasFTaylorSeriesUpToOn_top_iff /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpToOn`. -/ theorem hasFTaylorSeriesUpToOn_top_iff' : HasFTaylorSeriesUpToOn ∞ f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ ∀ m : ℕ, ∀ x ∈ s, HasFDerivWithinAt (fun y => p y m) (p x m.succ).curryLeft s x := -- Everything except for the continuity is trivial: ⟨fun h => ⟨h.1, fun m => h.2 m (WithTop.coe_lt_top m)⟩, fun h => ⟨h.1, fun m _ => h.2 m, fun m _ x hx => -- The continuity follows from the existence of a derivative: (h.2 m x hx).continuousWithinAt⟩⟩ #align has_ftaylor_series_up_to_on_top_iff' hasFTaylorSeriesUpToOn_top_iff' /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivWithinAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : x ∈ s) : HasFDerivWithinAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x := by have A : ∀ y ∈ s, f y = (continuousMultilinearCurryFin0 𝕜 E F) (p y 0) := fun y hy ↦ (h.zero_eq y hy).symm suffices H : HasFDerivWithinAt (continuousMultilinearCurryFin0 𝕜 E F ∘ (p · 0)) (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x from H.congr A (A x hx) rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] have : ((0 : ℕ) : ℕ∞) < n := zero_lt_one.trans_le hn convert h.fderivWithin _ this x hx ext y v change (p x 1) (snoc 0 y) = (p x 1) (cons y v) congr with i rw [Unique.eq_default (α := Fin 1) i] rfl #align has_ftaylor_series_up_to_on.has_fderiv_within_at HasFTaylorSeriesUpToOn.hasFDerivWithinAt theorem HasFTaylorSeriesUpToOn.differentiableOn (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun _x hx => (h.hasFDerivWithinAt hn hx).differentiableWithinAt #align has_ftaylor_series_up_to_on.differentiable_on HasFTaylorSeriesUpToOn.differentiableOn /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then the term of order `1` of this series is a derivative of `f` at `x`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := (h.hasFDerivWithinAt hn (mem_of_mem_nhds hx)).hasFDerivAt hx #align has_ftaylor_series_up_to_on.has_fderiv_at HasFTaylorSeriesUpToOn.hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then in a neighborhood of `x`, the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.eventually_hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p y 1)) y := (eventually_eventually_nhds.2 hx).mono fun _y hy => h.hasFDerivAt hn hy #align has_ftaylor_series_up_to_on.eventually_has_fderiv_at HasFTaylorSeriesUpToOn.eventually_hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then it is differentiable at `x`. -/ theorem HasFTaylorSeriesUpToOn.differentiableAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hn hx).differentiableAt #align has_ftaylor_series_up_to_on.differentiable_at HasFTaylorSeriesUpToOn.differentiableAt /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and `p (n + 1)` is a derivative of `p n`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_left {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1) f p s ↔ HasFTaylorSeriesUpToOn n f p s ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y n) (p x n.succ).curryLeft s x) ∧ ContinuousOn (fun x => p x (n + 1)) s := by constructor · exact fun h ↦ ⟨h.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n)), h.fderivWithin _ (WithTop.coe_lt_coe.2 (lt_add_one n)), h.cont (n + 1) le_rfl⟩ · intro h constructor · exact h.1.zero_eq · intro m hm by_cases h' : m < n · exact h.1.fderivWithin m (WithTop.coe_lt_coe.2 h') · have : m = n := Nat.eq_of_lt_succ_of_not_lt (WithTop.coe_lt_coe.1 hm) h' rw [this] exact h.2.1 · intro m hm by_cases h' : m ≤ n · apply h.1.cont m (WithTop.coe_le_coe.2 h') · have : m = n + 1 := le_antisymm (WithTop.coe_le_coe.1 hm) (not_le.1 h') rw [this] exact h.2.2 #align has_ftaylor_series_up_to_on_succ_iff_left hasFTaylorSeriesUpToOn_succ_iff_left #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119, without `set_option maxSynthPendingDepth 2` this proof needs substantial repair. -/ set_option maxSynthPendingDepth 2 in -- Porting note: this was split out from `hasFTaylorSeriesUpToOn_succ_iff_right` to avoid a timeout. theorem HasFTaylorSeriesUpToOn.shift_of_succ {n : ℕ} (H : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s) : (HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift)) s := by constructor · intro x _ rfl · intro m (hm : (m : ℕ∞) < n) x (hx : x ∈ s) have A : (m.succ : ℕ∞) < n.succ := by rw [Nat.cast_lt] at hm ⊢ exact Nat.succ_lt_succ hm change HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) (p x m.succ.succ).curryRight.curryLeft s x rw [((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).comp_hasFDerivWithinAt_iff'] convert H.fderivWithin _ A x hx ext y v change p x (m + 2) (snoc (cons y (init v)) (v (last _))) = p x (m + 2) (cons y v) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≤ n) suffices A : ContinuousOn (p · (m + 1)) s from ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).continuous.comp_continuousOn A refine H.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.succ_le_succ hm /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y 0) (p x 1).curryLeft s x) ∧ HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift) s := by constructor · intro H refine ⟨H.zero_eq, H.fderivWithin 0 (Nat.cast_lt.2 (Nat.succ_pos n)), ?_⟩ exact H.shift_of_succ · rintro ⟨Hzero_eq, Hfderiv_zero, Htaylor⟩ constructor · exact Hzero_eq · intro m (hm : (m : ℕ∞) < n.succ) x (hx : x ∈ s) cases' m with m · exact Hfderiv_zero x hx · have A : (m : ℕ∞) < n := by rw [Nat.cast_lt] at hm ⊢ exact Nat.lt_of_succ_lt_succ hm have : HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) ((p x).shift m.succ).curryLeft s x := Htaylor.fderivWithin _ A x hx rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] at this convert this ext y v change (p x (Nat.succ (Nat.succ m))) (cons y v) = (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≤ n.succ) cases' m with m · have : DifferentiableOn 𝕜 (fun x => p x 0) s := fun x hx => (Hfderiv_zero x hx).differentiableWithinAt exact this.continuousOn · refine (continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm.comp_continuousOn_iff.mp ?_ refine Htaylor.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.lt_succ_iff.mp hm #align has_ftaylor_series_up_to_on_succ_iff_right hasFTaylorSeriesUpToOn_succ_iff_right /-! ### Smooth functions within a set around a point -/ variable (𝕜) /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := ∀ m : ℕ, (m : ℕ∞) ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u #align cont_diff_within_at ContDiffWithinAt variable {𝕜} theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le hm⟩⟩ #align cont_diff_within_at_nat contDiffWithinAt_nat theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := fun k hk => h k (le_trans hk hmn) #align cont_diff_within_at.of_le ContDiffWithinAt.of_le theorem contDiffWithinAt_iff_forall_nat_le : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _m hm => H.of_le hm, fun H m hm => H m hm _ le_rfl⟩ #align cont_diff_within_at_iff_forall_nat_le contDiffWithinAt_iff_forall_nat_le theorem contDiffWithinAt_top : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] #align cont_diff_within_at_top contDiffWithinAt_top theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by rcases h 0 bot_le with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem hu.2 #align cont_diff_within_at.continuous_within_at ContDiffWithinAt.continuousWithinAt theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := fun m hm => let ⟨u, hu, p, H⟩ := h m hm ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ => And.right⟩ #align cont_diff_within_at.congr_of_eventually_eq ContDiffWithinAt.congr_of_eventuallyEq theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ : _) #align cont_diff_within_at.congr_of_eventually_eq_insert ContDiffWithinAt.congr_of_eventuallyEq_insert theorem ContDiffWithinAt.congr_of_eventually_eq' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx #align cont_diff_within_at.congr_of_eventually_eq' ContDiffWithinAt.congr_of_eventually_eq' theorem Filter.EventuallyEq.contDiffWithinAt_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H => ContDiffWithinAt.congr_of_eventuallyEq H h₁.symm hx.symm, fun H => H.congr_of_eventuallyEq h₁ hx⟩ #align filter.eventually_eq.cont_diff_within_at_iff Filter.EventuallyEq.contDiffWithinAt_iff theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx #align cont_diff_within_at.congr ContDiffWithinAt.congr theorem ContDiffWithinAt.congr' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) #align cont_diff_within_at.congr' ContDiffWithinAt.congr' theorem ContDiffWithinAt.mono_of_mem (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ #align cont_diff_within_at.mono_of_mem ContDiffWithinAt.mono_of_mem theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| Filter.mem_of_superset self_mem_nhdsWithin hst #align cont_diff_within_at.mono ContDiffWithinAt.mono theorem ContDiffWithinAt.congr_nhds (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| hst ▸ self_mem_nhdsWithin #align cont_diff_within_at.congr_nhds ContDiffWithinAt.congr_nhds theorem contDiffWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ #align cont_diff_within_at_congr_nhds contDiffWithinAt_congr_nhds theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_nhds <| Eq.symm <| nhdsWithin_restrict'' _ h #align cont_diff_within_at_inter' contDiffWithinAt_inter' theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) #align cont_diff_within_at_inter contDiffWithinAt_inter theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | h) · exact contDiffWithinAt_insert_self simp_rw [ContDiffWithinAt, insert_comm x y, nhdsWithin_insert_of_ne h] #align cont_diff_within_at_insert contDiffWithinAt_insert alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert #align cont_diff_within_at.of_insert ContDiffWithinAt.of_insert #align cont_diff_within_at.insert' ContDiffWithinAt.insert' protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' #align cont_diff_within_at.insert ContDiffWithinAt.insert /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiable_within_at' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases h 1 hn with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu have := ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 this #align cont_diff_within_at.differentiable_within_at' ContDiffWithinAt.differentiable_within_at' theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiable_within_at' hn).mono (subset_insert x s) #align cont_diff_within_at.differentiable_within_at ContDiffWithinAt.differentiableWithinAt /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by constructor · intro h rcases h n.succ le_rfl with ⟨u, hu, p, Hp⟩ refine ⟨u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ intro m hm refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · -- Porting note: without the explicit argument Lean is not sure of the type. convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp exact Hp.2.2.of_le hm · rintro ⟨u, hu, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_nat] rcases Hf' n le_rfl with ⟨v, hv, p', Hp'⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y -- Porting note: needed `erw` here. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] #align cont_diff_within_at_succ_iff_has_fderiv_within_at contDiffWithinAt_succ_iff_hasFDerivWithinAt /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f', huf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt.mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, f', fun y hy => ?_, ?_⟩ · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f', huf', hf'⟩ exact ⟨u, hu, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ #align cont_diff_within_at_succ_iff_has_fderiv_within_at' contDiffWithinAt_succ_iff_hasFDerivWithinAt' /-! ### Smooth functions within a set -/ variable (𝕜) /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x #align cont_diff_on ContDiffOn variable {𝕜} theorem HasFTaylorSeriesUpToOn.contDiffOn {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and_iff] exact ⟨f', hf.of_le hm⟩ #align has_ftaylor_series_up_to_on.cont_diff_on HasFTaylorSeriesUpToOn.contDiffOn theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx #align cont_diff_on.cont_diff_within_at ContDiffOn.contDiffWithinAt theorem ContDiffWithinAt.contDiffOn' {m : ℕ} (hm : (m : ℕ∞) ≤ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases h m hm with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ #align cont_diff_within_at.cont_diff_on' ContDiffWithinAt.contDiffOn' theorem ContDiffWithinAt.contDiffOn {m : ℕ} (hm : (m : ℕ∞) ≤ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := let ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ #align cont_diff_within_at.cont_diff_on ContDiffWithinAt.contDiffOn protected theorem ContDiffWithinAt.eventually {n : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_nhdsWithin_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 #align cont_diff_within_at.eventually ContDiffWithinAt.eventually theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn #align cont_diff_on.of_le ContDiffOn.of_le theorem ContDiffOn.of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le <| WithTop.coe_le_coe.mpr le_self_add #align cont_diff_on.of_succ ContDiffOn.of_succ theorem ContDiffOn.one_of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le <| WithTop.coe_le_coe.mpr le_add_self #align cont_diff_on.one_of_succ ContDiffOn.one_of_succ theorem contDiffOn_iff_forall_nat_le : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le hm, fun H x hx m hm => H m hm x hx m le_rfl⟩ #align cont_diff_on_iff_forall_nat_le contDiffOn_iff_forall_nat_le theorem contDiffOn_top : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] #align cont_diff_on_top contDiffOn_top theorem contDiffOn_all_iff_nat : (∀ n, ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_top.2 H, H n] #align cont_diff_on_all_iff_nat contDiffOn_all_iff_nat theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt #align cont_diff_on.continuous_on ContDiffOn.continuousOn theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) #align cont_diff_on.congr ContDiffOn.congr theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ #align cont_diff_on_congr contDiffOn_congr theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst #align cont_diff_on.mono ContDiffOn.mono theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ #align cont_diff_on.congr_mono ContDiffOn.congr_mono /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn #align cont_diff_on.differentiable_on ContDiffOn.differentiableOn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu #align cont_diff_on_of_locally_cont_diff_on contDiffOn_of_locally_contDiffOn /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (h x hx) n.succ le_rfl with ⟨u, hu, p, Hp⟩ refine ⟨u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp intro z hz m hm refine ⟨u, ?_, fun x : E => (p x).shift, Hp.2.2.of_le hm⟩ -- Porting note: without the explicit arguments `convert` can not determine the type. convert @self_mem_nhdsWithin _ _ z u exact insert_eq_of_mem hz · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt] rcases h x hx with ⟨u, u_nhbd, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f', hu, hf' x this⟩ #align cont_diff_on_succ_iff_has_fderiv_within_at contDiffOn_succ_iff_hasFDerivWithinAt /-! ### Iterated derivative within a set -/ variable (𝕜) /-- The `n`-th derivative of a function along a set, defined inductively by saying that the `n+1`-th derivative of `f` is the derivative of the `n`-th derivative of `f` along this set, together with an uncurrying step to see it as a multilinear map in `n+1` variables.. -/ noncomputable def iteratedFDerivWithin (n : ℕ) (f : E → F) (s : Set E) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderivWithin 𝕜 rec s x) #align iterated_fderiv_within iteratedFDerivWithin /-- Formal Taylor series associated to a function within a set. -/ def ftaylorSeriesWithin (f : E → F) (s : Set E) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDerivWithin 𝕜 n f s x #align ftaylor_series_within ftaylorSeriesWithin variable {𝕜} @[simp] theorem iteratedFDerivWithin_zero_apply (m : Fin 0 → E) : (iteratedFDerivWithin 𝕜 0 f s x : (Fin 0 → E) → F) m = f x := rfl #align iterated_fderiv_within_zero_apply iteratedFDerivWithin_zero_apply theorem iteratedFDerivWithin_zero_eq_comp : iteratedFDerivWithin 𝕜 0 f s = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl #align iterated_fderiv_within_zero_eq_comp iteratedFDerivWithin_zero_eq_comp @[simp] theorem norm_iteratedFDerivWithin_zero : ‖iteratedFDerivWithin 𝕜 0 f s x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_within_zero norm_iteratedFDerivWithin_zero theorem iteratedFDerivWithin_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl #align iterated_fderiv_within_succ_apply_left iteratedFDerivWithin_succ_apply_left /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_left {n : ℕ} : iteratedFDerivWithin 𝕜 (n + 1) f s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F : (E →L[𝕜] (E [×n]→L[𝕜] F)) → (E [×n.succ]→L[𝕜] F)) ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s := rfl #align iterated_fderiv_within_succ_eq_comp_left iteratedFDerivWithin_succ_eq_comp_left theorem fderivWithin_iteratedFDerivWithin {s : Set E} {n : ℕ} : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDerivWithin 𝕜 (n + 1) f s := by rw [iteratedFDerivWithin_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] theorem norm_fderivWithin_iteratedFDerivWithin {n : ℕ} : ‖fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] #align norm_fderiv_within_iterated_fderiv_within norm_fderivWithin_iteratedFDerivWithin theorem iteratedFDerivWithin_succ_apply_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last n)) := by induction' n with n IH generalizing x · rw [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, iteratedFDerivWithin_zero_apply, Function.comp_apply, LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl · let I := continuousMultilinearCurryRightEquiv' 𝕜 n E F have A : ∀ y ∈ s, iteratedFDerivWithin 𝕜 n.succ f s y = (I ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) y := fun y hy ↦ by ext m rw [@IH y hy m] rfl calc (iteratedFDerivWithin 𝕜 (n + 2) f s x : (Fin (n + 2) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n.succ f s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := rfl _ = (fderivWithin 𝕜 (I ∘ iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by rw [fderivWithin_congr A (A x hx)] _ = (I ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119 we need to either use `set_option maxSynthPendingDepth 2 in` or fill in an explicit argument as ``` simp only [LinearIsometryEquiv.comp_fderivWithin _ (f := iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) (hs x hx)] ``` -/ set_option maxSynthPendingDepth 2 in simp only [LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl _ = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) s x : E → E[×n]→L[𝕜] E →L[𝕜] F) (m 0) (init (tail m)) ((tail m) (last n)) := rfl _ = iteratedFDerivWithin 𝕜 (Nat.succ n) (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last (n + 1))) := by rw [iteratedFDerivWithin_succ_apply_left, tail_init_eq_init_tail] rfl #align iterated_fderiv_within_succ_apply_right iteratedFDerivWithin_succ_apply_right /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) f s x = (continuousMultilinearCurryRightEquiv' 𝕜 n E F ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) x := by ext m; rw [iteratedFDerivWithin_succ_apply_right hs hx]; rfl #align iterated_fderiv_within_succ_eq_comp_right iteratedFDerivWithin_succ_eq_comp_right theorem norm_iteratedFDerivWithin_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : ‖iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_within_fderiv_within norm_iteratedFDerivWithin_fderivWithin @[simp] theorem iteratedFDerivWithin_one_apply (h : UniqueDiffWithinAt 𝕜 s x) (m : Fin 1 → E) : iteratedFDerivWithin 𝕜 1 f s x m = fderivWithin 𝕜 f s x (m 0) := by simp only [iteratedFDerivWithin_succ_apply_left, iteratedFDerivWithin_zero_eq_comp, (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_fderivWithin h] rfl #align iterated_fderiv_within_one_apply iteratedFDerivWithin_one_apply /-- On a set of unique differentiability, the second derivative is obtained by taking the derivative of the derivative. -/ lemma iteratedFDerivWithin_two_apply (f : E → F) {z : E} (hs : UniqueDiffOn 𝕜 s) (hz : z ∈ s) (m : Fin 2 → E) : iteratedFDerivWithin 𝕜 2 f s z m = fderivWithin 𝕜 (fderivWithin 𝕜 f s) s z (m 0) (m 1) := by simp only [iteratedFDerivWithin_succ_apply_right hs hz] rfl theorem Filter.EventuallyEq.iteratedFDerivWithin' (h : f₁ =ᶠ[𝓝[s] x] f) (ht : t ⊆ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ t =ᶠ[𝓝[s] x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn · exact h.mono fun y hy => DFunLike.ext _ _ fun _ => hy · have : fderivWithin 𝕜 _ t =ᶠ[𝓝[s] x] fderivWithin 𝕜 _ t := ihn.fderivWithin' ht apply this.mono intro y hy simp only [iteratedFDerivWithin_succ_eq_comp_left, hy, (· ∘ ·)] #align filter.eventually_eq.iterated_fderiv_within' Filter.EventuallyEq.iteratedFDerivWithin' protected theorem Filter.EventuallyEq.iteratedFDerivWithin (h : f₁ =ᶠ[𝓝[s] x] f) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s =ᶠ[𝓝[s] x] iteratedFDerivWithin 𝕜 n f s := h.iteratedFDerivWithin' Subset.rfl n #align filter.eventually_eq.iterated_fderiv_within Filter.EventuallyEq.iteratedFDerivWithin /-- If two functions coincide in a neighborhood of `x` within a set `s` and at `x`, then their iterated differentials within this set at `x` coincide. -/ theorem Filter.EventuallyEq.iteratedFDerivWithin_eq (h : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := have : f₁ =ᶠ[𝓝[insert x s] x] f := by simpa [EventuallyEq, hx] (this.iteratedFDerivWithin' (subset_insert _ _) n).self_of_nhdsWithin (mem_insert _ _) #align filter.eventually_eq.iterated_fderiv_within_eq Filter.EventuallyEq.iteratedFDerivWithin_eq /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ theorem iteratedFDerivWithin_congr (hs : EqOn f₁ f s) (hx : x ∈ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := (hs.eventuallyEq.filter_mono inf_le_right).iteratedFDerivWithin_eq (hs hx) _ #align iterated_fderiv_within_congr iteratedFDerivWithin_congr /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ protected theorem Set.EqOn.iteratedFDerivWithin (hs : EqOn f₁ f s) (n : ℕ) : EqOn (iteratedFDerivWithin 𝕜 n f₁ s) (iteratedFDerivWithin 𝕜 n f s) s := fun _x hx => iteratedFDerivWithin_congr hs hx n #align set.eq_on.iterated_fderiv_within Set.EqOn.iteratedFDerivWithin theorem iteratedFDerivWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn generalizing x · rfl · refine (eventually_nhds_nhdsWithin.2 h).mono fun y hy => ?_ simp only [iteratedFDerivWithin_succ_eq_comp_left, (· ∘ ·)] rw [(ihn hy).fderivWithin_eq_nhds, fderivWithin_congr_set' _ hy] #align iterated_fderiv_within_eventually_congr_set' iteratedFDerivWithin_eventually_congr_set' theorem iteratedFDerivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 n f t := iteratedFDerivWithin_eventually_congr_set' x (h.filter_mono inf_le_left) n #align iterated_fderiv_within_eventually_congr_set iteratedFDerivWithin_eventually_congr_set theorem iteratedFDerivWithin_congr_set (h : s =ᶠ[𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (iteratedFDerivWithin_eventually_congr_set h n).self_of_nhds #align iterated_fderiv_within_congr_set iteratedFDerivWithin_congr_set /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x` within `s`. -/ theorem iteratedFDerivWithin_inter' {n : ℕ} (hu : u ∈ 𝓝[s] x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_congr_set (nhdsWithin_eq_iff_eventuallyEq.1 <| nhdsWithin_inter_of_mem' hu) _ #align iterated_fderiv_within_inter' iteratedFDerivWithin_inter' /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x`. -/ theorem iteratedFDerivWithin_inter {n : ℕ} (hu : u ∈ 𝓝 x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter' (mem_nhdsWithin_of_mem_nhds hu) #align iterated_fderiv_within_inter iteratedFDerivWithin_inter /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with an open set containing `x`. -/ theorem iteratedFDerivWithin_inter_open {n : ℕ} (hu : IsOpen u) (hx : x ∈ u) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter (hu.mem_nhds hx) #align iterated_fderiv_within_inter_open iteratedFDerivWithin_inter_open @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => ?_⟩ intro x hx m hm have : (m : ℕ∞) = 0 := le_antisymm hm bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ #align cont_diff_on_zero contDiffOn_zero theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' #align cont_diff_within_at_zero contDiffWithinAt_zero /-- On a set with unique differentiability, any choice of iterated differential has to coincide with the one we have chosen in `iteratedFDerivWithin 𝕜 m f s`. -/ theorem HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn (h : HasFTaylorSeriesUpToOn n f p s) {m : ℕ} (hmn : (m : ℕ∞) ≤ n) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : p x m = iteratedFDerivWithin 𝕜 m f s x := by induction' m with m IH generalizing x · rw [h.zero_eq' hx, iteratedFDerivWithin_zero_eq_comp]; rfl · have A : (m : ℕ∞) < n := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (lt_add_one m)) hmn have : HasFDerivWithinAt (fun y : E => iteratedFDerivWithin 𝕜 m f s y) (ContinuousMultilinearMap.curryLeft (p x (Nat.succ m))) s x := (h.fderivWithin m A x hx).congr (fun y hy => (IH (le_of_lt A) hy).symm) (IH (le_of_lt A) hx).symm rw [iteratedFDerivWithin_succ_eq_comp_left, Function.comp_apply, this.fderivWithin (hs x hx)] exact (ContinuousMultilinearMap.uncurry_curryLeft _).symm #align has_ftaylor_series_up_to_on.eq_ftaylor_series_of_unique_diff_on HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn @[deprecated] alias HasFTaylorSeriesUpToOn.eq_ftaylor_series_of_uniqueDiffOn := HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn -- 2024-03-28 /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx rcases (h x hx) m.succ (ENat.add_one_le_of_lt hm) with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (WithTop.coe_le_coe.2 (Nat.le_succ m)) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases h x hx m hm with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm #align cont_diff_on.ftaylor_series_within ContDiffOn.ftaylorSeriesWithin theorem contDiffOn_of_continuousOn_differentiableOn (Hcont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le hk hm) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans hk hm) #align cont_diff_on_of_continuous_on_differentiable_on contDiffOn_of_continuousOn_differentiableOn theorem contDiffOn_of_differentiableOn (h : ∀ m : ℕ, (m : ℕ∞) ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) #align cont_diff_on_of_differentiable_on contDiffOn_of_differentiableOn theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := (h.ftaylorSeriesWithin hs).cont m hmn #align cont_diff_on.continuous_on_iterated_fderiv_within ContDiffOn.continuousOn_iteratedFDerivWithin theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := fun x hx => ((h.ftaylorSeriesWithin hs).fderivWithin m hmn x hx).differentiableWithinAt #align cont_diff_on.differentiable_on_iterated_fderiv_within ContDiffOn.differentiableOn_iteratedFDerivWithin theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by rcases h.contDiffOn' (ENat.add_one_le_of_lt hmn) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds #align cont_diff_within_at.differentiable_within_at_iterated_fderiv_within ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin theorem contDiffOn_iff_continuousOn_differentiableOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin hm hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin hm hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ #align cont_diff_on_iff_continuous_on_differentiable_on contDiffOn_iff_continuousOn_differentiableOn theorem contDiffOn_succ_of_fderivWithin {n : ℕ} (hf : DifferentiableOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s := by intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ #align cont_diff_on_succ_of_fderiv_within contDiffOn_succ_of_fderivWithin /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s := by refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2⟩ refine ⟨H.differentiableOn (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)), fun x hx => ?_⟩ rcases contDiffWithinAt_succ_iff_hasFDerivWithinAt.1 (H x hx) with ⟨u, hu, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventually_eq' _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A #align cont_diff_on_succ_iff_fderiv_within contDiffOn_succ_iff_fderivWithin theorem contDiffOn_succ_iff_hasFDerivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟨fun h => ⟨fderivWithin 𝕜 f s, h.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun h => ?_⟩ rcases h with ⟨f', h1, h2⟩ refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, fun x hx => ?_⟩ exact (h1 x hx).congr' (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx #align cont_diff_on_succ_iff_has_fderiv_within contDiffOn_succ_iff_hasFDerivWithin /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen {n : ℕ} (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and (contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx) #align cont_diff_on_succ_iff_fderiv_of_open contDiffOn_succ_iff_fderiv_of_isOpen /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderivWithin 𝕜 f s y) s := by constructor · intro h refine ⟨h.differentiableOn le_top, ?_⟩ refine contDiffOn_top.2 fun n => ((contDiffOn_succ_iff_fderivWithin hs).1 ?_).2 exact h.of_le le_top · intro h refine contDiffOn_top.2 fun n => ?_ have A : (n : ℕ∞) ≤ ∞ := le_top apply ((contDiffOn_succ_iff_fderivWithin hs).2 ⟨h.1, h.2.of_le A⟩).of_le exact WithTop.coe_le_coe.2 (Nat.le_succ n) #align cont_diff_on_top_iff_fderiv_within contDiffOn_top_iff_fderivWithin /-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_top_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and <| contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx #align cont_diff_on_top_iff_fderiv_of_open contDiffOn_top_iff_fderiv_of_isOpen protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fun y => fderivWithin 𝕜 f s y) s := by cases' m with m · change ∞ + 1 ≤ n at hmn have : n = ∞ := by simpa using hmn rw [this] at hf exact ((contDiffOn_top_iff_fderivWithin hs).1 hf).2 · change (m.succ : ℕ∞) ≤ n at hmn exact ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2 #align cont_diff_on.fderiv_within ContDiffOn.fderivWithin theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fun y => fderiv 𝕜 f y) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm #align cont_diff_on.fderiv_of_open ContDiffOn.fderiv_of_isOpen theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fun x => fderivWithin 𝕜 f s x) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le hn)).2.continuousOn #align cont_diff_on.continuous_on_fderiv_within ContDiffOn.continuousOn_fderivWithin theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≤ n) : ContinuousOn (fun x => fderiv 𝕜 f x) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le hn)).2.continuousOn #align cont_diff_on.continuous_on_fderiv_of_open ContDiffOn.continuousOn_fderiv_of_isOpen /-! ### Functions with a Taylor series on the whole space -/ /-- `HasFTaylorSeriesUpTo n f p` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an addition `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpTo (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) : Prop where zero_eq : ∀ x, (p x 0).uncurry0 = f x fderiv : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x, HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → Continuous fun x => p x m #align has_ftaylor_series_up_to HasFTaylorSeriesUpTo theorem HasFTaylorSeriesUpTo.zero_eq' (h : HasFTaylorSeriesUpTo n f p) (x : E) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to.zero_eq' HasFTaylorSeriesUpTo.zero_eq' theorem hasFTaylorSeriesUpToOn_univ_iff : HasFTaylorSeriesUpToOn n f p univ ↔ HasFTaylorSeriesUpTo n f p := by constructor · intro H constructor · exact fun x => H.zero_eq x (mem_univ x) · intro m hm x rw [← hasFDerivWithinAt_univ] exact H.fderivWithin m hm x (mem_univ x) · intro m hm rw [continuous_iff_continuousOn_univ] exact H.cont m hm · intro H constructor · exact fun x _ => H.zero_eq x · intro m hm x _ rw [hasFDerivWithinAt_univ] exact H.fderiv m hm x · intro m hm rw [← continuous_iff_continuousOn_univ] exact H.cont m hm #align has_ftaylor_series_up_to_on_univ_iff hasFTaylorSeriesUpToOn_univ_iff theorem HasFTaylorSeriesUpTo.hasFTaylorSeriesUpToOn (h : HasFTaylorSeriesUpTo n f p) (s : Set E) : HasFTaylorSeriesUpToOn n f p s := (hasFTaylorSeriesUpToOn_univ_iff.2 h).mono (subset_univ _) #align has_ftaylor_series_up_to.has_ftaylor_series_up_to_on HasFTaylorSeriesUpTo.hasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpTo.ofLe (h : HasFTaylorSeriesUpTo n f p) (hmn : m ≤ n) : HasFTaylorSeriesUpTo m f p := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h ⊢; exact h.of_le hmn #align has_ftaylor_series_up_to.of_le HasFTaylorSeriesUpTo.ofLe theorem HasFTaylorSeriesUpTo.continuous (h : HasFTaylorSeriesUpTo n f p) : Continuous f := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h rw [continuous_iff_continuousOn_univ] exact h.continuousOn #align has_ftaylor_series_up_to.continuous HasFTaylorSeriesUpTo.continuous theorem hasFTaylorSeriesUpTo_zero_iff : HasFTaylorSeriesUpTo 0 f p ↔ Continuous f ∧ ∀ x, (p x 0).uncurry0 = f x := by simp [hasFTaylorSeriesUpToOn_univ_iff.symm, continuous_iff_continuousOn_univ, hasFTaylorSeriesUpToOn_zero_iff] #align has_ftaylor_series_up_to_zero_iff hasFTaylorSeriesUpTo_zero_iff theorem hasFTaylorSeriesUpTo_top_iff : HasFTaylorSeriesUpTo ∞ f p ↔ ∀ n : ℕ, HasFTaylorSeriesUpTo n f p := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff] #align has_ftaylor_series_up_to_top_iff hasFTaylorSeriesUpTo_top_iff /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpTo`. -/ theorem hasFTaylorSeriesUpTo_top_iff' : HasFTaylorSeriesUpTo ∞ f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ ∀ (m : ℕ) (x), HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff', mem_univ, forall_true_left, hasFDerivWithinAt_univ] #align has_ftaylor_series_up_to_top_iff' hasFTaylorSeriesUpTo_top_iff' /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpTo.hasFDerivAt (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≤ n) (x : E) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := by rw [← hasFDerivWithinAt_univ] exact (hasFTaylorSeriesUpToOn_univ_iff.2 h).hasFDerivWithinAt hn (mem_univ _) #align has_ftaylor_series_up_to.has_fderiv_at HasFTaylorSeriesUpTo.hasFDerivAt theorem HasFTaylorSeriesUpTo.differentiable (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≤ n) : Differentiable 𝕜 f := fun x => (h.hasFDerivAt hn x).differentiableAt #align has_ftaylor_series_up_to.differentiable HasFTaylorSeriesUpTo.differentiable /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpTo_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpTo (n + 1 : ℕ) f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ (∀ x, HasFDerivAt (fun y => p y 0) (p x 1).curryLeft x) ∧ HasFTaylorSeriesUpTo n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) fun x => (p x).shift := by simp only [hasFTaylorSeriesUpToOn_succ_iff_right, ← hasFTaylorSeriesUpToOn_univ_iff, mem_univ, forall_true_left, hasFDerivWithinAt_univ] #align has_ftaylor_series_up_to_succ_iff_right hasFTaylorSeriesUpTo_succ_iff_right /-! ### Smooth functions at a point -/ variable (𝕜) /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x #align cont_diff_at ContDiffAt variable {𝕜} theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl #align cont_diff_within_at_univ contDiffWithinAt_univ theorem contDiffAt_top : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by simp [← contDiffWithinAt_univ, contDiffWithinAt_top] #align cont_diff_at_top contDiffAt_top theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x := h.mono (subset_univ _) #align cont_diff_at.cont_diff_within_at ContDiffAt.contDiffWithinAt theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter] #align cont_diff_within_at.cont_diff_at ContDiffWithinAt.contDiffAt -- Porting note (#10756): new lemma theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := (h _ (mem_of_mem_nhds hx)).contDiffAt hx theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) : ContDiffAt 𝕜 n f₁ x := h.congr_of_eventually_eq' (by rwa [nhdsWithin_univ]) (mem_univ x) #align cont_diff_at.congr_of_eventually_eq ContDiffAt.congr_of_eventuallyEq theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x := ContDiffWithinAt.of_le h hmn #align cont_diff_at.of_le ContDiffAt.of_le theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by simpa [continuousWithinAt_univ] using h.continuousWithinAt #align cont_diff_at.continuous_at ContDiffAt.continuousAt /-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/ theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) : DifferentiableAt 𝕜 f x := by simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt #align cont_diff_at.differentiable_at ContDiffAt.differentiableAt nonrec lemma ContDiffAt.contDiffOn {m : ℕ} (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) : ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by simpa [nhdsWithin_univ] using h.contDiffOn hm /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} : ContDiffAt 𝕜 (n + 1 : ℕ) f x ↔ ∃ f' : E → E →L[𝕜] F, (∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt] simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem] constructor · rintro ⟨u, H, f', h_fderiv, h_cont_diff⟩ rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩ refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩ refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩ intro y hyt refine (h_fderiv y (htu hyt)).hasFDerivAt ?_ exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩ · rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩ refine ⟨u, H, f', ?_, h_cont_diff.contDiffWithinAt⟩ intro x hxu exact (h_fderiv x hxu).hasFDerivWithinAt #align cont_diff_at_succ_iff_has_fderiv_at contDiffAt_succ_iff_hasFDerivAt protected theorem ContDiffAt.eventually {n : ℕ} (h : ContDiffAt 𝕜 n f x) : ∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h #align cont_diff_at.eventually ContDiffAt.eventually /-! ### Smooth functions -/ variable (𝕜) /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ def ContDiff (n : ℕ∞) (f : E → F) : Prop := ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p #align cont_diff ContDiff variable {𝕜} /-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/ theorem HasFTaylorSeriesUpTo.contDiff {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f := ⟨f', hf⟩ #align has_ftaylor_series_up_to.cont_diff HasFTaylorSeriesUpTo.contDiff theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] exact H.ftaylorSeriesWithin uniqueDiffOn_univ · rintro ⟨p, hp⟩ x _ m hm exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le hm⟩ #align cont_diff_on_univ contDiffOn_univ theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by simp [← contDiffOn_univ, ContDiffOn, ContDiffAt] #align cont_diff_iff_cont_diff_at contDiff_iff_contDiffAt theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x := contDiff_iff_contDiffAt.1 h x #align cont_diff.cont_diff_at ContDiff.contDiffAt theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x := h.contDiffAt.contDiffWithinAt #align cont_diff.cont_diff_within_at ContDiff.contDiffWithinAt theorem contDiff_top : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp [contDiffOn_univ.symm, contDiffOn_top] #align cont_diff_top contDiff_top theorem contDiff_all_iff_nat : (∀ n, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, contDiffOn_all_iff_nat] #align cont_diff_all_iff_nat contDiff_all_iff_nat theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s := (contDiffOn_univ.2 h).mono (subset_univ _) #align cont_diff.cont_diff_on ContDiff.contDiffOn @[simp] theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by rw [← contDiffOn_univ, continuous_iff_continuousOn_univ] exact contDiffOn_zero #align cont_diff_zero contDiff_zero theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ] #align cont_diff_at_zero contDiffAt_zero theorem contDiffAt_one_iff : ContDiffAt 𝕜 1 f x ↔ ∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by simp_rw [show (1 : ℕ∞) = (0 + 1 : ℕ) from (zero_add 1).symm, contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : ℕ∞) = 0 from rfl, contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm] #align cont_diff_at_one_iff contDiffAt_one_iff theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f := contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn #align cont_diff.of_le ContDiff.of_le theorem ContDiff.of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f := h.of_le <| WithTop.coe_le_coe.mpr le_self_add #align cont_diff.of_succ ContDiff.of_succ theorem ContDiff.one_of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := h.of_le <| WithTop.coe_le_coe.mpr le_add_self #align cont_diff.one_of_succ ContDiff.one_of_succ theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f := contDiff_zero.1 (h.of_le bot_le) #align cont_diff.continuous ContDiff.continuous /-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/ theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Differentiable 𝕜 f := differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn #align cont_diff.differentiable ContDiff.differentiable theorem contDiff_iff_forall_nat_le : ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≤ n → ContDiff 𝕜 m f := by simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le #align cont_diff_iff_forall_nat_le contDiff_iff_forall_nat_le /-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/ theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} : ContDiff 𝕜 (n + 1 : ℕ) f ↔ ∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, contDiffOn_succ_iff_hasFDerivWithin uniqueDiffOn_univ, Set.mem_univ, forall_true_left] #align cont_diff_succ_iff_has_fderiv contDiff_succ_iff_hasFDerivAt /-! ### Iterated derivative -/ variable (𝕜) /-- The `n`-th derivative of a function, as a multilinear map, defined inductively. -/ noncomputable def iteratedFDeriv (n : ℕ) (f : E → F) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderiv 𝕜 rec x) #align iterated_fderiv iteratedFDeriv /-- Formal Taylor series associated to a function. -/ def ftaylorSeries (f : E → F) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDeriv 𝕜 n f x #align ftaylor_series ftaylorSeries variable {𝕜} @[simp] theorem iteratedFDeriv_zero_apply (m : Fin 0 → E) : (iteratedFDeriv 𝕜 0 f x : (Fin 0 → E) → F) m = f x := rfl #align iterated_fderiv_zero_apply iteratedFDeriv_zero_apply theorem iteratedFDeriv_zero_eq_comp : iteratedFDeriv 𝕜 0 f = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl #align iterated_fderiv_zero_eq_comp iteratedFDeriv_zero_eq_comp @[simp] theorem norm_iteratedFDeriv_zero : ‖iteratedFDeriv 𝕜 0 f x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_zero norm_iteratedFDeriv_zero theorem iteratedFDerivWithin_zero_eq : iteratedFDerivWithin 𝕜 0 f s = iteratedFDeriv 𝕜 0 f := rfl #align iterated_fderiv_with_zero_eq iteratedFDerivWithin_zero_eq theorem iteratedFDeriv_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDeriv 𝕜 (n + 1) f x : (Fin (n + 1) → E) → F) m = (fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl #align iterated_fderiv_succ_apply_left iteratedFDeriv_succ_apply_left /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDeriv_succ_eq_comp_left {n : ℕ} : iteratedFDeriv 𝕜 (n + 1) f = continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F ∘ fderiv 𝕜 (iteratedFDeriv 𝕜 n f) := rfl #align iterated_fderiv_succ_eq_comp_left iteratedFDeriv_succ_eq_comp_left /-- Writing explicitly the derivative of the `n`-th derivative as the composition of a currying linear equiv, and the `n + 1`-th derivative. -/ theorem fderiv_iteratedFDeriv {n : ℕ} : fderiv 𝕜 (iteratedFDeriv 𝕜 n f) = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDeriv 𝕜 (n + 1) f := by rw [iteratedFDeriv_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] #align fderiv_iterated_fderiv fderiv_iteratedFDeriv theorem tsupport_iteratedFDeriv_subset (n : ℕ) : tsupport (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans subset_closure) isClosed_closure · rw [iteratedFDeriv_succ_eq_comp_left] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans ((support_fderiv_subset 𝕜).trans IH)) isClosed_closure theorem support_iteratedFDeriv_subset (n : ℕ) : support (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := subset_closure.trans (tsupport_iteratedFDeriv_subset n) theorem HasCompactSupport.iteratedFDeriv (hf : HasCompactSupport f) (n : ℕ) : HasCompactSupport (iteratedFDeriv 𝕜 n f) := hf.of_isClosed_subset isClosed_closure (tsupport_iteratedFDeriv_subset n) #align has_compact_support.iterated_fderiv HasCompactSupport.iteratedFDeriv theorem norm_fderiv_iteratedFDeriv {n : ℕ} : ‖fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x‖ = ‖iteratedFDeriv 𝕜 (n + 1) f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] #align norm_fderiv_iterated_fderiv norm_fderiv_iteratedFDeriv theorem iteratedFDerivWithin_univ {n : ℕ} : iteratedFDerivWithin 𝕜 n f univ = iteratedFDeriv 𝕜 n f := by induction' n with n IH · ext x; simp · ext x m rw [iteratedFDeriv_succ_apply_left, iteratedFDerivWithin_succ_apply_left, IH, fderivWithin_univ] #align iterated_fderiv_within_univ iteratedFDerivWithin_univ theorem HasFTaylorSeriesUpTo.eq_iteratedFDeriv (h : HasFTaylorSeriesUpTo n f p) {m : ℕ} (hmn : (m : ℕ∞) ≤ n) (x : E) : p x m = iteratedFDeriv 𝕜 m f x := by rw [← iteratedFDerivWithin_univ] rw [← hasFTaylorSeriesUpToOn_univ_iff] at h exact h.eq_iteratedFDerivWithin_of_uniqueDiffOn hmn uniqueDiffOn_univ (mem_univ _) /-- In an open set, the iterated derivative within this set coincides with the global iterated derivative. -/ theorem iteratedFDerivWithin_of_isOpen (n : ℕ) (hs : IsOpen s) : EqOn (iteratedFDerivWithin 𝕜 n f s) (iteratedFDeriv 𝕜 n f) s := by induction' n with n IH · intro x _ ext1 simp only [Nat.zero_eq, iteratedFDerivWithin_zero_apply, iteratedFDeriv_zero_apply] · intro x hx rw [iteratedFDeriv_succ_eq_comp_left, iteratedFDerivWithin_succ_eq_comp_left] dsimp congr 1 rw [fderivWithin_of_isOpen hs hx] apply Filter.EventuallyEq.fderiv_eq filter_upwards [hs.mem_nhds hx] exact IH #align iterated_fderiv_within_of_is_open iteratedFDerivWithin_of_isOpen theorem ftaylorSeriesWithin_univ : ftaylorSeriesWithin 𝕜 f univ = ftaylorSeries 𝕜 f := by ext1 x; ext1 n change iteratedFDerivWithin 𝕜 n f univ x = iteratedFDeriv 𝕜 n f x rw [iteratedFDerivWithin_univ] #align ftaylor_series_within_univ ftaylorSeriesWithin_univ theorem iteratedFDeriv_succ_apply_right {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDeriv 𝕜 (n + 1) f x : (Fin (n + 1) → E) → F) m = iteratedFDeriv 𝕜 n (fun y => fderiv 𝕜 f y) x (init m) (m (last n)) := by rw [← iteratedFDerivWithin_univ, ← iteratedFDerivWithin_univ, ← fderivWithin_univ] exact iteratedFDerivWithin_succ_apply_right uniqueDiffOn_univ (mem_univ _) _ #align iterated_fderiv_succ_apply_right iteratedFDeriv_succ_apply_right /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ theorem iteratedFDeriv_succ_eq_comp_right {n : ℕ} : iteratedFDeriv 𝕜 (n + 1) f x = (continuousMultilinearCurryRightEquiv' 𝕜 n E F ∘ iteratedFDeriv 𝕜 n fun y => fderiv 𝕜 f y) x := by ext m; rw [iteratedFDeriv_succ_apply_right]; rfl #align iterated_fderiv_succ_eq_comp_right iteratedFDeriv_succ_eq_comp_right theorem norm_iteratedFDeriv_fderiv {n : ℕ} : ‖iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x‖ = ‖iteratedFDeriv 𝕜 (n + 1) f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_succ_eq_comp_right, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_fderiv norm_iteratedFDeriv_fderiv @[simp] theorem iteratedFDeriv_one_apply (m : Fin 1 → E) : iteratedFDeriv 𝕜 1 f x m = fderiv 𝕜 f x (m 0) := by rw [iteratedFDeriv_succ_apply_right, iteratedFDeriv_zero_apply]; rfl #align iterated_fderiv_one_apply iteratedFDeriv_one_apply lemma iteratedFDeriv_two_apply (f : E → F) (z : E) (m : Fin 2 → E) : iteratedFDeriv 𝕜 2 f z m = fderiv 𝕜 (fderiv 𝕜 f) z (m 0) (m 1) := by simp only [iteratedFDeriv_succ_apply_right] rfl /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ theorem contDiff_iff_ftaylorSeries : ContDiff 𝕜 n f ↔ HasFTaylorSeriesUpTo n f (ftaylorSeries 𝕜 f) := by constructor · rw [← contDiffOn_univ, ← hasFTaylorSeriesUpToOn_univ_iff, ← ftaylorSeriesWithin_univ] exact fun h => ContDiffOn.ftaylorSeriesWithin h uniqueDiffOn_univ · intro h; exact ⟨ftaylorSeries 𝕜 f, h⟩ #align cont_diff_iff_ftaylor_series contDiff_iff_ftaylorSeries
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
1,709
1,714
theorem contDiff_iff_continuous_differentiable : ContDiff 𝕜 n f ↔ (∀ m : ℕ, (m : ℕ∞) ≤ n → Continuous fun x => iteratedFDeriv 𝕜 m f x) ∧ ∀ m : ℕ, (m : ℕ∞) < n → Differentiable 𝕜 fun x => iteratedFDeriv 𝕜 m f x := by
simp [contDiffOn_univ.symm, continuous_iff_continuousOn_univ, differentiableOn_univ.symm, iteratedFDerivWithin_univ, contDiffOn_iff_continuousOn_differentiableOn uniqueDiffOn_univ]
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Polynomial.Eval import Mathlib.RingTheory.Ideal.Quotient #align_import linear_algebra.smodeq from "leanprover-community/mathlib"@"146d3d1fa59c091fedaad8a4afa09d6802886d24" /-! # modular equivalence for submodule -/ open Submodule open Polynomial variable {R : Type*} [Ring R] variable {A : Type*} [CommRing A] variable {M : Type*} [AddCommGroup M] [Module R M] (U U₁ U₂ : Submodule R M) variable {x x₁ x₂ y y₁ y₂ z z₁ z₂ : M} variable {N : Type*} [AddCommGroup N] [Module R N] (V V₁ V₂ : Submodule R N) set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 /-- A predicate saying two elements of a module are equivalent modulo a submodule. -/ def SModEq (x y : M) : Prop := (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y #align smodeq SModEq notation:50 x " ≡ " y " [SMOD " N "]" => SModEq N x y variable {U U₁ U₂} set_option backward.isDefEq.lazyWhnfCore false in -- See https://github.com/leanprover-community/mathlib4/issues/12534 protected theorem SModEq.def : x ≡ y [SMOD U] ↔ (Submodule.Quotient.mk x : M ⧸ U) = Submodule.Quotient.mk y := Iff.rfl #align smodeq.def SModEq.def namespace SModEq theorem sub_mem : x ≡ y [SMOD U] ↔ x - y ∈ U := by rw [SModEq.def, Submodule.Quotient.eq] #align smodeq.sub_mem SModEq.sub_mem @[simp] theorem top : x ≡ y [SMOD (⊤ : Submodule R M)] := (Submodule.Quotient.eq ⊤).2 mem_top #align smodeq.top SModEq.top @[simp] theorem bot : x ≡ y [SMOD (⊥ : Submodule R M)] ↔ x = y := by rw [SModEq.def, Submodule.Quotient.eq, mem_bot, sub_eq_zero] #align smodeq.bot SModEq.bot @[mono] theorem mono (HU : U₁ ≤ U₂) (hxy : x ≡ y [SMOD U₁]) : x ≡ y [SMOD U₂] := (Submodule.Quotient.eq U₂).2 <| HU <| (Submodule.Quotient.eq U₁).1 hxy #align smodeq.mono SModEq.mono @[refl] protected theorem refl (x : M) : x ≡ x [SMOD U] := @rfl _ _ #align smodeq.refl SModEq.refl protected theorem rfl : x ≡ x [SMOD U] := SModEq.refl _ #align smodeq.rfl SModEq.rfl instance : IsRefl _ (SModEq U) := ⟨SModEq.refl⟩ @[symm] nonrec theorem symm (hxy : x ≡ y [SMOD U]) : y ≡ x [SMOD U] := hxy.symm #align smodeq.symm SModEq.symm @[trans] nonrec theorem trans (hxy : x ≡ y [SMOD U]) (hyz : y ≡ z [SMOD U]) : x ≡ z [SMOD U] := hxy.trans hyz #align smodeq.trans SModEq.trans instance instTrans : Trans (SModEq U) (SModEq U) (SModEq U) where trans := trans theorem add (hxy₁ : x₁ ≡ y₁ [SMOD U]) (hxy₂ : x₂ ≡ y₂ [SMOD U]) : x₁ + x₂ ≡ y₁ + y₂ [SMOD U] := by rw [SModEq.def] at hxy₁ hxy₂ ⊢ simp_rw [Quotient.mk_add, hxy₁, hxy₂] #align smodeq.add SModEq.add theorem smul (hxy : x ≡ y [SMOD U]) (c : R) : c • x ≡ c • y [SMOD U] := by rw [SModEq.def] at hxy ⊢ simp_rw [Quotient.mk_smul, hxy] #align smodeq.smul SModEq.smul theorem mul {I : Ideal A} {x₁ x₂ y₁ y₂ : A} (hxy₁ : x₁ ≡ y₁ [SMOD I]) (hxy₂ : x₂ ≡ y₂ [SMOD I]) : x₁ * x₂ ≡ y₁ * y₂ [SMOD I] := by simp only [SModEq.def, Ideal.Quotient.mk_eq_mk, map_mul] at hxy₁ hxy₂ ⊢ rw [hxy₁, hxy₂] theorem zero : x ≡ 0 [SMOD U] ↔ x ∈ U := by rw [SModEq.def, Submodule.Quotient.eq, sub_zero] #align smodeq.zero SModEq.zero theorem map (hxy : x ≡ y [SMOD U]) (f : M →ₗ[R] N) : f x ≡ f y [SMOD U.map f] := (Submodule.Quotient.eq _).2 <| f.map_sub x y ▸ mem_map_of_mem <| (Submodule.Quotient.eq _).1 hxy #align smodeq.map SModEq.map theorem comap {f : M →ₗ[R] N} (hxy : f x ≡ f y [SMOD V]) : x ≡ y [SMOD V.comap f] := (Submodule.Quotient.eq _).2 <| show f (x - y) ∈ V from (f.map_sub x y).symm ▸ (Submodule.Quotient.eq _).1 hxy #align smodeq.comap SModEq.comap
Mathlib/LinearAlgebra/SModEq.lean
114
119
theorem eval {R : Type*} [CommRing R] {I : Ideal R} {x y : R} (h : x ≡ y [SMOD I]) (f : R[X]) : f.eval x ≡ f.eval y [SMOD I] := by
rw [SModEq.def] at h ⊢ show Ideal.Quotient.mk I (f.eval x) = Ideal.Quotient.mk I (f.eval y) replace h : Ideal.Quotient.mk I x = Ideal.Quotient.mk I y := h rw [← Polynomial.eval₂_at_apply, ← Polynomial.eval₂_at_apply, h]
/- 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.Order.CompleteBooleanAlgebra import Mathlib.Order.Directed import Mathlib.Order.GaloisConnection #align_import data.set.lattice from "leanprover-community/mathlib"@"b86832321b586c6ac23ef8cdef6a7a27e42b13bd" /-! # The set lattice This file provides usual set notation for unions and intersections, a `CompleteLattice` instance for `Set α`, and some more set constructions. ## Main declarations * `Set.iUnion`: **i**ndexed **union**. Union of an indexed family of sets. * `Set.iInter`: **i**ndexed **inter**section. Intersection of an indexed family of sets. * `Set.sInter`: **s**et **inter**section. Intersection of sets belonging to a set of sets. * `Set.sUnion`: **s**et **union**. Union of sets belonging to a set of sets. * `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.BooleanAlgebra`. * `Set.kernImage`: For a function `f : α → β`, `s.kernImage f` is the set of `y` such that `f ⁻¹ y ⊆ s`. * `Set.seq`: Union of the image of a set under a **seq**uence of functions. `seq s t` is the union of `f '' t` over all `f ∈ s`, where `t : Set α` and `s : Set (α → β)`. * `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] #align set.mem_Union₂ Set.mem_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.mem_Inter₂ Set.mem_iInter₂ theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ #align set.mem_Union_of_mem Set.mem_iUnion_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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⟩ #align set.mem_Union₂_of_mem Set.mem_iUnion₂_of_mem theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h #align set.mem_Inter_of_mem Set.mem_iInter_of_mem /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.mem_Inter₂_of_mem Set.mem_iInter₂_of_mem instance completeAtomicBooleanAlgebra : CompleteAtomicBooleanAlgebra (Set α) := { instBooleanAlgebraSet with le_sSup := fun s t t_in a a_in => ⟨t, t_in, a_in⟩ sSup_le := fun s t h a ⟨t', ⟨t'_in, a_in⟩⟩ => h t' t'_in a_in le_sInf := fun s t h a a_in t' t'_in => h t' t'_in a_in sInf_le := fun s t t_in a h => h _ t_in iInf_iSup_eq := by intros; ext; simp [Classical.skolem] } section GaloisConnection variable {f : α → β} protected theorem image_preimage : GaloisConnection (image f) (preimage f) := fun _ _ => image_subset_iff #align set.image_preimage Set.image_preimage protected theorem preimage_kernImage : GaloisConnection (preimage f) (kernImage f) := fun _ _ => subset_kernImage_iff.symm #align set.preimage_kern_image Set.preimage_kernImage end GaloisConnection section kernImage variable {f : α → β} lemma kernImage_mono : Monotone (kernImage f) := Set.preimage_kernImage.monotone_u lemma kernImage_eq_compl {s : Set α} : kernImage f s = (f '' sᶜ)ᶜ := Set.preimage_kernImage.u_unique (Set.image_preimage.compl) (fun t ↦ compl_compl (f ⁻¹' t) ▸ Set.preimage_compl) lemma kernImage_compl {s : Set α} : kernImage f (sᶜ) = (f '' s)ᶜ := by rw [kernImage_eq_compl, compl_compl] lemma kernImage_empty : kernImage f ∅ = (range f)ᶜ := by rw [kernImage_eq_compl, compl_empty, image_univ] lemma kernImage_preimage_eq_iff {s : Set β} : kernImage f (f ⁻¹' s) = s ↔ (range f)ᶜ ⊆ s := by rw [kernImage_eq_compl, ← preimage_compl, compl_eq_comm, eq_comm, image_preimage_eq_iff, compl_subset_comm] lemma compl_range_subset_kernImage {s : Set α} : (range f)ᶜ ⊆ kernImage f s := by rw [← kernImage_empty] exact kernImage_mono (empty_subset _) lemma kernImage_union_preimage {s : Set α} {t : Set β} : kernImage f (s ∪ f ⁻¹' t) = kernImage f s ∪ t := by rw [kernImage_eq_compl, kernImage_eq_compl, compl_union, ← preimage_compl, image_inter_preimage, compl_inter, compl_compl] lemma kernImage_preimage_union {s : Set α} {t : Set β} : kernImage f (f ⁻¹' t ∪ s) = t ∪ kernImage f s := by rw [union_comm, kernImage_union_preimage, union_comm] end kernImage /-! ### Union and intersection over an indexed family of sets -/ instance : OrderTop (Set α) where top := univ le_top := by simp @[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 #align set.Union_congr_Prop Set.iUnion_congr_Prop @[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 #align set.Inter_congr_Prop Set.iInter_congr_Prop theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ #align set.Union_plift_up Set.iUnion_plift_up theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ #align set.Union_plift_down Set.iUnion_plift_down theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ #align set.Inter_plift_up Set.iInter_plift_up theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ #align set.Inter_plift_down Set.iInter_plift_down theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ #align set.Union_eq_if Set.iUnion_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 _ #align set.Union_eq_dif Set.iUnion_eq_dif theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ #align set.Inter_eq_if Set.iInter_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 _ #align set.Infi_eq_dif Set.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 #align set.exists_set_mem_of_union_eq_top Set.exists_set_mem_of_union_eq_top 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⟩ #align set.nonempty_of_union_eq_top_of_nonempty Set.nonempty_of_union_eq_top_of_nonempty 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 #align set.set_of_exists Set.setOf_exists theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm #align set.set_of_forall Set.setOf_forall theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h #align set.Union_subset Set.iUnion_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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) #align set.Union₂_subset Set.iUnion₂_subset theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h #align set.subset_Inter Set.subset_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.subset_Inter₂ Set.subset_iInter₂ @[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⟩ #align set.Union_subset_iff Set.iUnion_subset_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.Union₂_subset_iff Set.iUnion₂_subset_iff @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff #align set.subset_Inter_iff Set.subset_iInter_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- Porting note (#10618): removing `simp`. `simp` can prove it 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] #align set.subset_Inter₂_iff Set.subset_iInter₂_iff theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup #align set.subset_Union Set.subset_iUnion theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le #align set.Inter_subset Set.iInter_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j #align set.subset_Union₂ Set.subset_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j #align set.Inter₂_subset Set.iInter₂_subset /-- 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 #align set.subset_Union_of_subset Set.subset_iUnion_of_subset /-- 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 #align set.Inter_subset_of_subset Set.iInter_subset_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- 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 #align set.subset_Union₂_of_subset Set.subset_iUnion₂_of_subset /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /-- 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 #align set.Inter₂_subset_of_subset Set.iInter₂_subset_of_subset theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h #align set.Union_mono Set.iUnion_mono @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.Union₂_mono Set.iUnion₂_mono theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h #align set.Inter_mono Set.iInter_mono @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.Inter₂_mono Set.iInter₂_mono theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h #align set.Union_mono' Set.iUnion_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ 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 #align set.Union₂_mono' Set.iUnion₂_mono' 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 #align set.Inter_mono' Set.iInter_mono' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' j') -/ 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 #align set.Inter₂_mono' Set.iInter₂_mono' theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl #align set.Union₂_subset_Union Set.iUnion₂_subset_iUnion theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl #align set.Inter_subset_Inter₂ Set.iInter_subset_iInter₂ theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion #align set.Union_set_of Set.iUnion_setOf theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter #align set.Inter_set_of Set.iInter_setOf 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 #align set.Union_congr_of_surjective Set.iUnion_congr_of_surjective 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 #align set.Inter_congr_of_surjective Set.iInter_congr_of_surjective lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h #align set.Union_congr Set.iUnion_congr lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h #align set.Inter_congr Set.iInter_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.Union₂_congr Set.iUnion₂_congr /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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 #align set.Inter₂_congr Set.iInter₂_congr section Nonempty variable [Nonempty ι] {f : ι → Set α} {s : Set α} lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const #align set.Union_const Set.iUnion_const lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const #align set.Inter_const Set.iInter_const lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ #align set.Union_eq_const Set.iUnion_eq_const lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s := (iInter_congr hf).trans <| iInter_const _ #align set.Inter_eq_const Set.iInter_eq_const end Nonempty @[simp] theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ := compl_iSup #align set.compl_Union Set.compl_iUnion /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by simp_rw [compl_iUnion] #align set.compl_Union₂ Set.compl_iUnion₂ @[simp] theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ := compl_iInf #align set.compl_Inter Set.compl_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by simp_rw [compl_iInter] #align set.compl_Inter₂ Set.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] #align set.Union_eq_compl_Inter_compl Set.iUnion_eq_compl_iInter_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] #align set.Inter_eq_compl_Union_compl Set.iInter_eq_compl_iUnion_compl theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ #align set.inter_Union Set.inter_iUnion theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ #align set.Union_inter Set.iUnion_inter theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) : ⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i := iSup_sup_eq #align set.Union_union_distrib Set.iUnion_union_distrib theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) : ⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i := iInf_inf_eq #align set.Inter_inter_distrib Set.iInter_inter_distrib theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i := sup_iSup #align set.union_Union Set.union_iUnion theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := iSup_sup #align set.Union_union Set.iUnion_union theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i := inf_iInf #align set.inter_Inter Set.inter_iInter theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := iInf_inf #align set.Inter_inter Set.iInter_inter -- classical theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i := sup_iInf_eq _ _ #align set.union_Inter Set.union_iInter theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ #align set.Inter_union Set.iInter_union theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ #align set.Union_diff Set.iUnion_diff 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 #align set.diff_Union Set.diff_iUnion theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl #align set.diff_Inter Set.diff_iInter theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t #align set.Union_inter_subset Set.iUnion_inter_subset 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 #align set.Union_inter_of_monotone Set.iUnion_inter_of_monotone 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 #align set.Union_inter_of_antitone Set.iUnion_inter_of_antitone 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 #align set.Inter_union_of_monotone Set.iInter_union_of_monotone 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 #align set.Inter_union_of_antitone Set.iInter_union_of_antitone /-- 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) #align set.Union_Inter_subset Set.iUnion_iInter_subset theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) := iSup_option s #align set.Union_option Set.iUnion_option theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) := iInf_option s #align set.Inter_option Set.iInter_option 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 _ _ _ #align set.Union_dite Set.iUnion_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 _ _ _ #align set.Union_ite Set.iUnion_ite 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 _ _ _ #align set.Inter_dite Set.iInter_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 _ _ _ #align set.Inter_ite Set.iInter_ite end theorem image_projection_prod {ι : Type*} {α : ι → Type*} {v : ∀ i : ι, Set (α i)} (hv : (pi univ v).Nonempty) (i : ι) : ((fun x : ∀ i : ι, α i => x i) '' ⋂ k, (fun x : ∀ j : ι, α j => x k) ⁻¹' v k) = v i := by classical apply Subset.antisymm · simp [iInter_subset] · intro y y_in simp only [mem_image, mem_iInter, mem_preimage] rcases hv with ⟨z, hz⟩ refine ⟨Function.update z i y, ?_, update_same i y z⟩ rw [@forall_update_iff ι α _ z i y fun i t => t ∈ v i] exact ⟨y_in, fun j _ => by simpa using hz j⟩ #align set.image_projection_prod Set.image_projection_prod /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False → Set α} : iInter s = univ := iInf_false #align set.Inter_false Set.iInter_false theorem iUnion_false {s : False → Set α} : iUnion s = ∅ := iSup_false #align set.Union_false Set.iUnion_false @[simp] theorem iInter_true {s : True → Set α} : iInter s = s trivial := iInf_true #align set.Inter_true Set.iInter_true @[simp] theorem iUnion_true {s : True → Set α} : iUnion s = s trivial := iSup_true #align set.Union_true Set.iUnion_true @[simp] theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} : ⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ := iInf_exists #align set.Inter_exists Set.iInter_exists @[simp] theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists #align set.Union_exists Set.iUnion_exists @[simp] theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ := iSup_bot #align set.Union_empty Set.iUnion_empty @[simp] theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ := iInf_top #align set.Inter_univ Set.iInter_univ section variable {s : ι → Set α} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ := iSup_eq_bot #align set.Union_eq_empty Set.iUnion_eq_empty @[simp] theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ := iInf_eq_top #align set.Inter_eq_univ Set.iInter_eq_univ @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] #align set.nonempty_Union Set.nonempty_iUnion -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_biUnion {t : Set α} {s : α → Set β} : (⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp #align set.nonempty_bUnion Set.nonempty_biUnion theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ := iSup_exists #align set.Union_nonempty_index Set.iUnion_nonempty_index 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 #align set.Inter_Inter_eq_left Set.iInter_iInter_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 #align set.Inter_Inter_eq_right Set.iInter_iInter_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 #align set.Union_Union_eq_left Set.iUnion_iUnion_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 #align set.Union_Union_eq_right Set.iUnion_iUnion_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 #align set.Inter_or Set.iInter_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 #align set.Union_or Set.iUnion_or /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and #align set.Union_and Set.iUnion_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (hp hq) -/ theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ := iInf_and #align set.Inter_and Set.iInter_and /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm #align set.Union_comm Set.iUnion_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i i') -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i' i) -/ theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' := iInf_comm #align set.Inter_comm Set.iInter_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' _ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ 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 _ #align set.Union₂_comm Set.iUnion₂_comm /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₁ j₁ i₂ j₂) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i₂ j₂ i₁ j₁) -/ 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 _ #align set.Inter₂_comm Set.iInter₂_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 _ ι'] #align set.bUnion_and Set.biUnion_and @[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 _ ι] #align set.bUnion_and' Set.biUnion_and' @[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 _ ι'] #align set.bInter_and Set.biInter_and @[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 _ ι] #align set.bInter_and' Set.biInter_and' /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[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] #align set.Union_Union_eq_or_left Set.iUnion_iUnion_eq_or_left /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (x h) -/ @[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] #align set.Inter_Inter_eq_or_left Set.iInter_iInter_eq_or_left /-! ### 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 #align set.mem_bUnion Set.mem_biUnion /-- 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 #align set.mem_bInter Set.mem_biInter /-- A specialization of `subset_iUnion₂`. -/ theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) : u x ⊆ ⋃ x ∈ s, u x := -- Porting note: Why is this not just `subset_iUnion₂ x xs`? @subset_iUnion₂ β α (· ∈ s) (fun i _ => u i) x xs #align set.subset_bUnion_of_mem Set.subset_biUnion_of_mem /-- 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 #align set.bInter_subset_of_mem Set.biInter_subset_of_mem 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 #align set.bUnion_subset_bUnion_left Set.biUnion_subset_biUnion_left 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 #align set.bInter_subset_bInter_left Set.biInter_subset_biInter_left 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 #align set.bUnion_mono Set.biUnion_mono 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 #align set.bInter_mono Set.biInter_mono theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) : ⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 := iSup_subtype' #align set.bUnion_eq_Union Set.biUnion_eq_iUnion theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) : ⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 := iInf_subtype' #align set.bInter_eq_Inter Set.biInter_eq_iInter 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 #align set.Union_subtype Set.iUnion_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 #align set.Inter_subtype Set.iInter_subtype theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ := iInf_emptyset #align set.bInter_empty Set.biInter_empty theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x := iInf_univ #align set.bInter_univ Set.biInter_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 #align set.bUnion_self Set.biUnion_self @[simp] theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] #align set.Union_nonempty_self Set.iUnion_nonempty_self theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a := iInf_singleton #align set.bInter_singleton Set.biInter_singleton theorem biInter_union (s t : Set α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union #align set.bInter_union Set.biInter_union theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp #align set.bInter_insert Set.biInter_insert theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] #align set.bInter_pair Set.biInter_pair 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] #align set.bInter_inter Set.biInter_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] #align set.inter_bInter Set.inter_biInter theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ := iSup_emptyset #align set.bUnion_empty Set.biUnion_empty theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x := iSup_univ #align set.bUnion_univ Set.biUnion_univ theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a := iSup_singleton #align set.bUnion_singleton Set.biUnion_singleton @[simp] theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s := ext <| by simp #align set.bUnion_of_singleton Set.biUnion_of_singleton theorem biUnion_union (s t : Set α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union #align set.bUnion_union Set.biUnion_union @[simp] theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iUnion_subtype _ _ #align set.Union_coe_set Set.iUnion_coe_set @[simp] theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iInter_subtype _ _ #align set.Inter_coe_set Set.iInter_coe_set theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp #align set.bUnion_insert Set.biUnion_insert theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by simp #align set.bUnion_pair Set.biUnion_pair /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.inter_Union₂ Set.inter_iUnion₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.Union₂_inter Set.iUnion₂_inter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.union_Inter₂ Set.union_iInter₂ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.Inter₂_union Set.iInter₂_union theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀S := ⟨t, ht, hx⟩ #align set.mem_sUnion_of_mem Set.mem_sUnion_of_mem -- 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⟩ #align set.not_mem_of_not_mem_sUnion Set.not_mem_of_not_mem_sUnion theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := sInf_le tS #align set.sInter_subset_of_mem Set.sInter_subset_of_mem theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀S := le_sSup tS #align set.subset_sUnion_of_mem Set.subset_sUnion_of_mem 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₂) #align set.subset_sUnion_of_subset Set.subset_sUnion_of_subset theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀S ⊆ t := sSup_le h #align set.sUnion_subset Set.sUnion_subset @[simp] theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t := sSup_le_iff #align set.sUnion_subset_iff Set.sUnion_subset_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 #align set.subset_sInter Set.subset_sInter @[simp] theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' := le_sInf_iff #align set.subset_sInter_iff Set.subset_sInter_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) #align set.sUnion_subset_sUnion Set.sUnion_subset_sUnion @[gcongr] theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) #align set.sInter_subset_sInter Set.sInter_subset_sInter @[simp] theorem sUnion_empty : ⋃₀∅ = (∅ : Set α) := sSup_empty #align set.sUnion_empty Set.sUnion_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) := sInf_empty #align set.sInter_empty Set.sInter_empty @[simp] theorem sUnion_singleton (s : Set α) : ⋃₀{s} = s := sSup_singleton #align set.sUnion_singleton Set.sUnion_singleton @[simp] theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s := sInf_singleton #align set.sInter_singleton Set.sInter_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀S = ∅ ↔ ∀ s ∈ S, s = ∅ := sSup_eq_bot #align set.sUnion_eq_empty Set.sUnion_eq_empty @[simp] theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ := sInf_eq_top #align set.sInter_eq_univ Set.sInter_eq_univ 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 sUnion_powerset_gi : GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gi_sSup_Iic /-- 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] #align set.nonempty_sUnion Set.nonempty_sUnion theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ #align set.nonempty.of_sUnion Set.Nonempty.of_sUnion theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm ▸ univ_nonempty #align set.nonempty.of_sUnion_eq_univ Set.Nonempty.of_sUnion_eq_univ theorem sUnion_union (S T : Set (Set α)) : ⋃₀(S ∪ T) = ⋃₀S ∪ ⋃₀T := sSup_union #align set.sUnion_union Set.sUnion_union theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := sInf_union #align set.sInter_union Set.sInter_union @[simp] theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀insert s T = s ∪ ⋃₀T := sSup_insert #align set.sUnion_insert Set.sUnion_insert @[simp] theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T := sInf_insert #align set.sInter_insert Set.sInter_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀(s \ {∅}) = ⋃₀s := sSup_diff_singleton_bot s #align set.sUnion_diff_singleton_empty Set.sUnion_diff_singleton_empty @[simp] theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s := sInf_diff_singleton_top s #align set.sInter_diff_singleton_univ Set.sInter_diff_singleton_univ theorem sUnion_pair (s t : Set α) : ⋃₀{s, t} = s ∪ t := sSup_pair #align set.sUnion_pair Set.sUnion_pair theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t := sInf_pair #align set.sInter_pair Set.sInter_pair @[simp] theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀(f '' s) = ⋃ x ∈ s, f x := sSup_image #align set.sUnion_image Set.sUnion_image @[simp] theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := sInf_image #align set.sInter_image Set.sInter_image @[simp] theorem sUnion_range (f : ι → Set β) : ⋃₀range f = ⋃ x, f x := rfl #align set.sUnion_range Set.sUnion_range @[simp] theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x := rfl #align set.sInter_range Set.sInter_range 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] #align set.Union_eq_univ_iff Set.iUnion_eq_univ_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ 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] #align set.Union₂_eq_univ_iff Set.iUnion₂_eq_univ_iff theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] #align set.sUnion_eq_univ_iff Set.sUnion_eq_univ_iff -- 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] #align set.Inter_eq_empty_iff Set.iInter_eq_empty_iff /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- 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] #align set.Inter₂_eq_empty_iff Set.iInter₂_eq_empty_iff -- classical theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by simp [Set.eq_empty_iff_forall_not_mem] #align set.sInter_eq_empty_iff Set.sInter_eq_empty_iff -- 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] #align set.nonempty_Inter Set.nonempty_iInter /- ./././Mathport/Syntax/Translate/Expr.lean:107:6: warning: expanding binder group (i j) -/ -- classical -- Porting note (#10618): removing `simp`. `simp` can prove it theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} : (⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by simp #align set.nonempty_Inter₂ Set.nonempty_iInter₂ -- 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] #align set.nonempty_sInter Set.nonempty_sInter -- classical theorem compl_sUnion (S : Set (Set α)) : (⋃₀S)ᶜ = ⋂₀ (compl '' S) := ext fun x => by simp #align set.compl_sUnion Set.compl_sUnion -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀S = (⋂₀ (compl '' S))ᶜ := by rw [← compl_compl (⋃₀S), compl_sUnion] #align set.sUnion_eq_compl_sInter_compl Set.sUnion_eq_compl_sInter_compl -- classical theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀(compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] #align set.compl_sInter Set.compl_sInter -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀(compl '' S))ᶜ := by rw [← compl_compl (⋂₀ S), compl_sInter] #align set.sInter_eq_compl_sUnion_compl Set.sInter_eq_compl_sUnion_compl 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) #align set.inter_empty_of_inter_sUnion_empty Set.inter_empty_of_inter_sUnion_empty theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp #align set.range_sigma_eq_Union_range Set.range_sigma_eq_iUnion_range theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_sigma Set.iUnion_eq_range_sigma theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by simp [Set.ext_iff] #align set.Union_eq_range_psigma Set.iUnion_eq_range_psigma 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 cases' x with i a exact ⟨i, a, h, rfl⟩ #align set.Union_image_preimage_sigma_mk_eq_self Set.iUnion_image_preimage_sigma_mk_eq_self 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⟩ #align set.sigma.univ Set.Sigma.univ alias sUnion_mono := sUnion_subset_sUnion #align set.sUnion_mono Set.sUnion_mono theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s := iSup_const_mono (α := Set α) h #align set.Union_subset_Union_const Set.iUnion_subset_iUnion_const @[simp]
Mathlib/Data/Set/Lattice.lean
1,293
1,295
theorem iUnion_singleton_eq_range {α β : Type*} (f : α → β) : ⋃ x : α, {f x} = range f := by
ext x simp [@eq_comm _ x]
/- 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.MeasureTheory.Function.StronglyMeasurable.Lp import Mathlib.MeasureTheory.Integral.Bochner import Mathlib.Order.Filter.IndicatorFunction import Mathlib.MeasureTheory.Function.StronglyMeasurable.Inner import Mathlib.MeasureTheory.Function.LpSeminorm.Trim #align_import measure_theory.function.conditional_expectation.ae_measurable from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Functions a.e. measurable with respect to a sub-σ-algebra A function `f` verifies `AEStronglyMeasurable' m f μ` if it is `μ`-a.e. equal to an `m`-strongly measurable function. This is similar to `AEStronglyMeasurable`, but the `MeasurableSpace` structures used for the measurability statement and for the measure are different. We define `lpMeas F 𝕜 m p μ`, the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable' m f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. ## Main statements We define an `IsometryEquiv` between `lpMeasSubgroup` and the `Lp` space corresponding to the measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of `lpMeas`. `Lp.induction_stronglyMeasurable` (see also `Memℒp.induction_stronglyMeasurable`): To prove something for an `Lp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is closed. -/ set_option linter.uppercaseLean3 false open TopologicalSpace Filter open scoped ENNReal MeasureTheory namespace MeasureTheory /-- A function `f` verifies `AEStronglyMeasurable' m f μ` if it is `μ`-a.e. equal to an `m`-strongly measurable function. This is similar to `AEStronglyMeasurable`, but the `MeasurableSpace` structures used for the measurability statement and for the measure are different. -/ def AEStronglyMeasurable' {α β} [TopologicalSpace β] (m : MeasurableSpace α) {_ : MeasurableSpace α} (f : α → β) (μ : Measure α) : Prop := ∃ g : α → β, StronglyMeasurable[m] g ∧ f =ᵐ[μ] g #align measure_theory.ae_strongly_measurable' MeasureTheory.AEStronglyMeasurable' namespace AEStronglyMeasurable' variable {α β 𝕜 : Type*} {m m0 : MeasurableSpace α} {μ : Measure α} [TopologicalSpace β] {f g : α → β} theorem congr (hf : AEStronglyMeasurable' m f μ) (hfg : f =ᵐ[μ] g) : AEStronglyMeasurable' m g μ := by obtain ⟨f', hf'_meas, hff'⟩ := hf; exact ⟨f', hf'_meas, hfg.symm.trans hff'⟩ #align measure_theory.ae_strongly_measurable'.congr MeasureTheory.AEStronglyMeasurable'.congr theorem mono {m'} (hf : AEStronglyMeasurable' m f μ) (hm : m ≤ m') : AEStronglyMeasurable' m' f μ := let ⟨f', hf'_meas, hff'⟩ := hf; ⟨f', hf'_meas.mono hm, hff'⟩ theorem add [Add β] [ContinuousAdd β] (hf : AEStronglyMeasurable' m f μ) (hg : AEStronglyMeasurable' m g μ) : AEStronglyMeasurable' m (f + g) μ := by rcases hf with ⟨f', h_f'_meas, hff'⟩ rcases hg with ⟨g', h_g'_meas, hgg'⟩ exact ⟨f' + g', h_f'_meas.add h_g'_meas, hff'.add hgg'⟩ #align measure_theory.ae_strongly_measurable'.add MeasureTheory.AEStronglyMeasurable'.add theorem neg [AddGroup β] [TopologicalAddGroup β] {f : α → β} (hfm : AEStronglyMeasurable' m f μ) : AEStronglyMeasurable' m (-f) μ := by rcases hfm with ⟨f', hf'_meas, hf_ae⟩ refine ⟨-f', hf'_meas.neg, hf_ae.mono fun x hx => ?_⟩ simp_rw [Pi.neg_apply] rw [hx] #align measure_theory.ae_strongly_measurable'.neg MeasureTheory.AEStronglyMeasurable'.neg theorem sub [AddGroup β] [TopologicalAddGroup β] {f g : α → β} (hfm : AEStronglyMeasurable' m f μ) (hgm : AEStronglyMeasurable' m g μ) : AEStronglyMeasurable' m (f - g) μ := by rcases hfm with ⟨f', hf'_meas, hf_ae⟩ rcases hgm with ⟨g', hg'_meas, hg_ae⟩ refine ⟨f' - g', hf'_meas.sub hg'_meas, hf_ae.mp (hg_ae.mono fun x hx1 hx2 => ?_)⟩ simp_rw [Pi.sub_apply] rw [hx1, hx2] #align measure_theory.ae_strongly_measurable'.sub MeasureTheory.AEStronglyMeasurable'.sub theorem const_smul [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (c : 𝕜) (hf : AEStronglyMeasurable' m f μ) : AEStronglyMeasurable' m (c • f) μ := by rcases hf with ⟨f', h_f'_meas, hff'⟩ refine ⟨c • f', h_f'_meas.const_smul c, ?_⟩ exact EventuallyEq.fun_comp hff' fun x => c • x #align measure_theory.ae_strongly_measurable'.const_smul MeasureTheory.AEStronglyMeasurable'.const_smul theorem const_inner {𝕜 β} [RCLike 𝕜] [NormedAddCommGroup β] [InnerProductSpace 𝕜 β] {f : α → β} (hfm : AEStronglyMeasurable' m f μ) (c : β) : AEStronglyMeasurable' m (fun x => (inner c (f x) : 𝕜)) μ := by rcases hfm with ⟨f', hf'_meas, hf_ae⟩ refine ⟨fun x => (inner c (f' x) : 𝕜), (@stronglyMeasurable_const _ _ m _ c).inner hf'_meas, hf_ae.mono fun x hx => ?_⟩ dsimp only rw [hx] #align measure_theory.ae_strongly_measurable'.const_inner MeasureTheory.AEStronglyMeasurable'.const_inner /-- An `m`-strongly measurable function almost everywhere equal to `f`. -/ noncomputable def mk (f : α → β) (hfm : AEStronglyMeasurable' m f μ) : α → β := hfm.choose #align measure_theory.ae_strongly_measurable'.mk MeasureTheory.AEStronglyMeasurable'.mk theorem stronglyMeasurable_mk {f : α → β} (hfm : AEStronglyMeasurable' m f μ) : StronglyMeasurable[m] (hfm.mk f) := hfm.choose_spec.1 #align measure_theory.ae_strongly_measurable'.stronglyMeasurable_mk MeasureTheory.AEStronglyMeasurable'.stronglyMeasurable_mk theorem ae_eq_mk {f : α → β} (hfm : AEStronglyMeasurable' m f μ) : f =ᵐ[μ] hfm.mk f := hfm.choose_spec.2 #align measure_theory.ae_strongly_measurable'.ae_eq_mk MeasureTheory.AEStronglyMeasurable'.ae_eq_mk theorem continuous_comp {γ} [TopologicalSpace γ] {f : α → β} {g : β → γ} (hg : Continuous g) (hf : AEStronglyMeasurable' m f μ) : AEStronglyMeasurable' m (g ∘ f) μ := ⟨fun x => g (hf.mk _ x), @Continuous.comp_stronglyMeasurable _ _ _ m _ _ _ _ hg hf.stronglyMeasurable_mk, hf.ae_eq_mk.mono fun x hx => by rw [Function.comp_apply, hx]⟩ #align measure_theory.ae_strongly_measurable'.continuous_comp MeasureTheory.AEStronglyMeasurable'.continuous_comp end AEStronglyMeasurable' theorem aeStronglyMeasurable'_of_aeStronglyMeasurable'_trim {α β} {m m0 m0' : MeasurableSpace α} [TopologicalSpace β] (hm0 : m0 ≤ m0') {μ : Measure α} {f : α → β} (hf : AEStronglyMeasurable' m f (μ.trim hm0)) : AEStronglyMeasurable' m f μ := by obtain ⟨g, hg_meas, hfg⟩ := hf; exact ⟨g, hg_meas, ae_eq_of_ae_eq_trim hfg⟩ #align measure_theory.ae_strongly_measurable'_of_ae_strongly_measurable'_trim MeasureTheory.aeStronglyMeasurable'_of_aeStronglyMeasurable'_trim theorem StronglyMeasurable.aeStronglyMeasurable' {α β} {m _ : MeasurableSpace α} [TopologicalSpace β] {μ : Measure α} {f : α → β} (hf : StronglyMeasurable[m] f) : AEStronglyMeasurable' m f μ := ⟨f, hf, ae_eq_refl _⟩ #align measure_theory.strongly_measurable.ae_strongly_measurable' MeasureTheory.StronglyMeasurable.aeStronglyMeasurable' theorem ae_eq_trim_iff_of_aeStronglyMeasurable' {α β} [TopologicalSpace β] [MetrizableSpace β] {m m0 : MeasurableSpace α} {μ : Measure α} {f g : α → β} (hm : m ≤ m0) (hfm : AEStronglyMeasurable' m f μ) (hgm : AEStronglyMeasurable' m g μ) : hfm.mk f =ᵐ[μ.trim hm] hgm.mk g ↔ f =ᵐ[μ] g := (ae_eq_trim_iff hm hfm.stronglyMeasurable_mk hgm.stronglyMeasurable_mk).trans ⟨fun h => hfm.ae_eq_mk.trans (h.trans hgm.ae_eq_mk.symm), fun h => hfm.ae_eq_mk.symm.trans (h.trans hgm.ae_eq_mk)⟩ #align measure_theory.ae_eq_trim_iff_of_ae_strongly_measurable' MeasureTheory.ae_eq_trim_iff_of_aeStronglyMeasurable' theorem AEStronglyMeasurable.comp_ae_measurable' {α β γ : Type*} [TopologicalSpace β] {mα : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → β} {μ : Measure γ} {g : γ → α} (hf : AEStronglyMeasurable f (μ.map g)) (hg : AEMeasurable g μ) : AEStronglyMeasurable' (mα.comap g) (f ∘ g) μ := ⟨hf.mk f ∘ g, hf.stronglyMeasurable_mk.comp_measurable (measurable_iff_comap_le.mpr le_rfl), ae_eq_comp hg hf.ae_eq_mk⟩ #align measure_theory.ae_strongly_measurable.comp_ae_measurable' MeasureTheory.AEStronglyMeasurable.comp_ae_measurable' /-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` almost everywhere supported on `s` is `m`-ae-strongly-measurable, then `f` is also `m₂`-ae-strongly-measurable. -/ theorem AEStronglyMeasurable'.aeStronglyMeasurable'_of_measurableSpace_le_on {α E} {m m₂ m0 : MeasurableSpace α} {μ : Measure α} [TopologicalSpace E] [Zero E] (hm : m ≤ m0) {s : Set α} {f : α → E} (hs_m : MeasurableSet[m] s) (hs : ∀ t, MeasurableSet[m] (s ∩ t) → MeasurableSet[m₂] (s ∩ t)) (hf : AEStronglyMeasurable' m f μ) (hf_zero : f =ᵐ[μ.restrict sᶜ] 0) : AEStronglyMeasurable' m₂ f μ := by have h_ind_eq : s.indicator (hf.mk f) =ᵐ[μ] f := by refine Filter.EventuallyEq.trans ?_ <| indicator_ae_eq_of_restrict_compl_ae_eq_zero (hm _ hs_m) hf_zero filter_upwards [hf.ae_eq_mk] with x hx by_cases hxs : x ∈ s · simp [hxs, hx] · simp [hxs] suffices StronglyMeasurable[m₂] (s.indicator (hf.mk f)) from AEStronglyMeasurable'.congr this.aeStronglyMeasurable' h_ind_eq have hf_ind : StronglyMeasurable[m] (s.indicator (hf.mk f)) := hf.stronglyMeasurable_mk.indicator hs_m exact hf_ind.stronglyMeasurable_of_measurableSpace_le_on hs_m hs fun x hxs => Set.indicator_of_not_mem hxs _ #align measure_theory.ae_strongly_measurable'.ae_strongly_measurable'_of_measurable_space_le_on MeasureTheory.AEStronglyMeasurable'.aeStronglyMeasurable'_of_measurableSpace_le_on variable {α E' F F' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- F' for integrals on a Lp submodule [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F'] section LpMeas /-! ## The subset `lpMeas` of `Lp` functions a.e. measurable with respect to a sub-sigma-algebra -/ variable (F) /-- `lpMeasSubgroup F m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable' m f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. -/ def lpMeasSubgroup (m : MeasurableSpace α) [MeasurableSpace α] (p : ℝ≥0∞) (μ : Measure α) : AddSubgroup (Lp F p μ) where carrier := {f : Lp F p μ | AEStronglyMeasurable' m f μ} zero_mem' := ⟨(0 : α → F), @stronglyMeasurable_zero _ _ m _ _, Lp.coeFn_zero _ _ _⟩ add_mem' {f g} hf hg := (hf.add hg).congr (Lp.coeFn_add f g).symm neg_mem' {f} hf := AEStronglyMeasurable'.congr hf.neg (Lp.coeFn_neg f).symm #align measure_theory.Lp_meas_subgroup MeasureTheory.lpMeasSubgroup variable (𝕜) /-- `lpMeas F 𝕜 m p μ` is the subspace of `Lp F p μ` containing functions `f` verifying `AEStronglyMeasurable' m f μ`, i.e. functions which are `μ`-a.e. equal to an `m`-strongly measurable function. -/ def lpMeas (m : MeasurableSpace α) [MeasurableSpace α] (p : ℝ≥0∞) (μ : Measure α) : Submodule 𝕜 (Lp F p μ) where carrier := {f : Lp F p μ | AEStronglyMeasurable' m f μ} zero_mem' := ⟨(0 : α → F), @stronglyMeasurable_zero _ _ m _ _, Lp.coeFn_zero _ _ _⟩ add_mem' {f g} hf hg := (hf.add hg).congr (Lp.coeFn_add f g).symm smul_mem' c f hf := (hf.const_smul c).congr (Lp.coeFn_smul c f).symm #align measure_theory.Lp_meas MeasureTheory.lpMeas variable {F 𝕜} theorem mem_lpMeasSubgroup_iff_aeStronglyMeasurable' {m m0 : MeasurableSpace α} {μ : Measure α} {f : Lp F p μ} : f ∈ lpMeasSubgroup F m p μ ↔ AEStronglyMeasurable' m f μ := by rw [← AddSubgroup.mem_carrier, lpMeasSubgroup, Set.mem_setOf_eq] #align measure_theory.mem_Lp_meas_subgroup_iff_ae_strongly_measurable' MeasureTheory.mem_lpMeasSubgroup_iff_aeStronglyMeasurable' theorem mem_lpMeas_iff_aeStronglyMeasurable' {m m0 : MeasurableSpace α} {μ : Measure α} {f : Lp F p μ} : f ∈ lpMeas F 𝕜 m p μ ↔ AEStronglyMeasurable' m f μ := by rw [← SetLike.mem_coe, ← Submodule.mem_carrier, lpMeas, Set.mem_setOf_eq] #align measure_theory.mem_Lp_meas_iff_ae_strongly_measurable' MeasureTheory.mem_lpMeas_iff_aeStronglyMeasurable' theorem lpMeas.aeStronglyMeasurable' {m _ : MeasurableSpace α} {μ : Measure α} (f : lpMeas F 𝕜 m p μ) : AEStronglyMeasurable' (β := F) m f μ := mem_lpMeas_iff_aeStronglyMeasurable'.mp f.mem #align measure_theory.Lp_meas.ae_strongly_measurable' MeasureTheory.lpMeas.aeStronglyMeasurable' theorem mem_lpMeas_self {m0 : MeasurableSpace α} (μ : Measure α) (f : Lp F p μ) : f ∈ lpMeas F 𝕜 m0 p μ := mem_lpMeas_iff_aeStronglyMeasurable'.mpr (Lp.aestronglyMeasurable f) #align measure_theory.mem_Lp_meas_self MeasureTheory.mem_lpMeas_self theorem lpMeasSubgroup_coe {m _ : MeasurableSpace α} {μ : Measure α} {f : lpMeasSubgroup F m p μ} : (f : _ → _) = (f : Lp F p μ) := rfl #align measure_theory.Lp_meas_subgroup_coe MeasureTheory.lpMeasSubgroup_coe theorem lpMeas_coe {m _ : MeasurableSpace α} {μ : Measure α} {f : lpMeas F 𝕜 m p μ} : (f : _ → _) = (f : Lp F p μ) := rfl #align measure_theory.Lp_meas_coe MeasureTheory.lpMeas_coe theorem mem_lpMeas_indicatorConstLp {m m0 : MeasurableSpace α} (hm : m ≤ m0) {μ : Measure α} {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {c : F} : indicatorConstLp p (hm s hs) hμs c ∈ lpMeas F 𝕜 m p μ := ⟨s.indicator fun _ : α => c, (@stronglyMeasurable_const _ _ m _ _).indicator hs, indicatorConstLp_coeFn⟩ #align measure_theory.mem_Lp_meas_indicator_const_Lp MeasureTheory.mem_lpMeas_indicatorConstLp section CompleteSubspace /-! ## The subspace `lpMeas` is complete. We define an `IsometryEquiv` between `lpMeasSubgroup` and the `Lp` space corresponding to the measure `μ.trim hm`. As a consequence, the completeness of `Lp` implies completeness of `lpMeasSubgroup` (and `lpMeas`). -/ variable {ι : Type*} {m m0 : MeasurableSpace α} {μ : Measure α} /-- If `f` belongs to `lpMeasSubgroup F m p μ`, then the measurable function it is almost everywhere equal to (given by `AEMeasurable.mk`) belongs to `ℒp` for the measure `μ.trim hm`. -/ theorem memℒp_trim_of_mem_lpMeasSubgroup (hm : m ≤ m0) (f : Lp F p μ) (hf_meas : f ∈ lpMeasSubgroup F m p μ) : Memℒp (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp hf_meas).choose p (μ.trim hm) := by have hf : AEStronglyMeasurable' m f μ := mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp hf_meas let g := hf.choose obtain ⟨hg, hfg⟩ := hf.choose_spec change Memℒp g p (μ.trim hm) refine ⟨hg.aestronglyMeasurable, ?_⟩ have h_snorm_fg : snorm g p (μ.trim hm) = snorm f p μ := by rw [snorm_trim hm hg] exact snorm_congr_ae hfg.symm rw [h_snorm_fg] exact Lp.snorm_lt_top f #align measure_theory.mem_ℒp_trim_of_mem_Lp_meas_subgroup MeasureTheory.memℒp_trim_of_mem_lpMeasSubgroup /-- If `f` belongs to `Lp` for the measure `μ.trim hm`, then it belongs to the subgroup `lpMeasSubgroup F m p μ`. -/ theorem mem_lpMeasSubgroup_toLp_of_trim (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : (memℒp_of_memℒp_trim hm (Lp.memℒp f)).toLp f ∈ lpMeasSubgroup F m p μ := by let hf_mem_ℒp := memℒp_of_memℒp_trim hm (Lp.memℒp f) rw [mem_lpMeasSubgroup_iff_aeStronglyMeasurable'] refine AEStronglyMeasurable'.congr ?_ (Memℒp.coeFn_toLp hf_mem_ℒp).symm refine aeStronglyMeasurable'_of_aeStronglyMeasurable'_trim hm ?_ exact Lp.aestronglyMeasurable f #align measure_theory.mem_Lp_meas_subgroup_to_Lp_of_trim MeasureTheory.mem_lpMeasSubgroup_toLp_of_trim variable (F p μ) /-- Map from `lpMeasSubgroup` to `Lp F p (μ.trim hm)`. -/ noncomputable def lpMeasSubgroupToLpTrim (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : Lp F p (μ.trim hm) := Memℒp.toLp (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.mem).choose -- Porting note: had to replace `f` with `f.1` here. (memℒp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem) #align measure_theory.Lp_meas_subgroup_to_Lp_trim MeasureTheory.lpMeasSubgroupToLpTrim variable (𝕜) /-- Map from `lpMeas` to `Lp F p (μ.trim hm)`. -/ noncomputable def lpMeasToLpTrim (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) : Lp F p (μ.trim hm) := Memℒp.toLp (mem_lpMeas_iff_aeStronglyMeasurable'.mp f.mem).choose -- Porting note: had to replace `f` with `f.1` here. (memℒp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem) #align measure_theory.Lp_meas_to_Lp_trim MeasureTheory.lpMeasToLpTrim variable {𝕜} /-- Map from `Lp F p (μ.trim hm)` to `lpMeasSubgroup`, inverse of `lpMeasSubgroupToLpTrim`. -/ noncomputable def lpTrimToLpMeasSubgroup (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpMeasSubgroup F m p μ := ⟨(memℒp_of_memℒp_trim hm (Lp.memℒp f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f⟩ #align measure_theory.Lp_trim_to_Lp_meas_subgroup MeasureTheory.lpTrimToLpMeasSubgroup variable (𝕜) /-- Map from `Lp F p (μ.trim hm)` to `lpMeas`, inverse of `Lp_meas_to_Lp_trim`. -/ noncomputable def lpTrimToLpMeas (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpMeas F 𝕜 m p μ := ⟨(memℒp_of_memℒp_trim hm (Lp.memℒp f)).toLp f, mem_lpMeasSubgroup_toLp_of_trim hm f⟩ #align measure_theory.Lp_trim_to_Lp_meas MeasureTheory.lpTrimToLpMeas variable {F 𝕜 p μ} theorem lpMeasSubgroupToLpTrim_ae_eq (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm f =ᵐ[μ] f := -- Porting note: replaced `(↑f)` with `f.1` here. (ae_eq_of_ae_eq_trim (Memℒp.coeFn_toLp (memℒp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem))).trans (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.mem).choose_spec.2.symm #align measure_theory.Lp_meas_subgroup_to_Lp_trim_ae_eq MeasureTheory.lpMeasSubgroupToLpTrim_ae_eq theorem lpTrimToLpMeasSubgroup_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpTrimToLpMeasSubgroup F p μ hm f =ᵐ[μ] f := -- Porting note: filled in the argument Memℒp.coeFn_toLp (memℒp_of_memℒp_trim hm (Lp.memℒp f)) #align measure_theory.Lp_trim_to_Lp_meas_subgroup_ae_eq MeasureTheory.lpTrimToLpMeasSubgroup_ae_eq theorem lpMeasToLpTrim_ae_eq (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) : lpMeasToLpTrim F 𝕜 p μ hm f =ᵐ[μ] f := -- Porting note: replaced `(↑f)` with `f.1` here. (ae_eq_of_ae_eq_trim (Memℒp.coeFn_toLp (memℒp_trim_of_mem_lpMeasSubgroup hm f.1 f.mem))).trans (mem_lpMeasSubgroup_iff_aeStronglyMeasurable'.mp f.mem).choose_spec.2.symm #align measure_theory.Lp_meas_to_Lp_trim_ae_eq MeasureTheory.lpMeasToLpTrim_ae_eq theorem lpTrimToLpMeas_ae_eq (hm : m ≤ m0) (f : Lp F p (μ.trim hm)) : lpTrimToLpMeas F 𝕜 p μ hm f =ᵐ[μ] f := -- Porting note: filled in the argument Memℒp.coeFn_toLp (memℒp_of_memℒp_trim hm (Lp.memℒp f)) #align measure_theory.Lp_trim_to_Lp_meas_ae_eq MeasureTheory.lpTrimToLpMeas_ae_eq /-- `lpTrimToLpMeasSubgroup` is a right inverse of `lpMeasSubgroupToLpTrim`. -/ theorem lpMeasSubgroupToLpTrim_right_inv (hm : m ≤ m0) : Function.RightInverse (lpTrimToLpMeasSubgroup F p μ hm) (lpMeasSubgroupToLpTrim F p μ hm) := by intro f ext1 refine ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _) (Lp.stronglyMeasurable _) ?_ exact (lpMeasSubgroupToLpTrim_ae_eq hm _).trans (lpTrimToLpMeasSubgroup_ae_eq hm _) #align measure_theory.Lp_meas_subgroup_to_Lp_trim_right_inv MeasureTheory.lpMeasSubgroupToLpTrim_right_inv /-- `lpTrimToLpMeasSubgroup` is a left inverse of `lpMeasSubgroupToLpTrim`. -/ theorem lpMeasSubgroupToLpTrim_left_inv (hm : m ≤ m0) : Function.LeftInverse (lpTrimToLpMeasSubgroup F p μ hm) (lpMeasSubgroupToLpTrim F p μ hm) := by intro f ext1 ext1 rw [← lpMeasSubgroup_coe] exact (lpTrimToLpMeasSubgroup_ae_eq hm _).trans (lpMeasSubgroupToLpTrim_ae_eq hm _) #align measure_theory.Lp_meas_subgroup_to_Lp_trim_left_inv MeasureTheory.lpMeasSubgroupToLpTrim_left_inv theorem lpMeasSubgroupToLpTrim_add (hm : m ≤ m0) (f g : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (f + g) = lpMeasSubgroupToLpTrim F p μ hm f + lpMeasSubgroupToLpTrim F p μ hm g := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _) ?_ ?_ · exact (Lp.stronglyMeasurable _).add (Lp.stronglyMeasurable _) refine (lpMeasSubgroupToLpTrim_ae_eq hm _).trans ?_ refine EventuallyEq.trans ?_ (EventuallyEq.add (lpMeasSubgroupToLpTrim_ae_eq hm f).symm (lpMeasSubgroupToLpTrim_ae_eq hm g).symm) refine (Lp.coeFn_add _ _).trans ?_ simp_rw [lpMeasSubgroup_coe] filter_upwards with x using rfl #align measure_theory.Lp_meas_subgroup_to_Lp_trim_add MeasureTheory.lpMeasSubgroupToLpTrim_add theorem lpMeasSubgroupToLpTrim_neg (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (-f) = -lpMeasSubgroupToLpTrim F p μ hm f := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_neg _).symm refine ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _) ?_ ?_ · exact @StronglyMeasurable.neg _ _ _ m _ _ _ (Lp.stronglyMeasurable _) refine (lpMeasSubgroupToLpTrim_ae_eq hm _).trans ?_ refine EventuallyEq.trans ?_ (EventuallyEq.neg (lpMeasSubgroupToLpTrim_ae_eq hm f).symm) refine (Lp.coeFn_neg _).trans ?_ simp_rw [lpMeasSubgroup_coe] exact eventually_of_forall fun x => by rfl #align measure_theory.Lp_meas_subgroup_to_Lp_trim_neg MeasureTheory.lpMeasSubgroupToLpTrim_neg theorem lpMeasSubgroupToLpTrim_sub (hm : m ≤ m0) (f g : lpMeasSubgroup F m p μ) : lpMeasSubgroupToLpTrim F p μ hm (f - g) = lpMeasSubgroupToLpTrim F p μ hm f - lpMeasSubgroupToLpTrim F p μ hm g := by rw [sub_eq_add_neg, sub_eq_add_neg, lpMeasSubgroupToLpTrim_add, lpMeasSubgroupToLpTrim_neg] #align measure_theory.Lp_meas_subgroup_to_Lp_trim_sub MeasureTheory.lpMeasSubgroupToLpTrim_sub theorem lpMeasToLpTrim_smul (hm : m ≤ m0) (c : 𝕜) (f : lpMeas F 𝕜 m p μ) : lpMeasToLpTrim F 𝕜 p μ hm (c • f) = c • lpMeasToLpTrim F 𝕜 p μ hm f := by ext1 refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm refine ae_eq_trim_of_stronglyMeasurable hm (Lp.stronglyMeasurable _) ?_ ?_ · exact (Lp.stronglyMeasurable _).const_smul c refine (lpMeasToLpTrim_ae_eq hm _).trans ?_ refine (Lp.coeFn_smul _ _).trans ?_ refine (lpMeasToLpTrim_ae_eq hm f).mono fun x hx => ?_ simp only [Pi.smul_apply, hx] #align measure_theory.Lp_meas_to_Lp_trim_smul MeasureTheory.lpMeasToLpTrim_smul /-- `lpMeasSubgroupToLpTrim` preserves the norm. -/ theorem lpMeasSubgroupToLpTrim_norm_map [hp : Fact (1 ≤ p)] (hm : m ≤ m0) (f : lpMeasSubgroup F m p μ) : ‖lpMeasSubgroupToLpTrim F p μ hm f‖ = ‖f‖ := by rw [Lp.norm_def, snorm_trim hm (Lp.stronglyMeasurable _), snorm_congr_ae (lpMeasSubgroupToLpTrim_ae_eq hm _), lpMeasSubgroup_coe, ← Lp.norm_def] congr #align measure_theory.Lp_meas_subgroup_to_Lp_trim_norm_map MeasureTheory.lpMeasSubgroupToLpTrim_norm_map theorem isometry_lpMeasSubgroupToLpTrim [hp : Fact (1 ≤ p)] (hm : m ≤ m0) : Isometry (lpMeasSubgroupToLpTrim F p μ hm) := Isometry.of_dist_eq fun f g => by rw [dist_eq_norm, ← lpMeasSubgroupToLpTrim_sub, lpMeasSubgroupToLpTrim_norm_map, dist_eq_norm] #align measure_theory.isometry_Lp_meas_subgroup_to_Lp_trim MeasureTheory.isometry_lpMeasSubgroupToLpTrim variable (F p μ) /-- `lpMeasSubgroup` and `Lp F p (μ.trim hm)` are isometric. -/ noncomputable def lpMeasSubgroupToLpTrimIso [Fact (1 ≤ p)] (hm : m ≤ m0) : lpMeasSubgroup F m p μ ≃ᵢ Lp F p (μ.trim hm) where toFun := lpMeasSubgroupToLpTrim F p μ hm invFun := lpTrimToLpMeasSubgroup F p μ hm left_inv := lpMeasSubgroupToLpTrim_left_inv hm right_inv := lpMeasSubgroupToLpTrim_right_inv hm isometry_toFun := isometry_lpMeasSubgroupToLpTrim hm #align measure_theory.Lp_meas_subgroup_to_Lp_trim_iso MeasureTheory.lpMeasSubgroupToLpTrimIso variable (𝕜) /-- `lpMeasSubgroup` and `lpMeas` are isometric. -/ noncomputable def lpMeasSubgroupToLpMeasIso [Fact (1 ≤ p)] : lpMeasSubgroup F m p μ ≃ᵢ lpMeas F 𝕜 m p μ := IsometryEquiv.refl (lpMeasSubgroup F m p μ) #align measure_theory.Lp_meas_subgroup_to_Lp_meas_iso MeasureTheory.lpMeasSubgroupToLpMeasIso /-- `lpMeas` and `Lp F p (μ.trim hm)` are isometric, with a linear equivalence. -/ noncomputable def lpMeasToLpTrimLie [Fact (1 ≤ p)] (hm : m ≤ m0) : lpMeas F 𝕜 m p μ ≃ₗᵢ[𝕜] Lp F p (μ.trim hm) where toFun := lpMeasToLpTrim F 𝕜 p μ hm invFun := lpTrimToLpMeas F 𝕜 p μ hm left_inv := lpMeasSubgroupToLpTrim_left_inv hm right_inv := lpMeasSubgroupToLpTrim_right_inv hm map_add' := lpMeasSubgroupToLpTrim_add hm map_smul' := lpMeasToLpTrim_smul hm norm_map' := lpMeasSubgroupToLpTrim_norm_map hm #align measure_theory.Lp_meas_to_Lp_trim_lie MeasureTheory.lpMeasToLpTrimLie variable {F 𝕜 p μ} instance [hm : Fact (m ≤ m0)] [CompleteSpace F] [hp : Fact (1 ≤ p)] : CompleteSpace (lpMeasSubgroup F m p μ) := by rw [(lpMeasSubgroupToLpTrimIso F p μ hm.elim).completeSpace_iff]; infer_instance -- For now just no-lint this; lean4's tree-based logging will make this easier to debug. -- One possible change might be to generalize `𝕜` from `RCLike` to `NormedField`, as this -- result may well hold there. -- Porting note: removed @[nolint fails_quickly] instance [hm : Fact (m ≤ m0)] [CompleteSpace F] [hp : Fact (1 ≤ p)] : CompleteSpace (lpMeas F 𝕜 m p μ) := by rw [(lpMeasSubgroupToLpMeasIso F 𝕜 p μ).symm.completeSpace_iff]; infer_instance theorem isComplete_aeStronglyMeasurable' [hp : Fact (1 ≤ p)] [CompleteSpace F] (hm : m ≤ m0) : IsComplete {f : Lp F p μ | AEStronglyMeasurable' m f μ} := by rw [← completeSpace_coe_iff_isComplete] haveI : Fact (m ≤ m0) := ⟨hm⟩ change CompleteSpace (lpMeasSubgroup F m p μ) infer_instance #align measure_theory.is_complete_ae_strongly_measurable' MeasureTheory.isComplete_aeStronglyMeasurable' theorem isClosed_aeStronglyMeasurable' [Fact (1 ≤ p)] [CompleteSpace F] (hm : m ≤ m0) : IsClosed {f : Lp F p μ | AEStronglyMeasurable' m f μ} := IsComplete.isClosed (isComplete_aeStronglyMeasurable' hm) #align measure_theory.is_closed_ae_strongly_measurable' MeasureTheory.isClosed_aeStronglyMeasurable' end CompleteSubspace section StronglyMeasurable variable {m m0 : MeasurableSpace α} {μ : Measure α} /-- We do not get `ae_fin_strongly_measurable f (μ.trim hm)`, since we don't have `f =ᵐ[μ.trim hm] Lp_meas_to_Lp_trim F 𝕜 p μ hm f` but only the weaker `f =ᵐ[μ] Lp_meas_to_Lp_trim F 𝕜 p μ hm f`. -/ theorem lpMeas.ae_fin_strongly_measurable' (hm : m ≤ m0) (f : lpMeas F 𝕜 m p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : -- Porting note: changed `f` to `f.1` in the next line. Not certain this is okay. ∃ g, FinStronglyMeasurable g (μ.trim hm) ∧ f.1 =ᵐ[μ] g := ⟨lpMeasSubgroupToLpTrim F p μ hm f, Lp.finStronglyMeasurable _ hp_ne_zero hp_ne_top, (lpMeasSubgroupToLpTrim_ae_eq hm f).symm⟩ #align measure_theory.Lp_meas.ae_fin_strongly_measurable' MeasureTheory.lpMeas.ae_fin_strongly_measurable' /-- When applying the inverse of `lpMeasToLpTrimLie` (which takes a function in the Lp space of the sub-sigma algebra and returns its version in the larger Lp space) to an indicator of the sub-sigma-algebra, we obtain an indicator in the Lp space of the larger sigma-algebra. -/ theorem lpMeasToLpTrimLie_symm_indicator [one_le_p : Fact (1 ≤ p)] [NormedSpace ℝ F] {hm : m ≤ m0} {s : Set α} {μ : Measure α} (hs : MeasurableSet[m] s) (hμs : μ.trim hm s ≠ ∞) (c : F) : ((lpMeasToLpTrimLie F ℝ p μ hm).symm (indicatorConstLp p hs hμs c) : Lp F p μ) = indicatorConstLp p (hm s hs) ((le_trim hm).trans_lt hμs.lt_top).ne c := by ext1 rw [← lpMeas_coe] change lpTrimToLpMeas F ℝ p μ hm (indicatorConstLp p hs hμs c) =ᵐ[μ] (indicatorConstLp p _ _ c : α → F) refine (lpTrimToLpMeas_ae_eq hm _).trans ?_ exact (ae_eq_of_ae_eq_trim indicatorConstLp_coeFn).trans indicatorConstLp_coeFn.symm #align measure_theory.Lp_meas_to_Lp_trim_lie_symm_indicator MeasureTheory.lpMeasToLpTrimLie_symm_indicator theorem lpMeasToLpTrimLie_symm_toLp [one_le_p : Fact (1 ≤ p)] [NormedSpace ℝ F] (hm : m ≤ m0) (f : α → F) (hf : Memℒp f p (μ.trim hm)) : ((lpMeasToLpTrimLie F ℝ p μ hm).symm (hf.toLp f) : Lp F p μ) = (memℒp_of_memℒp_trim hm hf).toLp f := by ext1 rw [← lpMeas_coe] refine (lpTrimToLpMeas_ae_eq hm _).trans ?_ exact (ae_eq_of_ae_eq_trim (Memℒp.coeFn_toLp hf)).trans (Memℒp.coeFn_toLp _).symm #align measure_theory.Lp_meas_to_Lp_trim_lie_symm_to_Lp MeasureTheory.lpMeasToLpTrimLie_symm_toLp end StronglyMeasurable end LpMeas section Induction variable {m m0 : MeasurableSpace α} {μ : Measure α} [Fact (1 ≤ p)] [NormedSpace ℝ F] /-- Auxiliary lemma for `Lp.induction_stronglyMeasurable`. -/ @[elab_as_elim] theorem Lp.induction_stronglyMeasurable_aux (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop) (h_ind : ∀ (c : F) {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s < ∞), P (Lp.simpleFunc.indicatorConst p (hm s hs) hμs.ne c)) (h_add : ∀ ⦃f g⦄, ∀ hf : Memℒp f p μ, ∀ hg : Memℒp g p μ, AEStronglyMeasurable' m f μ → AEStronglyMeasurable' m g μ → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) : ∀ f : Lp F p μ, AEStronglyMeasurable' m f μ → P f := by intro f hf let f' := (⟨f, hf⟩ : lpMeas F ℝ m p μ) let g := lpMeasToLpTrimLie F ℝ p μ hm f' have hfg : f' = (lpMeasToLpTrimLie F ℝ p μ hm).symm g := by simp only [f', g, LinearIsometryEquiv.symm_apply_apply] change P ↑f' rw [hfg] refine @Lp.induction α F m _ p (μ.trim hm) _ hp_ne_top (fun g => P ((lpMeasToLpTrimLie F ℝ p μ hm).symm g)) ?_ ?_ ?_ g · intro b t ht hμt -- Porting note: needed to pass `m` to `Lp.simpleFunc.coe_indicatorConst` to avoid -- synthesized type class instance is not definitionally equal to expression inferred by typing -- rules, synthesized m0 inferred m rw [@Lp.simpleFunc.coe_indicatorConst _ _ m, lpMeasToLpTrimLie_symm_indicator ht hμt.ne b] have hμt' : μ t < ∞ := (le_trim hm).trans_lt hμt specialize h_ind b ht hμt' rwa [Lp.simpleFunc.coe_indicatorConst] at h_ind · intro f g hf hg h_disj hfP hgP rw [LinearIsometryEquiv.map_add] push_cast have h_eq : ∀ (f : α → F) (hf : Memℒp f p (μ.trim hm)), ((lpMeasToLpTrimLie F ℝ p μ hm).symm (Memℒp.toLp f hf) : Lp F p μ) = (memℒp_of_memℒp_trim hm hf).toLp f := lpMeasToLpTrimLie_symm_toLp hm rw [h_eq f hf] at hfP ⊢ rw [h_eq g hg] at hgP ⊢ exact h_add (memℒp_of_memℒp_trim hm hf) (memℒp_of_memℒp_trim hm hg) (aeStronglyMeasurable'_of_aeStronglyMeasurable'_trim hm hf.aestronglyMeasurable) (aeStronglyMeasurable'_of_aeStronglyMeasurable'_trim hm hg.aestronglyMeasurable) h_disj hfP hgP · change IsClosed ((lpMeasToLpTrimLie F ℝ p μ hm).symm ⁻¹' {g : lpMeas F ℝ m p μ | P ↑g}) exact IsClosed.preimage (LinearIsometryEquiv.continuous _) h_closed #align measure_theory.Lp.induction_strongly_measurable_aux MeasureTheory.Lp.induction_stronglyMeasurable_aux /-- To prove something for an `Lp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in `Lp` strongly measurable w.r.t. `m` for which the property holds is closed. -/ @[elab_as_elim] theorem Lp.induction_stronglyMeasurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : Lp F p μ → Prop) (h_ind : ∀ (c : F) {s : Set α} (hs : MeasurableSet[m] s) (hμs : μ s < ∞), P (Lp.simpleFunc.indicatorConst p (hm s hs) hμs.ne c)) (h_add : ∀ ⦃f g⦄, ∀ hf : Memℒp f p μ, ∀ hg : Memℒp g p μ, StronglyMeasurable[m] f → StronglyMeasurable[m] g → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) : ∀ f : Lp F p μ, AEStronglyMeasurable' m f μ → P f := by intro f hf suffices h_add_ae : ∀ ⦃f g⦄, ∀ hf : Memℒp f p μ, ∀ hg : Memℒp g p μ, AEStronglyMeasurable' m f μ → AEStronglyMeasurable' m g μ → Disjoint (Function.support f) (Function.support g) → P (hf.toLp f) → P (hg.toLp g) → P (hf.toLp f + hg.toLp g) from -- Porting note: `P` should be an explicit argument to `Lp.induction_stronglyMeasurable_aux`, but -- it isn't? Lp.induction_stronglyMeasurable_aux hm hp_ne_top h_ind h_add_ae h_closed f hf intro f g hf hg hfm hgm h_disj hPf hPg let s_f : Set α := Function.support (hfm.mk f) have hs_f : MeasurableSet[m] s_f := hfm.stronglyMeasurable_mk.measurableSet_support have hs_f_eq : s_f =ᵐ[μ] Function.support f := hfm.ae_eq_mk.symm.support let s_g : Set α := Function.support (hgm.mk g) have hs_g : MeasurableSet[m] s_g := hgm.stronglyMeasurable_mk.measurableSet_support have hs_g_eq : s_g =ᵐ[μ] Function.support g := hgm.ae_eq_mk.symm.support have h_inter_empty : (s_f ∩ s_g : Set α) =ᵐ[μ] (∅ : Set α) := by refine (hs_f_eq.inter hs_g_eq).trans ?_ suffices Function.support f ∩ Function.support g = ∅ by rw [this] exact Set.disjoint_iff_inter_eq_empty.mp h_disj let f' := (s_f \ s_g).indicator (hfm.mk f) have hff' : f =ᵐ[μ] f' := by have : s_f \ s_g =ᵐ[μ] s_f := by rw [← Set.diff_inter_self_eq_diff, Set.inter_comm] refine ((ae_eq_refl s_f).diff h_inter_empty).trans ?_ rw [Set.diff_empty] refine ((indicator_ae_eq_of_ae_eq_set this).trans ?_).symm rw [Set.indicator_support] exact hfm.ae_eq_mk.symm have hf'_meas : StronglyMeasurable[m] f' := hfm.stronglyMeasurable_mk.indicator (hs_f.diff hs_g) have hf'_Lp : Memℒp f' p μ := hf.ae_eq hff' let g' := (s_g \ s_f).indicator (hgm.mk g) have hgg' : g =ᵐ[μ] g' := by have : s_g \ s_f =ᵐ[μ] s_g := by rw [← Set.diff_inter_self_eq_diff] refine ((ae_eq_refl s_g).diff h_inter_empty).trans ?_ rw [Set.diff_empty] refine ((indicator_ae_eq_of_ae_eq_set this).trans ?_).symm rw [Set.indicator_support] exact hgm.ae_eq_mk.symm have hg'_meas : StronglyMeasurable[m] g' := hgm.stronglyMeasurable_mk.indicator (hs_g.diff hs_f) have hg'_Lp : Memℒp g' p μ := hg.ae_eq hgg' have h_disj : Disjoint (Function.support f') (Function.support g') := haveI : Disjoint (s_f \ s_g) (s_g \ s_f) := disjoint_sdiff_sdiff this.mono Set.support_indicator_subset Set.support_indicator_subset rw [← Memℒp.toLp_congr hf'_Lp hf hff'.symm] at hPf ⊢ rw [← Memℒp.toLp_congr hg'_Lp hg hgg'.symm] at hPg ⊢ exact h_add hf'_Lp hg'_Lp hf'_meas hg'_meas h_disj hPf hPg #align measure_theory.Lp.induction_strongly_measurable MeasureTheory.Lp.induction_stronglyMeasurable /-- To prove something for an arbitrary `Memℒp` function a.e. strongly measurable with respect to a sub-σ-algebra `m` in a normed space, it suffices to show that * the property holds for (multiples of) characteristic functions which are measurable w.r.t. `m`; * is closed under addition; * the set of functions in the `Lᵖ` space strongly measurable w.r.t. `m` for which the property holds is closed. * the property is closed under the almost-everywhere equal relation. -/ @[elab_as_elim]
Mathlib/MeasureTheory/Function/ConditionalExpectation/AEMeasurable.lean
691
716
theorem Memℒp.induction_stronglyMeasurable (hm : m ≤ m0) (hp_ne_top : p ≠ ∞) (P : (α → F) → Prop) (h_ind : ∀ (c : F) ⦃s⦄, MeasurableSet[m] s → μ s < ∞ → P (s.indicator fun _ => c)) (h_add : ∀ ⦃f g : α → F⦄, Disjoint (Function.support f) (Function.support g) → Memℒp f p μ → Memℒp g p μ → StronglyMeasurable[m] f → StronglyMeasurable[m] g → P f → P g → P (f + g)) (h_closed : IsClosed {f : lpMeas F ℝ m p μ | P f}) (h_ae : ∀ ⦃f g⦄, f =ᵐ[μ] g → Memℒp f p μ → P f → P g) : ∀ ⦃f : α → F⦄, Memℒp f p μ → AEStronglyMeasurable' m f μ → P f := by
intro f hf hfm let f_Lp := hf.toLp f have hfm_Lp : AEStronglyMeasurable' m f_Lp μ := hfm.congr hf.coeFn_toLp.symm refine h_ae hf.coeFn_toLp (Lp.memℒp _) ?_ change P f_Lp -- Porting note: `P` should be an explicit argument to `Lp.induction_stronglyMeasurable`, but -- it isn't? refine Lp.induction_stronglyMeasurable hm hp_ne_top (P := fun f => P f) ?_ ?_ h_closed f_Lp hfm_Lp · intro c s hs hμs rw [Lp.simpleFunc.coe_indicatorConst] refine h_ae indicatorConstLp_coeFn.symm ?_ (h_ind c hs hμs) exact memℒp_indicator_const p (hm s hs) c (Or.inr hμs.ne) · intro f g hf_mem hg_mem hfm hgm h_disj hfP hgP have hfP' : P f := h_ae hf_mem.coeFn_toLp (Lp.memℒp _) hfP have hgP' : P g := h_ae hg_mem.coeFn_toLp (Lp.memℒp _) hgP specialize h_add h_disj hf_mem hg_mem hfm hgm hfP' hgP' refine h_ae ?_ (hf_mem.add hg_mem) h_add exact (hf_mem.coeFn_toLp.symm.add hg_mem.coeFn_toLp.symm).trans (Lp.coeFn_add _ _).symm
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Patrick Massot -/ import Mathlib.Data.Set.Image import Mathlib.Data.SProd #align_import data.set.prod from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4" /-! # Sets in product and pi types This file defines the product of sets in `α × β` and in `Π i, α i` along with the diagonal of a type. ## Main declarations * `Set.prod`: Binary product of sets. For `s : Set α`, `t : Set β`, we have `s.prod t : Set (α × β)`. * `Set.diagonal`: Diagonal of a type. `Set.diagonal α = {(x, x) | x : α}`. * `Set.offDiag`: Off-diagonal. `s ×ˢ s` without the diagonal. * `Set.pi`: Arbitrary product of sets. -/ open Function namespace Set /-! ### Cartesian binary product of sets -/ section Prod variable {α β γ δ : Type*} {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {a : α} {b : β} theorem Subsingleton.prod (hs : s.Subsingleton) (ht : t.Subsingleton) : (s ×ˢ t).Subsingleton := fun _x hx _y hy ↦ Prod.ext (hs hx.1 hy.1) (ht hx.2 hy.2) noncomputable instance decidableMemProd [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] : DecidablePred (· ∈ s ×ˢ t) := fun _ => And.decidable #align set.decidable_mem_prod Set.decidableMemProd @[gcongr] theorem prod_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁ ×ˢ t₁ ⊆ s₂ ×ˢ t₂ := fun _ ⟨h₁, h₂⟩ => ⟨hs h₁, ht h₂⟩ #align set.prod_mono Set.prod_mono @[gcongr] theorem prod_mono_left (hs : s₁ ⊆ s₂) : s₁ ×ˢ t ⊆ s₂ ×ˢ t := prod_mono hs Subset.rfl #align set.prod_mono_left Set.prod_mono_left @[gcongr] theorem prod_mono_right (ht : t₁ ⊆ t₂) : s ×ˢ t₁ ⊆ s ×ˢ t₂ := prod_mono Subset.rfl ht #align set.prod_mono_right Set.prod_mono_right @[simp] theorem prod_self_subset_prod_self : s₁ ×ˢ s₁ ⊆ s₂ ×ˢ s₂ ↔ s₁ ⊆ s₂ := ⟨fun h _ hx => (h (mk_mem_prod hx hx)).1, fun h _ hx => ⟨h hx.1, h hx.2⟩⟩ #align set.prod_self_subset_prod_self Set.prod_self_subset_prod_self @[simp] theorem prod_self_ssubset_prod_self : s₁ ×ˢ s₁ ⊂ s₂ ×ˢ s₂ ↔ s₁ ⊂ s₂ := and_congr prod_self_subset_prod_self <| not_congr prod_self_subset_prod_self #align set.prod_self_ssubset_prod_self Set.prod_self_ssubset_prod_self theorem prod_subset_iff {P : Set (α × β)} : s ×ˢ t ⊆ P ↔ ∀ x ∈ s, ∀ y ∈ t, (x, y) ∈ P := ⟨fun h _ hx _ hy => h (mk_mem_prod hx hy), fun h ⟨_, _⟩ hp => h _ hp.1 _ hp.2⟩ #align set.prod_subset_iff Set.prod_subset_iff theorem forall_prod_set {p : α × β → Prop} : (∀ x ∈ s ×ˢ t, p x) ↔ ∀ x ∈ s, ∀ y ∈ t, p (x, y) := prod_subset_iff #align set.forall_prod_set Set.forall_prod_set theorem exists_prod_set {p : α × β → Prop} : (∃ x ∈ s ×ˢ t, p x) ↔ ∃ x ∈ s, ∃ y ∈ t, p (x, y) := by simp [and_assoc] #align set.exists_prod_set Set.exists_prod_set @[simp] theorem prod_empty : s ×ˢ (∅ : Set β) = ∅ := by ext exact and_false_iff _ #align set.prod_empty Set.prod_empty @[simp] theorem empty_prod : (∅ : Set α) ×ˢ t = ∅ := by ext exact false_and_iff _ #align set.empty_prod Set.empty_prod @[simp, mfld_simps] theorem univ_prod_univ : @univ α ×ˢ @univ β = univ := by ext exact true_and_iff _ #align set.univ_prod_univ Set.univ_prod_univ theorem univ_prod {t : Set β} : (univ : Set α) ×ˢ t = Prod.snd ⁻¹' t := by simp [prod_eq] #align set.univ_prod Set.univ_prod theorem prod_univ {s : Set α} : s ×ˢ (univ : Set β) = Prod.fst ⁻¹' s := by simp [prod_eq] #align set.prod_univ Set.prod_univ @[simp] lemma prod_eq_univ [Nonempty α] [Nonempty β] : s ×ˢ t = univ ↔ s = univ ∧ t = univ := by simp [eq_univ_iff_forall, forall_and] @[simp] theorem singleton_prod : ({a} : Set α) ×ˢ t = Prod.mk a '' t := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.singleton_prod Set.singleton_prod @[simp] theorem prod_singleton : s ×ˢ ({b} : Set β) = (fun a => (a, b)) '' s := by ext ⟨x, y⟩ simp [and_left_comm, eq_comm] #align set.prod_singleton Set.prod_singleton theorem singleton_prod_singleton : ({a} : Set α) ×ˢ ({b} : Set β) = {(a, b)} := by simp #align set.singleton_prod_singleton Set.singleton_prod_singleton @[simp] theorem union_prod : (s₁ ∪ s₂) ×ˢ t = s₁ ×ˢ t ∪ s₂ ×ˢ t := by ext ⟨x, y⟩ simp [or_and_right] #align set.union_prod Set.union_prod @[simp] theorem prod_union : s ×ˢ (t₁ ∪ t₂) = s ×ˢ t₁ ∪ s ×ˢ t₂ := by ext ⟨x, y⟩ simp [and_or_left] #align set.prod_union Set.prod_union theorem inter_prod : (s₁ ∩ s₂) ×ˢ t = s₁ ×ˢ t ∩ s₂ ×ˢ t := by ext ⟨x, y⟩ simp only [← and_and_right, mem_inter_iff, mem_prod] #align set.inter_prod Set.inter_prod theorem prod_inter : s ×ˢ (t₁ ∩ t₂) = s ×ˢ t₁ ∩ s ×ˢ t₂ := by ext ⟨x, y⟩ simp only [← and_and_left, mem_inter_iff, mem_prod] #align set.prod_inter Set.prod_inter @[mfld_simps] theorem prod_inter_prod : s₁ ×ˢ t₁ ∩ s₂ ×ˢ t₂ = (s₁ ∩ s₂) ×ˢ (t₁ ∩ t₂) := by ext ⟨x, y⟩ simp [and_assoc, and_left_comm] #align set.prod_inter_prod Set.prod_inter_prod lemma compl_prod_eq_union {α β : Type*} (s : Set α) (t : Set β) : (s ×ˢ t)ᶜ = (sᶜ ×ˢ univ) ∪ (univ ×ˢ tᶜ) := by ext p simp only [mem_compl_iff, mem_prod, not_and, mem_union, mem_univ, and_true, true_and] constructor <;> intro h · by_cases fst_in_s : p.fst ∈ s · exact Or.inr (h fst_in_s) · exact Or.inl fst_in_s · intro fst_in_s simpa only [fst_in_s, not_true, false_or] using h @[simp] theorem disjoint_prod : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) ↔ Disjoint s₁ s₂ ∨ Disjoint t₁ t₂ := by simp_rw [disjoint_left, mem_prod, not_and_or, Prod.forall, and_imp, ← @forall_or_right α, ← @forall_or_left β, ← @forall_or_right (_ ∈ s₁), ← @forall_or_left (_ ∈ t₁)] #align set.disjoint_prod Set.disjoint_prod theorem Disjoint.set_prod_left (hs : Disjoint s₁ s₂) (t₁ t₂ : Set β) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨ha₁, _⟩ ⟨ha₂, _⟩ => disjoint_left.1 hs ha₁ ha₂ #align set.disjoint.set_prod_left Set.Disjoint.set_prod_left theorem Disjoint.set_prod_right (ht : Disjoint t₁ t₂) (s₁ s₂ : Set α) : Disjoint (s₁ ×ˢ t₁) (s₂ ×ˢ t₂) := disjoint_left.2 fun ⟨_a, _b⟩ ⟨_, hb₁⟩ ⟨_, hb₂⟩ => disjoint_left.1 ht hb₁ hb₂ #align set.disjoint.set_prod_right Set.Disjoint.set_prod_right theorem insert_prod : insert a s ×ˢ t = Prod.mk a '' t ∪ s ×ˢ t := by ext ⟨x, y⟩ simp (config := { contextual := true }) [image, iff_def, or_imp] #align set.insert_prod Set.insert_prod theorem prod_insert : s ×ˢ insert b t = (fun a => (a, b)) '' s ∪ s ×ˢ t := by ext ⟨x, y⟩ -- porting note (#10745): -- was `simp (config := { contextual := true }) [image, iff_def, or_imp, Imp.swap]` simp only [mem_prod, mem_insert_iff, image, mem_union, mem_setOf_eq, Prod.mk.injEq] refine ⟨fun h => ?_, fun h => ?_⟩ · obtain ⟨hx, rfl|hy⟩ := h · exact Or.inl ⟨x, hx, rfl, rfl⟩ · exact Or.inr ⟨hx, hy⟩ · obtain ⟨x, hx, rfl, rfl⟩|⟨hx, hy⟩ := h · exact ⟨hx, Or.inl rfl⟩ · exact ⟨hx, Or.inr hy⟩ #align set.prod_insert Set.prod_insert theorem prod_preimage_eq {f : γ → α} {g : δ → β} : (f ⁻¹' s) ×ˢ (g ⁻¹' t) = (fun p : γ × δ => (f p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_eq Set.prod_preimage_eq theorem prod_preimage_left {f : γ → α} : (f ⁻¹' s) ×ˢ t = (fun p : γ × β => (f p.1, p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_left Set.prod_preimage_left theorem prod_preimage_right {g : δ → β} : s ×ˢ (g ⁻¹' t) = (fun p : α × δ => (p.1, g p.2)) ⁻¹' s ×ˢ t := rfl #align set.prod_preimage_right Set.prod_preimage_right theorem preimage_prod_map_prod (f : α → β) (g : γ → δ) (s : Set β) (t : Set δ) : Prod.map f g ⁻¹' s ×ˢ t = (f ⁻¹' s) ×ˢ (g ⁻¹' t) := rfl #align set.preimage_prod_map_prod Set.preimage_prod_map_prod theorem mk_preimage_prod (f : γ → α) (g : γ → β) : (fun x => (f x, g x)) ⁻¹' s ×ˢ t = f ⁻¹' s ∩ g ⁻¹' t := rfl #align set.mk_preimage_prod Set.mk_preimage_prod @[simp] theorem mk_preimage_prod_left (hb : b ∈ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = s := by ext a simp [hb] #align set.mk_preimage_prod_left Set.mk_preimage_prod_left @[simp] theorem mk_preimage_prod_right (ha : a ∈ s) : Prod.mk a ⁻¹' s ×ˢ t = t := by ext b simp [ha] #align set.mk_preimage_prod_right Set.mk_preimage_prod_right @[simp] theorem mk_preimage_prod_left_eq_empty (hb : b ∉ t) : (fun a => (a, b)) ⁻¹' s ×ˢ t = ∅ := by ext a simp [hb] #align set.mk_preimage_prod_left_eq_empty Set.mk_preimage_prod_left_eq_empty @[simp] theorem mk_preimage_prod_right_eq_empty (ha : a ∉ s) : Prod.mk a ⁻¹' s ×ˢ t = ∅ := by ext b simp [ha] #align set.mk_preimage_prod_right_eq_empty Set.mk_preimage_prod_right_eq_empty theorem mk_preimage_prod_left_eq_if [DecidablePred (· ∈ t)] : (fun a => (a, b)) ⁻¹' s ×ˢ t = if b ∈ t then s else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_left_eq_if Set.mk_preimage_prod_left_eq_if theorem mk_preimage_prod_right_eq_if [DecidablePred (· ∈ s)] : Prod.mk a ⁻¹' s ×ˢ t = if a ∈ s then t else ∅ := by split_ifs with h <;> simp [h] #align set.mk_preimage_prod_right_eq_if Set.mk_preimage_prod_right_eq_if theorem mk_preimage_prod_left_fn_eq_if [DecidablePred (· ∈ t)] (f : γ → α) : (fun a => (f a, b)) ⁻¹' s ×ˢ t = if b ∈ t then f ⁻¹' s else ∅ := by rw [← mk_preimage_prod_left_eq_if, prod_preimage_left, preimage_preimage] #align set.mk_preimage_prod_left_fn_eq_if Set.mk_preimage_prod_left_fn_eq_if theorem mk_preimage_prod_right_fn_eq_if [DecidablePred (· ∈ s)] (g : δ → β) : (fun b => (a, g b)) ⁻¹' s ×ˢ t = if a ∈ s then g ⁻¹' t else ∅ := by rw [← mk_preimage_prod_right_eq_if, prod_preimage_right, preimage_preimage] #align set.mk_preimage_prod_right_fn_eq_if Set.mk_preimage_prod_right_fn_eq_if @[simp] theorem preimage_swap_prod (s : Set α) (t : Set β) : Prod.swap ⁻¹' s ×ˢ t = t ×ˢ s := by ext ⟨x, y⟩ simp [and_comm] #align set.preimage_swap_prod Set.preimage_swap_prod @[simp] theorem image_swap_prod (s : Set α) (t : Set β) : Prod.swap '' s ×ˢ t = t ×ˢ s := by rw [image_swap_eq_preimage_swap, preimage_swap_prod] #align set.image_swap_prod Set.image_swap_prod theorem prod_image_image_eq {m₁ : α → γ} {m₂ : β → δ} : (m₁ '' s) ×ˢ (m₂ '' t) = (fun p : α × β => (m₁ p.1, m₂ p.2)) '' s ×ˢ t := ext <| by simp [-exists_and_right, exists_and_right.symm, and_left_comm, and_assoc, and_comm] #align set.prod_image_image_eq Set.prod_image_image_eq theorem prod_range_range_eq {m₁ : α → γ} {m₂ : β → δ} : range m₁ ×ˢ range m₂ = range fun p : α × β => (m₁ p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_range_range_eq Set.prod_range_range_eq @[simp, mfld_simps] theorem range_prod_map {m₁ : α → γ} {m₂ : β → δ} : range (Prod.map m₁ m₂) = range m₁ ×ˢ range m₂ := prod_range_range_eq.symm #align set.range_prod_map Set.range_prod_map theorem prod_range_univ_eq {m₁ : α → γ} : range m₁ ×ˢ (univ : Set β) = range fun p : α × β => (m₁ p.1, p.2) := ext <| by simp [range] #align set.prod_range_univ_eq Set.prod_range_univ_eq theorem prod_univ_range_eq {m₂ : β → δ} : (univ : Set α) ×ˢ range m₂ = range fun p : α × β => (p.1, m₂ p.2) := ext <| by simp [range] #align set.prod_univ_range_eq Set.prod_univ_range_eq theorem range_pair_subset (f : α → β) (g : α → γ) : (range fun x => (f x, g x)) ⊆ range f ×ˢ range g := by have : (fun x => (f x, g x)) = Prod.map f g ∘ fun x => (x, x) := funext fun x => rfl rw [this, ← range_prod_map] apply range_comp_subset_range #align set.range_pair_subset Set.range_pair_subset theorem Nonempty.prod : s.Nonempty → t.Nonempty → (s ×ˢ t).Nonempty := fun ⟨x, hx⟩ ⟨y, hy⟩ => ⟨(x, y), ⟨hx, hy⟩⟩ #align set.nonempty.prod Set.Nonempty.prod theorem Nonempty.fst : (s ×ˢ t).Nonempty → s.Nonempty := fun ⟨x, hx⟩ => ⟨x.1, hx.1⟩ #align set.nonempty.fst Set.Nonempty.fst theorem Nonempty.snd : (s ×ˢ t).Nonempty → t.Nonempty := fun ⟨x, hx⟩ => ⟨x.2, hx.2⟩ #align set.nonempty.snd Set.Nonempty.snd @[simp] theorem prod_nonempty_iff : (s ×ˢ t).Nonempty ↔ s.Nonempty ∧ t.Nonempty := ⟨fun h => ⟨h.fst, h.snd⟩, fun h => h.1.prod h.2⟩ #align set.prod_nonempty_iff Set.prod_nonempty_iff @[simp] theorem prod_eq_empty_iff : s ×ˢ t = ∅ ↔ s = ∅ ∨ t = ∅ := by simp only [not_nonempty_iff_eq_empty.symm, prod_nonempty_iff, not_and_or] #align set.prod_eq_empty_iff Set.prod_eq_empty_iff theorem prod_sub_preimage_iff {W : Set γ} {f : α × β → γ} : s ×ˢ t ⊆ f ⁻¹' W ↔ ∀ a b, a ∈ s → b ∈ t → f (a, b) ∈ W := by simp [subset_def] #align set.prod_sub_preimage_iff Set.prod_sub_preimage_iff theorem image_prod_mk_subset_prod {f : α → β} {g : α → γ} {s : Set α} : (fun x => (f x, g x)) '' s ⊆ (f '' s) ×ˢ (g '' s) := by rintro _ ⟨x, hx, rfl⟩ exact mk_mem_prod (mem_image_of_mem f hx) (mem_image_of_mem g hx) #align set.image_prod_mk_subset_prod Set.image_prod_mk_subset_prod theorem image_prod_mk_subset_prod_left (hb : b ∈ t) : (fun a => (a, b)) '' s ⊆ s ×ˢ t := by rintro _ ⟨a, ha, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_left Set.image_prod_mk_subset_prod_left theorem image_prod_mk_subset_prod_right (ha : a ∈ s) : Prod.mk a '' t ⊆ s ×ˢ t := by rintro _ ⟨b, hb, rfl⟩ exact ⟨ha, hb⟩ #align set.image_prod_mk_subset_prod_right Set.image_prod_mk_subset_prod_right theorem prod_subset_preimage_fst (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.fst ⁻¹' s := inter_subset_left #align set.prod_subset_preimage_fst Set.prod_subset_preimage_fst theorem fst_image_prod_subset (s : Set α) (t : Set β) : Prod.fst '' s ×ˢ t ⊆ s := image_subset_iff.2 <| prod_subset_preimage_fst s t #align set.fst_image_prod_subset Set.fst_image_prod_subset theorem fst_image_prod (s : Set β) {t : Set α} (ht : t.Nonempty) : Prod.fst '' s ×ˢ t = s := (fst_image_prod_subset _ _).antisymm fun y hy => let ⟨x, hx⟩ := ht ⟨(y, x), ⟨hy, hx⟩, rfl⟩ #align set.fst_image_prod Set.fst_image_prod theorem prod_subset_preimage_snd (s : Set α) (t : Set β) : s ×ˢ t ⊆ Prod.snd ⁻¹' t := inter_subset_right #align set.prod_subset_preimage_snd Set.prod_subset_preimage_snd theorem snd_image_prod_subset (s : Set α) (t : Set β) : Prod.snd '' s ×ˢ t ⊆ t := image_subset_iff.2 <| prod_subset_preimage_snd s t #align set.snd_image_prod_subset Set.snd_image_prod_subset theorem snd_image_prod {s : Set α} (hs : s.Nonempty) (t : Set β) : Prod.snd '' s ×ˢ t = t := (snd_image_prod_subset _ _).antisymm fun y y_in => let ⟨x, x_in⟩ := hs ⟨(x, y), ⟨x_in, y_in⟩, rfl⟩ #align set.snd_image_prod Set.snd_image_prod theorem prod_diff_prod : s ×ˢ t \ s₁ ×ˢ t₁ = s ×ˢ (t \ t₁) ∪ (s \ s₁) ×ˢ t := by ext x by_cases h₁ : x.1 ∈ s₁ <;> by_cases h₂ : x.2 ∈ t₁ <;> simp [*] #align set.prod_diff_prod Set.prod_diff_prod /-- A product set is included in a product set if and only factors are included, or a factor of the first set is empty. -/ theorem prod_subset_prod_iff : s ×ˢ t ⊆ s₁ ×ˢ t₁ ↔ s ⊆ s₁ ∧ t ⊆ t₁ ∨ s = ∅ ∨ t = ∅ := by rcases (s ×ˢ t).eq_empty_or_nonempty with h | h · simp [h, prod_eq_empty_iff.1 h] have st : s.Nonempty ∧ t.Nonempty := by rwa [prod_nonempty_iff] at h refine ⟨fun H => Or.inl ⟨?_, ?_⟩, ?_⟩ · have := image_subset (Prod.fst : α × β → α) H rwa [fst_image_prod _ st.2, fst_image_prod _ (h.mono H).snd] at this · have := image_subset (Prod.snd : α × β → β) H rwa [snd_image_prod st.1, snd_image_prod (h.mono H).fst] at this · intro H simp only [st.1.ne_empty, st.2.ne_empty, or_false_iff] at H exact prod_mono H.1 H.2 #align set.prod_subset_prod_iff Set.prod_subset_prod_iff theorem prod_eq_prod_iff_of_nonempty (h : (s ×ˢ t).Nonempty) : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ := by constructor · intro heq have h₁ : (s₁ ×ˢ t₁ : Set _).Nonempty := by rwa [← heq] rw [prod_nonempty_iff] at h h₁ rw [← fst_image_prod s h.2, ← fst_image_prod s₁ h₁.2, heq, eq_self_iff_true, true_and_iff, ← snd_image_prod h.1 t, ← snd_image_prod h₁.1 t₁, heq] · rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_prod_iff_of_nonempty Set.prod_eq_prod_iff_of_nonempty theorem prod_eq_prod_iff : s ×ˢ t = s₁ ×ˢ t₁ ↔ s = s₁ ∧ t = t₁ ∨ (s = ∅ ∨ t = ∅) ∧ (s₁ = ∅ ∨ t₁ = ∅) := by symm rcases eq_empty_or_nonempty (s ×ˢ t) with h | h · simp_rw [h, @eq_comm _ ∅, prod_eq_empty_iff, prod_eq_empty_iff.mp h, true_and_iff, or_iff_right_iff_imp] rintro ⟨rfl, rfl⟩ exact prod_eq_empty_iff.mp h rw [prod_eq_prod_iff_of_nonempty h] rw [nonempty_iff_ne_empty, Ne, prod_eq_empty_iff] at h simp_rw [h, false_and_iff, or_false_iff] #align set.prod_eq_prod_iff Set.prod_eq_prod_iff @[simp] theorem prod_eq_iff_eq (ht : t.Nonempty) : s ×ˢ t = s₁ ×ˢ t ↔ s = s₁ := by simp_rw [prod_eq_prod_iff, ht.ne_empty, and_true_iff, or_iff_left_iff_imp, or_false_iff] rintro ⟨rfl, rfl⟩ rfl #align set.prod_eq_iff_eq Set.prod_eq_iff_eq section Mono variable [Preorder α] {f : α → Set β} {g : α → Set γ} theorem _root_.Monotone.set_prod (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align monotone.set_prod Monotone.set_prod theorem _root_.Antitone.set_prod (hf : Antitone f) (hg : Antitone g) : Antitone fun x => f x ×ˢ g x := fun _ _ h => prod_mono (hf h) (hg h) #align antitone.set_prod Antitone.set_prod theorem _root_.MonotoneOn.set_prod (hf : MonotoneOn f s) (hg : MonotoneOn g s) : MonotoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align monotone_on.set_prod MonotoneOn.set_prod theorem _root_.AntitoneOn.set_prod (hf : AntitoneOn f s) (hg : AntitoneOn g s) : AntitoneOn (fun x => f x ×ˢ g x) s := fun _ ha _ hb h => prod_mono (hf ha hb h) (hg ha hb h) #align antitone_on.set_prod AntitoneOn.set_prod end Mono end Prod /-! ### Diagonal In this section we prove some lemmas about the diagonal set `{p | p.1 = p.2}` and the diagonal map `fun x ↦ (x, x)`. -/ section Diagonal variable {α : Type*} {s t : Set α} lemma diagonal_nonempty [Nonempty α] : (diagonal α).Nonempty := Nonempty.elim ‹_› fun x => ⟨_, mem_diagonal x⟩ #align set.diagonal_nonempty Set.diagonal_nonempty instance decidableMemDiagonal [h : DecidableEq α] (x : α × α) : Decidable (x ∈ diagonal α) := h x.1 x.2 #align set.decidable_mem_diagonal Set.decidableMemDiagonal theorem preimage_coe_coe_diagonal (s : Set α) : Prod.map (fun x : s => (x : α)) (fun x : s => (x : α)) ⁻¹' diagonal α = diagonal s := by ext ⟨⟨x, hx⟩, ⟨y, hy⟩⟩ simp [Set.diagonal] #align set.preimage_coe_coe_diagonal Set.preimage_coe_coe_diagonal @[simp] theorem range_diag : (range fun x => (x, x)) = diagonal α := by ext ⟨x, y⟩ simp [diagonal, eq_comm] #align set.range_diag Set.range_diag theorem diagonal_subset_iff {s} : diagonal α ⊆ s ↔ ∀ x, (x, x) ∈ s := by rw [← range_diag, range_subset_iff] #align set.diagonal_subset_iff Set.diagonal_subset_iff @[simp] theorem prod_subset_compl_diagonal_iff_disjoint : s ×ˢ t ⊆ (diagonal α)ᶜ ↔ Disjoint s t := prod_subset_iff.trans disjoint_iff_forall_ne.symm #align set.prod_subset_compl_diagonal_iff_disjoint Set.prod_subset_compl_diagonal_iff_disjoint @[simp] theorem diag_preimage_prod (s t : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ t = s ∩ t := rfl #align set.diag_preimage_prod Set.diag_preimage_prod theorem diag_preimage_prod_self (s : Set α) : (fun x => (x, x)) ⁻¹' s ×ˢ s = s := inter_self s #align set.diag_preimage_prod_self Set.diag_preimage_prod_self theorem diag_image (s : Set α) : (fun x => (x, x)) '' s = diagonal α ∩ s ×ˢ s := by rw [← range_diag, ← image_preimage_eq_range_inter, diag_preimage_prod_self] #align set.diag_image Set.diag_image theorem diagonal_eq_univ_iff : diagonal α = univ ↔ Subsingleton α := by simp only [subsingleton_iff, eq_univ_iff_forall, Prod.forall, mem_diagonal_iff] theorem diagonal_eq_univ [Subsingleton α] : diagonal α = univ := diagonal_eq_univ_iff.2 ‹_› end Diagonal /-- A function is `Function.const α a` for some `a` if and only if `∀ x y, f x = f y`. -/ theorem range_const_eq_diagonal {α β : Type*} [hβ : Nonempty β] : range (const α) = {f : α → β | ∀ x y, f x = f y} := by refine (range_eq_iff _ _).mpr ⟨fun _ _ _ ↦ rfl, fun f hf ↦ ?_⟩ rcases isEmpty_or_nonempty α with h|⟨⟨a⟩⟩ · exact hβ.elim fun b ↦ ⟨b, Subsingleton.elim _ _⟩ · exact ⟨f a, funext fun x ↦ hf _ _⟩ end Set section Pullback open Set variable {X Y Z} /-- The fiber product $X \times_Y Z$. -/ abbrev Function.Pullback (f : X → Y) (g : Z → Y) := {p : X × Z // f p.1 = g p.2} /-- The fiber product $X \times_Y X$. -/ abbrev Function.PullbackSelf (f : X → Y) := f.Pullback f /-- The projection from the fiber product to the first factor. -/ def Function.Pullback.fst {f : X → Y} {g : Z → Y} (p : f.Pullback g) : X := p.val.1 /-- The projection from the fiber product to the second factor. -/ def Function.Pullback.snd {f : X → Y} {g : Z → Y} (p : f.Pullback g) : Z := p.val.2 open Function.Pullback in lemma Function.pullback_comm_sq (f : X → Y) (g : Z → Y) : f ∘ @fst X Y Z f g = g ∘ @snd X Y Z f g := funext fun p ↦ p.2 /-- The diagonal map $\Delta: X \to X \times_Y X$. -/ def toPullbackDiag (f : X → Y) (x : X) : f.Pullback f := ⟨(x, x), rfl⟩ /-- The diagonal $\Delta(X) \subseteq X \times_Y X$. -/ def Function.pullbackDiagonal (f : X → Y) : Set (f.Pullback f) := {p | p.fst = p.snd} /-- Three functions between the three pairs of spaces $X_i, Y_i, Z_i$ that are compatible induce a function $X_1 \times_{Y_1} Z_1 \to X_2 \times_{Y_2} Z_2$. -/ def Function.mapPullback {X₁ X₂ Y₁ Y₂ Z₁ Z₂} {f₁ : X₁ → Y₁} {g₁ : Z₁ → Y₁} {f₂ : X₂ → Y₂} {g₂ : Z₂ → Y₂} (mapX : X₁ → X₂) (mapY : Y₁ → Y₂) (mapZ : Z₁ → Z₂) (commX : f₂ ∘ mapX = mapY ∘ f₁) (commZ : g₂ ∘ mapZ = mapY ∘ g₁) (p : f₁.Pullback g₁) : f₂.Pullback g₂ := ⟨(mapX p.fst, mapZ p.snd), (congr_fun commX _).trans <| (congr_arg mapY p.2).trans <| congr_fun commZ.symm _⟩ open Function.Pullback in /-- The projection $(X \times_Y Z) \times_Z (X \times_Y Z) \to X \times_Y X$. -/ def Function.PullbackSelf.map_fst {f : X → Y} {g : Z → Y} : (@snd X Y Z f g).PullbackSelf → f.PullbackSelf := mapPullback fst g fst (pullback_comm_sq f g) (pullback_comm_sq f g) open Function.Pullback in /-- The projection $(X \times_Y Z) \times_X (X \times_Y Z) \to Z \times_Y Z$. -/ def Function.PullbackSelf.map_snd {f : X → Y} {g : Z → Y} : (@fst X Y Z f g).PullbackSelf → g.PullbackSelf := mapPullback snd f snd (pullback_comm_sq f g).symm (pullback_comm_sq f g).symm open Function.PullbackSelf Function.Pullback theorem preimage_map_fst_pullbackDiagonal {f : X → Y} {g : Z → Y} : @map_fst X Y Z f g ⁻¹' pullbackDiagonal f = pullbackDiagonal (@snd X Y Z f g) := by ext ⟨⟨p₁, p₂⟩, he⟩ simp_rw [pullbackDiagonal, mem_setOf, Subtype.ext_iff, Prod.ext_iff] exact (and_iff_left he).symm theorem Function.Injective.preimage_pullbackDiagonal {f : X → Y} {g : Z → X} (inj : g.Injective) : mapPullback g id g (by rfl) (by rfl) ⁻¹' pullbackDiagonal f = pullbackDiagonal (f ∘ g) := ext fun _ ↦ inj.eq_iff theorem image_toPullbackDiag (f : X → Y) (s : Set X) : toPullbackDiag f '' s = pullbackDiagonal f ∩ Subtype.val ⁻¹' s ×ˢ s := by ext x constructor · rintro ⟨x, hx, rfl⟩ exact ⟨rfl, hx, hx⟩ · obtain ⟨⟨x, y⟩, h⟩ := x rintro ⟨rfl : x = y, h2x⟩ exact mem_image_of_mem _ h2x.1 theorem range_toPullbackDiag (f : X → Y) : range (toPullbackDiag f) = pullbackDiagonal f := by rw [← image_univ, image_toPullbackDiag, univ_prod_univ, preimage_univ, inter_univ] theorem injective_toPullbackDiag (f : X → Y) : (toPullbackDiag f).Injective := fun _ _ h ↦ congr_arg Prod.fst (congr_arg Subtype.val h) end Pullback namespace Set section OffDiag variable {α : Type*} {s t : Set α} {x : α × α} {a : α} theorem offDiag_mono : Monotone (offDiag : Set α → Set (α × α)) := fun _ _ h _ => And.imp (@h _) <| And.imp_left <| @h _ #align set.off_diag_mono Set.offDiag_mono @[simp] theorem offDiag_nonempty : s.offDiag.Nonempty ↔ s.Nontrivial := by simp [offDiag, Set.Nonempty, Set.Nontrivial] #align set.off_diag_nonempty Set.offDiag_nonempty @[simp] theorem offDiag_eq_empty : s.offDiag = ∅ ↔ s.Subsingleton := by rw [← not_nonempty_iff_eq_empty, ← not_nontrivial_iff, offDiag_nonempty.not] #align set.off_diag_eq_empty Set.offDiag_eq_empty alias ⟨_, Nontrivial.offDiag_nonempty⟩ := offDiag_nonempty #align set.nontrivial.off_diag_nonempty Set.Nontrivial.offDiag_nonempty alias ⟨_, Subsingleton.offDiag_eq_empty⟩ := offDiag_nonempty #align set.subsingleton.off_diag_eq_empty Set.Subsingleton.offDiag_eq_empty variable (s t) theorem offDiag_subset_prod : s.offDiag ⊆ s ×ˢ s := fun _ hx => ⟨hx.1, hx.2.1⟩ #align set.off_diag_subset_prod Set.offDiag_subset_prod theorem offDiag_eq_sep_prod : s.offDiag = { x ∈ s ×ˢ s | x.1 ≠ x.2 } := ext fun _ => and_assoc.symm #align set.off_diag_eq_sep_prod Set.offDiag_eq_sep_prod @[simp] theorem offDiag_empty : (∅ : Set α).offDiag = ∅ := by simp #align set.off_diag_empty Set.offDiag_empty @[simp] theorem offDiag_singleton (a : α) : ({a} : Set α).offDiag = ∅ := by simp #align set.off_diag_singleton Set.offDiag_singleton @[simp] theorem offDiag_univ : (univ : Set α).offDiag = (diagonal α)ᶜ := ext <| by simp #align set.off_diag_univ Set.offDiag_univ @[simp] theorem prod_sdiff_diagonal : s ×ˢ s \ diagonal α = s.offDiag := ext fun _ => and_assoc #align set.prod_sdiff_diagonal Set.prod_sdiff_diagonal @[simp] theorem disjoint_diagonal_offDiag : Disjoint (diagonal α) s.offDiag := disjoint_left.mpr fun _ hd ho => ho.2.2 hd #align set.disjoint_diagonal_off_diag Set.disjoint_diagonal_offDiag theorem offDiag_inter : (s ∩ t).offDiag = s.offDiag ∩ t.offDiag := ext fun x => by simp only [mem_offDiag, mem_inter_iff] tauto #align set.off_diag_inter Set.offDiag_inter variable {s t} theorem offDiag_union (h : Disjoint s t) : (s ∪ t).offDiag = s.offDiag ∪ t.offDiag ∪ s ×ˢ t ∪ t ×ˢ s := by ext x simp only [mem_offDiag, mem_union, ne_eq, mem_prod] constructor · rintro ⟨h0|h0, h1|h1, h2⟩ <;> simp [h0, h1, h2] · rintro (((⟨h0, h1, h2⟩|⟨h0, h1, h2⟩)|⟨h0, h1⟩)|⟨h0, h1⟩) <;> simp [*] · rintro h3 rw [h3] at h0 exact Set.disjoint_left.mp h h0 h1 · rintro h3 rw [h3] at h0 exact (Set.disjoint_right.mp h h0 h1).elim #align set.off_diag_union Set.offDiag_union theorem offDiag_insert (ha : a ∉ s) : (insert a s).offDiag = s.offDiag ∪ {a} ×ˢ s ∪ s ×ˢ {a} := by rw [insert_eq, union_comm, offDiag_union, offDiag_singleton, union_empty, union_right_comm] rw [disjoint_left] rintro b hb (rfl : b = a) exact ha hb #align set.off_diag_insert Set.offDiag_insert end OffDiag /-! ### Cartesian set-indexed product of sets -/ section Pi variable {ι : Type*} {α β : ι → Type*} {s s₁ s₂ : Set ι} {t t₁ t₂ : ∀ i, Set (α i)} {i : ι} @[simp] theorem empty_pi (s : ∀ i, Set (α i)) : pi ∅ s = univ := by ext simp [pi] #align set.empty_pi Set.empty_pi theorem subsingleton_univ_pi (ht : ∀ i, (t i).Subsingleton) : (univ.pi t).Subsingleton := fun _f hf _g hg ↦ funext fun i ↦ (ht i) (hf _ <| mem_univ _) (hg _ <| mem_univ _) @[simp] theorem pi_univ (s : Set ι) : (pi s fun i => (univ : Set (α i))) = univ := eq_univ_of_forall fun _ _ _ => mem_univ _ #align set.pi_univ Set.pi_univ @[simp] theorem pi_univ_ite (s : Set ι) [DecidablePred (· ∈ s)] (t : ∀ i, Set (α i)) : (pi univ fun i => if i ∈ s then t i else univ) = s.pi t := by ext; simp_rw [Set.mem_pi]; apply forall_congr'; intro i; split_ifs with h <;> simp [h] theorem pi_mono (h : ∀ i ∈ s, t₁ i ⊆ t₂ i) : pi s t₁ ⊆ pi s t₂ := fun _ hx i hi => h i hi <| hx i hi #align set.pi_mono Set.pi_mono theorem pi_inter_distrib : (s.pi fun i => t i ∩ t₁ i) = s.pi t ∩ s.pi t₁ := ext fun x => by simp only [forall_and, mem_pi, mem_inter_iff] #align set.pi_inter_distrib Set.pi_inter_distrib theorem pi_congr (h : s₁ = s₂) (h' : ∀ i ∈ s₁, t₁ i = t₂ i) : s₁.pi t₁ = s₂.pi t₂ := h ▸ ext fun _ => forall₂_congr fun i hi => h' i hi ▸ Iff.rfl #align set.pi_congr Set.pi_congr theorem pi_eq_empty (hs : i ∈ s) (ht : t i = ∅) : s.pi t = ∅ := by ext f simp only [mem_empty_iff_false, not_forall, iff_false_iff, mem_pi, Classical.not_imp] exact ⟨i, hs, by simp [ht]⟩ #align set.pi_eq_empty Set.pi_eq_empty theorem univ_pi_eq_empty (ht : t i = ∅) : pi univ t = ∅ := pi_eq_empty (mem_univ i) ht #align set.univ_pi_eq_empty Set.univ_pi_eq_empty theorem pi_nonempty_iff : (s.pi t).Nonempty ↔ ∀ i, ∃ x, i ∈ s → x ∈ t i := by simp [Classical.skolem, Set.Nonempty] #align set.pi_nonempty_iff Set.pi_nonempty_iff theorem univ_pi_nonempty_iff : (pi univ t).Nonempty ↔ ∀ i, (t i).Nonempty := by simp [Classical.skolem, Set.Nonempty] #align set.univ_pi_nonempty_iff Set.univ_pi_nonempty_iff theorem pi_eq_empty_iff : s.pi t = ∅ ↔ ∃ i, IsEmpty (α i) ∨ i ∈ s ∧ t i = ∅ := by rw [← not_nonempty_iff_eq_empty, pi_nonempty_iff] push_neg refine exists_congr fun i => ?_ cases isEmpty_or_nonempty (α i) <;> simp [*, forall_and, eq_empty_iff_forall_not_mem] #align set.pi_eq_empty_iff Set.pi_eq_empty_iff @[simp] theorem univ_pi_eq_empty_iff : pi univ t = ∅ ↔ ∃ i, t i = ∅ := by simp [← not_nonempty_iff_eq_empty, univ_pi_nonempty_iff] #align set.univ_pi_eq_empty_iff Set.univ_pi_eq_empty_iff @[simp] theorem univ_pi_empty [h : Nonempty ι] : pi univ (fun _ => ∅ : ∀ i, Set (α i)) = ∅ := univ_pi_eq_empty_iff.2 <| h.elim fun x => ⟨x, rfl⟩ #align set.univ_pi_empty Set.univ_pi_empty @[simp] theorem disjoint_univ_pi : Disjoint (pi univ t₁) (pi univ t₂) ↔ ∃ i, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, univ_pi_eq_empty_iff] #align set.disjoint_univ_pi Set.disjoint_univ_pi theorem Disjoint.set_pi (hi : i ∈ s) (ht : Disjoint (t₁ i) (t₂ i)) : Disjoint (s.pi t₁) (s.pi t₂) := disjoint_left.2 fun _ h₁ h₂ => disjoint_left.1 ht (h₁ _ hi) (h₂ _ hi) #align set.disjoint.set_pi Set.Disjoint.set_pi theorem uniqueElim_preimage [Unique ι] (t : ∀ i, Set (α i)) : uniqueElim ⁻¹' pi univ t = t (default : ι) := by ext; simp [Unique.forall_iff] section Nonempty variable [∀ i, Nonempty (α i)] theorem pi_eq_empty_iff' : s.pi t = ∅ ↔ ∃ i ∈ s, t i = ∅ := by simp [pi_eq_empty_iff] #align set.pi_eq_empty_iff' Set.pi_eq_empty_iff' @[simp] theorem disjoint_pi : Disjoint (s.pi t₁) (s.pi t₂) ↔ ∃ i ∈ s, Disjoint (t₁ i) (t₂ i) := by simp only [disjoint_iff_inter_eq_empty, ← pi_inter_distrib, pi_eq_empty_iff'] #align set.disjoint_pi Set.disjoint_pi end Nonempty -- Porting note: Removing `simp` - LHS does not simplify theorem range_dcomp (f : ∀ i, α i → β i) : (range fun g : ∀ i, α i => fun i => f i (g i)) = pi univ fun i => range (f i) := by refine Subset.antisymm ?_ fun x hx => ?_ · rintro _ ⟨x, rfl⟩ i - exact ⟨x i, rfl⟩ · choose y hy using hx exact ⟨fun i => y i trivial, funext fun i => hy i trivial⟩ #align set.range_dcomp Set.range_dcomp @[simp] theorem insert_pi (i : ι) (s : Set ι) (t : ∀ i, Set (α i)) : pi (insert i s) t = eval i ⁻¹' t i ∩ pi s t := by ext simp [pi, or_imp, forall_and] #align set.insert_pi Set.insert_pi @[simp] theorem singleton_pi (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = eval i ⁻¹' t i := by ext simp [pi] #align set.singleton_pi Set.singleton_pi theorem singleton_pi' (i : ι) (t : ∀ i, Set (α i)) : pi {i} t = { x | x i ∈ t i } := singleton_pi i t #align set.singleton_pi' Set.singleton_pi' theorem univ_pi_singleton (f : ∀ i, α i) : (pi univ fun i => {f i}) = ({f} : Set (∀ i, α i)) := ext fun g => by simp [funext_iff] #align set.univ_pi_singleton Set.univ_pi_singleton theorem preimage_pi (s : Set ι) (t : ∀ i, Set (β i)) (f : ∀ i, α i → β i) : (fun (g : ∀ i, α i) i => f _ (g i)) ⁻¹' s.pi t = s.pi fun i => f i ⁻¹' t i := rfl #align set.preimage_pi Set.preimage_pi theorem pi_if {p : ι → Prop} [h : DecidablePred p] (s : Set ι) (t₁ t₂ : ∀ i, Set (α i)) : (pi s fun i => if p i then t₁ i else t₂ i) = pi ({ i ∈ s | p i }) t₁ ∩ pi ({ i ∈ s | ¬p i }) t₂ := by ext f refine ⟨fun h => ?_, ?_⟩ · constructor <;> · rintro i ⟨his, hpi⟩ simpa [*] using h i · rintro ⟨ht₁, ht₂⟩ i his by_cases p i <;> simp_all #align set.pi_if Set.pi_if theorem union_pi : (s₁ ∪ s₂).pi t = s₁.pi t ∩ s₂.pi t := by simp [pi, or_imp, forall_and, setOf_and] #align set.union_pi Set.union_pi theorem union_pi_inter (ht₁ : ∀ i ∉ s₁, t₁ i = univ) (ht₂ : ∀ i ∉ s₂, t₂ i = univ) : (s₁ ∪ s₂).pi (fun i ↦ t₁ i ∩ t₂ i) = s₁.pi t₁ ∩ s₂.pi t₂ := by ext x simp only [mem_pi, mem_union, mem_inter_iff] refine ⟨fun h ↦ ⟨fun i his₁ ↦ (h i (Or.inl his₁)).1, fun i his₂ ↦ (h i (Or.inr his₂)).2⟩, fun h i hi ↦ ?_⟩ cases' hi with hi hi · by_cases hi2 : i ∈ s₂ · exact ⟨h.1 i hi, h.2 i hi2⟩ · refine ⟨h.1 i hi, ?_⟩ rw [ht₂ i hi2] exact mem_univ _ · by_cases hi1 : i ∈ s₁ · exact ⟨h.1 i hi1, h.2 i hi⟩ · refine ⟨?_, h.2 i hi⟩ rw [ht₁ i hi1] exact mem_univ _ @[simp] theorem pi_inter_compl (s : Set ι) : pi s t ∩ pi sᶜ t = pi univ t := by rw [← union_pi, union_compl_self] #align set.pi_inter_compl Set.pi_inter_compl theorem pi_update_of_not_mem [DecidableEq ι] (hi : i ∉ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = s.pi fun j => t j (f j) := (pi_congr rfl) fun j hj => by rw [update_noteq] exact fun h => hi (h ▸ hj) #align set.pi_update_of_not_mem Set.pi_update_of_not_mem theorem pi_update_of_mem [DecidableEq ι] (hi : i ∈ s) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (s.pi fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := calc (s.pi fun j => t j (update f i a j)) = ({i} ∪ s \ {i}).pi fun j => t j (update f i a j) := by rw [union_diff_self, union_eq_self_of_subset_left (singleton_subset_iff.2 hi)] _ = { x | x i ∈ t i a } ∩ (s \ {i}).pi fun j => t j (f j) := by rw [union_pi, singleton_pi', update_same, pi_update_of_not_mem]; simp #align set.pi_update_of_mem Set.pi_update_of_mem theorem univ_pi_update [DecidableEq ι] {β : ι → Type*} (i : ι) (f : ∀ j, α j) (a : α i) (t : ∀ j, α j → Set (β j)) : (pi univ fun j => t j (update f i a j)) = { x | x i ∈ t i a } ∩ pi {i}ᶜ fun j => t j (f j) := by rw [compl_eq_univ_diff, ← pi_update_of_mem (mem_univ _)] #align set.univ_pi_update Set.univ_pi_update theorem univ_pi_update_univ [DecidableEq ι] (i : ι) (s : Set (α i)) : pi univ (update (fun j : ι => (univ : Set (α j))) i s) = eval i ⁻¹' s := by rw [univ_pi_update i (fun j => (univ : Set (α j))) s fun j t => t, pi_univ, inter_univ, preimage] #align set.univ_pi_update_univ Set.univ_pi_update_univ theorem eval_image_pi_subset (hs : i ∈ s) : eval i '' s.pi t ⊆ t i := image_subset_iff.2 fun _ hf => hf i hs #align set.eval_image_pi_subset Set.eval_image_pi_subset theorem eval_image_univ_pi_subset : eval i '' pi univ t ⊆ t i := eval_image_pi_subset (mem_univ i) #align set.eval_image_univ_pi_subset Set.eval_image_univ_pi_subset theorem subset_eval_image_pi (ht : (s.pi t).Nonempty) (i : ι) : t i ⊆ eval i '' s.pi t := by classical obtain ⟨f, hf⟩ := ht refine fun y hy => ⟨update f i y, fun j hj => ?_, update_same _ _ _⟩ obtain rfl | hji := eq_or_ne j i <;> simp [*, hf _ hj] #align set.subset_eval_image_pi Set.subset_eval_image_pi theorem eval_image_pi (hs : i ∈ s) (ht : (s.pi t).Nonempty) : eval i '' s.pi t = t i := (eval_image_pi_subset hs).antisymm (subset_eval_image_pi ht i) #align set.eval_image_pi Set.eval_image_pi @[simp] theorem eval_image_univ_pi (ht : (pi univ t).Nonempty) : (fun f : ∀ i, α i => f i) '' pi univ t = t i := eval_image_pi (mem_univ i) ht #align set.eval_image_univ_pi Set.eval_image_univ_pi theorem pi_subset_pi_iff : pi s t₁ ⊆ pi s t₂ ↔ (∀ i ∈ s, t₁ i ⊆ t₂ i) ∨ pi s t₁ = ∅ := by refine ⟨fun h => or_iff_not_imp_right.2 ?_, fun h => h.elim pi_mono fun h' => h'.symm ▸ empty_subset _⟩ rw [← Ne, ← nonempty_iff_ne_empty] intro hne i hi simpa only [eval_image_pi hi hne, eval_image_pi hi (hne.mono h)] using image_subset (fun f : ∀ i, α i => f i) h #align set.pi_subset_pi_iff Set.pi_subset_pi_iff theorem univ_pi_subset_univ_pi_iff : pi univ t₁ ⊆ pi univ t₂ ↔ (∀ i, t₁ i ⊆ t₂ i) ∨ ∃ i, t₁ i = ∅ := by simp [pi_subset_pi_iff] #align set.univ_pi_subset_univ_pi_iff Set.univ_pi_subset_univ_pi_iff
Mathlib/Data/Set/Prod.lean
938
941
theorem eval_preimage [DecidableEq ι] {s : Set (α i)} : eval i ⁻¹' s = pi univ (update (fun i => univ) i s) := by
ext x simp [@forall_update_iff _ (fun i => Set (α i)) _ _ _ _ fun i' y => x i' ∈ y]
/- Copyright (c) 2019 Minchao Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Minchao Wu, Chris Hughes, Mantas Bakšys -/ import Mathlib.Data.List.Basic import Mathlib.Order.MinMax import Mathlib.Order.WithBot #align_import data.list.min_max from "leanprover-community/mathlib"@"6d0adfa76594f304b4650d098273d4366edeb61b" /-! # Minimum and maximum of lists ## Main definitions The main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists. `argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmax f [] = none` `minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for `[]` -/ namespace List variable {α β : Type*} section ArgAux variable (r : α → α → Prop) [DecidableRel r] {l : List α} {o : Option α} {a m : α} /-- Auxiliary definition for `argmax` and `argmin`. -/ def argAux (a : Option α) (b : α) : Option α := Option.casesOn a (some b) fun c => if r b c then some b else some c #align list.arg_aux List.argAux @[simp] theorem foldl_argAux_eq_none : l.foldl (argAux r) o = none ↔ l = [] ∧ o = none := List.reverseRecOn l (by simp) fun tl hd => by simp only [foldl_append, foldl_cons, argAux, foldl_nil, append_eq_nil, and_false, false_and, iff_false]; cases foldl (argAux r) o tl <;> simp; try split_ifs <;> simp #align list.foldl_arg_aux_eq_none List.foldl_argAux_eq_none private theorem foldl_argAux_mem (l) : ∀ a m : α, m ∈ foldl (argAux r) (some a) l → m ∈ a :: l := List.reverseRecOn l (by simp [eq_comm]) (by intro tl hd ih a m simp only [foldl_append, foldl_cons, foldl_nil, argAux] cases hf : foldl (argAux r) (some a) tl · simp (config := { contextual := true }) · dsimp only split_ifs · simp (config := { contextual := true }) · -- `finish [ih _ _ hf]` closes this goal simp only [List.mem_cons] at ih rcases ih _ _ hf with rfl | H · simp (config := { contextual := true }) only [Option.mem_def, Option.some.injEq, find?, eq_comm, mem_cons, mem_append, mem_singleton, true_or, implies_true] · simp (config := { contextual := true }) [@eq_comm _ _ m, H]) @[simp] theorem argAux_self (hr₀ : Irreflexive r) (a : α) : argAux r (some a) a = a := if_neg <| hr₀ _ #align list.arg_aux_self List.argAux_self theorem not_of_mem_foldl_argAux (hr₀ : Irreflexive r) (hr₁ : Transitive r) : ∀ {a m : α} {o : Option α}, a ∈ l → m ∈ foldl (argAux r) o l → ¬r a m := by induction' l using List.reverseRecOn with tl a ih · simp intro b m o hb ho rw [foldl_append, foldl_cons, foldl_nil, argAux] at ho cases' hf : foldl (argAux r) o tl with c · rw [hf] at ho rw [foldl_argAux_eq_none] at hf simp_all [hf.1, hf.2, hr₀ _] rw [hf, Option.mem_def] at ho dsimp only at ho split_ifs at ho with hac <;> cases' mem_append.1 hb with h h <;> injection ho with ho <;> subst ho · exact fun hba => ih h hf (hr₁ hba hac) · simp_all [hr₀ _] · exact ih h hf · simp_all #align list.not_of_mem_foldl_arg_aux List.not_of_mem_foldl_argAux end ArgAux section Preorder variable [Preorder β] [@DecidableRel β (· < ·)] {f : α → β} {l : List α} {o : Option α} {a m : α} /-- `argmax f l` returns `some a`, where `f a` is maximal among the elements of `l`, in the sense that there is no `b ∈ l` with `f a < f b`. If `a`, `b` are such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmax f [] = none`. -/ def argmax (f : α → β) (l : List α) : Option α := l.foldl (argAux fun b c => f c < f b) none #align list.argmax List.argmax /-- `argmin f l` returns `some a`, where `f a` is minimal among the elements of `l`, in the sense that there is no `b ∈ l` with `f b < f a`. If `a`, `b` are such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmin f [] = none`. -/ def argmin (f : α → β) (l : List α) := l.foldl (argAux fun b c => f b < f c) none #align list.argmin List.argmin @[simp] theorem argmax_nil (f : α → β) : argmax f [] = none := rfl #align list.argmax_nil List.argmax_nil @[simp] theorem argmin_nil (f : α → β) : argmin f [] = none := rfl #align list.argmin_nil List.argmin_nil @[simp] theorem argmax_singleton {f : α → β} {a : α} : argmax f [a] = a := rfl #align list.argmax_singleton List.argmax_singleton @[simp] theorem argmin_singleton {f : α → β} {a : α} : argmin f [a] = a := rfl #align list.argmin_singleton List.argmin_singleton theorem not_lt_of_mem_argmax : a ∈ l → m ∈ argmax f l → ¬f m < f a := not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h) (fun _ _ z hxy hyz => lt_trans (a := f z) hyz hxy) #align list.not_lt_of_mem_argmax List.not_lt_of_mem_argmax theorem not_lt_of_mem_argmin : a ∈ l → m ∈ argmin f l → ¬f a < f m := not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h) (fun x _ _ hxy hyz => lt_trans (a := f x) hxy hyz) #align list.not_lt_of_mem_argmin List.not_lt_of_mem_argmin theorem argmax_concat (f : α → β) (a : α) (l : List α) : argmax f (l ++ [a]) = Option.casesOn (argmax f l) (some a) fun c => if f c < f a then some a else some c := by rw [argmax, argmax]; simp [argAux] #align list.argmax_concat List.argmax_concat theorem argmin_concat (f : α → β) (a : α) (l : List α) : argmin f (l ++ [a]) = Option.casesOn (argmin f l) (some a) fun c => if f a < f c then some a else some c := @argmax_concat _ βᵒᵈ _ _ _ _ _ #align list.argmin_concat List.argmin_concat theorem argmax_mem : ∀ {l : List α} {m : α}, m ∈ argmax f l → m ∈ l | [], m => by simp | hd :: tl, m => by simpa [argmax, argAux] using foldl_argAux_mem _ tl hd m #align list.argmax_mem List.argmax_mem theorem argmin_mem : ∀ {l : List α} {m : α}, m ∈ argmin f l → m ∈ l := @argmax_mem _ βᵒᵈ _ _ _ #align list.argmin_mem List.argmin_mem @[simp] theorem argmax_eq_none : l.argmax f = none ↔ l = [] := by simp [argmax] #align list.argmax_eq_none List.argmax_eq_none @[simp] theorem argmin_eq_none : l.argmin f = none ↔ l = [] := @argmax_eq_none _ βᵒᵈ _ _ _ _ #align list.argmin_eq_none List.argmin_eq_none end Preorder section LinearOrder variable [LinearOrder β] {f : α → β} {l : List α} {o : Option α} {a m : α} theorem le_of_mem_argmax : a ∈ l → m ∈ argmax f l → f a ≤ f m := fun ha hm => le_of_not_lt <| not_lt_of_mem_argmax ha hm #align list.le_of_mem_argmax List.le_of_mem_argmax theorem le_of_mem_argmin : a ∈ l → m ∈ argmin f l → f m ≤ f a := @le_of_mem_argmax _ βᵒᵈ _ _ _ _ _ #align list.le_of_mem_argmin List.le_of_mem_argmin theorem argmax_cons (f : α → β) (a : α) (l : List α) : argmax f (a :: l) = Option.casesOn (argmax f l) (some a) fun c => if f a < f c then some c else some a := List.reverseRecOn l rfl fun hd tl ih => by rw [← cons_append, argmax_concat, ih, argmax_concat] cases' h : argmax f hd with m · simp [h] dsimp rw [← apply_ite, ← apply_ite] dsimp split_ifs <;> try rfl · exact absurd (lt_trans ‹f a < f m› ‹_›) ‹_› · cases (‹f a < f tl›.lt_or_lt _).elim ‹_› ‹_› #align list.argmax_cons List.argmax_cons theorem argmin_cons (f : α → β) (a : α) (l : List α) : argmin f (a :: l) = Option.casesOn (argmin f l) (some a) fun c => if f c < f a then some c else some a := @argmax_cons α βᵒᵈ _ _ _ _ #align list.argmin_cons List.argmin_cons variable [DecidableEq α] theorem index_of_argmax : ∀ {l : List α} {m : α}, m ∈ argmax f l → ∀ {a}, a ∈ l → f m ≤ f a → l.indexOf m ≤ l.indexOf a | [], m, _, _, _, _ => by simp | hd :: tl, m, hm, a, ha, ham => by simp only [indexOf_cons, argmax_cons, Option.mem_def] at hm ⊢ cases h : argmax f tl · rw [h] at hm simp_all rw [h] at hm dsimp only at hm simp only [cond_eq_if, beq_iff_eq] obtain ha | ha := ha <;> split_ifs at hm <;> injection hm with hm <;> subst hm · cases not_le_of_lt ‹_› ‹_› · rw [if_pos rfl] · rw [if_neg, if_neg] · exact Nat.succ_le_succ (index_of_argmax h (by assumption) ham) · exact ne_of_apply_ne f (lt_of_lt_of_le ‹_› ‹_›).ne · exact ne_of_apply_ne _ ‹f hd < f _›.ne · rw [if_pos rfl] exact Nat.zero_le _ #align list.index_of_argmax List.index_of_argmax theorem index_of_argmin : ∀ {l : List α} {m : α}, m ∈ argmin f l → ∀ {a}, a ∈ l → f a ≤ f m → l.indexOf m ≤ l.indexOf a := @index_of_argmax _ βᵒᵈ _ _ _ #align list.index_of_argmin List.index_of_argmin theorem mem_argmax_iff : m ∈ argmax f l ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.indexOf m ≤ l.indexOf a := ⟨fun hm => ⟨argmax_mem hm, fun a ha => le_of_mem_argmax ha hm, fun _ => index_of_argmax hm⟩, by rintro ⟨hml, ham, hma⟩ cases' harg : argmax f l with n · simp_all · have := _root_.le_antisymm (hma n (argmax_mem harg) (le_of_mem_argmax hml harg)) (index_of_argmax harg hml (ham _ (argmax_mem harg))) rw [(indexOf_inj hml (argmax_mem harg)).1 this, Option.mem_def]⟩ #align list.mem_argmax_iff List.mem_argmax_iff theorem argmax_eq_some_iff : argmax f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.indexOf m ≤ l.indexOf a := mem_argmax_iff #align list.argmax_eq_some_iff List.argmax_eq_some_iff theorem mem_argmin_iff : m ∈ argmin f l ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.indexOf m ≤ l.indexOf a := @mem_argmax_iff _ βᵒᵈ _ _ _ _ _ #align list.mem_argmin_iff List.mem_argmin_iff theorem argmin_eq_some_iff : argmin f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.indexOf m ≤ l.indexOf a := mem_argmin_iff #align list.argmin_eq_some_iff List.argmin_eq_some_iff end LinearOrder section MaximumMinimum section Preorder variable [Preorder α] [@DecidableRel α (· < ·)] {l : List α} {a m : α} /-- `maximum l` returns a `WithBot α`, the largest element of `l` for nonempty lists, and `⊥` for `[]` -/ def maximum (l : List α) : WithBot α := argmax id l #align list.maximum List.maximum /-- `minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for `[]` -/ def minimum (l : List α) : WithTop α := argmin id l #align list.minimum List.minimum @[simp] theorem maximum_nil : maximum ([] : List α) = ⊥ := rfl #align list.maximum_nil List.maximum_nil @[simp] theorem minimum_nil : minimum ([] : List α) = ⊤ := rfl #align list.minimum_nil List.minimum_nil @[simp] theorem maximum_singleton (a : α) : maximum [a] = a := rfl #align list.maximum_singleton List.maximum_singleton @[simp] theorem minimum_singleton (a : α) : minimum [a] = a := rfl #align list.minimum_singleton List.minimum_singleton theorem maximum_mem {l : List α} {m : α} : (maximum l : WithTop α) = m → m ∈ l := argmax_mem #align list.maximum_mem List.maximum_mem theorem minimum_mem {l : List α} {m : α} : (minimum l : WithBot α) = m → m ∈ l := argmin_mem #align list.minimum_mem List.minimum_mem @[simp] theorem maximum_eq_bot {l : List α} : l.maximum = ⊥ ↔ l = [] := argmax_eq_none @[simp, deprecated maximum_eq_bot "Don't mix Option and WithBot" (since := "2024-05-27")] theorem maximum_eq_none {l : List α} : l.maximum = none ↔ l = [] := maximum_eq_bot #align list.maximum_eq_none List.maximum_eq_none @[simp] theorem minimum_eq_top {l : List α} : l.minimum = ⊤ ↔ l = [] := argmin_eq_none @[simp, deprecated minimum_eq_top "Don't mix Option and WithTop" (since := "2024-05-27")] theorem minimum_eq_none {l : List α} : l.minimum = none ↔ l = [] := minimum_eq_top #align list.minimum_eq_none List.minimum_eq_none theorem not_lt_maximum_of_mem : a ∈ l → (maximum l : WithBot α) = m → ¬m < a := not_lt_of_mem_argmax #align list.not_lt_maximum_of_mem List.not_lt_maximum_of_mem theorem minimum_not_lt_of_mem : a ∈ l → (minimum l : WithTop α) = m → ¬a < m := not_lt_of_mem_argmin #align list.minimum_not_lt_of_mem List.minimum_not_lt_of_mem theorem not_lt_maximum_of_mem' (ha : a ∈ l) : ¬maximum l < (a : WithBot α) := by cases h : l.maximum · simp_all · simp [not_lt_maximum_of_mem ha h, not_false_iff] #align list.not_lt_maximum_of_mem' List.not_lt_maximum_of_mem' theorem not_lt_minimum_of_mem' (ha : a ∈ l) : ¬(a : WithTop α) < minimum l := @not_lt_maximum_of_mem' αᵒᵈ _ _ _ _ ha #align list.not_lt_minimum_of_mem' List.not_lt_minimum_of_mem' end Preorder section LinearOrder variable [LinearOrder α] {l : List α} {a m : α} theorem maximum_concat (a : α) (l : List α) : maximum (l ++ [a]) = max (maximum l) a := by simp only [maximum, argmax_concat, id] cases argmax id l · exact (max_eq_right bot_le).symm · simp [WithBot.some_eq_coe, max_def_lt, WithBot.coe_lt_coe] #align list.maximum_concat List.maximum_concat theorem le_maximum_of_mem : a ∈ l → (maximum l : WithBot α) = m → a ≤ m := le_of_mem_argmax #align list.le_maximum_of_mem List.le_maximum_of_mem theorem minimum_le_of_mem : a ∈ l → (minimum l : WithTop α) = m → m ≤ a := le_of_mem_argmin #align list.minimum_le_of_mem List.minimum_le_of_mem theorem le_maximum_of_mem' (ha : a ∈ l) : (a : WithBot α) ≤ maximum l := le_of_not_lt <| not_lt_maximum_of_mem' ha #align list.le_maximum_of_mem' List.le_maximum_of_mem' theorem minimum_le_of_mem' (ha : a ∈ l) : minimum l ≤ (a : WithTop α) := @le_maximum_of_mem' αᵒᵈ _ _ _ ha #align list.le_minimum_of_mem' List.minimum_le_of_mem' theorem minimum_concat (a : α) (l : List α) : minimum (l ++ [a]) = min (minimum l) a := @maximum_concat αᵒᵈ _ _ _ #align list.minimum_concat List.minimum_concat theorem maximum_cons (a : α) (l : List α) : maximum (a :: l) = max ↑a (maximum l) := List.reverseRecOn l (by simp [@max_eq_left (WithBot α) _ _ _ bot_le]) fun tl hd ih => by rw [← cons_append, maximum_concat, ih, maximum_concat, max_assoc] #align list.maximum_cons List.maximum_cons theorem minimum_cons (a : α) (l : List α) : minimum (a :: l) = min ↑a (minimum l) := @maximum_cons αᵒᵈ _ _ _ #align list.minimum_cons List.minimum_cons
Mathlib/Data/List/MinMax.lean
389
394
theorem maximum_le_of_forall_le {b : WithBot α} (h : ∀ a ∈ l, a ≤ b) : l.maximum ≤ b := by
induction l with | nil => simp | cons a l ih => simp only [maximum_cons, ge_iff_le, max_le_iff, WithBot.coe_le_coe] exact ⟨h a (by simp), ih fun a w => h a (mem_cons.mpr (Or.inr w))⟩
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Finset.NoncommProd import Mathlib.Data.Fintype.Perm import Mathlib.Data.Int.ModEq import Mathlib.GroupTheory.Perm.List import Mathlib.GroupTheory.Perm.Sign import Mathlib.Logic.Equiv.Fintype import Mathlib.GroupTheory.Perm.Cycle.Basic #align_import group_theory.perm.cycle.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Cycle factors of a permutation Let `β` be a `Fintype` and `f : Equiv.Perm β`. * `Equiv.Perm.cycleOf`: `f.cycleOf x` is the cycle of `f` that `x` belongs to. * `Equiv.Perm.cycleFactors`: `f.cycleFactors` is a list of disjoint cyclic permutations that multiply to `f`. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `cycleOf` -/ section CycleOf variable [DecidableEq α] [Fintype α] {f g : Perm α} {x y : α} /-- `f.cycleOf x` is the cycle of the permutation `f` to which `x` belongs. -/ def cycleOf (f : Perm α) (x : α) : Perm α := ofSubtype (subtypePerm f fun _ => sameCycle_apply_right.symm : Perm { y // SameCycle f x y }) #align equiv.perm.cycle_of Equiv.Perm.cycleOf theorem cycleOf_apply (f : Perm α) (x y : α) : cycleOf f x y = if SameCycle f x y then f y else y := by dsimp only [cycleOf] split_ifs with h · apply ofSubtype_apply_of_mem exact h · apply ofSubtype_apply_of_not_mem exact h #align equiv.perm.cycle_of_apply Equiv.Perm.cycleOf_apply theorem cycleOf_inv (f : Perm α) (x : α) : (cycleOf f x)⁻¹ = cycleOf f⁻¹ x := Equiv.ext fun y => by rw [inv_eq_iff_eq, cycleOf_apply, cycleOf_apply] split_ifs <;> simp_all [sameCycle_inv, sameCycle_inv_apply_right] #align equiv.perm.cycle_of_inv Equiv.Perm.cycleOf_inv @[simp] theorem cycleOf_pow_apply_self (f : Perm α) (x : α) : ∀ n : ℕ, (cycleOf f x ^ n) x = (f ^ n) x := by intro n induction' n with n hn · rfl · rw [pow_succ', mul_apply, cycleOf_apply, hn, if_pos, pow_succ', mul_apply] exact ⟨n, rfl⟩ #align equiv.perm.cycle_of_pow_apply_self Equiv.Perm.cycleOf_pow_apply_self @[simp] theorem cycleOf_zpow_apply_self (f : Perm α) (x : α) : ∀ n : ℤ, (cycleOf f x ^ n) x = (f ^ n) x := by intro z induction' z with z hz · exact cycleOf_pow_apply_self f x z · rw [zpow_negSucc, ← inv_pow, cycleOf_inv, zpow_negSucc, ← inv_pow, cycleOf_pow_apply_self] #align equiv.perm.cycle_of_zpow_apply_self Equiv.Perm.cycleOf_zpow_apply_self theorem SameCycle.cycleOf_apply : SameCycle f x y → cycleOf f x y = f y := ofSubtype_apply_of_mem _ #align equiv.perm.same_cycle.cycle_of_apply Equiv.Perm.SameCycle.cycleOf_apply theorem cycleOf_apply_of_not_sameCycle : ¬SameCycle f x y → cycleOf f x y = y := ofSubtype_apply_of_not_mem _ #align equiv.perm.cycle_of_apply_of_not_same_cycle Equiv.Perm.cycleOf_apply_of_not_sameCycle theorem SameCycle.cycleOf_eq (h : SameCycle f x y) : cycleOf f x = cycleOf f y := by ext z rw [Equiv.Perm.cycleOf_apply] split_ifs with hz · exact (h.symm.trans hz).cycleOf_apply.symm · exact (cycleOf_apply_of_not_sameCycle (mt h.trans hz)).symm #align equiv.perm.same_cycle.cycle_of_eq Equiv.Perm.SameCycle.cycleOf_eq @[simp] theorem cycleOf_apply_apply_zpow_self (f : Perm α) (x : α) (k : ℤ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by rw [SameCycle.cycleOf_apply] · rw [add_comm, zpow_add, zpow_one, mul_apply] · exact ⟨k, rfl⟩ #align equiv.perm.cycle_of_apply_apply_zpow_self Equiv.Perm.cycleOf_apply_apply_zpow_self @[simp] theorem cycleOf_apply_apply_pow_self (f : Perm α) (x : α) (k : ℕ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by convert cycleOf_apply_apply_zpow_self f x k using 1 #align equiv.perm.cycle_of_apply_apply_pow_self Equiv.Perm.cycleOf_apply_apply_pow_self @[simp] theorem cycleOf_apply_apply_self (f : Perm α) (x : α) : cycleOf f x (f x) = f (f x) := by convert cycleOf_apply_apply_pow_self f x 1 using 1 #align equiv.perm.cycle_of_apply_apply_self Equiv.Perm.cycleOf_apply_apply_self @[simp] theorem cycleOf_apply_self (f : Perm α) (x : α) : cycleOf f x x = f x := SameCycle.rfl.cycleOf_apply #align equiv.perm.cycle_of_apply_self Equiv.Perm.cycleOf_apply_self theorem IsCycle.cycleOf_eq (hf : IsCycle f) (hx : f x ≠ x) : cycleOf f x = f := Equiv.ext fun y => if h : SameCycle f x y then by rw [h.cycleOf_apply] else by rw [cycleOf_apply_of_not_sameCycle h, Classical.not_not.1 (mt ((isCycle_iff_sameCycle hx).1 hf).2 h)] #align equiv.perm.is_cycle.cycle_of_eq Equiv.Perm.IsCycle.cycleOf_eq @[simp] theorem cycleOf_eq_one_iff (f : Perm α) : cycleOf f x = 1 ↔ f x = x := by simp_rw [ext_iff, cycleOf_apply, one_apply] refine ⟨fun h => (if_pos (SameCycle.refl f x)).symm.trans (h x), fun h y => ?_⟩ by_cases hy : f y = y · rw [hy, ite_self] · exact if_neg (mt SameCycle.apply_eq_self_iff (by tauto)) #align equiv.perm.cycle_of_eq_one_iff Equiv.Perm.cycleOf_eq_one_iff @[simp] theorem cycleOf_self_apply (f : Perm α) (x : α) : cycleOf f (f x) = cycleOf f x := (sameCycle_apply_right.2 SameCycle.rfl).symm.cycleOf_eq #align equiv.perm.cycle_of_self_apply Equiv.Perm.cycleOf_self_apply @[simp] theorem cycleOf_self_apply_pow (f : Perm α) (n : ℕ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.pow_left.cycleOf_eq #align equiv.perm.cycle_of_self_apply_pow Equiv.Perm.cycleOf_self_apply_pow @[simp] theorem cycleOf_self_apply_zpow (f : Perm α) (n : ℤ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.zpow_left.cycleOf_eq #align equiv.perm.cycle_of_self_apply_zpow Equiv.Perm.cycleOf_self_apply_zpow protected theorem IsCycle.cycleOf (hf : IsCycle f) : cycleOf f x = if f x = x then 1 else f := by by_cases hx : f x = x · rwa [if_pos hx, cycleOf_eq_one_iff] · rwa [if_neg hx, hf.cycleOf_eq] #align equiv.perm.is_cycle.cycle_of Equiv.Perm.IsCycle.cycleOf theorem cycleOf_one (x : α) : cycleOf 1 x = 1 := (cycleOf_eq_one_iff 1).mpr rfl #align equiv.perm.cycle_of_one Equiv.Perm.cycleOf_one theorem isCycle_cycleOf (f : Perm α) (hx : f x ≠ x) : IsCycle (cycleOf f x) := have : cycleOf f x x ≠ x := by rwa [SameCycle.rfl.cycleOf_apply] (isCycle_iff_sameCycle this).2 @fun y => ⟨fun h => mt h.apply_eq_self_iff.2 this, fun h => if hxy : SameCycle f x y then let ⟨i, hi⟩ := hxy ⟨i, by rw [cycleOf_zpow_apply_self, hi]⟩ else by rw [cycleOf_apply_of_not_sameCycle hxy] at h exact (h rfl).elim⟩ #align equiv.perm.is_cycle_cycle_of Equiv.Perm.isCycle_cycleOf @[simp] theorem two_le_card_support_cycleOf_iff : 2 ≤ card (cycleOf f x).support ↔ f x ≠ x := by refine ⟨fun h => ?_, fun h => by simpa using (isCycle_cycleOf _ h).two_le_card_support⟩ contrapose! h rw [← cycleOf_eq_one_iff] at h simp [h] #align equiv.perm.two_le_card_support_cycle_of_iff Equiv.Perm.two_le_card_support_cycleOf_iff @[simp] theorem card_support_cycleOf_pos_iff : 0 < card (cycleOf f x).support ↔ f x ≠ x := by rw [← two_le_card_support_cycleOf_iff, ← Nat.succ_le_iff] exact ⟨fun h => Or.resolve_left h.eq_or_lt (card_support_ne_one _).symm, zero_lt_two.trans_le⟩ #align equiv.perm.card_support_cycle_of_pos_iff Equiv.Perm.card_support_cycleOf_pos_iff theorem pow_mod_orderOf_cycleOf_apply (f : Perm α) (n : ℕ) (x : α) : (f ^ (n % orderOf (cycleOf f x))) x = (f ^ n) x := by rw [← cycleOf_pow_apply_self f, ← cycleOf_pow_apply_self f, pow_mod_orderOf] #align equiv.perm.pow_apply_eq_pow_mod_order_of_cycle_of_apply Equiv.Perm.pow_mod_orderOf_cycleOf_apply theorem cycleOf_mul_of_apply_right_eq_self (h : Commute f g) (x : α) (hx : g x = x) : (f * g).cycleOf x = f.cycleOf x := by ext y by_cases hxy : (f * g).SameCycle x y · obtain ⟨z, rfl⟩ := hxy rw [cycleOf_apply_apply_zpow_self] simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] · rw [cycleOf_apply_of_not_sameCycle hxy, cycleOf_apply_of_not_sameCycle] contrapose! hxy obtain ⟨z, rfl⟩ := hxy refine ⟨z, ?_⟩ simp [h.mul_zpow, zpow_apply_eq_self_of_apply_eq_self hx] #align equiv.perm.cycle_of_mul_of_apply_right_eq_self Equiv.Perm.cycleOf_mul_of_apply_right_eq_self theorem Disjoint.cycleOf_mul_distrib (h : f.Disjoint g) (x : α) : (f * g).cycleOf x = f.cycleOf x * g.cycleOf x := by cases' (disjoint_iff_eq_or_eq.mp h) x with hfx hgx · simp [h.commute.eq, cycleOf_mul_of_apply_right_eq_self h.symm.commute, hfx] · simp [cycleOf_mul_of_apply_right_eq_self h.commute, hgx] #align equiv.perm.disjoint.cycle_of_mul_distrib Equiv.Perm.Disjoint.cycleOf_mul_distrib theorem support_cycleOf_eq_nil_iff : (f.cycleOf x).support = ∅ ↔ x ∉ f.support := by simp #align equiv.perm.support_cycle_of_eq_nil_iff Equiv.Perm.support_cycleOf_eq_nil_iff theorem support_cycleOf_le (f : Perm α) (x : α) : support (f.cycleOf x) ≤ support f := by intro y hy rw [mem_support, cycleOf_apply] at hy split_ifs at hy · exact mem_support.mpr hy · exact absurd rfl hy #align equiv.perm.support_cycle_of_le Equiv.Perm.support_cycleOf_le theorem mem_support_cycleOf_iff : y ∈ support (f.cycleOf x) ↔ SameCycle f x y ∧ x ∈ support f := by by_cases hx : f x = x · rw [(cycleOf_eq_one_iff _).mpr hx] simp [hx] · rw [mem_support, cycleOf_apply] split_ifs with hy · simp only [hx, hy, iff_true_iff, Ne, not_false_iff, and_self_iff, mem_support] rcases hy with ⟨k, rfl⟩ rw [← not_mem_support] simpa using hx · simpa [hx] using hy #align equiv.perm.mem_support_cycle_of_iff Equiv.Perm.mem_support_cycleOf_iff theorem mem_support_cycleOf_iff' (hx : f x ≠ x) : y ∈ support (f.cycleOf x) ↔ SameCycle f x y := by rw [mem_support_cycleOf_iff, and_iff_left (mem_support.2 hx)] #align equiv.perm.mem_support_cycle_of_iff' Equiv.Perm.mem_support_cycleOf_iff' theorem SameCycle.mem_support_iff (h : SameCycle f x y) : x ∈ support f ↔ y ∈ support f := ⟨fun hx => support_cycleOf_le f x (mem_support_cycleOf_iff.mpr ⟨h, hx⟩), fun hy => support_cycleOf_le f y (mem_support_cycleOf_iff.mpr ⟨h.symm, hy⟩)⟩ #align equiv.perm.same_cycle.mem_support_iff Equiv.Perm.SameCycle.mem_support_iff theorem pow_mod_card_support_cycleOf_self_apply (f : Perm α) (n : ℕ) (x : α) : (f ^ (n % (f.cycleOf x).support.card)) x = (f ^ n) x := by by_cases hx : f x = x · rw [pow_apply_eq_self_of_apply_eq_self hx, pow_apply_eq_self_of_apply_eq_self hx] · rw [← cycleOf_pow_apply_self, ← cycleOf_pow_apply_self f, ← (isCycle_cycleOf f hx).orderOf, pow_mod_orderOf] #align equiv.perm.pow_mod_card_support_cycle_of_self_apply Equiv.Perm.pow_mod_card_support_cycleOf_self_apply /-- `x` is in the support of `f` iff `Equiv.Perm.cycle_of f x` is a cycle. -/ theorem isCycle_cycleOf_iff (f : Perm α) : IsCycle (cycleOf f x) ↔ f x ≠ x := by refine ⟨fun hx => ?_, f.isCycle_cycleOf⟩ rw [Ne, ← cycleOf_eq_one_iff f] exact hx.ne_one #align equiv.perm.is_cycle_cycle_of_iff Equiv.Perm.isCycle_cycleOf_iff theorem isCycleOn_support_cycleOf (f : Perm α) (x : α) : f.IsCycleOn (f.cycleOf x).support := ⟨f.bijOn <| by refine fun _ ↦ ⟨fun h ↦ mem_support_cycleOf_iff.2 ?_, fun h ↦ mem_support_cycleOf_iff.2 ?_⟩ · exact ⟨sameCycle_apply_right.1 (mem_support_cycleOf_iff.1 h).1, (mem_support_cycleOf_iff.1 h).2⟩ · exact ⟨sameCycle_apply_right.2 (mem_support_cycleOf_iff.1 h).1, (mem_support_cycleOf_iff.1 h).2⟩ , fun a ha b hb => by rw [mem_coe, mem_support_cycleOf_iff] at ha hb exact ha.1.symm.trans hb.1⟩ #align equiv.perm.is_cycle_on_support_cycle_of Equiv.Perm.isCycleOn_support_cycleOf theorem SameCycle.exists_pow_eq_of_mem_support (h : SameCycle f x y) (hx : x ∈ f.support) : ∃ i < (f.cycleOf x).support.card, (f ^ i) x = y := by rw [mem_support] at hx exact Equiv.Perm.IsCycleOn.exists_pow_eq (b := y) (f.isCycleOn_support_cycleOf x) (by rw [mem_support_cycleOf_iff' hx]) (by rwa [mem_support_cycleOf_iff' hx]) #align equiv.perm.same_cycle.exists_pow_eq_of_mem_support Equiv.Perm.SameCycle.exists_pow_eq_of_mem_support theorem SameCycle.exists_pow_eq (f : Perm α) (h : SameCycle f x y) : ∃ i : ℕ, 0 < i ∧ i ≤ (f.cycleOf x).support.card + 1 ∧ (f ^ i) x = y := by by_cases hx : x ∈ f.support · obtain ⟨k, hk, hk'⟩ := h.exists_pow_eq_of_mem_support hx cases' k with k · refine ⟨(f.cycleOf x).support.card, ?_, self_le_add_right _ _, ?_⟩ · refine zero_lt_one.trans (one_lt_card_support_of_ne_one ?_) simpa using hx · simp only [Nat.zero_eq, pow_zero, coe_one, id_eq] at hk' subst hk' rw [← (isCycle_cycleOf _ <| mem_support.1 hx).orderOf, ← cycleOf_pow_apply_self, pow_orderOf_eq_one, one_apply] · exact ⟨k + 1, by simp, Nat.le_succ_of_le hk.le, hk'⟩ · refine ⟨1, zero_lt_one, by simp, ?_⟩ obtain ⟨k, rfl⟩ := h rw [not_mem_support] at hx rw [pow_apply_eq_self_of_apply_eq_self hx, zpow_apply_eq_self_of_apply_eq_self hx] #align equiv.perm.same_cycle.exists_pow_eq Equiv.Perm.SameCycle.exists_pow_eq end CycleOf /-! ### `cycleFactors` -/ section cycleFactors open scoped List in /-- Given a list `l : List α` and a permutation `f : Perm α` whose nonfixed points are all in `l`, recursively factors `f` into cycles. -/ def cycleFactorsAux [DecidableEq α] [Fintype α] : ∀ (l : List α) (f : Perm α), (∀ {x}, f x ≠ x → x ∈ l) → { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := by intro l f h exact match l with | [] => ⟨[], by { simp only [imp_false, List.Pairwise.nil, List.not_mem_nil, forall_const, and_true_iff, forall_prop_of_false, Classical.not_not, not_false_iff, List.prod_nil] at * ext simp [*]}⟩ | x::l => if hx : f x = x then cycleFactorsAux l f (by intro y hy; exact List.mem_of_ne_of_mem (fun h => hy (by rwa [h])) (h hy)) else let ⟨m, hm₁, hm₂, hm₃⟩ := cycleFactorsAux l ((cycleOf f x)⁻¹ * f) (by intro y hy exact List.mem_of_ne_of_mem (fun h : y = x => by rw [h, mul_apply, Ne, inv_eq_iff_eq, cycleOf_apply_self] at hy exact hy rfl) (h fun h : f y = y => by rw [mul_apply, h, Ne, inv_eq_iff_eq, cycleOf_apply] at hy split_ifs at hy <;> tauto)) ⟨cycleOf f x::m, by rw [List.prod_cons, hm₁] simp, fun g hg ↦ ((List.mem_cons).1 hg).elim (fun hg => hg.symm ▸ isCycle_cycleOf _ hx) (hm₂ g), List.pairwise_cons.2 ⟨fun g hg y => or_iff_not_imp_left.2 fun hfy => have hxy : SameCycle f x y := Classical.not_not.1 (mt cycleOf_apply_of_not_sameCycle hfy) have hgm : (g::m.erase g) ~ m := List.cons_perm_iff_perm_erase.2 ⟨hg, List.Perm.refl _⟩ have : ∀ h ∈ m.erase g, Disjoint g h := (List.pairwise_cons.1 ((hgm.pairwise_iff Disjoint.symm).2 hm₃)).1 by_cases id fun hgy : g y ≠ y => (disjoint_prod_right _ this y).resolve_right <| by have hsc : SameCycle f⁻¹ x (f y) := by rwa [sameCycle_inv, sameCycle_apply_right] rw [disjoint_prod_perm hm₃ hgm.symm, List.prod_cons, ← eq_inv_mul_iff_mul_eq] at hm₁ rwa [hm₁, mul_apply, mul_apply, cycleOf_inv, hsc.cycleOf_apply, inv_apply_self, inv_eq_iff_eq, eq_comm], hm₃⟩⟩ #align equiv.perm.cycle_factors_aux Equiv.Perm.cycleFactorsAux theorem mem_list_cycles_iff {α : Type*} [Finite α] {l : List (Perm α)} (h1 : ∀ σ : Perm α, σ ∈ l → σ.IsCycle) (h2 : l.Pairwise Disjoint) {σ : Perm α} : σ ∈ l ↔ σ.IsCycle ∧ ∀ a, σ a ≠ a → σ a = l.prod a := by suffices σ.IsCycle → (σ ∈ l ↔ ∀ a, σ a ≠ a → σ a = l.prod a) by exact ⟨fun hσ => ⟨h1 σ hσ, (this (h1 σ hσ)).mp hσ⟩, fun hσ => (this hσ.1).mpr hσ.2⟩ intro h3 classical cases nonempty_fintype α constructor · intro h a ha exact eq_on_support_mem_disjoint h h2 _ (mem_support.mpr ha) · intro h have hσl : σ.support ⊆ l.prod.support := by intro x hx rw [mem_support] at hx rwa [mem_support, ← h _ hx] obtain ⟨a, ha, -⟩ := id h3 rw [← mem_support] at ha obtain ⟨τ, hτ, hτa⟩ := exists_mem_support_of_mem_support_prod (hσl ha) have hτl : ∀ x ∈ τ.support, τ x = l.prod x := eq_on_support_mem_disjoint hτ h2 have key : ∀ x ∈ σ.support ∩ τ.support, σ x = τ x := by intro x hx rw [h x (mem_support.mp (mem_of_mem_inter_left hx)), hτl x (mem_of_mem_inter_right hx)] convert hτ refine h3.eq_on_support_inter_nonempty_congr (h1 _ hτ) key ?_ ha exact key a (mem_inter_of_mem ha hτa) #align equiv.perm.mem_list_cycles_iff Equiv.Perm.mem_list_cycles_iff open scoped List in theorem list_cycles_perm_list_cycles {α : Type*} [Finite α] {l₁ l₂ : List (Perm α)} (h₀ : l₁.prod = l₂.prod) (h₁l₁ : ∀ σ : Perm α, σ ∈ l₁ → σ.IsCycle) (h₁l₂ : ∀ σ : Perm α, σ ∈ l₂ → σ.IsCycle) (h₂l₁ : l₁.Pairwise Disjoint) (h₂l₂ : l₂.Pairwise Disjoint) : l₁ ~ l₂ := by classical refine (List.perm_ext_iff_of_nodup (nodup_of_pairwise_disjoint_cycles h₁l₁ h₂l₁) (nodup_of_pairwise_disjoint_cycles h₁l₂ h₂l₂)).mpr fun σ => ?_ by_cases hσ : σ.IsCycle · obtain _ := not_forall.mp (mt ext hσ.ne_one) rw [mem_list_cycles_iff h₁l₁ h₂l₁, mem_list_cycles_iff h₁l₂ h₂l₂, h₀] · exact iff_of_false (mt (h₁l₁ σ) hσ) (mt (h₁l₂ σ) hσ) #align equiv.perm.list_cycles_perm_list_cycles Equiv.Perm.list_cycles_perm_list_cycles /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactors [Fintype α] [LinearOrder α] (f : Perm α) : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := cycleFactorsAux (sort (α := α) (· ≤ ·) univ) f (fun {_ _} ↦ (mem_sort _).2 (mem_univ _)) #align equiv.perm.cycle_factors Equiv.Perm.cycleFactors /-- Factors a permutation `f` into a list of disjoint cyclic permutations that multiply to `f`, without a linear order. -/ def truncCycleFactors [DecidableEq α] [Fintype α] (f : Perm α) : Trunc { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } := Quotient.recOnSubsingleton (@univ α _).1 (fun l h => Trunc.mk (cycleFactorsAux l f (h _))) (show ∀ x, f x ≠ x → x ∈ (@univ α _).1 from fun _ _ => mem_univ _) #align equiv.perm.trunc_cycle_factors Equiv.Perm.truncCycleFactors section CycleFactorsFinset variable [DecidableEq α] [Fintype α] (f : Perm α) /-- Factors a permutation `f` into a `Finset` of disjoint cyclic permutations that multiply to `f`. -/ def cycleFactorsFinset : Finset (Perm α) := (truncCycleFactors f).lift (fun l : { l : List (Perm α) // l.prod = f ∧ (∀ g ∈ l, IsCycle g) ∧ l.Pairwise Disjoint } => l.val.toFinset) fun ⟨_, hl⟩ ⟨_, hl'⟩ => List.toFinset_eq_of_perm _ _ (list_cycles_perm_list_cycles (hl'.left.symm ▸ hl.left) hl.right.left hl'.right.left hl.right.right hl'.right.right) #align equiv.perm.cycle_factors_finset Equiv.Perm.cycleFactorsFinset open scoped List in theorem cycleFactorsFinset_eq_list_toFinset {σ : Perm α} {l : List (Perm α)} (hn : l.Nodup) : σ.cycleFactorsFinset = l.toFinset ↔ (∀ f : Perm α, f ∈ l → f.IsCycle) ∧ l.Pairwise Disjoint ∧ l.prod = σ := by obtain ⟨⟨l', hp', hc', hd'⟩, hl⟩ := Trunc.exists_rep σ.truncCycleFactors have ht : cycleFactorsFinset σ = l'.toFinset := by rw [cycleFactorsFinset, ← hl, Trunc.lift_mk] rw [ht] constructor · intro h have hn' : l'.Nodup := nodup_of_pairwise_disjoint_cycles hc' hd' have hperm : l ~ l' := List.perm_of_nodup_nodup_toFinset_eq hn hn' h.symm refine ⟨?_, ?_, ?_⟩ · exact fun _ h => hc' _ (hperm.subset h) · have := List.Perm.pairwise_iff (@Disjoint.symmetric _) hperm rwa [this] · rw [← hp', hperm.symm.prod_eq'] refine hd'.imp ?_ exact Disjoint.commute · rintro ⟨hc, hd, hp⟩ refine List.toFinset_eq_of_perm _ _ ?_ refine list_cycles_perm_list_cycles ?_ hc' hc hd' hd rw [hp, hp'] #align equiv.perm.cycle_factors_finset_eq_list_to_finset Equiv.Perm.cycleFactorsFinset_eq_list_toFinset theorem cycleFactorsFinset_eq_finset {σ : Perm α} {s : Finset (Perm α)} : σ.cycleFactorsFinset = s ↔ (∀ f : Perm α, f ∈ s → f.IsCycle) ∧ ∃ h : (s : Set (Perm α)).Pairwise Disjoint, s.noncommProd id (h.mono' fun _ _ => Disjoint.commute) = σ := by obtain ⟨l, hl, rfl⟩ := s.exists_list_nodup_eq simp [cycleFactorsFinset_eq_list_toFinset, hl] #align equiv.perm.cycle_factors_finset_eq_finset Equiv.Perm.cycleFactorsFinset_eq_finset theorem cycleFactorsFinset_pairwise_disjoint : (cycleFactorsFinset f : Set (Perm α)).Pairwise Disjoint := (cycleFactorsFinset_eq_finset.mp rfl).2.choose #align equiv.perm.cycle_factors_finset_pairwise_disjoint Equiv.Perm.cycleFactorsFinset_pairwise_disjoint theorem cycleFactorsFinset_mem_commute : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := (cycleFactorsFinset_pairwise_disjoint _).mono' fun _ _ => Disjoint.commute #align equiv.perm.cycle_factors_finset_mem_commute Equiv.Perm.cycleFactorsFinset_mem_commute /-- The product of cycle factors is equal to the original `f : perm α`. -/ theorem cycleFactorsFinset_noncommProd (comm : (cycleFactorsFinset f : Set (Perm α)).Pairwise Commute := cycleFactorsFinset_mem_commute f) : f.cycleFactorsFinset.noncommProd id comm = f := (cycleFactorsFinset_eq_finset.mp rfl).2.choose_spec #align equiv.perm.cycle_factors_finset_noncomm_prod Equiv.Perm.cycleFactorsFinset_noncommProd theorem mem_cycleFactorsFinset_iff {f p : Perm α} : p ∈ cycleFactorsFinset f ↔ p.IsCycle ∧ ∀ a ∈ p.support, p a = f a := by obtain ⟨l, hl, hl'⟩ := f.cycleFactorsFinset.exists_list_nodup_eq rw [← hl'] rw [eq_comm, cycleFactorsFinset_eq_list_toFinset hl] at hl' simpa [List.mem_toFinset, Ne, ← hl'.right.right] using mem_list_cycles_iff hl'.left hl'.right.left #align equiv.perm.mem_cycle_factors_finset_iff Equiv.Perm.mem_cycleFactorsFinset_iff theorem cycleOf_mem_cycleFactorsFinset_iff {f : Perm α} {x : α} : cycleOf f x ∈ cycleFactorsFinset f ↔ x ∈ f.support := by rw [mem_cycleFactorsFinset_iff] constructor · rintro ⟨hc, _⟩ contrapose! hc rw [not_mem_support, ← cycleOf_eq_one_iff] at hc simp [hc] · intro hx refine ⟨isCycle_cycleOf _ (mem_support.mp hx), ?_⟩ intro y hy rw [mem_support] at hy rw [cycleOf_apply] split_ifs with H · rfl · rw [cycleOf_apply_of_not_sameCycle H] at hy contradiction #align equiv.perm.cycle_of_mem_cycle_factors_finset_iff Equiv.Perm.cycleOf_mem_cycleFactorsFinset_iff theorem mem_cycleFactorsFinset_support_le {p f : Perm α} (h : p ∈ cycleFactorsFinset f) : p.support ≤ f.support := by rw [mem_cycleFactorsFinset_iff] at h intro x hx rwa [mem_support, ← h.right x hx, ← mem_support] #align equiv.perm.mem_cycle_factors_finset_support_le Equiv.Perm.mem_cycleFactorsFinset_support_le theorem cycleFactorsFinset_eq_empty_iff {f : Perm α} : cycleFactorsFinset f = ∅ ↔ f = 1 := by simpa [cycleFactorsFinset_eq_finset] using eq_comm #align equiv.perm.cycle_factors_finset_eq_empty_iff Equiv.Perm.cycleFactorsFinset_eq_empty_iff @[simp] theorem cycleFactorsFinset_one : cycleFactorsFinset (1 : Perm α) = ∅ := by simp [cycleFactorsFinset_eq_empty_iff] #align equiv.perm.cycle_factors_finset_one Equiv.Perm.cycleFactorsFinset_one @[simp] theorem cycleFactorsFinset_eq_singleton_self_iff {f : Perm α} : f.cycleFactorsFinset = {f} ↔ f.IsCycle := by simp [cycleFactorsFinset_eq_finset] #align equiv.perm.cycle_factors_finset_eq_singleton_self_iff Equiv.Perm.cycleFactorsFinset_eq_singleton_self_iff theorem IsCycle.cycleFactorsFinset_eq_singleton {f : Perm α} (hf : IsCycle f) : f.cycleFactorsFinset = {f} := cycleFactorsFinset_eq_singleton_self_iff.mpr hf #align equiv.perm.is_cycle.cycle_factors_finset_eq_singleton Equiv.Perm.IsCycle.cycleFactorsFinset_eq_singleton theorem cycleFactorsFinset_eq_singleton_iff {f g : Perm α} : f.cycleFactorsFinset = {g} ↔ f.IsCycle ∧ f = g := by suffices f = g → (g.IsCycle ↔ f.IsCycle) by rw [cycleFactorsFinset_eq_finset] simpa [eq_comm] rintro rfl exact Iff.rfl #align equiv.perm.cycle_factors_finset_eq_singleton_iff Equiv.Perm.cycleFactorsFinset_eq_singleton_iff /-- Two permutations `f g : Perm α` have the same cycle factors iff they are the same. -/
Mathlib/GroupTheory/Perm/Cycle/Factors.lean
554
557
theorem cycleFactorsFinset_injective : Function.Injective (@cycleFactorsFinset α _ _) := by
intro f g h rw [← cycleFactorsFinset_noncommProd f] simpa [h] using cycleFactorsFinset_noncommProd g
/- 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 -/ import Mathlib.Init.Algebra.Classes import Mathlib.Logic.Nontrivial.Basic import Mathlib.Order.BoundedOrder import Mathlib.Data.Option.NAry import Mathlib.Tactic.Lift import Mathlib.Data.Option.Basic #align_import order.with_bot from "leanprover-community/mathlib"@"0111834459f5d7400215223ea95ae38a1265a907" /-! # `WithBot`, `WithTop` Adding a `bot` or a `top` to an order. ## Main declarations * `With<Top/Bot> α`: Equips `Option α` with the order on `α` plus `none` as the top/bottom element. -/ variable {α β γ δ : Type*} /-- Attach `⊥` to a type. -/ def WithBot (α : Type*) := Option α #align with_bot WithBot namespace WithBot variable {a b : α} instance [Repr α] : Repr (WithBot α) := ⟨fun o _ => match o with | none => "⊥" | some a => "↑" ++ repr a⟩ /-- The canonical map from `α` into `WithBot α` -/ @[coe, match_pattern] def some : α → WithBot α := Option.some -- Porting note: changed this from `CoeTC` to `Coe` but I am not 100% confident that's correct. instance coe : Coe α (WithBot α) := ⟨some⟩ instance bot : Bot (WithBot α) := ⟨none⟩ instance inhabited : Inhabited (WithBot α) := ⟨⊥⟩ instance nontrivial [Nonempty α] : Nontrivial (WithBot α) := Option.nontrivial open Function theorem coe_injective : Injective ((↑) : α → WithBot α) := Option.some_injective _ #align with_bot.coe_injective WithBot.coe_injective @[simp, norm_cast] theorem coe_inj : (a : WithBot α) = b ↔ a = b := Option.some_inj #align with_bot.coe_inj WithBot.coe_inj protected theorem «forall» {p : WithBot α → Prop} : (∀ x, p x) ↔ p ⊥ ∧ ∀ x : α, p x := Option.forall #align with_bot.forall WithBot.forall protected theorem «exists» {p : WithBot α → Prop} : (∃ x, p x) ↔ p ⊥ ∨ ∃ x : α, p x := Option.exists #align with_bot.exists WithBot.exists theorem none_eq_bot : (none : WithBot α) = (⊥ : WithBot α) := rfl #align with_bot.none_eq_bot WithBot.none_eq_bot theorem some_eq_coe (a : α) : (Option.some a : WithBot α) = (↑a : WithBot α) := rfl #align with_bot.some_eq_coe WithBot.some_eq_coe @[simp] theorem bot_ne_coe : ⊥ ≠ (a : WithBot α) := nofun #align with_bot.bot_ne_coe WithBot.bot_ne_coe @[simp] theorem coe_ne_bot : (a : WithBot α) ≠ ⊥ := nofun #align with_bot.coe_ne_bot WithBot.coe_ne_bot /-- Recursor for `WithBot` using the preferred forms `⊥` and `↑a`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recBotCoe {C : WithBot α → Sort*} (bot : C ⊥) (coe : ∀ a : α, C a) : ∀ n : WithBot α, C n | ⊥ => bot | (a : α) => coe a #align with_bot.rec_bot_coe WithBot.recBotCoe @[simp] theorem recBotCoe_bot {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) : @recBotCoe _ C d f ⊥ = d := rfl #align with_bot.rec_bot_coe_bot WithBot.recBotCoe_bot @[simp] theorem recBotCoe_coe {C : WithBot α → Sort*} (d : C ⊥) (f : ∀ a : α, C a) (x : α) : @recBotCoe _ C d f ↑x = f x := rfl #align with_bot.rec_bot_coe_coe WithBot.recBotCoe_coe /-- Specialization of `Option.getD` to values in `WithBot α` that respects API boundaries. -/ def unbot' (d : α) (x : WithBot α) : α := recBotCoe d id x #align with_bot.unbot' WithBot.unbot' @[simp] theorem unbot'_bot {α} (d : α) : unbot' d ⊥ = d := rfl #align with_bot.unbot'_bot WithBot.unbot'_bot @[simp] theorem unbot'_coe {α} (d x : α) : unbot' d x = x := rfl #align with_bot.unbot'_coe WithBot.unbot'_coe theorem coe_eq_coe : (a : WithBot α) = b ↔ a = b := coe_inj #align with_bot.coe_eq_coe WithBot.coe_eq_coe theorem unbot'_eq_iff {d y : α} {x : WithBot α} : unbot' d x = y ↔ x = y ∨ x = ⊥ ∧ y = d := by induction x <;> simp [@eq_comm _ d] #align with_bot.unbot'_eq_iff WithBot.unbot'_eq_iff @[simp] theorem unbot'_eq_self_iff {d : α} {x : WithBot α} : unbot' d x = d ↔ x = d ∨ x = ⊥ := by simp [unbot'_eq_iff] #align with_bot.unbot'_eq_self_iff WithBot.unbot'_eq_self_iff theorem unbot'_eq_unbot'_iff {d : α} {x y : WithBot α} : unbot' d x = unbot' d y ↔ x = y ∨ x = d ∧ y = ⊥ ∨ x = ⊥ ∧ y = d := by induction y <;> simp [unbot'_eq_iff, or_comm] #align with_bot.unbot'_eq_unbot'_iff WithBot.unbot'_eq_unbot'_iff /-- Lift a map `f : α → β` to `WithBot α → WithBot β`. Implemented using `Option.map`. -/ def map (f : α → β) : WithBot α → WithBot β := Option.map f #align with_bot.map WithBot.map @[simp] theorem map_bot (f : α → β) : map f ⊥ = ⊥ := rfl #align with_bot.map_bot WithBot.map_bot @[simp] theorem map_coe (f : α → β) (a : α) : map f a = f a := rfl #align with_bot.map_coe WithBot.map_coe theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ} (h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : map g₁ (map f₁ a) = map g₂ (map f₂ a) := Option.map_comm h _ #align with_bot.map_comm WithBot.map_comm /-- The image of a binary function `f : α → β → γ` as a function `WithBot α → WithBot β → WithBot γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def map₂ : (α → β → γ) → WithBot α → WithBot β → WithBot γ := Option.map₂ lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl @[simp] lemma map₂_bot_left (f : α → β → γ) (b) : map₂ f ⊥ b = ⊥ := rfl @[simp] lemma map₂_bot_right (f : α → β → γ) (a) : map₂ f a ⊥ = ⊥ := by cases a <;> rfl @[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl @[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by cases a <;> rfl @[simp] lemma map₂_eq_bot_iff {f : α → β → γ} {a : WithBot α} {b : WithBot β} : map₂ f a b = ⊥ ↔ a = ⊥ ∨ b = ⊥ := Option.map₂_eq_none_iff theorem ne_bot_iff_exists {x : WithBot α} : x ≠ ⊥ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists #align with_bot.ne_bot_iff_exists WithBot.ne_bot_iff_exists /-- Deconstruct a `x : WithBot α` to the underlying value in `α`, given a proof that `x ≠ ⊥`. -/ def unbot : ∀ x : WithBot α, x ≠ ⊥ → α | (x : α), _ => x #align with_bot.unbot WithBot.unbot @[simp] lemma coe_unbot : ∀ (x : WithBot α) hx, x.unbot hx = x | (x : α), _ => rfl #align with_bot.coe_unbot WithBot.coe_unbot @[simp] theorem unbot_coe (x : α) (h : (x : WithBot α) ≠ ⊥ := coe_ne_bot) : (x : WithBot α).unbot h = x := rfl #align with_bot.unbot_coe WithBot.unbot_coe instance canLift : CanLift (WithBot α) α (↑) fun r => r ≠ ⊥ where prf x h := ⟨x.unbot h, coe_unbot _ _⟩ #align with_bot.can_lift WithBot.canLift section LE variable [LE α] instance (priority := 10) le : LE (WithBot α) := ⟨fun o₁ o₂ => ∀ a : α, o₁ = ↑a → ∃ b : α, o₂ = ↑b ∧ a ≤ b⟩ @[simp, norm_cast] theorem coe_le_coe : (a : WithBot α) ≤ b ↔ a ≤ b := by simp [LE.le] #align with_bot.coe_le_coe WithBot.coe_le_coe instance orderBot : OrderBot (WithBot α) where bot_le _ := fun _ h => Option.noConfusion h @[simp, deprecated coe_le_coe "Don't mix Option and WithBot" (since := "2024-05-27")] theorem some_le_some : @LE.le (WithBot α) _ (Option.some a) (Option.some b) ↔ a ≤ b := coe_le_coe #align with_bot.some_le_some WithBot.some_le_some @[simp, deprecated bot_le "Don't mix Option and WithBot" (since := "2024-05-27")] theorem none_le {a : WithBot α} : @LE.le (WithBot α) _ none a := bot_le #align with_bot.none_le WithBot.none_le instance orderTop [OrderTop α] : OrderTop (WithBot α) where top := (⊤ : α) le_top o a ha := by cases ha; exact ⟨_, rfl, le_top⟩ instance instBoundedOrder [OrderTop α] : BoundedOrder (WithBot α) := { WithBot.orderBot, WithBot.orderTop with } theorem not_coe_le_bot (a : α) : ¬(a : WithBot α) ≤ ⊥ := fun h => let ⟨_, hb, _⟩ := h _ rfl Option.not_mem_none _ hb #align with_bot.not_coe_le_bot WithBot.not_coe_le_bot /-- There is a general version `le_bot_iff`, but this lemma does not require a `PartialOrder`. -/ @[simp] protected theorem le_bot_iff : ∀ {a : WithBot α}, a ≤ ⊥ ↔ a = ⊥ | (a : α) => by simp [not_coe_le_bot _] | ⊥ => by simp theorem coe_le : ∀ {o : Option α}, b ∈ o → ((a : WithBot α) ≤ o ↔ a ≤ b) | _, rfl => coe_le_coe #align with_bot.coe_le WithBot.coe_le theorem coe_le_iff : ∀ {x : WithBot α}, (a : WithBot α) ≤ x ↔ ∃ b : α, x = b ∧ a ≤ b | (x : α) => by simp | ⊥ => iff_of_false (not_coe_le_bot _) <| by simp #align with_bot.coe_le_iff WithBot.coe_le_iff theorem le_coe_iff : ∀ {x : WithBot α}, x ≤ b ↔ ∀ a : α, x = ↑a → a ≤ b | (b : α) => by simp | ⊥ => by simp #align with_bot.le_coe_iff WithBot.le_coe_iff protected theorem _root_.IsMax.withBot (h : IsMax a) : IsMax (a : WithBot α) | ⊥, _ => bot_le | (_ : α), hb => coe_le_coe.2 <| h <| coe_le_coe.1 hb #align is_max.with_bot IsMax.withBot theorem le_unbot_iff {a : α} {b : WithBot α} (h : b ≠ ⊥) : a ≤ unbot b h ↔ (a : WithBot α) ≤ b := by match b, h with | some _, _ => simp only [unbot_coe, coe_le_coe] theorem unbot_le_iff {a : WithBot α} (h : a ≠ ⊥) {b : α} : unbot a h ≤ b ↔ a ≤ (b : WithBot α) := by match a, h with | some _, _ => simp only [unbot_coe, coe_le_coe] theorem unbot'_le_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b ≤ c) : a.unbot' b ≤ c ↔ a ≤ c := by induction a · simpa using h rfl · simp #align with_bot.unbot'_bot_le_iff WithBot.unbot'_le_iff end LE section LT variable [LT α] instance (priority := 10) lt : LT (WithBot α) := ⟨fun o₁ o₂ : WithBot α => ∃ b : α, o₂ = ↑b ∧ ∀ a : α, o₁ = ↑a → a < b⟩ @[simp, norm_cast] theorem coe_lt_coe : (a : WithBot α) < b ↔ a < b := by simp [LT.lt] #align with_bot.coe_lt_coe WithBot.coe_lt_coe @[simp] theorem bot_lt_coe (a : α) : ⊥ < (a : WithBot α) := ⟨a, rfl, fun _ hb => (Option.not_mem_none _ hb).elim⟩ #align with_bot.bot_lt_coe WithBot.bot_lt_coe @[simp] protected theorem not_lt_bot (a : WithBot α) : ¬a < ⊥ := fun ⟨_, h, _⟩ => Option.not_mem_none _ h @[simp, deprecated coe_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")] theorem some_lt_some : @LT.lt (WithBot α) _ (Option.some a) (Option.some b) ↔ a < b := coe_lt_coe #align with_bot.some_lt_some WithBot.some_lt_some @[simp, deprecated bot_lt_coe "Don't mix Option and WithBot" (since := "2024-05-27")] theorem none_lt_some (a : α) : @LT.lt (WithBot α) _ none (some a) := bot_lt_coe _ #align with_bot.none_lt_some WithBot.none_lt_some @[simp, deprecated not_lt_none "Don't mix Option and WithBot" (since := "2024-05-27")] theorem not_lt_none (a : WithBot α) : ¬@LT.lt (WithBot α) _ a none := WithBot.not_lt_bot _ #align with_bot.not_lt_none WithBot.not_lt_none theorem lt_iff_exists_coe : ∀ {a b : WithBot α}, a < b ↔ ∃ p : α, b = p ∧ a < p | a, some b => by simp [coe_eq_coe] | a, ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp #align with_bot.lt_iff_exists_coe WithBot.lt_iff_exists_coe theorem lt_coe_iff : ∀ {x : WithBot α}, x < b ↔ ∀ a : α, x = a → a < b | (_ : α) => by simp | ⊥ => by simp [bot_lt_coe] #align with_bot.lt_coe_iff WithBot.lt_coe_iff /-- A version of `bot_lt_iff_ne_bot` for `WithBot` that only requires `LT α`, not `PartialOrder α`. -/ protected theorem bot_lt_iff_ne_bot : ∀ {x : WithBot α}, ⊥ < x ↔ x ≠ ⊥ | ⊥ => iff_of_false (WithBot.not_lt_bot _) <| by simp | (x : α) => by simp [bot_lt_coe] #align with_bot.bot_lt_iff_ne_bot WithBot.bot_lt_iff_ne_bot theorem unbot'_lt_iff {a : WithBot α} {b c : α} (h : a = ⊥ → b < c) : a.unbot' b < c ↔ a < c := by induction a · simpa [bot_lt_coe] using h rfl · simp end LT instance preorder [Preorder α] : Preorder (WithBot α) where le := (· ≤ ·) lt := (· < ·) lt_iff_le_not_le := by intros a b cases a <;> cases b <;> simp [lt_iff_le_not_le] le_refl o a ha := ⟨a, ha, le_rfl⟩ le_trans o₁ o₂ o₃ h₁ h₂ a ha := let ⟨b, hb, ab⟩ := h₁ a ha let ⟨c, hc, bc⟩ := h₂ b hb ⟨c, hc, le_trans ab bc⟩ instance partialOrder [PartialOrder α] : PartialOrder (WithBot α) := { WithBot.preorder with le_antisymm := fun o₁ o₂ h₁ h₂ => by cases' o₁ with a · cases' o₂ with b · rfl have := h₂ b rcases h₂ b rfl with ⟨_, ⟨⟩, _⟩ · rcases h₁ a rfl with ⟨b, ⟨⟩, h₁'⟩ rcases h₂ b rfl with ⟨_, ⟨⟩, h₂'⟩ rw [le_antisymm h₁' h₂'] } #align with_bot.partial_order WithBot.partialOrder section Preorder variable [Preorder α] [Preorder β] theorem coe_strictMono : StrictMono (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_lt_coe.2 #align with_bot.coe_strict_mono WithBot.coe_strictMono theorem coe_mono : Monotone (fun (a : α) => (a : WithBot α)) := fun _ _ => coe_le_coe.2 #align with_bot.coe_mono WithBot.coe_mono theorem monotone_iff {f : WithBot α → β} : Monotone f ↔ Monotone (fun a ↦ f a : α → β) ∧ ∀ x : α, f ⊥ ≤ f x := ⟨fun h ↦ ⟨h.comp WithBot.coe_mono, fun _ ↦ h bot_le⟩, fun h ↦ WithBot.forall.2 ⟨WithBot.forall.2 ⟨fun _ => le_rfl, fun x _ => h.2 x⟩, fun _ => WithBot.forall.2 ⟨fun h => (not_coe_le_bot _ h).elim, fun _ hle => h.1 (coe_le_coe.1 hle)⟩⟩⟩ #align with_bot.monotone_iff WithBot.monotone_iff @[simp] theorem monotone_map_iff {f : α → β} : Monotone (WithBot.map f) ↔ Monotone f := monotone_iff.trans <| by simp [Monotone] #align with_bot.monotone_map_iff WithBot.monotone_map_iff alias ⟨_, _root_.Monotone.withBot_map⟩ := monotone_map_iff #align monotone.with_bot_map Monotone.withBot_map theorem strictMono_iff {f : WithBot α → β} : StrictMono f ↔ StrictMono (fun a => f a : α → β) ∧ ∀ x : α, f ⊥ < f x := ⟨fun h => ⟨h.comp WithBot.coe_strictMono, fun _ => h (bot_lt_coe _)⟩, fun h => WithBot.forall.2 ⟨WithBot.forall.2 ⟨flip absurd (lt_irrefl _), fun x _ => h.2 x⟩, fun _ => WithBot.forall.2 ⟨fun h => (not_lt_bot h).elim, fun _ hle => h.1 (coe_lt_coe.1 hle)⟩⟩⟩ #align with_bot.strict_mono_iff WithBot.strictMono_iff theorem strictAnti_iff {f : WithBot α → β} : StrictAnti f ↔ StrictAnti (fun a ↦ f a : α → β) ∧ ∀ x : α, f x < f ⊥ := strictMono_iff (β := βᵒᵈ) @[simp] theorem strictMono_map_iff {f : α → β} : StrictMono (WithBot.map f) ↔ StrictMono f := strictMono_iff.trans <| by simp [StrictMono, bot_lt_coe] #align with_bot.strict_mono_map_iff WithBot.strictMono_map_iff alias ⟨_, _root_.StrictMono.withBot_map⟩ := strictMono_map_iff #align strict_mono.with_bot_map StrictMono.withBot_map theorem map_le_iff (f : α → β) (mono_iff : ∀ {a b}, f a ≤ f b ↔ a ≤ b) : ∀ a b : WithBot α, a.map f ≤ b.map f ↔ a ≤ b | ⊥, _ => by simp only [map_bot, bot_le] | (a : α), ⊥ => by simp only [map_coe, map_bot, coe_ne_bot, not_coe_le_bot _] | (a : α), (b : α) => by simpa only [map_coe, coe_le_coe] using mono_iff #align with_bot.map_le_iff WithBot.map_le_iff theorem le_coe_unbot' : ∀ (a : WithBot α) (b : α), a ≤ a.unbot' b | (a : α), _ => le_rfl | ⊥, _ => bot_le #align with_bot.le_coe_unbot' WithBot.le_coe_unbot' @[simp] theorem lt_coe_bot [OrderBot α] : ∀ {x : WithBot α}, x < (⊥ : α) ↔ x = ⊥ | (x : α) => by simp | ⊥ => by simp end Preorder instance semilatticeSup [SemilatticeSup α] : SemilatticeSup (WithBot α) where sup -- note this is `Option.liftOrGet`, but with the right defeq when unfolding | ⊥, ⊥ => ⊥ | (a : α), ⊥ => a | ⊥, (b : α) => b | (a : α), (b : α) => ↑(a ⊔ b) le_sup_left := fun o₁ o₂ a ha => by cases ha; cases o₂ <;> simp le_sup_right := fun o₁ o₂ a ha => by cases ha; cases o₁ <;> simp sup_le := fun o₁ o₂ o₃ h₁ h₂ a ha => by cases' o₁ with b <;> cases' o₂ with c <;> cases ha · exact h₂ a rfl · exact h₁ a rfl · rcases h₁ b rfl with ⟨d, ⟨⟩, h₁'⟩ simp only [coe_le_coe] at h₂ exact ⟨d, rfl, sup_le h₁' h₂⟩ theorem coe_sup [SemilatticeSup α] (a b : α) : ((a ⊔ b : α) : WithBot α) = (a : WithBot α) ⊔ b := rfl #align with_bot.coe_sup WithBot.coe_sup instance semilatticeInf [SemilatticeInf α] : SemilatticeInf (WithBot α) := { WithBot.partialOrder, @WithBot.orderBot α _ with inf := WithBot.map₂ (· ⊓ ·), inf_le_left := fun o₁ o₂ a ha => by rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩ exact ⟨_, rfl, inf_le_left⟩, inf_le_right := fun o₁ o₂ a ha => by rcases Option.mem_map₂_iff.1 ha with ⟨a, b, (rfl : _ = _), (rfl : _ = _), rfl⟩ exact ⟨_, rfl, inf_le_right⟩, le_inf := fun o₁ o₂ o₃ h₁ h₂ a ha => by cases ha rcases h₁ a rfl with ⟨b, ⟨⟩, ab⟩ rcases h₂ a rfl with ⟨c, ⟨⟩, ac⟩ exact ⟨_, rfl, le_inf ab ac⟩ } theorem coe_inf [SemilatticeInf α] (a b : α) : ((a ⊓ b : α) : WithBot α) = (a : WithBot α) ⊓ b := rfl #align with_bot.coe_inf WithBot.coe_inf instance lattice [Lattice α] : Lattice (WithBot α) := { WithBot.semilatticeSup, WithBot.semilatticeInf with } instance distribLattice [DistribLattice α] : DistribLattice (WithBot α) := { WithBot.lattice with le_sup_inf := fun o₁ o₂ o₃ => match o₁, o₂, o₃ with | ⊥, ⊥, ⊥ => le_rfl | ⊥, ⊥, (a₁ : α) => le_rfl | ⊥, (a₁ : α), ⊥ => le_rfl | ⊥, (a₁ : α), (a₃ : α) => le_rfl | (a₁ : α), ⊥, ⊥ => inf_le_left | (a₁ : α), ⊥, (a₃ : α) => inf_le_left | (a₁ : α), (a₂ : α), ⊥ => inf_le_right | (a₁ : α), (a₂ : α), (a₃ : α) => coe_le_coe.mpr le_sup_inf } instance decidableEq [DecidableEq α] : DecidableEq (WithBot α) := inferInstanceAs <| DecidableEq (Option α) instance decidableLE [LE α] [@DecidableRel α (· ≤ ·)] : @DecidableRel (WithBot α) (· ≤ ·) | none, x => isTrue fun a h => Option.noConfusion h | Option.some x, Option.some y => if h : x ≤ y then isTrue (coe_le_coe.2 h) else isFalse <| by simp [*] | Option.some x, none => isFalse fun h => by rcases h x rfl with ⟨y, ⟨_⟩, _⟩ #align with_bot.decidable_le WithBot.decidableLE instance decidableLT [LT α] [@DecidableRel α (· < ·)] : @DecidableRel (WithBot α) (· < ·) | none, Option.some x => isTrue <| by exists x, rfl; rintro _ ⟨⟩ | Option.some x, Option.some y => if h : x < y then isTrue <| by simp [*] else isFalse <| by simp [*] | x, none => isFalse <| by rintro ⟨a, ⟨⟨⟩⟩⟩ #align with_bot.decidable_lt WithBot.decidableLT instance isTotal_le [LE α] [IsTotal α (· ≤ ·)] : IsTotal (WithBot α) (· ≤ ·) := ⟨fun a b => match a, b with | none, _ => Or.inl bot_le | _, none => Or.inr bot_le | Option.some x, Option.some y => (total_of (· ≤ ·) x y).imp coe_le_coe.2 coe_le_coe.2⟩ #align with_bot.is_total_le WithBot.isTotal_le instance linearOrder [LinearOrder α] : LinearOrder (WithBot α) := Lattice.toLinearOrder _ #align with_bot.linear_order WithBot.linearOrder @[simp, norm_cast] theorem coe_min [LinearOrder α] (x y : α) : ((min x y : α) : WithBot α) = min (x : WithBot α) y := rfl #align with_bot.coe_min WithBot.coe_min @[simp, norm_cast] theorem coe_max [LinearOrder α] (x y : α) : ((max x y : α) : WithBot α) = max (x : WithBot α) y := rfl #align with_bot.coe_max WithBot.coe_max instance instWellFoundedLT [LT α] [WellFoundedLT α] : WellFoundedLT (WithBot α) where wf := have not_lt_bot : ∀ a : WithBot α, ¬ a < ⊥ := nofun have acc_bot := ⟨_, by simp [not_lt_bot]⟩ .intro fun | ⊥ => acc_bot | (a : α) => (wellFounded_lt.1 a).rec fun a _ ih => .intro _ fun | ⊥, _ => acc_bot | (b : α), hlt => ih _ (coe_lt_coe.1 hlt) #align with_bot.well_founded_lt WithBot.instWellFoundedLT instance _root_.WithBot.instWellFoundedGT [LT α] [WellFoundedGT α] : WellFoundedGT (WithBot α) where wf := have acc_some (a : α) : Acc ((· > ·) : WithBot α → WithBot α → Prop) a := (wellFounded_gt.1 a).rec fun _ _ ih => .intro _ fun | (b : α), hlt => ih _ (coe_lt_coe.1 hlt) | ⊥, hlt => absurd hlt (WithBot.not_lt_bot _) .intro fun | (a : α) => acc_some a | ⊥ => .intro _ fun | (b : α), _ => acc_some b | ⊥, hlt => absurd hlt (WithBot.not_lt_bot _) #align with_bot.well_founded_gt WithBot.instWellFoundedGT instance denselyOrdered [LT α] [DenselyOrdered α] [NoMinOrder α] : DenselyOrdered (WithBot α) := ⟨fun a b => match a, b with | a, none => fun h : a < ⊥ => (WithBot.not_lt_bot _ h).elim | none, Option.some b => fun _ => let ⟨a, ha⟩ := exists_lt b ⟨a, bot_lt_coe a, coe_lt_coe.2 ha⟩ | Option.some _, Option.some _ => fun h => let ⟨a, ha₁, ha₂⟩ := exists_between (coe_lt_coe.1 h) ⟨a, coe_lt_coe.2 ha₁, coe_lt_coe.2 ha₂⟩⟩ theorem lt_iff_exists_coe_btwn [Preorder α] [DenselyOrdered α] [NoMinOrder α] {a b : WithBot α} : a < b ↔ ∃ x : α, a < ↑x ∧ ↑x < b := ⟨fun h => let ⟨_, hy⟩ := exists_between h let ⟨x, hx⟩ := lt_iff_exists_coe.1 hy.1 ⟨x, hx.1 ▸ hy⟩, fun ⟨_, hx⟩ => lt_trans hx.1 hx.2⟩ #align with_bot.lt_iff_exists_coe_btwn WithBot.lt_iff_exists_coe_btwn instance noTopOrder [LE α] [NoTopOrder α] [Nonempty α] : NoTopOrder (WithBot α) := ⟨by apply recBotCoe · exact ‹Nonempty α›.elim fun a => ⟨a, not_coe_le_bot a⟩ · intro a obtain ⟨b, h⟩ := exists_not_le a exact ⟨b, by rwa [coe_le_coe]⟩ ⟩ instance noMaxOrder [LT α] [NoMaxOrder α] [Nonempty α] : NoMaxOrder (WithBot α) := ⟨by apply WithBot.recBotCoe · apply ‹Nonempty α›.elim exact fun a => ⟨a, WithBot.bot_lt_coe a⟩ · intro a obtain ⟨b, ha⟩ := exists_gt a exact ⟨b, coe_lt_coe.mpr ha⟩ ⟩ end WithBot --TODO(Mario): Construct using order dual on `WithBot` /-- Attach `⊤` to a type. -/ def WithTop (α : Type*) := Option α #align with_top WithTop namespace WithTop variable {a b : α} instance [Repr α] : Repr (WithTop α) := ⟨fun o _ => match o with | none => "⊤" | some a => "↑" ++ repr a⟩ /-- The canonical map from `α` into `WithTop α` -/ @[coe, match_pattern] def some : α → WithTop α := Option.some instance coeTC : CoeTC α (WithTop α) := ⟨some⟩ instance top : Top (WithTop α) := ⟨none⟩ instance inhabited : Inhabited (WithTop α) := ⟨⊤⟩ instance nontrivial [Nonempty α] : Nontrivial (WithTop α) := Option.nontrivial open Function theorem coe_injective : Injective ((↑) : α → WithTop α) := Option.some_injective _ @[norm_cast] theorem coe_inj : (a : WithTop α) = b ↔ a = b := Option.some_inj protected theorem «forall» {p : WithTop α → Prop} : (∀ x, p x) ↔ p ⊤ ∧ ∀ x : α, p x := Option.forall #align with_top.forall WithTop.forall protected theorem «exists» {p : WithTop α → Prop} : (∃ x, p x) ↔ p ⊤ ∨ ∃ x : α, p x := Option.exists #align with_top.exists WithTop.exists theorem none_eq_top : (none : WithTop α) = (⊤ : WithTop α) := rfl #align with_top.none_eq_top WithTop.none_eq_top theorem some_eq_coe (a : α) : (Option.some a : WithTop α) = (↑a : WithTop α) := rfl #align with_top.some_eq_coe WithTop.some_eq_coe @[simp] theorem top_ne_coe : ⊤ ≠ (a : WithTop α) := nofun #align with_top.top_ne_coe WithTop.top_ne_coe @[simp] theorem coe_ne_top : (a : WithTop α) ≠ ⊤ := nofun #align with_top.coe_ne_top WithTop.coe_ne_top /-- Recursor for `WithTop` using the preferred forms `⊤` and `↑a`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : WithTop α → Sort*} (top : C ⊤) (coe : ∀ a : α, C a) : ∀ n : WithTop α, C n | none => top | Option.some a => coe a #align with_top.rec_top_coe WithTop.recTopCoe @[simp] theorem recTopCoe_top {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) : @recTopCoe _ C d f ⊤ = d := rfl #align with_top.rec_top_coe_top WithTop.recTopCoe_top @[simp] theorem recTopCoe_coe {C : WithTop α → Sort*} (d : C ⊤) (f : ∀ a : α, C a) (x : α) : @recTopCoe _ C d f ↑x = f x := rfl #align with_top.rec_top_coe_coe WithTop.recTopCoe_coe /-- `WithTop.toDual` is the equivalence sending `⊤` to `⊥` and any `a : α` to `toDual a : αᵒᵈ`. See `WithTop.toDualBotEquiv` for the related order-iso. -/ protected def toDual : WithTop α ≃ WithBot αᵒᵈ := Equiv.refl _ #align with_top.to_dual WithTop.toDual /-- `WithTop.ofDual` is the equivalence sending `⊤` to `⊥` and any `a : αᵒᵈ` to `ofDual a : α`. See `WithTop.toDualBotEquiv` for the related order-iso. -/ protected def ofDual : WithTop αᵒᵈ ≃ WithBot α := Equiv.refl _ #align with_top.of_dual WithTop.ofDual /-- `WithBot.toDual` is the equivalence sending `⊥` to `⊤` and any `a : α` to `toDual a : αᵒᵈ`. See `WithBot.toDual_top_equiv` for the related order-iso. -/ protected def _root_.WithBot.toDual : WithBot α ≃ WithTop αᵒᵈ := Equiv.refl _ #align with_bot.to_dual WithBot.toDual /-- `WithBot.ofDual` is the equivalence sending `⊥` to `⊤` and any `a : αᵒᵈ` to `ofDual a : α`. See `WithBot.ofDual_top_equiv` for the related order-iso. -/ protected def _root_.WithBot.ofDual : WithBot αᵒᵈ ≃ WithTop α := Equiv.refl _ #align with_bot.of_dual WithBot.ofDual @[simp] theorem toDual_symm_apply (a : WithBot αᵒᵈ) : WithTop.toDual.symm a = WithBot.ofDual a := rfl #align with_top.to_dual_symm_apply WithTop.toDual_symm_apply @[simp] theorem ofDual_symm_apply (a : WithBot α) : WithTop.ofDual.symm a = WithBot.toDual a := rfl #align with_top.of_dual_symm_apply WithTop.ofDual_symm_apply @[simp] theorem toDual_apply_top : WithTop.toDual (⊤ : WithTop α) = ⊥ := rfl #align with_top.to_dual_apply_top WithTop.toDual_apply_top @[simp] theorem ofDual_apply_top : WithTop.ofDual (⊤ : WithTop α) = ⊥ := rfl #align with_top.of_dual_apply_top WithTop.ofDual_apply_top open OrderDual @[simp] theorem toDual_apply_coe (a : α) : WithTop.toDual (a : WithTop α) = toDual a := rfl #align with_top.to_dual_apply_coe WithTop.toDual_apply_coe @[simp] theorem ofDual_apply_coe (a : αᵒᵈ) : WithTop.ofDual (a : WithTop αᵒᵈ) = ofDual a := rfl #align with_top.of_dual_apply_coe WithTop.ofDual_apply_coe /-- Specialization of `Option.getD` to values in `WithTop α` that respects API boundaries. -/ def untop' (d : α) (x : WithTop α) : α := recTopCoe d id x #align with_top.untop' WithTop.untop' @[simp] theorem untop'_top {α} (d : α) : untop' d ⊤ = d := rfl #align with_top.untop'_top WithTop.untop'_top @[simp] theorem untop'_coe {α} (d x : α) : untop' d x = x := rfl #align with_top.untop'_coe WithTop.untop'_coe @[simp, norm_cast] -- Porting note: added `simp` theorem coe_eq_coe : (a : WithTop α) = b ↔ a = b := Option.some_inj #align with_top.coe_eq_coe WithTop.coe_eq_coe theorem untop'_eq_iff {d y : α} {x : WithTop α} : untop' d x = y ↔ x = y ∨ x = ⊤ ∧ y = d := WithBot.unbot'_eq_iff #align with_top.untop'_eq_iff WithTop.untop'_eq_iff @[simp] theorem untop'_eq_self_iff {d : α} {x : WithTop α} : untop' d x = d ↔ x = d ∨ x = ⊤ := WithBot.unbot'_eq_self_iff #align with_top.untop'_eq_self_iff WithTop.untop'_eq_self_iff theorem untop'_eq_untop'_iff {d : α} {x y : WithTop α} : untop' d x = untop' d y ↔ x = y ∨ x = d ∧ y = ⊤ ∨ x = ⊤ ∧ y = d := WithBot.unbot'_eq_unbot'_iff #align with_top.untop'_eq_untop'_iff WithTop.untop'_eq_untop'_iff /-- Lift a map `f : α → β` to `WithTop α → WithTop β`. Implemented using `Option.map`. -/ def map (f : α → β) : WithTop α → WithTop β := Option.map f #align with_top.map WithTop.map @[simp] theorem map_top (f : α → β) : map f ⊤ = ⊤ := rfl #align with_top.map_top WithTop.map_top @[simp] theorem map_coe (f : α → β) (a : α) : map f a = f a := rfl #align with_top.map_coe WithTop.map_coe theorem map_comm {f₁ : α → β} {f₂ : α → γ} {g₁ : β → δ} {g₂ : γ → δ} (h : g₁ ∘ f₁ = g₂ ∘ f₂) (a : α) : map g₁ (map f₁ a) = map g₂ (map f₂ a) := Option.map_comm h _ #align with_top.map_comm WithTop.map_comm /-- The image of a binary function `f : α → β → γ` as a function `WithTop α → WithTop β → WithTop γ`. Mathematically this should be thought of as the image of the corresponding function `α × β → γ`. -/ def map₂ : (α → β → γ) → WithTop α → WithTop β → WithTop γ := Option.map₂ lemma map₂_coe_coe (f : α → β → γ) (a : α) (b : β) : map₂ f a b = f a b := rfl @[simp] lemma map₂_top_left (f : α → β → γ) (b) : map₂ f ⊤ b = ⊤ := rfl @[simp] lemma map₂_top_right (f : α → β → γ) (a) : map₂ f a ⊤ = ⊤ := by cases a <;> rfl @[simp] lemma map₂_coe_left (f : α → β → γ) (a : α) (b) : map₂ f a b = b.map fun b ↦ f a b := rfl @[simp] lemma map₂_coe_right (f : α → β → γ) (a) (b : β) : map₂ f a b = a.map (f · b) := by cases a <;> rfl @[simp] lemma map₂_eq_top_iff {f : α → β → γ} {a : WithTop α} {b : WithTop β} : map₂ f a b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := Option.map₂_eq_none_iff theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithBot α) : map f (WithBot.toDual a) = a.map (toDual ∘ f) := rfl #align with_top.map_to_dual WithTop.map_toDual theorem map_ofDual (f : α → β) (a : WithBot αᵒᵈ) : map f (WithBot.ofDual a) = a.map (ofDual ∘ f) := rfl #align with_top.map_of_dual WithTop.map_ofDual theorem toDual_map (f : α → β) (a : WithTop α) : WithTop.toDual (map f a) = WithBot.map (toDual ∘ f ∘ ofDual) (WithTop.toDual a) := rfl #align with_top.to_dual_map WithTop.toDual_map theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithTop αᵒᵈ) : WithTop.ofDual (map f a) = WithBot.map (ofDual ∘ f ∘ toDual) (WithTop.ofDual a) := rfl #align with_top.of_dual_map WithTop.ofDual_map theorem ne_top_iff_exists {x : WithTop α} : x ≠ ⊤ ↔ ∃ a : α, ↑a = x := Option.ne_none_iff_exists #align with_top.ne_top_iff_exists WithTop.ne_top_iff_exists /-- Deconstruct a `x : WithTop α` to the underlying value in `α`, given a proof that `x ≠ ⊤`. -/ def untop : ∀ x : WithTop α, x ≠ ⊤ → α | (x : α), _ => x #align with_top.untop WithTop.untop @[simp] lemma coe_untop : ∀ (x : WithTop α) hx, x.untop hx = x | (x : α), _ => rfl #align with_top.coe_untop WithTop.coe_untop @[simp] theorem untop_coe (x : α) (h : (x : WithTop α) ≠ ⊤ := coe_ne_top) : (x : WithTop α).untop h = x := rfl #align with_top.untop_coe WithTop.untop_coe instance canLift : CanLift (WithTop α) α (↑) fun r => r ≠ ⊤ where prf x h := ⟨x.untop h, coe_untop _ _⟩ #align with_top.can_lift WithTop.canLift section LE variable [LE α] instance (priority := 10) le : LE (WithTop α) := ⟨fun o₁ o₂ => ∀ a : α, o₂ = ↑a → ∃ b : α, o₁ = ↑b ∧ b ≤ a⟩ theorem toDual_le_iff {a : WithTop α} {b : WithBot αᵒᵈ} : WithTop.toDual a ≤ b ↔ WithBot.ofDual b ≤ a := Iff.rfl #align with_top.to_dual_le_iff WithTop.toDual_le_iff theorem le_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} : a ≤ WithTop.toDual b ↔ b ≤ WithBot.ofDual a := Iff.rfl #align with_top.le_to_dual_iff WithTop.le_toDual_iff @[simp] theorem toDual_le_toDual_iff {a b : WithTop α} : WithTop.toDual a ≤ WithTop.toDual b ↔ b ≤ a := Iff.rfl #align with_top.to_dual_le_to_dual_iff WithTop.toDual_le_toDual_iff theorem ofDual_le_iff {a : WithTop αᵒᵈ} {b : WithBot α} : WithTop.ofDual a ≤ b ↔ WithBot.toDual b ≤ a := Iff.rfl #align with_top.of_dual_le_iff WithTop.ofDual_le_iff theorem le_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} : a ≤ WithTop.ofDual b ↔ b ≤ WithBot.toDual a := Iff.rfl #align with_top.le_of_dual_iff WithTop.le_ofDual_iff @[simp] theorem ofDual_le_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a ≤ WithTop.ofDual b ↔ b ≤ a := Iff.rfl #align with_top.of_dual_le_of_dual_iff WithTop.ofDual_le_ofDual_iff @[simp, norm_cast] theorem coe_le_coe : (a : WithTop α) ≤ b ↔ a ≤ b := by simp only [← toDual_le_toDual_iff, toDual_apply_coe, WithBot.coe_le_coe, toDual_le_toDual] #align with_top.coe_le_coe WithTop.coe_le_coe @[simp, deprecated coe_le_coe "Don't mix Option and WithTop" (since := "2024-05-27")] theorem some_le_some : @LE.le (WithTop α) _ (Option.some a) (Option.some b) ↔ a ≤ b := coe_le_coe #align with_top.some_le_some WithTop.some_le_some instance orderTop : OrderTop (WithTop α) where le_top := fun _ => toDual_le_toDual_iff.mp bot_le @[simp, deprecated le_top "Don't mix Option and WithTop" (since := "2024-05-27")] theorem le_none {a : WithTop α} : @LE.le (WithTop α) _ a none := le_top #align with_top.le_none WithTop.le_none instance orderBot [OrderBot α] : OrderBot (WithTop α) where bot := (⊥ : α) bot_le o a ha := by cases ha; exact ⟨_, rfl, bot_le⟩ #align with_top.order_bot WithTop.orderBot instance boundedOrder [OrderBot α] : BoundedOrder (WithTop α) := { WithTop.orderTop, WithTop.orderBot with } theorem not_top_le_coe (a : α) : ¬(⊤ : WithTop α) ≤ ↑a := WithBot.not_coe_le_bot (toDual a) #align with_top.not_top_le_coe WithTop.not_top_le_coe /-- There is a general version `top_le_iff`, but this lemma does not require a `PartialOrder`. -/ @[simp] protected theorem top_le_iff : ∀ {a : WithTop α}, ⊤ ≤ a ↔ a = ⊤ | (a : α) => by simp [not_top_le_coe _] | ⊤ => by simp theorem le_coe : ∀ {o : Option α}, a ∈ o → (@LE.le (WithTop α) _ o b ↔ a ≤ b) | _, rfl => coe_le_coe #align with_top.le_coe WithTop.le_coe theorem le_coe_iff {x : WithTop α} : x ≤ b ↔ ∃ a : α, x = a ∧ a ≤ b := @WithBot.coe_le_iff (αᵒᵈ) _ _ (toDual x) #align with_top.le_coe_iff WithTop.le_coe_iff theorem coe_le_iff {x : WithTop α} : ↑a ≤ x ↔ ∀ b : α, x = ↑b → a ≤ b := @WithBot.le_coe_iff (αᵒᵈ) _ _ (toDual x) #align with_top.coe_le_iff WithTop.coe_le_iff protected theorem _root_.IsMin.withTop (h : IsMin a) : IsMin (a : WithTop α) := by -- defeq to is_max_to_dual_iff.mp (is_max.with_bot _), but that breaks API boundary intro _ hb rw [← toDual_le_toDual_iff] at hb simpa [toDual_le_iff] using h.toDual.withBot hb #align is_min.with_top IsMin.withTop theorem untop_le_iff {a : WithTop α} {b : α} (h : a ≠ ⊤) : untop a h ≤ b ↔ a ≤ (b : WithTop α) := @WithBot.le_unbot_iff αᵒᵈ _ _ _ _ theorem le_untop_iff {a : α} {b : WithTop α} (h : b ≠ ⊤) : a ≤ untop b h ↔ (a : WithTop α) ≤ b := @WithBot.unbot_le_iff αᵒᵈ _ _ _ _ theorem le_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c ≤ b) : c ≤ a.untop' b ↔ c ≤ a := WithBot.unbot'_le_iff (α := αᵒᵈ) h end LE section LT variable [LT α] instance (priority := 10) lt : LT (WithTop α) := ⟨fun o₁ o₂ : Option α => ∃ b ∈ o₁, ∀ a ∈ o₂, b < a⟩ theorem toDual_lt_iff {a : WithTop α} {b : WithBot αᵒᵈ} : WithTop.toDual a < b ↔ WithBot.ofDual b < a := Iff.rfl #align with_top.to_dual_lt_iff WithTop.toDual_lt_iff theorem lt_toDual_iff {a : WithBot αᵒᵈ} {b : WithTop α} : a < WithTop.toDual b ↔ b < WithBot.ofDual a := Iff.rfl #align with_top.lt_to_dual_iff WithTop.lt_toDual_iff @[simp] theorem toDual_lt_toDual_iff {a b : WithTop α} : WithTop.toDual a < WithTop.toDual b ↔ b < a := Iff.rfl #align with_top.to_dual_lt_to_dual_iff WithTop.toDual_lt_toDual_iff theorem ofDual_lt_iff {a : WithTop αᵒᵈ} {b : WithBot α} : WithTop.ofDual a < b ↔ WithBot.toDual b < a := Iff.rfl #align with_top.of_dual_lt_iff WithTop.ofDual_lt_iff theorem lt_ofDual_iff {a : WithBot α} {b : WithTop αᵒᵈ} : a < WithTop.ofDual b ↔ b < WithBot.toDual a := Iff.rfl #align with_top.lt_of_dual_iff WithTop.lt_ofDual_iff @[simp] theorem ofDual_lt_ofDual_iff {a b : WithTop αᵒᵈ} : WithTop.ofDual a < WithTop.ofDual b ↔ b < a := Iff.rfl #align with_top.of_dual_lt_of_dual_iff WithTop.ofDual_lt_ofDual_iff theorem lt_untop'_iff {a : WithTop α} {b c : α} (h : a = ⊤ → c < b) : c < a.untop' b ↔ c < a := WithBot.unbot'_lt_iff (α := αᵒᵈ) h end LT end WithTop namespace WithBot open OrderDual @[simp] theorem toDual_symm_apply (a : WithTop αᵒᵈ) : WithBot.toDual.symm a = WithTop.ofDual a := rfl #align with_bot.to_dual_symm_apply WithBot.toDual_symm_apply @[simp] theorem ofDual_symm_apply (a : WithTop α) : WithBot.ofDual.symm a = WithTop.toDual a := rfl #align with_bot.of_dual_symm_apply WithBot.ofDual_symm_apply @[simp] theorem toDual_apply_bot : WithBot.toDual (⊥ : WithBot α) = ⊤ := rfl #align with_bot.to_dual_apply_bot WithBot.toDual_apply_bot @[simp] theorem ofDual_apply_bot : WithBot.ofDual (⊥ : WithBot α) = ⊤ := rfl #align with_bot.of_dual_apply_bot WithBot.ofDual_apply_bot @[simp] theorem toDual_apply_coe (a : α) : WithBot.toDual (a : WithBot α) = toDual a := rfl #align with_bot.to_dual_apply_coe WithBot.toDual_apply_coe @[simp] theorem ofDual_apply_coe (a : αᵒᵈ) : WithBot.ofDual (a : WithBot αᵒᵈ) = ofDual a := rfl #align with_bot.of_dual_apply_coe WithBot.ofDual_apply_coe theorem map_toDual (f : αᵒᵈ → βᵒᵈ) (a : WithTop α) : WithBot.map f (WithTop.toDual a) = a.map (toDual ∘ f) := rfl #align with_bot.map_to_dual WithBot.map_toDual theorem map_ofDual (f : α → β) (a : WithTop αᵒᵈ) : WithBot.map f (WithTop.ofDual a) = a.map (ofDual ∘ f) := rfl #align with_bot.map_of_dual WithBot.map_ofDual theorem toDual_map (f : α → β) (a : WithBot α) : WithBot.toDual (WithBot.map f a) = map (toDual ∘ f ∘ ofDual) (WithBot.toDual a) := rfl #align with_bot.to_dual_map WithBot.toDual_map theorem ofDual_map (f : αᵒᵈ → βᵒᵈ) (a : WithBot αᵒᵈ) : WithBot.ofDual (WithBot.map f a) = map (ofDual ∘ f ∘ toDual) (WithBot.ofDual a) := rfl #align with_bot.of_dual_map WithBot.ofDual_map section LE variable [LE α] {a b : α} theorem toDual_le_iff {a : WithBot α} {b : WithTop αᵒᵈ} : WithBot.toDual a ≤ b ↔ WithTop.ofDual b ≤ a := Iff.rfl #align with_bot.to_dual_le_iff WithBot.toDual_le_iff theorem le_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} : a ≤ WithBot.toDual b ↔ b ≤ WithTop.ofDual a := Iff.rfl #align with_bot.le_to_dual_iff WithBot.le_toDual_iff @[simp] theorem toDual_le_toDual_iff {a b : WithBot α} : WithBot.toDual a ≤ WithBot.toDual b ↔ b ≤ a := Iff.rfl #align with_bot.to_dual_le_to_dual_iff WithBot.toDual_le_toDual_iff theorem ofDual_le_iff {a : WithBot αᵒᵈ} {b : WithTop α} : WithBot.ofDual a ≤ b ↔ WithTop.toDual b ≤ a := Iff.rfl #align with_bot.of_dual_le_iff WithBot.ofDual_le_iff theorem le_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} : a ≤ WithBot.ofDual b ↔ b ≤ WithTop.toDual a := Iff.rfl #align with_bot.le_of_dual_iff WithBot.le_ofDual_iff @[simp] theorem ofDual_le_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a ≤ WithBot.ofDual b ↔ b ≤ a := Iff.rfl #align with_bot.of_dual_le_of_dual_iff WithBot.ofDual_le_ofDual_iff end LE section LT variable [LT α] {a b : α} theorem toDual_lt_iff {a : WithBot α} {b : WithTop αᵒᵈ} : WithBot.toDual a < b ↔ WithTop.ofDual b < a := Iff.rfl #align with_bot.to_dual_lt_iff WithBot.toDual_lt_iff theorem lt_toDual_iff {a : WithTop αᵒᵈ} {b : WithBot α} : a < WithBot.toDual b ↔ b < WithTop.ofDual a := Iff.rfl #align with_bot.lt_to_dual_iff WithBot.lt_toDual_iff @[simp] theorem toDual_lt_toDual_iff {a b : WithBot α} : WithBot.toDual a < WithBot.toDual b ↔ b < a := Iff.rfl #align with_bot.to_dual_lt_to_dual_iff WithBot.toDual_lt_toDual_iff theorem ofDual_lt_iff {a : WithBot αᵒᵈ} {b : WithTop α} : WithBot.ofDual a < b ↔ WithTop.toDual b < a := Iff.rfl #align with_bot.of_dual_lt_iff WithBot.ofDual_lt_iff theorem lt_ofDual_iff {a : WithTop α} {b : WithBot αᵒᵈ} : a < WithBot.ofDual b ↔ b < WithTop.toDual a := Iff.rfl #align with_bot.lt_of_dual_iff WithBot.lt_ofDual_iff @[simp] theorem ofDual_lt_ofDual_iff {a b : WithBot αᵒᵈ} : WithBot.ofDual a < WithBot.ofDual b ↔ b < a := Iff.rfl #align with_bot.of_dual_lt_of_dual_iff WithBot.ofDual_lt_ofDual_iff end LT end WithBot namespace WithTop section LT variable [LT α] {a b : α} open OrderDual @[simp, norm_cast] theorem coe_lt_coe : (a : WithTop α) < b ↔ a < b := by simp only [← toDual_lt_toDual_iff, toDual_apply_coe, WithBot.coe_lt_coe, toDual_lt_toDual] #align with_top.coe_lt_coe WithTop.coe_lt_coe @[simp] theorem coe_lt_top (a : α) : (a : WithTop α) < ⊤ := by simp [← toDual_lt_toDual_iff, WithBot.bot_lt_coe] #align with_top.coe_lt_top WithTop.coe_lt_top @[simp] protected theorem not_top_lt (a : WithTop α) : ¬⊤ < a := by rw [← toDual_lt_toDual_iff] exact WithBot.not_lt_bot _ @[simp, deprecated coe_lt_coe "Don't mix Option and WithTop" (since := "2024-05-27")] theorem some_lt_some : @LT.lt (WithTop α) _ (Option.some a) (Option.some b) ↔ a < b := coe_lt_coe #align with_top.some_lt_some WithTop.some_lt_some @[simp, deprecated coe_lt_top "Don't mix Option and WithTop" (since := "2024-05-27")] theorem some_lt_none (a : α) : @LT.lt (WithTop α) _ (Option.some a) none := coe_lt_top a #align with_top.some_lt_none WithTop.some_lt_none @[simp, deprecated not_top_lt "Don't mix Option and WithTop" (since := "2024-05-27")] theorem not_none_lt (a : WithTop α) : ¬@LT.lt (WithTop α) _ none a := WithTop.not_top_lt _ #align with_top.not_none_lt WithTop.not_none_lt
Mathlib/Order/WithBot.lean
1,169
1,171
theorem lt_iff_exists_coe {a b : WithTop α} : a < b ↔ ∃ p : α, a = p ∧ ↑p < b := by
rw [← toDual_lt_toDual_iff, WithBot.lt_iff_exists_coe, OrderDual.exists] exact exists_congr fun _ => and_congr_left' Iff.rfl
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Decomposition.Lebesgue import Mathlib.MeasureTheory.Measure.Complex import Mathlib.MeasureTheory.Decomposition.Jordan import Mathlib.MeasureTheory.Measure.WithDensityVectorMeasure /-! # Lebesgue decomposition This file proves the Lebesgue decomposition theorem for signed measures. The Lebesgue decomposition theorem states that, given two σ-finite measures `μ` and `ν`, there exists a σ-finite measure `ξ` and a measurable function `f` such that `μ = ξ + fν` and `ξ` is mutually singular with respect to `ν`. ## Main definitions * `MeasureTheory.SignedMeasure.HaveLebesgueDecomposition` : A signed measure `s` and a measure `μ` is said to `HaveLebesgueDecomposition` if both the positive part and negative part of `s` `HaveLebesgueDecomposition` with respect to `μ`. * `MeasureTheory.SignedMeasure.singularPart` : The singular part between a signed measure `s` and a measure `μ` is simply the singular part of the positive part of `s` with respect to `μ` minus the singular part of the negative part of `s` with respect to `μ`. * `MeasureTheory.SignedMeasure.rnDeriv` : The Radon-Nikodym derivative of a signed measure `s` with respect to a measure `μ` is the Radon-Nikodym derivative of the positive part of `s` with respect to `μ` minus the Radon-Nikodym derivative of the negative part of `s` with respect to `μ`. ## Main results * `MeasureTheory.SignedMeasure.singularPart_add_withDensity_rnDeriv_eq` : the Lebesgue decomposition theorem between a signed measure and a σ-finite positive measure. ## Tags Lebesgue decomposition theorem -/ noncomputable section open scoped Classical MeasureTheory NNReal ENNReal open Set variable {α β : Type*} {m : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} namespace MeasureTheory namespace SignedMeasure open Measure /-- A signed measure `s` is said to `HaveLebesgueDecomposition` with respect to a measure `μ` if the positive part and the negative part of `s` both `HaveLebesgueDecomposition` with respect to `μ`. -/ class HaveLebesgueDecomposition (s : SignedMeasure α) (μ : Measure α) : Prop where posPart : s.toJordanDecomposition.posPart.HaveLebesgueDecomposition μ negPart : s.toJordanDecomposition.negPart.HaveLebesgueDecomposition μ #align measure_theory.signed_measure.have_lebesgue_decomposition MeasureTheory.SignedMeasure.HaveLebesgueDecomposition #align measure_theory.signed_measure.have_lebesgue_decomposition.pos_part MeasureTheory.SignedMeasure.HaveLebesgueDecomposition.posPart #align measure_theory.signed_measure.have_lebesgue_decomposition.neg_part MeasureTheory.SignedMeasure.HaveLebesgueDecomposition.negPart attribute [instance] HaveLebesgueDecomposition.posPart attribute [instance] HaveLebesgueDecomposition.negPart theorem not_haveLebesgueDecomposition_iff (s : SignedMeasure α) (μ : Measure α) : ¬s.HaveLebesgueDecomposition μ ↔ ¬s.toJordanDecomposition.posPart.HaveLebesgueDecomposition μ ∨ ¬s.toJordanDecomposition.negPart.HaveLebesgueDecomposition μ := ⟨fun h => not_or_of_imp fun hp hn => h ⟨hp, hn⟩, fun h hl => (not_and_or.2 h) ⟨hl.1, hl.2⟩⟩ #align measure_theory.signed_measure.not_have_lebesgue_decomposition_iff MeasureTheory.SignedMeasure.not_haveLebesgueDecomposition_iff -- `inferInstance` directly does not work -- see Note [lower instance priority] instance (priority := 100) haveLebesgueDecomposition_of_sigmaFinite (s : SignedMeasure α) (μ : Measure α) [SigmaFinite μ] : s.HaveLebesgueDecomposition μ where posPart := inferInstance negPart := inferInstance #align measure_theory.signed_measure.have_lebesgue_decomposition_of_sigma_finite MeasureTheory.SignedMeasure.haveLebesgueDecomposition_of_sigmaFinite instance haveLebesgueDecomposition_neg (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] : (-s).HaveLebesgueDecomposition μ where posPart := by rw [toJordanDecomposition_neg, JordanDecomposition.neg_posPart] infer_instance negPart := by rw [toJordanDecomposition_neg, JordanDecomposition.neg_negPart] infer_instance #align measure_theory.signed_measure.have_lebesgue_decomposition_neg MeasureTheory.SignedMeasure.haveLebesgueDecomposition_neg instance haveLebesgueDecomposition_smul (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] (r : ℝ≥0) : (r • s).HaveLebesgueDecomposition μ where posPart := by rw [toJordanDecomposition_smul, JordanDecomposition.smul_posPart] infer_instance negPart := by rw [toJordanDecomposition_smul, JordanDecomposition.smul_negPart] infer_instance #align measure_theory.signed_measure.have_lebesgue_decomposition_smul MeasureTheory.SignedMeasure.haveLebesgueDecomposition_smul instance haveLebesgueDecomposition_smul_real (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] (r : ℝ) : (r • s).HaveLebesgueDecomposition μ := by by_cases hr : 0 ≤ r · lift r to ℝ≥0 using hr exact s.haveLebesgueDecomposition_smul μ _ · rw [not_le] at hr refine { posPart := by rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_posPart_neg _ _ hr] infer_instance negPart := by rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_negPart_neg _ _ hr] infer_instance } #align measure_theory.signed_measure.have_lebesgue_decomposition_smul_real MeasureTheory.SignedMeasure.haveLebesgueDecomposition_smul_real /-- Given a signed measure `s` and a measure `μ`, `s.singularPart μ` is the signed measure such that `s.singularPart μ + μ.withDensityᵥ (s.rnDeriv μ) = s` and `s.singularPart μ` is mutually singular with respect to `μ`. -/ def singularPart (s : SignedMeasure α) (μ : Measure α) : SignedMeasure α := (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure - (s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure #align measure_theory.signed_measure.singular_part MeasureTheory.SignedMeasure.singularPart section theorem singularPart_mutuallySingular (s : SignedMeasure α) (μ : Measure α) : s.toJordanDecomposition.posPart.singularPart μ ⟂ₘ s.toJordanDecomposition.negPart.singularPart μ := by by_cases hl : s.HaveLebesgueDecomposition μ · obtain ⟨i, hi, hpos, hneg⟩ := s.toJordanDecomposition.mutuallySingular rw [s.toJordanDecomposition.posPart.haveLebesgueDecomposition_add μ] at hpos rw [s.toJordanDecomposition.negPart.haveLebesgueDecomposition_add μ] at hneg rw [add_apply, add_eq_zero_iff] at hpos hneg exact ⟨i, hi, hpos.1, hneg.1⟩ · rw [not_haveLebesgueDecomposition_iff] at hl cases' hl with hp hn · rw [Measure.singularPart, dif_neg hp] exact MutuallySingular.zero_left · rw [Measure.singularPart, Measure.singularPart, dif_neg hn] exact MutuallySingular.zero_right #align measure_theory.signed_measure.singular_part_mutually_singular MeasureTheory.SignedMeasure.singularPart_mutuallySingular theorem singularPart_totalVariation (s : SignedMeasure α) (μ : Measure α) : (s.singularPart μ).totalVariation = s.toJordanDecomposition.posPart.singularPart μ + s.toJordanDecomposition.negPart.singularPart μ := by have : (s.singularPart μ).toJordanDecomposition = ⟨s.toJordanDecomposition.posPart.singularPart μ, s.toJordanDecomposition.negPart.singularPart μ, singularPart_mutuallySingular s μ⟩ := by refine JordanDecomposition.toSignedMeasure_injective ?_ rw [toSignedMeasure_toJordanDecomposition, singularPart, JordanDecomposition.toSignedMeasure] rw [totalVariation, this] #align measure_theory.signed_measure.singular_part_total_variation MeasureTheory.SignedMeasure.singularPart_totalVariation nonrec theorem mutuallySingular_singularPart (s : SignedMeasure α) (μ : Measure α) : singularPart s μ ⟂ᵥ μ.toENNRealVectorMeasure := by rw [mutuallySingular_ennreal_iff, singularPart_totalVariation, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] exact (mutuallySingular_singularPart _ _).add_left (mutuallySingular_singularPart _ _) #align measure_theory.signed_measure.mutually_singular_singular_part MeasureTheory.SignedMeasure.mutuallySingular_singularPart end /-- The Radon-Nikodym derivative between a signed measure and a positive measure. `rnDeriv s μ` satisfies `μ.withDensityᵥ (s.rnDeriv μ) = s` if and only if `s` is absolutely continuous with respect to `μ` and this fact is known as `MeasureTheory.SignedMeasure.absolutelyContinuous_iff_withDensity_rnDeriv_eq` and can be found in `MeasureTheory.Decomposition.RadonNikodym`. -/ def rnDeriv (s : SignedMeasure α) (μ : Measure α) : α → ℝ := fun x => (s.toJordanDecomposition.posPart.rnDeriv μ x).toReal - (s.toJordanDecomposition.negPart.rnDeriv μ x).toReal #align measure_theory.signed_measure.rn_deriv MeasureTheory.SignedMeasure.rnDeriv -- The generated equation theorem is the form of `rnDeriv s μ x = ...`. theorem rnDeriv_def (s : SignedMeasure α) (μ : Measure α) : rnDeriv s μ = fun x => (s.toJordanDecomposition.posPart.rnDeriv μ x).toReal - (s.toJordanDecomposition.negPart.rnDeriv μ x).toReal := rfl variable {s t : SignedMeasure α} @[measurability] theorem measurable_rnDeriv (s : SignedMeasure α) (μ : Measure α) : Measurable (rnDeriv s μ) := by rw [rnDeriv_def] measurability #align measure_theory.signed_measure.measurable_rn_deriv MeasureTheory.SignedMeasure.measurable_rnDeriv theorem integrable_rnDeriv (s : SignedMeasure α) (μ : Measure α) : Integrable (rnDeriv s μ) μ := by refine Integrable.sub ?_ ?_ <;> · constructor · apply Measurable.aestronglyMeasurable; measurability exact hasFiniteIntegral_toReal_of_lintegral_ne_top (lintegral_rnDeriv_lt_top _ μ).ne #align measure_theory.signed_measure.integrable_rn_deriv MeasureTheory.SignedMeasure.integrable_rnDeriv variable (s μ) /-- **The Lebesgue Decomposition theorem between a signed measure and a measure**: Given a signed measure `s` and a σ-finite measure `μ`, there exist a signed measure `t` and a measurable and integrable function `f`, such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`. In this case `t = s.singularPart μ` and `f = s.rnDeriv μ`. -/ theorem singularPart_add_withDensity_rnDeriv_eq [s.HaveLebesgueDecomposition μ] : s.singularPart μ + μ.withDensityᵥ (s.rnDeriv μ) = s := by conv_rhs => rw [← toSignedMeasure_toJordanDecomposition s, JordanDecomposition.toSignedMeasure] rw [singularPart, rnDeriv_def, withDensityᵥ_sub' (integrable_toReal_of_lintegral_ne_top _ _) (integrable_toReal_of_lintegral_ne_top _ _), withDensityᵥ_toReal, withDensityᵥ_toReal, sub_eq_add_neg, sub_eq_add_neg, add_comm (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure, ← add_assoc, add_assoc (-(s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure), ← toSignedMeasure_add, add_comm, ← add_assoc, ← neg_add, ← toSignedMeasure_add, add_comm, ← sub_eq_add_neg] · convert rfl -- `convert rfl` much faster than `congr` · exact s.toJordanDecomposition.posPart.haveLebesgueDecomposition_add μ · rw [add_comm] exact s.toJordanDecomposition.negPart.haveLebesgueDecomposition_add μ all_goals first | exact (lintegral_rnDeriv_lt_top _ _).ne | measurability #align measure_theory.signed_measure.singular_part_add_with_density_rn_deriv_eq MeasureTheory.SignedMeasure.singularPart_add_withDensity_rnDeriv_eq variable {s μ} theorem jordanDecomposition_add_withDensity_mutuallySingular {f : α → ℝ} (hf : Measurable f) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) : (t.toJordanDecomposition.posPart + μ.withDensity fun x : α => ENNReal.ofReal (f x)) ⟂ₘ t.toJordanDecomposition.negPart + μ.withDensity fun x : α => ENNReal.ofReal (-f x) := by rw [mutuallySingular_ennreal_iff, totalVariation_mutuallySingular_iff, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] at htμ exact ((JordanDecomposition.mutuallySingular _).add_right (htμ.1.mono_ac (refl _) (withDensity_absolutelyContinuous _ _))).add_left ((htμ.2.symm.mono_ac (withDensity_absolutelyContinuous _ _) (refl _)).add_right (withDensity_ofReal_mutuallySingular hf)) #align measure_theory.signed_measure.jordan_decomposition_add_with_density_mutually_singular MeasureTheory.SignedMeasure.jordanDecomposition_add_withDensity_mutuallySingular theorem toJordanDecomposition_eq_of_eq_add_withDensity {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.toJordanDecomposition = @JordanDecomposition.mk α _ (t.toJordanDecomposition.posPart + μ.withDensity fun x => ENNReal.ofReal (f x)) (t.toJordanDecomposition.negPart + μ.withDensity fun x => ENNReal.ofReal (-f x)) (by haveI := isFiniteMeasure_withDensity_ofReal hfi.2; infer_instance) (by haveI := isFiniteMeasure_withDensity_ofReal hfi.neg.2; infer_instance) (jordanDecomposition_add_withDensity_mutuallySingular hf htμ) := by haveI := isFiniteMeasure_withDensity_ofReal hfi.2 haveI := isFiniteMeasure_withDensity_ofReal hfi.neg.2 refine toJordanDecomposition_eq ?_ simp_rw [JordanDecomposition.toSignedMeasure, hadd] ext i hi rw [VectorMeasure.sub_apply, toSignedMeasure_apply_measurable hi, toSignedMeasure_apply_measurable hi, add_apply, add_apply, ENNReal.toReal_add, ENNReal.toReal_add, add_sub_add_comm, ← toSignedMeasure_apply_measurable hi, ← toSignedMeasure_apply_measurable hi, ← VectorMeasure.sub_apply, ← JordanDecomposition.toSignedMeasure, toSignedMeasure_toJordanDecomposition, VectorMeasure.add_apply, ← toSignedMeasure_apply_measurable hi, ← toSignedMeasure_apply_measurable hi, withDensityᵥ_eq_withDensity_pos_part_sub_withDensity_neg_part hfi, VectorMeasure.sub_apply] <;> exact (measure_lt_top _ _).ne #align measure_theory.signed_measure.to_jordan_decomposition_eq_of_eq_add_with_density MeasureTheory.SignedMeasure.toJordanDecomposition_eq_of_eq_add_withDensity private theorem haveLebesgueDecomposition_mk' (μ : Measure α) {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.HaveLebesgueDecomposition μ := by have htμ' := htμ rw [mutuallySingular_ennreal_iff] at htμ change _ ⟂ₘ VectorMeasure.equivMeasure.toFun (VectorMeasure.equivMeasure.invFun μ) at htμ rw [VectorMeasure.equivMeasure.right_inv, totalVariation_mutuallySingular_iff] at htμ refine { posPart := by use ⟨t.toJordanDecomposition.posPart, fun x => ENNReal.ofReal (f x)⟩ refine ⟨hf.ennreal_ofReal, htμ.1, ?_⟩ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] negPart := by use ⟨t.toJordanDecomposition.negPart, fun x => ENNReal.ofReal (-f x)⟩ refine ⟨hf.neg.ennreal_ofReal, htμ.2, ?_⟩ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] } theorem haveLebesgueDecomposition_mk (μ : Measure α) {f : α → ℝ} (hf : Measurable f) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : s.HaveLebesgueDecomposition μ := by by_cases hfi : Integrable f μ · exact haveLebesgueDecomposition_mk' μ hf hfi htμ hadd · rw [withDensityᵥ, dif_neg hfi, add_zero] at hadd refine haveLebesgueDecomposition_mk' μ measurable_zero (integrable_zero _ _ μ) htμ ?_ rwa [withDensityᵥ_zero, add_zero] #align measure_theory.signed_measure.have_lebesgue_decomposition_mk MeasureTheory.SignedMeasure.haveLebesgueDecomposition_mk private theorem eq_singularPart' (t : SignedMeasure α) {f : α → ℝ} (hf : Measurable f) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : t = s.singularPart μ := by have htμ' := htμ rw [mutuallySingular_ennreal_iff, totalVariation_mutuallySingular_iff, VectorMeasure.ennrealToMeasure_toENNRealVectorMeasure] at htμ rw [singularPart, ← t.toSignedMeasure_toJordanDecomposition, JordanDecomposition.toSignedMeasure] congr · have hfpos : Measurable fun x => ENNReal.ofReal (f x) := by measurability refine eq_singularPart hfpos htμ.1 ?_ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] · have hfneg : Measurable fun x => ENNReal.ofReal (-f x) := by measurability refine eq_singularPart hfneg htμ.2 ?_ rw [toJordanDecomposition_eq_of_eq_add_withDensity hf hfi htμ' hadd] /-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`, we have `t = singularPart s μ`, i.e. `t` is the singular part of the Lebesgue decomposition between `s` and `μ`. -/ theorem eq_singularPart (t : SignedMeasure α) (f : α → ℝ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : t = s.singularPart μ := by by_cases hfi : Integrable f μ · refine eq_singularPart' t hfi.1.measurable_mk (hfi.congr hfi.1.ae_eq_mk) htμ ?_ convert hadd using 2 exact WithDensityᵥEq.congr_ae hfi.1.ae_eq_mk.symm · rw [withDensityᵥ, dif_neg hfi, add_zero] at hadd refine eq_singularPart' t measurable_zero (integrable_zero _ _ μ) htμ ?_ rwa [withDensityᵥ_zero, add_zero] #align measure_theory.signed_measure.eq_singular_part MeasureTheory.SignedMeasure.eq_singularPart theorem singularPart_zero (μ : Measure α) : (0 : SignedMeasure α).singularPart μ = 0 := by refine (eq_singularPart 0 0 VectorMeasure.MutuallySingular.zero_left ?_).symm rw [zero_add, withDensityᵥ_zero] #align measure_theory.signed_measure.singular_part_zero MeasureTheory.SignedMeasure.singularPart_zero theorem singularPart_neg (s : SignedMeasure α) (μ : Measure α) : (-s).singularPart μ = -s.singularPart μ := by have h₁ : ((-s).toJordanDecomposition.posPart.singularPart μ).toSignedMeasure = (s.toJordanDecomposition.negPart.singularPart μ).toSignedMeasure := by refine toSignedMeasure_congr ?_ rw [toJordanDecomposition_neg, JordanDecomposition.neg_posPart] have h₂ : ((-s).toJordanDecomposition.negPart.singularPart μ).toSignedMeasure = (s.toJordanDecomposition.posPart.singularPart μ).toSignedMeasure := by refine toSignedMeasure_congr ?_ rw [toJordanDecomposition_neg, JordanDecomposition.neg_negPart] rw [singularPart, singularPart, neg_sub, h₁, h₂] #align measure_theory.signed_measure.singular_part_neg MeasureTheory.SignedMeasure.singularPart_neg theorem singularPart_smul_nnreal (s : SignedMeasure α) (μ : Measure α) (r : ℝ≥0) : (r • s).singularPart μ = r • s.singularPart μ := by rw [singularPart, singularPart, smul_sub, ← toSignedMeasure_smul, ← toSignedMeasure_smul] conv_lhs => congr · congr · rw [toJordanDecomposition_smul, JordanDecomposition.smul_posPart, singularPart_smul] · congr rw [toJordanDecomposition_smul, JordanDecomposition.smul_negPart, singularPart_smul] #align measure_theory.signed_measure.singular_part_smul_nnreal MeasureTheory.SignedMeasure.singularPart_smul_nnreal nonrec theorem singularPart_smul (s : SignedMeasure α) (μ : Measure α) (r : ℝ) : (r • s).singularPart μ = r • s.singularPart μ := by cases le_or_lt 0 r with | inl hr => lift r to ℝ≥0 using hr exact singularPart_smul_nnreal s μ r | inr hr => rw [singularPart, singularPart] conv_lhs => congr · congr · rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_posPart_neg _ _ hr, singularPart_smul] · congr · rw [toJordanDecomposition_smul_real, JordanDecomposition.real_smul_negPart_neg _ _ hr, singularPart_smul] rw [toSignedMeasure_smul, toSignedMeasure_smul, ← neg_sub, ← smul_sub, NNReal.smul_def, ← neg_smul, Real.coe_toNNReal _ (le_of_lt (neg_pos.mpr hr)), neg_neg] #align measure_theory.signed_measure.singular_part_smul MeasureTheory.SignedMeasure.singularPart_smul theorem singularPart_add (s t : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] [t.HaveLebesgueDecomposition μ] : (s + t).singularPart μ = s.singularPart μ + t.singularPart μ := by refine (eq_singularPart _ (s.rnDeriv μ + t.rnDeriv μ) ((mutuallySingular_singularPart s μ).add_left (mutuallySingular_singularPart t μ)) ?_).symm rw [withDensityᵥ_add (integrable_rnDeriv s μ) (integrable_rnDeriv t μ), add_assoc, add_comm (t.singularPart μ), add_assoc, add_comm _ (t.singularPart μ), singularPart_add_withDensity_rnDeriv_eq, ← add_assoc, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.singular_part_add MeasureTheory.SignedMeasure.singularPart_add theorem singularPart_sub (s t : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] [t.HaveLebesgueDecomposition μ] : (s - t).singularPart μ = s.singularPart μ - t.singularPart μ := by rw [sub_eq_add_neg, sub_eq_add_neg, singularPart_add, singularPart_neg] #align measure_theory.signed_measure.singular_part_sub MeasureTheory.SignedMeasure.singularPart_sub /-- Given a measure `μ`, signed measures `s` and `t`, and a function `f` such that `t` is mutually singular with respect to `μ` and `s = t + μ.withDensityᵥ f`, we have `f = rnDeriv s μ`, i.e. `f` is the Radon-Nikodym derivative of `s` and `μ`. -/ theorem eq_rnDeriv (t : SignedMeasure α) (f : α → ℝ) (hfi : Integrable f μ) (htμ : t ⟂ᵥ μ.toENNRealVectorMeasure) (hadd : s = t + μ.withDensityᵥ f) : f =ᵐ[μ] s.rnDeriv μ := by set f' := hfi.1.mk f have hadd' : s = t + μ.withDensityᵥ f' := by convert hadd using 2 exact WithDensityᵥEq.congr_ae hfi.1.ae_eq_mk.symm have := haveLebesgueDecomposition_mk μ hfi.1.measurable_mk htμ hadd' refine (Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) hfi ?_).symm rw [← add_right_inj t, ← hadd, eq_singularPart _ f htμ hadd, singularPart_add_withDensity_rnDeriv_eq] #align measure_theory.signed_measure.eq_rn_deriv MeasureTheory.SignedMeasure.eq_rnDeriv
Mathlib/MeasureTheory/Decomposition/SignedLebesgue.lean
417
423
theorem rnDeriv_neg (s : SignedMeasure α) (μ : Measure α) [s.HaveLebesgueDecomposition μ] : (-s).rnDeriv μ =ᵐ[μ] -s.rnDeriv μ := by
refine Integrable.ae_eq_of_withDensityᵥ_eq (integrable_rnDeriv _ _) (integrable_rnDeriv _ _).neg ?_ rw [withDensityᵥ_neg, ← add_right_inj ((-s).singularPart μ), singularPart_add_withDensity_rnDeriv_eq, singularPart_neg, ← neg_add, singularPart_add_withDensity_rnDeriv_eq]
/- Copyright (c) 2019 Minchao Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Minchao Wu, Chris Hughes, Mantas Bakšys -/ import Mathlib.Data.List.Basic import Mathlib.Order.MinMax import Mathlib.Order.WithBot #align_import data.list.min_max from "leanprover-community/mathlib"@"6d0adfa76594f304b4650d098273d4366edeb61b" /-! # Minimum and maximum of lists ## Main definitions The main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists. `argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmax f [] = none` `minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for `[]` -/ namespace List variable {α β : Type*} section ArgAux variable (r : α → α → Prop) [DecidableRel r] {l : List α} {o : Option α} {a m : α} /-- Auxiliary definition for `argmax` and `argmin`. -/ def argAux (a : Option α) (b : α) : Option α := Option.casesOn a (some b) fun c => if r b c then some b else some c #align list.arg_aux List.argAux @[simp] theorem foldl_argAux_eq_none : l.foldl (argAux r) o = none ↔ l = [] ∧ o = none := List.reverseRecOn l (by simp) fun tl hd => by simp only [foldl_append, foldl_cons, argAux, foldl_nil, append_eq_nil, and_false, false_and, iff_false]; cases foldl (argAux r) o tl <;> simp; try split_ifs <;> simp #align list.foldl_arg_aux_eq_none List.foldl_argAux_eq_none private theorem foldl_argAux_mem (l) : ∀ a m : α, m ∈ foldl (argAux r) (some a) l → m ∈ a :: l := List.reverseRecOn l (by simp [eq_comm]) (by intro tl hd ih a m simp only [foldl_append, foldl_cons, foldl_nil, argAux] cases hf : foldl (argAux r) (some a) tl · simp (config := { contextual := true }) · dsimp only split_ifs · simp (config := { contextual := true }) · -- `finish [ih _ _ hf]` closes this goal simp only [List.mem_cons] at ih rcases ih _ _ hf with rfl | H · simp (config := { contextual := true }) only [Option.mem_def, Option.some.injEq, find?, eq_comm, mem_cons, mem_append, mem_singleton, true_or, implies_true] · simp (config := { contextual := true }) [@eq_comm _ _ m, H]) @[simp] theorem argAux_self (hr₀ : Irreflexive r) (a : α) : argAux r (some a) a = a := if_neg <| hr₀ _ #align list.arg_aux_self List.argAux_self theorem not_of_mem_foldl_argAux (hr₀ : Irreflexive r) (hr₁ : Transitive r) : ∀ {a m : α} {o : Option α}, a ∈ l → m ∈ foldl (argAux r) o l → ¬r a m := by induction' l using List.reverseRecOn with tl a ih · simp intro b m o hb ho rw [foldl_append, foldl_cons, foldl_nil, argAux] at ho cases' hf : foldl (argAux r) o tl with c · rw [hf] at ho rw [foldl_argAux_eq_none] at hf simp_all [hf.1, hf.2, hr₀ _] rw [hf, Option.mem_def] at ho dsimp only at ho split_ifs at ho with hac <;> cases' mem_append.1 hb with h h <;> injection ho with ho <;> subst ho · exact fun hba => ih h hf (hr₁ hba hac) · simp_all [hr₀ _] · exact ih h hf · simp_all #align list.not_of_mem_foldl_arg_aux List.not_of_mem_foldl_argAux end ArgAux section Preorder variable [Preorder β] [@DecidableRel β (· < ·)] {f : α → β} {l : List α} {o : Option α} {a m : α} /-- `argmax f l` returns `some a`, where `f a` is maximal among the elements of `l`, in the sense that there is no `b ∈ l` with `f a < f b`. If `a`, `b` are such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmax f [] = none`. -/ def argmax (f : α → β) (l : List α) : Option α := l.foldl (argAux fun b c => f c < f b) none #align list.argmax List.argmax /-- `argmin f l` returns `some a`, where `f a` is minimal among the elements of `l`, in the sense that there is no `b ∈ l` with `f b < f a`. If `a`, `b` are such that `f a = f b`, it returns whichever of `a` or `b` comes first in the list. `argmin f [] = none`. -/ def argmin (f : α → β) (l : List α) := l.foldl (argAux fun b c => f b < f c) none #align list.argmin List.argmin @[simp] theorem argmax_nil (f : α → β) : argmax f [] = none := rfl #align list.argmax_nil List.argmax_nil @[simp] theorem argmin_nil (f : α → β) : argmin f [] = none := rfl #align list.argmin_nil List.argmin_nil @[simp] theorem argmax_singleton {f : α → β} {a : α} : argmax f [a] = a := rfl #align list.argmax_singleton List.argmax_singleton @[simp] theorem argmin_singleton {f : α → β} {a : α} : argmin f [a] = a := rfl #align list.argmin_singleton List.argmin_singleton theorem not_lt_of_mem_argmax : a ∈ l → m ∈ argmax f l → ¬f m < f a := not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h) (fun _ _ z hxy hyz => lt_trans (a := f z) hyz hxy) #align list.not_lt_of_mem_argmax List.not_lt_of_mem_argmax theorem not_lt_of_mem_argmin : a ∈ l → m ∈ argmin f l → ¬f a < f m := not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h) (fun x _ _ hxy hyz => lt_trans (a := f x) hxy hyz) #align list.not_lt_of_mem_argmin List.not_lt_of_mem_argmin theorem argmax_concat (f : α → β) (a : α) (l : List α) : argmax f (l ++ [a]) = Option.casesOn (argmax f l) (some a) fun c => if f c < f a then some a else some c := by rw [argmax, argmax]; simp [argAux] #align list.argmax_concat List.argmax_concat theorem argmin_concat (f : α → β) (a : α) (l : List α) : argmin f (l ++ [a]) = Option.casesOn (argmin f l) (some a) fun c => if f a < f c then some a else some c := @argmax_concat _ βᵒᵈ _ _ _ _ _ #align list.argmin_concat List.argmin_concat theorem argmax_mem : ∀ {l : List α} {m : α}, m ∈ argmax f l → m ∈ l | [], m => by simp | hd :: tl, m => by simpa [argmax, argAux] using foldl_argAux_mem _ tl hd m #align list.argmax_mem List.argmax_mem theorem argmin_mem : ∀ {l : List α} {m : α}, m ∈ argmin f l → m ∈ l := @argmax_mem _ βᵒᵈ _ _ _ #align list.argmin_mem List.argmin_mem @[simp] theorem argmax_eq_none : l.argmax f = none ↔ l = [] := by simp [argmax] #align list.argmax_eq_none List.argmax_eq_none @[simp] theorem argmin_eq_none : l.argmin f = none ↔ l = [] := @argmax_eq_none _ βᵒᵈ _ _ _ _ #align list.argmin_eq_none List.argmin_eq_none end Preorder section LinearOrder variable [LinearOrder β] {f : α → β} {l : List α} {o : Option α} {a m : α} theorem le_of_mem_argmax : a ∈ l → m ∈ argmax f l → f a ≤ f m := fun ha hm => le_of_not_lt <| not_lt_of_mem_argmax ha hm #align list.le_of_mem_argmax List.le_of_mem_argmax theorem le_of_mem_argmin : a ∈ l → m ∈ argmin f l → f m ≤ f a := @le_of_mem_argmax _ βᵒᵈ _ _ _ _ _ #align list.le_of_mem_argmin List.le_of_mem_argmin theorem argmax_cons (f : α → β) (a : α) (l : List α) : argmax f (a :: l) = Option.casesOn (argmax f l) (some a) fun c => if f a < f c then some c else some a := List.reverseRecOn l rfl fun hd tl ih => by rw [← cons_append, argmax_concat, ih, argmax_concat] cases' h : argmax f hd with m · simp [h] dsimp rw [← apply_ite, ← apply_ite] dsimp split_ifs <;> try rfl · exact absurd (lt_trans ‹f a < f m› ‹_›) ‹_› · cases (‹f a < f tl›.lt_or_lt _).elim ‹_› ‹_› #align list.argmax_cons List.argmax_cons theorem argmin_cons (f : α → β) (a : α) (l : List α) : argmin f (a :: l) = Option.casesOn (argmin f l) (some a) fun c => if f c < f a then some c else some a := @argmax_cons α βᵒᵈ _ _ _ _ #align list.argmin_cons List.argmin_cons variable [DecidableEq α] theorem index_of_argmax : ∀ {l : List α} {m : α}, m ∈ argmax f l → ∀ {a}, a ∈ l → f m ≤ f a → l.indexOf m ≤ l.indexOf a | [], m, _, _, _, _ => by simp | hd :: tl, m, hm, a, ha, ham => by simp only [indexOf_cons, argmax_cons, Option.mem_def] at hm ⊢ cases h : argmax f tl · rw [h] at hm simp_all rw [h] at hm dsimp only at hm simp only [cond_eq_if, beq_iff_eq] obtain ha | ha := ha <;> split_ifs at hm <;> injection hm with hm <;> subst hm · cases not_le_of_lt ‹_› ‹_› · rw [if_pos rfl] · rw [if_neg, if_neg] · exact Nat.succ_le_succ (index_of_argmax h (by assumption) ham) · exact ne_of_apply_ne f (lt_of_lt_of_le ‹_› ‹_›).ne · exact ne_of_apply_ne _ ‹f hd < f _›.ne · rw [if_pos rfl] exact Nat.zero_le _ #align list.index_of_argmax List.index_of_argmax theorem index_of_argmin : ∀ {l : List α} {m : α}, m ∈ argmin f l → ∀ {a}, a ∈ l → f a ≤ f m → l.indexOf m ≤ l.indexOf a := @index_of_argmax _ βᵒᵈ _ _ _ #align list.index_of_argmin List.index_of_argmin theorem mem_argmax_iff : m ∈ argmax f l ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.indexOf m ≤ l.indexOf a := ⟨fun hm => ⟨argmax_mem hm, fun a ha => le_of_mem_argmax ha hm, fun _ => index_of_argmax hm⟩, by rintro ⟨hml, ham, hma⟩ cases' harg : argmax f l with n · simp_all · have := _root_.le_antisymm (hma n (argmax_mem harg) (le_of_mem_argmax hml harg)) (index_of_argmax harg hml (ham _ (argmax_mem harg))) rw [(indexOf_inj hml (argmax_mem harg)).1 this, Option.mem_def]⟩ #align list.mem_argmax_iff List.mem_argmax_iff theorem argmax_eq_some_iff : argmax f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.indexOf m ≤ l.indexOf a := mem_argmax_iff #align list.argmax_eq_some_iff List.argmax_eq_some_iff theorem mem_argmin_iff : m ∈ argmin f l ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.indexOf m ≤ l.indexOf a := @mem_argmax_iff _ βᵒᵈ _ _ _ _ _ #align list.mem_argmin_iff List.mem_argmin_iff theorem argmin_eq_some_iff : argmin f l = some m ↔ m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.indexOf m ≤ l.indexOf a := mem_argmin_iff #align list.argmin_eq_some_iff List.argmin_eq_some_iff end LinearOrder section MaximumMinimum section Preorder variable [Preorder α] [@DecidableRel α (· < ·)] {l : List α} {a m : α} /-- `maximum l` returns a `WithBot α`, the largest element of `l` for nonempty lists, and `⊥` for `[]` -/ def maximum (l : List α) : WithBot α := argmax id l #align list.maximum List.maximum /-- `minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for `[]` -/ def minimum (l : List α) : WithTop α := argmin id l #align list.minimum List.minimum @[simp] theorem maximum_nil : maximum ([] : List α) = ⊥ := rfl #align list.maximum_nil List.maximum_nil @[simp] theorem minimum_nil : minimum ([] : List α) = ⊤ := rfl #align list.minimum_nil List.minimum_nil @[simp] theorem maximum_singleton (a : α) : maximum [a] = a := rfl #align list.maximum_singleton List.maximum_singleton @[simp] theorem minimum_singleton (a : α) : minimum [a] = a := rfl #align list.minimum_singleton List.minimum_singleton theorem maximum_mem {l : List α} {m : α} : (maximum l : WithTop α) = m → m ∈ l := argmax_mem #align list.maximum_mem List.maximum_mem theorem minimum_mem {l : List α} {m : α} : (minimum l : WithBot α) = m → m ∈ l := argmin_mem #align list.minimum_mem List.minimum_mem @[simp] theorem maximum_eq_bot {l : List α} : l.maximum = ⊥ ↔ l = [] := argmax_eq_none @[simp, deprecated maximum_eq_bot "Don't mix Option and WithBot" (since := "2024-05-27")] theorem maximum_eq_none {l : List α} : l.maximum = none ↔ l = [] := maximum_eq_bot #align list.maximum_eq_none List.maximum_eq_none @[simp] theorem minimum_eq_top {l : List α} : l.minimum = ⊤ ↔ l = [] := argmin_eq_none @[simp, deprecated minimum_eq_top "Don't mix Option and WithTop" (since := "2024-05-27")] theorem minimum_eq_none {l : List α} : l.minimum = none ↔ l = [] := minimum_eq_top #align list.minimum_eq_none List.minimum_eq_none theorem not_lt_maximum_of_mem : a ∈ l → (maximum l : WithBot α) = m → ¬m < a := not_lt_of_mem_argmax #align list.not_lt_maximum_of_mem List.not_lt_maximum_of_mem theorem minimum_not_lt_of_mem : a ∈ l → (minimum l : WithTop α) = m → ¬a < m := not_lt_of_mem_argmin #align list.minimum_not_lt_of_mem List.minimum_not_lt_of_mem theorem not_lt_maximum_of_mem' (ha : a ∈ l) : ¬maximum l < (a : WithBot α) := by cases h : l.maximum · simp_all · simp [not_lt_maximum_of_mem ha h, not_false_iff] #align list.not_lt_maximum_of_mem' List.not_lt_maximum_of_mem' theorem not_lt_minimum_of_mem' (ha : a ∈ l) : ¬(a : WithTop α) < minimum l := @not_lt_maximum_of_mem' αᵒᵈ _ _ _ _ ha #align list.not_lt_minimum_of_mem' List.not_lt_minimum_of_mem' end Preorder section LinearOrder variable [LinearOrder α] {l : List α} {a m : α} theorem maximum_concat (a : α) (l : List α) : maximum (l ++ [a]) = max (maximum l) a := by simp only [maximum, argmax_concat, id] cases argmax id l · exact (max_eq_right bot_le).symm · simp [WithBot.some_eq_coe, max_def_lt, WithBot.coe_lt_coe] #align list.maximum_concat List.maximum_concat theorem le_maximum_of_mem : a ∈ l → (maximum l : WithBot α) = m → a ≤ m := le_of_mem_argmax #align list.le_maximum_of_mem List.le_maximum_of_mem theorem minimum_le_of_mem : a ∈ l → (minimum l : WithTop α) = m → m ≤ a := le_of_mem_argmin #align list.minimum_le_of_mem List.minimum_le_of_mem theorem le_maximum_of_mem' (ha : a ∈ l) : (a : WithBot α) ≤ maximum l := le_of_not_lt <| not_lt_maximum_of_mem' ha #align list.le_maximum_of_mem' List.le_maximum_of_mem' theorem minimum_le_of_mem' (ha : a ∈ l) : minimum l ≤ (a : WithTop α) := @le_maximum_of_mem' αᵒᵈ _ _ _ ha #align list.le_minimum_of_mem' List.minimum_le_of_mem' theorem minimum_concat (a : α) (l : List α) : minimum (l ++ [a]) = min (minimum l) a := @maximum_concat αᵒᵈ _ _ _ #align list.minimum_concat List.minimum_concat theorem maximum_cons (a : α) (l : List α) : maximum (a :: l) = max ↑a (maximum l) := List.reverseRecOn l (by simp [@max_eq_left (WithBot α) _ _ _ bot_le]) fun tl hd ih => by rw [← cons_append, maximum_concat, ih, maximum_concat, max_assoc] #align list.maximum_cons List.maximum_cons theorem minimum_cons (a : α) (l : List α) : minimum (a :: l) = min ↑a (minimum l) := @maximum_cons αᵒᵈ _ _ _ #align list.minimum_cons List.minimum_cons theorem maximum_le_of_forall_le {b : WithBot α} (h : ∀ a ∈ l, a ≤ b) : l.maximum ≤ b := by induction l with | nil => simp | cons a l ih => simp only [maximum_cons, ge_iff_le, max_le_iff, WithBot.coe_le_coe] exact ⟨h a (by simp), ih fun a w => h a (mem_cons.mpr (Or.inr w))⟩ theorem le_minimum_of_forall_le {b : WithTop α} (h : ∀ a ∈ l, b ≤ a) : b ≤ l.minimum := maximum_le_of_forall_le (α := αᵒᵈ) h theorem maximum_eq_coe_iff : maximum l = m ↔ m ∈ l ∧ ∀ a ∈ l, a ≤ m := by rw [maximum, ← WithBot.some_eq_coe, argmax_eq_some_iff] simp only [id_eq, and_congr_right_iff, and_iff_left_iff_imp] intro _ h a hal hma rw [_root_.le_antisymm hma (h a hal)] #align list.maximum_eq_coe_iff List.maximum_eq_coe_iff theorem minimum_eq_coe_iff : minimum l = m ↔ m ∈ l ∧ ∀ a ∈ l, m ≤ a := @maximum_eq_coe_iff αᵒᵈ _ _ _ #align list.minimum_eq_coe_iff List.minimum_eq_coe_iff theorem coe_le_maximum_iff : a ≤ l.maximum ↔ ∃ b, b ∈ l ∧ a ≤ b := by induction l with | nil => simp | cons h t ih => simp [maximum_cons, ih] theorem minimum_le_coe_iff : l.minimum ≤ a ↔ ∃ b, b ∈ l ∧ b ≤ a := coe_le_maximum_iff (α := αᵒᵈ) theorem maximum_ne_bot_of_ne_nil (h : l ≠ []) : l.maximum ≠ ⊥ := match l, h with | _ :: _, _ => by simp [maximum_cons] theorem minimum_ne_top_of_ne_nil (h : l ≠ []) : l.minimum ≠ ⊤ := @maximum_ne_bot_of_ne_nil αᵒᵈ _ _ h theorem maximum_ne_bot_of_length_pos (h : 0 < l.length) : l.maximum ≠ ⊥ := match l, h with | _ :: _, _ => by simp [maximum_cons] theorem minimum_ne_top_of_length_pos (h : 0 < l.length) : l.minimum ≠ ⊤ := maximum_ne_bot_of_length_pos (α := αᵒᵈ) h /-- The maximum value in a non-empty `List`. -/ def maximum_of_length_pos (h : 0 < l.length) : α := WithBot.unbot l.maximum (maximum_ne_bot_of_length_pos h) /-- The minimum value in a non-empty `List`. -/ def minimum_of_length_pos (h : 0 < l.length) : α := maximum_of_length_pos (α := αᵒᵈ) h @[simp] lemma coe_maximum_of_length_pos (h : 0 < l.length) : (l.maximum_of_length_pos h : α) = l.maximum := WithBot.coe_unbot _ _ @[simp] lemma coe_minimum_of_length_pos (h : 0 < l.length) : (l.minimum_of_length_pos h : α) = l.minimum := WithTop.coe_untop _ _ @[simp] theorem le_maximum_of_length_pos_iff {b : α} (h : 0 < l.length) : b ≤ maximum_of_length_pos h ↔ b ≤ l.maximum := WithBot.le_unbot_iff _ @[simp] theorem minimum_of_length_pos_le_iff {b : α} (h : 0 < l.length) : minimum_of_length_pos h ≤ b ↔ l.minimum ≤ b := le_maximum_of_length_pos_iff (α := αᵒᵈ) h theorem maximum_of_length_pos_mem (h : 0 < l.length) : maximum_of_length_pos h ∈ l := by apply maximum_mem simp only [coe_maximum_of_length_pos] theorem minimum_of_length_pos_mem (h : 0 < l.length) : minimum_of_length_pos h ∈ l := maximum_of_length_pos_mem (α := αᵒᵈ) h theorem le_maximum_of_length_pos_of_mem (h : a ∈ l) (w : 0 < l.length) : a ≤ l.maximum_of_length_pos w := by simp only [le_maximum_of_length_pos_iff] exact le_maximum_of_mem' h theorem minimum_of_length_pos_le_of_mem (h : a ∈ l) (w : 0 < l.length) : l.minimum_of_length_pos w ≤ a := le_maximum_of_length_pos_of_mem (α := αᵒᵈ) h w
Mathlib/Data/List/MinMax.lean
477
480
theorem getElem_le_maximum_of_length_pos {i : ℕ} (w : i < l.length) (h := (Nat.zero_lt_of_lt w)) : l[i] ≤ l.maximum_of_length_pos h := by
apply le_maximum_of_length_pos_of_mem exact get_mem l i w
/- Copyright (c) 2023 Shogo Saito. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shogo Saito. Adapted for mathlib by Hunter Monroe -/ import Mathlib.Algebra.BigOperators.Ring.List import Mathlib.Data.Nat.ModEq import Mathlib.Data.Nat.GCD.BigOperators /-! # Chinese Remainder Theorem This file provides definitions and theorems for the Chinese Remainder Theorem. These are used in Gödel's Beta function, which is used in proving Gödel's incompleteness theorems. ## Main result - `chineseRemainderOfList`: Definition of the Chinese remainder of a list ## Tags Chinese Remainder Theorem, Gödel, beta function -/ namespace Nat variable {ι : Type*} lemma modEq_list_prod_iff {a b} {l : List ℕ} (co : l.Pairwise Coprime) : a ≡ b [MOD l.prod] ↔ ∀ i, a ≡ b [MOD l.get i] := by induction' l with m l ih · simp [modEq_one] · have : Coprime m l.prod := coprime_list_prod_right_iff.mpr (List.pairwise_cons.mp co).1 simp only [List.prod_cons, ← modEq_and_modEq_iff_modEq_mul this, ih (List.Pairwise.of_cons co), List.length_cons] constructor · rintro ⟨h0, hs⟩ i cases i using Fin.cases <;> simp [h0, hs] · intro h; exact ⟨h 0, fun i => h i.succ⟩ lemma modEq_list_prod_iff' {a b} {s : ι → ℕ} {l : List ι} (co : l.Pairwise (Coprime on s)) : a ≡ b [MOD (l.map s).prod] ↔ ∀ i ∈ l, a ≡ b [MOD s i] := by induction' l with i l ih · simp [modEq_one] · have : Coprime (s i) (l.map s).prod := by simp only [coprime_list_prod_right_iff, List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro j hj exact (List.pairwise_cons.mp co).1 j hj simp [← modEq_and_modEq_iff_modEq_mul this, ih (List.Pairwise.of_cons co)] variable (a s : ι → ℕ) /-- The natural number less than `(l.map s).prod` congruent to `a i` mod `s i` for all `i ∈ l`. -/ def chineseRemainderOfList : (l : List ι) → l.Pairwise (Coprime on s) → { k // ∀ i ∈ l, k ≡ a i [MOD s i] } | [], _ => ⟨0, by simp⟩ | i :: l, co => by have : Coprime (s i) (l.map s).prod := by simp only [coprime_list_prod_right_iff, List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro j hj exact (List.pairwise_cons.mp co).1 j hj have ih := chineseRemainderOfList l co.of_cons have k := chineseRemainder this (a i) ih use k simp only [List.mem_cons, forall_eq_or_imp, k.prop.1, true_and] intro j hj exact ((modEq_list_prod_iff' co.of_cons).mp k.prop.2 j hj).trans (ih.prop j hj) @[simp] theorem chineseRemainderOfList_nil : (chineseRemainderOfList a s [] List.Pairwise.nil : ℕ) = 0 := rfl theorem chineseRemainderOfList_lt_prod (l : List ι) (co : l.Pairwise (Coprime on s)) (hs : ∀ i ∈ l, s i ≠ 0) : chineseRemainderOfList a s l co < (l.map s).prod := by cases l with | nil => simp | cons i l => simp only [chineseRemainderOfList, List.map_cons, List.prod_cons] have : Coprime (s i) (l.map s).prod := by simp only [coprime_list_prod_right_iff, List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro j hj exact (List.pairwise_cons.mp co).1 j hj refine chineseRemainder_lt_mul this (a i) (chineseRemainderOfList a s l co.of_cons) (hs i (List.mem_cons_self _ l)) ?_ simp only [ne_eq, List.prod_eq_zero_iff, List.mem_map, not_exists, not_and] intro j hj exact hs j (List.mem_cons_of_mem _ hj) theorem chineseRemainderOfList_modEq_unique (l : List ι) (co : l.Pairwise (Coprime on s)) {z} (hz : ∀ i ∈ l, z ≡ a i [MOD s i]) : z ≡ chineseRemainderOfList a s l co [MOD (l.map s).prod] := by induction' l with i l ih · simp [modEq_one] · simp only [List.map_cons, List.prod_cons, chineseRemainderOfList] have : Coprime (s i) (l.map s).prod := by simp only [coprime_list_prod_right_iff, List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro j hj exact (List.pairwise_cons.mp co).1 j hj exact chineseRemainder_modEq_unique this (hz i (List.mem_cons_self _ _)) (ih co.of_cons (fun j hj => hz j (List.mem_cons_of_mem _ hj))) theorem chineseRemainderOfList_perm {l l' : List ι} (hl : l.Perm l') (hs : ∀ i ∈ l, s i ≠ 0) (co : l.Pairwise (Coprime on s)) : (chineseRemainderOfList a s l co : ℕ) = chineseRemainderOfList a s l' (co.perm hl coprime_comm.mpr) := by let z := chineseRemainderOfList a s l' (co.perm hl coprime_comm.mpr) have hlp : (l.map s).prod = (l'.map s).prod := List.Perm.prod_eq (List.Perm.map s hl) exact (chineseRemainderOfList_modEq_unique a s l co (z := z) (fun i hi => z.prop i (hl.symm.mem_iff.mpr hi))).symm.eq_of_lt_of_lt (chineseRemainderOfList_lt_prod _ _ _ _ hs) (by rw [hlp] exact chineseRemainderOfList_lt_prod _ _ _ _ (by simpa [List.Perm.mem_iff hl.symm] using hs)) /-- The natural number less than `(m.map s).prod` congruent to `a i` mod `s i` for all `i ∈ m`. -/ def chineseRemainderOfMultiset {m : Multiset ι} : m.Nodup → (∀ i ∈ m, s i ≠ 0) → Set.Pairwise {x | x ∈ m} (Coprime on s) → { k // ∀ i ∈ m, k ≡ a i [MOD s i] } := Quotient.recOn m (fun l nod _ co => chineseRemainderOfList a s l (List.Nodup.pairwise_of_forall_ne nod co)) (fun l l' (pp : l.Perm l') ↦ funext fun nod' : l'.Nodup => have nod : l.Nodup := pp.symm.nodup_iff.mp nod' funext fun hs' : ∀ i ∈ l', s i ≠ 0 => have hs : ∀ i ∈ l, s i ≠ 0 := by simpa [List.Perm.mem_iff pp] using hs' funext fun co' : Set.Pairwise {x | x ∈ l'} (Coprime on s) => have co : Set.Pairwise {x | x ∈ l} (Coprime on s) := by simpa [List.Perm.mem_iff pp] using co' have lco : l.Pairwise (Coprime on s) := List.Nodup.pairwise_of_forall_ne nod co have : ∀ {m' e nod'' hs'' co''}, @Eq.ndrec (Multiset ι) l (fun m ↦ m.Nodup → (∀ i ∈ m, s i ≠ 0) → Set.Pairwise {x | x ∈ m} (Coprime on s) → { k // ∀ i ∈ m, k ≡ a i [MOD s i] }) (fun nod _ co ↦ chineseRemainderOfList a s l (List.Nodup.pairwise_of_forall_ne nod co)) m' e nod'' hs'' co'' = (chineseRemainderOfList a s l lco : ℕ) := by rintro _ rfl _ _ _; rfl by ext; exact this.trans <| chineseRemainderOfList_perm a s pp hs lco)
Mathlib/Data/Nat/ChineseRemainder.lean
145
151
theorem chineseRemainderOfMultiset_lt_prod {m : Multiset ι} (nod : m.Nodup) (hs : ∀ i ∈ m, s i ≠ 0) (pp : Set.Pairwise {x | x ∈ m} (Coprime on s)) : chineseRemainderOfMultiset a s nod hs pp < (m.map s).prod := by
induction' m using Quot.ind with l unfold chineseRemainderOfMultiset; simp exact chineseRemainderOfList_lt_prod a s l (List.Nodup.pairwise_of_forall_ne nod pp) (by simpa using hs)
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import Mathlib.Data.Set.Prod import Mathlib.Logic.Function.Conjugate #align_import data.set.function from "leanprover-community/mathlib"@"996b0ff959da753a555053a480f36e5f264d4207" /-! # Functions over sets ## Main definitions ### Predicate * `Set.EqOn f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `Set.MapsTo f s t` : `f` sends every point of `s` to a point of `t`; * `Set.InjOn f s` : restriction of `f` to `s` is injective; * `Set.SurjOn f s t` : every point in `s` has a preimage in `s`; * `Set.BijOn f s t` : `f` is a bijection between `s` and `t`; * `Set.LeftInvOn f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `Set.RightInvOn f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `Set.InvOn f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `Set.LeftInvOn f' f s` and `Set.RightInvOn f' f t`. ### Functions * `Set.restrict f s` : restrict the domain of `f` to the set `s`; * `Set.codRestrict f s h` : given `h : ∀ x, f x ∈ s`, restrict the codomain of `f` to the set `s`; * `Set.MapsTo.restrict f s t h`: given `h : MapsTo f s t`, restrict the domain of `f` to `s` and the codomain to `t`. -/ variable {α β γ : Type*} {ι : Sort*} {π : α → Type*} open Equiv Equiv.Perm Function namespace Set /-! ### Restrict -/ section restrict /-- Restrict domain of a function `f` to a set `s`. Same as `Subtype.restrict` but this version takes an argument `↥s` instead of `Subtype s`. -/ def restrict (s : Set α) (f : ∀ a : α, π a) : ∀ a : s, π a := fun x => f x #align set.restrict Set.restrict theorem restrict_eq (f : α → β) (s : Set α) : s.restrict f = f ∘ Subtype.val := rfl #align set.restrict_eq Set.restrict_eq @[simp] theorem restrict_apply (f : α → β) (s : Set α) (x : s) : s.restrict f x = f x := rfl #align set.restrict_apply Set.restrict_apply theorem restrict_eq_iff {f : ∀ a, π a} {s : Set α} {g : ∀ a : s, π a} : restrict s f = g ↔ ∀ (a) (ha : a ∈ s), f a = g ⟨a, ha⟩ := funext_iff.trans Subtype.forall #align set.restrict_eq_iff Set.restrict_eq_iff theorem eq_restrict_iff {s : Set α} {f : ∀ a : s, π a} {g : ∀ a, π a} : f = restrict s g ↔ ∀ (a) (ha : a ∈ s), f ⟨a, ha⟩ = g a := funext_iff.trans Subtype.forall #align set.eq_restrict_iff Set.eq_restrict_iff @[simp] theorem range_restrict (f : α → β) (s : Set α) : Set.range (s.restrict f) = f '' s := (range_comp _ _).trans <| congr_arg (f '' ·) Subtype.range_coe #align set.range_restrict Set.range_restrict theorem image_restrict (f : α → β) (s t : Set α) : s.restrict f '' (Subtype.val ⁻¹' t) = f '' (t ∩ s) := by rw [restrict_eq, image_comp, image_preimage_eq_inter_range, Subtype.range_coe] #align set.image_restrict Set.image_restrict @[simp] theorem restrict_dite {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (s.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : s => f a a.2) := funext fun a => dif_pos a.2 #align set.restrict_dite Set.restrict_dite @[simp] theorem restrict_dite_compl {s : Set α} [∀ x, Decidable (x ∈ s)] (f : ∀ a ∈ s, β) (g : ∀ a ∉ s, β) : (sᶜ.restrict fun a => if h : a ∈ s then f a h else g a h) = (fun a : (sᶜ : Set α) => g a a.2) := funext fun a => dif_neg a.2 #align set.restrict_dite_compl Set.restrict_dite_compl @[simp] theorem restrict_ite (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (s.restrict fun a => if a ∈ s then f a else g a) = s.restrict f := restrict_dite _ _ #align set.restrict_ite Set.restrict_ite @[simp] theorem restrict_ite_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : (sᶜ.restrict fun a => if a ∈ s then f a else g a) = sᶜ.restrict g := restrict_dite_compl _ _ #align set.restrict_ite_compl Set.restrict_ite_compl @[simp] theorem restrict_piecewise (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : s.restrict (piecewise s f g) = s.restrict f := restrict_ite _ _ _ #align set.restrict_piecewise Set.restrict_piecewise @[simp] theorem restrict_piecewise_compl (f g : α → β) (s : Set α) [∀ x, Decidable (x ∈ s)] : sᶜ.restrict (piecewise s f g) = sᶜ.restrict g := restrict_ite_compl _ _ _ #align set.restrict_piecewise_compl Set.restrict_piecewise_compl theorem restrict_extend_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f).restrict (extend f g g') = fun x => g x.coe_prop.choose := by classical exact restrict_dite _ _ #align set.restrict_extend_range Set.restrict_extend_range @[simp] theorem restrict_extend_compl_range (f : α → β) (g : α → γ) (g' : β → γ) : (range f)ᶜ.restrict (extend f g g') = g' ∘ Subtype.val := by classical exact restrict_dite_compl _ _ #align set.restrict_extend_compl_range Set.restrict_extend_compl_range theorem range_extend_subset (f : α → β) (g : α → γ) (g' : β → γ) : range (extend f g g') ⊆ range g ∪ g' '' (range f)ᶜ := by classical rintro _ ⟨y, rfl⟩ rw [extend_def] split_ifs with h exacts [Or.inl (mem_range_self _), Or.inr (mem_image_of_mem _ h)] #align set.range_extend_subset Set.range_extend_subset theorem range_extend {f : α → β} (hf : Injective f) (g : α → γ) (g' : β → γ) : range (extend f g g') = range g ∪ g' '' (range f)ᶜ := by refine (range_extend_subset _ _ _).antisymm ?_ rintro z (⟨x, rfl⟩ | ⟨y, hy, rfl⟩) exacts [⟨f x, hf.extend_apply _ _ _⟩, ⟨y, extend_apply' _ _ _ hy⟩] #align set.range_extend Set.range_extend /-- Restrict codomain of a function `f` to a set `s`. Same as `Subtype.coind` but this version has codomain `↥s` instead of `Subtype s`. -/ def codRestrict (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) : ι → s := fun x => ⟨f x, h x⟩ #align set.cod_restrict Set.codRestrict @[simp] theorem val_codRestrict_apply (f : ι → α) (s : Set α) (h : ∀ x, f x ∈ s) (x : ι) : (codRestrict f s h x : α) = f x := rfl #align set.coe_cod_restrict_apply Set.val_codRestrict_apply @[simp] theorem restrict_comp_codRestrict {f : ι → α} {g : α → β} {b : Set α} (h : ∀ x, f x ∈ b) : b.restrict g ∘ b.codRestrict f h = g ∘ f := rfl #align set.restrict_comp_cod_restrict Set.restrict_comp_codRestrict @[simp] theorem injective_codRestrict {f : ι → α} {s : Set α} (h : ∀ x, f x ∈ s) : Injective (codRestrict f s h) ↔ Injective f := by simp only [Injective, Subtype.ext_iff, val_codRestrict_apply] #align set.injective_cod_restrict Set.injective_codRestrict alias ⟨_, _root_.Function.Injective.codRestrict⟩ := injective_codRestrict #align function.injective.cod_restrict Function.Injective.codRestrict end restrict /-! ### Equality on a set -/ section equality variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} @[simp] theorem eqOn_empty (f₁ f₂ : α → β) : EqOn f₁ f₂ ∅ := fun _ => False.elim #align set.eq_on_empty Set.eqOn_empty @[simp] theorem eqOn_singleton : Set.EqOn f₁ f₂ {a} ↔ f₁ a = f₂ a := by simp [Set.EqOn] #align set.eq_on_singleton Set.eqOn_singleton @[simp] theorem eqOn_univ (f₁ f₂ : α → β) : EqOn f₁ f₂ univ ↔ f₁ = f₂ := by simp [EqOn, funext_iff] @[simp] theorem restrict_eq_restrict_iff : restrict s f₁ = restrict s f₂ ↔ EqOn f₁ f₂ s := restrict_eq_iff #align set.restrict_eq_restrict_iff Set.restrict_eq_restrict_iff @[symm] theorem EqOn.symm (h : EqOn f₁ f₂ s) : EqOn f₂ f₁ s := fun _ hx => (h hx).symm #align set.eq_on.symm Set.EqOn.symm theorem eqOn_comm : EqOn f₁ f₂ s ↔ EqOn f₂ f₁ s := ⟨EqOn.symm, EqOn.symm⟩ #align set.eq_on_comm Set.eqOn_comm -- This can not be tagged as `@[refl]` with the current argument order. -- See note below at `EqOn.trans`. theorem eqOn_refl (f : α → β) (s : Set α) : EqOn f f s := fun _ _ => rfl #align set.eq_on_refl Set.eqOn_refl -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in mathlib4#7014 will reject this attribute. -- It can be restored by changing the argument order from `EqOn f₁ f₂ s` to `EqOn s f₁ f₂`. -- This change will be made separately: [zulip](https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Reordering.20arguments.20of.20.60Set.2EEqOn.60/near/390467581). theorem EqOn.trans (h₁ : EqOn f₁ f₂ s) (h₂ : EqOn f₂ f₃ s) : EqOn f₁ f₃ s := fun _ hx => (h₁ hx).trans (h₂ hx) #align set.eq_on.trans Set.EqOn.trans theorem EqOn.image_eq (heq : EqOn f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq #align set.eq_on.image_eq Set.EqOn.image_eq /-- Variant of `EqOn.image_eq`, for one function being the identity. -/ theorem EqOn.image_eq_self {f : α → α} (h : Set.EqOn f id s) : f '' s = s := by rw [h.image_eq, image_id] theorem EqOn.inter_preimage_eq (heq : EqOn f₁ f₂ s) (t : Set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext fun x => and_congr_right_iff.2 fun hx => by rw [mem_preimage, mem_preimage, heq hx] #align set.eq_on.inter_preimage_eq Set.EqOn.inter_preimage_eq theorem EqOn.mono (hs : s₁ ⊆ s₂) (hf : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ s₁ := fun _ hx => hf (hs hx) #align set.eq_on.mono Set.EqOn.mono @[simp] theorem eqOn_union : EqOn f₁ f₂ (s₁ ∪ s₂) ↔ EqOn f₁ f₂ s₁ ∧ EqOn f₁ f₂ s₂ := forall₂_or_left #align set.eq_on_union Set.eqOn_union theorem EqOn.union (h₁ : EqOn f₁ f₂ s₁) (h₂ : EqOn f₁ f₂ s₂) : EqOn f₁ f₂ (s₁ ∪ s₂) := eqOn_union.2 ⟨h₁, h₂⟩ #align set.eq_on.union Set.EqOn.union theorem EqOn.comp_left (h : s.EqOn f₁ f₂) : s.EqOn (g ∘ f₁) (g ∘ f₂) := fun _ ha => congr_arg _ <| h ha #align set.eq_on.comp_left Set.EqOn.comp_left @[simp] theorem eqOn_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} : EqOn g₁ g₂ (range f) ↔ g₁ ∘ f = g₂ ∘ f := forall_mem_range.trans <| funext_iff.symm #align set.eq_on_range Set.eqOn_range alias ⟨EqOn.comp_eq, _⟩ := eqOn_range #align set.eq_on.comp_eq Set.EqOn.comp_eq end equality /-! ### Congruence lemmas for monotonicity and antitonicity -/ section Order variable {s : Set α} {f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.congr (h₁ : MonotoneOn f₁ s) (h : s.EqOn f₁ f₂) : MonotoneOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align monotone_on.congr MonotoneOn.congr theorem _root_.AntitoneOn.congr (h₁ : AntitoneOn f₁ s) (h : s.EqOn f₁ f₂) : AntitoneOn f₂ s := h₁.dual_right.congr h #align antitone_on.congr AntitoneOn.congr theorem _root_.StrictMonoOn.congr (h₁ : StrictMonoOn f₁ s) (h : s.EqOn f₁ f₂) : StrictMonoOn f₂ s := by intro a ha b hb hab rw [← h ha, ← h hb] exact h₁ ha hb hab #align strict_mono_on.congr StrictMonoOn.congr theorem _root_.StrictAntiOn.congr (h₁ : StrictAntiOn f₁ s) (h : s.EqOn f₁ f₂) : StrictAntiOn f₂ s := h₁.dual_right.congr h #align strict_anti_on.congr StrictAntiOn.congr theorem EqOn.congr_monotoneOn (h : s.EqOn f₁ f₂) : MonotoneOn f₁ s ↔ MonotoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_monotone_on Set.EqOn.congr_monotoneOn theorem EqOn.congr_antitoneOn (h : s.EqOn f₁ f₂) : AntitoneOn f₁ s ↔ AntitoneOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_antitone_on Set.EqOn.congr_antitoneOn theorem EqOn.congr_strictMonoOn (h : s.EqOn f₁ f₂) : StrictMonoOn f₁ s ↔ StrictMonoOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_mono_on Set.EqOn.congr_strictMonoOn theorem EqOn.congr_strictAntiOn (h : s.EqOn f₁ f₂) : StrictAntiOn f₁ s ↔ StrictAntiOn f₂ s := ⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩ #align set.eq_on.congr_strict_anti_on Set.EqOn.congr_strictAntiOn end Order /-! ### Monotonicity lemmas-/ section Mono variable {s s₁ s₂ : Set α} {f f₁ f₂ : α → β} [Preorder α] [Preorder β] theorem _root_.MonotoneOn.mono (h : MonotoneOn f s) (h' : s₂ ⊆ s) : MonotoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align monotone_on.mono MonotoneOn.mono theorem _root_.AntitoneOn.mono (h : AntitoneOn f s) (h' : s₂ ⊆ s) : AntitoneOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align antitone_on.mono AntitoneOn.mono theorem _root_.StrictMonoOn.mono (h : StrictMonoOn f s) (h' : s₂ ⊆ s) : StrictMonoOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_mono_on.mono StrictMonoOn.mono theorem _root_.StrictAntiOn.mono (h : StrictAntiOn f s) (h' : s₂ ⊆ s) : StrictAntiOn f s₂ := fun _ hx _ hy => h (h' hx) (h' hy) #align strict_anti_on.mono StrictAntiOn.mono protected theorem _root_.MonotoneOn.monotone (h : MonotoneOn f s) : Monotone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align monotone_on.monotone MonotoneOn.monotone protected theorem _root_.AntitoneOn.monotone (h : AntitoneOn f s) : Antitone (f ∘ Subtype.val : s → β) := fun x y hle => h x.coe_prop y.coe_prop hle #align antitone_on.monotone AntitoneOn.monotone protected theorem _root_.StrictMonoOn.strictMono (h : StrictMonoOn f s) : StrictMono (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_mono_on.strict_mono StrictMonoOn.strictMono protected theorem _root_.StrictAntiOn.strictAnti (h : StrictAntiOn f s) : StrictAnti (f ∘ Subtype.val : s → β) := fun x y hlt => h x.coe_prop y.coe_prop hlt #align strict_anti_on.strict_anti StrictAntiOn.strictAnti end Mono variable {s s₁ s₂ : Set α} {t t₁ t₂ : Set β} {p : Set γ} {f f₁ f₂ f₃ : α → β} {g g₁ g₂ : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} {a : α} {b : β} section MapsTo theorem MapsTo.restrict_commutes (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : Subtype.val ∘ h.restrict f s t = f ∘ Subtype.val := rfl @[simp] theorem MapsTo.val_restrict_apply (h : MapsTo f s t) (x : s) : (h.restrict f s t x : β) = f x := rfl #align set.maps_to.coe_restrict_apply Set.MapsTo.val_restrict_apply theorem MapsTo.coe_iterate_restrict {f : α → α} (h : MapsTo f s s) (x : s) (k : ℕ) : h.restrict^[k] x = f^[k] x := by induction' k with k ih; · simp simp only [iterate_succ', comp_apply, val_restrict_apply, ih] /-- Restricting the domain and then the codomain is the same as `MapsTo.restrict`. -/ @[simp] theorem codRestrict_restrict (h : ∀ x : s, f x ∈ t) : codRestrict (s.restrict f) t h = MapsTo.restrict f s t fun x hx => h ⟨x, hx⟩ := rfl #align set.cod_restrict_restrict Set.codRestrict_restrict /-- Reverse of `Set.codRestrict_restrict`. -/ theorem MapsTo.restrict_eq_codRestrict (h : MapsTo f s t) : h.restrict f s t = codRestrict (s.restrict f) t fun x => h x.2 := rfl #align set.maps_to.restrict_eq_cod_restrict Set.MapsTo.restrict_eq_codRestrict theorem MapsTo.coe_restrict (h : Set.MapsTo f s t) : Subtype.val ∘ h.restrict f s t = s.restrict f := rfl #align set.maps_to.coe_restrict Set.MapsTo.coe_restrict theorem MapsTo.range_restrict (f : α → β) (s : Set α) (t : Set β) (h : MapsTo f s t) : range (h.restrict f s t) = Subtype.val ⁻¹' (f '' s) := Set.range_subtype_map f h #align set.maps_to.range_restrict Set.MapsTo.range_restrict theorem mapsTo_iff_exists_map_subtype : MapsTo f s t ↔ ∃ g : s → t, ∀ x : s, f x = g x := ⟨fun h => ⟨h.restrict f s t, fun _ => rfl⟩, fun ⟨g, hg⟩ x hx => by erw [hg ⟨x, hx⟩] apply Subtype.coe_prop⟩ #align set.maps_to_iff_exists_map_subtype Set.mapsTo_iff_exists_map_subtype theorem mapsTo' : MapsTo f s t ↔ f '' s ⊆ t := image_subset_iff.symm #align set.maps_to' Set.mapsTo' theorem mapsTo_prod_map_diagonal : MapsTo (Prod.map f f) (diagonal α) (diagonal β) := diagonal_subset_iff.2 fun _ => rfl #align set.maps_to_prod_map_diagonal Set.mapsTo_prod_map_diagonal theorem MapsTo.subset_preimage {f : α → β} {s : Set α} {t : Set β} (hf : MapsTo f s t) : s ⊆ f ⁻¹' t := hf #align set.maps_to.subset_preimage Set.MapsTo.subset_preimage @[simp] theorem mapsTo_singleton {x : α} : MapsTo f {x} t ↔ f x ∈ t := singleton_subset_iff #align set.maps_to_singleton Set.mapsTo_singleton theorem mapsTo_empty (f : α → β) (t : Set β) : MapsTo f ∅ t := empty_subset _ #align set.maps_to_empty Set.mapsTo_empty @[simp] theorem mapsTo_empty_iff : MapsTo f s ∅ ↔ s = ∅ := by simp [mapsTo', subset_empty_iff] /-- If `f` maps `s` to `t` and `s` is non-empty, `t` is non-empty. -/ theorem MapsTo.nonempty (h : MapsTo f s t) (hs : s.Nonempty) : t.Nonempty := (hs.image f).mono (mapsTo'.mp h) theorem MapsTo.image_subset (h : MapsTo f s t) : f '' s ⊆ t := mapsTo'.1 h #align set.maps_to.image_subset Set.MapsTo.image_subset theorem MapsTo.congr (h₁ : MapsTo f₁ s t) (h : EqOn f₁ f₂ s) : MapsTo f₂ s t := fun _ hx => h hx ▸ h₁ hx #align set.maps_to.congr Set.MapsTo.congr theorem EqOn.comp_right (hg : t.EqOn g₁ g₂) (hf : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) := fun _ ha => hg <| hf ha #align set.eq_on.comp_right Set.EqOn.comp_right theorem EqOn.mapsTo_iff (H : EqOn f₁ f₂ s) : MapsTo f₁ s t ↔ MapsTo f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.maps_to_iff Set.EqOn.mapsTo_iff theorem MapsTo.comp (h₁ : MapsTo g t p) (h₂ : MapsTo f s t) : MapsTo (g ∘ f) s p := fun _ h => h₁ (h₂ h) #align set.maps_to.comp Set.MapsTo.comp theorem mapsTo_id (s : Set α) : MapsTo id s s := fun _ => id #align set.maps_to_id Set.mapsTo_id theorem MapsTo.iterate {f : α → α} {s : Set α} (h : MapsTo f s s) : ∀ n, MapsTo f^[n] s s | 0 => fun _ => id | n + 1 => (MapsTo.iterate h n).comp h #align set.maps_to.iterate Set.MapsTo.iterate theorem MapsTo.iterate_restrict {f : α → α} {s : Set α} (h : MapsTo f s s) (n : ℕ) : (h.restrict f s s)^[n] = (h.iterate n).restrict _ _ _ := by funext x rw [Subtype.ext_iff, MapsTo.val_restrict_apply] induction' n with n ihn generalizing x · rfl · simp [Nat.iterate, ihn] #align set.maps_to.iterate_restrict Set.MapsTo.iterate_restrict lemma mapsTo_of_subsingleton' [Subsingleton β] (f : α → β) (h : s.Nonempty → t.Nonempty) : MapsTo f s t := fun a ha ↦ Subsingleton.mem_iff_nonempty.2 <| h ⟨a, ha⟩ #align set.maps_to_of_subsingleton' Set.mapsTo_of_subsingleton' lemma mapsTo_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : MapsTo f s s := mapsTo_of_subsingleton' _ id #align set.maps_to_of_subsingleton Set.mapsTo_of_subsingleton theorem MapsTo.mono (hf : MapsTo f s₁ t₁) (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) : MapsTo f s₂ t₂ := fun _ hx => ht (hf <| hs hx) #align set.maps_to.mono Set.MapsTo.mono theorem MapsTo.mono_left (hf : MapsTo f s₁ t) (hs : s₂ ⊆ s₁) : MapsTo f s₂ t := fun _ hx => hf (hs hx) #align set.maps_to.mono_left Set.MapsTo.mono_left theorem MapsTo.mono_right (hf : MapsTo f s t₁) (ht : t₁ ⊆ t₂) : MapsTo f s t₂ := fun _ hx => ht (hf hx) #align set.maps_to.mono_right Set.MapsTo.mono_right theorem MapsTo.union_union (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∪ s₂) (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => Or.inl <| h₁ hx) fun hx => Or.inr <| h₂ hx #align set.maps_to.union_union Set.MapsTo.union_union theorem MapsTo.union (h₁ : MapsTo f s₁ t) (h₂ : MapsTo f s₂ t) : MapsTo f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ #align set.maps_to.union Set.MapsTo.union @[simp] theorem mapsTo_union : MapsTo f (s₁ ∪ s₂) t ↔ MapsTo f s₁ t ∧ MapsTo f s₂ t := ⟨fun h => ⟨h.mono subset_union_left (Subset.refl t), h.mono subset_union_right (Subset.refl t)⟩, fun h => h.1.union h.2⟩ #align set.maps_to_union Set.mapsTo_union theorem MapsTo.inter (h₁ : MapsTo f s t₁) (h₂ : MapsTo f s t₂) : MapsTo f s (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx, h₂ hx⟩ #align set.maps_to.inter Set.MapsTo.inter theorem MapsTo.inter_inter (h₁ : MapsTo f s₁ t₁) (h₂ : MapsTo f s₂ t₂) : MapsTo f (s₁ ∩ s₂) (t₁ ∩ t₂) := fun _ hx => ⟨h₁ hx.1, h₂ hx.2⟩ #align set.maps_to.inter_inter Set.MapsTo.inter_inter @[simp] theorem mapsTo_inter : MapsTo f s (t₁ ∩ t₂) ↔ MapsTo f s t₁ ∧ MapsTo f s t₂ := ⟨fun h => ⟨h.mono (Subset.refl s) inter_subset_left, h.mono (Subset.refl s) inter_subset_right⟩, fun h => h.1.inter h.2⟩ #align set.maps_to_inter Set.mapsTo_inter theorem mapsTo_univ (f : α → β) (s : Set α) : MapsTo f s univ := fun _ _ => trivial #align set.maps_to_univ Set.mapsTo_univ theorem mapsTo_range (f : α → β) (s : Set α) : MapsTo f s (range f) := (mapsTo_image f s).mono (Subset.refl s) (image_subset_range _ _) #align set.maps_to_range Set.mapsTo_range @[simp] theorem mapsTo_image_iff {f : α → β} {g : γ → α} {s : Set γ} {t : Set β} : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := ⟨fun h c hc => h ⟨c, hc, rfl⟩, fun h _ ⟨_, hc⟩ => hc.2 ▸ h hc.1⟩ #align set.maps_image_to Set.mapsTo_image_iff @[deprecated (since := "2023-12-25")] lemma maps_image_to (f : α → β) (g : γ → α) (s : Set γ) (t : Set β) : MapsTo f (g '' s) t ↔ MapsTo (f ∘ g) s t := mapsTo_image_iff lemma MapsTo.comp_left (g : β → γ) (hf : MapsTo f s t) : MapsTo (g ∘ f) s (g '' t) := fun x hx ↦ ⟨f x, hf hx, rfl⟩ #align set.maps_to.comp_left Set.MapsTo.comp_left lemma MapsTo.comp_right {s : Set β} {t : Set γ} (hg : MapsTo g s t) (f : α → β) : MapsTo (g ∘ f) (f ⁻¹' s) t := fun _ hx ↦ hg hx #align set.maps_to.comp_right Set.MapsTo.comp_right @[simp] lemma mapsTo_univ_iff : MapsTo f univ t ↔ ∀ x, f x ∈ t := ⟨fun h _ => h (mem_univ _), fun h x _ => h x⟩ @[deprecated (since := "2023-12-25")] theorem maps_univ_to (f : α → β) (s : Set β) : MapsTo f univ s ↔ ∀ a, f a ∈ s := mapsTo_univ_iff #align set.maps_univ_to Set.maps_univ_to @[simp] lemma mapsTo_range_iff {g : ι → α} : MapsTo f (range g) t ↔ ∀ i, f (g i) ∈ t := forall_mem_range @[deprecated mapsTo_range_iff (since := "2023-12-25")] theorem maps_range_to (f : α → β) (g : γ → α) (s : Set β) : MapsTo f (range g) s ↔ MapsTo (f ∘ g) univ s := by rw [← image_univ, mapsTo_image_iff] #align set.maps_range_to Set.maps_range_to theorem surjective_mapsTo_image_restrict (f : α → β) (s : Set α) : Surjective ((mapsTo_image f s).restrict f s (f '' s)) := fun ⟨_, x, hs, hxy⟩ => ⟨⟨x, hs⟩, Subtype.ext hxy⟩ #align set.surjective_maps_to_image_restrict Set.surjective_mapsTo_image_restrict theorem MapsTo.mem_iff (h : MapsTo f s t) (hc : MapsTo f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨fun ht => by_contra fun hs => hc hs ht, fun hx => h hx⟩ #align set.maps_to.mem_iff Set.MapsTo.mem_iff end MapsTo /-! ### Restriction onto preimage -/ section variable (t) variable (f s) in theorem image_restrictPreimage : t.restrictPreimage f '' (Subtype.val ⁻¹' s) = Subtype.val ⁻¹' (f '' s) := by delta Set.restrictPreimage rw [← (Subtype.coe_injective).image_injective.eq_iff, ← image_comp, MapsTo.restrict_commutes, image_comp, Subtype.image_preimage_coe, Subtype.image_preimage_coe, image_preimage_inter] variable (f) in theorem range_restrictPreimage : range (t.restrictPreimage f) = Subtype.val ⁻¹' range f := by simp only [← image_univ, ← image_restrictPreimage, preimage_univ] #align set.range_restrict_preimage Set.range_restrictPreimage variable {U : ι → Set β} lemma restrictPreimage_injective (hf : Injective f) : Injective (t.restrictPreimage f) := fun _ _ e => Subtype.coe_injective <| hf <| Subtype.mk.inj e #align set.restrict_preimage_injective Set.restrictPreimage_injective lemma restrictPreimage_surjective (hf : Surjective f) : Surjective (t.restrictPreimage f) := fun x => ⟨⟨_, ((hf x).choose_spec.symm ▸ x.2 : _ ∈ t)⟩, Subtype.ext (hf x).choose_spec⟩ #align set.restrict_preimage_surjective Set.restrictPreimage_surjective lemma restrictPreimage_bijective (hf : Bijective f) : Bijective (t.restrictPreimage f) := ⟨t.restrictPreimage_injective hf.1, t.restrictPreimage_surjective hf.2⟩ #align set.restrict_preimage_bijective Set.restrictPreimage_bijective alias _root_.Function.Injective.restrictPreimage := Set.restrictPreimage_injective alias _root_.Function.Surjective.restrictPreimage := Set.restrictPreimage_surjective alias _root_.Function.Bijective.restrictPreimage := Set.restrictPreimage_bijective #align function.bijective.restrict_preimage Function.Bijective.restrictPreimage #align function.surjective.restrict_preimage Function.Surjective.restrictPreimage #align function.injective.restrict_preimage Function.Injective.restrictPreimage end /-! ### Injectivity on a set -/ section injOn theorem Subsingleton.injOn (hs : s.Subsingleton) (f : α → β) : InjOn f s := fun _ hx _ hy _ => hs hx hy #align set.subsingleton.inj_on Set.Subsingleton.injOn @[simp] theorem injOn_empty (f : α → β) : InjOn f ∅ := subsingleton_empty.injOn f #align set.inj_on_empty Set.injOn_empty @[simp] theorem injOn_singleton (f : α → β) (a : α) : InjOn f {a} := subsingleton_singleton.injOn f #align set.inj_on_singleton Set.injOn_singleton @[simp] lemma injOn_pair {b : α} : InjOn f {a, b} ↔ f a = f b → a = b := by unfold InjOn; aesop theorem InjOn.eq_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, fun h => h ▸ rfl⟩ #align set.inj_on.eq_iff Set.InjOn.eq_iff theorem InjOn.ne_iff {x y} (h : InjOn f s) (hx : x ∈ s) (hy : y ∈ s) : f x ≠ f y ↔ x ≠ y := (h.eq_iff hx hy).not #align set.inj_on.ne_iff Set.InjOn.ne_iff alias ⟨_, InjOn.ne⟩ := InjOn.ne_iff #align set.inj_on.ne Set.InjOn.ne theorem InjOn.congr (h₁ : InjOn f₁ s) (h : EqOn f₁ f₂ s) : InjOn f₂ s := fun _ hx _ hy => h hx ▸ h hy ▸ h₁ hx hy #align set.inj_on.congr Set.InjOn.congr theorem EqOn.injOn_iff (H : EqOn f₁ f₂ s) : InjOn f₁ s ↔ InjOn f₂ s := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.inj_on_iff Set.EqOn.injOn_iff theorem InjOn.mono (h : s₁ ⊆ s₂) (ht : InjOn f s₂) : InjOn f s₁ := fun _ hx _ hy H => ht (h hx) (h hy) H #align set.inj_on.mono Set.InjOn.mono theorem injOn_union (h : Disjoint s₁ s₂) : InjOn f (s₁ ∪ s₂) ↔ InjOn f s₁ ∧ InjOn f s₂ ∧ ∀ x ∈ s₁, ∀ y ∈ s₂, f x ≠ f y := by refine ⟨fun H => ⟨H.mono subset_union_left, H.mono subset_union_right, ?_⟩, ?_⟩ · intro x hx y hy hxy obtain rfl : x = y := H (Or.inl hx) (Or.inr hy) hxy exact h.le_bot ⟨hx, hy⟩ · rintro ⟨h₁, h₂, h₁₂⟩ rintro x (hx | hx) y (hy | hy) hxy exacts [h₁ hx hy hxy, (h₁₂ _ hx _ hy hxy).elim, (h₁₂ _ hy _ hx hxy.symm).elim, h₂ hx hy hxy] #align set.inj_on_union Set.injOn_union theorem injOn_insert {f : α → β} {s : Set α} {a : α} (has : a ∉ s) : Set.InjOn f (insert a s) ↔ Set.InjOn f s ∧ f a ∉ f '' s := by rw [← union_singleton, injOn_union (disjoint_singleton_right.2 has)] simp #align set.inj_on_insert Set.injOn_insert theorem injective_iff_injOn_univ : Injective f ↔ InjOn f univ := ⟨fun h _ _ _ _ hxy => h hxy, fun h _ _ heq => h trivial trivial heq⟩ #align set.injective_iff_inj_on_univ Set.injective_iff_injOn_univ theorem injOn_of_injective (h : Injective f) {s : Set α} : InjOn f s := fun _ _ _ _ hxy => h hxy #align set.inj_on_of_injective Set.injOn_of_injective alias _root_.Function.Injective.injOn := injOn_of_injective #align function.injective.inj_on Function.Injective.injOn -- A specialization of `injOn_of_injective` for `Subtype.val`. theorem injOn_subtype_val {s : Set { x // p x }} : Set.InjOn Subtype.val s := Subtype.coe_injective.injOn lemma injOn_id (s : Set α) : InjOn id s := injective_id.injOn #align set.inj_on_id Set.injOn_id theorem InjOn.comp (hg : InjOn g t) (hf : InjOn f s) (h : MapsTo f s t) : InjOn (g ∘ f) s := fun _ hx _ hy heq => hf hx hy <| hg (h hx) (h hy) heq #align set.inj_on.comp Set.InjOn.comp lemma InjOn.image_of_comp (h : InjOn (g ∘ f) s) : InjOn g (f '' s) := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy heq ↦ congr_arg f <| h hx hy heq lemma InjOn.iterate {f : α → α} {s : Set α} (h : InjOn f s) (hf : MapsTo f s s) : ∀ n, InjOn f^[n] s | 0 => injOn_id _ | (n + 1) => (h.iterate hf n).comp h hf #align set.inj_on.iterate Set.InjOn.iterate lemma injOn_of_subsingleton [Subsingleton α] (f : α → β) (s : Set α) : InjOn f s := (injective_of_subsingleton _).injOn #align set.inj_on_of_subsingleton Set.injOn_of_subsingleton theorem _root_.Function.Injective.injOn_range (h : Injective (g ∘ f)) : InjOn g (range f) := by rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ H exact congr_arg f (h H) #align function.injective.inj_on_range Function.Injective.injOn_range theorem injOn_iff_injective : InjOn f s ↔ Injective (s.restrict f) := ⟨fun H a b h => Subtype.eq <| H a.2 b.2 h, fun H a as b bs h => congr_arg Subtype.val <| @H ⟨a, as⟩ ⟨b, bs⟩ h⟩ #align set.inj_on_iff_injective Set.injOn_iff_injective alias ⟨InjOn.injective, _⟩ := Set.injOn_iff_injective #align set.inj_on.injective Set.InjOn.injective theorem MapsTo.restrict_inj (h : MapsTo f s t) : Injective (h.restrict f s t) ↔ InjOn f s := by rw [h.restrict_eq_codRestrict, injective_codRestrict, injOn_iff_injective] #align set.maps_to.restrict_inj Set.MapsTo.restrict_inj theorem exists_injOn_iff_injective [Nonempty β] : (∃ f : α → β, InjOn f s) ↔ ∃ f : s → β, Injective f := ⟨fun ⟨f, hf⟩ => ⟨_, hf.injective⟩, fun ⟨f, hf⟩ => by lift f to α → β using trivial exact ⟨f, injOn_iff_injective.2 hf⟩⟩ #align set.exists_inj_on_iff_injective Set.exists_injOn_iff_injective theorem injOn_preimage {B : Set (Set β)} (hB : B ⊆ 𝒫 range f) : InjOn (preimage f) B := fun s hs t ht hst => (preimage_eq_preimage' (@hB s hs) (@hB t ht)).1 hst -- Porting note: is there a semi-implicit variable problem with `⊆`? #align set.inj_on_preimage Set.injOn_preimage theorem InjOn.mem_of_mem_image {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨_, h', Eq⟩ := h₁ hf (hs h') h Eq ▸ h' #align set.inj_on.mem_of_mem_image Set.InjOn.mem_of_mem_image theorem InjOn.mem_image_iff {x} (hf : InjOn f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ #align set.inj_on.mem_image_iff Set.InjOn.mem_image_iff theorem InjOn.preimage_image_inter (hf : InjOn f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext fun _ => ⟨fun ⟨h₁, h₂⟩ => hf.mem_of_mem_image hs h₂ h₁, fun h => ⟨mem_image_of_mem _ h, hs h⟩⟩ #align set.inj_on.preimage_image_inter Set.InjOn.preimage_image_inter theorem EqOn.cancel_left (h : s.EqOn (g ∘ f₁) (g ∘ f₂)) (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn f₁ f₂ := fun _ ha => hg (hf₁ ha) (hf₂ ha) (h ha) #align set.eq_on.cancel_left Set.EqOn.cancel_left theorem InjOn.cancel_left (hg : t.InjOn g) (hf₁ : s.MapsTo f₁ t) (hf₂ : s.MapsTo f₂ t) : s.EqOn (g ∘ f₁) (g ∘ f₂) ↔ s.EqOn f₁ f₂ := ⟨fun h => h.cancel_left hg hf₁ hf₂, EqOn.comp_left⟩ #align set.inj_on.cancel_left Set.InjOn.cancel_left lemma InjOn.image_inter {s t u : Set α} (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : f '' (s ∩ t) = f '' s ∩ f '' t := by apply Subset.antisymm (image_inter_subset _ _ _) intro x ⟨⟨y, ys, hy⟩, ⟨z, zt, hz⟩⟩ have : y = z := by apply hf (hs ys) (ht zt) rwa [← hz] at hy rw [← this] at zt exact ⟨y, ⟨ys, zt⟩, hy⟩ #align set.inj_on.image_inter Set.InjOn.image_inter lemma InjOn.image (h : s.InjOn f) : s.powerset.InjOn (image f) := fun s₁ hs₁ s₂ hs₂ h' ↦ by rw [← h.preimage_image_inter hs₁, h', h.preimage_image_inter hs₂] theorem InjOn.image_eq_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ = f '' s₂ ↔ s₁ = s₂ := h.image.eq_iff h₁ h₂ lemma InjOn.image_subset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊆ f '' s₂ ↔ s₁ ⊆ s₂ := by refine' ⟨fun h' ↦ _, image_subset _⟩ rw [← h.preimage_image_inter h₁, ← h.preimage_image_inter h₂] exact inter_subset_inter_left _ (preimage_mono h') lemma InjOn.image_ssubset_image_iff (h : s.InjOn f) (h₁ : s₁ ⊆ s) (h₂ : s₂ ⊆ s) : f '' s₁ ⊂ f '' s₂ ↔ s₁ ⊂ s₂ := by simp_rw [ssubset_def, h.image_subset_image_iff h₁ h₂, h.image_subset_image_iff h₂ h₁] -- TODO: can this move to a better place? theorem _root_.Disjoint.image {s t u : Set α} {f : α → β} (h : Disjoint s t) (hf : u.InjOn f) (hs : s ⊆ u) (ht : t ⊆ u) : Disjoint (f '' s) (f '' t) := by rw [disjoint_iff_inter_eq_empty] at h ⊢ rw [← hf.image_inter hs ht, h, image_empty] #align disjoint.image Disjoint.image lemma InjOn.image_diff {t : Set α} (h : s.InjOn f) : f '' (s \ t) = f '' s \ f '' (s ∩ t) := by refine subset_antisymm (subset_diff.2 ⟨image_subset f diff_subset, ?_⟩) (diff_subset_iff.2 (by rw [← image_union, inter_union_diff])) exact Disjoint.image disjoint_sdiff_inter h diff_subset inter_subset_left lemma InjOn.image_diff_subset {f : α → β} {t : Set α} (h : InjOn f s) (hst : t ⊆ s) : f '' (s \ t) = f '' s \ f '' t := by rw [h.image_diff, inter_eq_self_of_subset_right hst] theorem InjOn.imageFactorization_injective (h : InjOn f s) : Injective (s.imageFactorization f) := fun ⟨x, hx⟩ ⟨y, hy⟩ h' ↦ by simpa [imageFactorization, h.eq_iff hx hy] using h' @[simp] theorem imageFactorization_injective_iff : Injective (s.imageFactorization f) ↔ InjOn f s := ⟨fun h x hx y hy _ ↦ by simpa using @h ⟨x, hx⟩ ⟨y, hy⟩ (by simpa [imageFactorization]), InjOn.imageFactorization_injective⟩ end injOn section graphOn @[simp] lemma graphOn_empty (f : α → β) : graphOn f ∅ = ∅ := image_empty _ @[simp] lemma graphOn_union (f : α → β) (s t : Set α) : graphOn f (s ∪ t) = graphOn f s ∪ graphOn f t := image_union .. @[simp] lemma graphOn_singleton (f : α → β) (x : α) : graphOn f {x} = {(x, f x)} := image_singleton .. @[simp] lemma graphOn_insert (f : α → β) (x : α) (s : Set α) : graphOn f (insert x s) = insert (x, f x) (graphOn f s) := image_insert_eq .. @[simp] lemma image_fst_graphOn (f : α → β) (s : Set α) : Prod.fst '' graphOn f s = s := by simp [graphOn, image_image] lemma exists_eq_graphOn_image_fst [Nonempty β] {s : Set (α × β)} : (∃ f : α → β, s = graphOn f (Prod.fst '' s)) ↔ InjOn Prod.fst s := by refine ⟨?_, fun h ↦ ?_⟩ · rintro ⟨f, hf⟩ rw [hf] exact InjOn.image_of_comp <| injOn_id _ · have : ∀ x ∈ Prod.fst '' s, ∃ y, (x, y) ∈ s := forall_mem_image.2 fun (x, y) h ↦ ⟨y, h⟩ choose! f hf using this rw [forall_mem_image] at hf use f rw [graphOn, image_image, EqOn.image_eq_self] exact fun x hx ↦ h (hf hx) hx rfl lemma exists_eq_graphOn [Nonempty β] {s : Set (α × β)} : (∃ f t, s = graphOn f t) ↔ InjOn Prod.fst s := .trans ⟨fun ⟨f, t, hs⟩ ↦ ⟨f, by rw [hs, image_fst_graphOn]⟩, fun ⟨f, hf⟩ ↦ ⟨f, _, hf⟩⟩ exists_eq_graphOn_image_fst end graphOn /-! ### Surjectivity on a set -/ section surjOn theorem SurjOn.subset_range (h : SurjOn f s t) : t ⊆ range f := Subset.trans h <| image_subset_range f s #align set.surj_on.subset_range Set.SurjOn.subset_range theorem surjOn_iff_exists_map_subtype : SurjOn f s t ↔ ∃ (t' : Set β) (g : s → t'), t ⊆ t' ∧ Surjective g ∧ ∀ x : s, f x = g x := ⟨fun h => ⟨_, (mapsTo_image f s).restrict f s _, h, surjective_mapsTo_image_restrict _ _, fun _ => rfl⟩, fun ⟨t', g, htt', hg, hfg⟩ y hy => let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ ⟨x, x.2, by rw [hfg, hx, Subtype.coe_mk]⟩⟩ #align set.surj_on_iff_exists_map_subtype Set.surjOn_iff_exists_map_subtype theorem surjOn_empty (f : α → β) (s : Set α) : SurjOn f s ∅ := empty_subset _ #align set.surj_on_empty Set.surjOn_empty @[simp] theorem surjOn_empty_iff : SurjOn f ∅ t ↔ t = ∅ := by simp [SurjOn, subset_empty_iff] @[simp] lemma surjOn_singleton : SurjOn f s {b} ↔ b ∈ f '' s := singleton_subset_iff #align set.surj_on_singleton Set.surjOn_singleton theorem surjOn_image (f : α → β) (s : Set α) : SurjOn f s (f '' s) := Subset.rfl #align set.surj_on_image Set.surjOn_image theorem SurjOn.comap_nonempty (h : SurjOn f s t) (ht : t.Nonempty) : s.Nonempty := (ht.mono h).of_image #align set.surj_on.comap_nonempty Set.SurjOn.comap_nonempty theorem SurjOn.congr (h : SurjOn f₁ s t) (H : EqOn f₁ f₂ s) : SurjOn f₂ s t := by rwa [SurjOn, ← H.image_eq] #align set.surj_on.congr Set.SurjOn.congr theorem EqOn.surjOn_iff (h : EqOn f₁ f₂ s) : SurjOn f₁ s t ↔ SurjOn f₂ s t := ⟨fun H => H.congr h, fun H => H.congr h.symm⟩ #align set.eq_on.surj_on_iff Set.EqOn.surjOn_iff theorem SurjOn.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : SurjOn f s₁ t₂) : SurjOn f s₂ t₁ := Subset.trans ht <| Subset.trans hf <| image_subset _ hs #align set.surj_on.mono Set.SurjOn.mono theorem SurjOn.union (h₁ : SurjOn f s t₁) (h₂ : SurjOn f s t₂) : SurjOn f s (t₁ ∪ t₂) := fun _ hx => hx.elim (fun hx => h₁ hx) fun hx => h₂ hx #align set.surj_on.union Set.SurjOn.union theorem SurjOn.union_union (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) : SurjOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono subset_union_left (Subset.refl _)).union (h₂.mono subset_union_right (Subset.refl _)) #align set.surj_on.union_union Set.SurjOn.union_union theorem SurjOn.inter_inter (h₁ : SurjOn f s₁ t₁) (h₂ : SurjOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := by intro y hy rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩ rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩ obtain rfl : x₁ = x₂ := h (Or.inl hx₁) (Or.inr hx₂) heq.symm exact mem_image_of_mem f ⟨hx₁, hx₂⟩ #align set.surj_on.inter_inter Set.SurjOn.inter_inter theorem SurjOn.inter (h₁ : SurjOn f s₁ t) (h₂ : SurjOn f s₂ t) (h : InjOn f (s₁ ∪ s₂)) : SurjOn f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h #align set.surj_on.inter Set.SurjOn.inter -- Porting note: Why does `simp` not call `refl` by itself? lemma surjOn_id (s : Set α) : SurjOn id s s := by simp [SurjOn, subset_rfl] #align set.surj_on_id Set.surjOn_id theorem SurjOn.comp (hg : SurjOn g t p) (hf : SurjOn f s t) : SurjOn (g ∘ f) s p := Subset.trans hg <| Subset.trans (image_subset g hf) <| image_comp g f s ▸ Subset.refl _ #align set.surj_on.comp Set.SurjOn.comp lemma SurjOn.iterate {f : α → α} {s : Set α} (h : SurjOn f s s) : ∀ n, SurjOn f^[n] s s | 0 => surjOn_id _ | (n + 1) => (h.iterate n).comp h #align set.surj_on.iterate Set.SurjOn.iterate lemma SurjOn.comp_left (hf : SurjOn f s t) (g : β → γ) : SurjOn (g ∘ f) s (g '' t) := by rw [SurjOn, image_comp g f]; exact image_subset _ hf #align set.surj_on.comp_left Set.SurjOn.comp_left lemma SurjOn.comp_right {s : Set β} {t : Set γ} (hf : Surjective f) (hg : SurjOn g s t) : SurjOn (g ∘ f) (f ⁻¹' s) t := by rwa [SurjOn, image_comp g f, image_preimage_eq _ hf] #align set.surj_on.comp_right Set.SurjOn.comp_right lemma surjOn_of_subsingleton' [Subsingleton β] (f : α → β) (h : t.Nonempty → s.Nonempty) : SurjOn f s t := fun _ ha ↦ Subsingleton.mem_iff_nonempty.2 <| (h ⟨_, ha⟩).image _ #align set.surj_on_of_subsingleton' Set.surjOn_of_subsingleton' lemma surjOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : SurjOn f s s := surjOn_of_subsingleton' _ id #align set.surj_on_of_subsingleton Set.surjOn_of_subsingleton theorem surjective_iff_surjOn_univ : Surjective f ↔ SurjOn f univ univ := by simp [Surjective, SurjOn, subset_def] #align set.surjective_iff_surj_on_univ Set.surjective_iff_surjOn_univ theorem surjOn_iff_surjective : SurjOn f s univ ↔ Surjective (s.restrict f) := ⟨fun H b => let ⟨a, as, e⟩ := @H b trivial ⟨⟨a, as⟩, e⟩, fun H b _ => let ⟨⟨a, as⟩, e⟩ := H b ⟨a, as, e⟩⟩ #align set.surj_on_iff_surjective Set.surjOn_iff_surjective @[simp] theorem MapsTo.restrict_surjective_iff (h : MapsTo f s t) : Surjective (MapsTo.restrict _ _ _ h) ↔ SurjOn f s t := by refine ⟨fun h' b hb ↦ ?_, fun h' ⟨b, hb⟩ ↦ ?_⟩ · obtain ⟨⟨a, ha⟩, ha'⟩ := h' ⟨b, hb⟩ replace ha' : f a = b := by simpa [Subtype.ext_iff] using ha' rw [← ha'] exact mem_image_of_mem f ha · obtain ⟨a, ha, rfl⟩ := h' hb exact ⟨⟨a, ha⟩, rfl⟩ theorem SurjOn.image_eq_of_mapsTo (h₁ : SurjOn f s t) (h₂ : MapsTo f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ #align set.surj_on.image_eq_of_maps_to Set.SurjOn.image_eq_of_mapsTo theorem image_eq_iff_surjOn_mapsTo : f '' s = t ↔ s.SurjOn f t ∧ s.MapsTo f t := by refine ⟨?_, fun h => h.1.image_eq_of_mapsTo h.2⟩ rintro rfl exact ⟨s.surjOn_image f, s.mapsTo_image f⟩ #align set.image_eq_iff_surj_on_maps_to Set.image_eq_iff_surjOn_mapsTo lemma SurjOn.image_preimage (h : Set.SurjOn f s t) (ht : t₁ ⊆ t) : f '' (f ⁻¹' t₁) = t₁ := image_preimage_eq_iff.2 fun _ hx ↦ mem_range_of_mem_image f s <| h <| ht hx theorem SurjOn.mapsTo_compl (h : SurjOn f s t) (h' : Injective f) : MapsTo f sᶜ tᶜ := fun _ hs ht => let ⟨_, hx', HEq⟩ := h ht hs <| h' HEq ▸ hx' #align set.surj_on.maps_to_compl Set.SurjOn.mapsTo_compl theorem MapsTo.surjOn_compl (h : MapsTo f s t) (h' : Surjective f) : SurjOn f sᶜ tᶜ := h'.forall.2 fun _ ht => (mem_image_of_mem _) fun hs => ht (h hs) #align set.maps_to.surj_on_compl Set.MapsTo.surjOn_compl theorem EqOn.cancel_right (hf : s.EqOn (g₁ ∘ f) (g₂ ∘ f)) (hf' : s.SurjOn f t) : t.EqOn g₁ g₂ := by intro b hb obtain ⟨a, ha, rfl⟩ := hf' hb exact hf ha #align set.eq_on.cancel_right Set.EqOn.cancel_right theorem SurjOn.cancel_right (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ t.EqOn g₁ g₂ := ⟨fun h => h.cancel_right hf, fun h => h.comp_right hf'⟩ #align set.surj_on.cancel_right Set.SurjOn.cancel_right theorem eqOn_comp_right_iff : s.EqOn (g₁ ∘ f) (g₂ ∘ f) ↔ (f '' s).EqOn g₁ g₂ := (s.surjOn_image f).cancel_right <| s.mapsTo_image f #align set.eq_on_comp_right_iff Set.eqOn_comp_right_iff theorem SurjOn.forall {p : β → Prop} (hf : s.SurjOn f t) (hf' : s.MapsTo f t) : (∀ y ∈ t, p y) ↔ (∀ x ∈ s, p (f x)) := ⟨fun H x hx ↦ H (f x) (hf' hx), fun H _y hy ↦ let ⟨x, hx, hxy⟩ := hf hy; hxy ▸ H x hx⟩ end surjOn /-! ### Bijectivity -/ section bijOn theorem BijOn.mapsTo (h : BijOn f s t) : MapsTo f s t := h.left #align set.bij_on.maps_to Set.BijOn.mapsTo theorem BijOn.injOn (h : BijOn f s t) : InjOn f s := h.right.left #align set.bij_on.inj_on Set.BijOn.injOn theorem BijOn.surjOn (h : BijOn f s t) : SurjOn f s t := h.right.right #align set.bij_on.surj_on Set.BijOn.surjOn theorem BijOn.mk (h₁ : MapsTo f s t) (h₂ : InjOn f s) (h₃ : SurjOn f s t) : BijOn f s t := ⟨h₁, h₂, h₃⟩ #align set.bij_on.mk Set.BijOn.mk theorem bijOn_empty (f : α → β) : BijOn f ∅ ∅ := ⟨mapsTo_empty f ∅, injOn_empty f, surjOn_empty f ∅⟩ #align set.bij_on_empty Set.bijOn_empty @[simp] theorem bijOn_empty_iff_left : BijOn f s ∅ ↔ s = ∅ := ⟨fun h ↦ by simpa using h.mapsTo, by rintro rfl; exact bijOn_empty f⟩ @[simp] theorem bijOn_empty_iff_right : BijOn f ∅ t ↔ t = ∅ := ⟨fun h ↦ by simpa using h.surjOn, by rintro rfl; exact bijOn_empty f⟩ @[simp] lemma bijOn_singleton : BijOn f {a} {b} ↔ f a = b := by simp [BijOn, eq_comm] #align set.bij_on_singleton Set.bijOn_singleton theorem BijOn.inter_mapsTo (h₁ : BijOn f s₁ t₁) (h₂ : MapsTo f s₂ t₂) (h₃ : s₁ ∩ f ⁻¹' t₂ ⊆ s₂) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂, h₁.injOn.mono inter_subset_left, fun _ hy => let ⟨x, hx, hxy⟩ := h₁.surjOn hy.1 ⟨x, ⟨hx, h₃ ⟨hx, hxy.symm.subst hy.2⟩⟩, hxy⟩⟩ #align set.bij_on.inter_maps_to Set.BijOn.inter_mapsTo theorem MapsTo.inter_bijOn (h₁ : MapsTo f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h₃ : s₂ ∩ f ⁻¹' t₁ ⊆ s₁) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := inter_comm s₂ s₁ ▸ inter_comm t₂ t₁ ▸ h₂.inter_mapsTo h₁ h₃ #align set.maps_to.inter_bij_on Set.MapsTo.inter_bijOn theorem BijOn.inter (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.mapsTo.inter_inter h₂.mapsTo, h₁.injOn.mono inter_subset_left, h₁.surjOn.inter_inter h₂.surjOn h⟩ #align set.bij_on.inter Set.BijOn.inter theorem BijOn.union (h₁ : BijOn f s₁ t₁) (h₂ : BijOn f s₂ t₂) (h : InjOn f (s₁ ∪ s₂)) : BijOn f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.mapsTo.union_union h₂.mapsTo, h, h₁.surjOn.union_union h₂.surjOn⟩ #align set.bij_on.union Set.BijOn.union theorem BijOn.subset_range (h : BijOn f s t) : t ⊆ range f := h.surjOn.subset_range #align set.bij_on.subset_range Set.BijOn.subset_range theorem InjOn.bijOn_image (h : InjOn f s) : BijOn f s (f '' s) := BijOn.mk (mapsTo_image f s) h (Subset.refl _) #align set.inj_on.bij_on_image Set.InjOn.bijOn_image theorem BijOn.congr (h₁ : BijOn f₁ s t) (h : EqOn f₁ f₂ s) : BijOn f₂ s t := BijOn.mk (h₁.mapsTo.congr h) (h₁.injOn.congr h) (h₁.surjOn.congr h) #align set.bij_on.congr Set.BijOn.congr theorem EqOn.bijOn_iff (H : EqOn f₁ f₂ s) : BijOn f₁ s t ↔ BijOn f₂ s t := ⟨fun h => h.congr H, fun h => h.congr H.symm⟩ #align set.eq_on.bij_on_iff Set.EqOn.bijOn_iff theorem BijOn.image_eq (h : BijOn f s t) : f '' s = t := h.surjOn.image_eq_of_mapsTo h.mapsTo #align set.bij_on.image_eq Set.BijOn.image_eq lemma BijOn.forall {p : β → Prop} (hf : BijOn f s t) : (∀ b ∈ t, p b) ↔ ∀ a ∈ s, p (f a) where mp h a ha := h _ $ hf.mapsTo ha mpr h b hb := by obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact h _ ha lemma BijOn.exists {p : β → Prop} (hf : BijOn f s t) : (∃ b ∈ t, p b) ↔ ∃ a ∈ s, p (f a) where mp := by rintro ⟨b, hb, h⟩; obtain ⟨a, ha, rfl⟩ := hf.surjOn hb; exact ⟨a, ha, h⟩ mpr := by rintro ⟨a, ha, h⟩; exact ⟨f a, hf.mapsTo ha, h⟩ lemma _root_.Equiv.image_eq_iff_bijOn (e : α ≃ β) : e '' s = t ↔ BijOn e s t := ⟨fun h ↦ ⟨(mapsTo_image e s).mono_right h.subset, e.injective.injOn, h ▸ surjOn_image e s⟩, BijOn.image_eq⟩ lemma bijOn_id (s : Set α) : BijOn id s s := ⟨s.mapsTo_id, s.injOn_id, s.surjOn_id⟩ #align set.bij_on_id Set.bijOn_id theorem BijOn.comp (hg : BijOn g t p) (hf : BijOn f s t) : BijOn (g ∘ f) s p := BijOn.mk (hg.mapsTo.comp hf.mapsTo) (hg.injOn.comp hf.injOn hf.mapsTo) (hg.surjOn.comp hf.surjOn) #align set.bij_on.comp Set.BijOn.comp lemma BijOn.iterate {f : α → α} {s : Set α} (h : BijOn f s s) : ∀ n, BijOn f^[n] s s | 0 => s.bijOn_id | (n + 1) => (h.iterate n).comp h #align set.bij_on.iterate Set.BijOn.iterate lemma bijOn_of_subsingleton' [Subsingleton α] [Subsingleton β] (f : α → β) (h : s.Nonempty ↔ t.Nonempty) : BijOn f s t := ⟨mapsTo_of_subsingleton' _ h.1, injOn_of_subsingleton _ _, surjOn_of_subsingleton' _ h.2⟩ #align set.bij_on_of_subsingleton' Set.bijOn_of_subsingleton' lemma bijOn_of_subsingleton [Subsingleton α] (f : α → α) (s : Set α) : BijOn f s s := bijOn_of_subsingleton' _ Iff.rfl #align set.bij_on_of_subsingleton Set.bijOn_of_subsingleton theorem BijOn.bijective (h : BijOn f s t) : Bijective (h.mapsTo.restrict f s t) := ⟨fun x y h' => Subtype.ext <| h.injOn x.2 y.2 <| Subtype.ext_iff.1 h', fun ⟨_, hy⟩ => let ⟨x, hx, hxy⟩ := h.surjOn hy ⟨⟨x, hx⟩, Subtype.eq hxy⟩⟩ #align set.bij_on.bijective Set.BijOn.bijective theorem bijective_iff_bijOn_univ : Bijective f ↔ BijOn f univ univ := Iff.intro (fun h => let ⟨inj, surj⟩ := h ⟨mapsTo_univ f _, inj.injOn, Iff.mp surjective_iff_surjOn_univ surj⟩) fun h => let ⟨_map, inj, surj⟩ := h ⟨Iff.mpr injective_iff_injOn_univ inj, Iff.mpr surjective_iff_surjOn_univ surj⟩ #align set.bijective_iff_bij_on_univ Set.bijective_iff_bijOn_univ alias ⟨_root_.Function.Bijective.bijOn_univ, _⟩ := bijective_iff_bijOn_univ #align function.bijective.bij_on_univ Function.Bijective.bijOn_univ theorem BijOn.compl (hst : BijOn f s t) (hf : Bijective f) : BijOn f sᶜ tᶜ := ⟨hst.surjOn.mapsTo_compl hf.1, hf.1.injOn, hst.mapsTo.surjOn_compl hf.2⟩ #align set.bij_on.compl Set.BijOn.compl theorem BijOn.subset_right {r : Set β} (hf : BijOn f s t) (hrt : r ⊆ t) : BijOn f (s ∩ f ⁻¹' r) r := by refine ⟨inter_subset_right, hf.injOn.mono inter_subset_left, fun x hx ↦ ?_⟩ obtain ⟨y, hy, rfl⟩ := hf.surjOn (hrt hx) exact ⟨y, ⟨hy, hx⟩, rfl⟩ theorem BijOn.subset_left {r : Set α} (hf : BijOn f s t) (hrs : r ⊆ s) : BijOn f r (f '' r) := (hf.injOn.mono hrs).bijOn_image end bijOn /-! ### left inverse -/ namespace LeftInvOn theorem eqOn (h : LeftInvOn f' f s) : EqOn (f' ∘ f) id s := h #align set.left_inv_on.eq_on Set.LeftInvOn.eqOn theorem eq (h : LeftInvOn f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx #align set.left_inv_on.eq Set.LeftInvOn.eq theorem congr_left (h₁ : LeftInvOn f₁' f s) {t : Set β} (h₁' : MapsTo f s t) (heq : EqOn f₁' f₂' t) : LeftInvOn f₂' f s := fun _ hx => heq (h₁' hx) ▸ h₁ hx #align set.left_inv_on.congr_left Set.LeftInvOn.congr_left theorem congr_right (h₁ : LeftInvOn f₁' f₁ s) (heq : EqOn f₁ f₂ s) : LeftInvOn f₁' f₂ s := fun _ hx => heq hx ▸ h₁ hx #align set.left_inv_on.congr_right Set.LeftInvOn.congr_right theorem injOn (h : LeftInvOn f₁' f s) : InjOn f s := fun x₁ h₁ x₂ h₂ heq => calc x₁ = f₁' (f x₁) := Eq.symm <| h h₁ _ = f₁' (f x₂) := congr_arg f₁' heq _ = x₂ := h h₂ #align set.left_inv_on.inj_on Set.LeftInvOn.injOn theorem surjOn (h : LeftInvOn f' f s) (hf : MapsTo f s t) : SurjOn f' t s := fun x hx => ⟨f x, hf hx, h hx⟩ #align set.left_inv_on.surj_on Set.LeftInvOn.surjOn theorem mapsTo (h : LeftInvOn f' f s) (hf : SurjOn f s t) : MapsTo f' t s := fun y hy => by let ⟨x, hs, hx⟩ := hf hy rwa [← hx, h hs] #align set.left_inv_on.maps_to Set.LeftInvOn.mapsTo lemma _root_.Set.leftInvOn_id (s : Set α) : LeftInvOn id id s := fun _ _ ↦ rfl #align set.left_inv_on_id Set.leftInvOn_id theorem comp (hf' : LeftInvOn f' f s) (hg' : LeftInvOn g' g t) (hf : MapsTo f s t) : LeftInvOn (f' ∘ g') (g ∘ f) s := fun x h => calc (f' ∘ g') ((g ∘ f) x) = f' (f x) := congr_arg f' (hg' (hf h)) _ = x := hf' h #align set.left_inv_on.comp Set.LeftInvOn.comp theorem mono (hf : LeftInvOn f' f s) (ht : s₁ ⊆ s) : LeftInvOn f' f s₁ := fun _ hx => hf (ht hx) #align set.left_inv_on.mono Set.LeftInvOn.mono theorem image_inter' (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := by apply Subset.antisymm · rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩ exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ · rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩ exact mem_image_of_mem _ ⟨by rwa [← hf h], h⟩ #align set.left_inv_on.image_inter' Set.LeftInvOn.image_inter' theorem image_inter (hf : LeftInvOn f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := by rw [hf.image_inter'] refine Subset.antisymm ?_ (inter_subset_inter_left _ (preimage_mono inter_subset_left)) rintro _ ⟨h₁, x, hx, rfl⟩; exact ⟨⟨h₁, by rwa [hf hx]⟩, mem_image_of_mem _ hx⟩ #align set.left_inv_on.image_inter Set.LeftInvOn.image_inter theorem image_image (hf : LeftInvOn f' f s) : f' '' (f '' s) = s := by rw [Set.image_image, image_congr hf, image_id'] #align set.left_inv_on.image_image Set.LeftInvOn.image_image theorem image_image' (hf : LeftInvOn f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image #align set.left_inv_on.image_image' Set.LeftInvOn.image_image' end LeftInvOn /-! ### Right inverse -/ section RightInvOn namespace RightInvOn theorem eqOn (h : RightInvOn f' f t) : EqOn (f ∘ f') id t := h #align set.right_inv_on.eq_on Set.RightInvOn.eqOn theorem eq (h : RightInvOn f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy #align set.right_inv_on.eq Set.RightInvOn.eq theorem _root_.Set.LeftInvOn.rightInvOn_image (h : LeftInvOn f' f s) : RightInvOn f' f (f '' s) := fun _y ⟨_x, hx, heq⟩ => heq ▸ (congr_arg f <| h.eq hx) #align set.left_inv_on.right_inv_on_image Set.LeftInvOn.rightInvOn_image theorem congr_left (h₁ : RightInvOn f₁' f t) (heq : EqOn f₁' f₂' t) : RightInvOn f₂' f t := h₁.congr_right heq #align set.right_inv_on.congr_left Set.RightInvOn.congr_left theorem congr_right (h₁ : RightInvOn f' f₁ t) (hg : MapsTo f' t s) (heq : EqOn f₁ f₂ s) : RightInvOn f' f₂ t := LeftInvOn.congr_left h₁ hg heq #align set.right_inv_on.congr_right Set.RightInvOn.congr_right theorem surjOn (hf : RightInvOn f' f t) (hf' : MapsTo f' t s) : SurjOn f s t := LeftInvOn.surjOn hf hf' #align set.right_inv_on.surj_on Set.RightInvOn.surjOn theorem mapsTo (h : RightInvOn f' f t) (hf : SurjOn f' t s) : MapsTo f s t := LeftInvOn.mapsTo h hf #align set.right_inv_on.maps_to Set.RightInvOn.mapsTo lemma _root_.Set.rightInvOn_id (s : Set α) : RightInvOn id id s := fun _ _ ↦ rfl #align set.right_inv_on_id Set.rightInvOn_id theorem comp (hf : RightInvOn f' f t) (hg : RightInvOn g' g p) (g'pt : MapsTo g' p t) : RightInvOn (f' ∘ g') (g ∘ f) p := LeftInvOn.comp hg hf g'pt #align set.right_inv_on.comp Set.RightInvOn.comp theorem mono (hf : RightInvOn f' f t) (ht : t₁ ⊆ t) : RightInvOn f' f t₁ := LeftInvOn.mono hf ht #align set.right_inv_on.mono Set.RightInvOn.mono end RightInvOn theorem InjOn.rightInvOn_of_leftInvOn (hf : InjOn f s) (hf' : LeftInvOn f f' t) (h₁ : MapsTo f s t) (h₂ : MapsTo f' t s) : RightInvOn f f' s := fun _ h => hf (h₂ <| h₁ h) h (hf' (h₁ h)) #align set.inj_on.right_inv_on_of_left_inv_on Set.InjOn.rightInvOn_of_leftInvOn theorem eqOn_of_leftInvOn_of_rightInvOn (h₁ : LeftInvOn f₁' f s) (h₂ : RightInvOn f₂' f t) (h : MapsTo f₂' t s) : EqOn f₁' f₂' t := fun y hy => calc f₁' y = (f₁' ∘ f ∘ f₂') y := congr_arg f₁' (h₂ hy).symm _ = f₂' y := h₁ (h hy) #align set.eq_on_of_left_inv_on_of_right_inv_on Set.eqOn_of_leftInvOn_of_rightInvOn theorem SurjOn.leftInvOn_of_rightInvOn (hf : SurjOn f s t) (hf' : RightInvOn f f' s) : LeftInvOn f f' t := fun y hy => by let ⟨x, hx, heq⟩ := hf hy rw [← heq, hf' hx] #align set.surj_on.left_inv_on_of_right_inv_on Set.SurjOn.leftInvOn_of_rightInvOn end RightInvOn /-! ### Two-side inverses -/ namespace InvOn lemma _root_.Set.invOn_id (s : Set α) : InvOn id id s s := ⟨s.leftInvOn_id, s.rightInvOn_id⟩ #align set.inv_on_id Set.invOn_id lemma comp (hf : InvOn f' f s t) (hg : InvOn g' g t p) (fst : MapsTo f s t) (g'pt : MapsTo g' p t) : InvOn (f' ∘ g') (g ∘ f) s p := ⟨hf.1.comp hg.1 fst, hf.2.comp hg.2 g'pt⟩ #align set.inv_on.comp Set.InvOn.comp @[symm] theorem symm (h : InvOn f' f s t) : InvOn f f' t s := ⟨h.right, h.left⟩ #align set.inv_on.symm Set.InvOn.symm theorem mono (h : InvOn f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : InvOn f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ #align set.inv_on.mono Set.InvOn.mono /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `mapsTo` arguments can be deduced from `surjOn` statements using `LeftInvOn.mapsTo` and `RightInvOn.mapsTo`. -/ theorem bijOn (h : InvOn f' f s t) (hf : MapsTo f s t) (hf' : MapsTo f' t s) : BijOn f s t := ⟨hf, h.left.injOn, h.right.surjOn hf'⟩ #align set.inv_on.bij_on Set.InvOn.bijOn end InvOn end Set /-! ### `invFunOn` is a left/right inverse -/ namespace Function variable [Nonempty α] {s : Set α} {f : α → β} {a : α} {b : β} attribute [local instance] Classical.propDecidable /-- Construct the inverse for a function `f` on domain `s`. This function is a right inverse of `f` on `f '' s`. For a computable version, see `Function.Embedding.invOfMemRange`. -/ noncomputable def invFunOn (f : α → β) (s : Set α) (b : β) : α := if h : ∃ a, a ∈ s ∧ f a = b then Classical.choose h else Classical.choice ‹Nonempty α› #align function.inv_fun_on Function.invFunOn theorem invFunOn_pos (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s ∧ f (invFunOn f s b) = b := by rw [invFunOn, dif_pos h] exact Classical.choose_spec h #align function.inv_fun_on_pos Function.invFunOn_pos theorem invFunOn_mem (h : ∃ a ∈ s, f a = b) : invFunOn f s b ∈ s := (invFunOn_pos h).left #align function.inv_fun_on_mem Function.invFunOn_mem theorem invFunOn_eq (h : ∃ a ∈ s, f a = b) : f (invFunOn f s b) = b := (invFunOn_pos h).right #align function.inv_fun_on_eq Function.invFunOn_eq theorem invFunOn_neg (h : ¬∃ a ∈ s, f a = b) : invFunOn f s b = Classical.choice ‹Nonempty α› := by rw [invFunOn, dif_neg h] #align function.inv_fun_on_neg Function.invFunOn_neg @[simp] theorem invFunOn_apply_mem (h : a ∈ s) : invFunOn f s (f a) ∈ s := invFunOn_mem ⟨a, h, rfl⟩ #align function.inv_fun_on_apply_mem Function.invFunOn_apply_mem theorem invFunOn_apply_eq (h : a ∈ s) : f (invFunOn f s (f a)) = f a := invFunOn_eq ⟨a, h, rfl⟩ #align function.inv_fun_on_apply_eq Function.invFunOn_apply_eq end Function open Function namespace Set variable {s s₁ s₂ : Set α} {t : Set β} {f : α → β} theorem InjOn.leftInvOn_invFunOn [Nonempty α] (h : InjOn f s) : LeftInvOn (invFunOn f s) f s := fun _a ha => h (invFunOn_apply_mem ha) ha (invFunOn_apply_eq ha) #align set.inj_on.left_inv_on_inv_fun_on Set.InjOn.leftInvOn_invFunOn theorem InjOn.invFunOn_image [Nonempty α] (h : InjOn f s₂) (ht : s₁ ⊆ s₂) : invFunOn f s₂ '' (f '' s₁) = s₁ := h.leftInvOn_invFunOn.image_image' ht #align set.inj_on.inv_fun_on_image Set.InjOn.invFunOn_image theorem _root_.Function.leftInvOn_invFunOn_of_subset_image_image [Nonempty α] (h : s ⊆ (invFunOn f s) '' (f '' s)) : LeftInvOn (invFunOn f s) f s := fun x hx ↦ by obtain ⟨-, ⟨x, hx', rfl⟩, rfl⟩ := h hx rw [invFunOn_apply_eq (f := f) hx'] theorem injOn_iff_invFunOn_image_image_eq_self [Nonempty α] : InjOn f s ↔ (invFunOn f s) '' (f '' s) = s := ⟨fun h ↦ h.invFunOn_image Subset.rfl, fun h ↦ (Function.leftInvOn_invFunOn_of_subset_image_image h.symm.subset).injOn⟩ theorem _root_.Function.invFunOn_injOn_image [Nonempty α] (f : α → β) (s : Set α) : Set.InjOn (invFunOn f s) (f '' s) := by rintro _ ⟨x, hx, rfl⟩ _ ⟨x', hx', rfl⟩ he rw [← invFunOn_apply_eq (f := f) hx, he, invFunOn_apply_eq (f := f) hx'] theorem _root_.Function.invFunOn_image_image_subset [Nonempty α] (f : α → β) (s : Set α) : (invFunOn f s) '' (f '' s) ⊆ s := by rintro _ ⟨_, ⟨x,hx,rfl⟩, rfl⟩; exact invFunOn_apply_mem hx theorem SurjOn.rightInvOn_invFunOn [Nonempty α] (h : SurjOn f s t) : RightInvOn (invFunOn f s) f t := fun _y hy => invFunOn_eq <| h hy #align set.surj_on.right_inv_on_inv_fun_on Set.SurjOn.rightInvOn_invFunOn theorem BijOn.invOn_invFunOn [Nonempty α] (h : BijOn f s t) : InvOn (invFunOn f s) f s t := ⟨h.injOn.leftInvOn_invFunOn, h.surjOn.rightInvOn_invFunOn⟩ #align set.bij_on.inv_on_inv_fun_on Set.BijOn.invOn_invFunOn theorem SurjOn.invOn_invFunOn [Nonempty α] (h : SurjOn f s t) : InvOn (invFunOn f s) f (invFunOn f s '' t) t := by refine ⟨?_, h.rightInvOn_invFunOn⟩ rintro _ ⟨y, hy, rfl⟩ rw [h.rightInvOn_invFunOn hy] #align set.surj_on.inv_on_inv_fun_on Set.SurjOn.invOn_invFunOn theorem SurjOn.mapsTo_invFunOn [Nonempty α] (h : SurjOn f s t) : MapsTo (invFunOn f s) t s := fun _y hy => mem_preimage.2 <| invFunOn_mem <| h hy #align set.surj_on.maps_to_inv_fun_on Set.SurjOn.mapsTo_invFunOn /-- This lemma is a special case of `rightInvOn_invFunOn.image_image'`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image_of_subset [Nonempty α] {r : Set β} (hf : SurjOn f s t) (hrt : r ⊆ t) : f '' (f.invFunOn s '' r) = r := hf.rightInvOn_invFunOn.image_image' hrt /-- This lemma is a special case of `rightInvOn_invFunOn.image_image`; it may make more sense to use the other lemma directly in an application. -/ theorem SurjOn.image_invFunOn_image [Nonempty α] (hf : SurjOn f s t) : f '' (f.invFunOn s '' t) = t := hf.rightInvOn_invFunOn.image_image theorem SurjOn.bijOn_subset [Nonempty α] (h : SurjOn f s t) : BijOn f (invFunOn f s '' t) t := by refine h.invOn_invFunOn.bijOn ?_ (mapsTo_image _ _) rintro _ ⟨y, hy, rfl⟩ rwa [h.rightInvOn_invFunOn hy] #align set.surj_on.bij_on_subset Set.SurjOn.bijOn_subset theorem surjOn_iff_exists_bijOn_subset : SurjOn f s t ↔ ∃ s' ⊆ s, BijOn f s' t := by constructor · rcases eq_empty_or_nonempty t with (rfl | ht) · exact fun _ => ⟨∅, empty_subset _, bijOn_empty f⟩ · intro h haveI : Nonempty α := ⟨Classical.choose (h.comap_nonempty ht)⟩ exact ⟨_, h.mapsTo_invFunOn.image_subset, h.bijOn_subset⟩ · rintro ⟨s', hs', hfs'⟩ exact hfs'.surjOn.mono hs' (Subset.refl _) #align set.surj_on_iff_exists_bij_on_subset Set.surjOn_iff_exists_bijOn_subset alias ⟨SurjOn.exists_bijOn_subset, _⟩ := Set.surjOn_iff_exists_bijOn_subset variable (f s) lemma exists_subset_bijOn : ∃ s' ⊆ s, BijOn f s' (f '' s) := surjOn_iff_exists_bijOn_subset.mp (surjOn_image f s) lemma exists_image_eq_and_injOn : ∃ u, f '' u = f '' s ∧ InjOn f u := let ⟨u, _, hfu⟩ := exists_subset_bijOn s f ⟨u, hfu.image_eq, hfu.injOn⟩ variable {f s} lemma exists_image_eq_injOn_of_subset_range (ht : t ⊆ range f) : ∃ s, f '' s = t ∧ InjOn f s := image_preimage_eq_of_subset ht ▸ exists_image_eq_and_injOn _ _ theorem preimage_invFun_of_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∈ s) : invFun f ⁻¹' s = f '' s ∪ (range f)ᶜ := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · simp only [mem_preimage, mem_union, mem_compl_iff, mem_range_self, not_true, or_false, leftInverse_invFun hf _, hf.mem_set_image] · simp only [mem_preimage, invFun_neg hx, h, hx, mem_union, mem_compl_iff, not_false_iff, or_true] #align set.preimage_inv_fun_of_mem Set.preimage_invFun_of_mem theorem preimage_invFun_of_not_mem [n : Nonempty α] {f : α → β} (hf : Injective f) {s : Set α} (h : Classical.choice n ∉ s) : invFun f ⁻¹' s = f '' s := by ext x rcases em (x ∈ range f) with (⟨a, rfl⟩ | hx) · rw [mem_preimage, leftInverse_invFun hf, hf.mem_set_image] · have : x ∉ f '' s := fun h' => hx (image_subset_range _ _ h') simp only [mem_preimage, invFun_neg hx, h, this] #align set.preimage_inv_fun_of_not_mem Set.preimage_invFun_of_not_mem lemma BijOn.symm {g : β → α} (h : InvOn f g t s) (hf : BijOn f s t) : BijOn g t s := ⟨h.2.mapsTo hf.surjOn, h.1.injOn, h.2.surjOn hf.mapsTo⟩ #align set.bij_on.symm Set.BijOn.symm lemma bijOn_comm {g : β → α} (h : InvOn f g t s) : BijOn f s t ↔ BijOn g t s := ⟨BijOn.symm h, BijOn.symm h.symm⟩ #align set.bij_on_comm Set.bijOn_comm end Set /-! ### Monotone -/ namespace Monotone variable [Preorder α] [Preorder β] {f : α → β} protected theorem restrict (h : Monotone f) (s : Set α) : Monotone (s.restrict f) := fun _ _ hxy => h hxy #align monotone.restrict Monotone.restrict protected theorem codRestrict (h : Monotone f) {s : Set β} (hs : ∀ x, f x ∈ s) : Monotone (s.codRestrict f hs) := h #align monotone.cod_restrict Monotone.codRestrict protected theorem rangeFactorization (h : Monotone f) : Monotone (Set.rangeFactorization f) := h #align monotone.range_factorization Monotone.rangeFactorization end Monotone /-! ### Piecewise defined function -/ namespace Set variable {δ : α → Sort*} (s : Set α) (f g : ∀ i, δ i) @[simp] theorem piecewise_empty [∀ i : α, Decidable (i ∈ (∅ : Set α))] : piecewise ∅ f g = g := by ext i simp [piecewise] #align set.piecewise_empty Set.piecewise_empty @[simp] theorem piecewise_univ [∀ i : α, Decidable (i ∈ (Set.univ : Set α))] : piecewise Set.univ f g = f := by ext i simp [piecewise] #align set.piecewise_univ Set.piecewise_univ --@[simp] -- Porting note: simpNF linter complains theorem piecewise_insert_self {j : α} [∀ i, Decidable (i ∈ insert j s)] : (insert j s).piecewise f g j = f j := by simp [piecewise] #align set.piecewise_insert_self Set.piecewise_insert_self variable [∀ j, Decidable (j ∈ s)] -- TODO: move! instance Compl.decidableMem (j : α) : Decidable (j ∈ sᶜ) := instDecidableNot #align set.compl.decidable_mem Set.Compl.decidableMem theorem piecewise_insert [DecidableEq α] (j : α) [∀ i, Decidable (i ∈ insert j s)] : (insert j s).piecewise f g = Function.update (s.piecewise f g) j (f j) := by simp (config := { unfoldPartialApp := true }) only [piecewise, mem_insert_iff] ext i by_cases h : i = j · rw [h] simp · by_cases h' : i ∈ s <;> simp [h, h'] #align set.piecewise_insert Set.piecewise_insert @[simp] theorem piecewise_eq_of_mem {i : α} (hi : i ∈ s) : s.piecewise f g i = f i := if_pos hi #align set.piecewise_eq_of_mem Set.piecewise_eq_of_mem @[simp] theorem piecewise_eq_of_not_mem {i : α} (hi : i ∉ s) : s.piecewise f g i = g i := if_neg hi #align set.piecewise_eq_of_not_mem Set.piecewise_eq_of_not_mem
Mathlib/Data/Set/Function.lean
1,575
1,581
theorem piecewise_singleton (x : α) [∀ y, Decidable (y ∈ ({x} : Set α))] [DecidableEq α] (f g : α → β) : piecewise {x} f g = Function.update g x (f x) := by
ext y by_cases hy : y = x · subst y simp · simp [hy]
/- 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.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.RCLike.Basic #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # 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`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `∀ x, C (</≤/>/≥) (f' x)`, then `C * (y - x) (</≤/>/≥) (f y - f x)` whenever `x < y`. * `monotoneOn_of_deriv_nonneg`, `antitoneOn_of_deriv_nonpos`, `strictMono_of_deriv_pos`, `strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `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 Classical 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.prod 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 cases' 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_nhdsWithin_Ioi ⟨le_rfl, 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_nhdsWithin_Ioi 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_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- 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 #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- 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 #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- 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 #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- 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 #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- 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) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### 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 #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- 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 #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- 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 #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- 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) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- 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 #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/
Mathlib/Analysis/Calculus/MeanValue.lean
337
350
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 simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) 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]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Analysis.InnerProductSpace.Orthogonal import Mathlib.Analysis.InnerProductSpace.Symmetric import Mathlib.Analysis.NormedSpace.RCLike import Mathlib.Analysis.RCLike.Lemmas import Mathlib.Algebra.DirectSum.Decomposition #align_import analysis.inner_product_space.projection from "leanprover-community/mathlib"@"0b7c740e25651db0ba63648fbae9f9d6f941e31b" /-! # The orthogonal projection Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs `orthogonalProjection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map satisfies: for any point `u` in `E`, the point `v = orthogonalProjection K u` in `K` minimizes the distance `‖u - v‖` to `u`. Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for each `u : E`, the point `reflection K u` to satisfy `u + (reflection K u) = 2 • orthogonalProjection K u`. Basic API for `orthogonalProjection` and `reflection` is developed. Next, the orthogonal projection is used to prove a series of more subtle lemmas about the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was defined in `Analysis.InnerProductSpace.Orthogonal`); the lemma `Submodule.sup_orthogonal_of_completeSpace`, stating that for a complete subspace `K` of `E` we have `K ⊔ Kᗮ = ⊤`, is a typical example. ## References The orthogonal projection construction is adapted from * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open LinearMap (ker range) open Topology variable {𝕜 E F : Type*} [RCLike 𝕜] variable [NormedAddCommGroup E] [NormedAddCommGroup F] variable [InnerProductSpace 𝕜 E] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "absR" => abs /-! ### Orthogonal projection in inner product spaces -/ -- FIXME this monolithic proof causes a deterministic timeout with `-T50000` -- It should be broken in a sequence of more manageable pieces, -- perhaps with individual statements for the three steps below. /-- Existence of minimizers Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. -/ theorem exists_norm_eq_iInf_of_complete_convex {K : Set F} (ne : K.Nonempty) (h₁ : IsComplete K) (h₂ : Convex ℝ K) : ∀ u : F, ∃ v ∈ K, ‖u - v‖ = ⨅ w : K, ‖u - w‖ := fun u => by let δ := ⨅ w : K, ‖u - w‖ letI : Nonempty K := ne.to_subtype have zero_le_δ : 0 ≤ δ := le_ciInf fun _ => norm_nonneg _ have δ_le : ∀ w : K, δ ≤ ‖u - w‖ := ciInf_le ⟨0, Set.forall_mem_range.2 fun _ => norm_nonneg _⟩ have δ_le' : ∀ w ∈ K, δ ≤ ‖u - w‖ := fun w hw => δ_le ⟨w, hw⟩ -- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K` -- such that `‖u - w n‖ < δ + 1 / (n + 1)` (which implies `‖u - w n‖ --> δ`); -- maybe this should be a separate lemma have exists_seq : ∃ w : ℕ → K, ∀ n, ‖u - w n‖ < δ + 1 / (n + 1) := by have hδ : ∀ n : ℕ, δ < δ + 1 / (n + 1) := fun n => lt_add_of_le_of_pos le_rfl Nat.one_div_pos_of_nat have h := fun n => exists_lt_of_ciInf_lt (hδ n) let w : ℕ → K := fun n => Classical.choose (h n) exact ⟨w, fun n => Classical.choose_spec (h n)⟩ rcases exists_seq with ⟨w, hw⟩ have norm_tendsto : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 δ) := by have h : Tendsto (fun _ : ℕ => δ) atTop (𝓝 δ) := tendsto_const_nhds have h' : Tendsto (fun n : ℕ => δ + 1 / (n + 1)) atTop (𝓝 δ) := by convert h.add tendsto_one_div_add_atTop_nhds_zero_nat simp only [add_zero] exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h' (fun x => δ_le _) fun x => le_of_lt (hw _) -- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence have seq_is_cauchy : CauchySeq fun n => (w n : F) := by rw [cauchySeq_iff_le_tendsto_0] -- splits into three goals let b := fun n : ℕ => 8 * δ * (1 / (n + 1)) + 4 * (1 / (n + 1)) * (1 / (n + 1)) use fun n => √(b n) constructor -- first goal : `∀ (n : ℕ), 0 ≤ √(b n)` · intro n exact sqrt_nonneg _ constructor -- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ √(b N)` · intro p q N hp hq let wp := (w p : F) let wq := (w q : F) let a := u - wq let b := u - wp let half := 1 / (2 : ℝ) let div := 1 / ((N : ℝ) + 1) have : 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := calc 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ + ‖wp - wq‖ * ‖wp - wq‖ = 2 * ‖u - half • (wq + wp)‖ * (2 * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by ring _ = absR (2 : ℝ) * ‖u - half • (wq + wp)‖ * (absR (2 : ℝ) * ‖u - half • (wq + wp)‖) + ‖wp - wq‖ * ‖wp - wq‖ := by rw [_root_.abs_of_nonneg] exact zero_le_two _ = ‖(2 : ℝ) • (u - half • (wq + wp))‖ * ‖(2 : ℝ) • (u - half • (wq + wp))‖ + ‖wp - wq‖ * ‖wp - wq‖ := by simp [norm_smul] _ = ‖a + b‖ * ‖a + b‖ + ‖a - b‖ * ‖a - b‖ := by rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0), ← one_add_one_eq_two, add_smul] simp only [one_smul] have eq₁ : wp - wq = a - b := (sub_sub_sub_cancel_left _ _ _).symm have eq₂ : u + u - (wq + wp) = a + b := by show u + u - (wq + wp) = u - wq + (u - wp) abel rw [eq₁, eq₂] _ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) := parallelogram_law_with_norm ℝ _ _ have eq : δ ≤ ‖u - half • (wq + wp)‖ := by rw [smul_add] apply δ_le' apply h₂ repeat' exact Subtype.mem _ repeat' exact le_of_lt one_half_pos exact add_halves 1 have eq₁ : 4 * δ * δ ≤ 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp_rw [mul_assoc] gcongr have eq₂ : ‖a‖ ≤ δ + div := le_trans (le_of_lt <| hw q) (add_le_add_left (Nat.one_div_le_one_div hq) _) have eq₂' : ‖b‖ ≤ δ + div := le_trans (le_of_lt <| hw p) (add_le_add_left (Nat.one_div_le_one_div hp) _) rw [dist_eq_norm] apply nonneg_le_nonneg_of_sq_le_sq · exact sqrt_nonneg _ rw [mul_self_sqrt] · calc ‖wp - wq‖ * ‖wp - wq‖ = 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * ‖u - half • (wq + wp)‖ * ‖u - half • (wq + wp)‖ := by simp [← this] _ ≤ 2 * (‖a‖ * ‖a‖ + ‖b‖ * ‖b‖) - 4 * δ * δ := by gcongr _ ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ := by gcongr _ = 8 * δ * div + 4 * div * div := by ring positivity -- third goal : `Tendsto (fun (n : ℕ) => √(b n)) atTop (𝓝 0)` suffices Tendsto (fun x ↦ √(8 * δ * x + 4 * x * x) : ℝ → ℝ) (𝓝 0) (𝓝 0) from this.comp tendsto_one_div_add_atTop_nhds_zero_nat exact Continuous.tendsto' (by continuity) _ _ (by simp) -- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`. -- Prove that it satisfies all requirements. rcases cauchySeq_tendsto_of_isComplete h₁ (fun n => Subtype.mem _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩ use v use hv have h_cont : Continuous fun v => ‖u - v‖ := Continuous.comp continuous_norm (Continuous.sub continuous_const continuous_id) have : Tendsto (fun n => ‖u - w n‖) atTop (𝓝 ‖u - v‖) := by convert Tendsto.comp h_cont.continuousAt w_tendsto exact tendsto_nhds_unique this norm_tendsto #align exists_norm_eq_infi_of_complete_convex exists_norm_eq_iInf_of_complete_convex /-- Characterization of minimizers for the projection on a convex set in a real inner product space. -/ theorem norm_eq_iInf_iff_real_inner_le_zero {K : Set F} (h : Convex ℝ K) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by letI : Nonempty K := ⟨⟨v, hv⟩⟩ constructor · intro eq w hw let δ := ⨅ w : K, ‖u - w‖ let p := ⟪u - v, w - v⟫_ℝ let q := ‖w - v‖ ^ 2 have δ_le (w : K) : δ ≤ ‖u - w‖ := ciInf_le ⟨0, fun _ ⟨_, h⟩ => h ▸ norm_nonneg _⟩ _ have δ_le' (w) (hw : w ∈ K) : δ ≤ ‖u - w‖ := δ_le ⟨w, hw⟩ have (θ : ℝ) (hθ₁ : 0 < θ) (hθ₂ : θ ≤ 1) : 2 * p ≤ θ * q := by have : ‖u - v‖ ^ 2 ≤ ‖u - v‖ ^ 2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ * θ * ‖w - v‖ ^ 2 := calc ‖u - v‖ ^ 2 _ ≤ ‖u - (θ • w + (1 - θ) • v)‖ ^ 2 := by simp only [sq]; apply mul_self_le_mul_self (norm_nonneg _) rw [eq]; apply δ_le' apply h hw hv exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel _ _] _ = ‖u - v - θ • (w - v)‖ ^ 2 := by have : u - (θ • w + (1 - θ) • v) = u - v - θ • (w - v) := by rw [smul_sub, sub_smul, one_smul] simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] rw [this] _ = ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 := by rw [@norm_sub_sq ℝ, inner_smul_right, norm_smul] simp only [sq] show ‖u - v‖ * ‖u - v‖ - 2 * (θ * inner (u - v) (w - v)) + absR θ * ‖w - v‖ * (absR θ * ‖w - v‖) = ‖u - v‖ * ‖u - v‖ - 2 * θ * inner (u - v) (w - v) + θ * θ * (‖w - v‖ * ‖w - v‖) rw [abs_of_pos hθ₁]; ring have eq₁ : ‖u - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) + θ * θ * ‖w - v‖ ^ 2 = ‖u - v‖ ^ 2 + (θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v)) := by abel rw [eq₁, le_add_iff_nonneg_right] at this have eq₂ : θ * θ * ‖w - v‖ ^ 2 - 2 * θ * inner (u - v) (w - v) = θ * (θ * ‖w - v‖ ^ 2 - 2 * inner (u - v) (w - v)) := by ring rw [eq₂] at this have := le_of_sub_nonneg (nonneg_of_mul_nonneg_right this hθ₁) exact this by_cases hq : q = 0 · rw [hq] at this have : p ≤ 0 := by have := this (1 : ℝ) (by norm_num) (by norm_num) linarith exact this · have q_pos : 0 < q := lt_of_le_of_ne (sq_nonneg _) fun h ↦ hq h.symm by_contra hp rw [not_le] at hp let θ := min (1 : ℝ) (p / q) have eq₁ : θ * q ≤ p := calc θ * q ≤ p / q * q := mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _) _ = p := div_mul_cancel₀ _ hq have : 2 * p ≤ p := calc 2 * p ≤ θ * q := by set_option tactic.skipAssignedInstances false in exact this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num [θ]) _ ≤ p := eq₁ linarith · intro h apply le_antisymm · apply le_ciInf intro w apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) have := h w w.2 calc ‖u - v‖ * ‖u - v‖ ≤ ‖u - v‖ * ‖u - v‖ - 2 * inner (u - v) ((w : F) - v) := by linarith _ ≤ ‖u - v‖ ^ 2 - 2 * inner (u - v) ((w : F) - v) + ‖(w : F) - v‖ ^ 2 := by rw [sq] refine le_add_of_nonneg_right ?_ exact sq_nonneg _ _ = ‖u - v - (w - v)‖ ^ 2 := (@norm_sub_sq ℝ _ _ _ _ _ _).symm _ = ‖u - w‖ * ‖u - w‖ := by have : u - v - (w - v) = u - w := by abel rw [this, sq] · show ⨅ w : K, ‖u - w‖ ≤ (fun w : K => ‖u - w‖) ⟨v, hv⟩ apply ciInf_le use 0 rintro y ⟨z, rfl⟩ exact norm_nonneg _ #align norm_eq_infi_iff_real_inner_le_zero norm_eq_iInf_iff_real_inner_le_zero variable (K : Submodule 𝕜 E) /-- Existence of projections on complete subspaces. Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace. Then there exists a (unique) `v` in `K` that minimizes the distance `‖u - v‖` to `u`. This point `v` is usually called the orthogonal projection of `u` onto `K`. -/ theorem exists_norm_eq_iInf_of_complete_subspace (h : IsComplete (↑K : Set E)) : ∀ u : E, ∃ v ∈ K, ‖u - v‖ = ⨅ w : (K : Set E), ‖u - w‖ := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := Submodule.restrictScalars ℝ K exact exists_norm_eq_iInf_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex #align exists_norm_eq_infi_of_complete_subspace exists_norm_eq_iInf_of_complete_subspace /-- Characterization of minimizers in the projection on a subspace, in the real case. Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`). This is superceded by `norm_eq_iInf_iff_inner_eq_zero` that gives the same conclusion over any `RCLike` field. -/ theorem norm_eq_iInf_iff_real_inner_eq_zero (K : Submodule ℝ F) {u : F} {v : F} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : (↑K : Set F), ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 := Iff.intro (by intro h have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by rwa [norm_eq_iInf_iff_real_inner_le_zero] at h exacts [K.convex, hv] intro w hw have le : ⟪u - v, w⟫_ℝ ≤ 0 := by let w' := w + v have : w' ∈ K := Submodule.add_mem _ hw hv have h₁ := h w' this have h₂ : w' - v = w := by simp only [w', add_neg_cancel_right, sub_eq_add_neg] rw [h₂] at h₁ exact h₁ have ge : ⟪u - v, w⟫_ℝ ≥ 0 := by let w'' := -w + v have : w'' ∈ K := Submodule.add_mem _ (Submodule.neg_mem _ hw) hv have h₁ := h w'' this have h₂ : w'' - v = -w := by simp only [w'', neg_inj, add_neg_cancel_right, sub_eq_add_neg] rw [h₂, inner_neg_right] at h₁ linarith exact le_antisymm le ge) (by intro h have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 := by intro w hw let w' := w - v have : w' ∈ K := Submodule.sub_mem _ hw hv have h₁ := h w' this exact le_of_eq h₁ rwa [norm_eq_iInf_iff_real_inner_le_zero] exacts [Submodule.convex _, hv]) #align norm_eq_infi_iff_real_inner_eq_zero norm_eq_iInf_iff_real_inner_eq_zero /-- Characterization of minimizers in the projection on a subspace. Let `u` be a point in an inner product space, and let `K` be a nonempty subspace. Then point `v` minimizes the distance `‖u - v‖` over points in `K` if and only if for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`) -/ theorem norm_eq_iInf_iff_inner_eq_zero {u : E} {v : E} (hv : v ∈ K) : (‖u - v‖ = ⨅ w : K, ‖u - w‖) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 := by letI : InnerProductSpace ℝ E := InnerProductSpace.rclikeToReal 𝕜 E letI : Module ℝ E := RestrictScalars.module ℝ 𝕜 E let K' : Submodule ℝ E := K.restrictScalars ℝ constructor · intro H have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_iInf_iff_real_inner_eq_zero K' hv).1 H intro w hw apply ext · simp [A w hw] · symm calc im (0 : 𝕜) = 0 := im.map_zero _ = re ⟪u - v, (-I : 𝕜) • w⟫ := (A _ (K.smul_mem (-I) hw)).symm _ = re (-I * ⟪u - v, w⟫) := by rw [inner_smul_right] _ = im ⟪u - v, w⟫ := by simp · intro H have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0 := by intro w hw rw [real_inner_eq_re_inner, H w hw] exact zero_re' exact (norm_eq_iInf_iff_real_inner_eq_zero K' hv).2 this #align norm_eq_infi_iff_inner_eq_zero norm_eq_iInf_iff_inner_eq_zero /-- A subspace `K : Submodule 𝕜 E` has an orthogonal projection if evey vector `v : E` admits an orthogonal projection to `K`. -/ class HasOrthogonalProjection (K : Submodule 𝕜 E) : Prop where exists_orthogonal (v : E) : ∃ w ∈ K, v - w ∈ Kᗮ instance (priority := 100) HasOrthogonalProjection.ofCompleteSpace [CompleteSpace K] : HasOrthogonalProjection K where exists_orthogonal v := by rcases exists_norm_eq_iInf_of_complete_subspace K (completeSpace_coe_iff_isComplete.mp ‹_›) v with ⟨w, hwK, hw⟩ refine ⟨w, hwK, (K.mem_orthogonal' _).2 ?_⟩ rwa [← norm_eq_iInf_iff_inner_eq_zero K hwK] instance [HasOrthogonalProjection K] : HasOrthogonalProjection Kᗮ where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) v with ⟨w, hwK, hw⟩ refine ⟨_, hw, ?_⟩ rw [sub_sub_cancel] exact K.le_orthogonal_orthogonal hwK instance HasOrthogonalProjection.map_linearIsometryEquiv [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map (f.toLinearEquiv : E →ₗ[𝕜] E')) where exists_orthogonal v := by rcases HasOrthogonalProjection.exists_orthogonal (K := K) (f.symm v) with ⟨w, hwK, hw⟩ refine ⟨f w, Submodule.mem_map_of_mem hwK, Set.forall_mem_image.2 fun u hu ↦ ?_⟩ erw [← f.symm.inner_map_map, f.symm_apply_apply, map_sub, f.symm_apply_apply, hw u hu] instance HasOrthogonalProjection.map_linearIsometryEquiv' [HasOrthogonalProjection K] {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') : HasOrthogonalProjection (K.map f.toLinearIsometry) := HasOrthogonalProjection.map_linearIsometryEquiv K f instance : HasOrthogonalProjection (⊤ : Submodule 𝕜 E) := ⟨fun v ↦ ⟨v, trivial, by simp⟩⟩ section orthogonalProjection variable [HasOrthogonalProjection K] /-- The orthogonal projection onto a complete subspace, as an unbundled function. This definition is only intended for use in setting up the bundled version `orthogonalProjection` and should not be used once that is defined. -/ def orthogonalProjectionFn (v : E) := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose #align orthogonal_projection_fn orthogonalProjectionFn variable {K} /-- The unbundled orthogonal projection is in the given subspace. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_mem (v : E) : orthogonalProjectionFn K v ∈ K := (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.left #align orthogonal_projection_fn_mem orthogonalProjectionFn_mem /-- The characterization of the unbundled orthogonal projection. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem orthogonalProjectionFn_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjectionFn K v, w⟫ = 0 := (K.mem_orthogonal' _).1 (HasOrthogonalProjection.exists_orthogonal (K := K) v).choose_spec.right #align orthogonal_projection_fn_inner_eq_zero orthogonalProjectionFn_inner_eq_zero /-- The unbundled orthogonal projection is the unique point in `K` with the orthogonality property. This lemma is only intended for use in setting up the bundled version and should not be used once that is defined. -/ theorem eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : orthogonalProjectionFn K u = v := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜] have hvs : orthogonalProjectionFn K u - v ∈ K := Submodule.sub_mem K (orthogonalProjectionFn_mem u) hvm have huo : ⟪u - orthogonalProjectionFn K u, orthogonalProjectionFn K u - v⟫ = 0 := orthogonalProjectionFn_inner_eq_zero u _ hvs have huv : ⟪u - v, orthogonalProjectionFn K u - v⟫ = 0 := hvo _ hvs have houv : ⟪u - v - (u - orthogonalProjectionFn K u), orthogonalProjectionFn K u - v⟫ = 0 := by rw [inner_sub_left, huo, huv, sub_zero] rwa [sub_sub_sub_cancel_left] at houv #align eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero variable (K) theorem orthogonalProjectionFn_norm_sq (v : E) : ‖v‖ * ‖v‖ = ‖v - orthogonalProjectionFn K v‖ * ‖v - orthogonalProjectionFn K v‖ + ‖orthogonalProjectionFn K v‖ * ‖orthogonalProjectionFn K v‖ := by set p := orthogonalProjectionFn K v have h' : ⟪v - p, p⟫ = 0 := orthogonalProjectionFn_inner_eq_zero _ _ (orthogonalProjectionFn_mem v) convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2 <;> simp #align orthogonal_projection_fn_norm_sq orthogonalProjectionFn_norm_sq /-- The orthogonal projection onto a complete subspace. -/ def orthogonalProjection : E →L[𝕜] K := LinearMap.mkContinuous { toFun := fun v => ⟨orthogonalProjectionFn K v, orthogonalProjectionFn_mem v⟩ map_add' := fun x y => by have hm : orthogonalProjectionFn K x + orthogonalProjectionFn K y ∈ K := Submodule.add_mem K (orthogonalProjectionFn_mem x) (orthogonalProjectionFn_mem y) have ho : ∀ w ∈ K, ⟪x + y - (orthogonalProjectionFn K x + orthogonalProjectionFn K y), w⟫ = 0 := by intro w hw rw [add_sub_add_comm, inner_add_left, orthogonalProjectionFn_inner_eq_zero _ w hw, orthogonalProjectionFn_inner_eq_zero _ w hw, add_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] map_smul' := fun c x => by have hm : c • orthogonalProjectionFn K x ∈ K := Submodule.smul_mem K _ (orthogonalProjectionFn_mem x) have ho : ∀ w ∈ K, ⟪c • x - c • orthogonalProjectionFn K x, w⟫ = 0 := by intro w hw rw [← smul_sub, inner_smul_left, orthogonalProjectionFn_inner_eq_zero _ w hw, mul_zero] ext simp [eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hm ho] } 1 fun x => by simp only [one_mul, LinearMap.coe_mk] refine le_of_pow_le_pow_left two_ne_zero (norm_nonneg _) ?_ change ‖orthogonalProjectionFn K x‖ ^ 2 ≤ ‖x‖ ^ 2 nlinarith [orthogonalProjectionFn_norm_sq K x] #align orthogonal_projection orthogonalProjection variable {K} @[simp] theorem orthogonalProjectionFn_eq (v : E) : orthogonalProjectionFn K v = (orthogonalProjection K v : E) := rfl #align orthogonal_projection_fn_eq orthogonalProjectionFn_eq /-- The characterization of the orthogonal projection. -/ @[simp] theorem orthogonalProjection_inner_eq_zero (v : E) : ∀ w ∈ K, ⟪v - orthogonalProjection K v, w⟫ = 0 := orthogonalProjectionFn_inner_eq_zero v #align orthogonal_projection_inner_eq_zero orthogonalProjection_inner_eq_zero /-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/ @[simp] theorem sub_orthogonalProjection_mem_orthogonal (v : E) : v - orthogonalProjection K v ∈ Kᗮ := by intro w hw rw [inner_eq_zero_symm] exact orthogonalProjection_inner_eq_zero _ _ hw #align sub_orthogonal_projection_mem_orthogonal sub_orthogonalProjection_mem_orthogonal /-- The orthogonal projection is the unique point in `K` with the orthogonality property. -/ theorem eq_orthogonalProjection_of_mem_of_inner_eq_zero {u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hvm hvo #align eq_orthogonal_projection_of_mem_of_inner_eq_zero eq_orthogonalProjection_of_mem_of_inner_eq_zero /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) : (orthogonalProjection K u : E) = v := eq_orthogonalProjectionFn_of_mem_of_inner_eq_zero hv <| (Submodule.mem_orthogonal' _ _).1 hvo #align eq_orthogonal_projection_of_mem_orthogonal eq_orthogonalProjection_of_mem_orthogonal /-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the orthogonal projection. -/ theorem eq_orthogonalProjection_of_mem_orthogonal' {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) : (orthogonalProjection K u : E) = v := eq_orthogonalProjection_of_mem_orthogonal hv (by simpa [hu] ) #align eq_orthogonal_projection_of_mem_orthogonal' eq_orthogonalProjection_of_mem_orthogonal' @[simp] theorem orthogonalProjection_orthogonal_val (u : E) : (orthogonalProjection Kᗮ u : E) = u - orthogonalProjection K u := eq_orthogonalProjection_of_mem_orthogonal' (sub_orthogonalProjection_mem_orthogonal _) (K.le_orthogonal_orthogonal (orthogonalProjection K u).2) <| by simp theorem orthogonalProjection_orthogonal (u : E) : orthogonalProjection Kᗮ u = ⟨u - orthogonalProjection K u, sub_orthogonalProjection_mem_orthogonal _⟩ := Subtype.eq <| orthogonalProjection_orthogonal_val _ /-- The orthogonal projection of `y` on `U` minimizes the distance `‖y - x‖` for `x ∈ U`. -/ theorem orthogonalProjection_minimal {U : Submodule 𝕜 E} [HasOrthogonalProjection U] (y : E) : ‖y - orthogonalProjection U y‖ = ⨅ x : U, ‖y - x‖ := by rw [norm_eq_iInf_iff_inner_eq_zero _ (Submodule.coe_mem _)] exact orthogonalProjection_inner_eq_zero _ #align orthogonal_projection_minimal orthogonalProjection_minimal /-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/ theorem eq_orthogonalProjection_of_eq_submodule {K' : Submodule 𝕜 E} [HasOrthogonalProjection K'] (h : K = K') (u : E) : (orthogonalProjection K u : E) = (orthogonalProjection K' u : E) := by subst h; rfl #align eq_orthogonal_projection_of_eq_submodule eq_orthogonalProjection_of_eq_submodule /-- The orthogonal projection sends elements of `K` to themselves. -/ @[simp]
Mathlib/Analysis/InnerProductSpace/Projection.lean
551
553
theorem orthogonalProjection_mem_subspace_eq_self (v : K) : orthogonalProjection K v = v := by
ext apply eq_orthogonalProjection_of_mem_of_inner_eq_zero <;> simp
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.RingTheory.Polynomial.Cyclotomic.Basic import Mathlib.RingTheory.RootsOfUnity.Minpoly #align_import ring_theory.polynomial.cyclotomic.roots from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f" /-! # Roots of cyclotomic polynomials. We gather results about roots of cyclotomic polynomials. In particular we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n R` is the minimal polynomial of a primitive root of unity. ## Main results * `IsPrimitiveRoot.isRoot_cyclotomic` : Any `n`-th primitive root of unity is a root of `cyclotomic n R`. * `isRoot_cyclotomic_iff` : if `NeZero (n : R)`, then `μ` is a root of `cyclotomic n R` if and only if `μ` is a primitive root of unity. * `Polynomial.cyclotomic_eq_minpoly` : `cyclotomic n ℤ` is the minimal polynomial of a primitive `n`-th root of unity `μ`. * `Polynomial.cyclotomic.irreducible` : `cyclotomic n ℤ` is irreducible. ## Implementation details To prove `Polynomial.cyclotomic.irreducible`, the irreducibility of `cyclotomic n ℤ`, we show in `Polynomial.cyclotomic_eq_minpoly` that `cyclotomic n ℤ` is the minimal polynomial of any `n`-th primitive root of unity `μ : K`, where `K` is a field of characteristic `0`. -/ namespace Polynomial variable {R : Type*} [CommRing R] {n : ℕ} theorem isRoot_of_unity_of_root_cyclotomic {ζ : R} {i : ℕ} (hi : i ∈ n.divisors) (h : (cyclotomic i R).IsRoot ζ) : ζ ^ n = 1 := by rcases n.eq_zero_or_pos with (rfl | hn) · exact pow_zero _ have := congr_arg (eval ζ) (prod_cyclotomic_eq_X_pow_sub_one hn R).symm rw [eval_sub, eval_pow, eval_X, eval_one] at this convert eq_add_of_sub_eq' this convert (add_zero (M := R) _).symm apply eval_eq_zero_of_dvd_of_eval_eq_zero _ h exact Finset.dvd_prod_of_mem _ hi #align polynomial.is_root_of_unity_of_root_cyclotomic Polynomial.isRoot_of_unity_of_root_cyclotomic section IsDomain variable [IsDomain R] theorem _root_.isRoot_of_unity_iff (h : 0 < n) (R : Type*) [CommRing R] [IsDomain R] {ζ : R} : ζ ^ n = 1 ↔ ∃ i ∈ n.divisors, (cyclotomic i R).IsRoot ζ := by rw [← mem_nthRoots h, nthRoots, mem_roots <| X_pow_sub_C_ne_zero h _, C_1, ← prod_cyclotomic_eq_X_pow_sub_one h, isRoot_prod] #align is_root_of_unity_iff isRoot_of_unity_iff /-- Any `n`-th primitive root of unity is a root of `cyclotomic n R`. -/ theorem _root_.IsPrimitiveRoot.isRoot_cyclotomic (hpos : 0 < n) {μ : R} (h : IsPrimitiveRoot μ n) : IsRoot (cyclotomic n R) μ := by rw [← mem_roots (cyclotomic_ne_zero n R), cyclotomic_eq_prod_X_sub_primitiveRoots h, roots_prod_X_sub_C, ← Finset.mem_def] rwa [← mem_primitiveRoots hpos] at h #align is_primitive_root.is_root_cyclotomic IsPrimitiveRoot.isRoot_cyclotomic private theorem isRoot_cyclotomic_iff' {n : ℕ} {K : Type*} [Field K] {μ : K} [NeZero (n : K)] : IsRoot (cyclotomic n K) μ ↔ IsPrimitiveRoot μ n := by -- in this proof, `o` stands for `orderOf μ` have hnpos : 0 < n := (NeZero.of_neZero_natCast K).out.bot_lt refine ⟨fun hμ => ?_, IsPrimitiveRoot.isRoot_cyclotomic hnpos⟩ have hμn : μ ^ n = 1 := by rw [isRoot_of_unity_iff hnpos _] exact ⟨n, n.mem_divisors_self hnpos.ne', hμ⟩ by_contra hnμ have ho : 0 < orderOf μ := (isOfFinOrder_iff_pow_eq_one.2 <| ⟨n, hnpos, hμn⟩).orderOf_pos have := pow_orderOf_eq_one μ rw [isRoot_of_unity_iff ho] at this obtain ⟨i, hio, hiμ⟩ := this replace hio := Nat.dvd_of_mem_divisors hio rw [IsPrimitiveRoot.not_iff] at hnμ rw [← orderOf_dvd_iff_pow_eq_one] at hμn have key : i < n := (Nat.le_of_dvd ho hio).trans_lt ((Nat.le_of_dvd hnpos hμn).lt_of_ne hnμ) have key' : i ∣ n := hio.trans hμn rw [← Polynomial.dvd_iff_isRoot] at hμ hiμ have hni : {i, n} ⊆ n.divisors := by simpa [Finset.insert_subset_iff, key'] using hnpos.ne' obtain ⟨k, hk⟩ := hiμ obtain ⟨j, hj⟩ := hμ have := prod_cyclotomic_eq_X_pow_sub_one hnpos K rw [← Finset.prod_sdiff hni, Finset.prod_pair key.ne, hk, hj] at this have hn := (X_pow_sub_one_separable_iff.mpr <| NeZero.natCast_ne n K).squarefree rw [← this, Squarefree] at hn specialize hn (X - C μ) ⟨(∏ x ∈ n.divisors \ {i, n}, cyclotomic x K) * k * j, by ring⟩ simp [Polynomial.isUnit_iff_degree_eq_zero] at hn theorem isRoot_cyclotomic_iff [NeZero (n : R)] {μ : R} : IsRoot (cyclotomic n R) μ ↔ IsPrimitiveRoot μ n := by have hf : Function.Injective _ := IsFractionRing.injective R (FractionRing R) haveI : NeZero (n : FractionRing R) := NeZero.nat_of_injective hf rw [← isRoot_map_iff hf, ← IsPrimitiveRoot.map_iff_of_injective hf, map_cyclotomic, ← isRoot_cyclotomic_iff'] #align polynomial.is_root_cyclotomic_iff Polynomial.isRoot_cyclotomic_iff
Mathlib/RingTheory/Polynomial/Cyclotomic/Roots.lean
107
113
theorem roots_cyclotomic_nodup [NeZero (n : R)] : (cyclotomic n R).roots.Nodup := by
obtain h | ⟨ζ, hζ⟩ := (cyclotomic n R).roots.empty_or_exists_mem · exact h.symm ▸ Multiset.nodup_zero rw [mem_roots <| cyclotomic_ne_zero n R, isRoot_cyclotomic_iff] at hζ refine Multiset.nodup_of_le (roots.le_of_dvd (X_pow_sub_C_ne_zero (NeZero.pos_of_neZero_natCast R) 1) <| cyclotomic.dvd_X_pow_sub_one n R) hζ.nthRoots_one_nodup
/- 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.Topology.Instances.Real import Mathlib.Order.Filter.Archimedean #align_import analysis.subadditive from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Convergence of subadditive sequences A subadditive sequence `u : ℕ → ℝ` is a sequence satisfying `u (m + n) ≤ u m + u n` for all `m, n`. We define this notion as `Subadditive u`, and prove in `Subadditive.tendsto_lim` that, if `u n / n` is bounded below, then it converges to a limit (that we denote by `Subadditive.lim` for convenience). This result is known as Fekete's lemma in the literature. ## TODO Define a bundled `SubadditiveHom`, use it. -/ noncomputable section open Set Filter Topology /-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) ≤ u m + u n` for all `m, n`. -/ def Subadditive (u : ℕ → ℝ) : Prop := ∀ m n, u (m + n) ≤ u m + u n #align subadditive Subadditive namespace Subadditive variable {u : ℕ → ℝ} (h : Subadditive u) /-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to this limit is given in `Subadditive.tendsto_lim` -/ @[nolint unusedArguments] -- Porting note: was irreducible protected def lim (_h : Subadditive u) := sInf ((fun n : ℕ => u n / n) '' Ici 1) #align subadditive.lim Subadditive.lim
Mathlib/Analysis/Subadditive.lean
45
48
theorem lim_le_div (hbdd : BddBelow (range fun n => u n / n)) {n : ℕ} (hn : n ≠ 0) : h.lim ≤ u n / n := by
rw [Subadditive.lim] exact csInf_le (hbdd.mono <| image_subset_range _ _) ⟨n, hn.bot_lt, rfl⟩
/- 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 #align_import algebra.cubic_discriminant from "leanprover-community/mathlib"@"930133160e24036d5242039fe4972407cd4f1222" /-! # 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 (a b c d : R) #align cubic Cubic namespace Cubic open Cubic Polynomial 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 #align cubic.to_poly Cubic.toPoly 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 set_option linter.uppercaseLean3 false in #align cubic.C_mul_prod_X_sub_C_eq Cubic.C_mul_prod_X_sub_C_eq 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] set_option linter.uppercaseLean3 false in #align cubic.prod_X_sub_C_eq Cubic.prod_X_sub_C_eq /-! ### 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] set_option tactic.skipAssignedInstances false in norm_num intro n hn repeat' rw [if_neg] any_goals linarith only [hn] repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn #align cubic.coeff_eq_zero Cubic.coeff_eq_zero @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 #align cubic.coeff_eq_a Cubic.coeff_eq_a @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 #align cubic.coeff_eq_b Cubic.coeff_eq_b @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 #align cubic.coeff_eq_c Cubic.coeff_eq_c @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 #align cubic.coeff_eq_d Cubic.coeff_eq_d theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] #align cubic.a_of_eq Cubic.a_of_eq theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] #align cubic.b_of_eq Cubic.b_of_eq theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] #align cubic.c_of_eq Cubic.c_of_eq theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] #align cubic.d_of_eq Cubic.d_of_eq theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext P Q (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ #align cubic.to_poly_injective Cubic.toPoly_injective 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] #align cubic.of_a_eq_zero Cubic.of_a_eq_zero theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl #align cubic.of_a_eq_zero' Cubic.of_a_eq_zero'
Mathlib/Algebra/CubicDiscriminant.lean
145
146
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]
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Topology import Mathlib.Analysis.NormedSpace.Pointwise import Mathlib.Analysis.Seminorm import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.RCLike.Basic #align_import analysis.convex.gauge from "leanprover-community/mathlib"@"373b03b5b9d0486534edbe94747f23cb3712f93d" /-! # The Minkowski functional This file defines the Minkowski functional, aka gauge. The Minkowski functional of a set `s` is the function which associates each point to how much you need to scale `s` for `x` to be inside it. When `s` is symmetric, convex and absorbent, its gauge is a seminorm. Reciprocally, any seminorm arises as the gauge of some set, namely its unit ball. This induces the equivalence of seminorms and locally convex topological vector spaces. ## Main declarations For a real vector space, * `gauge`: Aka Minkowski functional. `gauge s x` is the least (actually, an infimum) `r` such that `x ∈ r • s`. * `gaugeSeminorm`: The Minkowski functional as a seminorm, when `s` is symmetric, convex and absorbent. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags Minkowski functional, gauge -/ open NormedField Set open scoped Pointwise Topology NNReal noncomputable section variable {𝕜 E F : Type*} section AddCommGroup variable [AddCommGroup E] [Module ℝ E] /-- The Minkowski functional. Given a set `s` in a real vector space, `gauge s` is the functional which sends `x : E` to the smallest `r : ℝ` such that `x` is in `s` scaled by `r`. -/ def gauge (s : Set E) (x : E) : ℝ := sInf { r : ℝ | 0 < r ∧ x ∈ r • s } #align gauge gauge variable {s t : Set E} {x : E} {a : ℝ} theorem gauge_def : gauge s x = sInf ({ r ∈ Set.Ioi (0 : ℝ) | x ∈ r • s }) := rfl #align gauge_def gauge_def /-- An alternative definition of the gauge using scalar multiplication on the element rather than on the set. -/ theorem gauge_def' : gauge s x = sInf {r ∈ Set.Ioi (0 : ℝ) | r⁻¹ • x ∈ s} := by congrm sInf {r | ?_} exact and_congr_right fun hr => mem_smul_set_iff_inv_smul_mem₀ hr.ne' _ _ #align gauge_def' gauge_def' private theorem gauge_set_bddBelow : BddBelow { r : ℝ | 0 < r ∧ x ∈ r • s } := ⟨0, fun _ hr => hr.1.le⟩ /-- If the given subset is `Absorbent` then the set we take an infimum over in `gauge` is nonempty, which is useful for proving many properties about the gauge. -/ theorem Absorbent.gauge_set_nonempty (absorbs : Absorbent ℝ s) : { r : ℝ | 0 < r ∧ x ∈ r • s }.Nonempty := let ⟨r, hr₁, hr₂⟩ := (absorbs x).exists_pos ⟨r, hr₁, hr₂ r (Real.norm_of_nonneg hr₁.le).ge rfl⟩ #align absorbent.gauge_set_nonempty Absorbent.gauge_set_nonempty theorem gauge_mono (hs : Absorbent ℝ s) (h : s ⊆ t) : gauge t ≤ gauge s := fun _ => csInf_le_csInf gauge_set_bddBelow hs.gauge_set_nonempty fun _ hr => ⟨hr.1, smul_set_mono h hr.2⟩ #align gauge_mono gauge_mono theorem exists_lt_of_gauge_lt (absorbs : Absorbent ℝ s) (h : gauge s x < a) : ∃ b, 0 < b ∧ b < a ∧ x ∈ b • s := by obtain ⟨b, ⟨hb, hx⟩, hba⟩ := exists_lt_of_csInf_lt absorbs.gauge_set_nonempty h exact ⟨b, hb, hba, hx⟩ #align exists_lt_of_gauge_lt exists_lt_of_gauge_lt /-- The gauge evaluated at `0` is always zero (mathematically this requires `0` to be in the set `s` but, the real infimum of the empty set in Lean being defined as `0`, it holds unconditionally). -/ @[simp] theorem gauge_zero : gauge s 0 = 0 := by rw [gauge_def'] by_cases h : (0 : E) ∈ s · simp only [smul_zero, sep_true, h, csInf_Ioi] · simp only [smul_zero, sep_false, h, Real.sInf_empty] #align gauge_zero gauge_zero @[simp]
Mathlib/Analysis/Convex/Gauge.lean
103
110
theorem gauge_zero' : gauge (0 : Set E) = 0 := by
ext x rw [gauge_def'] obtain rfl | hx := eq_or_ne x 0 · simp only [csInf_Ioi, mem_zero, Pi.zero_apply, eq_self_iff_true, sep_true, smul_zero] · simp only [mem_zero, Pi.zero_apply, inv_eq_zero, smul_eq_zero] convert Real.sInf_empty exact eq_empty_iff_forall_not_mem.2 fun r hr => hr.2.elim (ne_of_gt hr.1) hx
/- Copyright (c) 2020 Paul van Wamelen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Paul van Wamelen -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.Order.Group.Basic import Mathlib.Algebra.Order.Ring.Basic import Mathlib.RingTheory.Int.Basic import Mathlib.Tactic.Ring import Mathlib.Tactic.FieldSimp import Mathlib.Data.Int.NatPrime import Mathlib.Data.ZMod.Basic #align_import number_theory.pythagorean_triples from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Pythagorean Triples The main result is the classification of Pythagorean triples. The final result is for general Pythagorean triples. It follows from the more interesting relatively prime case. We use the "rational parametrization of the circle" method for the proof. The parametrization maps the point `(x / z, y / z)` to the slope of the line through `(-1 , 0)` and `(x / z, y / z)`. This quickly shows that `(x / z, y / z) = (2 * m * n / (m ^ 2 + n ^ 2), (m ^ 2 - n ^ 2) / (m ^ 2 + n ^ 2))` where `m / n` is the slope. In order to identify numerators and denominators we now need results showing that these are coprime. This is easy except for the prime 2. In order to deal with that we have to analyze the parity of `x`, `y`, `m` and `n` and eliminate all the impossible cases. This takes up the bulk of the proof below. -/ theorem sq_ne_two_fin_zmod_four (z : ZMod 4) : z * z ≠ 2 := by change Fin 4 at z fin_cases z <;> decide #align sq_ne_two_fin_zmod_four sq_ne_two_fin_zmod_four theorem Int.sq_ne_two_mod_four (z : ℤ) : z * z % 4 ≠ 2 := by suffices ¬z * z % (4 : ℕ) = 2 % (4 : ℕ) by exact this rw [← ZMod.intCast_eq_intCast_iff'] simpa using sq_ne_two_fin_zmod_four _ #align int.sq_ne_two_mod_four Int.sq_ne_two_mod_four noncomputable section open scoped Classical /-- Three integers `x`, `y`, and `z` form a Pythagorean triple if `x * x + y * y = z * z`. -/ def PythagoreanTriple (x y z : ℤ) : Prop := x * x + y * y = z * z #align pythagorean_triple PythagoreanTriple /-- Pythagorean triples are interchangeable, i.e `x * x + y * y = y * y + x * x = z * z`. This comes from additive commutativity. -/ theorem pythagoreanTriple_comm {x y z : ℤ} : PythagoreanTriple x y z ↔ PythagoreanTriple y x z := by delta PythagoreanTriple rw [add_comm] #align pythagorean_triple_comm pythagoreanTriple_comm /-- The zeroth Pythagorean triple is all zeros. -/ theorem PythagoreanTriple.zero : PythagoreanTriple 0 0 0 := by simp only [PythagoreanTriple, zero_mul, zero_add] #align pythagorean_triple.zero PythagoreanTriple.zero namespace PythagoreanTriple variable {x y z : ℤ} (h : PythagoreanTriple x y z) theorem eq : x * x + y * y = z * z := h #align pythagorean_triple.eq PythagoreanTriple.eq @[symm] theorem symm : PythagoreanTriple y x z := by rwa [pythagoreanTriple_comm] #align pythagorean_triple.symm PythagoreanTriple.symm /-- A triple is still a triple if you multiply `x`, `y` and `z` by a constant `k`. -/ theorem mul (k : ℤ) : PythagoreanTriple (k * x) (k * y) (k * z) := calc k * x * (k * x) + k * y * (k * y) = k ^ 2 * (x * x + y * y) := by ring _ = k ^ 2 * (z * z) := by rw [h.eq] _ = k * z * (k * z) := by ring #align pythagorean_triple.mul PythagoreanTriple.mul /-- `(k*x, k*y, k*z)` is a Pythagorean triple if and only if `(x, y, z)` is also a triple. -/ theorem mul_iff (k : ℤ) (hk : k ≠ 0) : PythagoreanTriple (k * x) (k * y) (k * z) ↔ PythagoreanTriple x y z := by refine ⟨?_, fun h => h.mul k⟩ simp only [PythagoreanTriple] intro h rw [← mul_left_inj' (mul_ne_zero hk hk)] convert h using 1 <;> ring #align pythagorean_triple.mul_iff PythagoreanTriple.mul_iff /-- A Pythagorean triple `x, y, z` is “classified” if there exist integers `k, m, n` such that either * `x = k * (m ^ 2 - n ^ 2)` and `y = k * (2 * m * n)`, or * `x = k * (2 * m * n)` and `y = k * (m ^ 2 - n ^ 2)`. -/ @[nolint unusedArguments] def IsClassified (_ : PythagoreanTriple x y z) := ∃ k m n : ℤ, (x = k * (m ^ 2 - n ^ 2) ∧ y = k * (2 * m * n) ∨ x = k * (2 * m * n) ∧ y = k * (m ^ 2 - n ^ 2)) ∧ Int.gcd m n = 1 #align pythagorean_triple.is_classified PythagoreanTriple.IsClassified /-- A primitive Pythagorean triple `x, y, z` is a Pythagorean triple with `x` and `y` coprime. Such a triple is “primitively classified” if there exist coprime integers `m, n` such that either * `x = m ^ 2 - n ^ 2` and `y = 2 * m * n`, or * `x = 2 * m * n` and `y = m ^ 2 - n ^ 2`. -/ @[nolint unusedArguments] def IsPrimitiveClassified (_ : PythagoreanTriple x y z) := ∃ m n : ℤ, (x = m ^ 2 - n ^ 2 ∧ y = 2 * m * n ∨ x = 2 * m * n ∧ y = m ^ 2 - n ^ 2) ∧ Int.gcd m n = 1 ∧ (m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) #align pythagorean_triple.is_primitive_classified PythagoreanTriple.IsPrimitiveClassified theorem mul_isClassified (k : ℤ) (hc : h.IsClassified) : (h.mul k).IsClassified := by obtain ⟨l, m, n, ⟨⟨rfl, rfl⟩ | ⟨rfl, rfl⟩, co⟩⟩ := hc · use k * l, m, n apply And.intro _ co left constructor <;> ring · use k * l, m, n apply And.intro _ co right constructor <;> ring #align pythagorean_triple.mul_is_classified PythagoreanTriple.mul_isClassified theorem even_odd_of_coprime (hc : Int.gcd x y = 1) : x % 2 = 0 ∧ y % 2 = 1 ∨ x % 2 = 1 ∧ y % 2 = 0 := by cases' Int.emod_two_eq_zero_or_one x with hx hx <;> cases' Int.emod_two_eq_zero_or_one y with hy hy -- x even, y even · exfalso apply Nat.not_coprime_of_dvd_of_dvd (by decide : 1 < 2) _ _ hc · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hx · apply Int.natCast_dvd.1 apply Int.dvd_of_emod_eq_zero hy -- x even, y odd · left exact ⟨hx, hy⟩ -- x odd, y even · right exact ⟨hx, hy⟩ -- x odd, y odd · exfalso obtain ⟨x0, y0, rfl, rfl⟩ : ∃ x0 y0, x = x0 * 2 + 1 ∧ y = y0 * 2 + 1 := by cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hx) with x0 hx2 cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hy) with y0 hy2 rw [sub_eq_iff_eq_add] at hx2 hy2 exact ⟨x0, y0, hx2, hy2⟩ apply Int.sq_ne_two_mod_four z rw [show z * z = 4 * (x0 * x0 + x0 + y0 * y0 + y0) + 2 by rw [← h.eq] ring] simp only [Int.add_emod, Int.mul_emod_right, zero_add] decide #align pythagorean_triple.even_odd_of_coprime PythagoreanTriple.even_odd_of_coprime theorem gcd_dvd : (Int.gcd x y : ℤ) ∣ z := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hz, dvd_zero] obtain ⟨k, x0, y0, _, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) rw [Int.gcd_mul_right, h2, Int.natAbs_ofNat, one_mul] rw [← Int.pow_dvd_pow_iff two_ne_zero, sq z, ← h.eq] rw [(by ring : x0 * k * (x0 * k) + y0 * k * (y0 * k) = (k : ℤ) ^ 2 * (x0 * x0 + y0 * y0))] exact dvd_mul_right _ _ #align pythagorean_triple.gcd_dvd PythagoreanTriple.gcd_dvd theorem normalize : PythagoreanTriple (x / Int.gcd x y) (y / Int.gcd x y) (z / Int.gcd x y) := by by_cases h0 : Int.gcd x y = 0 · have hx : x = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_left h0 have hy : y = 0 := by apply Int.natAbs_eq_zero.mp apply Nat.eq_zero_of_gcd_eq_zero_right h0 have hz : z = 0 := by simpa only [PythagoreanTriple, hx, hy, add_zero, zero_eq_mul, mul_zero, or_self_iff] using h simp only [hx, hy, hz, Int.zero_div] exact zero rcases h.gcd_dvd with ⟨z0, rfl⟩ obtain ⟨k, x0, y0, k0, h2, rfl, rfl⟩ : ∃ (k : ℕ) (x0 y0 : _), 0 < k ∧ Int.gcd x0 y0 = 1 ∧ x = x0 * k ∧ y = y0 * k := Int.exists_gcd_one' (Nat.pos_of_ne_zero h0) have hk : (k : ℤ) ≠ 0 := by norm_cast rwa [pos_iff_ne_zero] at k0 rw [Int.gcd_mul_right, h2, Int.natAbs_ofNat, one_mul] at h ⊢ rw [mul_comm x0, mul_comm y0, mul_iff k hk] at h rwa [Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel _ hk, Int.mul_ediv_cancel_left _ hk] #align pythagorean_triple.normalize PythagoreanTriple.normalize theorem isClassified_of_isPrimitiveClassified (hp : h.IsPrimitiveClassified) : h.IsClassified := by obtain ⟨m, n, H⟩ := hp use 1, m, n rcases H with ⟨t, co, _⟩ rw [one_mul, one_mul] exact ⟨t, co⟩ #align pythagorean_triple.is_classified_of_is_primitive_classified PythagoreanTriple.isClassified_of_isPrimitiveClassified theorem isClassified_of_normalize_isPrimitiveClassified (hc : h.normalize.IsPrimitiveClassified) : h.IsClassified := by convert h.normalize.mul_isClassified (Int.gcd x y) (isClassified_of_isPrimitiveClassified h.normalize hc) <;> rw [Int.mul_ediv_cancel'] · exact Int.gcd_dvd_left · exact Int.gcd_dvd_right · exact h.gcd_dvd #align pythagorean_triple.is_classified_of_normalize_is_primitive_classified PythagoreanTriple.isClassified_of_normalize_isPrimitiveClassified theorem ne_zero_of_coprime (hc : Int.gcd x y = 1) : z ≠ 0 := by suffices 0 < z * z by rintro rfl norm_num at this rw [← h.eq, ← sq, ← sq] have hc' : Int.gcd x y ≠ 0 := by rw [hc] exact one_ne_zero cases' Int.ne_zero_of_gcd hc' with hxz hyz · apply lt_add_of_pos_of_le (sq_pos_of_ne_zero hxz) (sq_nonneg y) · apply lt_add_of_le_of_pos (sq_nonneg x) (sq_pos_of_ne_zero hyz) #align pythagorean_triple.ne_zero_of_coprime PythagoreanTriple.ne_zero_of_coprime theorem isPrimitiveClassified_of_coprime_of_zero_left (hc : Int.gcd x y = 1) (hx : x = 0) : h.IsPrimitiveClassified := by subst x change Nat.gcd 0 (Int.natAbs y) = 1 at hc rw [Nat.gcd_zero_left (Int.natAbs y)] at hc cases' Int.natAbs_eq y with hy hy · use 1, 0 rw [hy, hc, Int.gcd_zero_right] decide · use 0, 1 rw [hy, hc, Int.gcd_zero_left] decide #align pythagorean_triple.is_primitive_classified_of_coprime_of_zero_left PythagoreanTriple.isPrimitiveClassified_of_coprime_of_zero_left theorem coprime_of_coprime (hc : Int.gcd x y = 1) : Int.gcd y z = 1 := by by_contra H obtain ⟨p, hp, hpy, hpz⟩ := Nat.Prime.not_coprime_iff_dvd.mp H apply hp.not_dvd_one rw [← hc] apply Nat.dvd_gcd (Int.Prime.dvd_natAbs_of_coe_dvd_sq hp _ _) hpy rw [sq, eq_sub_of_add_eq h] rw [← Int.natCast_dvd] at hpy hpz exact dvd_sub (hpz.mul_right _) (hpy.mul_right _) #align pythagorean_triple.coprime_of_coprime PythagoreanTriple.coprime_of_coprime end PythagoreanTriple section circleEquivGen /-! ### A parametrization of the unit circle For the classification of Pythagorean triples, we will use a parametrization of the unit circle. -/ variable {K : Type*} [Field K] /-- A parameterization of the unit circle that is useful for classifying Pythagorean triples. (To be applied in the case where `K = ℚ`.) -/ def circleEquivGen (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) : K ≃ { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 } where toFun x := ⟨⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩, by field_simp [hk x, div_pow] ring, by simp only [Ne, div_eq_iff (hk x), neg_mul, one_mul, neg_add, sub_eq_add_neg, add_left_inj] simpa only [eq_neg_iff_add_eq_zero, one_pow] using hk 1⟩ invFun p := (p : K × K).1 / ((p : K × K).2 + 1) left_inv x := by have h2 : (1 + 1 : K) = 2 := by norm_num -- Porting note: rfl is not enough to close this have h3 : (2 : K) ≠ 0 := by convert hk 1 rw [one_pow 2, h2] field_simp [hk x, h2, add_assoc, add_comm, add_sub_cancel, mul_comm] right_inv := fun ⟨⟨x, y⟩, hxy, hy⟩ => by change x ^ 2 + y ^ 2 = 1 at hxy have h2 : y + 1 ≠ 0 := mt eq_neg_of_add_eq_zero_left hy have h3 : (y + 1) ^ 2 + x ^ 2 = 2 * (y + 1) := by rw [(add_neg_eq_iff_eq_add.mpr hxy.symm).symm] ring have h4 : (2 : K) ≠ 0 := by convert hk 1 rw [one_pow 2] ring -- Porting note: rfl is not enough to close this simp only [Prod.mk.inj_iff, Subtype.mk_eq_mk] constructor · field_simp [h3] ring · field_simp [h3] rw [← add_neg_eq_iff_eq_add.mpr hxy.symm] ring #align circle_equiv_gen circleEquivGen @[simp] theorem circleEquivGen_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (x : K) : (circleEquivGen hk x : K × K) = ⟨2 * x / (1 + x ^ 2), (1 - x ^ 2) / (1 + x ^ 2)⟩ := rfl #align circle_equiv_apply circleEquivGen_apply @[simp] theorem circleEquivGen_symm_apply (hk : ∀ x : K, 1 + x ^ 2 ≠ 0) (v : { p : K × K // p.1 ^ 2 + p.2 ^ 2 = 1 ∧ p.2 ≠ -1 }) : (circleEquivGen hk).symm v = (v : K × K).1 / ((v : K × K).2 + 1) := rfl #align circle_equiv_symm_apply circleEquivGen_symm_apply end circleEquivGen private theorem coprime_sq_sub_sq_add_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have h2m : (p : ℤ) ∣ 2 * m ^ 2 := by convert dvd_add hp2 hp1 using 1 ring have h2n : (p : ℤ) ∣ 2 * n ^ 2 := by convert dvd_sub hp2 hp1 using 1 ring have hmc : p = 2 ∨ p ∣ Int.natAbs m := prime_two_or_dvd_of_dvd_two_mul_pow_self_two hp h2m have hnc : p = 2 ∨ p ∣ Int.natAbs n := prime_two_or_dvd_of_dvd_two_mul_pow_self_two hp h2n by_cases h2 : p = 2 -- Porting note: norm_num is not enough to close h3 · have h3 : (m ^ 2 + n ^ 2) % 2 = 1 := by simp only [sq, Int.add_emod, Int.mul_emod, hm, hn, dvd_refl, Int.emod_emod_of_dvd] decide have h4 : (m ^ 2 + n ^ 2) % 2 = 0 := by apply Int.emod_eq_zero_of_dvd rwa [h2] at hp2 rw [h4] at h3 exact zero_ne_one h3 · apply hp.not_dvd_one rw [← h] exact Nat.dvd_gcd (Or.resolve_left hmc h2) (Or.resolve_left hnc h2) private theorem coprime_sq_sub_sq_add_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2), add_comm] apply coprime_sq_sub_sq_add_of_even_odd _ hn hm; rwa [Int.gcd_comm] private theorem coprime_sq_sub_mul_of_even_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 0) (hn : n % 2 = 1) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by by_contra H obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp H rw [← Int.natCast_dvd] at hp1 hp2 have hnp : ¬(p : ℤ) ∣ Int.gcd m n := by rw [h] norm_cast exact mt Nat.dvd_one.mp (Nat.Prime.ne_one hp) cases' Int.Prime.dvd_mul hp hp2 with hp2m hpn · rw [Int.natAbs_mul] at hp2m cases' (Nat.Prime.dvd_mul hp).mp hp2m with hp2 hpm · have hp2' : p = 2 := (Nat.le_of_dvd zero_lt_two hp2).antisymm hp.two_le revert hp1 rw [hp2'] apply mt Int.emod_eq_zero_of_dvd -- Porting note: norm_num is not enough to close this simp only [sq, Nat.cast_ofNat, Int.sub_emod, Int.mul_emod, hm, hn, mul_zero, EuclideanDomain.zero_mod, mul_one, zero_sub] decide apply mt (Int.dvd_gcd (Int.natCast_dvd.mpr hpm)) hnp apply or_self_iff.mp apply Int.Prime.dvd_mul' hp rw [(by ring : n * n = -(m ^ 2 - n ^ 2) + m * m)] exact hp1.neg_right.add ((Int.natCast_dvd.2 hpm).mul_right _) rw [Int.gcd_comm] at hnp apply mt (Int.dvd_gcd (Int.natCast_dvd.mpr hpn)) hnp apply or_self_iff.mp apply Int.Prime.dvd_mul' hp rw [(by ring : m * m = m ^ 2 - n ^ 2 + n * n)] apply dvd_add hp1 exact (Int.natCast_dvd.mpr hpn).mul_right n private theorem coprime_sq_sub_mul_of_odd_even {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by rw [Int.gcd, ← Int.natAbs_neg (m ^ 2 - n ^ 2)] rw [(by ring : 2 * m * n = 2 * n * m), (by ring : -(m ^ 2 - n ^ 2) = n ^ 2 - m ^ 2)] apply coprime_sq_sub_mul_of_even_odd _ hn hm; rwa [Int.gcd_comm] private theorem coprime_sq_sub_mul {m n : ℤ} (h : Int.gcd m n = 1) (hmn : m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) : Int.gcd (m ^ 2 - n ^ 2) (2 * m * n) = 1 := by cases' hmn with h1 h2 · exact coprime_sq_sub_mul_of_even_odd h h1.left h1.right · exact coprime_sq_sub_mul_of_odd_even h h2.left h2.right private theorem coprime_sq_sub_sq_sum_of_odd_odd {m n : ℤ} (h : Int.gcd m n = 1) (hm : m % 2 = 1) (hn : n % 2 = 1) : 2 ∣ m ^ 2 + n ^ 2 ∧ 2 ∣ m ^ 2 - n ^ 2 ∧ (m ^ 2 - n ^ 2) / 2 % 2 = 0 ∧ Int.gcd ((m ^ 2 - n ^ 2) / 2) ((m ^ 2 + n ^ 2) / 2) = 1 := by cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hm) with m0 hm2 cases' exists_eq_mul_left_of_dvd (Int.dvd_sub_of_emod_eq hn) with n0 hn2 rw [sub_eq_iff_eq_add] at hm2 hn2 subst m subst n have h1 : (m0 * 2 + 1) ^ 2 + (n0 * 2 + 1) ^ 2 = 2 * (2 * (m0 ^ 2 + n0 ^ 2 + m0 + n0) + 1) := by ring have h2 : (m0 * 2 + 1) ^ 2 - (n0 * 2 + 1) ^ 2 = 2 * (2 * (m0 ^ 2 - n0 ^ 2 + m0 - n0)) := by ring have h3 : ((m0 * 2 + 1) ^ 2 - (n0 * 2 + 1) ^ 2) / 2 % 2 = 0 := by rw [h2, Int.mul_ediv_cancel_left, Int.mul_emod_right] decide refine ⟨⟨_, h1⟩, ⟨_, h2⟩, h3, ?_⟩ have h20 : (2 : ℤ) ≠ 0 := by decide rw [h1, h2, Int.mul_ediv_cancel_left _ h20, Int.mul_ediv_cancel_left _ h20] by_contra h4 obtain ⟨p, hp, hp1, hp2⟩ := Nat.Prime.not_coprime_iff_dvd.mp h4 apply hp.not_dvd_one rw [← h] rw [← Int.natCast_dvd] at hp1 hp2 apply Nat.dvd_gcd · apply Int.Prime.dvd_natAbs_of_coe_dvd_sq hp convert dvd_add hp1 hp2 ring · apply Int.Prime.dvd_natAbs_of_coe_dvd_sq hp convert dvd_sub hp2 hp1 ring namespace PythagoreanTriple variable {x y z : ℤ} (h : PythagoreanTriple x y z)
Mathlib/NumberTheory/PythagoreanTriples.lean
445
460
theorem isPrimitiveClassified_aux (hc : x.gcd y = 1) (hzpos : 0 < z) {m n : ℤ} (hm2n2 : 0 < m ^ 2 + n ^ 2) (hv2 : (x : ℚ) / z = 2 * m * n / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (hw2 : (y : ℚ) / z = ((m : ℚ) ^ 2 - (n : ℚ) ^ 2) / ((m : ℚ) ^ 2 + (n : ℚ) ^ 2)) (H : Int.gcd (m ^ 2 - n ^ 2) (m ^ 2 + n ^ 2) = 1) (co : Int.gcd m n = 1) (pp : m % 2 = 0 ∧ n % 2 = 1 ∨ m % 2 = 1 ∧ n % 2 = 0) : h.IsPrimitiveClassified := by
have hz : z ≠ 0 := ne_of_gt hzpos have h2 : y = m ^ 2 - n ^ 2 ∧ z = m ^ 2 + n ^ 2 := by apply Rat.div_int_inj hzpos hm2n2 (h.coprime_of_coprime hc) H rw [hw2] norm_cast use m, n apply And.intro _ (And.intro co pp) right refine ⟨?_, h2.left⟩ rw [← Rat.coe_int_inj _ _, ← div_left_inj' ((mt (Rat.coe_int_inj z 0).mp) hz), hv2, h2.right] norm_cast
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Mathlib.Data.Nat.Defs import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Init.Data.List.Basic import Mathlib.Init.Data.List.Instances import Mathlib.Init.Data.List.Lemmas import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common #align_import data.list.basic from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Basic properties of lists -/ assert_not_exists Set.range assert_not_exists GroupWithZero assert_not_exists Ring open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} -- Porting note: Delete this attribute -- attribute [inline] List.head! /-- There is only one list of an empty type -/ instance uniqueOfIsEmpty [IsEmpty α] : Unique (List α) := { instInhabitedList with uniq := fun l => match l with | [] => rfl | a :: _ => isEmptyElim a } #align list.unique_of_is_empty List.uniqueOfIsEmpty instance : Std.LawfulIdentity (α := List α) Append.append [] where left_id := nil_append right_id := append_nil instance : Std.Associative (α := List α) Append.append where assoc := append_assoc #align list.cons_ne_nil List.cons_ne_nil #align list.cons_ne_self List.cons_ne_self #align list.head_eq_of_cons_eq List.head_eq_of_cons_eqₓ -- implicits order #align list.tail_eq_of_cons_eq List.tail_eq_of_cons_eqₓ -- implicits order @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq #align list.cons_injective List.cons_injective #align list.cons_inj List.cons_inj #align list.cons_eq_cons List.cons_eq_cons theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 #align list.singleton_injective List.singleton_injective theorem singleton_inj {a b : α} : [a] = [b] ↔ a = b := singleton_injective.eq_iff #align list.singleton_inj List.singleton_inj #align list.exists_cons_of_ne_nil List.exists_cons_of_ne_nil theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons #align list.set_of_mem_cons List.set_of_mem_cons /-! ### mem -/ #align list.mem_singleton_self List.mem_singleton_self #align list.eq_of_mem_singleton List.eq_of_mem_singleton #align list.mem_singleton List.mem_singleton #align list.mem_of_mem_cons_of_mem List.mem_of_mem_cons_of_mem theorem _root_.Decidable.List.eq_or_ne_mem_of_mem [DecidableEq α] {a b : α} {l : List α} (h : a ∈ b :: l) : a = b ∨ a ≠ b ∧ a ∈ l := by by_cases hab : a = b · exact Or.inl hab · exact ((List.mem_cons.1 h).elim Or.inl (fun h => Or.inr ⟨hab, h⟩)) #align decidable.list.eq_or_ne_mem_of_mem Decidable.List.eq_or_ne_mem_of_mem #align list.eq_or_ne_mem_of_mem List.eq_or_ne_mem_of_mem #align list.not_mem_append List.not_mem_append #align list.ne_nil_of_mem List.ne_nil_of_mem lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] @[deprecated (since := "2024-03-23")] alias mem_split := append_of_mem #align list.mem_split List.append_of_mem #align list.mem_of_ne_of_mem List.mem_of_ne_of_mem #align list.ne_of_not_mem_cons List.ne_of_not_mem_cons #align list.not_mem_of_not_mem_cons List.not_mem_of_not_mem_cons #align list.not_mem_cons_of_ne_of_not_mem List.not_mem_cons_of_ne_of_not_mem #align list.ne_and_not_mem_of_not_mem_cons List.ne_and_not_mem_of_not_mem_cons #align list.mem_map List.mem_map #align list.exists_of_mem_map List.exists_of_mem_map #align list.mem_map_of_mem List.mem_map_of_memₓ -- implicits order -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- https://github.com/leanprover/std4/issues/207 @[simp 1100, nolint simpNF] theorem mem_map_of_injective {f : α → β} (H : Injective f) {a : α} {l : List α} : f a ∈ map f l ↔ a ∈ l := ⟨fun m => let ⟨_, m', e⟩ := exists_of_mem_map m; H e ▸ m', mem_map_of_mem _⟩ #align list.mem_map_of_injective List.mem_map_of_injective @[simp] theorem _root_.Function.Involutive.exists_mem_and_apply_eq_iff {f : α → α} (hf : Function.Involutive f) (x : α) (l : List α) : (∃ y : α, y ∈ l ∧ f y = x) ↔ f x ∈ l := ⟨by rintro ⟨y, h, rfl⟩; rwa [hf y], fun h => ⟨f x, h, hf _⟩⟩ #align function.involutive.exists_mem_and_apply_eq_iff Function.Involutive.exists_mem_and_apply_eq_iff theorem mem_map_of_involutive {f : α → α} (hf : Involutive f) {a : α} {l : List α} : a ∈ map f l ↔ f a ∈ l := by rw [mem_map, hf.exists_mem_and_apply_eq_iff] #align list.mem_map_of_involutive List.mem_map_of_involutive #align list.forall_mem_map_iff List.forall_mem_map_iffₓ -- universe order #align list.map_eq_nil List.map_eq_nilₓ -- universe order attribute [simp] List.mem_join #align list.mem_join List.mem_join #align list.exists_of_mem_join List.exists_of_mem_join #align list.mem_join_of_mem List.mem_join_of_memₓ -- implicits order attribute [simp] List.mem_bind #align list.mem_bind List.mem_bindₓ -- implicits order -- Porting note: bExists in Lean3, And in Lean4 #align list.exists_of_mem_bind List.exists_of_mem_bindₓ -- implicits order #align list.mem_bind_of_mem List.mem_bind_of_memₓ -- implicits order #align list.bind_map List.bind_mapₓ -- implicits order theorem map_bind (g : β → List γ) (f : α → β) : ∀ l : List α, (List.map f l).bind g = l.bind fun a => g (f a) | [] => rfl | a :: l => by simp only [cons_bind, map_cons, map_bind _ _ l] #align list.map_bind List.map_bind /-! ### length -/ #align list.length_eq_zero List.length_eq_zero #align list.length_singleton List.length_singleton #align list.length_pos_of_mem List.length_pos_of_mem #align list.exists_mem_of_length_pos List.exists_mem_of_length_pos #align list.length_pos_iff_exists_mem List.length_pos_iff_exists_mem alias ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ := length_pos #align list.ne_nil_of_length_pos List.ne_nil_of_length_pos #align list.length_pos_of_ne_nil List.length_pos_of_ne_nil theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ #align list.length_pos_iff_ne_nil List.length_pos_iff_ne_nil #align list.exists_mem_of_ne_nil List.exists_mem_of_ne_nil #align list.length_eq_one List.length_eq_one theorem exists_of_length_succ {n} : ∀ l : List α, l.length = n + 1 → ∃ h t, l = h :: t | [], H => absurd H.symm <| succ_ne_zero n | h :: t, _ => ⟨h, t, rfl⟩ #align list.exists_of_length_succ List.exists_of_length_succ @[simp] lemma length_injective_iff : Injective (List.length : List α → ℕ) ↔ Subsingleton α := by constructor · intro h; refine ⟨fun x y => ?_⟩; (suffices [x] = [y] by simpa using this); apply h; rfl · intros hα l1 l2 hl induction l1 generalizing l2 <;> cases l2 · rfl · cases hl · cases hl · next ih _ _ => congr · exact Subsingleton.elim _ _ · apply ih; simpa using hl #align list.length_injective_iff List.length_injective_iff @[simp default+1] -- Porting note: this used to be just @[simp] lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance #align list.length_injective List.length_injective theorem length_eq_two {l : List α} : l.length = 2 ↔ ∃ a b, l = [a, b] := ⟨fun _ => let [a, b] := l; ⟨a, b, rfl⟩, fun ⟨_, _, e⟩ => e ▸ rfl⟩ #align list.length_eq_two List.length_eq_two theorem length_eq_three {l : List α} : l.length = 3 ↔ ∃ a b c, l = [a, b, c] := ⟨fun _ => let [a, b, c] := l; ⟨a, b, c, rfl⟩, fun ⟨_, _, _, e⟩ => e ▸ rfl⟩ #align list.length_eq_three List.length_eq_three #align list.sublist.length_le List.Sublist.length_le /-! ### set-theoretic notation of lists -/ -- ADHOC Porting note: instance from Lean3 core instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ #align list.has_singleton List.instSingletonList -- ADHOC Porting note: instance from Lean3 core instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ -- ADHOC Porting note: instance from Lean3 core instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_emptyc_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg (not_mem_nil _) } #align list.empty_eq List.empty_eq theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl #align list.singleton_eq List.singleton_eq theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h #align list.insert_neg List.insert_neg theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h #align list.insert_pos List.insert_pos theorem doubleton_eq [DecidableEq α] {x y : α} (h : x ≠ y) : ({x, y} : List α) = [x, y] := by rw [insert_neg, singleton_eq] rwa [singleton_eq, mem_singleton] #align list.doubleton_eq List.doubleton_eq /-! ### bounded quantifiers over lists -/ #align list.forall_mem_nil List.forall_mem_nil #align list.forall_mem_cons List.forall_mem_cons theorem forall_mem_of_forall_mem_cons {p : α → Prop} {a : α} {l : List α} (h : ∀ x ∈ a :: l, p x) : ∀ x ∈ l, p x := (forall_mem_cons.1 h).2 #align list.forall_mem_of_forall_mem_cons List.forall_mem_of_forall_mem_cons #align list.forall_mem_singleton List.forall_mem_singleton #align list.forall_mem_append List.forall_mem_append #align list.not_exists_mem_nil List.not_exists_mem_nilₓ -- bExists change -- Porting note: bExists in Lean3 and And in Lean4 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self _ _, h⟩ #align list.exists_mem_cons_of List.exists_mem_cons_ofₓ -- bExists change -- Porting note: bExists in Lean3 and And in Lean4 theorem exists_mem_cons_of_exists {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x := fun ⟨x, xl, px⟩ => ⟨x, mem_cons_of_mem _ xl, px⟩ #align list.exists_mem_cons_of_exists List.exists_mem_cons_of_existsₓ -- bExists change -- Porting note: bExists in Lean3 and And in Lean4 theorem or_exists_of_exists_mem_cons {p : α → Prop} {a : α} {l : List α} : (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x := fun ⟨x, xal, px⟩ => Or.elim (eq_or_mem_of_mem_cons xal) (fun h : x = a => by rw [← h]; left; exact px) fun h : x ∈ l => Or.inr ⟨x, h, px⟩ #align list.or_exists_of_exists_mem_cons List.or_exists_of_exists_mem_consₓ -- bExists change theorem exists_mem_cons_iff (p : α → Prop) (a : α) (l : List α) : (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x := Iff.intro or_exists_of_exists_mem_cons fun h => Or.elim h (exists_mem_cons_of l) exists_mem_cons_of_exists #align list.exists_mem_cons_iff List.exists_mem_cons_iff /-! ### list subset -/ instance : IsTrans (List α) Subset where trans := fun _ _ _ => List.Subset.trans #align list.subset_def List.subset_def #align list.subset_append_of_subset_left List.subset_append_of_subset_left #align list.subset_append_of_subset_right List.subset_append_of_subset_right #align list.cons_subset List.cons_subset theorem cons_subset_of_subset_of_mem {a : α} {l m : List α} (ainm : a ∈ m) (lsubm : l ⊆ m) : a::l ⊆ m := cons_subset.2 ⟨ainm, lsubm⟩ #align list.cons_subset_of_subset_of_mem List.cons_subset_of_subset_of_mem theorem append_subset_of_subset_of_subset {l₁ l₂ l : List α} (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) : l₁ ++ l₂ ⊆ l := fun _ h ↦ (mem_append.1 h).elim (@l₁subl _) (@l₂subl _) #align list.append_subset_of_subset_of_subset List.append_subset_of_subset_of_subset -- Porting note: in Batteries #align list.append_subset_iff List.append_subset alias ⟨eq_nil_of_subset_nil, _⟩ := subset_nil #align list.eq_nil_of_subset_nil List.eq_nil_of_subset_nil #align list.eq_nil_iff_forall_not_mem List.eq_nil_iff_forall_not_mem #align list.map_subset List.map_subset theorem map_subset_iff {l₁ l₂ : List α} (f : α → β) (h : Injective f) : map f l₁ ⊆ map f l₂ ↔ l₁ ⊆ l₂ := by refine ⟨?_, map_subset f⟩; intro h2 x hx rcases mem_map.1 (h2 (mem_map_of_mem f hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' #align list.map_subset_iff List.map_subset_iff /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl #align list.append_eq_has_append List.append_eq_has_append #align list.singleton_append List.singleton_append #align list.append_ne_nil_of_ne_nil_left List.append_ne_nil_of_ne_nil_left #align list.append_ne_nil_of_ne_nil_right List.append_ne_nil_of_ne_nil_right #align list.append_eq_nil List.append_eq_nil -- Porting note: in Batteries #align list.nil_eq_append_iff List.nil_eq_append @[deprecated (since := "2024-03-24")] alias append_eq_cons_iff := append_eq_cons #align list.append_eq_cons_iff List.append_eq_cons @[deprecated (since := "2024-03-24")] alias cons_eq_append_iff := cons_eq_append #align list.cons_eq_append_iff List.cons_eq_append #align list.append_eq_append_iff List.append_eq_append_iff #align list.take_append_drop List.take_append_drop #align list.append_inj List.append_inj #align list.append_inj_right List.append_inj_rightₓ -- implicits order #align list.append_inj_left List.append_inj_leftₓ -- implicits order #align list.append_inj' List.append_inj'ₓ -- implicits order #align list.append_inj_right' List.append_inj_right'ₓ -- implicits order #align list.append_inj_left' List.append_inj_left'ₓ -- implicits order @[deprecated (since := "2024-01-18")] alias append_left_cancel := append_cancel_left #align list.append_left_cancel List.append_cancel_left @[deprecated (since := "2024-01-18")] alias append_right_cancel := append_cancel_right #align list.append_right_cancel List.append_cancel_right @[simp] theorem append_left_eq_self {x y : List α} : x ++ y = y ↔ x = [] := by rw [← append_left_inj (s₁ := x), nil_append] @[simp] theorem self_eq_append_left {x y : List α} : y = x ++ y ↔ x = [] := by rw [eq_comm, append_left_eq_self] @[simp] theorem append_right_eq_self {x y : List α} : x ++ y = x ↔ y = [] := by rw [← append_right_inj (t₁ := y), append_nil] @[simp] theorem self_eq_append_right {x y : List α} : x = x ++ y ↔ y = [] := by rw [eq_comm, append_right_eq_self] theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left #align list.append_right_injective List.append_right_injective #align list.append_right_inj List.append_right_inj theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right #align list.append_left_injective List.append_left_injective #align list.append_left_inj List.append_left_inj #align list.map_eq_append_split List.map_eq_append_split /-! ### replicate -/ @[simp] lemma replicate_zero (a : α) : replicate 0 a = [] := rfl #align list.replicate_zero List.replicate_zero attribute [simp] replicate_succ #align list.replicate_succ List.replicate_succ lemma replicate_one (a : α) : replicate 1 a = [a] := rfl #align list.replicate_one List.replicate_one #align list.length_replicate List.length_replicate #align list.mem_replicate List.mem_replicate #align list.eq_of_mem_replicate List.eq_of_mem_replicate theorem eq_replicate_length {a : α} : ∀ {l : List α}, l = replicate l.length a ↔ ∀ b ∈ l, b = a | [] => by simp | (b :: l) => by simp [eq_replicate_length] #align list.eq_replicate_length List.eq_replicate_length #align list.eq_replicate_of_mem List.eq_replicate_of_mem #align list.eq_replicate List.eq_replicate theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by induction m <;> simp [*, succ_add, replicate] #align list.replicate_add List.replicate_add theorem replicate_succ' (n) (a : α) : replicate (n + 1) a = replicate n a ++ [a] := replicate_add n 1 a #align list.replicate_succ' List.replicate_succ' theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) #align list.replicate_subset_singleton List.replicate_subset_singleton theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate, subset_def, mem_singleton, exists_eq_left'] #align list.subset_singleton_iff List.subset_singleton_iff @[simp] theorem map_replicate (f : α → β) (n) (a : α) : map f (replicate n a) = replicate n (f a) := by induction n <;> [rfl; simp only [*, replicate, map]] #align list.map_replicate List.map_replicate @[simp] theorem tail_replicate (a : α) (n) : tail (replicate n a) = replicate (n - 1) a := by cases n <;> rfl #align list.tail_replicate List.tail_replicate @[simp] theorem join_replicate_nil (n : ℕ) : join (replicate n []) = @nil α := by induction n <;> [rfl; simp only [*, replicate, join, append_nil]] #align list.join_replicate_nil List.join_replicate_nil theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ #align list.replicate_right_injective List.replicate_right_injective theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff #align list.replicate_right_inj List.replicate_right_inj @[simp] theorem replicate_right_inj' {a b : α} : ∀ {n}, replicate n a = replicate n b ↔ n = 0 ∨ a = b | 0 => by simp | n + 1 => (replicate_right_inj n.succ_ne_zero).trans <| by simp only [n.succ_ne_zero, false_or] #align list.replicate_right_inj' List.replicate_right_inj' theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate · a) #align list.replicate_left_injective List.replicate_left_injective @[simp] theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff #align list.replicate_left_inj List.replicate_left_inj @[simp] theorem head_replicate (n : ℕ) (a : α) (h) : head (replicate n a) h = a := by cases n <;> simp at h ⊢ /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp #align list.mem_pure List.mem_pure /-! ### bind -/ @[simp] theorem bind_eq_bind {α β} (f : α → List β) (l : List α) : l >>= f = l.bind f := rfl #align list.bind_eq_bind List.bind_eq_bind #align list.bind_append List.append_bind /-! ### concat -/ #align list.concat_nil List.concat_nil #align list.concat_cons List.concat_cons #align list.concat_eq_append List.concat_eq_append #align list.init_eq_of_concat_eq List.init_eq_of_concat_eq #align list.last_eq_of_concat_eq List.last_eq_of_concat_eq #align list.concat_ne_nil List.concat_ne_nil #align list.concat_append List.concat_append #align list.length_concat List.length_concat #align list.append_concat List.append_concat /-! ### reverse -/ #align list.reverse_nil List.reverse_nil #align list.reverse_core List.reverseAux -- Porting note: Do we need this? attribute [local simp] reverseAux #align list.reverse_cons List.reverse_cons #align list.reverse_core_eq List.reverseAux_eq theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] #align list.reverse_cons' List.reverse_cons' theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl -- Porting note (#10618): simp can prove this -- @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl #align list.reverse_singleton List.reverse_singleton #align list.reverse_append List.reverse_append #align list.reverse_concat List.reverse_concat #align list.reverse_reverse List.reverse_reverse @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse #align list.reverse_involutive List.reverse_involutive @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective #align list.reverse_injective List.reverse_injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective #align list.reverse_surjective List.reverse_surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective #align list.reverse_bijective List.reverse_bijective @[simp] theorem reverse_inj {l₁ l₂ : List α} : reverse l₁ = reverse l₂ ↔ l₁ = l₂ := reverse_injective.eq_iff #align list.reverse_inj List.reverse_inj theorem reverse_eq_iff {l l' : List α} : l.reverse = l' ↔ l = l'.reverse := reverse_involutive.eq_iff #align list.reverse_eq_iff List.reverse_eq_iff #align list.reverse_eq_nil List.reverse_eq_nil_iff theorem concat_eq_reverse_cons (a : α) (l : List α) : concat l a = reverse (a :: reverse l) := by simp only [concat_eq_append, reverse_cons, reverse_reverse] #align list.concat_eq_reverse_cons List.concat_eq_reverse_cons #align list.length_reverse List.length_reverse -- Porting note: This one was @[simp] in mathlib 3, -- but Lean contains a competing simp lemma reverse_map. -- For now we remove @[simp] to avoid simplification loops. -- TODO: Change Lean lemma to match mathlib 3? theorem map_reverse (f : α → β) (l : List α) : map f (reverse l) = reverse (map f l) := (reverse_map f l).symm #align list.map_reverse List.map_reverse theorem map_reverseAux (f : α → β) (l₁ l₂ : List α) : map f (reverseAux l₁ l₂) = reverseAux (map f l₁) (map f l₂) := by simp only [reverseAux_eq, map_append, map_reverse] #align list.map_reverse_core List.map_reverseAux #align list.mem_reverse List.mem_reverse @[simp] theorem reverse_replicate (n) (a : α) : reverse (replicate n a) = replicate n a := eq_replicate.2 ⟨by rw [length_reverse, length_replicate], fun b h => eq_of_mem_replicate (mem_reverse.1 h)⟩ #align list.reverse_replicate List.reverse_replicate /-! ### empty -/ -- Porting note: this does not work as desired -- attribute [simp] List.isEmpty theorem isEmpty_iff_eq_nil {l : List α} : l.isEmpty ↔ l = [] := by cases l <;> simp [isEmpty] #align list.empty_iff_eq_nil List.isEmpty_iff_eq_nil /-! ### dropLast -/ #align list.length_init List.length_dropLast /-! ### getLast -/ @[simp] theorem getLast_cons {a : α} {l : List α} : ∀ h : l ≠ nil, getLast (a :: l) (cons_ne_nil a l) = getLast l h := by induction l <;> intros · contradiction · rfl #align list.last_cons List.getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_ne_nil_right l _ (cons_ne_nil a _)) = a := by simp only [getLast_append] #align list.last_append_singleton List.getLast_append_singleton -- Porting note: name should be fixed upstream theorem getLast_append' (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_ne_nil_right l₁ l₂ h) = getLast l₂ h := by induction' l₁ with _ _ ih · simp · simp only [cons_append] rw [List.getLast_cons] exact ih #align list.last_append List.getLast_append' theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (concat_ne_nil a l) = a := getLast_concat .. #align list.last_concat List.getLast_concat' @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl #align list.last_singleton List.getLast_singleton' -- Porting note (#10618): simp can prove this -- @[simp] theorem getLast_cons_cons (a₁ a₂ : α) (l : List α) : getLast (a₁ :: a₂ :: l) (cons_ne_nil _ _) = getLast (a₂ :: l) (cons_ne_nil a₂ l) := rfl #align list.last_cons_cons List.getLast_cons_cons theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl h | [a], h => rfl | a :: b :: l, h => by rw [dropLast_cons₂, cons_append, getLast_cons (cons_ne_nil _ _)] congr exact dropLast_append_getLast (cons_ne_nil b l) #align list.init_append_last List.dropLast_append_getLast theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl #align list.last_congr List.getLast_congr #align list.last_mem List.getLast_mem theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_succ (length_replicate _ _)) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ #align list.last_replicate_succ List.getLast_replicate_succ /-! ### getLast? -/ -- Porting note: Moved earlier in file, for use in subsequent lemmas. @[simp] theorem getLast?_cons_cons (a b : α) (l : List α) : getLast? (a :: b :: l) = getLast? (b :: l) := rfl @[simp] theorem getLast?_isNone : ∀ {l : List α}, (getLast? l).isNone ↔ l = [] | [] => by simp | [a] => by simp | a :: b :: l => by simp [@getLast?_isNone (b :: l)] #align list.last'_is_none List.getLast?_isNone @[simp] theorem getLast?_isSome : ∀ {l : List α}, l.getLast?.isSome ↔ l ≠ [] | [] => by simp | [a] => by simp | a :: b :: l => by simp [@getLast?_isSome (b :: l)] #align list.last'_is_some List.getLast?_isSome theorem mem_getLast?_eq_getLast : ∀ {l : List α} {x : α}, x ∈ l.getLast? → ∃ h, x = getLast l h | [], x, hx => False.elim <| by simp at hx | [a], x, hx => have : a = x := by simpa using hx this ▸ ⟨cons_ne_nil a [], rfl⟩ | a :: b :: l, x, hx => by rw [getLast?_cons_cons] at hx rcases mem_getLast?_eq_getLast hx with ⟨_, h₂⟩ use cons_ne_nil _ _ assumption #align list.mem_last'_eq_last List.mem_getLast?_eq_getLast theorem getLast?_eq_getLast_of_ne_nil : ∀ {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h) | [], h => (h rfl).elim | [_], _ => rfl | _ :: b :: l, _ => @getLast?_eq_getLast_of_ne_nil (b :: l) (cons_ne_nil _ _) #align list.last'_eq_last_of_ne_nil List.getLast?_eq_getLast_of_ne_nil theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h #align list.mem_last'_cons List.mem_getLast?_cons theorem mem_of_mem_getLast? {l : List α} {a : α} (ha : a ∈ l.getLast?) : a ∈ l := let ⟨_, h₂⟩ := mem_getLast?_eq_getLast ha h₂.symm ▸ getLast_mem _ #align list.mem_of_mem_last' List.mem_of_mem_getLast? theorem dropLast_append_getLast? : ∀ {l : List α}, ∀ a ∈ l.getLast?, dropLast l ++ [a] = l | [], a, ha => (Option.not_mem_none a ha).elim | [a], _, rfl => rfl | a :: b :: l, c, hc => by rw [getLast?_cons_cons] at hc rw [dropLast_cons₂, cons_append, dropLast_append_getLast? _ hc] #align list.init_append_last' List.dropLast_append_getLast? theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [a] => rfl | [a, b] => rfl | [a, b, c] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] #align list.ilast_eq_last' List.getLastI_eq_getLast? @[simp] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], a, l₂ => rfl | [b], a, l₂ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] #align list.last'_append_cons List.getLast?_append_cons #align list.last'_cons_cons List.getLast?_cons_cons theorem getLast?_append_of_ne_nil (l₁ : List α) : ∀ {l₂ : List α} (_ : l₂ ≠ []), getLast? (l₁ ++ l₂) = getLast? l₂ | [], hl₂ => by contradiction | b :: l₂, _ => getLast?_append_cons l₁ b l₂ #align list.last'_append_of_ne_nil List.getLast?_append_of_ne_nil theorem getLast?_append {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h #align list.last'_append List.getLast?_append /-! ### head(!?) and tail -/ @[simp] theorem head!_nil [Inhabited α] : ([] : List α).head! = default := rfl @[simp] theorem head_cons_tail (x : List α) (h : x ≠ []) : x.head h :: x.tail = x := by cases x <;> simp at h ⊢ theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl #align list.head_eq_head' List.head!_eq_head? theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ #align list.surjective_head List.surjective_head! theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ #align list.surjective_head' List.surjective_head? theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ #align list.surjective_tail List.surjective_tail theorem eq_cons_of_mem_head? {x : α} : ∀ {l : List α}, x ∈ l.head? → l = x :: tail l | [], h => (Option.not_mem_none _ h).elim | a :: l, h => by simp only [head?, Option.mem_def, Option.some_inj] at h exact h ▸ rfl #align list.eq_cons_of_mem_head' List.eq_cons_of_mem_head? theorem mem_of_mem_head? {x : α} {l : List α} (h : x ∈ l.head?) : x ∈ l := (eq_cons_of_mem_head? h).symm ▸ mem_cons_self _ _ #align list.mem_of_mem_head' List.mem_of_mem_head? @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl #align list.head_cons List.head!_cons #align list.tail_nil List.tail_nil #align list.tail_cons List.tail_cons @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl #align list.head_append List.head!_append theorem head?_append {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h #align list.head'_append List.head?_append theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl #align list.head'_append_of_ne_nil List.head?_append_of_ne_nil theorem tail_append_singleton_of_ne_nil {a : α} {l : List α} (h : l ≠ nil) : tail (l ++ [a]) = tail l ++ [a] := by induction l · contradiction · rw [tail, cons_append, tail] #align list.tail_append_singleton_of_ne_nil List.tail_append_singleton_of_ne_nil theorem cons_head?_tail : ∀ {l : List α} {a : α}, a ∈ head? l → a :: tail l = l | [], a, h => by contradiction | b :: l, a, h => by simp? at h says simp only [head?_cons, Option.mem_def, Option.some.injEq] at h simp [h] #align list.cons_head'_tail List.cons_head?_tail theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | a :: l, _ => rfl #align list.head_mem_head' List.head!_mem_head? theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) #align list.cons_head_tail List.cons_head!_tail theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' := mem_cons_self l.head! l.tail rwa [cons_head!_tail h] at h' #align list.head_mem_self List.head!_mem_self theorem head_mem {l : List α} : ∀ (h : l ≠ nil), l.head h ∈ l := by cases l <;> simp @[simp] theorem head?_map (f : α → β) (l) : head? (map f l) = (head? l).map f := by cases l <;> rfl #align list.head'_map List.head?_map theorem tail_append_of_ne_nil (l l' : List α) (h : l ≠ []) : (l ++ l').tail = l.tail ++ l' := by cases l · contradiction · simp #align list.tail_append_of_ne_nil List.tail_append_of_ne_nil #align list.nth_le_eq_iff List.get_eq_iff theorem get_eq_get? (l : List α) (i : Fin l.length) : l.get i = (l.get? i).get (by simp [get?_eq_get]) := by simp [get_eq_iff] #align list.some_nth_le_eq List.get?_eq_get section deprecated set_option linter.deprecated false -- TODO(Mario): make replacements for theorems in this section /-- nth element of a list `l` given `n < l.length`. -/ @[deprecated get (since := "2023-01-05")] def nthLe (l : List α) (n) (h : n < l.length) : α := get l ⟨n, h⟩ #align list.nth_le List.nthLe @[simp] theorem nthLe_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.nthLe i h = l.nthLe (i + 1) h' := by cases l <;> [cases h; rfl] #align list.nth_le_tail List.nthLe_tail theorem nthLe_cons_aux {l : List α} {a : α} {n} (hn : n ≠ 0) (h : n < (a :: l).length) : n - 1 < l.length := by contrapose! h rw [length_cons] omega #align list.nth_le_cons_aux List.nthLe_cons_aux theorem nthLe_cons {l : List α} {a : α} {n} (hl) : (a :: l).nthLe n hl = if hn : n = 0 then a else l.nthLe (n - 1) (nthLe_cons_aux hn hl) := by split_ifs with h · simp [nthLe, h] cases l · rw [length_singleton, Nat.lt_succ_iff] at hl omega cases n · contradiction rfl #align list.nth_le_cons List.nthLe_cons end deprecated -- Porting note: List.modifyHead has @[simp], and Lean 4 treats this as -- an invitation to unfold modifyHead in any context, -- not just use the equational lemmas. -- @[simp] @[simp 1100, nolint simpNF] theorem modifyHead_modifyHead (l : List α) (f g : α → α) : (l.modifyHead f).modifyHead g = l.modifyHead (g ∘ f) := by cases l <;> simp #align list.modify_head_modify_head List.modifyHead_modifyHead /-! ### Induction from the right -/ /-- Induction principle from the right for lists: if a property holds for the empty list, and for `l ++ [a]` if it holds for `l`, then it holds for all lists. The principle is given for a `Sort`-valued predicate, i.e., it can also be used to construct data. -/ @[elab_as_elim] def reverseRecOn {motive : List α → Sort*} (l : List α) (nil : motive []) (append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : motive l := match h : reverse l with | [] => cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <| nil | head :: tail => cast (congr_arg motive <| by simpa using congr(reverse $h.symm)) <| append_singleton _ head <| reverseRecOn (reverse tail) nil append_singleton termination_by l.length decreasing_by simp_wf rw [← length_reverse l, h, length_cons] simp [Nat.lt_succ] #align list.reverse_rec_on List.reverseRecOn @[simp] theorem reverseRecOn_nil {motive : List α → Sort*} (nil : motive []) (append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : reverseRecOn [] nil append_singleton = nil := reverseRecOn.eq_1 .. -- `unusedHavesSuffices` is getting confused by the unfolding of `reverseRecOn` @[simp, nolint unusedHavesSuffices] theorem reverseRecOn_concat {motive : List α → Sort*} (x : α) (xs : List α) (nil : motive []) (append_singleton : ∀ (l : List α) (a : α), motive l → motive (l ++ [a])) : reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton = append_singleton _ _ (reverseRecOn (motive := motive) xs nil append_singleton) := by suffices ∀ ys (h : reverse (reverse xs) = ys), reverseRecOn (motive := motive) (xs ++ [x]) nil append_singleton = cast (by simp [(reverse_reverse _).symm.trans h]) (append_singleton _ x (reverseRecOn (motive := motive) ys nil append_singleton)) by exact this _ (reverse_reverse xs) intros ys hy conv_lhs => unfold reverseRecOn split next h => simp at h next heq => revert heq simp only [reverse_append, reverse_cons, reverse_nil, nil_append, singleton_append, cons.injEq] rintro ⟨rfl, rfl⟩ subst ys rfl /-- Bidirectional induction principle for lists: if a property holds for the empty list, the singleton list, and `a :: (l ++ [b])` from `l`, then it holds for all lists. This can be used to prove statements about palindromes. The principle is given for a `Sort`-valued predicate, i.e., it can also be used to construct data. -/ @[elab_as_elim] def bidirectionalRec {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a]) (cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) : ∀ l, motive l | [] => nil | [a] => singleton a | a :: b :: l => let l' := dropLast (b :: l) let b' := getLast (b :: l) (cons_ne_nil _ _) cast (by rw [← dropLast_append_getLast (cons_ne_nil b l)]) <| cons_append a l' b' (bidirectionalRec nil singleton cons_append l') termination_by l => l.length #align list.bidirectional_rec List.bidirectionalRecₓ -- universe order @[simp] theorem bidirectionalRec_nil {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a]) (cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) : bidirectionalRec nil singleton cons_append [] = nil := bidirectionalRec.eq_1 .. @[simp] theorem bidirectionalRec_singleton {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a]) (cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) (a : α): bidirectionalRec nil singleton cons_append [a] = singleton a := by simp [bidirectionalRec] @[simp] theorem bidirectionalRec_cons_append {motive : List α → Sort*} (nil : motive []) (singleton : ∀ a : α, motive [a]) (cons_append : ∀ (a : α) (l : List α) (b : α), motive l → motive (a :: (l ++ [b]))) (a : α) (l : List α) (b : α) : bidirectionalRec nil singleton cons_append (a :: (l ++ [b])) = cons_append a l b (bidirectionalRec nil singleton cons_append l) := by conv_lhs => unfold bidirectionalRec cases l with | nil => rfl | cons x xs => simp only [List.cons_append] dsimp only [← List.cons_append] suffices ∀ (ys init : List α) (hinit : init = ys) (last : α) (hlast : last = b), (cons_append a init last (bidirectionalRec nil singleton cons_append init)) = cast (congr_arg motive <| by simp [hinit, hlast]) (cons_append a ys b (bidirectionalRec nil singleton cons_append ys)) by rw [this (x :: xs) _ (by rw [dropLast_append_cons, dropLast_single, append_nil]) _ (by simp)] simp rintro ys init rfl last rfl rfl /-- Like `bidirectionalRec`, but with the list parameter placed first. -/ @[elab_as_elim] abbrev bidirectionalRecOn {C : List α → Sort*} (l : List α) (H0 : C []) (H1 : ∀ a : α, C [a]) (Hn : ∀ (a : α) (l : List α) (b : α), C l → C (a :: (l ++ [b]))) : C l := bidirectionalRec H0 H1 Hn l #align list.bidirectional_rec_on List.bidirectionalRecOn /-! ### sublists -/ attribute [refl] List.Sublist.refl #align list.nil_sublist List.nil_sublist #align list.sublist.refl List.Sublist.refl #align list.sublist.trans List.Sublist.trans #align list.sublist_cons List.sublist_cons #align list.sublist_of_cons_sublist List.sublist_of_cons_sublist theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s #align list.sublist.cons_cons List.Sublist.cons_cons #align list.sublist_append_left List.sublist_append_left #align list.sublist_append_right List.sublist_append_right theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ #align list.sublist_cons_of_sublist List.sublist_cons_of_sublist #align list.sublist_append_of_sublist_left List.sublist_append_of_sublist_left #align list.sublist_append_of_sublist_right List.sublist_append_of_sublist_right theorem tail_sublist : ∀ l : List α, tail l <+ l | [] => .slnil | a::l => sublist_cons a l #align list.tail_sublist List.tail_sublist @[gcongr] protected theorem Sublist.tail : ∀ {l₁ l₂ : List α}, l₁ <+ l₂ → tail l₁ <+ tail l₂ | _, _, slnil => .slnil | _, _, Sublist.cons _ h => (tail_sublist _).trans h | _, _, Sublist.cons₂ _ h => h theorem Sublist.of_cons_cons {l₁ l₂ : List α} {a b : α} (h : a :: l₁ <+ b :: l₂) : l₁ <+ l₂ := h.tail #align list.sublist_of_cons_sublist_cons List.Sublist.of_cons_cons @[deprecated (since := "2024-04-07")] theorem sublist_of_cons_sublist_cons {a} (h : a :: l₁ <+ a :: l₂) : l₁ <+ l₂ := h.of_cons_cons attribute [simp] cons_sublist_cons @[deprecated (since := "2024-04-07")] alias cons_sublist_cons_iff := cons_sublist_cons #align list.cons_sublist_cons_iff List.cons_sublist_cons_iff #align list.append_sublist_append_left List.append_sublist_append_left #align list.sublist.append_right List.Sublist.append_right #align list.sublist_or_mem_of_sublist List.sublist_or_mem_of_sublist #align list.sublist.reverse List.Sublist.reverse #align list.reverse_sublist_iff List.reverse_sublist #align list.append_sublist_append_right List.append_sublist_append_right #align list.sublist.append List.Sublist.append #align list.sublist.subset List.Sublist.subset #align list.singleton_sublist List.singleton_sublist theorem eq_nil_of_sublist_nil {l : List α} (s : l <+ []) : l = [] := eq_nil_of_subset_nil <| s.subset #align list.eq_nil_of_sublist_nil List.eq_nil_of_sublist_nil -- Porting note: this lemma seems to have been renamed on the occasion of its move to Batteries alias sublist_nil_iff_eq_nil := sublist_nil #align list.sublist_nil_iff_eq_nil List.sublist_nil_iff_eq_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop #align list.replicate_sublist_replicate List.replicate_sublist_replicate theorem sublist_replicate_iff {l : List α} {a : α} {n : ℕ} : l <+ replicate n a ↔ ∃ k ≤ n, l = replicate k a := ⟨fun h => ⟨l.length, h.length_le.trans_eq (length_replicate _ _), eq_replicate_length.mpr fun b hb => eq_of_mem_replicate (h.subset hb)⟩, by rintro ⟨k, h, rfl⟩; exact (replicate_sublist_replicate _).mpr h⟩ #align list.sublist_replicate_iff List.sublist_replicate_iff #align list.sublist.eq_of_length List.Sublist.eq_of_length #align list.sublist.eq_of_length_le List.Sublist.eq_of_length_le theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le #align list.sublist.antisymm List.Sublist.antisymm instance decidableSublist [DecidableEq α] : ∀ l₁ l₂ : List α, Decidable (l₁ <+ l₂) | [], _ => isTrue <| nil_sublist _ | _ :: _, [] => isFalse fun h => List.noConfusion <| eq_nil_of_sublist_nil h | a :: l₁, b :: l₂ => if h : a = b then @decidable_of_decidable_of_iff _ _ (decidableSublist l₁ l₂) <| h ▸ cons_sublist_cons.symm else @decidable_of_decidable_of_iff _ _ (decidableSublist (a :: l₁) l₂) ⟨sublist_cons_of_sublist _, fun s => match a, l₁, s, h with | _, _, Sublist.cons _ s', h => s' | _, _, Sublist.cons₂ t _, h => absurd rfl h⟩ #align list.decidable_sublist List.decidableSublist /-! ### indexOf -/ section IndexOf variable [DecidableEq α] #align list.index_of_nil List.indexOf_nil /- Porting note: The following proofs were simpler prior to the port. These proofs use the low-level `findIdx.go`. * `indexOf_cons_self` * `indexOf_cons_eq` * `indexOf_cons_ne` * `indexOf_cons` The ported versions of the earlier proofs are given in comments. -/ -- indexOf_cons_eq _ rfl @[simp] theorem indexOf_cons_self (a : α) (l : List α) : indexOf a (a :: l) = 0 := by rw [indexOf, findIdx_cons, beq_self_eq_true, cond] #align list.index_of_cons_self List.indexOf_cons_self -- fun e => if_pos e theorem indexOf_cons_eq {a b : α} (l : List α) : b = a → indexOf a (b :: l) = 0 | e => by rw [← e]; exact indexOf_cons_self b l #align list.index_of_cons_eq List.indexOf_cons_eq -- fun n => if_neg n @[simp] theorem indexOf_cons_ne {a b : α} (l : List α) : b ≠ a → indexOf a (b :: l) = succ (indexOf a l) | h => by simp only [indexOf, findIdx_cons, Bool.cond_eq_ite, beq_iff_eq, h, ite_false] #align list.index_of_cons_ne List.indexOf_cons_ne #align list.index_of_cons List.indexOf_cons theorem indexOf_eq_length {a : α} {l : List α} : indexOf a l = length l ↔ a ∉ l := by induction' l with b l ih · exact iff_of_true rfl (not_mem_nil _) simp only [length, mem_cons, indexOf_cons, eq_comm] rw [cond_eq_if] split_ifs with h <;> simp at h · exact iff_of_false (by rintro ⟨⟩) fun H => H <| Or.inl h.symm · simp only [Ne.symm h, false_or_iff] rw [← ih] exact succ_inj' #align list.index_of_eq_length List.indexOf_eq_length @[simp] theorem indexOf_of_not_mem {l : List α} {a : α} : a ∉ l → indexOf a l = length l := indexOf_eq_length.2 #align list.index_of_of_not_mem List.indexOf_of_not_mem theorem indexOf_le_length {a : α} {l : List α} : indexOf a l ≤ length l := by induction' l with b l ih; · rfl simp only [length, indexOf_cons, cond_eq_if, beq_iff_eq] by_cases h : b = a · rw [if_pos h]; exact Nat.zero_le _ · rw [if_neg h]; exact succ_le_succ ih #align list.index_of_le_length List.indexOf_le_length theorem indexOf_lt_length {a} {l : List α} : indexOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.by_contradiction fun al => Nat.ne_of_lt h <| indexOf_eq_length.2 al, fun al => (lt_of_le_of_ne indexOf_le_length) fun h => indexOf_eq_length.1 h al⟩ #align list.index_of_lt_length List.indexOf_lt_length theorem indexOf_append_of_mem {a : α} (h : a ∈ l₁) : indexOf a (l₁ ++ l₂) = indexOf a l₁ := by induction' l₁ with d₁ t₁ ih · exfalso exact not_mem_nil a h rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [indexOf_cons_eq _ hh] rw [indexOf_cons_ne _ hh, indexOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] #align list.index_of_append_of_mem List.indexOf_append_of_mem theorem indexOf_append_of_not_mem {a : α} (h : a ∉ l₁) : indexOf a (l₁ ++ l₂) = l₁.length + indexOf a l₂ := by induction' l₁ with d₁ t₁ ih · rw [List.nil_append, List.length, Nat.zero_add] rw [List.cons_append, indexOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] #align list.index_of_append_of_not_mem List.indexOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated set_option linter.deprecated false @[deprecated get_of_mem (since := "2023-01-05")] theorem nthLe_of_mem {a} {l : List α} (h : a ∈ l) : ∃ n h, nthLe l n h = a := let ⟨i, h⟩ := get_of_mem h; ⟨i.1, i.2, h⟩ #align list.nth_le_of_mem List.nthLe_of_mem @[deprecated get?_eq_get (since := "2023-01-05")] theorem nthLe_get? {l : List α} {n} (h) : get? l n = some (nthLe l n h) := get?_eq_get _ #align list.nth_le_nth List.nthLe_get? #align list.nth_len_le List.get?_len_le @[simp] theorem get?_length (l : List α) : l.get? l.length = none := get?_len_le le_rfl #align list.nth_length List.get?_length #align list.nth_eq_some List.get?_eq_some #align list.nth_eq_none_iff List.get?_eq_none #align list.nth_of_mem List.get?_of_mem @[deprecated get_mem (since := "2023-01-05")] theorem nthLe_mem (l : List α) (n h) : nthLe l n h ∈ l := get_mem .. #align list.nth_le_mem List.nthLe_mem #align list.nth_mem List.get?_mem @[deprecated mem_iff_get (since := "2023-01-05")] theorem mem_iff_nthLe {a} {l : List α} : a ∈ l ↔ ∃ n h, nthLe l n h = a := mem_iff_get.trans ⟨fun ⟨⟨n, h⟩, e⟩ => ⟨n, h, e⟩, fun ⟨n, h, e⟩ => ⟨⟨n, h⟩, e⟩⟩ #align list.mem_iff_nth_le List.mem_iff_nthLe #align list.mem_iff_nth List.mem_iff_get? #align list.nth_zero List.get?_zero @[deprecated (since := "2024-05-03")] alias get?_injective := get?_inj #align list.nth_injective List.get?_inj #align list.nth_map List.get?_map @[deprecated get_map (since := "2023-01-05")] theorem nthLe_map (f : α → β) {l n} (H1 H2) : nthLe (map f l) n H1 = f (nthLe l n H2) := get_map .. #align list.nth_le_map List.nthLe_map /-- A version of `get_map` that can be used for rewriting. -/ theorem get_map_rev (f : α → β) {l n} : f (get l n) = get (map f l) ⟨n.1, (l.length_map f).symm ▸ n.2⟩ := Eq.symm (get_map _) /-- A version of `nthLe_map` that can be used for rewriting. -/ @[deprecated get_map_rev (since := "2023-01-05")] theorem nthLe_map_rev (f : α → β) {l n} (H) : f (nthLe l n H) = nthLe (map f l) n ((l.length_map f).symm ▸ H) := (nthLe_map f _ _).symm #align list.nth_le_map_rev List.nthLe_map_rev @[simp, deprecated get_map (since := "2023-01-05")] theorem nthLe_map' (f : α → β) {l n} (H) : nthLe (map f l) n H = f (nthLe l n (l.length_map f ▸ H)) := nthLe_map f _ _ #align list.nth_le_map' List.nthLe_map' #align list.nth_le_of_eq List.get_of_eq @[simp, deprecated get_singleton (since := "2023-01-05")] theorem nthLe_singleton (a : α) {n : ℕ} (hn : n < 1) : nthLe [a] n hn = a := get_singleton .. #align list.nth_le_singleton List.get_singleton #align list.nth_le_zero List.get_mk_zero #align list.nth_le_append List.get_append @[deprecated get_append_right' (since := "2023-01-05")] theorem nthLe_append_right {l₁ l₂ : List α} {n : ℕ} (h₁ : l₁.length ≤ n) (h₂) : (l₁ ++ l₂).nthLe n h₂ = l₂.nthLe (n - l₁.length) (get_append_right_aux h₁ h₂) := get_append_right' h₁ h₂ #align list.nth_le_append_right_aux List.get_append_right_aux #align list.nth_le_append_right List.nthLe_append_right #align list.nth_le_replicate List.get_replicate #align list.nth_append List.get?_append #align list.nth_append_right List.get?_append_right #align list.last_eq_nth_le List.getLast_eq_get theorem get_length_sub_one {l : List α} (h : l.length - 1 < l.length) : l.get ⟨l.length - 1, h⟩ = l.getLast (by rintro rfl; exact Nat.lt_irrefl 0 h) := (getLast_eq_get l _).symm #align list.nth_le_length_sub_one List.get_length_sub_one #align list.nth_concat_length List.get?_concat_length @[deprecated get_cons_length (since := "2023-01-05")] theorem nthLe_cons_length : ∀ (x : α) (xs : List α) (n : ℕ) (h : n = xs.length), (x :: xs).nthLe n (by simp [h]) = (x :: xs).getLast (cons_ne_nil x xs) := get_cons_length #align list.nth_le_cons_length List.nthLe_cons_length theorem take_one_drop_eq_of_lt_length {l : List α} {n : ℕ} (h : n < l.length) : (l.drop n).take 1 = [l.get ⟨n, h⟩] := by rw [drop_eq_get_cons h, take, take] #align list.take_one_drop_eq_of_lt_length List.take_one_drop_eq_of_lt_length #align list.ext List.ext -- TODO one may rename ext in the standard library, and it is also not clear -- which of ext_get?, ext_get?', ext_get should be @[ext], if any alias ext_get? := ext theorem ext_get?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n) : l₁ = l₂ := by apply ext intro n rcases Nat.lt_or_ge n <| max l₁.length l₂.length with hn | hn · exact h' n hn · simp_all [Nat.max_le, get?_eq_none.mpr] theorem ext_get?_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n, l₁.get? n = l₂.get? n := ⟨by rintro rfl _; rfl, ext_get?⟩ theorem ext_get_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ n h₁ h₂, get l₁ ⟨n, h₁⟩ = get l₂ ⟨n, h₂⟩ := by constructor · rintro rfl exact ⟨rfl, fun _ _ _ ↦ rfl⟩ · intro ⟨h₁, h₂⟩ exact ext_get h₁ h₂ theorem ext_get?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁.get? n = l₂.get? n := ⟨by rintro rfl _ _; rfl, ext_get?'⟩ @[deprecated ext_get (since := "2023-01-05")] theorem ext_nthLe {l₁ l₂ : List α} (hl : length l₁ = length l₂) (h : ∀ n h₁ h₂, nthLe l₁ n h₁ = nthLe l₂ n h₂) : l₁ = l₂ := ext_get hl h #align list.ext_le List.ext_nthLe @[simp] theorem indexOf_get [DecidableEq α] {a : α} : ∀ {l : List α} (h), get l ⟨indexOf a l, h⟩ = a | b :: l, h => by by_cases h' : b = a <;> simp only [h', if_pos, if_false, indexOf_cons, get, @indexOf_get _ _ l, cond_eq_if, beq_iff_eq] #align list.index_of_nth_le List.indexOf_get @[simp] theorem indexOf_get? [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : get? l (indexOf a l) = some a := by rw [get?_eq_get, indexOf_get (indexOf_lt_length.2 h)] #align list.index_of_nth List.indexOf_get? @[deprecated (since := "2023-01-05")] theorem get_reverse_aux₁ : ∀ (l r : List α) (i h1 h2), get (reverseAux l r) ⟨i + length l, h1⟩ = get r ⟨i, h2⟩ | [], r, i => fun h1 _ => rfl | a :: l, r, i => by rw [show i + length (a :: l) = i + 1 + length l from Nat.add_right_comm i (length l) 1] exact fun h1 h2 => get_reverse_aux₁ l (a :: r) (i + 1) h1 (succ_lt_succ h2) #align list.nth_le_reverse_aux1 List.get_reverse_aux₁ theorem indexOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : indexOf x l = indexOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨indexOf x l, indexOf_lt_length.2 hx⟩ = get l ⟨indexOf y l, indexOf_lt_length.2 hy⟩ := by simp only [h] simp only [indexOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ #align list.index_of_inj List.indexOf_inj theorem get_reverse_aux₂ : ∀ (l r : List α) (i : Nat) (h1) (h2), get (reverseAux l r) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩ | [], r, i, h1, h2 => absurd h2 (Nat.not_lt_zero _) | a :: l, r, 0, h1, _ => by have aux := get_reverse_aux₁ l (a :: r) 0 rw [Nat.zero_add] at aux exact aux _ (zero_lt_succ _) | a :: l, r, i + 1, h1, h2 => by have aux := get_reverse_aux₂ l (a :: r) i have heq : length (a :: l) - 1 - (i + 1) = length l - 1 - i := by rw [length]; omega rw [← heq] at aux apply aux #align list.nth_le_reverse_aux2 List.get_reverse_aux₂ @[simp] theorem get_reverse (l : List α) (i : Nat) (h1 h2) : get (reverse l) ⟨length l - 1 - i, h1⟩ = get l ⟨i, h2⟩ := get_reverse_aux₂ _ _ _ _ _ @[simp, deprecated get_reverse (since := "2023-01-05")] theorem nthLe_reverse (l : List α) (i : Nat) (h1 h2) : nthLe (reverse l) (length l - 1 - i) h1 = nthLe l i h2 := get_reverse .. #align list.nth_le_reverse List.nthLe_reverse theorem nthLe_reverse' (l : List α) (n : ℕ) (hn : n < l.reverse.length) (hn') : l.reverse.nthLe n hn = l.nthLe (l.length - 1 - n) hn' := by rw [eq_comm] convert nthLe_reverse l.reverse n (by simpa) hn using 1 simp #align list.nth_le_reverse' List.nthLe_reverse' theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := nthLe_reverse' .. -- FIXME: prove it the other way around attribute [deprecated get_reverse' (since := "2023-01-05")] nthLe_reverse' theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.nthLe 0 (by omega)] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp only [get_singleton] congr omega #align list.eq_cons_of_length_one List.eq_cons_of_length_one end deprecated theorem modifyNthTail_modifyNthTail {f g : List α → List α} (m : ℕ) : ∀ (n) (l : List α), (l.modifyNthTail f n).modifyNthTail g (m + n) = l.modifyNthTail (fun l => (f l).modifyNthTail g m) n | 0, _ => rfl | _ + 1, [] => rfl | n + 1, a :: l => congr_arg (List.cons a) (modifyNthTail_modifyNthTail m n l) #align list.modify_nth_tail_modify_nth_tail List.modifyNthTail_modifyNthTail theorem modifyNthTail_modifyNthTail_le {f g : List α → List α} (m n : ℕ) (l : List α) (h : n ≤ m) : (l.modifyNthTail f n).modifyNthTail g m = l.modifyNthTail (fun l => (f l).modifyNthTail g (m - n)) n := by rcases Nat.exists_eq_add_of_le h with ⟨m, rfl⟩ rw [Nat.add_comm, modifyNthTail_modifyNthTail, Nat.add_sub_cancel] #align list.modify_nth_tail_modify_nth_tail_le List.modifyNthTail_modifyNthTail_le theorem modifyNthTail_modifyNthTail_same {f g : List α → List α} (n : ℕ) (l : List α) : (l.modifyNthTail f n).modifyNthTail g n = l.modifyNthTail (g ∘ f) n := by rw [modifyNthTail_modifyNthTail_le n n l (le_refl n), Nat.sub_self]; rfl #align list.modify_nth_tail_modify_nth_tail_same List.modifyNthTail_modifyNthTail_same #align list.modify_nth_tail_id List.modifyNthTail_id #align list.remove_nth_eq_nth_tail List.eraseIdx_eq_modifyNthTail #align list.update_nth_eq_modify_nth List.set_eq_modifyNth @[deprecated (since := "2024-05-04")] alias removeNth_eq_nthTail := eraseIdx_eq_modifyNthTail theorem modifyNth_eq_set (f : α → α) : ∀ (n) (l : List α), modifyNth f n l = ((fun a => set l n (f a)) <$> get? l n).getD l | 0, l => by cases l <;> rfl | n + 1, [] => rfl | n + 1, b :: l => (congr_arg (cons b) (modifyNth_eq_set f n l)).trans <| by cases h : get? l n <;> simp [h] #align list.modify_nth_eq_update_nth List.modifyNth_eq_set #align list.nth_modify_nth List.get?_modifyNth theorem length_modifyNthTail (f : List α → List α) (H : ∀ l, length (f l) = length l) : ∀ n l, length (modifyNthTail f n l) = length l | 0, _ => H _ | _ + 1, [] => rfl | _ + 1, _ :: _ => @congr_arg _ _ _ _ (· + 1) (length_modifyNthTail _ H _ _) #align list.modify_nth_tail_length List.length_modifyNthTail -- Porting note: Duplicate of `modify_get?_length` -- (but with a substantially better name?) -- @[simp] theorem length_modifyNth (f : α → α) : ∀ n l, length (modifyNth f n l) = length l := modify_get?_length f #align list.modify_nth_length List.length_modifyNth #align list.update_nth_length List.length_set #align list.nth_modify_nth_eq List.get?_modifyNth_eq #align list.nth_modify_nth_ne List.get?_modifyNth_ne #align list.nth_update_nth_eq List.get?_set_eq #align list.nth_update_nth_of_lt List.get?_set_eq_of_lt #align list.nth_update_nth_ne List.get?_set_ne #align list.update_nth_nil List.set_nil #align list.update_nth_succ List.set_succ #align list.update_nth_comm List.set_comm #align list.nth_le_update_nth_eq List.get_set_eq @[simp] theorem get_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a).get ⟨j, hj⟩ = l.get ⟨j, by simpa using hj⟩ := by rw [← Option.some_inj, ← List.get?_eq_get, List.get?_set_ne _ _ h, List.get?_eq_get] #align list.nth_le_update_nth_of_ne List.get_set_of_ne #align list.mem_or_eq_of_mem_update_nth List.mem_or_eq_of_mem_set /-! ### map -/ #align list.map_nil List.map_nil theorem map_eq_foldr (f : α → β) (l : List α) : map f l = foldr (fun a bs => f a :: bs) [] l := by induction l <;> simp [*] #align list.map_eq_foldr List.map_eq_foldr theorem map_congr {f g : α → β} : ∀ {l : List α}, (∀ x ∈ l, f x = g x) → map f l = map g l | [], _ => rfl | a :: l, h => by let ⟨h₁, h₂⟩ := forall_mem_cons.1 h rw [map, map, h₁, map_congr h₂] #align list.map_congr List.map_congr theorem map_eq_map_iff {f g : α → β} {l : List α} : map f l = map g l ↔ ∀ x ∈ l, f x = g x := by refine ⟨?_, map_congr⟩; intro h x hx rw [mem_iff_get] at hx; rcases hx with ⟨n, hn, rfl⟩ rw [get_map_rev f, get_map_rev g] congr! #align list.map_eq_map_iff List.map_eq_map_iff theorem map_concat (f : α → β) (a : α) (l : List α) : map f (concat l a) = concat (map f l) (f a) := by induction l <;> [rfl; simp only [*, concat_eq_append, cons_append, map, map_append]] #align list.map_concat List.map_concat #align list.map_id'' List.map_id' theorem map_id'' {f : α → α} (h : ∀ x, f x = x) (l : List α) : map f l = l := by simp [show f = id from funext h] #align list.map_id' List.map_id'' theorem eq_nil_of_map_eq_nil {f : α → β} {l : List α} (h : map f l = nil) : l = nil := eq_nil_of_length_eq_zero <| by rw [← length_map l f, h]; rfl #align list.eq_nil_of_map_eq_nil List.eq_nil_of_map_eq_nil @[simp] theorem map_join (f : α → β) (L : List (List α)) : map f (join L) = join (map (map f) L) := by induction L <;> [rfl; simp only [*, join, map, map_append]] #align list.map_join List.map_join theorem bind_pure_eq_map (f : α → β) (l : List α) : l.bind (pure ∘ f) = map f l := .symm <| map_eq_bind .. #align list.bind_ret_eq_map List.bind_pure_eq_map set_option linter.deprecated false in @[deprecated bind_pure_eq_map (since := "2024-03-24")] theorem bind_ret_eq_map (f : α → β) (l : List α) : l.bind (List.ret ∘ f) = map f l := bind_pure_eq_map f l theorem bind_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : List.bind l f = List.bind l g := (congr_arg List.join <| map_congr h : _) #align list.bind_congr List.bind_congr theorem infix_bind_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.bind f := List.infix_of_mem_join (List.mem_map_of_mem f h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl #align list.map_eq_map List.map_eq_map @[simp] theorem map_tail (f : α → β) (l) : map f (tail l) = tail (map f l) := by cases l <;> rfl #align list.map_tail List.map_tail /-- A single `List.map` of a composition of functions is equal to composing a `List.map` with another `List.map`, fully applied. This is the reverse direction of `List.map_map`. -/ theorem comp_map (h : β → γ) (g : α → β) (l : List α) : map (h ∘ g) l = map h (map g l) := (map_map _ _ _).symm #align list.comp_map List.comp_map /-- Composing a `List.map` with another `List.map` is equal to a single `List.map` of composed functions. -/ @[simp] theorem map_comp_map (g : β → γ) (f : α → β) : map g ∘ map f = map (g ∘ f) := by ext l; rw [comp_map, Function.comp_apply] #align list.map_comp_map List.map_comp_map section map_bijectivity theorem _root_.Function.LeftInverse.list_map {f : α → β} {g : β → α} (h : LeftInverse f g) : LeftInverse (map f) (map g) | [] => by simp_rw [map_nil] | x :: xs => by simp_rw [map_cons, h x, h.list_map xs] nonrec theorem _root_.Function.RightInverse.list_map {f : α → β} {g : β → α} (h : RightInverse f g) : RightInverse (map f) (map g) := h.list_map nonrec theorem _root_.Function.Involutive.list_map {f : α → α} (h : Involutive f) : Involutive (map f) := Function.LeftInverse.list_map h @[simp] theorem map_leftInverse_iff {f : α → β} {g : β → α} : LeftInverse (map f) (map g) ↔ LeftInverse f g := ⟨fun h x => by injection h [x], (·.list_map)⟩ @[simp] theorem map_rightInverse_iff {f : α → β} {g : β → α} : RightInverse (map f) (map g) ↔ RightInverse f g := map_leftInverse_iff @[simp] theorem map_involutive_iff {f : α → α} : Involutive (map f) ↔ Involutive f := map_leftInverse_iff theorem _root_.Function.Injective.list_map {f : α → β} (h : Injective f) : Injective (map f) | [], [], _ => rfl | x :: xs, y :: ys, hxy => by injection hxy with hxy hxys rw [h hxy, h.list_map hxys] @[simp] theorem map_injective_iff {f : α → β} : Injective (map f) ↔ Injective f := by refine ⟨fun h x y hxy => ?_, (·.list_map)⟩ suffices [x] = [y] by simpa using this apply h simp [hxy] #align list.map_injective_iff List.map_injective_iff theorem _root_.Function.Surjective.list_map {f : α → β} (h : Surjective f) : Surjective (map f) := let ⟨_, h⟩ := h.hasRightInverse; h.list_map.surjective @[simp] theorem map_surjective_iff {f : α → β} : Surjective (map f) ↔ Surjective f := by refine ⟨fun h x => ?_, (·.list_map)⟩ let ⟨[y], hxy⟩ := h [x] exact ⟨_, List.singleton_injective hxy⟩ theorem _root_.Function.Bijective.list_map {f : α → β} (h : Bijective f) : Bijective (map f) := ⟨h.1.list_map, h.2.list_map⟩ @[simp] theorem map_bijective_iff {f : α → β} : Bijective (map f) ↔ Bijective f := by simp_rw [Function.Bijective, map_injective_iff, map_surjective_iff] end map_bijectivity theorem map_filter_eq_foldr (f : α → β) (p : α → Bool) (as : List α) : map f (filter p as) = foldr (fun a bs => bif p a then f a :: bs else bs) [] as := by induction' as with head tail · rfl · simp only [foldr] cases hp : p head <;> simp [filter, *] #align list.map_filter_eq_foldr List.map_filter_eq_foldr theorem getLast_map (f : α → β) {l : List α} (hl : l ≠ []) : (l.map f).getLast (mt eq_nil_of_map_eq_nil hl) = f (l.getLast hl) := by induction' l with l_hd l_tl l_ih · apply (hl rfl).elim · cases l_tl · simp · simpa using l_ih _ #align list.last_map List.getLast_map theorem map_eq_replicate_iff {l : List α} {f : α → β} {b : β} : l.map f = replicate l.length b ↔ ∀ x ∈ l, f x = b := by simp [eq_replicate] #align list.map_eq_replicate_iff List.map_eq_replicate_iff @[simp] theorem map_const (l : List α) (b : β) : map (const α b) l = replicate l.length b := map_eq_replicate_iff.mpr fun _ _ => rfl #align list.map_const List.map_const @[simp] theorem map_const' (l : List α) (b : β) : map (fun _ => b) l = replicate l.length b := map_const l b #align list.map_const' List.map_const' theorem eq_of_mem_map_const {b₁ b₂ : β} {l : List α} (h : b₁ ∈ map (const α b₂) l) : b₁ = b₂ := by rw [map_const] at h; exact eq_of_mem_replicate h #align list.eq_of_mem_map_const List.eq_of_mem_map_const /-! ### zipWith -/ theorem nil_zipWith (f : α → β → γ) (l : List β) : zipWith f [] l = [] := by cases l <;> rfl #align list.nil_map₂ List.nil_zipWith theorem zipWith_nil (f : α → β → γ) (l : List α) : zipWith f l [] = [] := by cases l <;> rfl #align list.map₂_nil List.zipWith_nil @[simp] theorem zipWith_flip (f : α → β → γ) : ∀ as bs, zipWith (flip f) bs as = zipWith f as bs | [], [] => rfl | [], b :: bs => rfl | a :: as, [] => rfl | a :: as, b :: bs => by simp! [zipWith_flip] rfl #align list.map₂_flip List.zipWith_flip /-! ### take, drop -/ #align list.take_zero List.take_zero #align list.take_nil List.take_nil theorem take_cons (n) (a : α) (l : List α) : take (succ n) (a :: l) = a :: take n l := rfl #align list.take_cons List.take_cons #align list.take_length List.take_length #align list.take_all_of_le List.take_all_of_le #align list.take_left List.take_left #align list.take_left' List.take_left' #align list.take_take List.take_take #align list.take_replicate List.take_replicate #align list.map_take List.map_take #align list.take_append_eq_append_take List.take_append_eq_append_take #align list.take_append_of_le_length List.take_append_of_le_length #align list.take_append List.take_append #align list.nth_le_take List.get_take #align list.nth_le_take' List.get_take' #align list.nth_take List.get?_take #align list.nth_take_of_succ List.nth_take_of_succ #align list.take_succ List.take_succ #align list.take_eq_nil_iff List.take_eq_nil_iff #align list.take_eq_take List.take_eq_take #align list.take_add List.take_add #align list.init_eq_take List.dropLast_eq_take #align list.init_take List.dropLast_take #align list.init_cons_of_ne_nil List.dropLast_cons_of_ne_nil #align list.init_append_of_ne_nil List.dropLast_append_of_ne_nil #align list.drop_eq_nil_of_le List.drop_eq_nil_of_le #align list.drop_eq_nil_iff_le List.drop_eq_nil_iff_le #align list.tail_drop List.tail_drop @[simp] theorem drop_tail (l : List α) (n : ℕ) : l.tail.drop n = l.drop (n + 1) := by rw [drop_add, drop_one] theorem cons_get_drop_succ {l : List α} {n} : l.get n :: l.drop (n.1 + 1) = l.drop n.1 := (drop_eq_get_cons n.2).symm #align list.cons_nth_le_drop_succ List.cons_get_drop_succ #align list.drop_nil List.drop_nil #align list.drop_one List.drop_one #align list.drop_add List.drop_add #align list.drop_left List.drop_left #align list.drop_left' List.drop_left' #align list.drop_eq_nth_le_cons List.drop_eq_get_consₓ -- nth_le vs get #align list.drop_length List.drop_length #align list.drop_length_cons List.drop_length_cons #align list.drop_append_eq_append_drop List.drop_append_eq_append_drop #align list.drop_append_of_le_length List.drop_append_of_le_length #align list.drop_append List.drop_append #align list.drop_sizeof_le List.drop_sizeOf_le #align list.nth_le_drop List.get_drop #align list.nth_le_drop' List.get_drop' #align list.nth_drop List.get?_drop #align list.drop_drop List.drop_drop #align list.drop_take List.drop_take #align list.map_drop List.map_drop #align list.modify_nth_tail_eq_take_drop List.modifyNthTail_eq_take_drop #align list.modify_nth_eq_take_drop List.modifyNth_eq_take_drop #align list.modify_nth_eq_take_cons_drop List.modifyNth_eq_take_cons_drop #align list.update_nth_eq_take_cons_drop List.set_eq_take_cons_drop #align list.reverse_take List.reverse_take #align list.update_nth_eq_nil List.set_eq_nil section TakeI variable [Inhabited α] @[simp] theorem takeI_length : ∀ n l, length (@takeI α _ n l) = n | 0, _ => rfl | _ + 1, _ => congr_arg succ (takeI_length _ _) #align list.take'_length List.takeI_length @[simp] theorem takeI_nil : ∀ n, takeI n (@nil α) = replicate n default | 0 => rfl | _ + 1 => congr_arg (cons _) (takeI_nil _) #align list.take'_nil List.takeI_nil theorem takeI_eq_take : ∀ {n} {l : List α}, n ≤ length l → takeI n l = take n l | 0, _, _ => rfl | _ + 1, _ :: _, h => congr_arg (cons _) <| takeI_eq_take <| le_of_succ_le_succ h #align list.take'_eq_take List.takeI_eq_take @[simp] theorem takeI_left (l₁ l₂ : List α) : takeI (length l₁) (l₁ ++ l₂) = l₁ := (takeI_eq_take (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _) #align list.take'_left List.takeI_left theorem takeI_left' {l₁ l₂ : List α} {n} (h : length l₁ = n) : takeI n (l₁ ++ l₂) = l₁ := by rw [← h]; apply takeI_left #align list.take'_left' List.takeI_left' end TakeI /- Porting note: in mathlib3 we just had `take` and `take'`. Now we have `take`, `takeI`, and `takeD`. The following section replicates the theorems above but for `takeD`. -/ section TakeD @[simp] theorem takeD_length : ∀ n l a, length (@takeD α n l a) = n | 0, _, _ => rfl | _ + 1, _, _ => congr_arg succ (takeD_length _ _ _) -- Porting note: `takeD_nil` is already in std theorem takeD_eq_take : ∀ {n} {l : List α} a, n ≤ length l → takeD n l a = take n l | 0, _, _, _ => rfl | _ + 1, _ :: _, a, h => congr_arg (cons _) <| takeD_eq_take a <| le_of_succ_le_succ h @[simp] theorem takeD_left (l₁ l₂ : List α) (a : α) : takeD (length l₁) (l₁ ++ l₂) a = l₁ := (takeD_eq_take a (by simp only [length_append, Nat.le_add_right])).trans (take_left _ _) theorem takeD_left' {l₁ l₂ : List α} {n} {a} (h : length l₁ = n) : takeD n (l₁ ++ l₂) a = l₁ := by rw [← h]; apply takeD_left end TakeD /-! ### foldl, foldr -/ theorem foldl_ext (f g : α → β → α) (a : α) {l : List β} (H : ∀ a : α, ∀ b ∈ l, f a b = g a b) : foldl f a l = foldl g a l := by induction l generalizing a with | nil => rfl | cons hd tl ih => unfold foldl rw [ih _ fun a b bin => H a b <| mem_cons_of_mem _ bin, H a hd (mem_cons_self _ _)] #align list.foldl_ext List.foldl_ext theorem foldr_ext (f g : α → β → β) (b : β) {l : List α} (H : ∀ a ∈ l, ∀ b : β, f a b = g a b) : foldr f b l = foldr g b l := by induction' l with hd tl ih; · rfl simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] #align list.foldr_ext List.foldr_ext #align list.foldl_nil List.foldl_nil #align list.foldl_cons List.foldl_cons #align list.foldr_nil List.foldr_nil #align list.foldr_cons List.foldr_cons #align list.foldl_append List.foldl_append #align list.foldr_append List.foldr_append theorem foldl_concat (f : β → α → β) (b : β) (x : α) (xs : List α) : List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x := by simp only [List.foldl_append, List.foldl] theorem foldr_concat (f : α → β → β) (b : β) (x : α) (xs : List α) : List.foldr f b (xs ++ [x]) = (List.foldr f (f x b) xs) := by simp only [List.foldr_append, List.foldr] theorem foldl_fixed' {f : α → β → α} {a : α} (hf : ∀ b, f a b = a) : ∀ l : List β, foldl f a l = a | [] => rfl | b :: l => by rw [foldl_cons, hf b, foldl_fixed' hf l] #align list.foldl_fixed' List.foldl_fixed' theorem foldr_fixed' {f : α → β → β} {b : β} (hf : ∀ a, f a b = b) : ∀ l : List α, foldr f b l = b | [] => rfl | a :: l => by rw [foldr_cons, foldr_fixed' hf l, hf a] #align list.foldr_fixed' List.foldr_fixed' @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl #align list.foldl_fixed List.foldl_fixed @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl #align list.foldr_fixed List.foldr_fixed @[simp] theorem foldl_join (f : α → β → α) : ∀ (a : α) (L : List (List β)), foldl f a (join L) = foldl (foldl f) a L | a, [] => rfl | a, l :: L => by simp only [join, foldl_append, foldl_cons, foldl_join f (foldl f a l) L] #align list.foldl_join List.foldl_join @[simp] theorem foldr_join (f : α → β → β) : ∀ (b : β) (L : List (List α)), foldr f b (join L) = foldr (fun l b => foldr f b l) b L | a, [] => rfl | a, l :: L => by simp only [join, foldr_append, foldr_join f a L, foldr_cons] #align list.foldr_join List.foldr_join #align list.foldl_reverse List.foldl_reverse #align list.foldr_reverse List.foldr_reverse -- Porting note (#10618): simp can prove this -- @[simp] theorem foldr_eta : ∀ l : List α, foldr cons [] l = l := by simp only [foldr_self_append, append_nil, forall_const] #align list.foldr_eta List.foldr_eta @[simp] theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by rw [← foldr_reverse]; simp only [foldr_self_append, append_nil, reverse_reverse] #align list.reverse_foldl List.reverse_foldl #align list.foldl_map List.foldl_map #align list.foldr_map List.foldr_map theorem foldl_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α) (h : ∀ x y, f' (g x) (g y) = g (f x y)) : List.foldl f' (g a) (l.map g) = g (List.foldl f a l) := by induction l generalizing a · simp · simp [*, h] #align list.foldl_map' List.foldl_map' theorem foldr_map' {α β : Type u} (g : α → β) (f : α → α → α) (f' : β → β → β) (a : α) (l : List α) (h : ∀ x y, f' (g x) (g y) = g (f x y)) : List.foldr f' (g a) (l.map g) = g (List.foldr f a l) := by induction l generalizing a · simp · simp [*, h] #align list.foldr_map' List.foldr_map' #align list.foldl_hom List.foldl_hom #align list.foldr_hom List.foldr_hom theorem foldl_hom₂ (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β) (op₃ : γ → ι → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ a i) (op₂ b i) = op₃ (f a b) i) : foldl op₃ (f a b) l = f (foldl op₁ a l) (foldl op₂ b l) := Eq.symm <| by revert a b induction l <;> intros <;> [rfl; simp only [*, foldl]] #align list.foldl_hom₂ List.foldl_hom₂ theorem foldr_hom₂ (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β) (op₃ : ι → γ → γ) (a : α) (b : β) (h : ∀ a b i, f (op₁ i a) (op₂ i b) = op₃ i (f a b)) : foldr op₃ (f a b) l = f (foldr op₁ a l) (foldr op₂ b l) := by revert a induction l <;> intros <;> [rfl; simp only [*, foldr]] #align list.foldr_hom₂ List.foldr_hom₂ theorem injective_foldl_comp {l : List (α → α)} {f : α → α} (hl : ∀ f ∈ l, Function.Injective f) (hf : Function.Injective f) : Function.Injective (@List.foldl (α → α) (α → α) Function.comp f l) := by induction' l with lh lt l_ih generalizing f · exact hf · apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ (List.mem_cons_self _ _) #align list.injective_foldl_comp List.injective_foldl_comp /-- Induction principle for values produced by a `foldr`: if a property holds for the seed element `b : β` and for all incremental `op : α → β → β` performed on the elements `(a : α) ∈ l`. The principle is given for a `Sort`-valued predicate, i.e., it can also be used to construct data. -/ def foldrRecOn {C : β → Sort*} (l : List α) (op : α → β → β) (b : β) (hb : C b) (hl : ∀ b, C b → ∀ a ∈ l, C (op a b)) : C (foldr op b l) := by induction l with | nil => exact hb | cons hd tl IH => refine hl _ ?_ hd (mem_cons_self hd tl) refine IH ?_ intro y hy x hx exact hl y hy x (mem_cons_of_mem hd hx) #align list.foldr_rec_on List.foldrRecOn /-- Induction principle for values produced by a `foldl`: if a property holds for the seed element `b : β` and for all incremental `op : β → α → β` performed on the elements `(a : α) ∈ l`. The principle is given for a `Sort`-valued predicate, i.e., it can also be used to construct data. -/ def foldlRecOn {C : β → Sort*} (l : List α) (op : β → α → β) (b : β) (hb : C b) (hl : ∀ b, C b → ∀ a ∈ l, C (op b a)) : C (foldl op b l) := by induction l generalizing b with | nil => exact hb | cons hd tl IH => refine IH _ ?_ ?_ · exact hl b hb hd (mem_cons_self hd tl) · intro y hy x hx exact hl y hy x (mem_cons_of_mem hd hx) #align list.foldl_rec_on List.foldlRecOn @[simp] theorem foldrRecOn_nil {C : β → Sort*} (op : α → β → β) (b) (hb : C b) (hl) : foldrRecOn [] op b hb hl = hb := rfl #align list.foldr_rec_on_nil List.foldrRecOn_nil @[simp] theorem foldrRecOn_cons {C : β → Sort*} (x : α) (l : List α) (op : α → β → β) (b) (hb : C b) (hl : ∀ b, C b → ∀ a ∈ x :: l, C (op a b)) : foldrRecOn (x :: l) op b hb hl = hl _ (foldrRecOn l op b hb fun b hb a ha => hl b hb a (mem_cons_of_mem _ ha)) x (mem_cons_self _ _) := rfl #align list.foldr_rec_on_cons List.foldrRecOn_cons @[simp] theorem foldlRecOn_nil {C : β → Sort*} (op : β → α → β) (b) (hb : C b) (hl) : foldlRecOn [] op b hb hl = hb := rfl #align list.foldl_rec_on_nil List.foldlRecOn_nil /-- Consider two lists `l₁` and `l₂` with designated elements `a₁` and `a₂` somewhere in them: `l₁ = x₁ ++ [a₁] ++ z₁` and `l₂ = x₂ ++ [a₂] ++ z₂`. Assume the designated element `a₂` is present in neither `x₁` nor `z₁`. We conclude that the lists are equal (`l₁ = l₂`) if and only if their respective parts are equal (`x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂`). -/ lemma append_cons_inj_of_not_mem {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α} (notin_x : a₂ ∉ x₁) (notin_z : a₂ ∉ z₁) : x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂ := by constructor · simp only [append_eq_append_iff, cons_eq_append, cons_eq_cons] rintro (⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩ | ⟨c, rfl, ⟨rfl, rfl, rfl⟩ | ⟨d, rfl, rfl⟩⟩) <;> simp_all · rintro ⟨rfl, rfl, rfl⟩ rfl section Scanl variable {f : β → α → β} {b : β} {a : α} {l : List α} theorem length_scanl : ∀ a l, length (scanl f a l) = l.length + 1 | a, [] => rfl | a, x :: l => by rw [scanl, length_cons, length_cons, ← succ_eq_add_one, congr_arg succ] exact length_scanl _ _ #align list.length_scanl List.length_scanl @[simp] theorem scanl_nil (b : β) : scanl f b nil = [b] := rfl #align list.scanl_nil List.scanl_nil @[simp] theorem scanl_cons : scanl f b (a :: l) = [b] ++ scanl f (f b a) l := by simp only [scanl, eq_self_iff_true, singleton_append, and_self_iff] #align list.scanl_cons List.scanl_cons @[simp] theorem get?_zero_scanl : (scanl f b l).get? 0 = some b := by cases l · simp only [get?, scanl_nil] · simp only [get?, scanl_cons, singleton_append] #align list.nth_zero_scanl List.get?_zero_scanl @[simp] theorem get_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).get ⟨0, h⟩ = b := by cases l · simp only [get, scanl_nil] · simp only [get, scanl_cons, singleton_append] set_option linter.deprecated false in @[simp, deprecated get_zero_scanl (since := "2023-01-05")] theorem nthLe_zero_scanl {h : 0 < (scanl f b l).length} : (scanl f b l).nthLe 0 h = b := get_zero_scanl #align list.nth_le_zero_scanl List.nthLe_zero_scanl theorem get?_succ_scanl {i : ℕ} : (scanl f b l).get? (i + 1) = ((scanl f b l).get? i).bind fun x => (l.get? i).map fun y => f x y := by induction' l with hd tl hl generalizing b i · symm simp only [Option.bind_eq_none', get?, forall₂_true_iff, not_false_iff, Option.map_none', scanl_nil, Option.not_mem_none, forall_true_iff] · simp only [scanl_cons, singleton_append] cases i · simp only [Option.map_some', get?_zero_scanl, get?, Option.some_bind'] · simp only [hl, get?] #align list.nth_succ_scanl List.get?_succ_scanl set_option linter.deprecated false in theorem nthLe_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} : (scanl f b l).nthLe (i + 1) h = f ((scanl f b l).nthLe i (Nat.lt_of_succ_lt h)) (l.nthLe i (Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l))))) := by induction i generalizing b l with | zero => cases l · simp only [length, zero_eq, lt_self_iff_false] at h · simp [scanl_cons, singleton_append, nthLe_zero_scanl, nthLe_cons] | succ i hi => cases l · simp only [length] at h exact absurd h (by omega) · simp_rw [scanl_cons] rw [nthLe_append_right] · simp only [length, Nat.zero_add 1, succ_add_sub_one, hi]; rfl · simp only [length_singleton]; omega #align list.nth_le_succ_scanl List.nthLe_succ_scanl theorem get_succ_scanl {i : ℕ} {h : i + 1 < (scanl f b l).length} : (scanl f b l).get ⟨i + 1, h⟩ = f ((scanl f b l).get ⟨i, Nat.lt_of_succ_lt h⟩) (l.get ⟨i, Nat.lt_of_succ_lt_succ (lt_of_lt_of_le h (le_of_eq (length_scanl b l)))⟩) := nthLe_succ_scanl -- FIXME: we should do the proof the other way around attribute [deprecated get_succ_scanl (since := "2023-01-05")] nthLe_succ_scanl end Scanl -- scanr @[simp] theorem scanr_nil (f : α → β → β) (b : β) : scanr f b [] = [b] := rfl #align list.scanr_nil List.scanr_nil #noalign list.scanr_aux_cons @[simp] theorem scanr_cons (f : α → β → β) (b : β) (a : α) (l : List α) : scanr f b (a :: l) = foldr f b (a :: l) :: scanr f b l := by simp only [scanr, foldr, cons.injEq, and_true] induction l generalizing a with | nil => rfl | cons hd tl ih => simp only [foldr, ih] #align list.scanr_cons List.scanr_cons section FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} (hcomm : Commutative f) (hassoc : Associative f) theorem foldl1_eq_foldr1 : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | a, b, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l]; rw [hassoc] #align list.foldl1_eq_foldr1 List.foldl1_eq_foldr1 theorem foldl_eq_of_comm_of_assoc : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm a b | a, b, c :: l => by simp only [foldl_cons] rw [← foldl_eq_of_comm_of_assoc .., right_comm _ hcomm hassoc]; rfl #align list.foldl_eq_of_comm_of_assoc List.foldl_eq_of_comm_of_assoc theorem foldl_eq_foldr : ∀ a l, foldl f a l = foldr f a l | a, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc hcomm hassoc]; rw [foldl_eq_foldr a l] #align list.foldl_eq_foldr List.foldl_eq_foldr end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | a, b, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] #align list.foldl_eq_of_comm' List.foldl_eq_of_comm' theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | a, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl #align list.foldl_eq_foldr' List.foldl_eq_foldr' end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} variable (hf : ∀ a b c, f a (f b c) = f b (f a c)) theorem foldr_eq_of_comm' : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | a, b, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' ..]; rfl #align list.foldr_eq_of_comm' List.foldr_eq_of_comm' end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative op] [hc : Std.Commutative op] /-- Notation for `op a b`. -/ local notation a " ⋆ " b => op a b /-- Notation for `foldl op a l`. -/ local notation l " <*> " a => foldl op a l theorem foldl_assoc : ∀ {l : List α} {a₁ a₂}, (l <*> a₁ ⋆ a₂) = a₁ ⋆ l <*> a₂ | [], a₁, a₂ => rfl | a :: l, a₁, a₂ => calc ((a :: l) <*> a₁ ⋆ a₂) = l <*> a₁ ⋆ a₂ ⋆ a := by simp only [foldl_cons, ha.assoc] _ = a₁ ⋆ (a :: l) <*> a₂ := by rw [foldl_assoc, foldl_cons] #align list.foldl_assoc List.foldl_assoc theorem foldl_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], a₁, a₂ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] #align list.foldl_op_eq_op_foldr_assoc List.foldl_op_eq_op_foldr_assoc theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] #align list.foldl_assoc_comm_cons List.foldl_assoc_comm_cons end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] #align list.mfoldl_nil List.foldlM_nil -- Porting note: now in std #align list.mfoldr_nil List.foldrM_nil #align list.mfoldl_cons List.foldlM_cons /- Porting note: now in std; now assumes an instance of `LawfulMonad m`, so we make everything `foldrM_eq_foldr` depend on one as well. (An instance of `LawfulMonad m` was already present for everything following; this just moves it a few lines up.) -/ #align list.mfoldr_cons List.foldrM_cons variable [LawfulMonad m] theorem foldrM_eq_foldr (f : α → β → m β) (b l) : foldrM f b l = foldr (fun a mb => mb >>= f a) (pure b) l := by induction l <;> simp [*] #align list.mfoldr_eq_foldr List.foldrM_eq_foldr attribute [simp] mapM mapM' theorem foldlM_eq_foldl (f : β → α → m β) (b l) : List.foldlM f b l = foldl (fun mb a => mb >>= fun b => f b a) (pure b) l := by suffices h : ∀ mb : m β, (mb >>= fun b => List.foldlM f b l) = foldl (fun mb a => mb >>= fun b => f b a) mb l by simp [← h (pure b)] induction l with | nil => intro; simp | cons _ _ l_ih => intro; simp only [List.foldlM, foldl, ← l_ih, functor_norm] #align list.mfoldl_eq_foldl List.foldlM_eq_foldl -- Porting note: now in std #align list.mfoldl_append List.foldlM_append -- Porting note: now in std #align list.mfoldr_append List.foldrM_append end FoldlMFoldrM /-! ### intersperse -/ #align list.intersperse_nil List.intersperse_nil @[simp] theorem intersperse_singleton (a b : α) : intersperse a [b] = [b] := rfl #align list.intersperse_singleton List.intersperse_singleton @[simp] theorem intersperse_cons_cons (a b c : α) (tl : List α) : intersperse a (b :: c :: tl) = b :: a :: intersperse a (c :: tl) := rfl #align list.intersperse_cons_cons List.intersperse_cons_cons /-! ### splitAt and splitOn -/ section SplitAtOn /- Porting note: the new version of `splitOnP` uses a `Bool`-valued predicate instead of a `Prop`-valued one. All downstream definitions have been updated to match. -/ variable (p : α → Bool) (xs ys : List α) (ls : List (List α)) (f : List α → List α) /- Porting note: this had to be rewritten because of the new implementation of `splitAt`. It's long in large part because `splitAt.go` (`splitAt`'s auxiliary function) works differently in the case where n ≥ length l, requiring two separate cases (and two separate inductions). Still, this can hopefully be golfed. -/ @[simp] theorem splitAt_eq_take_drop (n : ℕ) (l : List α) : splitAt n l = (take n l, drop n l) := by by_cases h : n < l.length <;> rw [splitAt, go_eq_take_drop] · rw [if_pos h]; rfl · rw [if_neg h, take_all_of_le <| le_of_not_lt h, drop_eq_nil_of_le <| le_of_not_lt h] where go_eq_take_drop (n : ℕ) (l xs : List α) (acc : Array α) : splitAt.go l xs n acc = if n < xs.length then (acc.toList ++ take n xs, drop n xs) else (l, []) := by split_ifs with h · induction n generalizing xs acc with | zero => rw [splitAt.go, take, drop, append_nil] · intros h₁; rw [h₁] at h; contradiction · intros; contradiction | succ _ ih => cases xs with | nil => contradiction | cons hd tl => rw [length] at h rw [splitAt.go, take, drop, append_cons, Array.toList_eq, ← Array.push_data, ← Array.toList_eq] exact ih _ _ <| (by omega) · induction n generalizing xs acc with | zero => replace h : xs.length = 0 := by omega rw [eq_nil_of_length_eq_zero h, splitAt.go] | succ _ ih => cases xs with | nil => rw [splitAt.go] | cons hd tl => rw [length] at h rw [splitAt.go] exact ih _ _ <| not_imp_not.mpr (Nat.add_lt_add_right · 1) h #align list.split_at_eq_take_drop List.splitAt_eq_take_drop @[simp] theorem splitOn_nil [DecidableEq α] (a : α) : [].splitOn a = [[]] := rfl #align list.split_on_nil List.splitOn_nil @[simp] theorem splitOnP_nil : [].splitOnP p = [[]] := rfl #align list.split_on_p_nil List.splitOnP_nilₓ /- Porting note: `split_on_p_aux` and `split_on_p_aux'` were used to prove facts about `split_on_p`. `splitOnP` has a different structure, and we need different facts about `splitOnP.go`. Theorems involving `split_on_p_aux` have been omitted where possible. -/ #noalign list.split_on_p_aux_ne_nil #noalign list.split_on_p_aux_spec #noalign list.split_on_p_aux' #noalign list.split_on_p_aux_eq #noalign list.split_on_p_aux_nil theorem splitOnP.go_ne_nil (xs acc : List α) : splitOnP.go p xs acc ≠ [] := by induction xs generalizing acc <;> simp [go]; split <;> simp [*] theorem splitOnP.go_acc (xs acc : List α) : splitOnP.go p xs acc = modifyHead (acc.reverse ++ ·) (splitOnP p xs) := by induction xs generalizing acc with | nil => simp only [go, modifyHead, splitOnP_nil, append_nil] | cons hd tl ih => simp only [splitOnP, go]; split · simp only [modifyHead, reverse_nil, append_nil] · rw [ih [hd], modifyHead_modifyHead, ih] congr; funext x; simp only [reverse_cons, append_assoc]; rfl theorem splitOnP_ne_nil (xs : List α) : xs.splitOnP p ≠ [] := splitOnP.go_ne_nil _ _ _ #align list.split_on_p_ne_nil List.splitOnP_ne_nilₓ @[simp] theorem splitOnP_cons (x : α) (xs : List α) : (x :: xs).splitOnP p = if p x then [] :: xs.splitOnP p else (xs.splitOnP p).modifyHead (cons x) := by rw [splitOnP, splitOnP.go]; split <;> [rfl; simp [splitOnP.go_acc]] #align list.split_on_p_cons List.splitOnP_consₓ /-- The original list `L` can be recovered by joining the lists produced by `splitOnP p L`, interspersed with the elements `L.filter p`. -/ theorem splitOnP_spec (as : List α) : join (zipWith (· ++ ·) (splitOnP p as) (((as.filter p).map fun x => [x]) ++ [[]])) = as := by induction as with | nil => rfl | cons a as' ih => rw [splitOnP_cons, filter] by_cases h : p a · rw [if_pos h, h, map, cons_append, zipWith, nil_append, join, cons_append, cons_inj] exact ih · rw [if_neg h, eq_false_of_ne_true h, join_zipWith (splitOnP_ne_nil _ _) (append_ne_nil_of_ne_nil_right _ [[]] (cons_ne_nil [] [])), cons_inj] exact ih where join_zipWith {xs ys : List (List α)} {a : α} (hxs : xs ≠ []) (hys : ys ≠ []) : join (zipWith (fun x x_1 ↦ x ++ x_1) (modifyHead (cons a) xs) ys) = a :: join (zipWith (fun x x_1 ↦ x ++ x_1) xs ys) := by cases xs with | nil => contradiction | cons => cases ys with | nil => contradiction | cons => rfl #align list.split_on_p_spec List.splitOnP_specₓ /-- If no element satisfies `p` in the list `xs`, then `xs.splitOnP p = [xs]` -/ theorem splitOnP_eq_single (h : ∀ x ∈ xs, ¬p x) : xs.splitOnP p = [xs] := by induction xs with | nil => rfl | cons hd tl ih => simp only [splitOnP_cons, h hd (mem_cons_self hd tl), if_neg] rw [ih <| forall_mem_of_forall_mem_cons h] rfl #align list.split_on_p_eq_single List.splitOnP_eq_singleₓ /-- When a list of the form `[...xs, sep, ...as]` is split on `p`, the first element is `xs`, assuming no element in `xs` satisfies `p` but `sep` does satisfy `p` -/ theorem splitOnP_first (h : ∀ x ∈ xs, ¬p x) (sep : α) (hsep : p sep) (as : List α) : (xs ++ sep :: as).splitOnP p = xs :: as.splitOnP p := by induction xs with | nil => simp [hsep] | cons hd tl ih => simp [h hd _, ih <| forall_mem_of_forall_mem_cons h] #align list.split_on_p_first List.splitOnP_firstₓ /-- `intercalate [x]` is the left inverse of `splitOn x` -/ theorem intercalate_splitOn (x : α) [DecidableEq α] : [x].intercalate (xs.splitOn x) = xs := by simp only [intercalate, splitOn] induction' xs with hd tl ih; · simp [join] cases' h' : splitOnP (· == x) tl with hd' tl'; · exact (splitOnP_ne_nil _ tl h').elim rw [h'] at ih rw [splitOnP_cons] split_ifs with h · rw [beq_iff_eq] at h subst h simp [ih, join, h'] cases tl' <;> simpa [join, h'] using ih #align list.intercalate_split_on List.intercalate_splitOn /-- `splitOn x` is the left inverse of `intercalate [x]`, on the domain consisting of each nonempty list of lists `ls` whose elements do not contain `x` -/ theorem splitOn_intercalate [DecidableEq α] (x : α) (hx : ∀ l ∈ ls, x ∉ l) (hls : ls ≠ []) : ([x].intercalate ls).splitOn x = ls := by simp only [intercalate] induction' ls with hd tl ih; · contradiction cases tl · suffices hd.splitOn x = [hd] by simpa [join] refine splitOnP_eq_single _ _ ?_ intro y hy H rw [eq_of_beq H] at hy refine hx hd ?_ hy simp · simp only [intersperse_cons_cons, singleton_append, join] specialize ih _ _ · intro l hl apply hx l simp only [mem_cons] at hl ⊢ exact Or.inr hl · exact List.noConfusion have := splitOnP_first (· == x) hd ?h x (beq_self_eq_true _) case h => intro y hy H rw [eq_of_beq H] at hy exact hx hd (.head _) hy simp only [splitOn] at ih ⊢ rw [this, ih] #align list.split_on_intercalate List.splitOn_intercalate end SplitAtOn /- Porting note: new; here tentatively -/ /-! ### modifyLast -/ section ModifyLast theorem modifyLast.go_append_one (f : α → α) (a : α) (tl : List α) (r : Array α) : modifyLast.go f (tl ++ [a]) r = (r.toListAppend <| modifyLast.go f (tl ++ [a]) #[]) := by cases tl with | nil => simp only [nil_append, modifyLast.go]; rfl | cons hd tl => simp only [cons_append] rw [modifyLast.go, modifyLast.go] case x_3 | x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a []) rw [modifyLast.go_append_one _ _ tl _, modifyLast.go_append_one _ _ tl (Array.push #[] hd)] simp only [Array.toListAppend_eq, Array.push_data, Array.data_toArray, nil_append, append_assoc] theorem modifyLast_append_one (f : α → α) (a : α) (l : List α) : modifyLast f (l ++ [a]) = l ++ [f a] := by cases l with | nil => simp only [nil_append, modifyLast, modifyLast.go, Array.toListAppend_eq, Array.data_toArray] | cons _ tl => simp only [cons_append, modifyLast] rw [modifyLast.go] case x_3 => exact append_ne_nil_of_ne_nil_right tl [a] (cons_ne_nil a []) rw [modifyLast.go_append_one, Array.toListAppend_eq, Array.push_data, Array.data_toArray, nil_append, cons_append, nil_append, cons_inj] exact modifyLast_append_one _ _ tl theorem modifyLast_append (f : α → α) (l₁ l₂ : List α) (_ : l₂ ≠ []) : modifyLast f (l₁ ++ l₂) = l₁ ++ modifyLast f l₂ := by cases l₂ with | nil => contradiction | cons hd tl => cases tl with | nil => exact modifyLast_append_one _ hd _ | cons hd' tl' => rw [append_cons, ← nil_append (hd :: hd' :: tl'), append_cons [], nil_append, modifyLast_append _ (l₁ ++ [hd]) (hd' :: tl') _, modifyLast_append _ [hd] (hd' :: tl') _, append_assoc] all_goals { exact cons_ne_nil _ _ } end ModifyLast /-! ### map for partial functions -/ #align list.pmap List.pmap #align list.attach List.attach @[simp] lemma attach_nil : ([] : List α).attach = [] := rfl #align list.attach_nil List.attach_nil theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction' l with h t ih <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega #align list.sizeof_lt_sizeof_of_mem List.sizeOf_lt_sizeOf_of_mem @[simp] theorem pmap_eq_map (p : α → Prop) (f : α → β) (l : List α) (H) : @pmap _ _ p (fun a _ => f a) l H = map f l := by induction l <;> [rfl; simp only [*, pmap, map]] #align list.pmap_eq_map List.pmap_eq_map theorem pmap_congr {p q : α → Prop} {f : ∀ a, p a → β} {g : ∀ a, q a → β} (l : List α) {H₁ H₂} (h : ∀ a ∈ l, ∀ (h₁ h₂), f a h₁ = g a h₂) : pmap f l H₁ = pmap g l H₂ := by induction' l with _ _ ih · rfl · rw [pmap, pmap, h _ (mem_cons_self _ _), ih fun a ha => h a (mem_cons_of_mem _ ha)] #align list.pmap_congr List.pmap_congr theorem map_pmap {p : α → Prop} (g : β → γ) (f : ∀ a, p a → β) (l H) : map g (pmap f l H) = pmap (fun a h => g (f a h)) l H := by induction l <;> [rfl; simp only [*, pmap, map]] #align list.map_pmap List.map_pmap theorem pmap_map {p : β → Prop} (g : ∀ b, p b → γ) (f : α → β) (l H) : pmap g (map f l) H = pmap (fun a h => g (f a) h) l fun a h => H _ (mem_map_of_mem _ h) := by induction l <;> [rfl; simp only [*, pmap, map]] #align list.pmap_map List.pmap_map theorem pmap_eq_map_attach {p : α → Prop} (f : ∀ a, p a → β) (l H) : pmap f l H = l.attach.map fun x => f x.1 (H _ x.2) := by rw [attach, attachWith, map_pmap]; exact pmap_congr l fun _ _ _ _ => rfl #align list.pmap_eq_map_attach List.pmap_eq_map_attach -- @[simp] -- Porting note (#10959): lean 4 simp can't rewrite with this theorem attach_map_coe' (l : List α) (f : α → β) : (l.attach.map fun (i : {i // i ∈ l}) => f i) = l.map f := by rw [attach, attachWith, map_pmap]; exact pmap_eq_map _ _ _ _ #align list.attach_map_coe' List.attach_map_coe' theorem attach_map_val' (l : List α) (f : α → β) : (l.attach.map fun i => f i.val) = l.map f := attach_map_coe' _ _ #align list.attach_map_val' List.attach_map_val' @[simp] theorem attach_map_val (l : List α) : l.attach.map Subtype.val = l := (attach_map_coe' _ _).trans l.map_id -- Porting note: coe is expanded eagerly, so "attach_map_coe" would have the same syntactic form. #align list.attach_map_coe List.attach_map_val #align list.attach_map_val List.attach_map_val @[simp] theorem mem_attach (l : List α) : ∀ x, x ∈ l.attach | ⟨a, h⟩ => by have := mem_map.1 (by rw [attach_map_val] <;> exact h) rcases this with ⟨⟨_, _⟩, m, rfl⟩ exact m #align list.mem_attach List.mem_attach @[simp] theorem mem_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H b} : b ∈ pmap f l H ↔ ∃ (a : _) (h : a ∈ l), f a (H a h) = b := by simp only [pmap_eq_map_attach, mem_map, mem_attach, true_and_iff, Subtype.exists, eq_comm] #align list.mem_pmap List.mem_pmap @[simp] theorem length_pmap {p : α → Prop} {f : ∀ a, p a → β} {l H} : length (pmap f l H) = length l := by induction l <;> [rfl; simp only [*, pmap, length]] #align list.length_pmap List.length_pmap @[simp] theorem length_attach (L : List α) : L.attach.length = L.length := length_pmap #align list.length_attach List.length_attach @[simp] theorem pmap_eq_nil {p : α → Prop} {f : ∀ a, p a → β} {l H} : pmap f l H = [] ↔ l = [] := by rw [← length_eq_zero, length_pmap, length_eq_zero] #align list.pmap_eq_nil List.pmap_eq_nil @[simp] theorem attach_eq_nil (l : List α) : l.attach = [] ↔ l = [] := pmap_eq_nil #align list.attach_eq_nil List.attach_eq_nil theorem getLast_pmap (p : α → Prop) (f : ∀ a, p a → β) (l : List α) (hl₁ : ∀ a ∈ l, p a) (hl₂ : l ≠ []) : (l.pmap f hl₁).getLast (mt List.pmap_eq_nil.1 hl₂) = f (l.getLast hl₂) (hl₁ _ (List.getLast_mem hl₂)) := by induction' l with l_hd l_tl l_ih · apply (hl₂ rfl).elim · by_cases hl_tl : l_tl = [] · simp [hl_tl] · simp only [pmap] rw [getLast_cons, l_ih _ hl_tl] simp only [getLast_cons hl_tl] #align list.last_pmap List.getLast_pmap theorem get?_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) (n : ℕ) : get? (pmap f l h) n = Option.pmap f (get? l n) fun x H => h x (get?_mem H) := by induction' l with hd tl hl generalizing n · simp · cases' n with n · simp · simp [hl] #align list.nth_pmap List.get?_pmap theorem get_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ} (hn : n < (pmap f l h).length) : get (pmap f l h) ⟨n, hn⟩ = f (get l ⟨n, @length_pmap _ _ p f l h ▸ hn⟩) (h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) := by induction' l with hd tl hl generalizing n · simp only [length, pmap] at hn exact absurd hn (not_lt_of_le n.zero_le) · cases n · simp · simp [hl] set_option linter.deprecated false in @[deprecated get_pmap (since := "2023-01-05")] theorem nthLe_pmap {p : α → Prop} (f : ∀ a, p a → β) {l : List α} (h : ∀ a ∈ l, p a) {n : ℕ} (hn : n < (pmap f l h).length) : nthLe (pmap f l h) n hn = f (nthLe l n (@length_pmap _ _ p f l h ▸ hn)) (h _ (get_mem l n (@length_pmap _ _ p f l h ▸ hn))) := get_pmap .. #align list.nth_le_pmap List.nthLe_pmap theorem pmap_append {p : ι → Prop} (f : ∀ a : ι, p a → α) (l₁ l₂ : List ι) (h : ∀ a ∈ l₁ ++ l₂, p a) : (l₁ ++ l₂).pmap f h = (l₁.pmap f fun a ha => h a (mem_append_left l₂ ha)) ++ l₂.pmap f fun a ha => h a (mem_append_right l₁ ha) := by induction' l₁ with _ _ ih · rfl · dsimp only [pmap, cons_append] rw [ih] #align list.pmap_append List.pmap_append theorem pmap_append' {p : α → Prop} (f : ∀ a : α, p a → β) (l₁ l₂ : List α) (h₁ : ∀ a ∈ l₁, p a) (h₂ : ∀ a ∈ l₂, p a) : ((l₁ ++ l₂).pmap f fun a ha => (List.mem_append.1 ha).elim (h₁ a) (h₂ a)) = l₁.pmap f h₁ ++ l₂.pmap f h₂ := pmap_append f l₁ l₂ _ #align list.pmap_append' List.pmap_append' /-! ### find -/ section find? variable {p : α → Bool} {l : List α} {a : α} #align list.find_nil List.find?_nil -- @[simp] -- Later porting note (at time of this lemma moving to Batteries): -- removing attribute `nolint simpNF` attribute [simp 1100] find?_cons_of_pos #align list.find_cons_of_pos List.find?_cons_of_pos -- @[simp] -- Later porting note (at time of this lemma moving to Batteries): -- removing attribute `nolint simpNF` attribute [simp 1100] find?_cons_of_neg #align list.find_cons_of_neg List.find?_cons_of_neg attribute [simp] find?_eq_none #align list.find_eq_none List.find?_eq_none #align list.find_some List.find?_some @[deprecated (since := "2024-05-05")] alias find?_mem := mem_of_find?_eq_some #align list.find_mem List.mem_of_find?_eq_some end find? /-! ### lookmap -/ section Lookmap variable (f : α → Option α) /- Porting note: need a helper theorem for lookmap.go. -/ theorem lookmap.go_append (l : List α) (acc : Array α) : lookmap.go f l acc = acc.toListAppend (lookmap f l) := by cases l with | nil => rfl | cons hd tl => rw [lookmap, go, go] cases f hd with | none => simp only [go_append tl _, Array.toListAppend_eq, append_assoc, Array.push_data]; rfl | some a => rfl @[simp] theorem lookmap_nil : [].lookmap f = [] := rfl #align list.lookmap_nil List.lookmap_nil @[simp] theorem lookmap_cons_none {a : α} (l : List α) (h : f a = none) : (a :: l).lookmap f = a :: l.lookmap f := by simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append] rw [lookmap.go_append, h]; rfl #align list.lookmap_cons_none List.lookmap_cons_none @[simp] theorem lookmap_cons_some {a b : α} (l : List α) (h : f a = some b) : (a :: l).lookmap f = b :: l := by simp only [lookmap, lookmap.go, Array.toListAppend_eq, Array.data_toArray, nil_append] rw [h] #align list.lookmap_cons_some List.lookmap_cons_some theorem lookmap_some : ∀ l : List α, l.lookmap some = l | [] => rfl | _ :: _ => rfl #align list.lookmap_some List.lookmap_some theorem lookmap_none : ∀ l : List α, (l.lookmap fun _ => none) = l | [] => rfl | a :: l => (lookmap_cons_none _ l rfl).trans (congr_arg (cons a) (lookmap_none l)) #align list.lookmap_none List.lookmap_none theorem lookmap_congr {f g : α → Option α} : ∀ {l : List α}, (∀ a ∈ l, f a = g a) → l.lookmap f = l.lookmap g | [], _ => rfl | a :: l, H => by cases' forall_mem_cons.1 H with H₁ H₂ cases' h : g a with b · simp [h, H₁.trans h, lookmap_congr H₂] · simp [lookmap_cons_some _ _ h, lookmap_cons_some _ _ (H₁.trans h)] #align list.lookmap_congr List.lookmap_congr theorem lookmap_of_forall_not {l : List α} (H : ∀ a ∈ l, f a = none) : l.lookmap f = l := (lookmap_congr H).trans (lookmap_none l) #align list.lookmap_of_forall_not List.lookmap_of_forall_not theorem lookmap_map_eq (g : α → β) (h : ∀ (a), ∀ b ∈ f a, g a = g b) : ∀ l : List α, map g (l.lookmap f) = map g l | [] => rfl | a :: l => by cases' h' : f a with b · simpa [h'] using lookmap_map_eq _ h l · simp [lookmap_cons_some _ _ h', h _ _ h'] #align list.lookmap_map_eq List.lookmap_map_eq theorem lookmap_id' (h : ∀ (a), ∀ b ∈ f a, a = b) (l : List α) : l.lookmap f = l := by rw [← map_id (l.lookmap f), lookmap_map_eq, map_id]; exact h #align list.lookmap_id' List.lookmap_id' theorem length_lookmap (l : List α) : length (l.lookmap f) = length l := by rw [← length_map, lookmap_map_eq _ fun _ => (), length_map]; simp #align list.length_lookmap List.length_lookmap end Lookmap /-! ### filter -/ theorem length_eq_length_filter_add {l : List (α)} (f : α → Bool) : l.length = (l.filter f).length + (l.filter (! f ·)).length := by simp_rw [← List.countP_eq_length_filter, l.length_eq_countP_add_countP f, Bool.not_eq_true, Bool.decide_eq_false] /-! ### filterMap -/ #align list.filter_map_nil List.filterMap_nil -- Later porting note (at time of this lemma moving to Batteries): -- removing attribute `nolint simpNF` attribute [simp 1100] filterMap_cons_none #align list.filter_map_cons_none List.filterMap_cons_none -- Later porting note (at time of this lemma moving to Batteries): -- removing attribute `nolint simpNF` attribute [simp 1100] filterMap_cons_some #align list.filter_map_cons_some List.filterMap_cons_some #align list.filter_map_cons List.filterMap_cons #align list.filter_map_append List.filterMap_append #align list.filter_map_eq_map List.filterMap_eq_map #align list.filter_map_eq_filter List.filterMap_eq_filter #align list.filter_map_filter_map List.filterMap_filterMap #align list.map_filter_map List.map_filterMap #align list.filter_map_map List.filterMap_map #align list.filter_filter_map List.filter_filterMap #align list.filter_map_filter List.filterMap_filter #align list.filter_map_some List.filterMap_some #align list.map_filter_map_some_eq_filter_map_is_some List.map_filterMap_some_eq_filter_map_is_some #align list.mem_filter_map List.mem_filterMap #align list.filter_map_join List.filterMap_join #align list.map_filter_map_of_inv List.map_filterMap_of_inv #align list.length_filter_le List.length_filter_leₓ #align list.length_filter_map_le List.length_filterMap_le #align list.sublist.filter_map List.Sublist.filterMap theorem Sublist.map (f : α → β) {l₁ l₂ : List α} (s : l₁ <+ l₂) : map f l₁ <+ map f l₂ := filterMap_eq_map f ▸ s.filterMap _ #align list.sublist.map List.Sublist.map theorem filterMap_eq_bind_toList (f : α → Option β) (l : List α) : l.filterMap f = l.bind fun a ↦ (f a).toList := by induction' l with a l ih <;> simp rcases f a <;> simp [ih] theorem filterMap_congr {f g : α → Option β} {l : List α} (h : ∀ x ∈ l, f x = g x) : l.filterMap f = l.filterMap g := by induction' l with a l ih <;> simp simp [ih (fun x hx ↦ h x (List.mem_cons_of_mem a hx))] cases' hfa : f a with b · have : g a = none := Eq.symm (by simpa [hfa] using h a (by simp)) simp [this] · have : g a = some b := Eq.symm (by simpa [hfa] using h a (by simp)) simp [this] theorem filterMap_eq_map_iff_forall_eq_some {f : α → Option β} {g : α → β} {l : List α} : l.filterMap f = l.map g ↔ ∀ x ∈ l, f x = some (g x) where mp := by induction' l with a l ih · simp cases' ha : f a with b <;> simp [ha] · intro h simpa [show (filterMap f l).length = l.length + 1 from by simp[h], Nat.add_one_le_iff] using List.length_filterMap_le f l · rintro rfl h exact ⟨rfl, ih h⟩ mpr h := Eq.trans (filterMap_congr <| by simpa) (congr_fun (List.filterMap_eq_map _) _) /-! ### filter -/ section Filter -- Porting note: Lemmas for `filter` are stated in terms of `p : α → Bool` -- rather than `p : α → Prop` with `DecidablePred p`, since `filter` itself is. -- Likewise, `if` sometimes becomes `bif`. variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl #align list.filter_singleton List.filter_singleton theorem filter_eq_foldr (p : α → Bool) (l : List α) : filter p l = foldr (fun a out => bif p a then a :: out else out) [] l := by induction l <;> simp [*, filter]; rfl #align list.filter_eq_foldr List.filter_eq_foldr #align list.filter_congr' List.filter_congr' @[simp] theorem filter_subset (l : List α) : filter p l ⊆ l := (filter_sublist l).subset #align list.filter_subset List.filter_subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 #align list.of_mem_filter List.of_mem_filter theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset l h #align list.mem_of_mem_filter List.mem_of_mem_filter theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ #align list.mem_filter_of_mem List.mem_filter_of_mem #align list.mem_filter List.mem_filter theorem monotone_filter_left (p : α → Bool) ⦃l l' : List α⦄ (h : l ⊆ l') : filter p l ⊆ filter p l' := by intro x hx rw [mem_filter] at hx ⊢ exact ⟨h hx.left, hx.right⟩ #align list.monotone_filter_left List.monotone_filter_left #align list.filter_eq_self List.filter_eq_self #align list.filter_length_eq_length List.filter_length_eq_length #align list.filter_eq_nil List.filter_eq_nil variable (p) #align list.sublist.filter List.Sublist.filter theorem monotone_filter_right (l : List α) ⦃p q : α → Bool⦄ (h : ∀ a, p a → q a) : l.filter p <+ l.filter q := by induction' l with hd tl IH · rfl · by_cases hp : p hd · rw [filter_cons_of_pos _ hp, filter_cons_of_pos _ (h _ hp)] exact IH.cons_cons hd · rw [filter_cons_of_neg _ hp] by_cases hq : q hd · rw [filter_cons_of_pos _ hq] exact sublist_cons_of_sublist hd IH · rw [filter_cons_of_neg _ hq] exact IH #align list.monotone_filter_right List.monotone_filter_right #align list.map_filter List.map_filter lemma map_filter' {f : α → β} (hf : Injective f) (l : List α) [DecidablePred fun b => ∃ a, p a ∧ f a = b] : (l.filter p).map f = (l.map f).filter fun b => ∃ a, p a ∧ f a = b := by simp [(· ∘ ·), map_filter, hf.eq_iff] #align list.map_filter' List.map_filter' lemma filter_attach' (l : List α) (p : {a // a ∈ l} → Bool) [DecidableEq α] : l.attach.filter p = (l.filter fun x => ∃ h, p ⟨x, h⟩).attach.map (Subtype.map id fun x => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [(· ∘ ·), map_filter' _ Subtype.coe_injective] #align list.filter_attach' List.filter_attach' -- Porting note: `Lean.Internal.coeM` forces us to type-ascript `{x // x ∈ l}` lemma filter_attach (l : List α) (p : α → Bool) : (l.attach.filter fun x => p x : List {x // x ∈ l}) = (l.filter p).attach.map (Subtype.map id fun x => mem_of_mem_filter) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, (· ∘ ·), Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← map_filter, attach_map_val] #align list.filter_attach List.filter_attach #align list.filter_filter List.filter_filter lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [and_comm] #align list.filter_comm List.filter_comm @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] #align list.filter_true List.filter_true @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] #align list.filter_false List.filter_false /- Porting note: need a helper theorem for span.loop. -/ theorem span.loop_eq_take_drop : ∀ l₁ l₂ : List α, span.loop p l₁ l₂ = (l₂.reverse ++ takeWhile p l₁, dropWhile p l₁) | [], l₂ => by simp [span.loop, takeWhile, dropWhile] | (a :: l), l₂ => by cases hp : p a <;> simp [hp, span.loop, span.loop_eq_take_drop, takeWhile, dropWhile] @[simp] theorem span_eq_take_drop (l : List α) : span p l = (takeWhile p l, dropWhile p l) := by simpa using span.loop_eq_take_drop p l [] #align list.span_eq_take_drop List.span_eq_take_drop #align list.take_while_append_drop List.takeWhile_append_dropWhile -- TODO update to use `get` instead of `nthLe` set_option linter.deprecated false in
Mathlib/Data/List/Basic.lean
2,977
2,984
theorem dropWhile_nthLe_zero_not (l : List α) (hl : 0 < (l.dropWhile p).length) : ¬p ((l.dropWhile p).nthLe 0 hl) := by
induction' l with hd tl IH · cases hl · simp only [dropWhile] by_cases hp : p hd · simp [hp, IH] · simp [hp, nthLe_cons]
/- 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, Scott Morrison -/ import Mathlib.Algebra.Group.Indicator import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Data.Set.Finite #align_import data.finsupp.defs from "leanprover-community/mathlib"@"842328d9df7e96fd90fc424e115679c15fb23a71" /-! # Type of functions with finite support For any type `α` and any type `M` with zero, we define the type `Finsupp α M` (notation: `α →₀ M`) of finitely supported functions from `α` to `M`, i.e. the functions which are zero everywhere on `α` except on a finite set. Functions with finite support are used (at least) in the following parts of the library: * `MonoidAlgebra R M` and `AddMonoidAlgebra R M` are defined as `M →₀ R`; * polynomials and multivariate polynomials are defined as `AddMonoidAlgebra`s, hence they use `Finsupp` under the hood; * the linear combination of a family of vectors `v i` with coefficients `f i` (as used, e.g., to define linearly independent family `LinearIndependent`) is defined as a map `Finsupp.total : (ι → M) → (ι →₀ R) →ₗ[R] M`. Some other constructions are naturally equivalent to `α →₀ M` with some `α` and `M` but are defined in a different way in the library: * `Multiset α ≃+ α →₀ ℕ`; * `FreeAbelianGroup α ≃+ α →₀ ℤ`. Most of the theory assumes that the range is a commutative additive monoid. This gives us the big sum operator as a powerful way to construct `Finsupp` elements, which is defined in `Algebra/BigOperators/Finsupp`. -- Porting note: the semireducibility remark no longer applies in Lean 4, afaict. Many constructions based on `α →₀ M` use `semireducible` type tags to avoid reusing unwanted type instances. E.g., `MonoidAlgebra`, `AddMonoidAlgebra`, and types based on these two have non-pointwise multiplication. ## Main declarations * `Finsupp`: The type of finitely supported functions from `α` to `β`. * `Finsupp.single`: The `Finsupp` which is nonzero in exactly one point. * `Finsupp.update`: Changes one value of a `Finsupp`. * `Finsupp.erase`: Replaces one value of a `Finsupp` by `0`. * `Finsupp.onFinset`: The restriction of a function to a `Finset` as a `Finsupp`. * `Finsupp.mapRange`: Composition of a `ZeroHom` with a `Finsupp`. * `Finsupp.embDomain`: Maps the domain of a `Finsupp` by an embedding. * `Finsupp.zipWith`: Postcomposition of two `Finsupp`s with a function `f` such that `f 0 0 = 0`. ## Notations This file adds `α →₀ M` as a global notation for `Finsupp α M`. We also use the following convention for `Type*` variables in this file * `α`, `β`, `γ`: types with no additional structure that appear as the first argument to `Finsupp` somewhere in the statement; * `ι` : an auxiliary index type; * `M`, `M'`, `N`, `P`: types with `Zero` or `(Add)(Comm)Monoid` structure; `M` is also used for a (semi)module over a (semi)ring. * `G`, `H`: groups (commutative or not, multiplicative or additive); * `R`, `S`: (semi)rings. ## Implementation notes This file is a `noncomputable theory` and uses classical logic throughout. ## TODO * Expand the list of definitions and important lemmas to the module docstring. -/ noncomputable section open Finset Function variable {α β γ ι M M' N P G H R S : Type*} /-- `Finsupp α M`, denoted `α →₀ M`, is the type of functions `f : α → M` such that `f x = 0` for all but finitely many `x`. -/ structure Finsupp (α : Type*) (M : Type*) [Zero M] where /-- The support of a finitely supported function (aka `Finsupp`). -/ support : Finset α /-- The underlying function of a bundled finitely supported function (aka `Finsupp`). -/ toFun : α → M /-- The witness that the support of a `Finsupp` is indeed the exact locus where its underlying function is nonzero. -/ mem_support_toFun : ∀ a, a ∈ support ↔ toFun a ≠ 0 #align finsupp Finsupp #align finsupp.support Finsupp.support #align finsupp.to_fun Finsupp.toFun #align finsupp.mem_support_to_fun Finsupp.mem_support_toFun @[inherit_doc] infixr:25 " →₀ " => Finsupp namespace Finsupp /-! ### Basic declarations about `Finsupp` -/ section Basic variable [Zero M] instance instFunLike : FunLike (α →₀ M) α M := ⟨toFun, by rintro ⟨s, f, hf⟩ ⟨t, g, hg⟩ (rfl : f = g) congr ext a exact (hf _).trans (hg _).symm⟩ #align finsupp.fun_like Finsupp.instFunLike /-- Helper instance for when there are too many metavariables to apply the `DFunLike` instance directly. -/ instance instCoeFun : CoeFun (α →₀ M) fun _ => α → M := inferInstance #align finsupp.has_coe_to_fun Finsupp.instCoeFun @[ext] theorem ext {f g : α →₀ M} (h : ∀ a, f a = g a) : f = g := DFunLike.ext _ _ h #align finsupp.ext Finsupp.ext #align finsupp.ext_iff DFunLike.ext_iff lemma ne_iff {f g : α →₀ M} : f ≠ g ↔ ∃ a, f a ≠ g a := DFunLike.ne_iff #align finsupp.coe_fn_inj DFunLike.coe_fn_eq #align finsupp.coe_fn_injective DFunLike.coe_injective #align finsupp.congr_fun DFunLike.congr_fun @[simp, norm_cast] theorem coe_mk (f : α → M) (s : Finset α) (h : ∀ a, a ∈ s ↔ f a ≠ 0) : ⇑(⟨s, f, h⟩ : α →₀ M) = f := rfl #align finsupp.coe_mk Finsupp.coe_mk instance instZero : Zero (α →₀ M) := ⟨⟨∅, 0, fun _ => ⟨fun h ↦ (not_mem_empty _ h).elim, fun H => (H rfl).elim⟩⟩⟩ #align finsupp.has_zero Finsupp.instZero @[simp, norm_cast] lemma coe_zero : ⇑(0 : α →₀ M) = 0 := rfl #align finsupp.coe_zero Finsupp.coe_zero theorem zero_apply {a : α} : (0 : α →₀ M) a = 0 := rfl #align finsupp.zero_apply Finsupp.zero_apply @[simp] theorem support_zero : (0 : α →₀ M).support = ∅ := rfl #align finsupp.support_zero Finsupp.support_zero instance instInhabited : Inhabited (α →₀ M) := ⟨0⟩ #align finsupp.inhabited Finsupp.instInhabited @[simp] theorem mem_support_iff {f : α →₀ M} : ∀ {a : α}, a ∈ f.support ↔ f a ≠ 0 := @(f.mem_support_toFun) #align finsupp.mem_support_iff Finsupp.mem_support_iff @[simp, norm_cast] theorem fun_support_eq (f : α →₀ M) : Function.support f = f.support := Set.ext fun _x => mem_support_iff.symm #align finsupp.fun_support_eq Finsupp.fun_support_eq theorem not_mem_support_iff {f : α →₀ M} {a} : a ∉ f.support ↔ f a = 0 := not_iff_comm.1 mem_support_iff.symm #align finsupp.not_mem_support_iff Finsupp.not_mem_support_iff @[simp, norm_cast] theorem coe_eq_zero {f : α →₀ M} : (f : α → M) = 0 ↔ f = 0 := by rw [← coe_zero, DFunLike.coe_fn_eq] #align finsupp.coe_eq_zero Finsupp.coe_eq_zero theorem ext_iff' {f g : α →₀ M} : f = g ↔ f.support = g.support ∧ ∀ x ∈ f.support, f x = g x := ⟨fun h => h ▸ ⟨rfl, fun _ _ => rfl⟩, fun ⟨h₁, h₂⟩ => ext fun a => by classical exact if h : a ∈ f.support then h₂ a h else by have hf : f a = 0 := not_mem_support_iff.1 h have hg : g a = 0 := by rwa [h₁, not_mem_support_iff] at h rw [hf, hg]⟩ #align finsupp.ext_iff' Finsupp.ext_iff' @[simp] theorem support_eq_empty {f : α →₀ M} : f.support = ∅ ↔ f = 0 := mod_cast @Function.support_eq_empty_iff _ _ _ f #align finsupp.support_eq_empty Finsupp.support_eq_empty theorem support_nonempty_iff {f : α →₀ M} : f.support.Nonempty ↔ f ≠ 0 := by simp only [Finsupp.support_eq_empty, Finset.nonempty_iff_ne_empty, Ne] #align finsupp.support_nonempty_iff Finsupp.support_nonempty_iff #align finsupp.nonzero_iff_exists Finsupp.ne_iff theorem card_support_eq_zero {f : α →₀ M} : card f.support = 0 ↔ f = 0 := by simp #align finsupp.card_support_eq_zero Finsupp.card_support_eq_zero instance instDecidableEq [DecidableEq α] [DecidableEq M] : DecidableEq (α →₀ M) := fun f g => decidable_of_iff (f.support = g.support ∧ ∀ a ∈ f.support, f a = g a) ext_iff'.symm #align finsupp.decidable_eq Finsupp.instDecidableEq theorem finite_support (f : α →₀ M) : Set.Finite (Function.support f) := f.fun_support_eq.symm ▸ f.support.finite_toSet #align finsupp.finite_support Finsupp.finite_support theorem support_subset_iff {s : Set α} {f : α →₀ M} : ↑f.support ⊆ s ↔ ∀ a ∉ s, f a = 0 := by simp only [Set.subset_def, mem_coe, mem_support_iff]; exact forall_congr' fun a => not_imp_comm #align finsupp.support_subset_iff Finsupp.support_subset_iff /-- Given `Finite α`, `equivFunOnFinite` is the `Equiv` between `α →₀ β` and `α → β`. (All functions on a finite type are finitely supported.) -/ @[simps] def equivFunOnFinite [Finite α] : (α →₀ M) ≃ (α → M) where toFun := (⇑) invFun f := mk (Function.support f).toFinite.toFinset f fun _a => Set.Finite.mem_toFinset _ left_inv _f := ext fun _x => rfl right_inv _f := rfl #align finsupp.equiv_fun_on_finite Finsupp.equivFunOnFinite @[simp] theorem equivFunOnFinite_symm_coe {α} [Finite α] (f : α →₀ M) : equivFunOnFinite.symm f = f := equivFunOnFinite.symm_apply_apply f #align finsupp.equiv_fun_on_finite_symm_coe Finsupp.equivFunOnFinite_symm_coe /-- If `α` has a unique term, the type of finitely supported functions `α →₀ β` is equivalent to `β`. -/ @[simps!] noncomputable def _root_.Equiv.finsuppUnique {ι : Type*} [Unique ι] : (ι →₀ M) ≃ M := Finsupp.equivFunOnFinite.trans (Equiv.funUnique ι M) #align equiv.finsupp_unique Equiv.finsuppUnique #align equiv.finsupp_unique_symm_apply_support_val Equiv.finsuppUnique_symm_apply_support_val #align equiv.finsupp_unique_symm_apply_to_fun Equiv.finsuppUnique_symm_apply_toFun #align equiv.finsupp_unique_apply Equiv.finsuppUnique_apply @[ext] theorem unique_ext [Unique α] {f g : α →₀ M} (h : f default = g default) : f = g := ext fun a => by rwa [Unique.eq_default a] #align finsupp.unique_ext Finsupp.unique_ext theorem unique_ext_iff [Unique α] {f g : α →₀ M} : f = g ↔ f default = g default := ⟨fun h => h ▸ rfl, unique_ext⟩ #align finsupp.unique_ext_iff Finsupp.unique_ext_iff end Basic /-! ### Declarations about `single` -/ section Single variable [Zero M] {a a' : α} {b : M} /-- `single a b` is the finitely supported function with value `b` at `a` and zero otherwise. -/ def single (a : α) (b : M) : α →₀ M where support := haveI := Classical.decEq M if b = 0 then ∅ else {a} toFun := haveI := Classical.decEq α Pi.single a b mem_support_toFun a' := by classical obtain rfl | hb := eq_or_ne b 0 · simp [Pi.single, update] rw [if_neg hb, mem_singleton] obtain rfl | ha := eq_or_ne a' a · simp [hb, Pi.single, update] simp [Pi.single_eq_of_ne' ha.symm, ha] #align finsupp.single Finsupp.single theorem single_apply [Decidable (a = a')] : single a b a' = if a = a' then b else 0 := by classical simp_rw [@eq_comm _ a a'] convert Pi.single_apply a b a' #align finsupp.single_apply Finsupp.single_apply theorem single_apply_left {f : α → β} (hf : Function.Injective f) (x z : α) (y : M) : single (f x) y (f z) = single x y z := by classical simp only [single_apply, hf.eq_iff] #align finsupp.single_apply_left Finsupp.single_apply_left theorem single_eq_set_indicator : ⇑(single a b) = Set.indicator {a} fun _ => b := by classical ext simp [single_apply, Set.indicator, @eq_comm _ a] #align finsupp.single_eq_set_indicator Finsupp.single_eq_set_indicator @[simp] theorem single_eq_same : (single a b : α →₀ M) a = b := by classical exact Pi.single_eq_same (f := fun _ ↦ M) a b #align finsupp.single_eq_same Finsupp.single_eq_same @[simp] theorem single_eq_of_ne (h : a ≠ a') : (single a b : α →₀ M) a' = 0 := by classical exact Pi.single_eq_of_ne' h _ #align finsupp.single_eq_of_ne Finsupp.single_eq_of_ne theorem single_eq_update [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Function.update (0 : _) a b := by classical rw [single_eq_set_indicator, ← Set.piecewise_eq_indicator, Set.piecewise_singleton] #align finsupp.single_eq_update Finsupp.single_eq_update theorem single_eq_pi_single [DecidableEq α] (a : α) (b : M) : ⇑(single a b) = Pi.single a b := single_eq_update a b #align finsupp.single_eq_pi_single Finsupp.single_eq_pi_single @[simp] theorem single_zero (a : α) : (single a 0 : α →₀ M) = 0 := DFunLike.coe_injective <| by classical simpa only [single_eq_update, coe_zero] using Function.update_eq_self a (0 : α → M) #align finsupp.single_zero Finsupp.single_zero theorem single_of_single_apply (a a' : α) (b : M) : single a ((single a' b) a) = single a' (single a' b) a := by classical rw [single_apply, single_apply] ext split_ifs with h · rw [h] · rw [zero_apply, single_apply, ite_self] #align finsupp.single_of_single_apply Finsupp.single_of_single_apply theorem support_single_ne_zero (a : α) (hb : b ≠ 0) : (single a b).support = {a} := if_neg hb #align finsupp.support_single_ne_zero Finsupp.support_single_ne_zero theorem support_single_subset : (single a b).support ⊆ {a} := by classical show ite _ _ _ ⊆ _; split_ifs <;> [exact empty_subset _; exact Subset.refl _] #align finsupp.support_single_subset Finsupp.support_single_subset theorem single_apply_mem (x) : single a b x ∈ ({0, b} : Set M) := by rcases em (a = x) with (rfl | hx) <;> [simp; simp [single_eq_of_ne hx]] #align finsupp.single_apply_mem Finsupp.single_apply_mem theorem range_single_subset : Set.range (single a b) ⊆ {0, b} := Set.range_subset_iff.2 single_apply_mem #align finsupp.range_single_subset Finsupp.range_single_subset /-- `Finsupp.single a b` is injective in `b`. For the statement that it is injective in `a`, see `Finsupp.single_left_injective` -/ theorem single_injective (a : α) : Function.Injective (single a : M → α →₀ M) := fun b₁ b₂ eq => by have : (single a b₁ : α →₀ M) a = (single a b₂ : α →₀ M) a := by rw [eq] rwa [single_eq_same, single_eq_same] at this #align finsupp.single_injective Finsupp.single_injective theorem single_apply_eq_zero {a x : α} {b : M} : single a b x = 0 ↔ x = a → b = 0 := by simp [single_eq_set_indicator] #align finsupp.single_apply_eq_zero Finsupp.single_apply_eq_zero theorem single_apply_ne_zero {a x : α} {b : M} : single a b x ≠ 0 ↔ x = a ∧ b ≠ 0 := by simp [single_apply_eq_zero] #align finsupp.single_apply_ne_zero Finsupp.single_apply_ne_zero theorem mem_support_single (a a' : α) (b : M) : a ∈ (single a' b).support ↔ a = a' ∧ b ≠ 0 := by simp [single_apply_eq_zero, not_or] #align finsupp.mem_support_single Finsupp.mem_support_single theorem eq_single_iff {f : α →₀ M} {a b} : f = single a b ↔ f.support ⊆ {a} ∧ f a = b := by refine ⟨fun h => h.symm ▸ ⟨support_single_subset, single_eq_same⟩, ?_⟩ rintro ⟨h, rfl⟩ ext x by_cases hx : a = x <;> simp only [hx, single_eq_same, single_eq_of_ne, Ne, not_false_iff] exact not_mem_support_iff.1 (mt (fun hx => (mem_singleton.1 (h hx)).symm) hx) #align finsupp.eq_single_iff Finsupp.eq_single_iff theorem single_eq_single_iff (a₁ a₂ : α) (b₁ b₂ : M) : single a₁ b₁ = single a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ b₁ = 0 ∧ b₂ = 0 := by constructor · intro eq by_cases h : a₁ = a₂ · refine Or.inl ⟨h, ?_⟩ rwa [h, (single_injective a₂).eq_iff] at eq · rw [DFunLike.ext_iff] at eq have h₁ := eq a₁ have h₂ := eq a₂ simp only [single_eq_same, single_eq_of_ne h, single_eq_of_ne (Ne.symm h)] at h₁ h₂ exact Or.inr ⟨h₁, h₂.symm⟩ · rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · rfl · rw [single_zero, single_zero] #align finsupp.single_eq_single_iff Finsupp.single_eq_single_iff /-- `Finsupp.single a b` is injective in `a`. For the statement that it is injective in `b`, see `Finsupp.single_injective` -/ theorem single_left_injective (h : b ≠ 0) : Function.Injective fun a : α => single a b := fun _a _a' H => (((single_eq_single_iff _ _ _ _).mp H).resolve_right fun hb => h hb.1).left #align finsupp.single_left_injective Finsupp.single_left_injective theorem single_left_inj (h : b ≠ 0) : single a b = single a' b ↔ a = a' := (single_left_injective h).eq_iff #align finsupp.single_left_inj Finsupp.single_left_inj theorem support_single_ne_bot (i : α) (h : b ≠ 0) : (single i b).support ≠ ⊥ := by simpa only [support_single_ne_zero _ h] using singleton_ne_empty _ #align finsupp.support_single_ne_bot Finsupp.support_single_ne_bot theorem support_single_disjoint {b' : M} (hb : b ≠ 0) (hb' : b' ≠ 0) {i j : α} : Disjoint (single i b).support (single j b').support ↔ i ≠ j := by rw [support_single_ne_zero _ hb, support_single_ne_zero _ hb', disjoint_singleton] #align finsupp.support_single_disjoint Finsupp.support_single_disjoint @[simp] theorem single_eq_zero : single a b = 0 ↔ b = 0 := by simp [DFunLike.ext_iff, single_eq_set_indicator] #align finsupp.single_eq_zero Finsupp.single_eq_zero theorem single_swap (a₁ a₂ : α) (b : M) : single a₁ b a₂ = single a₂ b a₁ := by classical simp only [single_apply, eq_comm] #align finsupp.single_swap Finsupp.single_swap instance instNontrivial [Nonempty α] [Nontrivial M] : Nontrivial (α →₀ M) := by inhabit α rcases exists_ne (0 : M) with ⟨x, hx⟩ exact nontrivial_of_ne (single default x) 0 (mt single_eq_zero.1 hx) #align finsupp.nontrivial Finsupp.instNontrivial theorem unique_single [Unique α] (x : α →₀ M) : x = single default (x default) := ext <| Unique.forall_iff.2 single_eq_same.symm #align finsupp.unique_single Finsupp.unique_single @[simp] theorem unique_single_eq_iff [Unique α] {b' : M} : single a b = single a' b' ↔ b = b' := by rw [unique_ext_iff, Unique.eq_default a, Unique.eq_default a', single_eq_same, single_eq_same] #align finsupp.unique_single_eq_iff Finsupp.unique_single_eq_iff lemma apply_single [AddCommMonoid N] [AddCommMonoid P] {F : Type*} [FunLike F N P] [AddMonoidHomClass F N P] (e : F) (a : α) (n : N) (b : α) : e ((single a n) b) = single a (e n) b := by classical simp only [single_apply] split_ifs · rfl · exact map_zero e theorem support_eq_singleton {f : α →₀ M} {a : α} : f.support = {a} ↔ f a ≠ 0 ∧ f = single a (f a) := ⟨fun h => ⟨mem_support_iff.1 <| h.symm ▸ Finset.mem_singleton_self a, eq_single_iff.2 ⟨subset_of_eq h, rfl⟩⟩, fun h => h.2.symm ▸ support_single_ne_zero _ h.1⟩ #align finsupp.support_eq_singleton Finsupp.support_eq_singleton theorem support_eq_singleton' {f : α →₀ M} {a : α} : f.support = {a} ↔ ∃ b ≠ 0, f = single a b := ⟨fun h => let h := support_eq_singleton.1 h ⟨_, h.1, h.2⟩, fun ⟨_b, hb, hf⟩ => hf.symm ▸ support_single_ne_zero _ hb⟩ #align finsupp.support_eq_singleton' Finsupp.support_eq_singleton' theorem card_support_eq_one {f : α →₀ M} : card f.support = 1 ↔ ∃ a, f a ≠ 0 ∧ f = single a (f a) := by simp only [card_eq_one, support_eq_singleton] #align finsupp.card_support_eq_one Finsupp.card_support_eq_one theorem card_support_eq_one' {f : α →₀ M} : card f.support = 1 ↔ ∃ a, ∃ b ≠ 0, f = single a b := by simp only [card_eq_one, support_eq_singleton'] #align finsupp.card_support_eq_one' Finsupp.card_support_eq_one' theorem support_subset_singleton {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ f = single a (f a) := ⟨fun h => eq_single_iff.mpr ⟨h, rfl⟩, fun h => (eq_single_iff.mp h).left⟩ #align finsupp.support_subset_singleton Finsupp.support_subset_singleton theorem support_subset_singleton' {f : α →₀ M} {a : α} : f.support ⊆ {a} ↔ ∃ b, f = single a b := ⟨fun h => ⟨f a, support_subset_singleton.mp h⟩, fun ⟨b, hb⟩ => by rw [hb, support_subset_singleton, single_eq_same]⟩ #align finsupp.support_subset_singleton' Finsupp.support_subset_singleton' theorem card_support_le_one [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a, f = single a (f a) := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton] #align finsupp.card_support_le_one Finsupp.card_support_le_one theorem card_support_le_one' [Nonempty α] {f : α →₀ M} : card f.support ≤ 1 ↔ ∃ a b, f = single a b := by simp only [card_le_one_iff_subset_singleton, support_subset_singleton'] #align finsupp.card_support_le_one' Finsupp.card_support_le_one' @[simp] theorem equivFunOnFinite_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite (Finsupp.single x m) = Pi.single x m := by ext simp [Finsupp.single_eq_pi_single, equivFunOnFinite] #align finsupp.equiv_fun_on_finite_single Finsupp.equivFunOnFinite_single @[simp] theorem equivFunOnFinite_symm_single [DecidableEq α] [Finite α] (x : α) (m : M) : Finsupp.equivFunOnFinite.symm (Pi.single x m) = Finsupp.single x m := by rw [← equivFunOnFinite_single, Equiv.symm_apply_apply] #align finsupp.equiv_fun_on_finite_symm_single Finsupp.equivFunOnFinite_symm_single end Single /-! ### Declarations about `update` -/ section Update variable [Zero M] (f : α →₀ M) (a : α) (b : M) (i : α) /-- Replace the value of a `α →₀ M` at a given point `a : α` by a given value `b : M`. If `b = 0`, this amounts to removing `a` from the `Finsupp.support`. Otherwise, if `a` was not in the `Finsupp.support`, it is added to it. This is the finitely-supported version of `Function.update`. -/ def update (f : α →₀ M) (a : α) (b : M) : α →₀ M where support := by haveI := Classical.decEq α; haveI := Classical.decEq M exact if b = 0 then f.support.erase a else insert a f.support toFun := haveI := Classical.decEq α Function.update f a b mem_support_toFun i := by classical rw [Function.update] simp only [eq_rec_constant, dite_eq_ite, ne_eq] split_ifs with hb ha ha <;> try simp only [*, not_false_iff, iff_true, not_true, iff_false] · rw [Finset.mem_erase] simp · rw [Finset.mem_erase] simp [ha] · rw [Finset.mem_insert] simp [ha] · rw [Finset.mem_insert] simp [ha] #align finsupp.update Finsupp.update @[simp, norm_cast] theorem coe_update [DecidableEq α] : (f.update a b : α → M) = Function.update f a b := by delta update Function.update ext dsimp split_ifs <;> simp #align finsupp.coe_update Finsupp.coe_update @[simp] theorem update_self : f.update a (f a) = f := by classical ext simp #align finsupp.update_self Finsupp.update_self @[simp] theorem zero_update : update 0 a b = single a b := by classical ext rw [single_eq_update] rfl #align finsupp.zero_update Finsupp.zero_update theorem support_update [DecidableEq α] [DecidableEq M] : support (f.update a b) = if b = 0 then f.support.erase a else insert a f.support := by classical dsimp [update]; congr <;> apply Subsingleton.elim #align finsupp.support_update Finsupp.support_update @[simp] theorem support_update_zero [DecidableEq α] : support (f.update a 0) = f.support.erase a := by classical simp only [update, ite_true, mem_support_iff, ne_eq, not_not] congr; apply Subsingleton.elim #align finsupp.support_update_zero Finsupp.support_update_zero variable {b} theorem support_update_ne_zero [DecidableEq α] (h : b ≠ 0) : support (f.update a b) = insert a f.support := by classical simp only [update, h, ite_false, mem_support_iff, ne_eq] congr; apply Subsingleton.elim #align finsupp.support_update_ne_zero Finsupp.support_update_ne_zero theorem support_update_subset [DecidableEq α] [DecidableEq M] : support (f.update a b) ⊆ insert a f.support := by rw [support_update] split_ifs · exact (erase_subset _ _).trans (subset_insert _ _) · rfl theorem update_comm (f : α →₀ M) {a₁ a₂ : α} (h : a₁ ≠ a₂) (m₁ m₂ : M) : update (update f a₁ m₁) a₂ m₂ = update (update f a₂ m₂) a₁ m₁ := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_comm h _ _ _ @[simp] theorem update_idem (f : α →₀ M) (a : α) (b c : M) : update (update f a b) a c = update f a c := letI := Classical.decEq α DFunLike.coe_injective <| Function.update_idem _ _ _ end Update /-! ### Declarations about `erase` -/ section Erase variable [Zero M] /-- `erase a f` is the finitely supported function equal to `f` except at `a` where it is equal to `0`. If `a` is not in the support of `f` then `erase a f = f`. -/ def erase (a : α) (f : α →₀ M) : α →₀ M where support := haveI := Classical.decEq α f.support.erase a toFun a' := haveI := Classical.decEq α if a' = a then 0 else f a' mem_support_toFun a' := by classical rw [mem_erase, mem_support_iff]; dsimp split_ifs with h · exact ⟨fun H _ => H.1 h, fun H => (H rfl).elim⟩ · exact and_iff_right h #align finsupp.erase Finsupp.erase @[simp] theorem support_erase [DecidableEq α] {a : α} {f : α →₀ M} : (f.erase a).support = f.support.erase a := by classical dsimp [erase] congr; apply Subsingleton.elim #align finsupp.support_erase Finsupp.support_erase @[simp] theorem erase_same {a : α} {f : α →₀ M} : (f.erase a) a = 0 := by classical simp only [erase, coe_mk, ite_true] #align finsupp.erase_same Finsupp.erase_same @[simp] theorem erase_ne {a a' : α} {f : α →₀ M} (h : a' ≠ a) : (f.erase a) a' = f a' := by classical simp only [erase, coe_mk, h, ite_false] #align finsupp.erase_ne Finsupp.erase_ne theorem erase_apply [DecidableEq α] {a a' : α} {f : α →₀ M} : f.erase a a' = if a' = a then 0 else f a' := by rw [erase, coe_mk] convert rfl @[simp] theorem erase_single {a : α} {b : M} : erase a (single a b) = 0 := by ext s; by_cases hs : s = a · rw [hs, erase_same] rfl · rw [erase_ne hs] exact single_eq_of_ne (Ne.symm hs) #align finsupp.erase_single Finsupp.erase_single theorem erase_single_ne {a a' : α} {b : M} (h : a ≠ a') : erase a (single a' b) = single a' b := by ext s; by_cases hs : s = a · rw [hs, erase_same, single_eq_of_ne h.symm] · rw [erase_ne hs] #align finsupp.erase_single_ne Finsupp.erase_single_ne @[simp] theorem erase_of_not_mem_support {f : α →₀ M} {a} (haf : a ∉ f.support) : erase a f = f := by ext b; by_cases hab : b = a · rwa [hab, erase_same, eq_comm, ← not_mem_support_iff] · rw [erase_ne hab] #align finsupp.erase_of_not_mem_support Finsupp.erase_of_not_mem_support @[simp, nolint simpNF] -- Porting note: simpNF linter claims simp can prove this, it can not
Mathlib/Data/Finsupp/Defs.lean
682
683
theorem erase_zero (a : α) : erase a (0 : α →₀ M) = 0 := by
classical rw [← support_eq_empty, support_erase, support_zero, erase_empty]
/- Copyright (c) 2023 Sophie Morel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sophie Morel -/ import Mathlib.Analysis.Analytic.Basic /-! We specialize the theory fo analytic functions to the case of functions that admit a development given by a *finite* formal multilinear series. We call them "continuously polynomial", which is abbreviated to `CPolynomial`. One reason to do that is that we no longer need a completeness assumption on the target space `F` to make the series converge, so some of the results are more general. The class of continuously polynomial functions includes functions defined by polynomials on a normed `𝕜`-algebra and continuous multilinear maps. ## 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 : ℕ`, and let `f` be a function from `E` to `F`. * `HasFiniteFPowerSeriesOnBall f p x n r`: on the ball of center `x` with radius `r`, `f (x + y) = ∑'_n pₘ yᵐ`, and moreover `pₘ = 0` if `n ≤ m`. * `HasFiniteFPowerSeriesAt f p x n`: on some ball of center `x` with positive radius, holds `HasFiniteFPowerSeriesOnBall f p x n r`. * `CPolynomialAt 𝕜 f x`: there exists a power series `p` and a natural number `n` such that holds `HasFPowerSeriesAt f p x n`. * `CPolynomialOn 𝕜 f s`: the function `f` is analytic at every point of `s`. We develop the basic properties of these notions, notably: * If a function is continuously polynomial, then it is analytic, see `HasFiniteFPowerSeriesOnBall.hasFPowerSeriesOnBall`, `HasFiniteFPowerSeriesAt.hasFPowerSeriesAt`, `CPolynomialAt.analyticAt` and `CPolynomialOn.analyticOn`. * The sum of a finite formal power series with positive radius is well defined on the whole space, see `FormalMultilinearSeries.hasFiniteFPowerSeriesOnBall_of_finite`. * If a function admits a finite power series in a ball, then it is continuously polynomial at any point `y` of this ball, and the power series there can be expressed in terms of the initial power series `p` as `p.changeOrigin y`, which is finite (with the same bound as `p`) by `changeOrigin_finite_of_finite`. See `HasFiniteFPowerSeriesOnBall.changeOrigin `. It follows in particular that the set of points at which a given function is continuously polynomial is open, see `isOpen_cPolynomialAt`. -/ variable {𝕜 E F G : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] [NormedAddCommGroup G] [NormedSpace 𝕜 G] open scoped Classical open Topology NNReal Filter ENNReal open Set Filter Asymptotics variable {f g : E → F} {p pf pg : FormalMultilinearSeries 𝕜 E F} {x : E} {r r' : ℝ≥0∞} {n m : ℕ} section FiniteFPowerSeries /-- Given a function `f : E → F`, a formal multilinear series `p` and `n : ℕ`, we say that `f` has `p` as a finite power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₘ yᵐ` for all `‖y‖ < r` and `pₙ = 0` for `n ≤ m`. -/ structure HasFiniteFPowerSeriesOnBall (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (n : ℕ) (r : ℝ≥0∞) extends HasFPowerSeriesOnBall f p x r : Prop where finite : ∀ (m : ℕ), n ≤ m → p m = 0 theorem HasFiniteFPowerSeriesOnBall.mk' {f : E → F} {p : FormalMultilinearSeries 𝕜 E F} {x : E} {n : ℕ} {r : ℝ≥0∞} (finite : ∀ (m : ℕ), n ≤ m → p m = 0) (pos : 0 < r) (sum_eq : ∀ y ∈ EMetric.ball 0 r, (∑ i ∈ Finset.range n, p i fun _ ↦ y) = f (x + y)) : HasFiniteFPowerSeriesOnBall f p x n r where r_le := p.radius_eq_top_of_eventually_eq_zero (Filter.eventually_atTop.mpr ⟨n, finite⟩) ▸ le_top r_pos := pos hasSum hy := sum_eq _ hy ▸ hasSum_sum_of_ne_finset_zero fun m hm ↦ by rw [Finset.mem_range, not_lt] at hm; rw [finite m hm]; rfl finite := finite /-- Given a function `f : E → F`, a formal multilinear series `p` and `n : ℕ`, we say that `f` has `p` as a finite power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`and `pₙ = 0` for `n ≤ m`. -/ def HasFiniteFPowerSeriesAt (f : E → F) (p : FormalMultilinearSeries 𝕜 E F) (x : E) (n : ℕ) := ∃ r, HasFiniteFPowerSeriesOnBall f p x n r theorem HasFiniteFPowerSeriesAt.toHasFPowerSeriesAt (hf : HasFiniteFPowerSeriesAt f p x n) : HasFPowerSeriesAt f p x := let ⟨r, hf⟩ := hf ⟨r, hf.toHasFPowerSeriesOnBall⟩ theorem HasFiniteFPowerSeriesAt.finite (hf : HasFiniteFPowerSeriesAt f p x n) : ∀ m : ℕ, n ≤ m → p m = 0 := let ⟨_, hf⟩ := hf; hf.finite variable (𝕜) /-- Given a function `f : E → F`, we say that `f` is continuously polynomial (cpolynomial) at `x` if it admits a finite power series expansion around `x`. -/ def CPolynomialAt (f : E → F) (x : E) := ∃ (p : FormalMultilinearSeries 𝕜 E F) (n : ℕ), HasFiniteFPowerSeriesAt f p x n /-- Given a function `f : E → F`, we say that `f` is continuously polynomial on a set `s` if it is continuously polynomial around every point of `s`. -/ def CPolynomialOn (f : E → F) (s : Set E) := ∀ x, x ∈ s → CPolynomialAt 𝕜 f x variable {𝕜} theorem HasFiniteFPowerSeriesOnBall.hasFiniteFPowerSeriesAt (hf : HasFiniteFPowerSeriesOnBall f p x n r) : HasFiniteFPowerSeriesAt f p x n := ⟨r, hf⟩ theorem HasFiniteFPowerSeriesAt.cPolynomialAt (hf : HasFiniteFPowerSeriesAt f p x n) : CPolynomialAt 𝕜 f x := ⟨p, n, hf⟩ theorem HasFiniteFPowerSeriesOnBall.cPolynomialAt (hf : HasFiniteFPowerSeriesOnBall f p x n r) : CPolynomialAt 𝕜 f x := hf.hasFiniteFPowerSeriesAt.cPolynomialAt theorem CPolynomialAt.analyticAt (hf : CPolynomialAt 𝕜 f x) : AnalyticAt 𝕜 f x := let ⟨p, _, hp⟩ := hf ⟨p, hp.toHasFPowerSeriesAt⟩ theorem CPolynomialOn.analyticOn {s : Set E} (hf : CPolynomialOn 𝕜 f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (hf x hx).analyticAt theorem HasFiniteFPowerSeriesOnBall.congr (hf : HasFiniteFPowerSeriesOnBall f p x n r) (hg : EqOn f g (EMetric.ball x r)) : HasFiniteFPowerSeriesOnBall g p x n r := ⟨hf.1.congr hg, hf.finite⟩ /-- If a function `f` has a finite power series `p` around `x`, then the function `z ↦ f (z - y)` has the same finite power series around `x + y`. -/ theorem HasFiniteFPowerSeriesOnBall.comp_sub (hf : HasFiniteFPowerSeriesOnBall f p x n r) (y : E) : HasFiniteFPowerSeriesOnBall (fun z => f (z - y)) p (x + y) n r := ⟨hf.1.comp_sub y, hf.finite⟩ theorem HasFiniteFPowerSeriesOnBall.mono (hf : HasFiniteFPowerSeriesOnBall f p x n r) (r'_pos : 0 < r') (hr : r' ≤ r) : HasFiniteFPowerSeriesOnBall f p x n r' := ⟨hf.1.mono r'_pos hr, hf.finite⟩ theorem HasFiniteFPowerSeriesAt.congr (hf : HasFiniteFPowerSeriesAt f p x n) (hg : f =ᶠ[𝓝 x] g) : HasFiniteFPowerSeriesAt g p x n := Exists.imp (fun _ hg ↦ ⟨hg, hf.finite⟩) (hf.toHasFPowerSeriesAt.congr hg) protected theorem HasFiniteFPowerSeriesAt.eventually (hf : HasFiniteFPowerSeriesAt f p x n) : ∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, HasFiniteFPowerSeriesOnBall f p x n r := hf.toHasFPowerSeriesAt.eventually.mono fun _ h ↦ ⟨h, hf.finite⟩ theorem hasFiniteFPowerSeriesOnBall_const {c : F} {e : E} : HasFiniteFPowerSeriesOnBall (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 ⊤ := ⟨hasFPowerSeriesOnBall_const, fun n hn ↦ constFormalMultilinearSeries_apply (id hn : 0 < n).ne'⟩ theorem hasFiniteFPowerSeriesAt_const {c : F} {e : E} : HasFiniteFPowerSeriesAt (fun _ => c) (constFormalMultilinearSeries 𝕜 E c) e 1 := ⟨⊤, hasFiniteFPowerSeriesOnBall_const⟩ theorem CPolynomialAt_const {v : F} : CPolynomialAt 𝕜 (fun _ => v) x := ⟨constFormalMultilinearSeries 𝕜 E v, 1, hasFiniteFPowerSeriesAt_const⟩ theorem CPolynomialOn_const {v : F} {s : Set E} : CPolynomialOn 𝕜 (fun _ => v) s := fun _ _ => CPolynomialAt_const theorem HasFiniteFPowerSeriesOnBall.add (hf : HasFiniteFPowerSeriesOnBall f pf x n r) (hg : HasFiniteFPowerSeriesOnBall g pg x m r) : HasFiniteFPowerSeriesOnBall (f + g) (pf + pg) x (max n m) r := ⟨hf.1.add hg.1, fun N hN ↦ by rw [Pi.add_apply, hf.finite _ ((le_max_left n m).trans hN), hg.finite _ ((le_max_right n m).trans hN), zero_add]⟩ theorem HasFiniteFPowerSeriesAt.add (hf : HasFiniteFPowerSeriesAt f pf x n) (hg : HasFiniteFPowerSeriesAt g pg x m) : HasFiniteFPowerSeriesAt (f + g) (pf + pg) x (max n m) := by rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩ exact ⟨r, hr.1.add hr.2⟩ theorem CPolynomialAt.congr (hf : CPolynomialAt 𝕜 f x) (hg : f =ᶠ[𝓝 x] g) : CPolynomialAt 𝕜 g x := let ⟨_, _, hpf⟩ := hf (hpf.congr hg).cPolynomialAt theorem CPolynomialAt_congr (h : f =ᶠ[𝓝 x] g) : CPolynomialAt 𝕜 f x ↔ CPolynomialAt 𝕜 g x := ⟨fun hf ↦ hf.congr h, fun hg ↦ hg.congr h.symm⟩ theorem CPolynomialAt.add (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) : CPolynomialAt 𝕜 (f + g) x := let ⟨_, _, hpf⟩ := hf let ⟨_, _, hqf⟩ := hg (hpf.add hqf).cPolynomialAt theorem HasFiniteFPowerSeriesOnBall.neg (hf : HasFiniteFPowerSeriesOnBall f pf x n r) : HasFiniteFPowerSeriesOnBall (-f) (-pf) x n r := ⟨hf.1.neg, fun m hm ↦ by rw [Pi.neg_apply, hf.finite m hm, neg_zero]⟩ theorem HasFiniteFPowerSeriesAt.neg (hf : HasFiniteFPowerSeriesAt f pf x n) : HasFiniteFPowerSeriesAt (-f) (-pf) x n := let ⟨_, hrf⟩ := hf hrf.neg.hasFiniteFPowerSeriesAt theorem CPolynomialAt.neg (hf : CPolynomialAt 𝕜 f x) : CPolynomialAt 𝕜 (-f) x := let ⟨_, _, hpf⟩ := hf hpf.neg.cPolynomialAt theorem HasFiniteFPowerSeriesOnBall.sub (hf : HasFiniteFPowerSeriesOnBall f pf x n r) (hg : HasFiniteFPowerSeriesOnBall g pg x m r) : HasFiniteFPowerSeriesOnBall (f - g) (pf - pg) x (max n m) r := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem HasFiniteFPowerSeriesAt.sub (hf : HasFiniteFPowerSeriesAt f pf x n) (hg : HasFiniteFPowerSeriesAt g pg x m) : HasFiniteFPowerSeriesAt (f - g) (pf - pg) x (max n m) := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem CPolynomialAt.sub (hf : CPolynomialAt 𝕜 f x) (hg : CPolynomialAt 𝕜 g x) : CPolynomialAt 𝕜 (f - g) x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem CPolynomialOn.mono {s t : Set E} (hf : CPolynomialOn 𝕜 f t) (hst : s ⊆ t) : CPolynomialOn 𝕜 f s := fun z hz => hf z (hst hz) theorem CPolynomialOn.congr' {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : f =ᶠ[𝓝ˢ s] g) : CPolynomialOn 𝕜 g s := fun z hz => (hf z hz).congr (mem_nhdsSet_iff_forall.mp hg z hz) theorem CPolynomialOn_congr' {s : Set E} (h : f =ᶠ[𝓝ˢ s] g) : CPolynomialOn 𝕜 f s ↔ CPolynomialOn 𝕜 g s := ⟨fun hf => hf.congr' h, fun hg => hg.congr' h.symm⟩ theorem CPolynomialOn.congr {s : Set E} (hs : IsOpen s) (hf : CPolynomialOn 𝕜 f s) (hg : s.EqOn f g) : CPolynomialOn 𝕜 g s := hf.congr' <| mem_nhdsSet_iff_forall.mpr (fun _ hz => eventuallyEq_iff_exists_mem.mpr ⟨s, hs.mem_nhds hz, hg⟩) theorem CPolynomialOn_congr {s : Set E} (hs : IsOpen s) (h : s.EqOn f g) : CPolynomialOn 𝕜 f s ↔ CPolynomialOn 𝕜 g s := ⟨fun hf => hf.congr hs h, fun hg => hg.congr hs h.symm⟩ theorem CPolynomialOn.add {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) : CPolynomialOn 𝕜 (f + g) s := fun z hz => (hf z hz).add (hg z hz) theorem CPolynomialOn.sub {s : Set E} (hf : CPolynomialOn 𝕜 f s) (hg : CPolynomialOn 𝕜 g s) : CPolynomialOn 𝕜 (f - g) s := fun z hz => (hf z hz).sub (hg z hz) /-- If a function `f` has a finite power series `p` on a ball and `g` is a continuous linear map, then `g ∘ f` has the finite power series `g ∘ p` on the same ball. -/ theorem ContinuousLinearMap.comp_hasFiniteFPowerSeriesOnBall (g : F →L[𝕜] G) (h : HasFiniteFPowerSeriesOnBall f p x n r) : HasFiniteFPowerSeriesOnBall (g ∘ f) (g.compFormalMultilinearSeries p) x n r := ⟨g.comp_hasFPowerSeriesOnBall h.1, fun m hm ↦ by rw [compFormalMultilinearSeries_apply, h.finite m hm] ext; exact map_zero g⟩ /-- If a function `f` is continuously polynomial on a set `s` and `g` is a continuous linear map, then `g ∘ f` is continuously polynomial on `s`. -/ theorem ContinuousLinearMap.comp_cPolynomialOn {s : Set E} (g : F →L[𝕜] G) (h : CPolynomialOn 𝕜 f s) : CPolynomialOn 𝕜 (g ∘ f) s := by rintro x hx rcases h x hx with ⟨p, n, r, hp⟩ exact ⟨g.compFormalMultilinearSeries p, n, r, g.comp_hasFiniteFPowerSeriesOnBall hp⟩ /-- If a function admits a finite power series expansion bounded by `n`, then it is equal to the `m`th partial sums of this power series at every point of the disk for `n ≤ m`. -/ theorem HasFiniteFPowerSeriesOnBall.eq_partialSum (hf : HasFiniteFPowerSeriesOnBall f p x n r) : ∀ y ∈ EMetric.ball (0 : E) r, ∀ m, n ≤ m → f (x + y) = p.partialSum m y := fun y hy m hm ↦ (hf.hasSum hy).unique (hasSum_sum_of_ne_finset_zero (f := fun m => p m (fun _ => y)) (s := Finset.range m) (fun N hN => by simp only; simp only [Finset.mem_range, not_lt] at hN rw [hf.finite _ (le_trans hm hN), ContinuousMultilinearMap.zero_apply])) /-- Variant of the previous result with the variable expressed as `y` instead of `x + y`. -/ theorem HasFiniteFPowerSeriesOnBall.eq_partialSum' (hf : HasFiniteFPowerSeriesOnBall f p x n r) : ∀ y ∈ EMetric.ball x r, ∀ m, n ≤ m → f y = p.partialSum m (y - x) := by intro y hy m hm rw [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, ← mem_emetric_ball_zero_iff] at hy rw [← (HasFiniteFPowerSeriesOnBall.eq_partialSum hf _ hy m hm), add_sub_cancel] /-! The particular cases where `f` has a finite power series bounded by `0` or `1`. -/ /-- If `f` has a formal power series on a ball bounded by `0`, then `f` is equal to `0` on the ball. -/ theorem HasFiniteFPowerSeriesOnBall.eq_zero_of_bound_zero (hf : HasFiniteFPowerSeriesOnBall f pf x 0 r) : ∀ y ∈ EMetric.ball x r, f y = 0 := by intro y hy rw [hf.eq_partialSum' y hy 0 le_rfl, FormalMultilinearSeries.partialSum] simp only [Finset.range_zero, Finset.sum_empty] theorem HasFiniteFPowerSeriesOnBall.bound_zero_of_eq_zero (hf : ∀ y ∈ EMetric.ball x r, f y = 0) (r_pos : 0 < r) (hp : ∀ n, p n = 0) : HasFiniteFPowerSeriesOnBall f p x 0 r := by refine ⟨⟨?_, r_pos, ?_⟩, fun n _ ↦ hp n⟩ · rw [p.radius_eq_top_of_forall_image_add_eq_zero 0 (fun n ↦ by rw [add_zero]; exact hp n)] exact le_top · intro y hy rw [hf (x + y)] · convert hasSum_zero rw [hp, ContinuousMultilinearMap.zero_apply] · rwa [EMetric.mem_ball, edist_eq_coe_nnnorm_sub, add_comm, add_sub_cancel_right, ← edist_eq_coe_nnnorm, ← EMetric.mem_ball] /-- If `f` has a formal power series at `x` bounded by `0`, then `f` is equal to `0` in a neighborhood of `x`. -/ theorem HasFiniteFPowerSeriesAt.eventually_zero_of_bound_zero (hf : HasFiniteFPowerSeriesAt f pf x 0) : f =ᶠ[𝓝 x] 0 := Filter.eventuallyEq_iff_exists_mem.mpr (let ⟨r, hf⟩ := hf; ⟨EMetric.ball x r, EMetric.ball_mem_nhds x hf.r_pos, fun y hy ↦ hf.eq_zero_of_bound_zero y hy⟩) /-- If `f` has a formal power series on a ball bounded by `1`, then `f` is constant equal to `f x` on the ball. -/ theorem HasFiniteFPowerSeriesOnBall.eq_const_of_bound_one (hf : HasFiniteFPowerSeriesOnBall f pf x 1 r) : ∀ y ∈ EMetric.ball x r, f y = f x := by intro y hy rw [hf.eq_partialSum' y hy 1 le_rfl, hf.eq_partialSum' x (by rw [EMetric.mem_ball, edist_self]; exact hf.r_pos) 1 le_rfl] simp only [FormalMultilinearSeries.partialSum, Finset.range_one, Finset.sum_singleton] congr apply funext simp only [IsEmpty.forall_iff] /-- If `f` has a formal power series at x bounded by `1`, then `f` is constant equal to `f x` in a neighborhood of `x`. -/ theorem HasFiniteFPowerSeriesAt.eventually_const_of_bound_one (hf : HasFiniteFPowerSeriesAt f pf x 1) : f =ᶠ[𝓝 x] (fun _ => f x) := Filter.eventuallyEq_iff_exists_mem.mpr (let ⟨r, hf⟩ := hf; ⟨EMetric.ball x r, EMetric.ball_mem_nhds x hf.r_pos, fun y hy ↦ hf.eq_const_of_bound_one y hy⟩) /-- If a function admits a finite power series expansion on a disk, then it is continuous there. -/ protected theorem HasFiniteFPowerSeriesOnBall.continuousOn (hf : HasFiniteFPowerSeriesOnBall f p x n r) : ContinuousOn f (EMetric.ball x r) := hf.1.continuousOn protected theorem HasFiniteFPowerSeriesAt.continuousAt (hf : HasFiniteFPowerSeriesAt f p x n) : ContinuousAt f x := hf.toHasFPowerSeriesAt.continuousAt protected theorem CPolynomialAt.continuousAt (hf : CPolynomialAt 𝕜 f x) : ContinuousAt f x := hf.analyticAt.continuousAt protected theorem CPolynomialOn.continuousOn {s : Set E} (hf : CPolynomialOn 𝕜 f s) : ContinuousOn f s := hf.analyticOn.continuousOn /-- Continuously polynomial everywhere implies continuous -/ theorem CPolynomialOn.continuous {f : E → F} (fa : CPolynomialOn 𝕜 f univ) : Continuous f := by rw [continuous_iff_continuousOn_univ]; exact fa.continuousOn protected theorem FormalMultilinearSeries.sum_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ m, n ≤ m → p m = 0) (x : E) : p.sum x = p.partialSum n x := tsum_eq_sum fun m hm ↦ by rw [Finset.mem_range, not_lt] at hm; rw [hn m hm]; rfl /-- A finite formal multilinear series sums to its sum at every point. -/ protected theorem FormalMultilinearSeries.hasSum_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ m, n ≤ m → p m = 0) (x : E) : HasSum (fun n : ℕ => p n fun _ => x) (p.sum x) := summable_of_ne_finset_zero (fun m hm ↦ by rw [Finset.mem_range, not_lt] at hm; rw [hn m hm]; rfl) |>.hasSum /-- The sum of a finite power series `p` admits `p` as a power series. -/ protected theorem FormalMultilinearSeries.hasFiniteFPowerSeriesOnBall_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ m, n ≤ m → p m = 0) : HasFiniteFPowerSeriesOnBall p.sum p 0 n ⊤ where r_le := by rw [radius_eq_top_of_forall_image_add_eq_zero p n fun _ => hn _ (Nat.le_add_left _ _)] r_pos := zero_lt_top finite := hn hasSum {y} _ := by rw [zero_add]; exact p.hasSum_of_finite hn y theorem HasFiniteFPowerSeriesOnBall.sum (h : HasFiniteFPowerSeriesOnBall f p x n r) {y : E} (hy : y ∈ EMetric.ball (0 : E) r) : f (x + y) = p.sum y := (h.hasSum hy).tsum_eq.symm /-- The sum of a finite power series is continuous. -/ protected theorem FormalMultilinearSeries.continuousOn_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ m, n ≤ m → p m = 0) : Continuous p.sum := by rw [continuous_iff_continuousOn_univ, ← Metric.emetric_ball_top] exact (p.hasFiniteFPowerSeriesOnBall_of_finite hn).continuousOn end FiniteFPowerSeries namespace FormalMultilinearSeries section /-! We study what happens when we change the origin of a finite formal multilinear series `p`. The main point is that the new series `p.changeOrigin x` is still finite, with the same bound. -/ variable (p : FormalMultilinearSeries 𝕜 E F) {x y : E} {r R : ℝ≥0} /-- If `p` is a formal multilinear series such that `p m = 0` for `n ≤ m`, then `p.changeOriginSeriesTerm k l = 0` for `n ≤ k + l`. -/ lemma changeOriginSeriesTerm_bound (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) (k l : ℕ) {s : Finset (Fin (k + l))} (hs : s.card = l) (hkl : n ≤ k + l) : p.changeOriginSeriesTerm k l s hs = 0 := by #adaptation_note /-- `set_option maxSynthPendingDepth 2` required after https://github.com/leanprover/lean4/pull/4119 -/ set_option maxSynthPendingDepth 2 in rw [changeOriginSeriesTerm, hn _ hkl, map_zero] /-- If `p` is a finite formal multilinear series, then so is `p.changeOriginSeries k` for every `k` in `ℕ`. More precisely, if `p m = 0` for `n ≤ m`, then `p.changeOriginSeries k m = 0` for `n ≤ k + m`. -/ lemma changeOriginSeries_finite_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) (k : ℕ) : ∀ {m : ℕ}, n ≤ k + m → p.changeOriginSeries k m = 0 := by intro m hm rw [changeOriginSeries] exact Finset.sum_eq_zero (fun _ _ => p.changeOriginSeriesTerm_bound hn _ _ _ hm) lemma changeOriginSeries_sum_eq_partialSum_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) (k : ℕ) : (p.changeOriginSeries k).sum = (p.changeOriginSeries k).partialSum (n - k) := by ext x rw [partialSum, FormalMultilinearSeries.sum, tsum_eq_sum (f := fun m => p.changeOriginSeries k m (fun _ => x)) (s := Finset.range (n - k))] intro m hm rw [Finset.mem_range, not_lt] at hm rw [p.changeOriginSeries_finite_of_finite hn k (by rw [add_comm]; exact Nat.le_add_of_sub_le hm), ContinuousMultilinearMap.zero_apply] /-- If `p` is a formal multilinear series such that `p m = 0` for `n ≤ m`, then `p.changeOrigin x k = 0` for `n ≤ k`. -/ lemma changeOrigin_finite_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) {k : ℕ} (hk : n ≤ k) : p.changeOrigin x k = 0 := by rw [changeOrigin, p.changeOriginSeries_sum_eq_partialSum_of_finite hn] apply Finset.sum_eq_zero intro m hm rw [Finset.mem_range] at hm rw [p.changeOriginSeries_finite_of_finite hn k (le_add_of_le_left hk), ContinuousMultilinearMap.zero_apply] theorem hasFiniteFPowerSeriesOnBall_changeOrigin (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (k : ℕ) (hn : ∀ (m : ℕ), n + k ≤ m → p m = 0) : HasFiniteFPowerSeriesOnBall (p.changeOrigin · k) (p.changeOriginSeries k) 0 n ⊤ := (p.changeOriginSeries k).hasFiniteFPowerSeriesOnBall_of_finite (fun _ hm => p.changeOriginSeries_finite_of_finite hn k (by rw [add_comm n k]; apply add_le_add_left hm)) theorem changeOrigin_eval_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) (x y : E) : (p.changeOrigin x).sum y = p.sum (x + y) := by let f (s : Σ k l : ℕ, { s : Finset (Fin (k + l)) // s.card = l }) : F := p.changeOriginSeriesTerm s.1 s.2.1 s.2.2 s.2.2.2 (fun _ ↦ x) fun _ ↦ y have finsupp : f.support.Finite := by apply Set.Finite.subset (s := changeOriginIndexEquiv ⁻¹' (Sigma.fst ⁻¹' {m | m < n})) · apply Set.Finite.preimage (Equiv.injective _).injOn simp_rw [← {m | m < n}.iUnion_of_singleton_coe, preimage_iUnion, ← range_sigmaMk] exact finite_iUnion fun _ ↦ finite_range _ · refine fun s ↦ Not.imp_symm fun hs ↦ ?_ simp only [preimage_setOf_eq, changeOriginIndexEquiv_apply_fst, mem_setOf, not_lt] at hs dsimp only [f] rw [changeOriginSeriesTerm_bound p hn _ _ _ hs, ContinuousMultilinearMap.zero_apply, ContinuousMultilinearMap.zero_apply] have hfkl k l : HasSum (f ⟨k, l, ·⟩) (changeOriginSeries p k l (fun _ ↦ x) fun _ ↦ y) := by simp_rw [changeOriginSeries, ContinuousMultilinearMap.sum_apply]; apply hasSum_fintype have hfk k : HasSum (f ⟨k, ·⟩) (changeOrigin p x k fun _ ↦ y) := by have (m) (hm : m ∉ Finset.range n) : changeOriginSeries p k m (fun _ ↦ x) = 0 := by rw [Finset.mem_range, not_lt] at hm rw [changeOriginSeries_finite_of_finite _ hn _ (le_add_of_le_right hm), ContinuousMultilinearMap.zero_apply] rw [changeOrigin, FormalMultilinearSeries.sum, ContinuousMultilinearMap.tsum_eval (summable_of_ne_finset_zero this)] refine (summable_of_ne_finset_zero (s := Finset.range n) fun m hm ↦ ?_).hasSum.sigma_of_hasSum (hfkl k) (summable_of_finite_support <| finsupp.preimage sigma_mk_injective.injOn) rw [this m hm, ContinuousMultilinearMap.zero_apply] have hf : HasSum f ((p.changeOrigin x).sum y) := ((p.changeOrigin x).hasSum_of_finite (fun _ ↦ changeOrigin_finite_of_finite p hn) _) |>.sigma_of_hasSum hfk (summable_of_finite_support finsupp) refine hf.unique (changeOriginIndexEquiv.symm.hasSum_iff.1 ?_) refine (p.hasSum_of_finite hn (x + y)).sigma_of_hasSum (fun n ↦ ?_) (changeOriginIndexEquiv.symm.summable_iff.2 hf.summable) rw [← Pi.add_def, (p n).map_add_univ (fun _ ↦ x) fun _ ↦ y] simp_rw [← changeOriginSeriesTerm_changeOriginIndexEquiv_symm] exact hasSum_fintype fun c ↦ f (changeOriginIndexEquiv.symm ⟨n, c⟩) /-- The terms of the formal multilinear series `p.changeOrigin` are continuously polynomial as we vary the origin -/ theorem cPolynomialAt_changeOrigin_of_finite (p : FormalMultilinearSeries 𝕜 E F) {n : ℕ} (hn : ∀ (m : ℕ), n ≤ m → p m = 0) (k : ℕ) : CPolynomialAt 𝕜 (p.changeOrigin · k) 0 := (p.hasFiniteFPowerSeriesOnBall_changeOrigin k fun _ h ↦ hn _ (le_self_add.trans h)).cPolynomialAt end end FormalMultilinearSeries section variable {x y : E}
Mathlib/Analysis/Analytic/CPolynomial.lean
487
501
theorem HasFiniteFPowerSeriesOnBall.changeOrigin (hf : HasFiniteFPowerSeriesOnBall f p x n r) (h : (‖y‖₊ : ℝ≥0∞) < r) : HasFiniteFPowerSeriesOnBall f (p.changeOrigin y) (x + y) n (r - ‖y‖₊) where r_le := (tsub_le_tsub_right hf.r_le _).trans p.changeOrigin_radius r_pos := by
simp [h] finite _ hm := p.changeOrigin_finite_of_finite hf.finite hm hasSum {z} hz := by have : f (x + y + z) = FormalMultilinearSeries.sum (FormalMultilinearSeries.changeOrigin p y) z := by rw [mem_emetric_ball_zero_iff, lt_tsub_iff_right, add_comm] at hz rw [p.changeOrigin_eval_of_finite hf.finite, add_assoc, hf.sum] refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt ?_ hz) exact mod_cast nnnorm_add_le y z rw [this] apply (p.changeOrigin y).hasSum_of_finite fun _ => p.changeOrigin_finite_of_finite hf.finite
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Basic #align_import category_theory.limits.preserves.shapes.binary_products from "leanprover-community/mathlib"@"024a4231815538ac739f52d08dd20a55da0d6b23" /-! # Preserving binary products Constructions to relate the notions of preserving binary products and reflecting binary products to concrete binary fans. In particular, we show that `ProdComparison G X Y` is an isomorphism iff `G` preserves the product of `X` and `Y`. -/ noncomputable section universe v₁ v₂ u₁ u₂ open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {C : Type u₁} [Category.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] variable (G : C ⥤ D) namespace CategoryTheory.Limits section variable {P X Y Z : C} (f : P ⟶ X) (g : P ⟶ Y) /-- The map of a binary fan is a limit iff the fork consisting of the mapped morphisms is a limit. This essentially lets us commute `BinaryFan.mk` with `Functor.mapCone`. -/ def isLimitMapConeBinaryFanEquiv : IsLimit (G.mapCone (BinaryFan.mk f g)) ≃ IsLimit (BinaryFan.mk (G.map f) (G.map g)) := (IsLimit.postcomposeHomEquiv (diagramIsoPair _) _).symm.trans (IsLimit.equivIsoLimit (Cones.ext (Iso.refl _) (by rintro (_ | _) <;> simp))) #align category_theory.limits.is_limit_map_cone_binary_fan_equiv CategoryTheory.Limits.isLimitMapConeBinaryFanEquiv /-- The property of preserving products expressed in terms of binary fans. -/ def mapIsLimitOfPreservesOfIsLimit [PreservesLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk f g)) : IsLimit (BinaryFan.mk (G.map f) (G.map g)) := isLimitMapConeBinaryFanEquiv G f g (PreservesLimit.preserves l) #align category_theory.limits.map_is_limit_of_preserves_of_is_limit CategoryTheory.Limits.mapIsLimitOfPreservesOfIsLimit /-- The property of reflecting products expressed in terms of binary fans. -/ def isLimitOfReflectsOfMapIsLimit [ReflectsLimit (pair X Y) G] (l : IsLimit (BinaryFan.mk (G.map f) (G.map g))) : IsLimit (BinaryFan.mk f g) := ReflectsLimit.reflects ((isLimitMapConeBinaryFanEquiv G f g).symm l) #align category_theory.limits.is_limit_of_reflects_of_map_is_limit CategoryTheory.Limits.isLimitOfReflectsOfMapIsLimit variable (X Y) [HasBinaryProduct X Y] /-- If `G` preserves binary products and `C` has them, then the binary fan constructed of the mapped morphisms of the binary product cone is a limit. -/ def isLimitOfHasBinaryProductOfPreservesLimit [PreservesLimit (pair X Y) G] : IsLimit (BinaryFan.mk (G.map (Limits.prod.fst : X ⨯ Y ⟶ X)) (G.map Limits.prod.snd)) := mapIsLimitOfPreservesOfIsLimit G _ _ (prodIsProd X Y) #align category_theory.limits.is_limit_of_has_binary_product_of_preserves_limit CategoryTheory.Limits.isLimitOfHasBinaryProductOfPreservesLimit variable [HasBinaryProduct (G.obj X) (G.obj Y)] /-- If the product comparison map for `G` at `(X,Y)` is an isomorphism, then `G` preserves the pair of `(X,Y)`. -/ def PreservesLimitPair.ofIsoProdComparison [i : IsIso (prodComparison G X Y)] : PreservesLimit (pair X Y) G := by apply preservesLimitOfPreservesLimitCone (prodIsProd X Y) apply (isLimitMapConeBinaryFanEquiv _ _ _).symm _ refine @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (pair (G.obj X) (G.obj Y))) ?_ apply i #align category_theory.limits.preserves_limit_pair.of_iso_prod_comparison CategoryTheory.Limits.PreservesLimitPair.ofIsoProdComparison variable [PreservesLimit (pair X Y) G] /-- If `G` preserves the product of `(X,Y)`, then the product comparison map for `G` at `(X,Y)` is an isomorphism. -/ def PreservesLimitPair.iso : G.obj (X ⨯ Y) ≅ G.obj X ⨯ G.obj Y := IsLimit.conePointUniqueUpToIso (isLimitOfHasBinaryProductOfPreservesLimit G X Y) (limit.isLimit _) #align category_theory.limits.preserves_limit_pair.iso CategoryTheory.Limits.PreservesLimitPair.iso @[simp] theorem PreservesLimitPair.iso_hom : (PreservesLimitPair.iso G X Y).hom = prodComparison G X Y := rfl #align category_theory.limits.preserves_limit_pair.iso_hom CategoryTheory.Limits.PreservesLimitPair.iso_hom @[simp]
Mathlib/CategoryTheory/Limits/Preserves/Shapes/BinaryProducts.lean
100
103
theorem PreservesLimitPair.iso_inv_fst : (PreservesLimitPair.iso G X Y).inv ≫ G.map prod.fst = prod.fst := by
rw [← Iso.cancel_iso_hom_left (PreservesLimitPair.iso G X Y), ← Category.assoc, Iso.hom_inv_id] simp
/- 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.Projection import Mathlib.Analysis.NormedSpace.lpSpace import Mathlib.Analysis.InnerProductSpace.PiL2 #align_import analysis.inner_product_space.l2_space from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Hilbert sum of a family of inner product spaces Given a family `(G : ι → Type*) [Π i, InnerProductSpace 𝕜 (G i)]` of inner product spaces, this file equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those dependent functions `f : Π i, G i` for which `∑' i, ‖f i‖ ^ 2`, the sum of the norms-squared, is summable. This construction is sometimes called the *Hilbert sum* of the family `G`. By choosing `G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction. We also define a *predicate* `IsHilbertSum 𝕜 G V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that `V` is an `OrthogonalFamily` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective. ## Main definitions * `OrthogonalFamily.linearIsometry`: Given a Hilbert space `E`, a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G` into `E`. * `IsHilbertSum`: Given a Hilbert space `E`, a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`, `IsHilbertSum 𝕜 G V` means that `V` is an `OrthogonalFamily` and that the above linear isometry is surjective. * `IsHilbertSum.linearIsometryEquiv`: If a Hilbert space `E` is a Hilbert sum of the inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the corresponding `OrthogonalFamily.linearIsometry` can be upgraded to a `LinearIsometryEquiv`. * `HilbertBasis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single field `HilbertBasis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert sum of `ι` copies of `𝕜`). This parallels the definition of `Basis`, in `LinearAlgebra.Basis`, as an isomorphism of an `R`-module with `ι →₀ R`. * `HilbertBasis.instCoeFun`: More conventionally a Hilbert basis is thought of as a family `ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness). We obtain this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image under `b.repr` of `lp.single 2 i (1:𝕜)`. This parallels the definition `Basis.coeFun` in `LinearAlgebra.Basis`. * `HilbertBasis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors in `E` whose span is dense. This parallels the definition `Basis.mk` in `LinearAlgebra.Basis`. * `HilbertBasis.mkOfOrthogonalEqBot`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors in `E` whose span has trivial orthogonal complement. ## Main results * `lp.instInnerProductSpace`: Construction of the inner product space instance on the Hilbert sum `lp G 2`. Note that from the file `Analysis.NormedSpace.lpSpace`, the space `lp G 2` already held a normed space instance (`lp.normedSpace`), and if each `G i` is a Hilbert space (i.e., complete), then `lp G 2` was already known to be complete (`lp.completeSpace`). So the work here is to define the inner product and show it is compatible. * `OrthogonalFamily.range_linearIsometry`: Given a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal images, the image of the embedding `OrthogonalFamily.linearIsometry` of the Hilbert sum of `G` into `E` is the closure of the span of the images of the `G i`. * `HilbertBasis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`. * `HilbertBasis.hasSum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be expressed as the "infinite linear combination" `∑' i, b.repr x i • b i` of the basis vectors `b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`. * `exists_hilbertBasis`: A Hilbert space admits a Hilbert basis. ## Keywords Hilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism -/ open RCLike Submodule Filter open scoped NNReal ENNReal Classical ComplexConjugate Topology noncomputable section variable {ι 𝕜 : Type*} [RCLike 𝕜] {E : Type*} variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [cplt : CompleteSpace E] variable {G : ι → Type*} [∀ i, NormedAddCommGroup (G i)] [∀ i, InnerProductSpace 𝕜 (G i)] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- `ℓ²(ι, 𝕜)` is the Hilbert space of square-summable functions `ι → 𝕜`, herein implemented as `lp (fun i : ι => 𝕜) 2`. -/ notation "ℓ²(" ι ", " 𝕜 ")" => lp (fun i : ι => 𝕜) 2 /-! ### Inner product space structure on `lp G 2` -/ namespace lp theorem summable_inner (f g : lp G 2) : Summable fun i => ⟪f i, g i⟫ := by -- Apply the Direct Comparison Test, comparing with ∑' i, ‖f i‖ * ‖g i‖ (summable by Hölder) refine .of_norm_bounded (fun i => ‖f i‖ * ‖g i‖) (lp.summable_mul ?_ f g) ?_ · rw [Real.isConjExponent_iff]; norm_num intro i -- Then apply Cauchy-Schwarz pointwise exact norm_inner_le_norm (𝕜 := 𝕜) _ _ #align lp.summable_inner lp.summable_inner instance instInnerProductSpace : InnerProductSpace 𝕜 (lp G 2) := { lp.normedAddCommGroup (E := G) (p := 2) with inner := fun f g => ∑' i, ⟪f i, g i⟫ norm_sq_eq_inner := fun f => by calc ‖f‖ ^ 2 = ‖f‖ ^ (2 : ℝ≥0∞).toReal := by norm_cast _ = ∑' i, ‖f i‖ ^ (2 : ℝ≥0∞).toReal := lp.norm_rpow_eq_tsum ?_ f _ = ∑' i, ‖f i‖ ^ (2 : ℕ) := by norm_cast _ = ∑' i, re ⟪f i, f i⟫ := by congr funext i rw [norm_sq_eq_inner (𝕜 := 𝕜)] -- Porting note: `simp` couldn't do this anymore _ = re (∑' i, ⟪f i, f i⟫) := (RCLike.reCLM.map_tsum ?_).symm · norm_num · exact summable_inner f f conj_symm := fun f g => by calc conj _ = conj (∑' i, ⟪g i, f i⟫) := by congr _ = ∑' i, conj ⟪g i, f i⟫ := RCLike.conjCLE.map_tsum _ = ∑' i, ⟪f i, g i⟫ := by simp only [inner_conj_symm] _ = _ := by congr add_left := fun f₁ f₂ g => by calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ := ?_ _ = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) := by simp only [inner_add_left, Pi.add_apply, coeFn_add] _ = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ := tsum_add ?_ ?_ _ = _ := by congr · congr · exact summable_inner f₁ g · exact summable_inner f₂ g smul_left := fun f g c => by calc _ = ∑' i, ⟪c • f i, g i⟫ := ?_ _ = ∑' i, conj c * ⟪f i, g i⟫ := by simp only [inner_smul_left] _ = conj c * ∑' i, ⟪f i, g i⟫ := tsum_mul_left _ = _ := ?_ · simp only [coeFn_smul, Pi.smul_apply] · congr } theorem inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl #align lp.inner_eq_tsum lp.inner_eq_tsum theorem hasSum_inner (f g : lp G 2) : HasSum (fun i => ⟪f i, g i⟫) ⟪f, g⟫ := (summable_inner f g).hasSum #align lp.has_sum_inner lp.hasSum_inner theorem inner_single_left (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ := by refine (hasSum_inner (lp.single 2 i a) f).unique ?_ convert hasSum_ite_eq i ⟪a, f i⟫ using 1 ext j rw [lp.single_apply] split_ifs with h · subst h; rfl · simp #align lp.inner_single_left lp.inner_single_left theorem inner_single_right (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ := by simpa [inner_conj_symm] using congr_arg conj (@inner_single_left _ 𝕜 _ _ _ _ i a f) #align lp.inner_single_right lp.inner_single_right end lp /-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/ namespace OrthogonalFamily variable {V : ∀ i, G i →ₗᵢ[𝕜] E} (hV : OrthogonalFamily 𝕜 G V) protected theorem summable_of_lp (f : lp G 2) : Summable fun i => V i (f i) := by rw [hV.summable_iff_norm_sq_summable] convert (lp.memℓp f).summable _ · norm_cast · norm_num #align orthogonal_family.summable_of_lp OrthogonalFamily.summable_of_lp /-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the subspaces into `E`. -/ protected def linearIsometry : lp G 2 →ₗᵢ[𝕜] E where toFun f := ∑' i, V i (f i) map_add' f g := by simp only [tsum_add (hV.summable_of_lp f) (hV.summable_of_lp g), lp.coeFn_add, Pi.add_apply, LinearIsometry.map_add] map_smul' c f := by simpa only [LinearIsometry.map_smul, Pi.smul_apply, lp.coeFn_smul] using tsum_const_smul c (hV.summable_of_lp f) norm_map' f := by classical -- needed for lattice instance on `Finset ι`, for `Filter.atTop_neBot` have H : 0 < (2 : ℝ≥0∞).toReal := by norm_num suffices ‖∑' i : ι, V i (f i)‖ ^ (2 : ℝ≥0∞).toReal = ‖f‖ ^ (2 : ℝ≥0∞).toReal by exact Real.rpow_left_injOn H.ne' (norm_nonneg _) (norm_nonneg _) this refine tendsto_nhds_unique ?_ (lp.hasSum_norm H f) convert (hV.summable_of_lp f).hasSum.norm.rpow_const (Or.inr H.le) using 1 ext s exact mod_cast (hV.norm_sum f s).symm #align orthogonal_family.linear_isometry OrthogonalFamily.linearIsometry protected theorem linearIsometry_apply (f : lp G 2) : hV.linearIsometry f = ∑' i, V i (f i) := rfl #align orthogonal_family.linear_isometry_apply OrthogonalFamily.linearIsometry_apply protected theorem hasSum_linearIsometry (f : lp G 2) : HasSum (fun i => V i (f i)) (hV.linearIsometry f) := (hV.summable_of_lp f).hasSum #align orthogonal_family.has_sum_linear_isometry OrthogonalFamily.hasSum_linearIsometry @[simp] protected theorem linearIsometry_apply_single {i : ι} (x : G i) : hV.linearIsometry (lp.single 2 i x) = V i x := by rw [hV.linearIsometry_apply, ← tsum_ite_eq i (V i x)] congr ext j rw [lp.single_apply] split_ifs with h · subst h; simp · simp [h] #align orthogonal_family.linear_isometry_apply_single OrthogonalFamily.linearIsometry_apply_single protected theorem linearIsometry_apply_dfinsupp_sum_single (W₀ : Π₀ i : ι, G i) : hV.linearIsometry (W₀.sum (lp.single 2)) = W₀.sum fun i => V i := by simp #align orthogonal_family.linear_isometry_apply_dfinsupp_sum_single OrthogonalFamily.linearIsometry_apply_dfinsupp_sum_single /-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of `E` into E, has range the closure of the span of the subspaces. -/ protected theorem range_linearIsometry [∀ i, CompleteSpace (G i)] : LinearMap.range hV.linearIsometry.toLinearMap = (⨆ i, LinearMap.range (V i).toLinearMap).topologicalClosure := by -- Porting note: dot notation broken refine le_antisymm ?_ ?_ · rintro x ⟨f, rfl⟩ refine mem_closure_of_tendsto (hV.hasSum_linearIsometry f) (eventually_of_forall ?_) intro s rw [SetLike.mem_coe] refine sum_mem ?_ intro i _ refine mem_iSup_of_mem i ?_ exact LinearMap.mem_range_self _ (f i) · apply topologicalClosure_minimal · refine iSup_le ?_ rintro i x ⟨x, rfl⟩ use lp.single 2 i x exact hV.linearIsometry_apply_single x exact hV.linearIsometry.isometry.uniformInducing.isComplete_range.isClosed #align orthogonal_family.range_linear_isometry OrthogonalFamily.range_linearIsometry end OrthogonalFamily section IsHilbertSum variable (𝕜 G) variable (V : ∀ i, G i →ₗᵢ[𝕜] E) (F : ι → Submodule 𝕜 E) /-- Given a family of Hilbert spaces `G : ι → Type*`, a Hilbert sum of `G` consists of a Hilbert space `E` and an orthogonal family `V : Π i, G i →ₗᵢ[𝕜] E` such that the induced isometry `Φ : lp G 2 → E` is surjective. Keeping in mind that `lp G 2` is "the" external Hilbert sum of `G : ι → Type*`, this is analogous to `DirectSum.IsInternal`, except that we don't express it in terms of actual submodules. -/ structure IsHilbertSum : Prop where ofSurjective :: /-- The orthogonal family constituting the summands in the Hilbert sum. -/ protected OrthogonalFamily : OrthogonalFamily 𝕜 G V /-- The isometry `lp G 2 → E` induced by the orthogonal family is surjective. -/ protected surjective_isometry : Function.Surjective OrthogonalFamily.linearIsometry #align is_hilbert_sum IsHilbertSum variable {𝕜 G V} /-- If `V : Π i, G i →ₗᵢ[𝕜] E` is an orthogonal family such that the supremum of the ranges of `V i` is dense, then `(E, V)` is a Hilbert sum of `G`. -/
Mathlib/Analysis/InnerProductSpace/l2Space.lean
290
297
theorem IsHilbertSum.mk [∀ i, CompleteSpace <| G i] (hVortho : OrthogonalFamily 𝕜 G V) (hVtotal : ⊤ ≤ (⨆ i, LinearMap.range (V i).toLinearMap).topologicalClosure) : IsHilbertSum 𝕜 G V := { OrthogonalFamily := hVortho surjective_isometry := by
rw [← LinearIsometry.coe_toLinearMap] exact LinearMap.range_eq_top.mp (eq_top_iff.mpr <| hVtotal.trans_eq hVortho.range_linearIsometry.symm) }
/- Copyright (c) 2022 Antoine Labelle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle -/ import Mathlib.Algebra.Group.Equiv.TypeTags import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.Algebra.MonoidAlgebra.Basic import Mathlib.LinearAlgebra.Dual import Mathlib.LinearAlgebra.Contraction import Mathlib.RingTheory.TensorProduct.Basic #align_import representation_theory.basic from "leanprover-community/mathlib"@"c04bc6e93e23aa0182aba53661a2211e80b6feac" /-! # Monoid representations This file introduces monoid representations and their characters and defines a few ways to construct representations. ## Main definitions * Representation.Representation * Representation.character * Representation.tprod * Representation.linHom * Representation.dual ## Implementation notes Representations of a monoid `G` on a `k`-module `V` are implemented as homomorphisms `G →* (V →ₗ[k] V)`. We use the abbreviation `Representation` for this hom space. The theorem `asAlgebraHom_def` constructs a module over the group `k`-algebra of `G` (implemented as `MonoidAlgebra k G`) corresponding to a representation. If `ρ : Representation k G V`, this module can be accessed via `ρ.asModule`. Conversely, given a `MonoidAlgebra k G-module `M` `M.ofModule` is the associociated representation seen as a homomorphism. -/ open MonoidAlgebra (lift of) open LinearMap section variable (k G V : Type*) [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- A representation of `G` on the `k`-module `V` is a homomorphism `G →* (V →ₗ[k] V)`. -/ abbrev Representation := G →* V →ₗ[k] V #align representation Representation end namespace Representation section trivial variable (k : Type*) {G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] /-- The trivial representation of `G` on a `k`-module V. -/ def trivial : Representation k G V := 1 #align representation.trivial Representation.trivial -- Porting note: why is `V` implicit theorem trivial_def (g : G) (v : V) : trivial k (V := V) g v = v := rfl #align representation.trivial_def Representation.trivial_def variable {k} /-- A predicate for representations that fix every element. -/ class IsTrivial (ρ : Representation k G V) : Prop where out : ∀ g x, ρ g x = x := by aesop instance : IsTrivial (trivial k (G := G) (V := V)) where @[simp] theorem apply_eq_self (ρ : Representation k G V) (g : G) (x : V) [h : IsTrivial ρ] : ρ g x = x := h.out g x end trivial section MonoidAlgebra variable {k G V : Type*} [CommSemiring k] [Monoid G] [AddCommMonoid V] [Module k V] variable (ρ : Representation k G V) /-- A `k`-linear representation of `G` on `V` can be thought of as an algebra map from `MonoidAlgebra k G` into the `k`-linear endomorphisms of `V`. -/ noncomputable def asAlgebraHom : MonoidAlgebra k G →ₐ[k] Module.End k V := (lift k G _) ρ #align representation.as_algebra_hom Representation.asAlgebraHom theorem asAlgebraHom_def : asAlgebraHom ρ = (lift k G _) ρ := rfl #align representation.as_algebra_hom_def Representation.asAlgebraHom_def @[simp] theorem asAlgebraHom_single (g : G) (r : k) : asAlgebraHom ρ (Finsupp.single g r) = r • ρ g := by simp only [asAlgebraHom_def, MonoidAlgebra.lift_single] #align representation.as_algebra_hom_single Representation.asAlgebraHom_single theorem asAlgebraHom_single_one (g : G) : asAlgebraHom ρ (Finsupp.single g 1) = ρ g := by simp #align representation.as_algebra_hom_single_one Representation.asAlgebraHom_single_one theorem asAlgebraHom_of (g : G) : asAlgebraHom ρ (of k G g) = ρ g := by simp only [MonoidAlgebra.of_apply, asAlgebraHom_single, one_smul] #align representation.as_algebra_hom_of Representation.asAlgebraHom_of /-- If `ρ : Representation k G V`, then `ρ.asModule` is a type synonym for `V`, which we equip with an instance `Module (MonoidAlgebra k G) ρ.asModule`. You should use `asModuleEquiv : ρ.asModule ≃+ V` to translate terms. -/ @[nolint unusedArguments] def asModule (_ : Representation k G V) := V #align representation.as_module Representation.asModule -- Porting note: no derive handler instance : AddCommMonoid (ρ.asModule) := inferInstanceAs <| AddCommMonoid V instance : Inhabited ρ.asModule where default := 0 /-- A `k`-linear representation of `G` on `V` can be thought of as a module over `MonoidAlgebra k G`. -/ noncomputable instance asModuleModule : Module (MonoidAlgebra k G) ρ.asModule := Module.compHom V (asAlgebraHom ρ).toRingHom #align representation.as_module_module Representation.asModuleModule -- Porting note: ρ.asModule doesn't unfold now instance : Module k ρ.asModule := inferInstanceAs <| Module k V /-- The additive equivalence from the `Module (MonoidAlgebra k G)` to the original vector space of the representative. This is just the identity, but it is helpful for typechecking and keeping track of instances. -/ def asModuleEquiv : ρ.asModule ≃+ V := AddEquiv.refl _ #align representation.as_module_equiv Representation.asModuleEquiv @[simp] theorem asModuleEquiv_map_smul (r : MonoidAlgebra k G) (x : ρ.asModule) : ρ.asModuleEquiv (r • x) = ρ.asAlgebraHom r (ρ.asModuleEquiv x) := rfl #align representation.as_module_equiv_map_smul Representation.asModuleEquiv_map_smul @[simp] theorem asModuleEquiv_symm_map_smul (r : k) (x : V) : ρ.asModuleEquiv.symm (r • x) = algebraMap k (MonoidAlgebra k G) r • ρ.asModuleEquiv.symm x := by apply_fun ρ.asModuleEquiv simp #align representation.as_module_equiv_symm_map_smul Representation.asModuleEquiv_symm_map_smul @[simp] theorem asModuleEquiv_symm_map_rho (g : G) (x : V) : ρ.asModuleEquiv.symm (ρ g x) = MonoidAlgebra.of k G g • ρ.asModuleEquiv.symm x := by apply_fun ρ.asModuleEquiv simp #align representation.as_module_equiv_symm_map_rho Representation.asModuleEquiv_symm_map_rho /-- Build a `Representation k G M` from a `[Module (MonoidAlgebra k G) M]`. This version is not always what we want, as it relies on an existing `[Module k M]` instance, along with a `[IsScalarTower k (MonoidAlgebra k G) M]` instance. We remedy this below in `ofModule` (with the tradeoff that the representation is defined only on a type synonym of the original module.) -/ noncomputable def ofModule' (M : Type*) [AddCommMonoid M] [Module k M] [Module (MonoidAlgebra k G) M] [IsScalarTower k (MonoidAlgebra k G) M] : Representation k G M := (MonoidAlgebra.lift k G (M →ₗ[k] M)).symm (Algebra.lsmul k k M) #align representation.of_module' Representation.ofModule' section variable (M : Type*) [AddCommMonoid M] [Module (MonoidAlgebra k G) M] /-- Build a `Representation` from a `[Module (MonoidAlgebra k G) M]`. Note that the representation is built on `restrictScalars k (MonoidAlgebra k G) M`, rather than on `M` itself. -/ noncomputable def ofModule : Representation k G (RestrictScalars k (MonoidAlgebra k G) M) := (MonoidAlgebra.lift k G (RestrictScalars k (MonoidAlgebra k G) M →ₗ[k] RestrictScalars k (MonoidAlgebra k G) M)).symm (RestrictScalars.lsmul k (MonoidAlgebra k G) M) #align representation.of_module Representation.ofModule /-! ## `ofModule` and `asModule` are inverses. This requires a little care in both directions: this is a categorical equivalence, not an isomorphism. See `Rep.equivalenceModuleMonoidAlgebra` for the full statement. Starting with `ρ : Representation k G V`, converting to a module and back again we have a `Representation k G (restrictScalars k (MonoidAlgebra k G) ρ.asModule)`. To compare these, we use the composition of `restrictScalarsAddEquiv` and `ρ.asModuleEquiv`. Similarly, starting with `Module (MonoidAlgebra k G) M`, after we convert to a representation and back to a module, we have `Module (MonoidAlgebra k G) (restrictScalars k (MonoidAlgebra k G) M)`. -/ @[simp]
Mathlib/RepresentationTheory/Basic.lean
221
234
theorem ofModule_asAlgebraHom_apply_apply (r : MonoidAlgebra k G) (m : RestrictScalars k (MonoidAlgebra k G) M) : ((ofModule M).asAlgebraHom r) m = (RestrictScalars.addEquiv _ _ _).symm (r • RestrictScalars.addEquiv _ _ _ m) := by
apply MonoidAlgebra.induction_on r · intro g simp only [one_smul, MonoidAlgebra.lift_symm_apply, MonoidAlgebra.of_apply, Representation.asAlgebraHom_single, Representation.ofModule, AddEquiv.apply_eq_iff_eq, RestrictScalars.lsmul_apply_apply] · intro f g fw gw simp only [fw, gw, map_add, add_smul, LinearMap.add_apply] · intro r f w simp only [w, AlgHom.map_smul, LinearMap.smul_apply, RestrictScalars.addEquiv_symm_map_smul_smul]
/- Copyright (c) 2020 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Halting import Mathlib.Computability.TuringMachine import Mathlib.Data.Num.Lemmas import Mathlib.Tactic.DeriveFintype #align_import computability.tm_to_partrec from "leanprover-community/mathlib"@"6155d4351090a6fad236e3d2e4e0e4e7342668e8" /-! # Modelling partial recursive functions using Turing machines This file defines a simplified basis for partial recursive functions, and a `Turing.TM2` model Turing machine for evaluating these functions. This amounts to a constructive proof that every `Partrec` function can be evaluated by a Turing machine. ## Main definitions * `ToPartrec.Code`: a simplified basis for partial recursive functions, valued in `List ℕ →. List ℕ`. * `ToPartrec.Code.eval`: semantics for a `ToPartrec.Code` program * `PartrecToTM2.tr`: A TM2 turing machine which can evaluate `code` programs -/ open Function (update) open Relation namespace Turing /-! ## A simplified basis for partrec This section constructs the type `Code`, which is a data type of programs with `List ℕ` input and output, with enough expressivity to write any partial recursive function. The primitives are: * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) This basis is convenient because it is closer to the Turing machine model - the key operations are splitting and merging of lists of unknown length, while the messy `n`-ary composition operation from the traditional basis for partial recursive functions is absent - but it retains a compositional semantics. The first step in transitioning to Turing machines is to make a sequential evaluator for this basis, which we take up in the next section. -/ namespace ToPartrec /-- The type of codes for primitive recursive functions. Unlike `Nat.Partrec.Code`, this uses a set of operations on `List ℕ`. See `Code.eval` for a description of the behavior of the primitives. -/ inductive Code | zero' | succ | tail | cons : Code → Code → Code | comp : Code → Code → Code | case : Code → Code → Code | fix : Code → Code deriving DecidableEq, Inhabited #align turing.to_partrec.code Turing.ToPartrec.Code #align turing.to_partrec.code.zero' Turing.ToPartrec.Code.zero' #align turing.to_partrec.code.succ Turing.ToPartrec.Code.succ #align turing.to_partrec.code.tail Turing.ToPartrec.Code.tail #align turing.to_partrec.code.cons Turing.ToPartrec.Code.cons #align turing.to_partrec.code.comp Turing.ToPartrec.Code.comp #align turing.to_partrec.code.case Turing.ToPartrec.Code.case #align turing.to_partrec.code.fix Turing.ToPartrec.Code.fix /-- The semantics of the `Code` primitives, as partial functions `List ℕ →. List ℕ`. By convention we functions that return a single result return a singleton `[n]`, or in some cases `n :: v` where `v` will be ignored by a subsequent function. * `zero'` appends a `0` to the input. That is, `zero' v = 0 :: v`. * `succ` returns the successor of the head of the input, defaulting to zero if there is no head: * `succ [] = [1]` * `succ (n :: v) = [n + 1]` * `tail` returns the tail of the input * `tail [] = []` * `tail (n :: v) = v` * `cons f fs` calls `f` and `fs` on the input and conses the results: * `cons f fs v = (f v).head :: fs v` * `comp f g` calls `f` on the output of `g`: * `comp f g v = f (g v)` * `case f g` cases on the head of the input, calling `f` or `g` depending on whether it is zero or a successor (similar to `Nat.casesOn`). * `case f g [] = f []` * `case f g (0 :: v) = f v` * `case f g (n+1 :: v) = g (n :: v)` * `fix f` calls `f` repeatedly, using the head of the result of `f` to decide whether to call `f` again or finish: * `fix f v = []` if `f v = []` * `fix f v = w` if `f v = 0 :: w` * `fix f v = fix f w` if `f v = n+1 :: w` (the exact value of `n` is discarded) -/ def Code.eval : Code → List ℕ →. List ℕ | Code.zero' => fun v => pure (0 :: v) | Code.succ => fun v => pure [v.headI.succ] | Code.tail => fun v => pure v.tail | Code.cons f fs => fun v => do let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) | Code.comp f g => fun v => g.eval v >>= f.eval | Code.case f g => fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) | Code.fix f => PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail #align turing.to_partrec.code.eval Turing.ToPartrec.Code.eval namespace Code /- Porting note: The equation lemma of `eval` is too strong; it simplifies terms like the LHS of `pred_eval`. Even `eqns` can't fix this. We removed `simp` attr from `eval` and prepare new simp lemmas for `eval`. -/ @[simp] theorem zero'_eval : zero'.eval = fun v => pure (0 :: v) := by simp [eval] @[simp] theorem succ_eval : succ.eval = fun v => pure [v.headI.succ] := by simp [eval] @[simp] theorem tail_eval : tail.eval = fun v => pure v.tail := by simp [eval] @[simp] theorem cons_eval (f fs) : (cons f fs).eval = fun v => do { let n ← Code.eval f v let ns ← Code.eval fs v pure (n.headI :: ns) } := by simp [eval] @[simp] theorem comp_eval (f g) : (comp f g).eval = fun v => g.eval v >>= f.eval := by simp [eval] @[simp] theorem case_eval (f g) : (case f g).eval = fun v => v.headI.rec (f.eval v.tail) fun y _ => g.eval (y::v.tail) := by simp [eval] @[simp] theorem fix_eval (f) : (fix f).eval = PFun.fix fun v => (f.eval v).map fun v => if v.headI = 0 then Sum.inl v.tail else Sum.inr v.tail := by simp [eval] /-- `nil` is the constant nil function: `nil v = []`. -/ def nil : Code := tail.comp succ #align turing.to_partrec.code.nil Turing.ToPartrec.Code.nil @[simp] theorem nil_eval (v) : nil.eval v = pure [] := by simp [nil] #align turing.to_partrec.code.nil_eval Turing.ToPartrec.Code.nil_eval /-- `id` is the identity function: `id v = v`. -/ def id : Code := tail.comp zero' #align turing.to_partrec.code.id Turing.ToPartrec.Code.id @[simp] theorem id_eval (v) : id.eval v = pure v := by simp [id] #align turing.to_partrec.code.id_eval Turing.ToPartrec.Code.id_eval /-- `head` gets the head of the input list: `head [] = [0]`, `head (n :: v) = [n]`. -/ def head : Code := cons id nil #align turing.to_partrec.code.head Turing.ToPartrec.Code.head @[simp] theorem head_eval (v) : head.eval v = pure [v.headI] := by simp [head] #align turing.to_partrec.code.head_eval Turing.ToPartrec.Code.head_eval /-- `zero` is the constant zero function: `zero v = [0]`. -/ def zero : Code := cons zero' nil #align turing.to_partrec.code.zero Turing.ToPartrec.Code.zero @[simp] theorem zero_eval (v) : zero.eval v = pure [0] := by simp [zero] #align turing.to_partrec.code.zero_eval Turing.ToPartrec.Code.zero_eval /-- `pred` returns the predecessor of the head of the input: `pred [] = [0]`, `pred (0 :: v) = [0]`, `pred (n+1 :: v) = [n]`. -/ def pred : Code := case zero head #align turing.to_partrec.code.pred Turing.ToPartrec.Code.pred @[simp] theorem pred_eval (v) : pred.eval v = pure [v.headI.pred] := by simp [pred]; cases v.headI <;> simp #align turing.to_partrec.code.pred_eval Turing.ToPartrec.Code.pred_eval /-- `rfind f` performs the function of the `rfind` primitive of partial recursive functions. `rfind f v` returns the smallest `n` such that `(f (n :: v)).head = 0`. It is implemented as: rfind f v = pred (fix (fun (n::v) => f (n::v) :: n+1 :: v) (0 :: v)) The idea is that the initial state is `0 :: v`, and the `fix` keeps `n :: v` as its internal state; it calls `f (n :: v)` as the exit test and `n+1 :: v` as the next state. At the end we get `n+1 :: v` where `n` is the desired output, and `pred (n+1 :: v) = [n]` returns the result. -/ def rfind (f : Code) : Code := comp pred <| comp (fix <| cons f <| cons succ tail) zero' #align turing.to_partrec.code.rfind Turing.ToPartrec.Code.rfind /-- `prec f g` implements the `prec` (primitive recursion) operation of partial recursive functions. `prec f g` evaluates as: * `prec f g [] = [f []]` * `prec f g (0 :: v) = [f v]` * `prec f g (n+1 :: v) = [g (n :: prec f g (n :: v) :: v)]` It is implemented as: G (a :: b :: IH :: v) = (b :: a+1 :: b-1 :: g (a :: IH :: v) :: v) F (0 :: f_v :: v) = (f_v :: v) F (n+1 :: f_v :: v) = (fix G (0 :: n :: f_v :: v)).tail.tail prec f g (a :: v) = [(F (a :: f v :: v)).head] Because `fix` always evaluates its body at least once, we must special case the `0` case to avoid calling `g` more times than necessary (which could be bad if `g` diverges). If the input is `0 :: v`, then `F (0 :: f v :: v) = (f v :: v)` so we return `[f v]`. If the input is `n+1 :: v`, we evaluate the function from the bottom up, with initial state `0 :: n :: f v :: v`. The first number counts up, providing arguments for the applications to `g`, while the second number counts down, providing the exit condition (this is the initial `b` in the return value of `G`, which is stripped by `fix`). After the `fix` is complete, the final state is `n :: 0 :: res :: v` where `res` is the desired result, and the rest reduces this to `[res]`. -/ def prec (f g : Code) : Code := let G := cons tail <| cons succ <| cons (comp pred tail) <| cons (comp g <| cons id <| comp tail tail) <| comp tail <| comp tail tail let F := case id <| comp (comp (comp tail tail) (fix G)) zero' cons (comp F (cons head <| cons (comp f tail) tail)) nil #align turing.to_partrec.code.prec Turing.ToPartrec.Code.prec attribute [-simp] Part.bind_eq_bind Part.map_eq_map Part.pure_eq_some theorem exists_code.comp {m n} {f : Vector ℕ n →. ℕ} {g : Fin n → Vector ℕ m →. ℕ} (hf : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v) (hg : ∀ i, ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> g i v) : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = pure <$> ((Vector.mOfFn fun i => g i v) >>= f) := by rsuffices ⟨cg, hg⟩ : ∃ c : Code, ∀ v : Vector ℕ m, c.eval v.1 = Subtype.val <$> Vector.mOfFn fun i => g i v · obtain ⟨cf, hf⟩ := hf exact ⟨cf.comp cg, fun v => by simp [hg, hf, map_bind, seq_bind_eq, Function.comp] rfl⟩ clear hf f; induction' n with n IH · exact ⟨nil, fun v => by simp [Vector.mOfFn, Bind.bind]; rfl⟩ · obtain ⟨cg, hg₁⟩ := hg 0 obtain ⟨cl, hl⟩ := IH fun i => hg i.succ exact ⟨cons cg cl, fun v => by simp [Vector.mOfFn, hg₁, map_bind, seq_bind_eq, bind_assoc, (· ∘ ·), hl] rfl⟩ #align turing.to_partrec.code.exists_code.comp Turing.ToPartrec.Code.exists_code.comp theorem exists_code {n} {f : Vector ℕ n →. ℕ} (hf : Nat.Partrec' f) : ∃ c : Code, ∀ v : Vector ℕ n, c.eval v.1 = pure <$> f v := by induction hf with | prim hf => induction hf with | zero => exact ⟨zero', fun ⟨[], _⟩ => rfl⟩ | succ => exact ⟨succ, fun ⟨[v], _⟩ => rfl⟩ | get i => refine Fin.succRec (fun n => ?_) (fun n i IH => ?_) i · exact ⟨head, fun ⟨List.cons a as, _⟩ => by simp [Bind.bind]; rfl⟩ · obtain ⟨c, h⟩ := IH exact ⟨c.comp tail, fun v => by simpa [← Vector.get_tail, Bind.bind] using h v.tail⟩ | comp g hf hg IHf IHg => simpa [Part.bind_eq_bind] using exists_code.comp IHf IHg | @prec n f g _ _ IHf IHg => obtain ⟨cf, hf⟩ := IHf obtain ⟨cg, hg⟩ := IHg simp only [Part.map_eq_map, Part.map_some, PFun.coe_val] at hf hg refine ⟨prec cf cg, fun v => ?_⟩ rw [← v.cons_head_tail] specialize hf v.tail replace hg := fun a b => hg (a ::ᵥ b ::ᵥ v.tail) simp only [Vector.cons_val, Vector.tail_val] at hf hg simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, Vector.tail_cons, Vector.head_cons, PFun.coe_val, Vector.tail_val] simp only [← Part.pure_eq_some] at hf hg ⊢ induction' v.head with n _ <;> simp [prec, hf, Part.bind_assoc, ← Part.bind_some_eq_map, Part.bind_some, show ∀ x, pure x = [x] from fun _ => rfl, Bind.bind, Functor.map] suffices ∀ a b, a + b = n → (n.succ :: 0 :: g (n ::ᵥ Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) n ::ᵥ v.tail) :: v.val.tail : List ℕ) ∈ PFun.fix (fun v : List ℕ => Part.bind (cg.eval (v.headI :: v.tail.tail)) (fun x => Part.some (if v.tail.headI = 0 then Sum.inl (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail : List ℕ) else Sum.inr (v.headI.succ :: v.tail.headI.pred :: x.headI :: v.tail.tail.tail)))) (a :: b :: Nat.rec (f v.tail) (fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)) a :: v.val.tail) by erw [Part.eq_some_iff.2 (this 0 n (zero_add n))] simp only [List.headI, Part.bind_some, List.tail_cons] intro a b e induction' b with b IH generalizing a · refine PFun.mem_fix_iff.2 (Or.inl <| Part.eq_some_iff.1 ?_) simp only [hg, ← e, Part.bind_some, List.tail_cons, pure] rfl · refine PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, IH (a + 1) (by rwa [add_right_comm])⟩) simp only [hg, eval, Part.bind_some, Nat.rec_add_one, List.tail_nil, List.tail_cons, pure] exact Part.mem_some_iff.2 rfl | comp g _ _ IHf IHg => exact exists_code.comp IHf IHg | @rfind n f _ IHf => obtain ⟨cf, hf⟩ := IHf; refine ⟨rfind cf, fun v => ?_⟩ replace hf := fun a => hf (a ::ᵥ v) simp only [Part.map_eq_map, Part.map_some, Vector.cons_val, PFun.coe_val, show ∀ x, pure x = [x] from fun _ => rfl] at hf ⊢ refine Part.ext fun x => ?_ simp only [rfind, Part.bind_eq_bind, Part.pure_eq_some, Part.map_eq_map, Part.bind_some, exists_prop, cons_eval, comp_eval, fix_eval, tail_eval, succ_eval, zero'_eval, List.headI_nil, List.headI_cons, pred_eval, Part.map_some, false_eq_decide_iff, Part.mem_bind_iff, List.length, Part.mem_map_iff, Nat.mem_rfind, List.tail_nil, List.tail_cons, true_eq_decide_iff, Part.mem_some_iff, Part.map_bind] constructor · rintro ⟨v', h1, rfl⟩ suffices ∀ v₁ : List ℕ, v' ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) v₁ → ∀ n, (v₁ = n :: v.val) → (∀ m < n, ¬f (m ::ᵥ v) = 0) → ∃ a : ℕ, (f (a ::ᵥ v) = 0 ∧ ∀ {m : ℕ}, m < a → ¬f (m ::ᵥ v) = 0) ∧ [a] = [v'.headI.pred] by exact this _ h1 0 rfl (by rintro _ ⟨⟩) clear h1 intro v₀ h1 refine PFun.fixInduction h1 fun v₁ h2 IH => ?_ clear h1 rintro n rfl hm have := PFun.mem_fix_iff.1 h2 simp only [hf, Part.bind_some] at this split_ifs at this with h · simp only [List.headI_nil, List.headI_cons, exists_false, or_false_iff, Part.mem_some_iff, List.tail_cons, false_and_iff, Sum.inl.injEq] at this subst this exact ⟨_, ⟨h, @(hm)⟩, rfl⟩ · refine IH (n.succ::v.val) (by simp_all) _ rfl fun m h' => ?_ obtain h | rfl := Nat.lt_succ_iff_lt_or_eq.1 h' exacts [hm _ h, h] · rintro ⟨n, ⟨hn, hm⟩, rfl⟩ refine ⟨n.succ::v.1, ?_, rfl⟩ have : (n.succ::v.1 : List ℕ) ∈ PFun.fix (fun v => (cf.eval v).bind fun y => Part.some <| if y.headI = 0 then Sum.inl (v.headI.succ :: v.tail) else Sum.inr (v.headI.succ :: v.tail)) (n::v.val) := PFun.mem_fix_iff.2 (Or.inl (by simp [hf, hn])) generalize (n.succ :: v.1 : List ℕ) = w at this ⊢ clear hn induction' n with n IH · exact this refine IH (fun {m} h' => hm (Nat.lt_succ_of_lt h')) (PFun.mem_fix_iff.2 (Or.inr ⟨_, ?_, this⟩)) simp only [hf, hm n.lt_succ_self, Part.bind_some, List.headI, eq_self_iff_true, if_false, Part.mem_some_iff, and_self_iff, List.tail_cons] #align turing.to_partrec.code.exists_code Turing.ToPartrec.Code.exists_code end Code /-! ## From compositional semantics to sequential semantics Our initial sequential model is designed to be as similar as possible to the compositional semantics in terms of its primitives, but it is a sequential semantics, meaning that rather than defining an `eval c : List ℕ →. List ℕ` function for each program, defined by recursion on programs, we have a type `Cfg` with a step function `step : Cfg → Option cfg` that provides a deterministic evaluation order. In order to do this, we introduce the notion of a *continuation*, which can be viewed as a `Code` with a hole in it where evaluation is currently taking place. Continuations can be assigned a `List ℕ →. List ℕ` semantics as well, with the interpretation being that given a `List ℕ` result returned from the code in the hole, the remainder of the program will evaluate to a `List ℕ` final value. The continuations are: * `halt`: the empty continuation: the hole is the whole program, whatever is returned is the final result. In our notation this is just `_`. * `cons₁ fs v k`: evaluating the first part of a `cons`, that is `k (_ :: fs v)`, where `k` is the outer continuation. * `cons₂ ns k`: evaluating the second part of a `cons`: `k (ns.headI :: _)`. (Technically we don't need to hold on to all of `ns` here since we are already committed to taking the head, but this is more regular.) * `comp f k`: evaluating the first part of a composition: `k (f _)`. * `fix f k`: waiting for the result of `f` in a `fix f` expression: `k (if _.headI = 0 then _.tail else fix f (_.tail))` The type `Cfg` of evaluation states is: * `ret k v`: we have received a result, and are now evaluating the continuation `k` with result `v`; that is, `k v` where `k` is ready to evaluate. * `halt v`: we are done and the result is `v`. The main theorem of this section is that for each code `c`, the state `stepNormal c halt v` steps to `v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ /-- The type of continuations, built up during evaluation of a `Code` expression. -/ inductive Cont | halt | cons₁ : Code → List ℕ → Cont → Cont | cons₂ : List ℕ → Cont → Cont | comp : Code → Cont → Cont | fix : Code → Cont → Cont deriving Inhabited #align turing.to_partrec.cont Turing.ToPartrec.Cont #align turing.to_partrec.cont.halt Turing.ToPartrec.Cont.halt #align turing.to_partrec.cont.cons₁ Turing.ToPartrec.Cont.cons₁ #align turing.to_partrec.cont.cons₂ Turing.ToPartrec.Cont.cons₂ #align turing.to_partrec.cont.comp Turing.ToPartrec.Cont.comp #align turing.to_partrec.cont.fix Turing.ToPartrec.Cont.fix /-- The semantics of a continuation. -/ def Cont.eval : Cont → List ℕ →. List ℕ | Cont.halt => pure | Cont.cons₁ fs as k => fun v => do let ns ← Code.eval fs as Cont.eval k (v.headI :: ns) | Cont.cons₂ ns k => fun v => Cont.eval k (ns.headI :: v) | Cont.comp f k => fun v => Code.eval f v >>= Cont.eval k | Cont.fix f k => fun v => if v.headI = 0 then k.eval v.tail else f.fix.eval v.tail >>= k.eval #align turing.to_partrec.cont.eval Turing.ToPartrec.Cont.eval /-- The set of configurations of the machine: * `halt v`: The machine is about to stop and `v : List ℕ` is the result. * `ret k v`: The machine is about to pass `v : List ℕ` to continuation `k : cont`. We don't have a state corresponding to normal evaluation because these are evaluated immediately to a `ret` "in zero steps" using the `stepNormal` function. -/ inductive Cfg | halt : List ℕ → Cfg | ret : Cont → List ℕ → Cfg deriving Inhabited #align turing.to_partrec.cfg Turing.ToPartrec.Cfg #align turing.to_partrec.cfg.halt Turing.ToPartrec.Cfg.halt #align turing.to_partrec.cfg.ret Turing.ToPartrec.Cfg.ret /-- Evaluating `c : Code` in a continuation `k : Cont` and input `v : List ℕ`. This goes by recursion on `c`, building an augmented continuation and a value to pass to it. * `zero' v = 0 :: v` evaluates immediately, so we return it to the parent continuation * `succ v = [v.headI.succ]` evaluates immediately, so we return it to the parent continuation * `tail v = v.tail` evaluates immediately, so we return it to the parent continuation * `cons f fs v = (f v).headI :: fs v` requires two sub-evaluations, so we evaluate `f v` in the continuation `k (_.headI :: fs v)` (called `Cont.cons₁ fs v k`) * `comp f g v = f (g v)` requires two sub-evaluations, so we evaluate `g v` in the continuation `k (f _)` (called `Cont.comp f k`) * `case f g v = v.head.casesOn (f v.tail) (fun n => g (n :: v.tail))` has the information needed to evaluate the case statement, so we do that and transition to either `f v` or `g (n :: v.tail)`. * `fix f v = let v' := f v; if v'.headI = 0 then k v'.tail else fix f v'.tail` needs to first evaluate `f v`, so we do that and leave the rest for the continuation (called `Cont.fix f k`) -/ def stepNormal : Code → Cont → List ℕ → Cfg | Code.zero' => fun k v => Cfg.ret k (0::v) | Code.succ => fun k v => Cfg.ret k [v.headI.succ] | Code.tail => fun k v => Cfg.ret k v.tail | Code.cons f fs => fun k v => stepNormal f (Cont.cons₁ fs v k) v | Code.comp f g => fun k v => stepNormal g (Cont.comp f k) v | Code.case f g => fun k v => v.headI.rec (stepNormal f k v.tail) fun y _ => stepNormal g k (y::v.tail) | Code.fix f => fun k v => stepNormal f (Cont.fix f k) v #align turing.to_partrec.step_normal Turing.ToPartrec.stepNormal /-- Evaluating a continuation `k : Cont` on input `v : List ℕ`. This is the second part of evaluation, when we receive results from continuations built by `stepNormal`. * `Cont.halt v = v`, so we are done and transition to the `Cfg.halt v` state * `Cont.cons₁ fs as k v = k (v.headI :: fs as)`, so we evaluate `fs as` now with the continuation `k (v.headI :: _)` (called `cons₂ v k`). * `Cont.cons₂ ns k v = k (ns.headI :: v)`, where we now have everything we need to evaluate `ns.headI :: v`, so we return it to `k`. * `Cont.comp f k v = k (f v)`, so we call `f v` with `k` as the continuation. * `Cont.fix f k v = k (if v.headI = 0 then k v.tail else fix f v.tail)`, where `v` is a value, so we evaluate the if statement and either call `k` with `v.tail`, or call `fix f v` with `k` as the continuation (which immediately calls `f` with `Cont.fix f k` as the continuation). -/ def stepRet : Cont → List ℕ → Cfg | Cont.halt, v => Cfg.halt v | Cont.cons₁ fs as k, v => stepNormal fs (Cont.cons₂ v k) as | Cont.cons₂ ns k, v => stepRet k (ns.headI :: v) | Cont.comp f k, v => stepNormal f k v | Cont.fix f k, v => if v.headI = 0 then stepRet k v.tail else stepNormal f (Cont.fix f k) v.tail #align turing.to_partrec.step_ret Turing.ToPartrec.stepRet /-- If we are not done (in `Cfg.halt` state), then we must be still stuck on a continuation, so this main loop calls `stepRet` with the new continuation. The overall `step` function transitions from one `Cfg` to another, only halting at the `Cfg.halt` state. -/ def step : Cfg → Option Cfg | Cfg.halt _ => none | Cfg.ret k v => some (stepRet k v) #align turing.to_partrec.step Turing.ToPartrec.step /-- In order to extract a compositional semantics from the sequential execution behavior of configurations, we observe that continuations have a monoid structure, with `Cont.halt` as the unit and `Cont.then` as the multiplication. `Cont.then k₁ k₂` runs `k₁` until it halts, and then takes the result of `k₁` and passes it to `k₂`. We will not prove it is associative (although it is), but we are instead interested in the associativity law `k₂ (eval c k₁) = eval c (k₁.then k₂)`. This holds at both the sequential and compositional levels, and allows us to express running a machine without the ambient continuation and relate it to the original machine's evaluation steps. In the literature this is usually where one uses Turing machines embedded inside other Turing machines, but this approach allows us to avoid changing the ambient type `Cfg` in the middle of the recursion. -/ def Cont.then : Cont → Cont → Cont | Cont.halt => fun k' => k' | Cont.cons₁ fs as k => fun k' => Cont.cons₁ fs as (k.then k') | Cont.cons₂ ns k => fun k' => Cont.cons₂ ns (k.then k') | Cont.comp f k => fun k' => Cont.comp f (k.then k') | Cont.fix f k => fun k' => Cont.fix f (k.then k') #align turing.to_partrec.cont.then Turing.ToPartrec.Cont.then theorem Cont.then_eval {k k' : Cont} {v} : (k.then k').eval v = k.eval v >>= k'.eval := by induction' k with _ _ _ _ _ _ _ _ _ k_ih _ _ k_ih generalizing v <;> simp only [Cont.eval, Cont.then, bind_assoc, pure_bind, *] · simp only [← k_ih] · split_ifs <;> [rfl; simp only [← k_ih, bind_assoc]] #align turing.to_partrec.cont.then_eval Turing.ToPartrec.Cont.then_eval /-- The `then k` function is a "configuration homomorphism". Its operation on states is to append `k` to the continuation of a `Cfg.ret` state, and to run `k` on `v` if we are in the `Cfg.halt v` state. -/ def Cfg.then : Cfg → Cont → Cfg | Cfg.halt v => fun k' => stepRet k' v | Cfg.ret k v => fun k' => Cfg.ret (k.then k') v #align turing.to_partrec.cfg.then Turing.ToPartrec.Cfg.then /-- The `stepNormal` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepNormal_then (c) (k k' : Cont) (v) : stepNormal c (k.then k') v = (stepNormal c k v).then k' := by induction c generalizing k v with simp only [Cont.then, stepNormal, *] | cons c c' ih _ => rw [← ih, Cont.then] | comp c c' _ ih' => rw [← ih', Cont.then] | case => cases v.headI <;> simp only [Nat.rec_zero] | fix c ih => rw [← ih, Cont.then] | _ => simp only [Cfg.then] #align turing.to_partrec.step_normal_then Turing.ToPartrec.stepNormal_then /-- The `stepRet` function respects the `then k'` homomorphism. Note that this is an exact equality, not a simulation; the original and embedded machines move in lock-step until the embedded machine reaches the halt state. -/ theorem stepRet_then {k k' : Cont} {v} : stepRet (k.then k') v = (stepRet k v).then k' := by induction k generalizing v with simp only [Cont.then, stepRet, *] | cons₁ => rw [← stepNormal_then] rfl | comp => rw [← stepNormal_then] | fix _ _ k_ih => split_ifs · rw [← k_ih] · rw [← stepNormal_then] rfl | _ => simp only [Cfg.then] #align turing.to_partrec.step_ret_then Turing.ToPartrec.stepRet_then /-- This is a temporary definition, because we will prove in `code_is_ok` that it always holds. It asserts that `c` is semantically correct; that is, for any `k` and `v`, `eval (stepNormal c k v) = eval (Cfg.ret k (Code.eval c v))`, as an equality of partial values (so one diverges iff the other does). In particular, we can let `k = Cont.halt`, and then this asserts that `stepNormal c Cont.halt v` evaluates to `Cfg.halt (Code.eval c v)`. -/ def Code.Ok (c : Code) := ∀ k v, Turing.eval step (stepNormal c k v) = Code.eval c v >>= fun v => Turing.eval step (Cfg.ret k v) #align turing.to_partrec.code.ok Turing.ToPartrec.Code.Ok theorem Code.Ok.zero {c} (h : Code.Ok c) {v} : Turing.eval step (stepNormal c Cont.halt v) = Cfg.halt <$> Code.eval c v := by rw [h, ← bind_pure_comp]; congr; funext v exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.single rfl, rfl⟩) #align turing.to_partrec.code.ok.zero Turing.ToPartrec.Code.Ok.zero theorem stepNormal.is_ret (c k v) : ∃ k' v', stepNormal c k v = Cfg.ret k' v' := by induction c generalizing k v with | cons _f fs IHf _IHfs => apply IHf | comp f _g _IHf IHg => apply IHg | case f g IHf IHg => rw [stepNormal] simp only [] cases v.headI <;> [apply IHf; apply IHg] | fix f IHf => apply IHf | _ => exact ⟨_, _, rfl⟩ #align turing.to_partrec.step_normal.is_ret Turing.ToPartrec.stepNormal.is_ret theorem cont_eval_fix {f k v} (fok : Code.Ok f) : Turing.eval step (stepNormal f (Cont.fix f k) v) = f.fix.eval v >>= fun v => Turing.eval step (Cfg.ret k v) := by refine Part.ext fun x => ?_ simp only [Part.bind_eq_bind, Part.mem_bind_iff] constructor · suffices ∀ c, x ∈ eval step c → ∀ v c', c = Cfg.then c' (Cont.fix f k) → Reaches step (stepNormal f Cont.halt v) c' → ∃ v₁ ∈ f.eval v, ∃ v₂ ∈ if List.headI v₁ = 0 then pure v₁.tail else f.fix.eval v₁.tail, x ∈ eval step (Cfg.ret k v₂) by intro h obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := this _ h _ _ (stepNormal_then _ Cont.halt _ _) ReflTransGen.refl refine ⟨v₂, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some] split_ifs at hv₂ ⊢ · rw [Part.mem_some_iff.1 hv₂] exact Or.inl (Part.mem_some _) · exact Or.inr ⟨_, Part.mem_some _, hv₂⟩ refine fun c he => evalInduction he fun y h IH => ?_ rintro v (⟨v'⟩ | ⟨k', v'⟩) rfl hr <;> rw [Cfg.then] at h IH <;> simp only [] at h IH · have := mem_eval.2 ⟨hr, rfl⟩ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] at this obtain ⟨v'', h₁, h₂⟩ := this rw [reaches_eval] at h₂ swap · exact ReflTransGen.single rfl cases Part.mem_unique h₂ (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) refine ⟨v', h₁, ?_⟩ rw [stepRet] at h revert h by_cases he : v'.headI = 0 <;> simp only [exists_prop, if_pos, if_false, he] <;> intro h · refine ⟨_, Part.mem_some _, ?_⟩ rw [reaches_eval] · exact h exact ReflTransGen.single rfl · obtain ⟨k₀, v₀, e₀⟩ := stepNormal.is_ret f Cont.halt v'.tail have e₁ := stepNormal_then f Cont.halt (Cont.fix f k) v'.tail rw [e₀, Cont.then, Cfg.then] at e₁ simp only [] at e₁ obtain ⟨v₁, hv₁, v₂, hv₂, h₃⟩ := IH (stepRet (k₀.then (Cont.fix f k)) v₀) (by rw [stepRet, if_neg he, e₁]; rfl) v'.tail _ stepRet_then (by apply ReflTransGen.single; rw [e₀]; rfl) refine ⟨_, PFun.mem_fix_iff.2 ?_, h₃⟩ simp only [Part.eq_some_iff.2 hv₁, Part.map_some, Part.mem_some_iff] split_ifs at hv₂ ⊢ <;> [exact Or.inl (congr_arg Sum.inl (Part.mem_some_iff.1 hv₂)); exact Or.inr ⟨_, rfl, hv₂⟩] · exact IH _ rfl _ _ stepRet_then (ReflTransGen.tail hr rfl) · rintro ⟨v', he, hr⟩ rw [reaches_eval] at hr swap · exact ReflTransGen.single rfl refine PFun.fixInduction he fun v (he : v' ∈ f.fix.eval v) IH => ?_ rw [fok, Part.bind_eq_bind, Part.mem_bind_iff] obtain he | ⟨v'', he₁', _⟩ := PFun.mem_fix_iff.1 he · obtain ⟨v', he₁, he₂⟩ := (Part.mem_map_iff _).1 he split_ifs at he₂ with h; cases he₂ refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rwa [stepRet, if_pos h] · obtain ⟨v₁, he₁, he₂⟩ := (Part.mem_map_iff _).1 he₁' split_ifs at he₂ with h; cases he₂ clear he₁' refine ⟨_, he₁, ?_⟩ rw [reaches_eval] swap · exact ReflTransGen.single rfl rw [stepRet, if_neg h] exact IH v₁.tail ((Part.mem_map_iff _).2 ⟨_, he₁, if_neg h⟩) #align turing.to_partrec.cont_eval_fix Turing.ToPartrec.cont_eval_fix theorem code_is_ok (c) : Code.Ok c := by induction c with (intro k v; rw [stepNormal]) | cons f fs IHf IHfs => rw [Code.eval, IHf] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHfs]; congr; funext v' refine Eq.trans (b := eval step (stepRet (Cont.cons₂ v k) v')) ?_ (Eq.symm ?_) <;> exact reaches_eval (ReflTransGen.single rfl) | comp f g IHf IHg => rw [Code.eval, IHg] simp only [bind_assoc, Cont.eval, pure_bind]; congr; funext v rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IHf] | case f g IHf IHg => simp only [Code.eval] cases v.headI <;> simp only [Nat.rec_zero, Part.bind_eq_bind] <;> [apply IHf; apply IHg] | fix f IHf => rw [cont_eval_fix IHf] | _ => simp only [Code.eval, pure_bind] #align turing.to_partrec.code_is_ok Turing.ToPartrec.code_is_ok theorem stepNormal_eval (c v) : eval step (stepNormal c Cont.halt v) = Cfg.halt <$> c.eval v := (code_is_ok c).zero #align turing.to_partrec.step_normal_eval Turing.ToPartrec.stepNormal_eval theorem stepRet_eval {k v} : eval step (stepRet k v) = Cfg.halt <$> k.eval v := by induction k generalizing v with | halt => simp only [mem_eval, Cont.eval, map_pure] exact Part.eq_some_iff.2 (mem_eval.2 ⟨ReflTransGen.refl, rfl⟩) | cons₁ fs as k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [stepRet, IH, bind_pure_comp] | cons₂ ns k IH => rw [Cont.eval, stepRet]; exact IH | comp f k IH => rw [Cont.eval, stepRet, code_is_ok] simp only [← bind_pure_comp, bind_assoc]; congr; funext v' rw [reaches_eval]; swap · exact ReflTransGen.single rfl rw [IH, bind_pure_comp] | fix f k IH => rw [Cont.eval, stepRet]; simp only [bind_pure_comp] split_ifs; · exact IH simp only [← bind_pure_comp, bind_assoc, cont_eval_fix (code_is_ok _)] congr; funext; rw [bind_pure_comp, ← IH] exact reaches_eval (ReflTransGen.single rfl) #align turing.to_partrec.step_ret_eval Turing.ToPartrec.stepRet_eval end ToPartrec /-! ## Simulating sequentialized partial recursive functions in TM2 At this point we have a sequential model of partial recursive functions: the `Cfg` type and `step : Cfg → Option Cfg` function from the previous section. The key feature of this model is that it does a finite amount of computation (in fact, an amount which is statically bounded by the size of the program) between each step, and no individual step can diverge (unlike the compositional semantics, where every sub-part of the computation is potentially divergent). So we can utilize the same techniques as in the other TM simulations in `Computability.TuringMachine` to prove that each step corresponds to a finite number of steps in a lower level model. (We don't prove it here, but in anticipation of the complexity class P, the simulation is actually polynomial-time as well.) The target model is `Turing.TM2`, which has a fixed finite set of stacks, a bit of local storage, with programs selected from a potentially infinite (but finitely accessible) set of program positions, or labels `Λ`, each of which executes a finite sequence of basic stack commands. For this program we will need four stacks, each on an alphabet `Γ'` like so: inductive Γ' | consₗ | cons | bit0 | bit1 We represent a number as a bit sequence, lists of numbers by putting `cons` after each element, and lists of lists of natural numbers by putting `consₗ` after each list. For example: 0 ~> [] 1 ~> [bit1] 6 ~> [bit0, bit1, bit1] [1, 2] ~> [bit1, cons, bit0, bit1, cons] [[], [1, 2]] ~> [consₗ, bit1, cons, bit0, bit1, cons, consₗ] The four stacks are `main`, `rev`, `aux`, `stack`. In normal mode, `main` contains the input to the current program (a `List ℕ`) and `stack` contains data (a `List (List ℕ)`) associated to the current continuation, and in `ret` mode `main` contains the value that is being passed to the continuation and `stack` contains the data for the continuation. The `rev` and `aux` stacks are usually empty; `rev` is used to store reversed data when e.g. moving a value from one stack to another, while `aux` is used as a temporary for a `main`/`stack` swap that happens during `cons₁` evaluation. The only local store we need is `Option Γ'`, which stores the result of the last pop operation. (Most of our working data are natural numbers, which are too large to fit in the local store.) The continuations from the previous section are data-carrying, containing all the values that have been computed and are awaiting other arguments. In order to have only a finite number of continuations appear in the program so that they can be used in machine states, we separate the data part (anything with type `List ℕ`) from the `Cont` type, producing a `Cont'` type that lacks this information. The data is kept on the `stack` stack. Because we want to have subroutines for e.g. moving an entire stack to another place, we use an infinite inductive type `Λ'` so that we can execute a program and then return to do something else without having to define too many different kinds of intermediate states. (We must nevertheless prove that only finitely many labels are accessible.) The labels are: * `move p k₁ k₂ q`: move elements from stack `k₁` to `k₂` while `p` holds of the value being moved. The last element, that fails `p`, is placed in neither stack but left in the local store. At the end of the operation, `k₂` will have the elements of `k₁` in reverse order. Then do `q`. * `clear p k q`: delete elements from stack `k` until `p` is true. Like `move`, the last element is left in the local storage. Then do `q`. * `copy q`: Move all elements from `rev` to both `main` and `stack` (in reverse order), then do `q`. That is, it takes `(a, b, c, d)` to `(b.reverse ++ a, [], c, b.reverse ++ d)`. * `push k f q`: push `f s`, where `s` is the local store, to stack `k`, then do `q`. This is a duplicate of the `push` instruction that is part of the TM2 model, but by having a subroutine just for this purpose we can build up programs to execute inside a `goto` statement, where we have the flexibility to be general recursive. * `read (f : Option Γ' → Λ')`: go to state `f s` where `s` is the local store. Again this is only here for convenience. * `succ q`: perform a successor operation. Assuming `[n]` is encoded on `main` before, `[n+1]` will be on main after. This implements successor for binary natural numbers. * `pred q₁ q₂`: perform a predecessor operation or `case` statement. If `[]` is encoded on `main` before, then we transition to `q₁` with `[]` on main; if `(0 :: v)` is on `main` before then `v` will be on `main` after and we transition to `q₁`; and if `(n+1 :: v)` is on `main` before then `n :: v` will be on `main` after and we transition to `q₂`. * `ret k`: call continuation `k`. Each continuation has its own interpretation of the data in `stack` and sets up the data for the next continuation. * `ret (cons₁ fs k)`: `v :: KData` on `stack` and `ns` on `main`, and the next step expects `v` on `main` and `ns :: KData` on `stack`. So we have to do a little dance here with six reverse-moves using the `aux` stack to perform a three-point swap, each of which involves two reversals. * `ret (cons₂ k)`: `ns :: KData` is on `stack` and `v` is on `main`, and we have to put `ns.headI :: v` on `main` and `KData` on `stack`. This is done using the `head` subroutine. * `ret (fix f k)`: This stores no data, so we just check if `main` starts with `0` and if so, remove it and call `k`, otherwise `clear` the first value and call `f`. * `ret halt`: the stack is empty, and `main` has the output. Do nothing and halt. In addition to these basic states, we define some additional subroutines that are used in the above: * `push'`, `peek'`, `pop'` are special versions of the builtins that use the local store to supply inputs and outputs. * `unrev`: special case `move false rev main` to move everything from `rev` back to `main`. Used as a cleanup operation in several functions. * `moveExcl p k₁ k₂ q`: same as `move` but pushes the last value read back onto the source stack. * `move₂ p k₁ k₂ q`: double `move`, so that the result comes out in the right order at the target stack. Implemented as `moveExcl p k rev; move false rev k₂`. Assumes that neither `k₁` nor `k₂` is `rev` and `rev` is initially empty. * `head k q`: get the first natural number from stack `k` and reverse-move it to `rev`, then clear the rest of the list at `k` and then `unrev` to reverse-move the head value to `main`. This is used with `k = main` to implement regular `head`, i.e. if `v` is on `main` before then `[v.headI]` will be on `main` after; and also with `k = stack` for the `cons` operation, which has `v` on `main` and `ns :: KData` on `stack`, and results in `KData` on `stack` and `ns.headI :: v` on `main`. * `trNormal` is the main entry point, defining states that perform a given `code` computation. It mostly just dispatches to functions written above. The main theorem of this section is `tr_eval`, which asserts that for each that for each code `c`, the state `init c v` steps to `halt v'` in finitely many steps if and only if `Code.eval c v = some v'`. -/ set_option linter.uppercaseLean3 false namespace PartrecToTM2 section open ToPartrec /-- The alphabet for the stacks in the program. `bit0` and `bit1` are used to represent `ℕ` values as lists of binary digits, `cons` is used to separate `List ℕ` values, and `consₗ` is used to separate `List (List ℕ)` values. See the section documentation. -/ inductive Γ' | consₗ | cons | bit0 | bit1 deriving DecidableEq, Inhabited, Fintype #align turing.partrec_to_TM2.Γ' Turing.PartrecToTM2.Γ' #align turing.partrec_to_TM2.Γ'.Cons Turing.PartrecToTM2.Γ'.consₗ #align turing.partrec_to_TM2.Γ'.cons Turing.PartrecToTM2.Γ'.cons #align turing.partrec_to_TM2.Γ'.bit0 Turing.PartrecToTM2.Γ'.bit0 #align turing.partrec_to_TM2.Γ'.bit1 Turing.PartrecToTM2.Γ'.bit1 /-- The four stacks used by the program. `main` is used to store the input value in `trNormal` mode and the output value in `Λ'.ret` mode, while `stack` is used to keep all the data for the continuations. `rev` is used to store reversed lists when transferring values between stacks, and `aux` is only used once in `cons₁`. See the section documentation. -/ inductive K' | main | rev | aux | stack deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.K' Turing.PartrecToTM2.K' #align turing.partrec_to_TM2.K'.main Turing.PartrecToTM2.K'.main #align turing.partrec_to_TM2.K'.rev Turing.PartrecToTM2.K'.rev #align turing.partrec_to_TM2.K'.aux Turing.PartrecToTM2.K'.aux #align turing.partrec_to_TM2.K'.stack Turing.PartrecToTM2.K'.stack open K' /-- Continuations as in `ToPartrec.Cont` but with the data removed. This is done because we want the set of all continuations in the program to be finite (so that it can ultimately be encoded into the finite state machine of a Turing machine), but a continuation can handle a potentially infinite number of data values during execution. -/ inductive Cont' | halt | cons₁ : Code → Cont' → Cont' | cons₂ : Cont' → Cont' | comp : Code → Cont' → Cont' | fix : Code → Cont' → Cont' deriving DecidableEq, Inhabited #align turing.partrec_to_TM2.cont' Turing.PartrecToTM2.Cont' #align turing.partrec_to_TM2.cont'.halt Turing.PartrecToTM2.Cont'.halt #align turing.partrec_to_TM2.cont'.cons₁ Turing.PartrecToTM2.Cont'.cons₁ #align turing.partrec_to_TM2.cont'.cons₂ Turing.PartrecToTM2.Cont'.cons₂ #align turing.partrec_to_TM2.cont'.comp Turing.PartrecToTM2.Cont'.comp #align turing.partrec_to_TM2.cont'.fix Turing.PartrecToTM2.Cont'.fix /-- The set of program positions. We make extensive use of inductive types here to let us describe "subroutines"; for example `clear p k q` is a program that clears stack `k`, then does `q` where `q` is another label. In order to prevent this from resulting in an infinite number of distinct accessible states, we are careful to be non-recursive (although loops are okay). See the section documentation for a description of all the programs. -/ inductive Λ' | move (p : Γ' → Bool) (k₁ k₂ : K') (q : Λ') | clear (p : Γ' → Bool) (k : K') (q : Λ') | copy (q : Λ') | push (k : K') (s : Option Γ' → Option Γ') (q : Λ') | read (f : Option Γ' → Λ') | succ (q : Λ') | pred (q₁ q₂ : Λ') | ret (k : Cont') #align turing.partrec_to_TM2.Λ' Turing.PartrecToTM2.Λ' #align turing.partrec_to_TM2.Λ'.move Turing.PartrecToTM2.Λ'.move #align turing.partrec_to_TM2.Λ'.clear Turing.PartrecToTM2.Λ'.clear #align turing.partrec_to_TM2.Λ'.copy Turing.PartrecToTM2.Λ'.copy #align turing.partrec_to_TM2.Λ'.push Turing.PartrecToTM2.Λ'.push #align turing.partrec_to_TM2.Λ'.read Turing.PartrecToTM2.Λ'.read #align turing.partrec_to_TM2.Λ'.succ Turing.PartrecToTM2.Λ'.succ #align turing.partrec_to_TM2.Λ'.pred Turing.PartrecToTM2.Λ'.pred #align turing.partrec_to_TM2.Λ'.ret Turing.PartrecToTM2.Λ'.ret -- Porting note: `Turing.PartrecToTM2.Λ'.rec` is noncomputable in Lean4, so we make it computable. compile_inductive% Code compile_inductive% Cont' compile_inductive% K' compile_inductive% Λ' instance Λ'.instInhabited : Inhabited Λ' := ⟨Λ'.ret Cont'.halt⟩ #align turing.partrec_to_TM2.Λ'.inhabited Turing.PartrecToTM2.Λ'.instInhabited instance Λ'.instDecidableEq : DecidableEq Λ' := fun a b => by induction a generalizing b <;> cases b <;> first | apply Decidable.isFalse; rintro ⟨⟨⟩⟩; done | exact decidable_of_iff' _ (by simp [Function.funext_iff]; rfl) #align turing.partrec_to_TM2.Λ'.decidable_eq Turing.PartrecToTM2.Λ'.instDecidableEq /-- The type of TM2 statements used by this machine. -/ def Stmt' := TM2.Stmt (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.stmt' Turing.PartrecToTM2.Stmt' /-- The type of TM2 configurations used by this machine. -/ def Cfg' := TM2.Cfg (fun _ : K' => Γ') Λ' (Option Γ') deriving Inhabited #align turing.partrec_to_TM2.cfg' Turing.PartrecToTM2.Cfg' open TM2.Stmt /-- A predicate that detects the end of a natural number, either `Γ'.cons` or `Γ'.consₗ` (or implicitly the end of the list), for use in predicate-taking functions like `move` and `clear`. -/ @[simp] def natEnd : Γ' → Bool | Γ'.consₗ => true | Γ'.cons => true | _ => false #align turing.partrec_to_TM2.nat_end Turing.PartrecToTM2.natEnd /-- Pop a value from the stack and place the result in local store. -/ @[simp] def pop' (k : K') : Stmt' → Stmt' := pop k fun _ v => v #align turing.partrec_to_TM2.pop' Turing.PartrecToTM2.pop' /-- Peek a value from the stack and place the result in local store. -/ @[simp] def peek' (k : K') : Stmt' → Stmt' := peek k fun _ v => v #align turing.partrec_to_TM2.peek' Turing.PartrecToTM2.peek' /-- Push the value in the local store to the given stack. -/ @[simp] def push' (k : K') : Stmt' → Stmt' := push k fun x => x.iget #align turing.partrec_to_TM2.push' Turing.PartrecToTM2.push' /-- Move everything from the `rev` stack to the `main` stack (reversed). -/ def unrev := Λ'.move (fun _ => false) rev main #align turing.partrec_to_TM2.unrev Turing.PartrecToTM2.unrev /-- Move elements from `k₁` to `k₂` while `p` holds, with the last element being left on `k₁`. -/ def moveExcl (p k₁ k₂ q) := Λ'.move p k₁ k₂ <| Λ'.push k₁ id q #align turing.partrec_to_TM2.move_excl Turing.PartrecToTM2.moveExcl /-- Move elements from `k₁` to `k₂` without reversion, by performing a double move via the `rev` stack. -/ def move₂ (p k₁ k₂ q) := moveExcl p k₁ rev <| Λ'.move (fun _ => false) rev k₂ q #align turing.partrec_to_TM2.move₂ Turing.PartrecToTM2.move₂ /-- Assuming `trList v` is on the front of stack `k`, remove it, and push `v.headI` onto `main`. See the section documentation. -/ def head (k : K') (q : Λ') : Λ' := Λ'.move natEnd k rev <| (Λ'.push rev fun _ => some Γ'.cons) <| Λ'.read fun s => (if s = some Γ'.consₗ then id else Λ'.clear (fun x => x = Γ'.consₗ) k) <| unrev q #align turing.partrec_to_TM2.head Turing.PartrecToTM2.head /-- The program that evaluates code `c` with continuation `k`. This expects an initial state where `trList v` is on `main`, `trContStack k` is on `stack`, and `aux` and `rev` are empty. See the section documentation for details. -/ @[simp] def trNormal : Code → Cont' → Λ' | Code.zero', k => (Λ'.push main fun _ => some Γ'.cons) <| Λ'.ret k | Code.succ, k => head main <| Λ'.succ <| Λ'.ret k | Code.tail, k => Λ'.clear natEnd main <| Λ'.ret k | Code.cons f fs, k => (Λ'.push stack fun _ => some Γ'.consₗ) <| Λ'.move (fun _ => false) main rev <| Λ'.copy <| trNormal f (Cont'.cons₁ fs k) | Code.comp f g, k => trNormal g (Cont'.comp f k) | Code.case f g, k => Λ'.pred (trNormal f k) (trNormal g k) | Code.fix f, k => trNormal f (Cont'.fix f k) #align turing.partrec_to_TM2.tr_normal Turing.PartrecToTM2.trNormal /-- The main program. See the section documentation for details. -/ def tr : Λ' → Stmt' | Λ'.move p k₁ k₂ q => pop' k₁ <| branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q) | Λ'.push k f q => branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) | Λ'.read q => goto q | Λ'.clear p k q => pop' k <| branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q) | Λ'.copy q => pop' rev <| branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q) | Λ'.succ q => pop' main <| branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) | Λ'.pred q₁ q₂ => pop' main <| branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂)) | Λ'.ret (Cont'.cons₁ fs k) => goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) | Λ'.ret (Cont'.cons₂ k) => goto fun _ => head stack <| Λ'.ret k | Λ'.ret (Cont'.comp f k) => goto fun _ => trNormal f k | Λ'.ret (Cont'.fix f k) => pop' main <| goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k) | Λ'.ret Cont'.halt => (load fun _ => none) <| halt #align turing.partrec_to_TM2.tr Turing.PartrecToTM2.tr /- Porting note: The equation lemma of `tr` simplifies to `match` structures. To prevent this, we replace equation lemmas of `tr`. -/ theorem tr_move (p k₁ k₂ q) : tr (Λ'.move p k₁ k₂ q) = pop' k₁ (branch (fun s => s.elim true p) (goto fun _ => q) (push' k₂ <| goto fun _ => Λ'.move p k₁ k₂ q)) := rfl theorem tr_push (k f q) : tr (Λ'.push k f q) = branch (fun s => (f s).isSome) ((push k fun s => (f s).iget) <| goto fun _ => q) (goto fun _ => q) := rfl theorem tr_read (q) : tr (Λ'.read q) = goto q := rfl theorem tr_clear (p k q) : tr (Λ'.clear p k q) = pop' k (branch (fun s => s.elim true p) (goto fun _ => q) (goto fun _ => Λ'.clear p k q)) := rfl theorem tr_copy (q) : tr (Λ'.copy q) = pop' rev (branch Option.isSome (push' main <| push' stack <| goto fun _ => Λ'.copy q) (goto fun _ => q)) := rfl theorem tr_succ (q) : tr (Λ'.succ q) = pop' main (branch (fun s => s = some Γ'.bit1) ((push rev fun _ => Γ'.bit0) <| goto fun _ => Λ'.succ q) <| branch (fun s => s = some Γ'.cons) ((push main fun _ => Γ'.cons) <| (push main fun _ => Γ'.bit1) <| goto fun _ => unrev q) ((push main fun _ => Γ'.bit1) <| goto fun _ => unrev q)) := rfl theorem tr_pred (q₁ q₂) : tr (Λ'.pred q₁ q₂) = pop' main (branch (fun s => s = some Γ'.bit0) ((push rev fun _ => Γ'.bit1) <| goto fun _ => Λ'.pred q₁ q₂) <| branch (fun s => natEnd s.iget) (goto fun _ => q₁) (peek' main <| branch (fun s => natEnd s.iget) (goto fun _ => unrev q₂) ((push rev fun _ => Γ'.bit0) <| goto fun _ => unrev q₂))) := rfl theorem tr_ret_cons₁ (fs k) : tr (Λ'.ret (Cont'.cons₁ fs k)) = goto fun _ => move₂ (fun _ => false) main aux <| move₂ (fun s => s = Γ'.consₗ) stack main <| move₂ (fun _ => false) aux stack <| trNormal fs (Cont'.cons₂ k) := rfl theorem tr_ret_cons₂ (k) : tr (Λ'.ret (Cont'.cons₂ k)) = goto fun _ => head stack <| Λ'.ret k := rfl theorem tr_ret_comp (f k) : tr (Λ'.ret (Cont'.comp f k)) = goto fun _ => trNormal f k := rfl theorem tr_ret_fix (f k) : tr (Λ'.ret (Cont'.fix f k)) = pop' main (goto fun s => cond (natEnd s.iget) (Λ'.ret k) <| Λ'.clear natEnd main <| trNormal f (Cont'.fix f k)) := rfl theorem tr_ret_halt : tr (Λ'.ret Cont'.halt) = (load fun _ => none) halt := rfl attribute [eqns tr_move tr_push tr_read tr_clear tr_copy tr_succ tr_pred tr_ret_cons₁ tr_ret_cons₂ tr_ret_comp tr_ret_fix tr_ret_halt] tr attribute [simp] tr /-- Translating a `Cont` continuation to a `Cont'` continuation simply entails dropping all the data. This data is instead encoded in `trContStack` in the configuration. -/ def trCont : Cont → Cont' | Cont.halt => Cont'.halt | Cont.cons₁ c _ k => Cont'.cons₁ c (trCont k) | Cont.cons₂ _ k => Cont'.cons₂ (trCont k) | Cont.comp c k => Cont'.comp c (trCont k) | Cont.fix c k => Cont'.fix c (trCont k) #align turing.partrec_to_TM2.tr_cont Turing.PartrecToTM2.trCont /-- We use `PosNum` to define the translation of binary natural numbers. A natural number is represented as a little-endian list of `bit0` and `bit1` elements: 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] In particular, this representation guarantees no trailing `bit0`'s at the end of the list. -/ def trPosNum : PosNum → List Γ' | PosNum.one => [Γ'.bit1] | PosNum.bit0 n => Γ'.bit0 :: trPosNum n | PosNum.bit1 n => Γ'.bit1 :: trPosNum n #align turing.partrec_to_TM2.tr_pos_num Turing.PartrecToTM2.trPosNum /-- We use `Num` to define the translation of binary natural numbers. Positive numbers are translated using `trPosNum`, and `trNum 0 = []`. So there are never any trailing `bit0`'s in a translated `Num`. 0 = [] 1 = [bit1] 2 = [bit0, bit1] 3 = [bit1, bit1] 4 = [bit0, bit0, bit1] -/ def trNum : Num → List Γ' | Num.zero => [] | Num.pos n => trPosNum n #align turing.partrec_to_TM2.tr_num Turing.PartrecToTM2.trNum /-- Because we use binary encoding, we define `trNat` in terms of `trNum`, using `Num`, which are binary natural numbers. (We could also use `Nat.binaryRecOn`, but `Num` and `PosNum` make for easy inductions.) -/ def trNat (n : ℕ) : List Γ' := trNum n #align turing.partrec_to_TM2.tr_nat Turing.PartrecToTM2.trNat @[simp] theorem trNat_zero : trNat 0 = [] := by rw [trNat, Nat.cast_zero]; rfl #align turing.partrec_to_TM2.tr_nat_zero Turing.PartrecToTM2.trNat_zero theorem trNat_default : trNat default = [] := trNat_zero #align turing.partrec_to_TM2.tr_nat_default Turing.PartrecToTM2.trNat_default /-- Lists are translated with a `cons` after each encoded number. For example: [] = [] [0] = [cons] [1] = [bit1, cons] [6, 0] = [bit0, bit1, bit1, cons, cons] -/ @[simp] def trList : List ℕ → List Γ' | [] => [] | n::ns => trNat n ++ Γ'.cons :: trList ns #align turing.partrec_to_TM2.tr_list Turing.PartrecToTM2.trList /-- Lists of lists are translated with a `consₗ` after each encoded list. For example: [] = [] [[]] = [consₗ] [[], []] = [consₗ, consₗ] [[0]] = [cons, consₗ] [[1, 2], [0]] = [bit1, cons, bit0, bit1, cons, consₗ, cons, consₗ] -/ @[simp] def trLList : List (List ℕ) → List Γ' | [] => [] | l::ls => trList l ++ Γ'.consₗ :: trLList ls #align turing.partrec_to_TM2.tr_llist Turing.PartrecToTM2.trLList /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ @[simp] def contStack : Cont → List (List ℕ) | Cont.halt => [] | Cont.cons₁ _ ns k => ns :: contStack k | Cont.cons₂ ns k => ns :: contStack k | Cont.comp _ k => contStack k | Cont.fix _ k => contStack k #align turing.partrec_to_TM2.cont_stack Turing.PartrecToTM2.contStack /-- The data part of a continuation is a list of lists, which is encoded on the `stack` stack using `trLList`. -/ def trContStack (k : Cont) := trLList (contStack k) #align turing.partrec_to_TM2.tr_cont_stack Turing.PartrecToTM2.trContStack /-- This is the nondependent eliminator for `K'`, but we use it specifically here in order to represent the stack data as four lists rather than as a function `K' → List Γ'`, because this makes rewrites easier. The theorems `K'.elim_update_main` et. al. show how such a function is updated after an `update` to one of the components. -/ def K'.elim (a b c d : List Γ') : K' → List Γ' | K'.main => a | K'.rev => b | K'.aux => c | K'.stack => d #align turing.partrec_to_TM2.K'.elim Turing.PartrecToTM2.K'.elim -- The equation lemma of `elim` simplifies to `match` structures. theorem K'.elim_main (a b c d) : K'.elim a b c d K'.main = a := rfl theorem K'.elim_rev (a b c d) : K'.elim a b c d K'.rev = b := rfl theorem K'.elim_aux (a b c d) : K'.elim a b c d K'.aux = c := rfl theorem K'.elim_stack (a b c d) : K'.elim a b c d K'.stack = d := rfl attribute [simp] K'.elim @[simp] theorem K'.elim_update_main {a b c d a'} : update (K'.elim a b c d) main a' = K'.elim a' b c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_main Turing.PartrecToTM2.K'.elim_update_main @[simp] theorem K'.elim_update_rev {a b c d b'} : update (K'.elim a b c d) rev b' = K'.elim a b' c d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_rev Turing.PartrecToTM2.K'.elim_update_rev @[simp] theorem K'.elim_update_aux {a b c d c'} : update (K'.elim a b c d) aux c' = K'.elim a b c' d := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_aux Turing.PartrecToTM2.K'.elim_update_aux @[simp] theorem K'.elim_update_stack {a b c d d'} : update (K'.elim a b c d) stack d' = K'.elim a b c d' := by funext x; cases x <;> rfl #align turing.partrec_to_TM2.K'.elim_update_stack Turing.PartrecToTM2.K'.elim_update_stack /-- The halting state corresponding to a `List ℕ` output value. -/ def halt (v : List ℕ) : Cfg' := ⟨none, none, K'.elim (trList v) [] [] []⟩ #align turing.partrec_to_TM2.halt Turing.PartrecToTM2.halt /-- The `Cfg` states map to `Cfg'` states almost one to one, except that in normal operation the local store contains an arbitrary garbage value. To make the final theorem cleaner we explicitly clear it in the halt state so that there is exactly one configuration corresponding to output `v`. -/ def TrCfg : Cfg → Cfg' → Prop | Cfg.ret k v, c' => ∃ s, c' = ⟨some (Λ'.ret (trCont k)), s, K'.elim (trList v) [] [] (trContStack k)⟩ | Cfg.halt v, c' => c' = halt v #align turing.partrec_to_TM2.tr_cfg Turing.PartrecToTM2.TrCfg /-- This could be a general list definition, but it is also somewhat specialized to this application. `splitAtPred p L` will search `L` for the first element satisfying `p`. If it is found, say `L = l₁ ++ a :: l₂` where `a` satisfies `p` but `l₁` does not, then it returns `(l₁, some a, l₂)`. Otherwise, if there is no such element, it returns `(L, none, [])`. -/ def splitAtPred {α} (p : α → Bool) : List α → List α × Option α × List α | [] => ([], none, []) | a :: as => cond (p a) ([], some a, as) <| let ⟨l₁, o, l₂⟩ := splitAtPred p as ⟨a::l₁, o, l₂⟩ #align turing.partrec_to_TM2.split_at_pred Turing.PartrecToTM2.splitAtPred theorem splitAtPred_eq {α} (p : α → Bool) : ∀ L l₁ o l₂, (∀ x ∈ l₁, p x = false) → Option.elim' (L = l₁ ∧ l₂ = []) (fun a => p a = true ∧ L = l₁ ++ a::l₂) o → splitAtPred p L = (l₁, o, l₂) | [], _, none, _, _, ⟨rfl, rfl⟩ => rfl | [], l₁, some o, l₂, _, ⟨_, h₃⟩ => by simp at h₃ | a :: L, l₁, o, l₂, h₁, h₂ => by rw [splitAtPred] have IH := splitAtPred_eq p L cases' o with o · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨⟨⟩, rfl⟩ rw [h₁ a (List.Mem.head _), cond, IH L none [] _ ⟨rfl, rfl⟩] exact fun x h => h₁ x (List.Mem.tail _ h) · cases' l₁ with a' l₁ <;> rcases h₂ with ⟨h₂, ⟨⟩⟩ · rw [h₂, cond] rw [h₁ a (List.Mem.head _), cond, IH l₁ (some o) l₂ _ ⟨h₂, _⟩] <;> try rfl exact fun x h => h₁ x (List.Mem.tail _ h) #align turing.partrec_to_TM2.split_at_pred_eq Turing.PartrecToTM2.splitAtPred_eq theorem splitAtPred_false {α} (L : List α) : splitAtPred (fun _ => false) L = (L, none, []) := splitAtPred_eq _ _ _ _ _ (fun _ _ => rfl) ⟨rfl, rfl⟩ #align turing.partrec_to_TM2.split_at_pred_ff Turing.PartrecToTM2.splitAtPred_false theorem move_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ k₂) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.move p k₁ k₂ q), s, S⟩ ⟨some q, o, update (update S k₁ L₂) k₂ (L₁.reverseAux (S k₂))⟩ := by induction' L₁ with a L₁ IH generalizing S s · rw [(_ : [].reverseAux _ = _), Function.update_eq_self] swap · rw [Function.update_noteq h₁.symm, List.reverseAux_nil] refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq] revert e; cases' S k₁ with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons, Option.iget_some] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ simp only [e] rfl · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim, ne_eq, List.reverseAux_cons] cases' e₁ : S k₁ with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, ne_eq, cond_false] convert @IH _ (update (update S k₁ Sk) k₂ (a :: S k₂)) _ using 2 <;> simp [Function.update_noteq, h₁, h₁.symm, e₃, List.reverseAux] simp [Function.update_comm h₁.symm] #align turing.partrec_to_TM2.move_ok Turing.PartrecToTM2.move_ok theorem unrev_ok {q s} {S : K' → List Γ'} : Reaches₁ (TM2.step tr) ⟨some (unrev q), s, S⟩ ⟨some q, none, update (update S rev []) main (List.reverseAux (S rev) (S main))⟩ := move_ok (by decide) <| splitAtPred_false _ #align turing.partrec_to_TM2.unrev_ok Turing.PartrecToTM2.unrev_ok theorem move₂_ok {p k₁ k₂ q s L₁ o L₂} {S : K' → List Γ'} (h₁ : k₁ ≠ rev ∧ k₂ ≠ rev ∧ k₁ ≠ k₂) (h₂ : S rev = []) (e : splitAtPred p (S k₁) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (move₂ p k₁ k₂ q), s, S⟩ ⟨some q, none, update (update S k₁ (o.elim id List.cons L₂)) k₂ (L₁ ++ S k₂)⟩ := by refine (move_ok h₁.1 e).trans (TransGen.head rfl ?_) simp only [TM2.step, Option.mem_def, TM2.stepAux, id_eq, ne_eq, Option.elim] cases o <;> simp only [Option.elim, id] · simp only [TM2.stepAux, Option.isSome, cond_false] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [Function.update_comm h₁.1, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_noteq h₁.1.symm, List.reverseAux_eq, h₂, Function.update_same, List.append_nil, List.reverse_reverse] · simp only [TM2.stepAux, Option.isSome, cond_true] convert move_ok h₁.2.1.symm (splitAtPred_false _) using 2 simp only [h₂, Function.update_comm h₁.1, List.reverseAux_eq, Function.update_same, List.append_nil, Function.update_idem] rw [show update S rev [] = S by rw [← h₂, Function.update_eq_self]] simp only [Function.update_noteq h₁.1.symm, Function.update_noteq h₁.2.2.symm, Function.update_noteq h₁.2.1, Function.update_same, List.reverse_reverse] #align turing.partrec_to_TM2.move₂_ok Turing.PartrecToTM2.move₂_ok theorem clear_ok {p k q s L₁ o L₂} {S : K' → List Γ'} (e : splitAtPred p (S k) = (L₁, o, L₂)) : Reaches₁ (TM2.step tr) ⟨some (Λ'.clear p k q), s, S⟩ ⟨some q, o, update S k L₂⟩ := by induction' L₁ with a L₁ IH generalizing S s · refine TransGen.head' rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] revert e; cases' S k with a Sk <;> intro e · cases e rfl simp only [splitAtPred, Option.elim, List.head?, List.tail_cons] at e ⊢ revert e; cases p a <;> intro e <;> simp only [cond_false, cond_true, Prod.mk.injEq, true_and, false_and] at e ⊢ rcases e with ⟨e₁, e₂⟩ rw [e₁, e₂] · refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, Option.elim] cases' e₁ : S k with a' Sk <;> rw [e₁, splitAtPred] at e · cases e cases e₂ : p a' <;> simp only [e₂, cond] at e swap · cases e rcases e₃ : splitAtPred p Sk with ⟨_, _, _⟩ rw [e₃] at e cases e simp only [List.head?_cons, e₂, List.tail_cons, cond_false] convert @IH _ (update S k Sk) _ using 2 <;> simp [e₃] #align turing.partrec_to_TM2.clear_ok Turing.PartrecToTM2.clear_ok theorem copy_ok (q s a b c d) : Reaches₁ (TM2.step tr) ⟨some (Λ'.copy q), s, K'.elim a b c d⟩ ⟨some q, none, K'.elim (List.reverseAux b a) [] c (List.reverseAux b d)⟩ := by induction' b with x b IH generalizing a d s · refine TransGen.single ?_ simp refine TransGen.head rfl ?_ simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_rev, List.head?_cons, Option.isSome_some, List.tail_cons, elim_update_rev, ne_eq, Function.update_noteq, elim_main, elim_update_main, elim_stack, elim_update_stack, cond_true, List.reverseAux_cons] exact IH _ _ _ #align turing.partrec_to_TM2.copy_ok Turing.PartrecToTM2.copy_ok theorem trPosNum_natEnd : ∀ (n), ∀ x ∈ trPosNum n, natEnd x = false | PosNum.one, _, List.Mem.head _ => rfl | PosNum.bit0 _, _, List.Mem.head _ => rfl | PosNum.bit0 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h | PosNum.bit1 _, _, List.Mem.head _ => rfl | PosNum.bit1 n, _, List.Mem.tail _ h => trPosNum_natEnd n _ h #align turing.partrec_to_TM2.tr_pos_num_nat_end Turing.PartrecToTM2.trPosNum_natEnd theorem trNum_natEnd : ∀ (n), ∀ x ∈ trNum n, natEnd x = false | Num.pos n, x, h => trPosNum_natEnd n x h #align turing.partrec_to_TM2.tr_num_nat_end Turing.PartrecToTM2.trNum_natEnd theorem trNat_natEnd (n) : ∀ x ∈ trNat n, natEnd x = false := trNum_natEnd _ #align turing.partrec_to_TM2.tr_nat_nat_end Turing.PartrecToTM2.trNat_natEnd theorem trList_ne_consₗ : ∀ (l), ∀ x ∈ trList l, x ≠ Γ'.consₗ | a :: l, x, h => by simp [trList] at h obtain h | rfl | h := h · rintro rfl cases trNat_natEnd _ _ h · rintro ⟨⟩ · exact trList_ne_consₗ l _ h #align turing.partrec_to_TM2.tr_list_ne_Cons Turing.PartrecToTM2.trList_ne_consₗ
Mathlib/Computability/TMToPartrec.lean
1,459
1,473
theorem head_main_ok {q s L} {c d : List Γ'} : Reaches₁ (TM2.step tr) ⟨some (head main q), s, K'.elim (trList L) [] c d⟩ ⟨some q, none, K'.elim (trList [L.headI]) [] c d⟩ := by
let o : Option Γ' := List.casesOn L none fun _ _ => some Γ'.cons refine (move_ok (by decide) (splitAtPred_eq _ _ (trNat L.headI) o (trList L.tail) (trNat_natEnd _) ?_)).trans (TransGen.head rfl (TransGen.head rfl ?_)) · cases L <;> simp [o] simp only [TM2.step, Option.mem_def, TM2.stepAux, elim_update_main, elim_rev, elim_update_rev, Function.update_same, trList] rw [if_neg (show o ≠ some Γ'.consₗ by cases L <;> simp [o])] refine (clear_ok (splitAtPred_eq _ _ _ none [] ?_ ⟨rfl, rfl⟩)).trans ?_ · exact fun x h => Bool.decide_false (trList_ne_consₗ _ _ h) convert unrev_ok using 2; simp [List.reverseAux_eq]
/- 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.Group.Equiv.Basic import Mathlib.Data.ENat.Lattice import Mathlib.Data.Part import Mathlib.Tactic.NormNum #align_import data.nat.part_enat from "leanprover-community/mathlib"@"3ff3f2d6a3118b8711063de7111a0d77a53219a8" /-! # Natural numbers with infinity The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an implementation. Use `ℕ∞` instead unless you care about computability. ## Main definitions The following instances are defined: * `OrderedAddCommMonoid PartENat` * `CanonicallyOrderedAddCommMonoid PartENat` * `CompleteLinearOrder PartENat` There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could be an `AddMonoidWithTop`. * `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well with `+` and `≤`. * `withTopAddEquiv : PartENat ≃+ ℕ∞` * `withTopOrderIso : PartENat ≃o ℕ∞` ## Implementation details `PartENat` is defined to be `Part ℕ`. `+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous so there is no `-` defined on `PartENat`. Before the `open scoped Classical` line, various proofs are made with decidability assumptions. This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`, followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`. ## Tags PartENat, ℕ∞ -/ open Part hiding some /-- Type of natural numbers with infinity (`⊤`) -/ def PartENat : Type := Part ℕ #align part_enat PartENat namespace PartENat /-- The computable embedding `ℕ → PartENat`. This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/ @[coe] def some : ℕ → PartENat := Part.some #align part_enat.some PartENat.some instance : Zero PartENat := ⟨some 0⟩ instance : Inhabited PartENat := ⟨0⟩ instance : One PartENat := ⟨some 1⟩ instance : Add PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩ instance (n : ℕ) : Decidable (some n).Dom := isTrue trivial @[simp] theorem dom_some (x : ℕ) : (some x).Dom := trivial #align part_enat.dom_some PartENat.dom_some instance addCommMonoid : AddCommMonoid PartENat where add := (· + ·) zero := 0 add_comm x y := Part.ext' and_comm fun _ _ => add_comm _ _ zero_add x := Part.ext' (true_and_iff _) fun _ _ => zero_add _ add_zero x := Part.ext' (and_true_iff _) fun _ _ => add_zero _ add_assoc x y z := Part.ext' and_assoc fun _ _ => add_assoc _ _ _ nsmul := nsmulRec instance : AddCommMonoidWithOne PartENat := { PartENat.addCommMonoid with one := 1 natCast := some natCast_zero := rfl natCast_succ := fun _ => Part.ext' (true_and_iff _).symm fun _ _ => rfl } theorem some_eq_natCast (n : ℕ) : some n = n := rfl #align part_enat.some_eq_coe PartENat.some_eq_natCast instance : CharZero PartENat where cast_injective := Part.some_injective /-- Alias of `Nat.cast_inj` specialized to `PartENat` --/ theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y := Nat.cast_inj #align part_enat.coe_inj PartENat.natCast_inj @[simp] theorem dom_natCast (x : ℕ) : (x : PartENat).Dom := trivial #align part_enat.dom_coe PartENat.dom_natCast -- See note [no_index around OfNat.ofNat] @[simp] theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)).Dom := trivial @[simp] theorem dom_zero : (0 : PartENat).Dom := trivial @[simp] theorem dom_one : (1 : PartENat).Dom := trivial instance : CanLift PartENat ℕ (↑) Dom := ⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩ instance : LE PartENat := ⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩ instance : Top PartENat := ⟨none⟩ instance : Bot PartENat := ⟨0⟩ instance : Sup PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩ theorem le_def (x y : PartENat) : x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy := Iff.rfl #align part_enat.le_def PartENat.le_def @[elab_as_elim] protected theorem casesOn' {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a := Part.induction_on #align part_enat.cases_on' PartENat.casesOn' @[elab_as_elim] protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by exact PartENat.casesOn' #align part_enat.cases_on PartENat.casesOn -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem top_add (x : PartENat) : ⊤ + x = ⊤ := Part.ext' (false_and_iff _) fun h => h.left.elim #align part_enat.top_add PartENat.top_add -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add] #align part_enat.add_top PartENat.add_top @[simp] theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl #align part_enat.coe_get PartENat.natCast_get @[simp, norm_cast] theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by rw [← natCast_inj, natCast_get] #align part_enat.get_coe' PartENat.get_natCast' theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x := get_natCast' _ _ #align part_enat.get_coe PartENat.get_natCast theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) : get ((x : PartENat) + y) h = x + get y h.2 := by rfl #align part_enat.coe_add_get PartENat.coe_add_get @[simp] theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 := rfl #align part_enat.get_add PartENat.get_add @[simp] theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 := rfl #align part_enat.get_zero PartENat.get_zero @[simp] theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 := rfl #align part_enat.get_one PartENat.get_one -- See note [no_index around OfNat.ofNat] @[simp] theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (no_index (OfNat.ofNat x : PartENat)).Dom) : Part.get (no_index (OfNat.ofNat x : PartENat)) h = (no_index (OfNat.ofNat x)) := get_natCast' x h nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b := get_eq_iff_eq_some #align part_enat.get_eq_iff_eq_some PartENat.get_eq_iff_eq_some theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by rw [get_eq_iff_eq_some] rfl #align part_enat.get_eq_iff_eq_coe PartENat.get_eq_iff_eq_coe theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h #align part_enat.dom_of_le_of_dom PartENat.dom_of_le_of_dom theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom := dom_of_le_of_dom h trivial #align part_enat.dom_of_le_some PartENat.dom_of_le_some theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by exact dom_of_le_some h #align part_enat.dom_of_le_coe PartENat.dom_of_le_natCast instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) := if hx : x.Dom then decidable_of_decidable_of_iff (by rw [le_def]) else if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩ #align part_enat.decidable_le PartENat.decidableLe -- Porting note: Removed. Use `Nat.castAddMonoidHom` instead. #noalign part_enat.coe_hom #noalign part_enat.coe_coe_hom instance partialOrder : PartialOrder PartENat where le := (· ≤ ·) le_refl _ := ⟨id, fun _ => le_rfl⟩ le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ => ⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩ lt_iff_le_not_le _ _ := Iff.rfl le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ => Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _) theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by rw [lt_iff_le_not_le, le_def, le_def, not_exists] constructor · rintro ⟨⟨hyx, H⟩, h⟩ by_cases hx : x.Dom · use hx intro hy specialize H hy specialize h fun _ => hy rw [not_forall] at h cases' h with hx' h rw [not_le] at h exact h · specialize h fun hx' => (hx hx').elim rw [not_forall] at h cases' h with hx' h exact (hx hx').elim · rintro ⟨hx, H⟩ exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩ #align part_enat.lt_def PartENat.lt_def noncomputable instance orderedAddCommMonoid : OrderedAddCommMonoid PartENat := { PartENat.partialOrder, PartENat.addCommMonoid with add_le_add_left := fun a b ⟨h₁, h₂⟩ c => PartENat.casesOn c (by simp [top_add]) fun c => ⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ } instance semilatticeSup : SemilatticeSup PartENat := { PartENat.partialOrder with sup := (· ⊔ ·) le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩ le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩ sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ => ⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ } #align part_enat.semilattice_sup PartENat.semilatticeSup instance orderBot : OrderBot PartENat where bot := ⊥ bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩ #align part_enat.order_bot PartENat.orderBot instance orderTop : OrderTop PartENat where top := ⊤ le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩ #align part_enat.order_top PartENat.orderTop instance : ZeroLEOneClass PartENat where zero_le_one := bot_le /-- Alias of `Nat.cast_le` specialized to `PartENat` --/ theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le #align part_enat.coe_le_coe PartENat.coe_le_coe /-- Alias of `Nat.cast_lt` specialized to `PartENat` --/ theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt #align part_enat.coe_lt_coe PartENat.coe_lt_coe @[simp] theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by conv => lhs rw [← coe_le_coe, natCast_get, natCast_get] #align part_enat.get_le_get PartENat.get_le_get theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n simp only [forall_prop_of_true, dom_natCast, get_natCast'] #align part_enat.le_coe_iff PartENat.le_coe_iff theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast] #align part_enat.lt_coe_iff PartENat.lt_coe_iff theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by rw [← some_eq_natCast] simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff] rfl #align part_enat.coe_le_iff PartENat.coe_le_iff theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by rw [← some_eq_natCast] simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff] rfl #align part_enat.coe_lt_iff PartENat.coe_lt_iff nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 := eq_bot_iff #align part_enat.eq_zero_iff PartENat.eq_zero_iff theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x := bot_lt_iff_ne_bot.symm #align part_enat.ne_zero_iff PartENat.ne_zero_iff theorem dom_of_lt {x y : PartENat} : x < y → x.Dom := PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _ #align part_enat.dom_of_lt PartENat.dom_of_lt theorem top_eq_none : (⊤ : PartENat) = Part.none := rfl #align part_enat.top_eq_none PartENat.top_eq_none @[simp] theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ := Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false #align part_enat.coe_lt_top PartENat.natCast_lt_top @[simp] theorem zero_lt_top : (0 : PartENat) < ⊤ := natCast_lt_top 0 @[simp] theorem one_lt_top : (1 : PartENat) < ⊤ := natCast_lt_top 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) < ⊤ := natCast_lt_top x @[simp] theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ := ne_of_lt (natCast_lt_top x) #align part_enat.coe_ne_top PartENat.natCast_ne_top @[simp] theorem zero_ne_top : (0 : PartENat) ≠ ⊤ := natCast_ne_top 0 @[simp] theorem one_ne_top : (1 : PartENat) ≠ ⊤ := natCast_ne_top 1 -- See note [no_index around OfNat.ofNat] @[simp] theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (no_index (OfNat.ofNat x : PartENat)) ≠ ⊤ := natCast_ne_top x theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) := not_isMax_of_lt (natCast_lt_top x) #align part_enat.not_is_max_coe PartENat.not_isMax_natCast theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by simpa only [← some_eq_natCast] using Part.ne_none_iff #align part_enat.ne_top_iff PartENat.ne_top_iff theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by classical exact not_iff_comm.1 Part.eq_none_iff'.symm #align part_enat.ne_top_iff_dom PartENat.ne_top_iff_dom theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ := Iff.not_left ne_top_iff_dom.symm #align part_enat.not_dom_iff_eq_top PartENat.not_dom_iff_eq_top theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ := ne_of_lt <| lt_of_lt_of_le h le_top #align part_enat.ne_top_of_lt PartENat.ne_top_of_lt theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by constructor · rintro rfl n exact natCast_lt_top _ · contrapose! rw [ne_top_iff] rintro ⟨n, rfl⟩ exact ⟨n, irrefl _⟩ #align part_enat.eq_top_iff_forall_lt PartENat.eq_top_iff_forall_lt theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x := (eq_top_iff_forall_lt x).trans ⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩ #align part_enat.eq_top_iff_forall_le PartENat.eq_top_iff_forall_le theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x := PartENat.casesOn x (by simp only [iff_true_iff, le_top, natCast_lt_top, ← @Nat.cast_zero PartENat]) fun n => by rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe] rfl #align part_enat.pos_iff_one_le PartENat.pos_iff_one_le instance isTotal : IsTotal PartENat (· ≤ ·) where total x y := PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top) (PartENat.casesOn y (fun _ => Or.inl le_top) fun x y => (le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2)) noncomputable instance linearOrder : LinearOrder PartENat := { PartENat.partialOrder with le_total := IsTotal.total decidableLE := Classical.decRel _ max := (· ⊔ ·) -- Porting note: was `max_def := @sup_eq_maxDefault _ _ (id _) _ }` max_def := fun a b => by change (fun a b => a ⊔ b) a b = _ rw [@sup_eq_maxDefault PartENat _ (id _) _] rfl } instance boundedOrder : BoundedOrder PartENat := { PartENat.orderTop, PartENat.orderBot with } noncomputable instance lattice : Lattice PartENat := { PartENat.semilatticeSup with inf := min inf_le_left := min_le_left inf_le_right := min_le_right le_inf := fun _ _ _ => le_min } noncomputable instance : CanonicallyOrderedAddCommMonoid PartENat := { PartENat.semilatticeSup, PartENat.orderBot, PartENat.orderedAddCommMonoid with le_self_add := fun a b => PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun b => PartENat.casesOn a (top_add _).ge fun a => (coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _) exists_add_of_le := fun {a b} => PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b => PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h => ⟨(b - a : ℕ), by rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ } theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) : x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h) lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h) rw [← Nat.cast_add, natCast_inj] at h rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h] #align part_enat.eq_coe_sub_of_add_eq_coe PartENat.eq_natCast_sub_of_add_eq_natCast protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ rcases ne_top_iff.mp hz with ⟨k, rfl⟩ induction' y using PartENat.casesOn with n · rw [top_add] -- Porting note: was apply_mod_cast natCast_lt_top norm_cast; apply natCast_lt_top norm_cast at h -- Porting note: was `apply_mod_cast add_lt_add_right h` norm_cast; apply add_lt_add_right h #align part_enat.add_lt_add_right PartENat.add_lt_add_right protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩ #align part_enat.add_lt_add_iff_right PartENat.add_lt_add_iff_right protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz] #align part_enat.add_lt_add_iff_left PartENat.add_lt_add_iff_left protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by conv_rhs => rw [← PartENat.add_lt_add_iff_left hx] rw [add_zero] #align part_enat.lt_add_iff_pos_right PartENat.lt_add_iff_pos_right theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by rw [PartENat.lt_add_iff_pos_right hx] norm_cast #align part_enat.lt_add_one PartENat.lt_add_one theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by induction' y using PartENat.casesOn with n · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.le_of_lt_succ; apply_mod_cast h` norm_cast; apply Nat.le_of_lt_succ; norm_cast at h #align part_enat.le_of_lt_add_one PartENat.le_of_lt_add_one theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by induction' y using PartENat.casesOn with n · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.succ_le_of_lt; apply_mod_cast h` norm_cast; apply Nat.succ_le_of_lt; norm_cast at h #align part_enat.add_one_le_of_lt PartENat.add_one_le_of_lt theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by refine ⟨fun h => ?_, add_one_le_of_lt⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction' y using PartENat.casesOn with n · apply natCast_lt_top -- Porting note: was `apply_mod_cast Nat.lt_of_succ_le; apply_mod_cast h` norm_cast; apply Nat.lt_of_succ_le; norm_cast at h #align part_enat.add_one_le_iff_lt PartENat.add_one_le_iff_lt theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)] #align part_enat.coe_succ_le_succ_iff PartENat.coe_succ_le_iff theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by refine ⟨le_of_lt_add_one, fun h => ?_⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction' y using PartENat.casesOn with n · rw [top_add] apply natCast_lt_top -- Porting note: was `apply_mod_cast Nat.lt_succ_of_le; apply_mod_cast h` norm_cast; apply Nat.lt_succ_of_le; norm_cast at h #align part_enat.lt_add_one_iff_lt PartENat.lt_add_one_iff_lt lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx] #align part_enat.lt_coe_succ_iff_le PartENat.lt_coe_succ_iff_le theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [top_add, add_top] simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true] #align part_enat.add_eq_top_iff PartENat.add_eq_top_iff protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by rcases ne_top_iff.1 hc with ⟨c, rfl⟩ refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add] simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const] #align part_enat.add_right_cancel_iff PartENat.add_right_cancel_iff protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha] #align part_enat.add_left_cancel_iff PartENat.add_left_cancel_iff section WithTop /-- Computably converts a `PartENat` to a `ℕ∞`. -/ def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ := x.toOption #align part_enat.to_with_top PartENat.toWithTop theorem toWithTop_top : have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable toWithTop ⊤ = ⊤ := rfl #align part_enat.to_with_top_top PartENat.toWithTop_top @[simp]
Mathlib/Data/Nat/PartENat.lean
594
595
theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by
convert toWithTop_top
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
258
264
theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by
induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih]
/- 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.Matrix.BilinearForm import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.FiniteDimensional import Mathlib.LinearAlgebra.Vandermonde import Mathlib.LinearAlgebra.Trace import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.PrimitiveElement import Mathlib.FieldTheory.Galois import Mathlib.RingTheory.PowerBasis import Mathlib.FieldTheory.Minpoly.MinpolyDiv #align_import ring_theory.trace from "leanprover-community/mathlib"@"3e068ece210655b7b9a9477c3aff38a492400aa1" /-! # Trace for (finite) ring extensions. Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`, the trace of the linear map given by multiplying by `s` gives information about the roots of the minimal polynomial of `s` over `R`. ## Main definitions * `Algebra.trace R S x`: the trace of an element `s` of an `R`-algebra `S` * `Algebra.traceForm R S`: bilinear form sending `x`, `y` to the trace of `x * y` * `Algebra.traceMatrix R b`: the matrix whose `(i j)`-th element is the trace of `b i * b j`. * `Algebra.embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose `(i, σ)` coefficient is `σ (b i)`. * `Algebra.embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ` given by a bijection `e : κ ≃ (B →ₐ[A] C)`. ## Main results * `trace_algebraMap_of_basis`, `trace_algebraMap`: if `x : K`, then `Tr_{L/K} x = [L : K] x` * `trace_trace_of_basis`, `trace_trace`: `Tr_{L/K} (Tr_{F/L} x) = Tr_{F/K} x` * `trace_eq_sum_roots`: the trace of `x : K(x)` is the sum of all conjugate roots of `x` * `trace_eq_sum_embeddings`: the trace of `x : K(x)` is the sum of all embeddings of `x` into an algebraically closed field * `traceForm_nondegenerate`: the trace form over a separable extension is a nondegenerate bilinear form * `traceForm_dualBasis_powerBasis_eq`: The dual basis of a powerbasis `{1, x, x²...}` under the trace form is `aᵢ / f'(x)`, with `f` being the minpoly of `x` and `f / (X - x) = ∑ aᵢxⁱ`. ## Implementation notes Typically, the trace is defined specifically for finite field extensions. The definition is as general as possible and the assumption that we have fields or that the extension is finite is added to the lemmas as needed. We only define the trace for left multiplication (`Algebra.leftMulMatrix`, i.e. `LinearMap.mulLeft`). For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway. ## References * https://en.wikipedia.org/wiki/Field_trace -/ universe u v w z variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] variable [Algebra R S] [Algebra R T] variable {K L : Type*} [Field K] [Field L] [Algebra K L] variable {ι κ : Type w} [Fintype ι] open FiniteDimensional open LinearMap (BilinForm) open LinearMap open Matrix open scoped Matrix namespace Algebra variable (b : Basis ι R S) variable (R S) /-- The trace of an element `s` of an `R`-algebra is the trace of `(s * ·)`, as an `R`-linear map. -/ noncomputable def trace : S →ₗ[R] R := (LinearMap.trace R S).comp (lmul R S).toLinearMap #align algebra.trace Algebra.trace variable {S} -- Not a `simp` lemma since there are more interesting ways to rewrite `trace R S x`, -- for example `trace_trace` theorem trace_apply (x) : trace R S x = LinearMap.trace R S (lmul R S x) := rfl #align algebra.trace_apply Algebra.trace_apply theorem trace_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset S, Nonempty (Basis s R S)) : trace R S = 0 := by ext s; simp [trace_apply, LinearMap.trace, h] #align algebra.trace_eq_zero_of_not_exists_basis Algebra.trace_eq_zero_of_not_exists_basis variable {R} -- Can't be a `simp` lemma because it depends on a choice of basis theorem trace_eq_matrix_trace [DecidableEq ι] (b : Basis ι R S) (s : S) : trace R S s = Matrix.trace (Algebra.leftMulMatrix b s) := by rw [trace_apply, LinearMap.trace_eq_matrix_trace _ b, ← toMatrix_lmul_eq]; rfl #align algebra.trace_eq_matrix_trace Algebra.trace_eq_matrix_trace /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/ theorem trace_algebraMap_of_basis (x : R) : trace R S (algebraMap R S x) = Fintype.card ι • x := by haveI := Classical.decEq ι rw [trace_apply, LinearMap.trace_eq_matrix_trace R b, Matrix.trace] convert Finset.sum_const x simp [-coe_lmul_eq_mul] #align algebra.trace_algebra_map_of_basis Algebra.trace_algebraMap_of_basis /-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. (If `L` is not finite-dimensional over `K`, then `trace` and `finrank` return `0`.) -/ @[simp] theorem trace_algebraMap (x : K) : trace K L (algebraMap K L x) = finrank K L • x := by by_cases H : ∃ s : Finset L, Nonempty (Basis s K L) · rw [trace_algebraMap_of_basis H.choose_spec.some, finrank_eq_card_basis H.choose_spec.some] · simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis_finset H] #align algebra.trace_algebra_map Algebra.trace_algebraMap theorem trace_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) (x : T) : trace R S (trace S T x) = trace R T x := by haveI := Classical.decEq ι haveI := Classical.decEq κ cases nonempty_fintype ι cases nonempty_fintype κ rw [trace_eq_matrix_trace (b.smul c), trace_eq_matrix_trace b, trace_eq_matrix_trace c, Matrix.trace, Matrix.trace, Matrix.trace, ← Finset.univ_product_univ, Finset.sum_product] refine Finset.sum_congr rfl fun i _ ↦ ?_ simp only [AlgHom.map_sum, smul_leftMulMatrix, Finset.sum_apply, Matrix.diag, Finset.sum_apply i (Finset.univ : Finset κ) fun y => leftMulMatrix b (leftMulMatrix c x y y)] #align algebra.trace_trace_of_basis Algebra.trace_trace_of_basis theorem trace_comp_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι] [Finite κ] (b : Basis ι R S) (c : Basis κ S T) : (trace R S).comp ((trace S T).restrictScalars R) = trace R T := by ext rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace_of_basis b c] #align algebra.trace_comp_trace_of_basis Algebra.trace_comp_trace_of_basis @[simp] theorem trace_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] (x : T) : trace K L (trace L T x) = trace K T x := trace_trace_of_basis (Basis.ofVectorSpace K L) (Basis.ofVectorSpace L T) x #align algebra.trace_trace Algebra.trace_trace @[simp] theorem trace_comp_trace [Algebra K T] [Algebra L T] [IsScalarTower K L T] [FiniteDimensional K L] [FiniteDimensional L T] : (trace K L).comp ((trace L T).restrictScalars K) = trace K T := by ext; rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace] #align algebra.trace_comp_trace Algebra.trace_comp_trace @[simp] theorem trace_prod_apply [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] (x : S × T) : trace R (S × T) x = trace R S x.fst + trace R T x.snd := by nontriviality R let f := (lmul R S).toLinearMap.prodMap (lmul R T).toLinearMap have : (lmul R (S × T)).toLinearMap = (prodMapLinear R S T S T R).comp f := LinearMap.ext₂ Prod.mul_def simp_rw [trace, this] exact trace_prodMap' _ _ #align algebra.trace_prod_apply Algebra.trace_prod_apply theorem trace_prod [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] : trace R (S × T) = (trace R S).coprod (trace R T) := LinearMap.ext fun p => by rw [coprod_apply, trace_prod_apply] #align algebra.trace_prod Algebra.trace_prod section TraceForm variable (R S) /-- The `traceForm` maps `x y : S` to the trace of `x * y`. It is a symmetric bilinear form and is nondegenerate if the extension is separable. -/ noncomputable def traceForm : BilinForm R S := LinearMap.compr₂ (lmul R S).toLinearMap (trace R S) #align algebra.trace_form Algebra.traceForm variable {S} -- This is a nicer lemma than the one produced by `@[simps] def traceForm`. @[simp] theorem traceForm_apply (x y : S) : traceForm R S x y = trace R S (x * y) := rfl #align algebra.trace_form_apply Algebra.traceForm_apply theorem traceForm_isSymm : (traceForm R S).IsSymm := fun _ _ => congr_arg (trace R S) (mul_comm _ _) #align algebra.trace_form_is_symm Algebra.traceForm_isSymm theorem traceForm_toMatrix [DecidableEq ι] (i j) : BilinForm.toMatrix b (traceForm R S) i j = trace R S (b i * b j) := by rw [BilinForm.toMatrix_apply, traceForm_apply] #align algebra.trace_form_to_matrix Algebra.traceForm_toMatrix theorem traceForm_toMatrix_powerBasis (h : PowerBasis R S) : BilinForm.toMatrix h.basis (traceForm R S) = of fun i j => trace R S (h.gen ^ (i.1 + j.1)) := by ext; rw [traceForm_toMatrix, of_apply, pow_add, h.basis_eq_pow, h.basis_eq_pow] #align algebra.trace_form_to_matrix_power_basis Algebra.traceForm_toMatrix_powerBasis end TraceForm end Algebra section EqSumRoots open Algebra Polynomial variable {F : Type*} [Field F] variable [Algebra K S] [Algebra K F] /-- Given `pb : PowerBasis K S`, the trace of `pb.gen` is `-(minpoly K pb.gen).nextCoeff`. -/ theorem PowerBasis.trace_gen_eq_nextCoeff_minpoly [Nontrivial S] (pb : PowerBasis K S) : Algebra.trace K S pb.gen = -(minpoly K pb.gen).nextCoeff := by have d_pos : 0 < pb.dim := PowerBasis.dim_pos pb have d_pos' : 0 < (minpoly K pb.gen).natDegree := by simpa haveI : Nonempty (Fin pb.dim) := ⟨⟨0, d_pos⟩⟩ rw [trace_eq_matrix_trace pb.basis, trace_eq_neg_charpoly_coeff, charpoly_leftMulMatrix, ← pb.natDegree_minpoly, Fintype.card_fin, ← nextCoeff_of_natDegree_pos d_pos'] #align power_basis.trace_gen_eq_next_coeff_minpoly PowerBasis.trace_gen_eq_nextCoeff_minpoly /-- Given `pb : PowerBasis K S`, then the trace of `pb.gen` is `((minpoly K pb.gen).aroots F).sum`. -/ theorem PowerBasis.trace_gen_eq_sum_roots [Nontrivial S] (pb : PowerBasis K S) (hf : (minpoly K pb.gen).Splits (algebraMap K F)) : algebraMap K F (trace K S pb.gen) = ((minpoly K pb.gen).aroots F).sum := by rw [PowerBasis.trace_gen_eq_nextCoeff_minpoly, RingHom.map_neg, ← nextCoeff_map (algebraMap K F).injective, sum_roots_eq_nextCoeff_of_monic_of_split ((minpoly.monic (PowerBasis.isIntegral_gen _)).map _) ((splits_id_iff_splits _).2 hf), neg_neg] #align power_basis.trace_gen_eq_sum_roots PowerBasis.trace_gen_eq_sum_roots namespace IntermediateField.AdjoinSimple open IntermediateField theorem trace_gen_eq_zero {x : L} (hx : ¬IsIntegral K x) : Algebra.trace K K⟮x⟯ (AdjoinSimple.gen K x) = 0 := by rw [trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply] contrapose! hx obtain ⟨s, ⟨b⟩⟩ := hx refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_ · exact (Submodule.fg_iff_finiteDimensional _).mpr (FiniteDimensional.of_fintype_basis b) · exact subset_adjoin K _ (Set.mem_singleton x) #align intermediate_field.adjoin_simple.trace_gen_eq_zero IntermediateField.AdjoinSimple.trace_gen_eq_zero theorem trace_gen_eq_sum_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (trace K K⟮x⟯ (AdjoinSimple.gen K x)) = ((minpoly K x).aroots F).sum := by have injKxL := (algebraMap K⟮x⟯ L).injective by_cases hx : IsIntegral K x; swap · simp [minpoly.eq_zero hx, trace_gen_eq_zero hx, aroots_def] rw [← adjoin.powerBasis_gen hx, (adjoin.powerBasis hx).trace_gen_eq_sum_roots] <;> rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;> try simp only [AdjoinSimple.algebraMap_gen _ _] exact hf #align intermediate_field.adjoin_simple.trace_gen_eq_sum_roots IntermediateField.AdjoinSimple.trace_gen_eq_sum_roots end IntermediateField.AdjoinSimple open IntermediateField variable (K) theorem trace_eq_trace_adjoin [FiniteDimensional K L] (x : L) : Algebra.trace K L x = finrank K⟮x⟯ L • trace K K⟮x⟯ (AdjoinSimple.gen K x) := by -- Porting note: `conv` was -- `conv in x => rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x]` -- and it was after the first `rw`. conv => lhs rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x] rw [← trace_trace (L := K⟮x⟯), trace_algebraMap, LinearMap.map_smul_of_tower] #align trace_eq_trace_adjoin trace_eq_trace_adjoin variable {K} theorem trace_eq_sum_roots [FiniteDimensional K L] {x : L} (hF : (minpoly K x).Splits (algebraMap K F)) : algebraMap K F (Algebra.trace K L x) = finrank K⟮x⟯ L • ((minpoly K x).aroots F).sum := by rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← Algebra.smul_def, IntermediateField.AdjoinSimple.trace_gen_eq_sum_roots _ hF, IsScalarTower.algebraMap_smul] #align trace_eq_sum_roots trace_eq_sum_roots end EqSumRoots variable {F : Type*} [Field F] variable [Algebra R L] [Algebra L F] [Algebra R F] [IsScalarTower R L F] open Polynomial attribute [-instance] Field.toEuclideanDomain theorem Algebra.isIntegral_trace [FiniteDimensional L F] {x : F} (hx : IsIntegral R x) : IsIntegral R (Algebra.trace L F x) := by have hx' : IsIntegral L x := hx.tower_top rw [← isIntegral_algebraMap_iff (algebraMap L (AlgebraicClosure F)).injective, trace_eq_sum_roots] · refine (IsIntegral.multiset_sum ?_).nsmul _ intro y hy rw [mem_roots_map (minpoly.ne_zero hx')] at hy use minpoly R x, minpoly.monic hx rw [← aeval_def] at hy ⊢ exact minpoly.aeval_of_isScalarTower R x y hy · apply IsAlgClosed.splits_codomain #align algebra.is_integral_trace Algebra.isIntegral_trace lemma Algebra.trace_eq_of_algEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] [Algebra A B] [Algebra A C] (e : B ≃ₐ[A] C) (x) : Algebra.trace A C (e x) = Algebra.trace A B x := by simp_rw [Algebra.trace_apply, ← LinearMap.trace_conj' _ e.toLinearEquiv] congr; ext; simp [LinearEquiv.conj_apply] lemma Algebra.trace_eq_of_ringEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] [Algebra A C] [Algebra B C] (e : A ≃+* B) (he : (algebraMap B C).comp e = algebraMap A C) (x) : e (Algebra.trace A C x) = Algebra.trace B C x := by classical by_cases h : ∃ s : Finset C, Nonempty (Basis s B C) · obtain ⟨s, ⟨b⟩⟩ := h letI : Algebra A B := RingHom.toAlgebra e letI : IsScalarTower A B C := IsScalarTower.of_algebraMap_eq' he.symm rw [Algebra.trace_eq_matrix_trace b, Algebra.trace_eq_matrix_trace (b.mapCoeffs e.symm (by simp [Algebra.smul_def, ← he]))] show e.toAddMonoidHom _ = _ rw [AddMonoidHom.map_trace] congr ext i j simp [leftMulMatrix_apply, LinearMap.toMatrix_apply] rw [trace_eq_zero_of_not_exists_basis _ h, trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply, LinearMap.zero_apply, map_zero] intro ⟨s, ⟨b⟩⟩ exact h ⟨s, ⟨b.mapCoeffs e (by simp [Algebra.smul_def, ← he])⟩⟩ lemma Algebra.trace_eq_of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [CommRing B₁] [CommRing A₂] [CommRing B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂) (he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁)) (x) : Algebra.trace A₁ B₁ x = e₁.symm (Algebra.trace A₂ B₂ (e₂ x)) := by letI := (RingHom.comp (e₂ : B₁ →+* B₂) (algebraMap A₁ B₁)).toAlgebra let e' : B₁ ≃ₐ[A₁] B₂ := { e₂ with commutes' := fun _ ↦ rfl } rw [← Algebra.trace_eq_of_ringEquiv e₁ he, ← Algebra.trace_eq_of_algEquiv e', RingEquiv.symm_apply_apply] rfl section EqSumEmbeddings variable [Algebra K F] [IsScalarTower K L F] open Algebra IntermediateField variable (F) (E : Type*) [Field E] [Algebra K E] theorem trace_eq_sum_embeddings_gen (pb : PowerBasis K L) (hE : (minpoly K pb.gen).Splits (algebraMap K E)) (hfx : (minpoly K pb.gen).Separable) : algebraMap K E (Algebra.trace K L pb.gen) = (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ => σ pb.gen := by letI := Classical.decEq E -- Porting note: the following `letI` was not needed. letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb rw [pb.trace_gen_eq_sum_roots hE, Fintype.sum_equiv pb.liftEquiv', Finset.sum_mem_multiset, Finset.sum_eq_multiset_sum, Multiset.toFinset_val, Multiset.dedup_eq_self.mpr _, Multiset.map_id] · exact nodup_roots ((separable_map _).mpr hfx) -- Porting note: the following goal does not exist in mathlib3. · exact (fun x => x.1) · intro x; rfl · intro σ rw [PowerBasis.liftEquiv'_apply_coe] #align trace_eq_sum_embeddings_gen trace_eq_sum_embeddings_gen variable [IsAlgClosed E] theorem sum_embeddings_eq_finrank_mul [FiniteDimensional K F] [IsSeparable K F] (pb : PowerBasis K L) : ∑ σ : F →ₐ[K] E, σ (algebraMap L F pb.gen) = finrank L F • (@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ : L →ₐ[K] E => σ pb.gen := by haveI : FiniteDimensional L F := FiniteDimensional.right K L F haveI : IsSeparable L F := isSeparable_tower_top_of_isSeparable K L F letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb letI : ∀ f : L →ₐ[K] E, Fintype (haveI := f.toRingHom.toAlgebra; AlgHom L F E) := ?_ · rw [Fintype.sum_equiv algHomEquivSigma (fun σ : F →ₐ[K] E => _) fun σ => σ.1 pb.gen, ← Finset.univ_sigma_univ, Finset.sum_sigma, ← Finset.sum_nsmul] · refine Finset.sum_congr rfl fun σ _ => ?_ letI : Algebra L E := σ.toRingHom.toAlgebra -- Porting note: `Finset.card_univ` was inside `simp only`. simp only [Finset.sum_const] congr rw [← AlgHom.card L F E] exact Finset.card_univ (α := F →ₐ[L] E) · intro σ simp only [algHomEquivSigma, Equiv.coe_fn_mk, AlgHom.restrictDomain, AlgHom.comp_apply, IsScalarTower.coe_toAlgHom'] #align sum_embeddings_eq_finrank_mul sum_embeddings_eq_finrank_mul theorem trace_eq_sum_embeddings [FiniteDimensional K L] [IsSeparable K L] {x : L} : algebraMap K E (Algebra.trace K L x) = ∑ σ : L →ₐ[K] E, σ x := by have hx := IsSeparable.isIntegral K x let pb := adjoin.powerBasis hx rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← adjoin.powerBasis_gen hx, trace_eq_sum_embeddings_gen E pb (IsAlgClosed.splits_codomain _)] -- Porting note: the following `convert` was `exact`, with `← algebra.smul_def, algebra_map_smul` -- in the previous `rw`. · convert (sum_embeddings_eq_finrank_mul L E pb).symm ext simp · haveI := isSeparable_tower_bot_of_isSeparable K K⟮x⟯ L exact IsSeparable.separable K _ #align trace_eq_sum_embeddings trace_eq_sum_embeddings theorem trace_eq_sum_automorphisms (x : L) [FiniteDimensional K L] [IsGalois K L] : algebraMap K L (Algebra.trace K L x) = ∑ σ : L ≃ₐ[K] L, σ x := by apply NoZeroSMulDivisors.algebraMap_injective L (AlgebraicClosure L) rw [_root_.map_sum (algebraMap L (AlgebraicClosure L))] rw [← Fintype.sum_equiv (Normal.algHomEquivAut K (AlgebraicClosure L) L)] · rw [← trace_eq_sum_embeddings (AlgebraicClosure L)] · simp only [algebraMap_eq_smul_one] -- Porting note: `smul_one_smul` was in the `simp only`. apply smul_one_smul · intro σ simp only [Normal.algHomEquivAut, AlgHom.restrictNormal', Equiv.coe_fn_mk, AlgEquiv.coe_ofBijective, AlgHom.restrictNormal_commutes, id.map_eq_id, RingHom.id_apply] #align trace_eq_sum_automorphisms trace_eq_sum_automorphisms end EqSumEmbeddings section DetNeZero namespace Algebra variable (A : Type u) {B : Type v} (C : Type z) variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C] open Finset /-- Given an `A`-algebra `B` and `b`, a `κ`-indexed family of elements of `B`, we define `traceMatrix A b` as the matrix whose `(i j)`-th element is the trace of `b i * b j`. -/ noncomputable def traceMatrix (b : κ → B) : Matrix κ κ A := of fun i j => traceForm A B (b i) (b j) #align algebra.trace_matrix Algebra.traceMatrix -- TODO: set as an equation lemma for `traceMatrix`, see mathlib4#3024 @[simp] theorem traceMatrix_apply (b : κ → B) (i j) : traceMatrix A b i j = traceForm A B (b i) (b j) := rfl #align algebra.trace_matrix_apply Algebra.traceMatrix_apply theorem traceMatrix_reindex {κ' : Type*} (b : Basis κ A B) (f : κ ≃ κ') : traceMatrix A (b.reindex f) = reindex f f (traceMatrix A b) := by ext (x y); simp #align algebra.trace_matrix_reindex Algebra.traceMatrix_reindex variable {A} theorem traceMatrix_of_matrix_vecMul [Fintype κ] (b : κ → B) (P : Matrix κ κ A) : traceMatrix A (b ᵥ* P.map (algebraMap A B)) = Pᵀ * traceMatrix A b * P := by ext (α β) rw [traceMatrix_apply, vecMul, dotProduct, vecMul, dotProduct, Matrix.mul_apply, BilinForm.sum_left, Fintype.sum_congr _ _ fun i : κ => BilinForm.sum_right _ _ (b i * P.map (algebraMap A B) i α) fun y : κ => b y * P.map (algebraMap A B) y β, sum_comm] congr; ext x rw [Matrix.mul_apply, sum_mul] congr; ext y rw [map_apply, traceForm_apply, mul_comm (b y), ← smul_def] simp only [id.smul_eq_mul, RingHom.id_apply, map_apply, transpose_apply, LinearMap.map_smulₛₗ, traceForm_apply, Algebra.smul_mul_assoc] rw [mul_comm (b x), ← smul_def] ring_nf rw [mul_assoc] simp [mul_comm] #align algebra.trace_matrix_of_matrix_vec_mul Algebra.traceMatrix_of_matrix_vecMul theorem traceMatrix_of_matrix_mulVec [Fintype κ] (b : κ → B) (P : Matrix κ κ A) : traceMatrix A (P.map (algebraMap A B) *ᵥ b) = P * traceMatrix A b * Pᵀ := by refine AddEquiv.injective (transposeAddEquiv κ κ A) ?_ rw [transposeAddEquiv_apply, transposeAddEquiv_apply, ← vecMul_transpose, ← transpose_map, traceMatrix_of_matrix_vecMul, transpose_transpose] #align algebra.trace_matrix_of_matrix_mul_vec Algebra.traceMatrix_of_matrix_mulVec theorem traceMatrix_of_basis [Fintype κ] [DecidableEq κ] (b : Basis κ A B) : traceMatrix A b = BilinForm.toMatrix b (traceForm A B) := by ext (i j) rw [traceMatrix_apply, traceForm_apply, traceForm_toMatrix] #align algebra.trace_matrix_of_basis Algebra.traceMatrix_of_basis theorem traceMatrix_of_basis_mulVec (b : Basis ι A B) (z : B) : traceMatrix A b *ᵥ b.equivFun z = fun i => trace A B (z * b i) := by ext i rw [← col_apply (traceMatrix A b *ᵥ b.equivFun z) i Unit.unit, col_mulVec, Matrix.mul_apply, traceMatrix] simp only [col_apply, traceForm_apply] conv_lhs => congr rfl ext rw [mul_comm _ (b.equivFun z _), ← smul_eq_mul, of_apply, ← LinearMap.map_smul] rw [← _root_.map_sum] congr conv_lhs => congr rfl ext rw [← mul_smul_comm] rw [← Finset.mul_sum, mul_comm z] congr rw [b.sum_equivFun] #align algebra.trace_matrix_of_basis_mul_vec Algebra.traceMatrix_of_basis_mulVec variable (A) /-- `embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose `(i, σ)` coefficient is `σ (b i)`. It is mostly useful for fields when `Fintype.card κ = finrank A B` and `C` is algebraically closed. -/ def embeddingsMatrix (b : κ → B) : Matrix κ (B →ₐ[A] C) C := of fun i (σ : B →ₐ[A] C) => σ (b i) #align algebra.embeddings_matrix Algebra.embeddingsMatrix -- TODO: set as an equation lemma for `embeddingsMatrix`, see mathlib4#3024 @[simp] theorem embeddingsMatrix_apply (b : κ → B) (i) (σ : B →ₐ[A] C) : embeddingsMatrix A C b i σ = σ (b i) := rfl #align algebra.embeddings_matrix_apply Algebra.embeddingsMatrix_apply /-- `embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)` coefficient is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ` given by a bijection `e : κ ≃ (B →ₐ[A] C)`. It is mostly useful for fields and `C` is algebraically closed. In this case, in presence of `h : Fintype.card κ = finrank A B`, one can take `e := equivOfCardEq ((AlgHom.card A B C).trans h.symm)`. -/ def embeddingsMatrixReindex (b : κ → B) (e : κ ≃ (B →ₐ[A] C)) := reindex (Equiv.refl κ) e.symm (embeddingsMatrix A C b) #align algebra.embeddings_matrix_reindex Algebra.embeddingsMatrixReindex variable {A} theorem embeddingsMatrixReindex_eq_vandermonde (pb : PowerBasis A B) (e : Fin pb.dim ≃ (B →ₐ[A] C)) : embeddingsMatrixReindex A C pb.basis e = (vandermonde fun i => e i pb.gen)ᵀ := by ext i j simp [embeddingsMatrixReindex, embeddingsMatrix] #align algebra.embeddings_matrix_reindex_eq_vandermonde Algebra.embeddingsMatrixReindex_eq_vandermonde section Field variable (K) (E : Type z) [Field E] variable [Algebra K E] variable [Module.Finite K L] [IsSeparable K L] [IsAlgClosed E] variable (b : κ → L) (pb : PowerBasis K L) theorem traceMatrix_eq_embeddingsMatrix_mul_trans : (traceMatrix K b).map (algebraMap K E) = embeddingsMatrix K E b * (embeddingsMatrix K E b)ᵀ := by ext (i j); simp [trace_eq_sum_embeddings, embeddingsMatrix, Matrix.mul_apply] #align algebra.trace_matrix_eq_embeddings_matrix_mul_trans Algebra.traceMatrix_eq_embeddingsMatrix_mul_trans theorem traceMatrix_eq_embeddingsMatrixReindex_mul_trans [Fintype κ] (e : κ ≃ (L →ₐ[K] E)) : (traceMatrix K b).map (algebraMap K E) = embeddingsMatrixReindex K E b e * (embeddingsMatrixReindex K E b e)ᵀ := by rw [traceMatrix_eq_embeddingsMatrix_mul_trans, embeddingsMatrixReindex, reindex_apply, transpose_submatrix, ← submatrix_mul_transpose_submatrix, ← Equiv.coe_refl, Equiv.refl_symm] #align algebra.trace_matrix_eq_embeddings_matrix_reindex_mul_trans Algebra.traceMatrix_eq_embeddingsMatrixReindex_mul_trans end Field end Algebra open Algebra variable (pb : PowerBasis K L) theorem det_traceMatrix_ne_zero' [IsSeparable K L] : det (traceMatrix K pb.basis) ≠ 0 := by suffices algebraMap K (AlgebraicClosure L) (det (traceMatrix K pb.basis)) ≠ 0 by refine mt (fun ht => ?_) this rw [ht, RingHom.map_zero] haveI : FiniteDimensional K L := pb.finite let e : Fin pb.dim ≃ (L →ₐ[K] AlgebraicClosure L) := (Fintype.equivFinOfCardEq ?_).symm · rw [RingHom.map_det, RingHom.mapMatrix_apply, traceMatrix_eq_embeddingsMatrixReindex_mul_trans K _ _ e, embeddingsMatrixReindex_eq_vandermonde, det_mul, det_transpose] refine mt mul_self_eq_zero.mp ?_ simp only [det_vandermonde, Finset.prod_eq_zero_iff, not_exists, sub_eq_zero] rintro i ⟨_, j, hij, h⟩ exact (Finset.mem_Ioi.mp hij).ne' (e.injective <| pb.algHom_ext h) · rw [AlgHom.card, pb.finrank] #align det_trace_matrix_ne_zero' det_traceMatrix_ne_zero' theorem det_traceForm_ne_zero [IsSeparable K L] [DecidableEq ι] (b : Basis ι K L) : det (BilinForm.toMatrix b (traceForm K L)) ≠ 0 := by haveI : FiniteDimensional K L := FiniteDimensional.of_fintype_basis b let pb : PowerBasis K L := Field.powerBasisOfFiniteOfSeparable _ _ rw [← BilinForm.toMatrix_mul_basis_toMatrix pb.basis b, ← det_comm' (pb.basis.toMatrix_mul_toMatrix_flip b) _, ← Matrix.mul_assoc, det_mul] swap; · apply Basis.toMatrix_mul_toMatrix_flip refine mul_ne_zero (isUnit_of_mul_eq_one _ ((b.toMatrix pb.basis)ᵀ * b.toMatrix pb.basis).det ?_).ne_zero ?_ · calc (pb.basis.toMatrix b * (pb.basis.toMatrix b)ᵀ).det * ((b.toMatrix pb.basis)ᵀ * b.toMatrix pb.basis).det = (pb.basis.toMatrix b * (b.toMatrix pb.basis * pb.basis.toMatrix b)ᵀ * b.toMatrix pb.basis).det := by simp only [← det_mul, Matrix.mul_assoc, Matrix.transpose_mul] _ = 1 := by simp only [Basis.toMatrix_mul_toMatrix_flip, Matrix.transpose_one, Matrix.mul_one, Matrix.det_one] simpa only [traceMatrix_of_basis] using det_traceMatrix_ne_zero' pb #align det_trace_form_ne_zero det_traceForm_ne_zero variable (K L) theorem traceForm_nondegenerate [FiniteDimensional K L] [IsSeparable K L] : (traceForm K L).Nondegenerate := BilinForm.nondegenerate_of_det_ne_zero (traceForm K L) _ (det_traceForm_ne_zero (FiniteDimensional.finBasis K L)) #align trace_form_nondegenerate traceForm_nondegenerate theorem Algebra.trace_ne_zero [FiniteDimensional K L] [IsSeparable K L] : Algebra.trace K L ≠ 0 := by intro e let pb : PowerBasis K L := Field.powerBasisOfFiniteOfSeparable _ _ apply det_traceMatrix_ne_zero' pb rw [show traceMatrix K pb.basis = 0 by ext; simp [e], Matrix.det_zero] rw [← pb.finrank, ← Fin.pos_iff_nonempty] exact finrank_pos
Mathlib/RingTheory/Trace.lean
641
646
theorem Algebra.trace_surjective [FiniteDimensional K L] [IsSeparable K L] : Function.Surjective (Algebra.trace K L) := by
rw [← LinearMap.range_eq_top] apply (IsSimpleOrder.eq_bot_or_eq_top (α := Ideal K) _).resolve_left rw [LinearMap.range_eq_bot] exact Algebra.trace_ne_zero K L
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kenny Lau -/ import Mathlib.Data.List.Forall2 #align_import data.list.zip from "leanprover-community/mathlib"@"134625f523e737f650a6ea7f0c82a6177e45e622" /-! # zip & unzip This file provides results about `List.zipWith`, `List.zip` and `List.unzip` (definitions are in core Lean). `zipWith f l₁ l₂` applies `f : α → β → γ` pointwise to a list `l₁ : List α` and `l₂ : List β`. It applies, until one of the lists is exhausted. For example, `zipWith f [0, 1, 2] [6.28, 31] = [f 0 6.28, f 1 31]`. `zip` is `zipWith` applied to `Prod.mk`. For example, `zip [a₁, a₂] [b₁, b₂, b₃] = [(a₁, b₁), (a₂, b₂)]`. `unzip` undoes `zip`. For example, `unzip [(a₁, b₁), (a₂, b₂)] = ([a₁, a₂], [b₁, b₂])`. -/ -- Make sure we don't import algebra assert_not_exists Monoid universe u open Nat namespace List variable {α : Type u} {β γ δ ε : Type*} #align list.zip_with_cons_cons List.zipWith_cons_cons #align list.zip_cons_cons List.zip_cons_cons #align list.zip_with_nil_left List.zipWith_nil_left #align list.zip_with_nil_right List.zipWith_nil_right #align list.zip_with_eq_nil_iff List.zipWith_eq_nil_iff #align list.zip_nil_left List.zip_nil_left #align list.zip_nil_right List.zip_nil_right @[simp] theorem zip_swap : ∀ (l₁ : List α) (l₂ : List β), (zip l₁ l₂).map Prod.swap = zip l₂ l₁ | [], l₂ => zip_nil_right.symm | l₁, [] => by rw [zip_nil_right]; rfl | a :: l₁, b :: l₂ => by simp only [zip_cons_cons, map_cons, zip_swap l₁ l₂, Prod.swap_prod_mk] #align list.zip_swap List.zip_swap #align list.length_zip_with List.length_zipWith #align list.length_zip List.length_zip theorem forall_zipWith {f : α → β → γ} {p : γ → Prop} : ∀ {l₁ : List α} {l₂ : List β}, length l₁ = length l₂ → (Forall p (zipWith f l₁ l₂) ↔ Forall₂ (fun x y => p (f x y)) l₁ l₂) | [], [], _ => by simp | a :: l₁, b :: l₂, h => by simp only [length_cons, succ_inj'] at h simp [forall_zipWith h] #align list.all₂_zip_with List.forall_zipWith theorem lt_length_left_of_zipWith {f : α → β → γ} {i : ℕ} {l : List α} {l' : List β} (h : i < (zipWith f l l').length) : i < l.length := by rw [length_zipWith] at h; omega #align list.lt_length_left_of_zip_with List.lt_length_left_of_zipWith theorem lt_length_right_of_zipWith {f : α → β → γ} {i : ℕ} {l : List α} {l' : List β} (h : i < (zipWith f l l').length) : i < l'.length := by rw [length_zipWith] at h; omega #align list.lt_length_right_of_zip_with List.lt_length_right_of_zipWith theorem lt_length_left_of_zip {i : ℕ} {l : List α} {l' : List β} (h : i < (zip l l').length) : i < l.length := lt_length_left_of_zipWith h #align list.lt_length_left_of_zip List.lt_length_left_of_zip theorem lt_length_right_of_zip {i : ℕ} {l : List α} {l' : List β} (h : i < (zip l l').length) : i < l'.length := lt_length_right_of_zipWith h #align list.lt_length_right_of_zip List.lt_length_right_of_zip #align list.zip_append List.zip_append #align list.zip_map List.zip_map #align list.zip_map_left List.zip_map_left #align list.zip_map_right List.zip_map_right #align list.zip_with_map List.zipWith_map #align list.zip_with_map_left List.zipWith_map_left #align list.zip_with_map_right List.zipWith_map_right #align list.zip_map' List.zip_map' #align list.map_zip_with List.map_zipWith theorem mem_zip {a b} : ∀ {l₁ : List α} {l₂ : List β}, (a, b) ∈ zip l₁ l₂ → a ∈ l₁ ∧ b ∈ l₂ | _ :: l₁, _ :: l₂, h => by cases' h with _ _ _ h · simp · have := mem_zip h exact ⟨Mem.tail _ this.1, Mem.tail _ this.2⟩ #align list.mem_zip List.mem_zip #align list.map_fst_zip List.map_fst_zip #align list.map_snd_zip List.map_snd_zip #align list.unzip_nil List.unzip_nil #align list.unzip_cons List.unzip_cons theorem unzip_eq_map : ∀ l : List (α × β), unzip l = (l.map Prod.fst, l.map Prod.snd) | [] => rfl | (a, b) :: l => by simp only [unzip_cons, map_cons, unzip_eq_map l] #align list.unzip_eq_map List.unzip_eq_map theorem unzip_left (l : List (α × β)) : (unzip l).1 = l.map Prod.fst := by simp only [unzip_eq_map] #align list.unzip_left List.unzip_left theorem unzip_right (l : List (α × β)) : (unzip l).2 = l.map Prod.snd := by simp only [unzip_eq_map] #align list.unzip_right List.unzip_right theorem unzip_swap (l : List (α × β)) : unzip (l.map Prod.swap) = (unzip l).swap := by simp only [unzip_eq_map, map_map] rfl #align list.unzip_swap List.unzip_swap theorem zip_unzip : ∀ l : List (α × β), zip (unzip l).1 (unzip l).2 = l | [] => rfl | (a, b) :: l => by simp only [unzip_cons, zip_cons_cons, zip_unzip l] #align list.zip_unzip List.zip_unzip theorem unzip_zip_left : ∀ {l₁ : List α} {l₂ : List β}, length l₁ ≤ length l₂ → (unzip (zip l₁ l₂)).1 = l₁ | [], l₂, _ => rfl | l₁, [], h => by rw [eq_nil_of_length_eq_zero (Nat.eq_zero_of_le_zero h)]; rfl | a :: l₁, b :: l₂, h => by simp only [zip_cons_cons, unzip_cons, unzip_zip_left (le_of_succ_le_succ h)] #align list.unzip_zip_left List.unzip_zip_left theorem unzip_zip_right {l₁ : List α} {l₂ : List β} (h : length l₂ ≤ length l₁) : (unzip (zip l₁ l₂)).2 = l₂ := by rw [← zip_swap, unzip_swap]; exact unzip_zip_left h #align list.unzip_zip_right List.unzip_zip_right theorem unzip_zip {l₁ : List α} {l₂ : List β} (h : length l₁ = length l₂) : unzip (zip l₁ l₂) = (l₁, l₂) := by rw [← Prod.mk.eta (p := unzip (zip l₁ l₂)), unzip_zip_left (le_of_eq h), unzip_zip_right (ge_of_eq h)] #align list.unzip_zip List.unzip_zip theorem zip_of_prod {l : List α} {l' : List β} {lp : List (α × β)} (hl : lp.map Prod.fst = l) (hr : lp.map Prod.snd = l') : lp = l.zip l' := by rw [← hl, ← hr, ← zip_unzip lp, ← unzip_left, ← unzip_right, zip_unzip, zip_unzip] #align list.zip_of_prod List.zip_of_prod theorem map_prod_left_eq_zip {l : List α} (f : α → β) : (l.map fun x => (x, f x)) = l.zip (l.map f) := by rw [← zip_map'] congr exact map_id _ #align list.map_prod_left_eq_zip List.map_prod_left_eq_zip theorem map_prod_right_eq_zip {l : List α} (f : α → β) : (l.map fun x => (f x, x)) = (l.map f).zip l := by rw [← zip_map'] congr exact map_id _ #align list.map_prod_right_eq_zip List.map_prod_right_eq_zip theorem zipWith_comm (f : α → β → γ) : ∀ (la : List α) (lb : List β), zipWith f la lb = zipWith (fun b a => f a b) lb la | [], _ => List.zipWith_nil_right.symm | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg _ (zipWith_comm f as bs) #align list.zip_with_comm List.zipWith_comm @[congr] theorem zipWith_congr (f g : α → β → γ) (la : List α) (lb : List β) (h : List.Forall₂ (fun a b => f a b = g a b) la lb) : zipWith f la lb = zipWith g la lb := by induction' h with a b as bs hfg _ ih · rfl · exact congr_arg₂ _ hfg ih #align list.zip_with_congr List.zipWith_congr theorem zipWith_comm_of_comm (f : α → α → β) (comm : ∀ x y : α, f x y = f y x) (l l' : List α) : zipWith f l l' = zipWith f l' l := by rw [zipWith_comm] simp only [comm] #align list.zip_with_comm_of_comm List.zipWith_comm_of_comm @[simp] theorem zipWith_same (f : α → α → δ) : ∀ l : List α, zipWith f l l = l.map fun a => f a a | [] => rfl | _ :: xs => congr_arg _ (zipWith_same f xs) #align list.zip_with_same List.zipWith_same theorem zipWith_zipWith_left (f : δ → γ → ε) (g : α → β → δ) : ∀ (la : List α) (lb : List β) (lc : List γ), zipWith f (zipWith g la lb) lc = zipWith3 (fun a b c => f (g a b) c) la lb lc | [], _, _ => rfl | _ :: _, [], _ => rfl | _ :: _, _ :: _, [] => rfl | _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_left f g as bs cs #align list.zip_with_zip_with_left List.zipWith_zipWith_left theorem zipWith_zipWith_right (f : α → δ → ε) (g : β → γ → δ) : ∀ (la : List α) (lb : List β) (lc : List γ), zipWith f la (zipWith g lb lc) = zipWith3 (fun a b c => f a (g b c)) la lb lc | [], _, _ => rfl | _ :: _, [], _ => rfl | _ :: _, _ :: _, [] => rfl | _ :: as, _ :: bs, _ :: cs => congr_arg (cons _) <| zipWith_zipWith_right f g as bs cs #align list.zip_with_zip_with_right List.zipWith_zipWith_right @[simp] theorem zipWith3_same_left (f : α → α → β → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la la lb = zipWith (fun a b => f a a b) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_left f as bs #align list.zip_with3_same_left List.zipWith3_same_left @[simp] theorem zipWith3_same_mid (f : α → β → α → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la lb la = zipWith (fun a b => f a b a) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_mid f as bs #align list.zip_with3_same_mid List.zipWith3_same_mid @[simp] theorem zipWith3_same_right (f : α → β → β → γ) : ∀ (la : List α) (lb : List β), zipWith3 f la lb lb = zipWith (fun a b => f a b b) la lb | [], _ => rfl | _ :: _, [] => rfl | _ :: as, _ :: bs => congr_arg (cons _) <| zipWith3_same_right f as bs #align list.zip_with3_same_right List.zipWith3_same_right instance (f : α → α → β) [IsSymmOp α β f] : IsSymmOp (List α) (List β) (zipWith f) := ⟨zipWith_comm_of_comm f IsSymmOp.symm_op⟩ @[simp] theorem length_revzip (l : List α) : length (revzip l) = length l := by simp only [revzip, length_zip, length_reverse, min_self] #align list.length_revzip List.length_revzip @[simp] theorem unzip_revzip (l : List α) : (revzip l).unzip = (l, l.reverse) := unzip_zip (length_reverse l).symm #align list.unzip_revzip List.unzip_revzip @[simp]
Mathlib/Data/List/Zip.lean
245
246
theorem revzip_map_fst (l : List α) : (revzip l).map Prod.fst = l := by
rw [← unzip_left, unzip_revzip]
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández -/ import Mathlib.Algebra.GradedMonoid import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.MvPolynomial.Basic #align_import ring_theory.mv_polynomial.weighted_homogeneous from "leanprover-community/mathlib"@"2f5b500a507264de86d666a5f87ddb976e2d8de4" /-! # Weighted homogeneous polynomials It is possible to assign weights (in a commutative additive monoid `M`) to the variables of a multivariate polynomial ring, so that monomials of the ring then have a weighted degree with respect to the weights of the variables. The weights are represented by a function `w : σ → M`, where `σ` are the indeterminates. A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m : M` if all monomials occurring in `φ` have the same weighted degree `m`. ## Main definitions/lemmas * `weightedTotalDegree' w φ` : the weighted total degree of a multivariate polynomial with respect to the weights `w`, taking values in `WithBot M`. * `weightedTotalDegree w φ` : When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. * `IsWeightedHomogeneous w φ m`: a predicate that asserts that `φ` is weighted homogeneous of weighted degree `m` with respect to the weights `w`. * `weightedHomogeneousSubmodule R w m`: the submodule of homogeneous polynomials of weighted degree `m`. * `weightedHomogeneousComponent w m`: the additive morphism that projects polynomials onto their summand that is weighted homogeneous of degree `n` with respect to `w`. * `sum_weightedHomogeneousComponent`: every polynomial is the sum of its weighted homogeneous components. -/ noncomputable section open Set Function Finset Finsupp AddMonoidAlgebra variable {R M : Type*} [CommSemiring R] namespace MvPolynomial variable {σ : Type*} section AddCommMonoid variable [AddCommMonoid M] /-! ### `weightedDegree` -/ /-- The `weightedDegree` of the finitely supported function `s : σ →₀ ℕ` is the sum `∑(s i)•(w i)`. -/ def weightedDegree (w : σ → M) : (σ →₀ ℕ) →+ M := (Finsupp.total σ M ℕ w).toAddMonoidHom #align mv_polynomial.weighted_degree' MvPolynomial.weightedDegree theorem weightedDegree_apply (w : σ → M) (f : σ →₀ ℕ): weightedDegree w f = Finsupp.sum f (fun i c => c • w i) := by rfl section SemilatticeSup variable [SemilatticeSup M] /-- The weighted total degree of a multivariate polynomial, taking values in `WithBot M`. -/ def weightedTotalDegree' (w : σ → M) (p : MvPolynomial σ R) : WithBot M := p.support.sup fun s => weightedDegree w s #align mv_polynomial.weighted_total_degree' MvPolynomial.weightedTotalDegree' /-- The `weightedTotalDegree'` of a polynomial `p` is `⊥` if and only if `p = 0`. -/ theorem weightedTotalDegree'_eq_bot_iff (w : σ → M) (p : MvPolynomial σ R) : weightedTotalDegree' w p = ⊥ ↔ p = 0 := by simp only [weightedTotalDegree', Finset.sup_eq_bot_iff, mem_support_iff, WithBot.coe_ne_bot, MvPolynomial.eq_zero_iff] exact forall_congr' fun _ => Classical.not_not #align mv_polynomial.weighted_total_degree'_eq_bot_iff MvPolynomial.weightedTotalDegree'_eq_bot_iff /-- The `weightedTotalDegree'` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree'_zero (w : σ → M) : weightedTotalDegree' w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree', support_zero, Finset.sup_empty] #align mv_polynomial.weighted_total_degree'_zero MvPolynomial.weightedTotalDegree'_zero section OrderBot variable [OrderBot M] /-- When `M` has a `⊥` element, we can define the weighted total degree of a multivariate polynomial as a function taking values in `M`. -/ def weightedTotalDegree (w : σ → M) (p : MvPolynomial σ R) : M := p.support.sup fun s => weightedDegree w s #align mv_polynomial.weighted_total_degree MvPolynomial.weightedTotalDegree /-- This lemma relates `weightedTotalDegree` and `weightedTotalDegree'`. -/ theorem weightedTotalDegree_coe (w : σ → M) (p : MvPolynomial σ R) (hp : p ≠ 0) : weightedTotalDegree' w p = ↑(weightedTotalDegree w p) := by rw [Ne, ← weightedTotalDegree'_eq_bot_iff w p, ← Ne, WithBot.ne_bot_iff_exists] at hp obtain ⟨m, hm⟩ := hp apply le_antisymm · simp only [weightedTotalDegree, weightedTotalDegree', Finset.sup_le_iff, WithBot.coe_le_coe] intro b exact Finset.le_sup · simp only [weightedTotalDegree] have hm' : weightedTotalDegree' w p ≤ m := le_of_eq hm.symm rw [← hm] simpa [weightedTotalDegree'] using hm' #align mv_polynomial.weighted_total_degree_coe MvPolynomial.weightedTotalDegree_coe /-- The `weightedTotalDegree` of the zero polynomial is `⊥`. -/ theorem weightedTotalDegree_zero (w : σ → M) : weightedTotalDegree w (0 : MvPolynomial σ R) = ⊥ := by simp only [weightedTotalDegree, support_zero, Finset.sup_empty] #align mv_polynomial.weighted_total_degree_zero MvPolynomial.weightedTotalDegree_zero theorem le_weightedTotalDegree (w : σ → M) {φ : MvPolynomial σ R} {d : σ →₀ ℕ} (hd : d ∈ φ.support) : weightedDegree w d ≤ φ.weightedTotalDegree w := le_sup hd #align mv_polynomial.le_weighted_total_degree MvPolynomial.le_weightedTotalDegree end OrderBot end SemilatticeSup /-- A multivariate polynomial `φ` is weighted homogeneous of weighted degree `m` if all monomials occurring in `φ` have weighted degree `m`. -/ def IsWeightedHomogeneous (w : σ → M) (φ : MvPolynomial σ R) (m : M) : Prop := ∀ ⦃d⦄, coeff d φ ≠ 0 → weightedDegree w d = m #align mv_polynomial.is_weighted_homogeneous MvPolynomial.IsWeightedHomogeneous variable (R) /-- The submodule of homogeneous `MvPolynomial`s of degree `n`. -/ def weightedHomogeneousSubmodule (w : σ → M) (m : M) : Submodule R (MvPolynomial σ R) where carrier := { x | x.IsWeightedHomogeneous w m } smul_mem' r a ha c hc := by rw [coeff_smul] at hc exact ha (right_ne_zero_of_mul hc) zero_mem' d hd := False.elim (hd <| coeff_zero _) add_mem' {a} {b} ha hb c hc := by rw [coeff_add] at hc obtain h | h : coeff c a ≠ 0 ∨ coeff c b ≠ 0 := by contrapose! hc simp only [hc, add_zero] · exact ha h · exact hb h #align mv_polynomial.weighted_homogeneous_submodule MvPolynomial.weightedHomogeneousSubmodule @[simp] theorem mem_weightedHomogeneousSubmodule (w : σ → M) (m : M) (p : MvPolynomial σ R) : p ∈ weightedHomogeneousSubmodule R w m ↔ p.IsWeightedHomogeneous w m := Iff.rfl #align mv_polynomial.mem_weighted_homogeneous_submodule MvPolynomial.mem_weightedHomogeneousSubmodule /-- The submodule `weightedHomogeneousSubmodule R w m` of homogeneous `MvPolynomial`s of degree `n` is equal to the `R`-submodule of all `p : (σ →₀ ℕ) →₀ R` such that `p.support ⊆ {d | weightedDegree w d = m}`. While equal, the former has a convenient definitional reduction. -/ theorem weightedHomogeneousSubmodule_eq_finsupp_supported (w : σ → M) (m : M) : weightedHomogeneousSubmodule R w m = Finsupp.supported R R { d | weightedDegree w d = m } := by ext x rw [mem_supported, Set.subset_def] simp only [Finsupp.mem_support_iff, mem_coe] rfl #align mv_polynomial.weighted_homogeneous_submodule_eq_finsupp_supported MvPolynomial.weightedHomogeneousSubmodule_eq_finsupp_supported variable {R} /-- The submodule generated by products `Pm * Pn` of weighted homogeneous polynomials of degrees `m` and `n` is contained in the submodule of weighted homogeneous polynomials of degree `m + n`. -/ theorem weightedHomogeneousSubmodule_mul (w : σ → M) (m n : M) : weightedHomogeneousSubmodule R w m * weightedHomogeneousSubmodule R w n ≤ weightedHomogeneousSubmodule R w (m + n) := by classical rw [Submodule.mul_le] intro φ hφ ψ hψ c hc rw [coeff_mul] at hc obtain ⟨⟨d, e⟩, hde, H⟩ := Finset.exists_ne_zero_of_sum_ne_zero hc have aux : coeff d φ ≠ 0 ∧ coeff e ψ ≠ 0 := by contrapose! H by_cases h : coeff d φ = 0 <;> simp_all only [Ne, not_false_iff, zero_mul, mul_zero] rw [← mem_antidiagonal.mp hde, ← hφ aux.1, ← hψ aux.2, map_add] #align mv_polynomial.weighted_homogeneous_submodule_mul MvPolynomial.weightedHomogeneousSubmodule_mul /-- Monomials are weighted homogeneous. -/
Mathlib/RingTheory/MvPolynomial/WeightedHomogeneous.lean
196
204
theorem isWeightedHomogeneous_monomial (w : σ → M) (d : σ →₀ ℕ) (r : R) {m : M} (hm : weightedDegree w d = m) : IsWeightedHomogeneous w (monomial d r) m := by
classical intro c hc rw [coeff_monomial] at hc split_ifs at hc with h · subst c exact hm · contradiction
/- Copyright (c) 2021 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.LinearAlgebra.Contraction #align_import linear_algebra.coevaluation from "leanprover-community/mathlib"@"d6814c584384ddf2825ff038e868451a7c956f31" /-! # The coevaluation map on finite dimensional vector spaces Given a finite dimensional vector space `V` over a field `K` this describes the canonical linear map from `K` to `V ⊗ Dual K V` which corresponds to the identity function on `V`. ## Tags coevaluation, dual module, tensor product ## Future work * Prove that this is independent of the choice of basis on `V`. -/ noncomputable section section coevaluation open TensorProduct FiniteDimensional open TensorProduct universe u v variable (K : Type u) [Field K] variable (V : Type v) [AddCommGroup V] [Module K V] [FiniteDimensional K V] /-- The coevaluation map is a linear map from a field `K` to a finite dimensional vector space `V`. -/ def coevaluation : K →ₗ[K] V ⊗[K] Module.Dual K V := let bV := Basis.ofVectorSpace K V (Basis.singleton Unit K).constr K fun _ => ∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i #align coevaluation coevaluation theorem coevaluation_apply_one : (coevaluation K V) (1 : K) = let bV := Basis.ofVectorSpace K V ∑ i : Basis.ofVectorSpaceIndex K V, bV i ⊗ₜ[K] bV.coord i := by simp only [coevaluation, id] rw [(Basis.singleton Unit K).constr_apply_fintype K] simp only [Fintype.univ_punit, Finset.sum_const, one_smul, Basis.singleton_repr, Basis.equivFun_apply, Basis.coe_ofVectorSpace, one_nsmul, Finset.card_singleton] #align coevaluation_apply_one coevaluation_apply_one open TensorProduct /-- This lemma corresponds to one of the coherence laws for duals in rigid categories, see `CategoryTheory.Monoidal.Rigid`. -/
Mathlib/LinearAlgebra/Coevaluation.lean
61
76
theorem contractLeft_assoc_coevaluation : (contractLeft K V).rTensor _ ∘ₗ (TensorProduct.assoc K _ _ _).symm.toLinearMap ∘ₗ (coevaluation K V).lTensor (Module.Dual K V) = (TensorProduct.lid K _).symm.toLinearMap ∘ₗ (TensorProduct.rid K _).toLinearMap := by
letI := Classical.decEq (Basis.ofVectorSpaceIndex K V) apply TensorProduct.ext apply (Basis.ofVectorSpace K V).dualBasis.ext; intro j; apply LinearMap.ext_ring rw [LinearMap.compr₂_apply, LinearMap.compr₂_apply, TensorProduct.mk_apply] simp only [LinearMap.coe_comp, Function.comp_apply, LinearEquiv.coe_toLinearMap] rw [rid_tmul, one_smul, lid_symm_apply] simp only [LinearEquiv.coe_toLinearMap, LinearMap.lTensor_tmul, coevaluation_apply_one] rw [TensorProduct.tmul_sum, map_sum]; simp only [assoc_symm_tmul] rw [map_sum]; simp only [LinearMap.rTensor_tmul, contractLeft_apply] simp only [Basis.coe_dualBasis, Basis.coord_apply, Basis.repr_self_apply, TensorProduct.ite_tmul] rw [Finset.sum_ite_eq']; simp only [Finset.mem_univ, if_true]
/- 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.Defs.Induced import Mathlib.Topology.Basic #align_import topology.order from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Ordering on topologies and (co)induced topologies Topologies on a fixed type `α` are ordered, by reverse inclusion. That is, for topologies `t₁` and `t₂` on `α`, we write `t₁ ≤ t₂` if every set open in `t₂` is also open in `t₁`. (One also calls `t₁` *finer* than `t₂`, and `t₂` *coarser* than `t₁`.) Any function `f : α → β` induces * `TopologicalSpace.induced f : TopologicalSpace β → TopologicalSpace α`; * `TopologicalSpace.coinduced f : TopologicalSpace α → TopologicalSpace β`. Continuity, the ordering on topologies and (co)induced topologies are related as follows: * The identity map `(α, t₁) → (α, t₂)` is continuous iff `t₁ ≤ t₂`. * A map `f : (α, t) → (β, u)` is continuous * iff `t ≤ TopologicalSpace.induced f u` (`continuous_iff_le_induced`) * iff `TopologicalSpace.coinduced f t ≤ u` (`continuous_iff_coinduced_le`). Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. For a function `f : α → β`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois connection between topologies on `α` and topologies on `β`. ## Implementation notes There is a Galois insertion between topologies on `α` (with the inclusion ordering) and all collections of sets in `α`. The complete lattice structure on topologies on `α` is defined as the reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding Galois coinsertion between topologies on `α` (with the reversed inclusion ordering) and collections of sets in `α` (with the reversed inclusion ordering). ## Tags finer, coarser, induced topology, coinduced topology -/ open Function Set Filter Topology universe u v w namespace TopologicalSpace variable {α : Type u} /-- The open sets of the least topology containing a collection of basic sets. -/ inductive GenerateOpen (g : Set (Set α)) : Set α → Prop | basic : ∀ s ∈ g, GenerateOpen g s | univ : GenerateOpen g univ | inter : ∀ s t, GenerateOpen g s → GenerateOpen g t → GenerateOpen g (s ∩ t) | sUnion : ∀ S : Set (Set α), (∀ s ∈ S, GenerateOpen g s) → GenerateOpen g (⋃₀ S) #align topological_space.generate_open TopologicalSpace.GenerateOpen /-- The smallest topological space containing the collection `g` of basic sets -/ def generateFrom (g : Set (Set α)) : TopologicalSpace α where IsOpen := GenerateOpen g isOpen_univ := GenerateOpen.univ isOpen_inter := GenerateOpen.inter isOpen_sUnion := GenerateOpen.sUnion #align topological_space.generate_from TopologicalSpace.generateFrom theorem isOpen_generateFrom_of_mem {g : Set (Set α)} {s : Set α} (hs : s ∈ g) : IsOpen[generateFrom g] s := GenerateOpen.basic s hs #align topological_space.is_open_generate_from_of_mem TopologicalSpace.isOpen_generateFrom_of_mem theorem nhds_generateFrom {g : Set (Set α)} {a : α} : @nhds α (generateFrom g) a = ⨅ s ∈ { s | a ∈ s ∧ s ∈ g }, 𝓟 s := by letI := generateFrom g rw [nhds_def] refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInf₂ ?_ rintro s ⟨ha, hs⟩ induction hs with | basic _ hs => exact iInf₂_le _ ⟨ha, hs⟩ | univ => exact le_top.trans_eq principal_univ.symm | inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal | sUnion _ _ hS => let ⟨t, htS, hat⟩ := ha exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS) #align topological_space.nhds_generate_from TopologicalSpace.nhds_generateFrom lemma tendsto_nhds_generateFrom_iff {β : Type*} {m : α → β} {f : Filter α} {g : Set (Set β)} {b : β} : Tendsto m f (@nhds β (generateFrom g) b) ↔ ∀ s ∈ g, b ∈ s → m ⁻¹' s ∈ f := by simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp, tendsto_principal]; rfl @[deprecated] alias ⟨_, tendsto_nhds_generateFrom⟩ := tendsto_nhds_generateFrom_iff #align topological_space.tendsto_nhds_generate_from TopologicalSpace.tendsto_nhds_generateFrom /-- Construct a topology on α given the filter of neighborhoods of each point of α. -/ protected def mkOfNhds (n : α → Filter α) : TopologicalSpace α where IsOpen s := ∀ a ∈ s, s ∈ n a isOpen_univ _ _ := univ_mem isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt) isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ => mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx) #align topological_space.mk_of_nhds TopologicalSpace.mkOfNhds theorem nhds_mkOfNhds_of_hasBasis {n : α → Filter α} {ι : α → Sort*} {p : ∀ a, ι a → Prop} {s : ∀ a, ι a → Set α} (hb : ∀ a, (n a).HasBasis (p a) (s a)) (hpure : ∀ a i, p a i → a ∈ s a i) (hopen : ∀ a i, p a i → ∀ᶠ x in n a, s a i ∈ n x) (a : α) : @nhds α (.mkOfNhds n) a = n a := by let t : TopologicalSpace α := .mkOfNhds n apply le_antisymm · intro U hU replace hpure : pure ≤ n := fun x ↦ (hb x).ge_iff.2 (hpure x) refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩ rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩ exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi · exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU theorem nhds_mkOfNhds (n : α → Filter α) (a : α) (h₀ : pure ≤ n) (h₁ : ∀ a, ∀ s ∈ n a, ∀ᶠ y in n a, s ∈ n y) : @nhds α (TopologicalSpace.mkOfNhds n) a = n a := nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) h₀ h₁ _ #align topological_space.nhds_mk_of_nhds TopologicalSpace.nhds_mkOfNhds theorem nhds_mkOfNhds_single [DecidableEq α] {a₀ : α} {l : Filter α} (h : pure a₀ ≤ l) (b : α) : @nhds α (TopologicalSpace.mkOfNhds (update pure a₀ l)) b = (update pure a₀ l : α → Filter α) b := by refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_ rcases eq_or_ne a a₀ with (rfl | ha) · filter_upwards [hs] with b hb rcases eq_or_ne b a with (rfl | hb) · exact hs · rwa [update_noteq hb] · simpa only [update_noteq ha, mem_pure, eventually_pure] using hs #align topological_space.nhds_mk_of_nhds_single TopologicalSpace.nhds_mkOfNhds_single theorem nhds_mkOfNhds_filterBasis (B : α → FilterBasis α) (a : α) (h₀ : ∀ x, ∀ n ∈ B x, x ∈ n) (h₁ : ∀ x, ∀ n ∈ B x, ∃ n₁ ∈ B x, ∀ x' ∈ n₁, ∃ n₂ ∈ B x', n₂ ⊆ n) : @nhds α (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter := nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) h₀ h₁ a #align topological_space.nhds_mk_of_nhds_filter_basis TopologicalSpace.nhds_mkOfNhds_filterBasis section Lattice variable {α : Type u} {β : Type v} /-- The ordering on topologies on the type `α`. `t ≤ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : PartialOrder (TopologicalSpace α) := { PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with le := fun s t => ∀ U, IsOpen[t] U → IsOpen[s] U } protected theorem le_def {α} {t s : TopologicalSpace α} : t ≤ s ↔ IsOpen[s] ≤ IsOpen[t] := Iff.rfl #align topological_space.le_def TopologicalSpace.le_def theorem le_generateFrom_iff_subset_isOpen {g : Set (Set α)} {t : TopologicalSpace α} : t ≤ generateFrom g ↔ g ⊆ { s | IsOpen[t] s } := ⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs => hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩ #align topological_space.le_generate_from_iff_subset_is_open TopologicalSpace.le_generateFrom_iff_subset_isOpen /-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a topology. -/ protected def mkOfClosure (s : Set (Set α)) (hs : { u | GenerateOpen s u } = s) : TopologicalSpace α where IsOpen u := u ∈ s isOpen_univ := hs ▸ TopologicalSpace.GenerateOpen.univ isOpen_inter := hs ▸ TopologicalSpace.GenerateOpen.inter isOpen_sUnion := hs ▸ TopologicalSpace.GenerateOpen.sUnion #align topological_space.mk_of_closure TopologicalSpace.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : { u | GenerateOpen s u } = s} : TopologicalSpace.mkOfClosure s hs = generateFrom s := TopologicalSpace.ext hs.symm #align topological_space.mk_of_closure_sets TopologicalSpace.mkOfClosure_sets theorem gc_generateFrom (α) : GaloisConnection (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) := fun _ _ => le_generateFrom_iff_subset_isOpen.symm /-- The Galois coinsertion between `TopologicalSpace α` and `(Set (Set α))ᵒᵈ` whose lower part sends a topology to its collection of open subsets, and whose upper part sends a collection of subsets of `α` to the topology they generate. -/ def gciGenerateFrom (α : Type*) : GaloisCoinsertion (fun t : TopologicalSpace α => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) where gc := gc_generateFrom α u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs choice g hg := TopologicalSpace.mkOfClosure g (Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align gi_generate_from TopologicalSpace.gciGenerateFrom /-- Topologies on `α` form a complete lattice, with `⊥` the discrete topology and `⊤` the indiscrete topology. The infimum of a collection of topologies is the topology generated by all their open sets, while the supremum is the topology whose open sets are those sets open in every member of the collection. -/ instance : CompleteLattice (TopologicalSpace α) := (gciGenerateFrom α).liftCompleteLattice @[mono] theorem generateFrom_anti {α} {g₁ g₂ : Set (Set α)} (h : g₁ ⊆ g₂) : generateFrom g₂ ≤ generateFrom g₁ := (gc_generateFrom _).monotone_u h #align topological_space.generate_from_anti TopologicalSpace.generateFrom_anti theorem generateFrom_setOf_isOpen (t : TopologicalSpace α) : generateFrom { s | IsOpen[t] s } = t := (gciGenerateFrom α).u_l_eq t #align topological_space.generate_from_set_of_is_open TopologicalSpace.generateFrom_setOf_isOpen theorem leftInverse_generateFrom : LeftInverse generateFrom fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).u_l_leftInverse #align topological_space.left_inverse_generate_from TopologicalSpace.leftInverse_generateFrom theorem generateFrom_surjective : Surjective (generateFrom : Set (Set α) → TopologicalSpace α) := (gciGenerateFrom α).u_surjective #align topological_space.generate_from_surjective TopologicalSpace.generateFrom_surjective theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace α => { s | IsOpen[t] s } := (gciGenerateFrom α).l_injective #align topological_space.set_of_is_open_injective TopologicalSpace.setOf_isOpen_injective end Lattice end TopologicalSpace section Lattice variable {α : Type*} {t t₁ t₂ : TopologicalSpace α} {s : Set α} theorem IsOpen.mono (hs : IsOpen[t₂] s) (h : t₁ ≤ t₂) : IsOpen[t₁] s := h s hs #align is_open.mono IsOpen.mono theorem IsClosed.mono (hs : IsClosed[t₂] s) (h : t₁ ≤ t₂) : IsClosed[t₁] s := (@isOpen_compl_iff α s t₁).mp <| hs.isOpen_compl.mono h #align is_closed.mono IsClosed.mono theorem closure.mono (h : t₁ ≤ t₂) : closure[t₁] s ⊆ closure[t₂] s := @closure_minimal _ s (@closure _ t₂ s) t₁ subset_closure (IsClosed.mono isClosed_closure h) theorem isOpen_implies_isOpen_iff : (∀ s, IsOpen[t₁] s → IsOpen[t₂] s) ↔ t₂ ≤ t₁ := Iff.rfl #align is_open_implies_is_open_iff isOpen_implies_isOpen_iff /-- The only open sets in the indiscrete topology are the empty set and the whole space. -/ theorem TopologicalSpace.isOpen_top_iff {α} (U : Set α) : IsOpen[⊤] U ↔ U = ∅ ∨ U = univ := ⟨fun h => by induction h with | basic _ h => exact False.elim h | univ => exact .inr rfl | inter _ _ _ _ h₁ h₂ => rcases h₁ with (rfl | rfl) <;> rcases h₂ with (rfl | rfl) <;> simp | sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by rintro (rfl | rfl) exacts [@isOpen_empty _ ⊤, @isOpen_univ _ ⊤]⟩ #align topological_space.is_open_top_iff TopologicalSpace.isOpen_top_iff /-- A topological space is discrete if every set is open, that is, its topology equals the discrete topology `⊥`. -/ class DiscreteTopology (α : Type*) [t : TopologicalSpace α] : Prop where /-- The `TopologicalSpace` structure on a type with discrete topology is equal to `⊥`. -/ eq_bot : t = ⊥ #align discrete_topology DiscreteTopology theorem discreteTopology_bot (α : Type*) : @DiscreteTopology α ⊥ := @DiscreteTopology.mk α ⊥ rfl #align discrete_topology_bot discreteTopology_bot section DiscreteTopology variable [TopologicalSpace α] [DiscreteTopology α] {β : Type*} @[simp] theorem isOpen_discrete (s : Set α) : IsOpen s := (@DiscreteTopology.eq_bot α _).symm ▸ trivial #align is_open_discrete isOpen_discrete @[simp] theorem isClosed_discrete (s : Set α) : IsClosed s := ⟨isOpen_discrete _⟩ #align is_closed_discrete isClosed_discrete @[simp] theorem closure_discrete (s : Set α) : closure s = s := (isClosed_discrete _).closure_eq @[simp] theorem dense_discrete {s : Set α} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq] @[simp] theorem denseRange_discrete {ι : Type*} {f : ι → α} : DenseRange f ↔ Surjective f := by rw [DenseRange, dense_discrete, range_iff_surjective] @[nontriviality, continuity] theorem continuous_of_discreteTopology [TopologicalSpace β] {f : α → β} : Continuous f := continuous_def.2 fun _ _ => isOpen_discrete _ #align continuous_of_discrete_topology continuous_of_discreteTopology /-- A function to a discrete topological space is continuous if and only if the preimage of every singleton is open. -/ theorem continuous_discrete_rng [TopologicalSpace β] [DiscreteTopology β] {f : α → β} : Continuous f ↔ ∀ b : β, IsOpen (f ⁻¹' {b}) := ⟨fun h b => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by rw [← biUnion_of_singleton s, preimage_iUnion₂] exact isOpen_biUnion fun _ _ => h _⟩⟩ @[simp] theorem nhds_discrete (α : Type*) [TopologicalSpace α] [DiscreteTopology α] : @nhds α _ = pure := le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds #align nhds_discrete nhds_discrete theorem mem_nhds_discrete {x : α} {s : Set α} : s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure] #align mem_nhds_discrete mem_nhds_discrete end DiscreteTopology theorem le_of_nhds_le_nhds (h : ∀ x, @nhds α t₁ x ≤ @nhds α t₂ x) : t₁ ≤ t₂ := fun s => by rw [@isOpen_iff_mem_nhds _ _ t₁, @isOpen_iff_mem_nhds α _ t₂] exact fun hs a ha => h _ (hs _ ha) #align le_of_nhds_le_nhds le_of_nhds_le_nhds @[deprecated (since := "2024-03-01")] alias eq_of_nhds_eq_nhds := TopologicalSpace.ext_nhds #align eq_of_nhds_eq_nhds TopologicalSpace.ext_nhds theorem eq_bot_of_singletons_open {t : TopologicalSpace α} (h : ∀ x, IsOpen[t] {x}) : t = ⊥ := bot_unique fun s _ => biUnion_of_singleton s ▸ isOpen_biUnion fun x _ => h x #align eq_bot_of_singletons_open eq_bot_of_singletons_open theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ s : Set X, IsOpen s) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩ #align forall_open_iff_discrete forall_open_iff_discrete theorem discreteTopology_iff_forall_isClosed [TopologicalSpace α] : DiscreteTopology α ↔ ∀ s : Set α, IsClosed s := forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦ isOpen_compl_iff theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] : (∀ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩ #align singletons_open_iff_discrete singletons_open_iff_discrete theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, {x} ∈ 𝓝 x := by simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq] #align discrete_topology_iff_singleton_mem_nhds discreteTopology_iff_singleton_mem_nhds /-- This lemma characterizes discrete topological spaces as those whose singletons are neighbourhoods. -/ theorem discreteTopology_iff_nhds [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝 x = pure x := by simp only [discreteTopology_iff_singleton_mem_nhds, ← nhds_neBot.le_pure_iff, le_pure_iff] #align discrete_topology_iff_nhds discreteTopology_iff_nhds theorem discreteTopology_iff_nhds_ne [TopologicalSpace α] : DiscreteTopology α ↔ ∀ x : α, 𝓝[≠] x = ⊥ := by simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl] #align discrete_topology_iff_nhds_ne discreteTopology_iff_nhds_ne /-- If the codomain of a continuous injective function has discrete topology, then so does the domain. See also `Embedding.discreteTopology` for an important special case. -/ theorem DiscreteTopology.of_continuous_injective {β : Type*} [TopologicalSpace α] [TopologicalSpace β] [DiscreteTopology β] {f : α → β} (hc : Continuous f) (hinj : Injective f) : DiscreteTopology α := forall_open_iff_discrete.1 fun s ↦ hinj.preimage_image s ▸ (isOpen_discrete _).preimage hc end Lattice section GaloisConnection variable {α β γ : Type*} theorem isOpen_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsOpen[t.induced f] s ↔ ∃ t, IsOpen t ∧ f ⁻¹' t = s := Iff.rfl #align is_open_induced_iff isOpen_induced_iff theorem isClosed_induced_iff [t : TopologicalSpace β] {s : Set α} {f : α → β} : IsClosed[t.induced f] s ↔ ∃ t, IsClosed t ∧ f ⁻¹' t = s := by letI := t.induced f simp only [← isOpen_compl_iff, isOpen_induced_iff] exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff]) #align is_closed_induced_iff isClosed_induced_iff theorem isOpen_coinduced {t : TopologicalSpace α} {s : Set β} {f : α → β} : IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) := Iff.rfl #align is_open_coinduced isOpen_coinduced theorem preimage_nhds_coinduced [TopologicalSpace α] {π : α → β} {s : Set β} {a : α} (hs : s ∈ @nhds β (TopologicalSpace.coinduced π ‹_›) (π a)) : π ⁻¹' s ∈ 𝓝 a := by letI := TopologicalSpace.coinduced π ‹_› rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩ exact mem_nhds_iff.mpr ⟨π ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩ #align preimage_nhds_coinduced preimage_nhds_coinduced variable {t t₁ t₂ : TopologicalSpace α} {t' : TopologicalSpace β} {f : α → β} {g : β → α} theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≤ t' := (@continuous_def α β t t').1 h #align continuous.coinduced_le Continuous.coinduced_le theorem coinduced_le_iff_le_induced {f : α → β} {tα : TopologicalSpace α} {tβ : TopologicalSpace β} : tα.coinduced f ≤ tβ ↔ tα ≤ tβ.induced f := ⟨fun h _s ⟨_t, ht, hst⟩ => hst ▸ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩ #align coinduced_le_iff_le_induced coinduced_le_iff_le_induced theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≤ t'.induced f := coinduced_le_iff_le_induced.1 h.coinduced_le #align continuous.le_induced Continuous.le_induced theorem gc_coinduced_induced (f : α → β) : GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ => coinduced_le_iff_le_induced #align gc_coinduced_induced gc_coinduced_induced theorem induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g := (gc_coinduced_induced g).monotone_u h #align induced_mono induced_mono theorem coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f := (gc_coinduced_induced f).monotone_l h #align coinduced_mono coinduced_mono @[simp] theorem induced_top : (⊤ : TopologicalSpace α).induced g = ⊤ := (gc_coinduced_induced g).u_top #align induced_top induced_top @[simp] theorem induced_inf : (t₁ ⊓ t₂).induced g = t₁.induced g ⊓ t₂.induced g := (gc_coinduced_induced g).u_inf #align induced_inf induced_inf @[simp] theorem induced_iInf {ι : Sort w} {t : ι → TopologicalSpace α} : (⨅ i, t i).induced g = ⨅ i, (t i).induced g := (gc_coinduced_induced g).u_iInf #align induced_infi induced_iInf @[simp] theorem coinduced_bot : (⊥ : TopologicalSpace α).coinduced f = ⊥ := (gc_coinduced_induced f).l_bot #align coinduced_bot coinduced_bot @[simp] theorem coinduced_sup : (t₁ ⊔ t₂).coinduced f = t₁.coinduced f ⊔ t₂.coinduced f := (gc_coinduced_induced f).l_sup #align coinduced_sup coinduced_sup @[simp] theorem coinduced_iSup {ι : Sort w} {t : ι → TopologicalSpace α} : (⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f := (gc_coinduced_induced f).l_iSup #align coinduced_supr coinduced_iSup theorem induced_id [t : TopologicalSpace α] : t.induced id = t := TopologicalSpace.ext <| funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h ▸ hs, fun hs => ⟨s, hs, rfl⟩⟩ #align induced_id induced_id theorem induced_compose {tγ : TopologicalSpace γ} {f : α → β} {g : β → γ} : (tγ.induced g).induced f = tγ.induced (g ∘ f) := TopologicalSpace.ext <| funext fun _ => propext ⟨fun ⟨_, ⟨s, hs, h₂⟩, h₁⟩ => h₁ ▸ h₂ ▸ ⟨s, hs, rfl⟩, fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h ▸ rfl⟩⟩ #align induced_compose induced_compose theorem induced_const [t : TopologicalSpace α] {x : α} : (t.induced fun _ : β => x) = ⊤ := le_antisymm le_top (@continuous_const β α ⊤ t x).le_induced #align induced_const induced_const theorem coinduced_id [t : TopologicalSpace α] : t.coinduced id = t := TopologicalSpace.ext rfl #align coinduced_id coinduced_id theorem coinduced_compose [tα : TopologicalSpace α] {f : α → β} {g : β → γ} : (tα.coinduced f).coinduced g = tα.coinduced (g ∘ f) := TopologicalSpace.ext rfl #align coinduced_compose coinduced_compose theorem Equiv.induced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by ext t U rw [isOpen_induced_iff, isOpen_coinduced] simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, ← preimage_equiv_eq_image_symm] #align equiv.induced_symm Equiv.induced_symm theorem Equiv.coinduced_symm {α β : Type*} (e : α ≃ β) : TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e := e.symm.induced_symm.symm #align equiv.coinduced_symm Equiv.coinduced_symm end GaloisConnection -- constructions using the complete lattice structure section Constructions open TopologicalSpace variable {α : Type u} {β : Type v} instance inhabitedTopologicalSpace {α : Type u} : Inhabited (TopologicalSpace α) := ⟨⊥⟩ #align inhabited_topological_space inhabitedTopologicalSpace instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton α] : Unique (TopologicalSpace α) where default := ⊥ uniq t := eq_bot_of_singletons_open fun x => Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set α) #align subsingleton.unique_topological_space Subsingleton.uniqueTopologicalSpace instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace α] [Subsingleton α] : DiscreteTopology α := ⟨Unique.eq_default t⟩ #align subsingleton.discrete_topology Subsingleton.discreteTopology instance : TopologicalSpace Empty := ⊥ instance : DiscreteTopology Empty := ⟨rfl⟩ instance : TopologicalSpace PEmpty := ⊥ instance : DiscreteTopology PEmpty := ⟨rfl⟩ instance : TopologicalSpace PUnit := ⊥ instance : DiscreteTopology PUnit := ⟨rfl⟩ instance : TopologicalSpace Bool := ⊥ instance : DiscreteTopology Bool := ⟨rfl⟩ instance : TopologicalSpace ℕ := ⊥ instance : DiscreteTopology ℕ := ⟨rfl⟩ instance : TopologicalSpace ℤ := ⊥ instance : DiscreteTopology ℤ := ⟨rfl⟩ instance {n} : TopologicalSpace (Fin n) := ⊥ instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩ instance sierpinskiSpace : TopologicalSpace Prop := generateFrom {{True}} #align sierpinski_space sierpinskiSpace theorem continuous_empty_function [TopologicalSpace α] [TopologicalSpace β] [IsEmpty β] (f : α → β) : Continuous f := letI := Function.isEmpty f continuous_of_discreteTopology #align continuous_empty_function continuous_empty_function theorem le_generateFrom {t : TopologicalSpace α} {g : Set (Set α)} (h : ∀ s ∈ g, IsOpen s) : t ≤ generateFrom g := le_generateFrom_iff_subset_isOpen.2 h #align le_generate_from le_generateFrom theorem induced_generateFrom_eq {α β} {b : Set (Set β)} {f : α → β} : (generateFrom b).induced f = generateFrom (preimage f '' b) := le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩) (coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs)) #align induced_generate_from_eq induced_generateFrom_eq theorem le_induced_generateFrom {α β} [t : TopologicalSpace α] {b : Set (Set β)} {f : α → β} (h : ∀ a : Set β, a ∈ b → IsOpen (f ⁻¹' a)) : t ≤ induced f (generateFrom b) := by rw [induced_generateFrom_eq] apply le_generateFrom simp only [mem_image, and_imp, forall_apply_eq_imp_iff₂, exists_imp] exact h #align le_induced_generate_from le_induced_generateFrom /-- This construction is left adjoint to the operation sending a topology on `α` to its neighborhood filter at a fixed point `a : α`. -/ def nhdsAdjoint (a : α) (f : Filter α) : TopologicalSpace α where IsOpen s := a ∈ s → s ∈ f isOpen_univ _ := univ_mem isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat) isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) #align nhds_adjoint nhdsAdjoint theorem gc_nhds (a : α) : GaloisConnection (nhdsAdjoint a) fun t => @nhds α t a := fun f t => by rw [le_nhds_iff] exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩ #align gc_nhds gc_nhds theorem nhds_mono {t₁ t₂ : TopologicalSpace α} {a : α} (h : t₁ ≤ t₂) : @nhds α t₁ a ≤ @nhds α t₂ a := (gc_nhds a).monotone_u h #align nhds_mono nhds_mono theorem le_iff_nhds {α : Type*} (t t' : TopologicalSpace α) : t ≤ t' ↔ ∀ x, @nhds α t x ≤ @nhds α t' x := ⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩ #align le_iff_nhds le_iff_nhds theorem isOpen_singleton_nhdsAdjoint {α : Type*} {a b : α} (f : Filter α) (hb : b ≠ a) : IsOpen[nhdsAdjoint a f] {b} := fun h ↦ absurd h hb.symm #align is_open_singleton_nhds_adjoint isOpen_singleton_nhdsAdjoint theorem nhds_nhdsAdjoint_same (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) a = pure a ⊔ f := by let _ := nhdsAdjoint a f apply le_antisymm · rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩ exact IsOpen.mem_nhds (fun _ ↦ htf) hat · exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f) @[deprecated (since := "2024-02-10")] alias nhdsAdjoint_nhds := nhds_nhdsAdjoint_same #align nhds_adjoint_nhds nhdsAdjoint_nhds theorem nhds_nhdsAdjoint_of_ne {a b : α} (f : Filter α) (h : b ≠ a) : @nhds α (nhdsAdjoint a f) b = pure b := let _ := nhdsAdjoint a f (isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h @[deprecated nhds_nhdsAdjoint_of_ne (since := "2024-02-10")] theorem nhdsAdjoint_nhds_of_ne (a : α) (f : Filter α) {b : α} (h : b ≠ a) : @nhds α (nhdsAdjoint a f) b = pure b := nhds_nhdsAdjoint_of_ne f h #align nhds_adjoint_nhds_of_ne nhdsAdjoint_nhds_of_ne theorem nhds_nhdsAdjoint [DecidableEq α] (a : α) (f : Filter α) : @nhds α (nhdsAdjoint a f) = update pure a (pure a ⊔ f) := eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩ theorem le_nhdsAdjoint_iff' {a : α} {f : Filter α} {t : TopologicalSpace α} : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, @nhds α t b = pure b := by classical simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).le_iff_eq] #align le_nhds_adjoint_iff' le_nhdsAdjoint_iff' theorem le_nhdsAdjoint_iff {α : Type*} (a : α) (f : Filter α) (t : TopologicalSpace α) : t ≤ nhdsAdjoint a f ↔ @nhds α t a ≤ pure a ⊔ f ∧ ∀ b ≠ a, IsOpen[t] {b} := by simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure α t] #align le_nhds_adjoint_iff le_nhdsAdjoint_iff theorem nhds_iInf {ι : Sort*} {t : ι → TopologicalSpace α} {a : α} : @nhds α (iInf t) a = ⨅ i, @nhds α (t i) a := (gc_nhds a).u_iInf #align nhds_infi nhds_iInf theorem nhds_sInf {s : Set (TopologicalSpace α)} {a : α} : @nhds α (sInf s) a = ⨅ t ∈ s, @nhds α t a := (gc_nhds a).u_sInf #align nhds_Inf nhds_sInf -- Porting note (#11215): TODO: timeouts without `b₁ := t₁` theorem nhds_inf {t₁ t₂ : TopologicalSpace α} {a : α} : @nhds α (t₁ ⊓ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a := (gc_nhds a).u_inf (b₁ := t₁) #align nhds_inf nhds_inf theorem nhds_top {a : α} : @nhds α ⊤ a = ⊤ := (gc_nhds a).u_top #align nhds_top nhds_top theorem isOpen_sup {t₁ t₂ : TopologicalSpace α} {s : Set α} : IsOpen[t₁ ⊔ t₂] s ↔ IsOpen[t₁] s ∧ IsOpen[t₂] s := Iff.rfl #align is_open_sup isOpen_sup open TopologicalSpace variable {γ : Type*} {f : α → β} {ι : Sort*} theorem continuous_iff_coinduced_le {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f ↔ coinduced f t₁ ≤ t₂ := continuous_def #align continuous_iff_coinduced_le continuous_iff_coinduced_le theorem continuous_iff_le_induced {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f ↔ t₁ ≤ induced f t₂ := Iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _) #align continuous_iff_le_induced continuous_iff_le_induced lemma continuous_generateFrom_iff {t : TopologicalSpace α} {b : Set (Set β)} : Continuous[t, generateFrom b] f ↔ ∀ s ∈ b, IsOpen (f ⁻¹' s) := by rw [continuous_iff_coinduced_le, le_generateFrom_iff_subset_isOpen] simp only [isOpen_coinduced, preimage_id', subset_def, mem_setOf] @[deprecated] alias ⟨_, continuous_generateFrom⟩ := continuous_generateFrom_iff #align continuous_generated_from continuous_generateFrom @[continuity] theorem continuous_induced_dom {t : TopologicalSpace β} : Continuous[induced f t, t] f := continuous_iff_le_induced.2 le_rfl #align continuous_induced_dom continuous_induced_dom theorem continuous_induced_rng {g : γ → α} {t₂ : TopologicalSpace β} {t₁ : TopologicalSpace γ} : Continuous[t₁, induced f t₂] g ↔ Continuous[t₁, t₂] (f ∘ g) := by simp only [continuous_iff_le_induced, induced_compose] #align continuous_induced_rng continuous_induced_rng theorem continuous_coinduced_rng {t : TopologicalSpace α} : Continuous[t, coinduced f t] f := continuous_iff_coinduced_le.2 le_rfl #align continuous_coinduced_rng continuous_coinduced_rng theorem continuous_coinduced_dom {g : β → γ} {t₁ : TopologicalSpace α} {t₂ : TopologicalSpace γ} : Continuous[coinduced f t₁, t₂] g ↔ Continuous[t₁, t₂] (g ∘ f) := by simp only [continuous_iff_coinduced_le, coinduced_compose] #align continuous_coinduced_dom continuous_coinduced_dom theorem continuous_le_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) (h₂ : Continuous[t₁, t₃] f) : Continuous[t₂, t₃] f := by rw [continuous_iff_le_induced] at h₂ ⊢ exact le_trans h₁ h₂ #align continuous_le_dom continuous_le_dom theorem continuous_le_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) (h₂ : Continuous[t₁, t₂] f) : Continuous[t₁, t₃] f := by rw [continuous_iff_coinduced_le] at h₂ ⊢ exact le_trans h₂ h₁ #align continuous_le_rng continuous_le_rng theorem continuous_sup_dom {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₁ ⊔ t₂, t₃] f ↔ Continuous[t₁, t₃] f ∧ Continuous[t₂, t₃] f := by simp only [continuous_iff_le_induced, sup_le_iff] #align continuous_sup_dom continuous_sup_dom theorem continuous_sup_rng_left {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} : Continuous[t₁, t₂] f → Continuous[t₁, t₂ ⊔ t₃] f := continuous_le_rng le_sup_left #align continuous_sup_rng_left continuous_sup_rng_left theorem continuous_sup_rng_right {t₁ : TopologicalSpace α} {t₃ t₂ : TopologicalSpace β} : Continuous[t₁, t₃] f → Continuous[t₁, t₂ ⊔ t₃] f := continuous_le_rng le_sup_right #align continuous_sup_rng_right continuous_sup_rng_right theorem continuous_sSup_dom {T : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} : Continuous[sSup T, t₂] f ↔ ∀ t ∈ T, Continuous[t, t₂] f := by simp only [continuous_iff_le_induced, sSup_le_iff] #align continuous_Sup_dom continuous_sSup_dom theorem continuous_sSup_rng {t₁ : TopologicalSpace α} {t₂ : Set (TopologicalSpace β)} {t : TopologicalSpace β} (h₁ : t ∈ t₂) (hf : Continuous[t₁, t] f) : Continuous[t₁, sSup t₂] f := continuous_iff_coinduced_le.2 <| le_sSup_of_le h₁ <| continuous_iff_coinduced_le.1 hf #align continuous_Sup_rng continuous_sSup_rng theorem continuous_iSup_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} : Continuous[iSup t₁, t₂] f ↔ ∀ i, Continuous[t₁ i, t₂] f := by simp only [continuous_iff_le_induced, iSup_le_iff] #align continuous_supr_dom continuous_iSup_dom theorem continuous_iSup_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} {i : ι} (h : Continuous[t₁, t₂ i] f) : Continuous[t₁, iSup t₂] f := continuous_sSup_rng ⟨i, rfl⟩ h #align continuous_supr_rng continuous_iSup_rng theorem continuous_inf_rng {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} : Continuous[t₁, t₂ ⊓ t₃] f ↔ Continuous[t₁, t₂] f ∧ Continuous[t₁, t₃] f := by simp only [continuous_iff_coinduced_le, le_inf_iff] #align continuous_inf_rng continuous_inf_rng theorem continuous_inf_dom_left {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₁, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f := continuous_le_dom inf_le_left #align continuous_inf_dom_left continuous_inf_dom_left theorem continuous_inf_dom_right {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} : Continuous[t₂, t₃] f → Continuous[t₁ ⊓ t₂, t₃] f := continuous_le_dom inf_le_right #align continuous_inf_dom_right continuous_inf_dom_right theorem continuous_sInf_dom {t₁ : Set (TopologicalSpace α)} {t₂ : TopologicalSpace β} {t : TopologicalSpace α} (h₁ : t ∈ t₁) : Continuous[t, t₂] f → Continuous[sInf t₁, t₂] f := continuous_le_dom <| sInf_le h₁ #align continuous_Inf_dom continuous_sInf_dom theorem continuous_sInf_rng {t₁ : TopologicalSpace α} {T : Set (TopologicalSpace β)} : Continuous[t₁, sInf T] f ↔ ∀ t ∈ T, Continuous[t₁, t] f := by simp only [continuous_iff_coinduced_le, le_sInf_iff] #align continuous_Inf_rng continuous_sInf_rng theorem continuous_iInf_dom {t₁ : ι → TopologicalSpace α} {t₂ : TopologicalSpace β} {i : ι} : Continuous[t₁ i, t₂] f → Continuous[iInf t₁, t₂] f := continuous_le_dom <| iInf_le _ _ #align continuous_infi_dom continuous_iInf_dom theorem continuous_iInf_rng {t₁ : TopologicalSpace α} {t₂ : ι → TopologicalSpace β} : Continuous[t₁, iInf t₂] f ↔ ∀ i, Continuous[t₁, t₂ i] f := by simp only [continuous_iff_coinduced_le, le_iInf_iff] #align continuous_infi_rng continuous_iInf_rng @[continuity] theorem continuous_bot {t : TopologicalSpace β} : Continuous[⊥, t] f := continuous_iff_le_induced.2 bot_le #align continuous_bot continuous_bot @[continuity] theorem continuous_top {t : TopologicalSpace α} : Continuous[t, ⊤] f := continuous_iff_coinduced_le.2 le_top #align continuous_top continuous_top theorem continuous_id_iff_le {t t' : TopologicalSpace α} : Continuous[t, t'] id ↔ t ≤ t' := @continuous_def _ _ t t' id #align continuous_id_iff_le continuous_id_iff_le theorem continuous_id_of_le {t t' : TopologicalSpace α} (h : t ≤ t') : Continuous[t, t'] id := continuous_id_iff_le.2 h #align continuous_id_of_le continuous_id_of_le -- 𝓝 in the induced topology theorem mem_nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) (s : Set β) : s ∈ @nhds β (TopologicalSpace.induced f T) a ↔ ∃ u ∈ 𝓝 (f a), f ⁻¹' u ⊆ s := by letI := T.induced f simp_rw [mem_nhds_iff, isOpen_induced_iff] constructor · rintro ⟨u, usub, ⟨v, openv, rfl⟩, au⟩ exact ⟨v, ⟨v, Subset.rfl, openv, au⟩, usub⟩ · rintro ⟨u, ⟨v, vsubu, openv, amem⟩, finvsub⟩ exact ⟨f ⁻¹' v, (Set.preimage_mono vsubu).trans finvsub, ⟨⟨v, openv, rfl⟩, amem⟩⟩ #align mem_nhds_induced mem_nhds_induced theorem nhds_induced [T : TopologicalSpace α] (f : β → α) (a : β) : @nhds β (TopologicalSpace.induced f T) a = comap f (𝓝 (f a)) := by ext s rw [mem_nhds_induced, mem_comap] #align nhds_induced nhds_induced theorem induced_iff_nhds_eq [tα : TopologicalSpace α] [tβ : TopologicalSpace β] (f : β → α) : tβ = tα.induced f ↔ ∀ b, 𝓝 b = comap f (𝓝 <| f b) := by simp only [ext_iff_nhds, nhds_induced] #align induced_iff_nhds_eq induced_iff_nhds_eq theorem map_nhds_induced_of_surjective [T : TopologicalSpace α] {f : β → α} (hf : Surjective f) (a : β) : map f (@nhds β (TopologicalSpace.induced f T) a) = 𝓝 (f a) := by rw [nhds_induced, map_comap_of_surjective hf] #align map_nhds_induced_of_surjective map_nhds_induced_of_surjective end Constructions section Induced open TopologicalSpace variable {α : Type*} {β : Type*} variable [t : TopologicalSpace β] {f : α → β} theorem isOpen_induced_eq {s : Set α} : IsOpen[induced f t] s ↔ s ∈ preimage f '' { s | IsOpen s } := Iff.rfl #align is_open_induced_eq isOpen_induced_eq theorem isOpen_induced {s : Set β} (h : IsOpen s) : IsOpen[induced f t] (f ⁻¹' s) := ⟨s, h, rfl⟩ #align is_open_induced isOpen_induced
Mathlib/Topology/Order.lean
859
860
theorem map_nhds_induced_eq (a : α) : map f (@nhds α (induced f t) a) = 𝓝[range f] f a := by
rw [nhds_induced, Filter.map_comap, nhdsWithin]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.CharP.Invertible import Mathlib.Algebra.Order.Interval.Set.Group import Mathlib.Analysis.Convex.Segment import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.FieldSimp #align_import analysis.convex.between from "leanprover-community/mathlib"@"571e13cacbed7bf042fd3058ce27157101433842" /-! # Betweenness in affine spaces This file defines notions of a point in an affine space being between two given points. ## Main definitions * `affineSegment R x y`: The segment of points weakly between `x` and `y`. * `Wbtw R x y z`: The point `y` is weakly between `x` and `z`. * `Sbtw R x y z`: The point `y` is strictly between `x` and `z`. -/ variable (R : Type*) {V V' P P' : Type*} open AffineEquiv AffineMap section OrderedRing variable [OrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The segment of points weakly between `x` and `y`. When convexity is refactored to support abstract affine combination spaces, this will no longer need to be a separate definition from `segment`. However, lemmas involving `+ᵥ` or `-ᵥ` will still be relevant after such a refactoring, as distinct from versions involving `+` or `-` in a module. -/ def affineSegment (x y : P) := lineMap x y '' Set.Icc (0 : R) 1 #align affine_segment affineSegment theorem affineSegment_eq_segment (x y : V) : affineSegment R x y = segment R x y := by rw [segment_eq_image_lineMap, affineSegment] #align affine_segment_eq_segment affineSegment_eq_segment theorem affineSegment_comm (x y : P) : affineSegment R x y = affineSegment R y x := by refine Set.ext fun z => ?_ constructor <;> · rintro ⟨t, ht, hxy⟩ refine ⟨1 - t, ?_, ?_⟩ · rwa [Set.sub_mem_Icc_iff_right, sub_self, sub_zero] · rwa [lineMap_apply_one_sub] #align affine_segment_comm affineSegment_comm theorem left_mem_affineSegment (x y : P) : x ∈ affineSegment R x y := ⟨0, Set.left_mem_Icc.2 zero_le_one, lineMap_apply_zero _ _⟩ #align left_mem_affine_segment left_mem_affineSegment theorem right_mem_affineSegment (x y : P) : y ∈ affineSegment R x y := ⟨1, Set.right_mem_Icc.2 zero_le_one, lineMap_apply_one _ _⟩ #align right_mem_affine_segment right_mem_affineSegment @[simp] theorem affineSegment_same (x : P) : affineSegment R x x = {x} := by -- Porting note: added as this doesn't do anything in `simp_rw` any more rw [affineSegment] -- Note: when adding "simp made no progress" in lean4#2336, -- had to change `lineMap_same` to `lineMap_same _`. Not sure why? -- Porting note: added `_ _` and `Function.const` simp_rw [lineMap_same _, AffineMap.coe_const _ _, Function.const, (Set.nonempty_Icc.mpr zero_le_one).image_const] #align affine_segment_same affineSegment_same variable {R} @[simp] theorem affineSegment_image (f : P →ᵃ[R] P') (x y : P) : f '' affineSegment R x y = affineSegment R (f x) (f y) := by rw [affineSegment, affineSegment, Set.image_image, ← comp_lineMap] rfl #align affine_segment_image affineSegment_image variable (R) @[simp] theorem affineSegment_const_vadd_image (x y : P) (v : V) : (v +ᵥ ·) '' affineSegment R x y = affineSegment R (v +ᵥ x) (v +ᵥ y) := affineSegment_image (AffineEquiv.constVAdd R P v : P →ᵃ[R] P) x y #align affine_segment_const_vadd_image affineSegment_const_vadd_image @[simp] theorem affineSegment_vadd_const_image (x y : V) (p : P) : (· +ᵥ p) '' affineSegment R x y = affineSegment R (x +ᵥ p) (y +ᵥ p) := affineSegment_image (AffineEquiv.vaddConst R p : V →ᵃ[R] P) x y #align affine_segment_vadd_const_image affineSegment_vadd_const_image @[simp] theorem affineSegment_const_vsub_image (x y p : P) : (p -ᵥ ·) '' affineSegment R x y = affineSegment R (p -ᵥ x) (p -ᵥ y) := affineSegment_image (AffineEquiv.constVSub R p : P →ᵃ[R] V) x y #align affine_segment_const_vsub_image affineSegment_const_vsub_image @[simp] theorem affineSegment_vsub_const_image (x y p : P) : (· -ᵥ p) '' affineSegment R x y = affineSegment R (x -ᵥ p) (y -ᵥ p) := affineSegment_image ((AffineEquiv.vaddConst R p).symm : P →ᵃ[R] V) x y #align affine_segment_vsub_const_image affineSegment_vsub_const_image variable {R} @[simp] theorem mem_const_vadd_affineSegment {x y z : P} (v : V) : v +ᵥ z ∈ affineSegment R (v +ᵥ x) (v +ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vadd_image, (AddAction.injective v).mem_set_image] #align mem_const_vadd_affine_segment mem_const_vadd_affineSegment @[simp] theorem mem_vadd_const_affineSegment {x y z : V} (p : P) : z +ᵥ p ∈ affineSegment R (x +ᵥ p) (y +ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vadd_const_image, (vadd_right_injective p).mem_set_image] #align mem_vadd_const_affine_segment mem_vadd_const_affineSegment @[simp] theorem mem_const_vsub_affineSegment {x y z : P} (p : P) : p -ᵥ z ∈ affineSegment R (p -ᵥ x) (p -ᵥ y) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_const_vsub_image, (vsub_right_injective p).mem_set_image] #align mem_const_vsub_affine_segment mem_const_vsub_affineSegment @[simp] theorem mem_vsub_const_affineSegment {x y z : P} (p : P) : z -ᵥ p ∈ affineSegment R (x -ᵥ p) (y -ᵥ p) ↔ z ∈ affineSegment R x y := by rw [← affineSegment_vsub_const_image, (vsub_left_injective p).mem_set_image] #align mem_vsub_const_affine_segment mem_vsub_const_affineSegment variable (R) /-- The point `y` is weakly between `x` and `z`. -/ def Wbtw (x y z : P) : Prop := y ∈ affineSegment R x z #align wbtw Wbtw /-- The point `y` is strictly between `x` and `z`. -/ def Sbtw (x y z : P) : Prop := Wbtw R x y z ∧ y ≠ x ∧ y ≠ z #align sbtw Sbtw variable {R} lemma mem_segment_iff_wbtw {x y z : V} : y ∈ segment R x z ↔ Wbtw R x y z := by rw [Wbtw, affineSegment_eq_segment] theorem Wbtw.map {x y z : P} (h : Wbtw R x y z) (f : P →ᵃ[R] P') : Wbtw R (f x) (f y) (f z) := by rw [Wbtw, ← affineSegment_image] exact Set.mem_image_of_mem _ h #align wbtw.map Wbtw.map theorem Function.Injective.wbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine ⟨fun h => ?_, fun h => h.map _⟩ rwa [Wbtw, ← affineSegment_image, hf.mem_set_image] at h #align function.injective.wbtw_map_iff Function.Injective.wbtw_map_iff theorem Function.Injective.sbtw_map_iff {x y z : P} {f : P →ᵃ[R] P'} (hf : Function.Injective f) : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by simp_rw [Sbtw, hf.wbtw_map_iff, hf.ne_iff] #align function.injective.sbtw_map_iff Function.Injective.sbtw_map_iff @[simp] theorem AffineEquiv.wbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Wbtw R (f x) (f y) (f z) ↔ Wbtw R x y z := by refine Function.Injective.wbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective #align affine_equiv.wbtw_map_iff AffineEquiv.wbtw_map_iff @[simp] theorem AffineEquiv.sbtw_map_iff {x y z : P} (f : P ≃ᵃ[R] P') : Sbtw R (f x) (f y) (f z) ↔ Sbtw R x y z := by refine Function.Injective.sbtw_map_iff (?_ : Function.Injective f.toAffineMap) exact f.injective #align affine_equiv.sbtw_map_iff AffineEquiv.sbtw_map_iff @[simp] theorem wbtw_const_vadd_iff {x y z : P} (v : V) : Wbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Wbtw R x y z := mem_const_vadd_affineSegment _ #align wbtw_const_vadd_iff wbtw_const_vadd_iff @[simp] theorem wbtw_vadd_const_iff {x y z : V} (p : P) : Wbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Wbtw R x y z := mem_vadd_const_affineSegment _ #align wbtw_vadd_const_iff wbtw_vadd_const_iff @[simp] theorem wbtw_const_vsub_iff {x y z : P} (p : P) : Wbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Wbtw R x y z := mem_const_vsub_affineSegment _ #align wbtw_const_vsub_iff wbtw_const_vsub_iff @[simp] theorem wbtw_vsub_const_iff {x y z : P} (p : P) : Wbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Wbtw R x y z := mem_vsub_const_affineSegment _ #align wbtw_vsub_const_iff wbtw_vsub_const_iff @[simp] theorem sbtw_const_vadd_iff {x y z : P} (v : V) : Sbtw R (v +ᵥ x) (v +ᵥ y) (v +ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vadd_iff, (AddAction.injective v).ne_iff, (AddAction.injective v).ne_iff] #align sbtw_const_vadd_iff sbtw_const_vadd_iff @[simp] theorem sbtw_vadd_const_iff {x y z : V} (p : P) : Sbtw R (x +ᵥ p) (y +ᵥ p) (z +ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vadd_const_iff, (vadd_right_injective p).ne_iff, (vadd_right_injective p).ne_iff] #align sbtw_vadd_const_iff sbtw_vadd_const_iff @[simp] theorem sbtw_const_vsub_iff {x y z : P} (p : P) : Sbtw R (p -ᵥ x) (p -ᵥ y) (p -ᵥ z) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_const_vsub_iff, (vsub_right_injective p).ne_iff, (vsub_right_injective p).ne_iff] #align sbtw_const_vsub_iff sbtw_const_vsub_iff @[simp] theorem sbtw_vsub_const_iff {x y z : P} (p : P) : Sbtw R (x -ᵥ p) (y -ᵥ p) (z -ᵥ p) ↔ Sbtw R x y z := by rw [Sbtw, Sbtw, wbtw_vsub_const_iff, (vsub_left_injective p).ne_iff, (vsub_left_injective p).ne_iff] #align sbtw_vsub_const_iff sbtw_vsub_const_iff theorem Sbtw.wbtw {x y z : P} (h : Sbtw R x y z) : Wbtw R x y z := h.1 #align sbtw.wbtw Sbtw.wbtw theorem Sbtw.ne_left {x y z : P} (h : Sbtw R x y z) : y ≠ x := h.2.1 #align sbtw.ne_left Sbtw.ne_left theorem Sbtw.left_ne {x y z : P} (h : Sbtw R x y z) : x ≠ y := h.2.1.symm #align sbtw.left_ne Sbtw.left_ne theorem Sbtw.ne_right {x y z : P} (h : Sbtw R x y z) : y ≠ z := h.2.2 #align sbtw.ne_right Sbtw.ne_right theorem Sbtw.right_ne {x y z : P} (h : Sbtw R x y z) : z ≠ y := h.2.2.symm #align sbtw.right_ne Sbtw.right_ne theorem Sbtw.mem_image_Ioo {x y z : P} (h : Sbtw R x y z) : y ∈ lineMap x z '' Set.Ioo (0 : R) 1 := by rcases h with ⟨⟨t, ht, rfl⟩, hyx, hyz⟩ rcases Set.eq_endpoints_or_mem_Ioo_of_mem_Icc ht with (rfl | rfl | ho) · exfalso exact hyx (lineMap_apply_zero _ _) · exfalso exact hyz (lineMap_apply_one _ _) · exact ⟨t, ho, rfl⟩ #align sbtw.mem_image_Ioo Sbtw.mem_image_Ioo theorem Wbtw.mem_affineSpan {x y z : P} (h : Wbtw R x y z) : y ∈ line[R, x, z] := by rcases h with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _ #align wbtw.mem_affine_span Wbtw.mem_affineSpan theorem wbtw_comm {x y z : P} : Wbtw R x y z ↔ Wbtw R z y x := by rw [Wbtw, Wbtw, affineSegment_comm] #align wbtw_comm wbtw_comm alias ⟨Wbtw.symm, _⟩ := wbtw_comm #align wbtw.symm Wbtw.symm theorem sbtw_comm {x y z : P} : Sbtw R x y z ↔ Sbtw R z y x := by rw [Sbtw, Sbtw, wbtw_comm, ← and_assoc, ← and_assoc, and_right_comm] #align sbtw_comm sbtw_comm alias ⟨Sbtw.symm, _⟩ := sbtw_comm #align sbtw.symm Sbtw.symm variable (R) @[simp] theorem wbtw_self_left (x y : P) : Wbtw R x x y := left_mem_affineSegment _ _ _ #align wbtw_self_left wbtw_self_left @[simp] theorem wbtw_self_right (x y : P) : Wbtw R x y y := right_mem_affineSegment _ _ _ #align wbtw_self_right wbtw_self_right @[simp] theorem wbtw_self_iff {x y : P} : Wbtw R x y x ↔ y = x := by refine ⟨fun h => ?_, fun h => ?_⟩ · -- Porting note: Originally `simpa [Wbtw, affineSegment] using h` have ⟨_, _, h₂⟩ := h rw [h₂.symm, lineMap_same_apply] · rw [h] exact wbtw_self_left R x x #align wbtw_self_iff wbtw_self_iff @[simp] theorem not_sbtw_self_left (x y : P) : ¬Sbtw R x x y := fun h => h.ne_left rfl #align not_sbtw_self_left not_sbtw_self_left @[simp] theorem not_sbtw_self_right (x y : P) : ¬Sbtw R x y y := fun h => h.ne_right rfl #align not_sbtw_self_right not_sbtw_self_right variable {R} theorem Wbtw.left_ne_right_of_ne_left {x y z : P} (h : Wbtw R x y z) (hne : y ≠ x) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h #align wbtw.left_ne_right_of_ne_left Wbtw.left_ne_right_of_ne_left theorem Wbtw.left_ne_right_of_ne_right {x y z : P} (h : Wbtw R x y z) (hne : y ≠ z) : x ≠ z := by rintro rfl rw [wbtw_self_iff] at h exact hne h #align wbtw.left_ne_right_of_ne_right Wbtw.left_ne_right_of_ne_right theorem Sbtw.left_ne_right {x y z : P} (h : Sbtw R x y z) : x ≠ z := h.wbtw.left_ne_right_of_ne_left h.2.1 #align sbtw.left_ne_right Sbtw.left_ne_right theorem sbtw_iff_mem_image_Ioo_and_ne [NoZeroSMulDivisors R V] {x y z : P} : Sbtw R x y z ↔ y ∈ lineMap x z '' Set.Ioo (0 : R) 1 ∧ x ≠ z := by refine ⟨fun h => ⟨h.mem_image_Ioo, h.left_ne_right⟩, fun h => ?_⟩ rcases h with ⟨⟨t, ht, rfl⟩, hxz⟩ refine ⟨⟨t, Set.mem_Icc_of_Ioo ht, rfl⟩, ?_⟩ rw [lineMap_apply, ← @vsub_ne_zero V, ← @vsub_ne_zero V _ _ _ _ z, vadd_vsub_assoc, vsub_self, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev z x, ← @neg_one_smul R, ← add_smul, ← sub_eq_add_neg] simp [smul_ne_zero, sub_eq_zero, ht.1.ne.symm, ht.2.ne, hxz.symm] #align sbtw_iff_mem_image_Ioo_and_ne sbtw_iff_mem_image_Ioo_and_ne variable (R) @[simp] theorem not_sbtw_self (x y : P) : ¬Sbtw R x y x := fun h => h.left_ne_right rfl #align not_sbtw_self not_sbtw_self theorem wbtw_swap_left_iff [NoZeroSMulDivisors R V] {x y : P} (z : P) : Wbtw R x y z ∧ Wbtw R y x z ↔ x = y := by constructor · rintro ⟨hxyz, hyxz⟩ rcases hxyz with ⟨ty, hty, rfl⟩ rcases hyxz with ⟨tx, htx, hx⟩ rw [lineMap_apply, lineMap_apply, ← add_vadd] at hx rw [← @vsub_eq_zero_iff_eq V, vadd_vsub, vsub_vadd_eq_vsub_sub, smul_sub, smul_smul, ← sub_smul, ← add_smul, smul_eq_zero] at hx rcases hx with (h | h) · nth_rw 1 [← mul_one tx] at h rw [← mul_sub, add_eq_zero_iff_neg_eq] at h have h' : ty = 0 := by refine le_antisymm ?_ hty.1 rw [← h, Left.neg_nonpos_iff] exact mul_nonneg htx.1 (sub_nonneg.2 hty.2) simp [h'] · rw [vsub_eq_zero_iff_eq] at h rw [h, lineMap_same_apply] · rintro rfl exact ⟨wbtw_self_left _ _ _, wbtw_self_left _ _ _⟩ #align wbtw_swap_left_iff wbtw_swap_left_iff theorem wbtw_swap_right_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R x z y ↔ y = z := by rw [wbtw_comm, wbtw_comm (z := y), eq_comm] exact wbtw_swap_left_iff R x #align wbtw_swap_right_iff wbtw_swap_right_iff theorem wbtw_rotate_iff [NoZeroSMulDivisors R V] (x : P) {y z : P} : Wbtw R x y z ∧ Wbtw R z x y ↔ x = y := by rw [wbtw_comm, wbtw_swap_right_iff, eq_comm] #align wbtw_rotate_iff wbtw_rotate_iff variable {R} theorem Wbtw.swap_left_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R y x z ↔ x = y := by rw [← wbtw_swap_left_iff R z, and_iff_right h] #align wbtw.swap_left_iff Wbtw.swap_left_iff theorem Wbtw.swap_right_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R x z y ↔ y = z := by rw [← wbtw_swap_right_iff R x, and_iff_right h] #align wbtw.swap_right_iff Wbtw.swap_right_iff theorem Wbtw.rotate_iff [NoZeroSMulDivisors R V] {x y z : P} (h : Wbtw R x y z) : Wbtw R z x y ↔ x = y := by rw [← wbtw_rotate_iff R x, and_iff_right h] #align wbtw.rotate_iff Wbtw.rotate_iff theorem Sbtw.not_swap_left [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R y x z := fun hs => h.left_ne (h.wbtw.swap_left_iff.1 hs) #align sbtw.not_swap_left Sbtw.not_swap_left theorem Sbtw.not_swap_right [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R x z y := fun hs => h.ne_right (h.wbtw.swap_right_iff.1 hs) #align sbtw.not_swap_right Sbtw.not_swap_right theorem Sbtw.not_rotate [NoZeroSMulDivisors R V] {x y z : P} (h : Sbtw R x y z) : ¬Wbtw R z x y := fun hs => h.left_ne (h.wbtw.rotate_iff.1 hs) #align sbtw.not_rotate Sbtw.not_rotate @[simp] theorem wbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Wbtw R x (lineMap x y r) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := by by_cases hxy : x = y · rw [hxy, lineMap_same_apply] simp rw [or_iff_right hxy, Wbtw, affineSegment, (lineMap_injective R hxy).mem_set_image] #align wbtw_line_map_iff wbtw_lineMap_iff @[simp] theorem sbtw_lineMap_iff [NoZeroSMulDivisors R V] {x y : P} {r : R} : Sbtw R x (lineMap x y r) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_iff_mem_image_Ioo_and_ne, and_comm, and_congr_right] intro hxy rw [(lineMap_injective R hxy).mem_set_image] #align sbtw_line_map_iff sbtw_lineMap_iff @[simp] theorem wbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Wbtw R x (r * (y - x) + x) y ↔ x = y ∨ r ∈ Set.Icc (0 : R) 1 := wbtw_lineMap_iff #align wbtw_mul_sub_add_iff wbtw_mul_sub_add_iff @[simp] theorem sbtw_mul_sub_add_iff [NoZeroDivisors R] {x y r : R} : Sbtw R x (r * (y - x) + x) y ↔ x ≠ y ∧ r ∈ Set.Ioo (0 : R) 1 := sbtw_lineMap_iff #align sbtw_mul_sub_add_iff sbtw_mul_sub_add_iff @[simp] theorem wbtw_zero_one_iff {x : R} : Wbtw R 0 x 1 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [Wbtw, affineSegment, Set.mem_image] simp_rw [lineMap_apply_ring] simp #align wbtw_zero_one_iff wbtw_zero_one_iff @[simp] theorem wbtw_one_zero_iff {x : R} : Wbtw R 1 x 0 ↔ x ∈ Set.Icc (0 : R) 1 := by rw [wbtw_comm, wbtw_zero_one_iff] #align wbtw_one_zero_iff wbtw_one_zero_iff @[simp] theorem sbtw_zero_one_iff {x : R} : Sbtw R 0 x 1 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [Sbtw, wbtw_zero_one_iff, Set.mem_Icc, Set.mem_Ioo] exact ⟨fun h => ⟨h.1.1.lt_of_ne (Ne.symm h.2.1), h.1.2.lt_of_ne h.2.2⟩, fun h => ⟨⟨h.1.le, h.2.le⟩, h.1.ne', h.2.ne⟩⟩ #align sbtw_zero_one_iff sbtw_zero_one_iff @[simp] theorem sbtw_one_zero_iff {x : R} : Sbtw R 1 x 0 ↔ x ∈ Set.Ioo (0 : R) 1 := by rw [sbtw_comm, sbtw_zero_one_iff] #align sbtw_one_zero_iff sbtw_one_zero_iff theorem Wbtw.trans_left {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) : Wbtw R w x z := by rcases h₁ with ⟨t₁, ht₁, rfl⟩ rcases h₂ with ⟨t₂, ht₂, rfl⟩ refine ⟨t₂ * t₁, ⟨mul_nonneg ht₂.1 ht₁.1, mul_le_one ht₂.2 ht₁.1 ht₁.2⟩, ?_⟩ rw [lineMap_apply, lineMap_apply, lineMap_vsub_left, smul_smul] #align wbtw.trans_left Wbtw.trans_left theorem Wbtw.trans_right {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) : Wbtw R w y z := by rw [wbtw_comm] at * exact h₁.trans_left h₂ #align wbtw.trans_right Wbtw.trans_right theorem Wbtw.trans_sbtw_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := by refine ⟨h₁.trans_left h₂.wbtw, h₂.ne_left, ?_⟩ rintro rfl exact h₂.right_ne ((wbtw_swap_right_iff R w).1 ⟨h₁, h₂.wbtw⟩) #align wbtw.trans_sbtw_left Wbtw.trans_sbtw_left theorem Wbtw.trans_sbtw_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := by rw [wbtw_comm] at * rw [sbtw_comm] at * exact h₁.trans_sbtw_left h₂ #align wbtw.trans_sbtw_right Wbtw.trans_sbtw_right theorem Sbtw.trans_left [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Sbtw R w x y) : Sbtw R w x z := h₁.wbtw.trans_sbtw_left h₂ #align sbtw.trans_left Sbtw.trans_left theorem Sbtw.trans_right [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Sbtw R x y z) : Sbtw R w y z := h₁.wbtw.trans_sbtw_right h₂ #align sbtw.trans_right Sbtw.trans_right theorem Wbtw.trans_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w y z) (h₂ : Wbtw R w x y) (h : y ≠ z) : x ≠ z := by rintro rfl exact h (h₁.swap_right_iff.1 h₂) #align wbtw.trans_left_ne Wbtw.trans_left_ne theorem Wbtw.trans_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Wbtw R w x z) (h₂ : Wbtw R x y z) (h : w ≠ x) : w ≠ y := by rintro rfl exact h (h₁.swap_left_iff.1 h₂) #align wbtw.trans_right_ne Wbtw.trans_right_ne theorem Sbtw.trans_wbtw_left_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w y z) (h₂ : Wbtw R w x y) : x ≠ z := h₁.wbtw.trans_left_ne h₂ h₁.ne_right #align sbtw.trans_wbtw_left_ne Sbtw.trans_wbtw_left_ne theorem Sbtw.trans_wbtw_right_ne [NoZeroSMulDivisors R V] {w x y z : P} (h₁ : Sbtw R w x z) (h₂ : Wbtw R x y z) : w ≠ y := h₁.wbtw.trans_right_ne h₂ h₁.left_ne #align sbtw.trans_wbtw_right_ne Sbtw.trans_wbtw_right_ne theorem Sbtw.affineCombination_of_mem_affineSpan_pair [NoZeroDivisors R] [NoZeroSMulDivisors R V] {ι : Type*} {p : ι → P} (ha : AffineIndependent R p) {w w₁ w₂ : ι → R} {s : Finset ι} (hw : ∑ i ∈ s, w i = 1) (hw₁ : ∑ i ∈ s, w₁ i = 1) (hw₂ : ∑ i ∈ s, w₂ i = 1) (h : s.affineCombination R p w ∈ line[R, s.affineCombination R p w₁, s.affineCombination R p w₂]) {i : ι} (his : i ∈ s) (hs : Sbtw R (w₁ i) (w i) (w₂ i)) : Sbtw R (s.affineCombination R p w₁) (s.affineCombination R p w) (s.affineCombination R p w₂) := by rw [affineCombination_mem_affineSpan_pair ha hw hw₁ hw₂] at h rcases h with ⟨r, hr⟩ rw [hr i his, sbtw_mul_sub_add_iff] at hs change ∀ i ∈ s, w i = (r • (w₂ - w₁) + w₁) i at hr rw [s.affineCombination_congr hr fun _ _ => rfl] rw [← s.weightedVSub_vadd_affineCombination, s.weightedVSub_const_smul, ← s.affineCombination_vsub, ← lineMap_apply, sbtw_lineMap_iff, and_iff_left hs.2, ← @vsub_ne_zero V, s.affineCombination_vsub] intro hz have hw₁w₂ : (∑ i ∈ s, (w₁ - w₂) i) = 0 := by simp_rw [Pi.sub_apply, Finset.sum_sub_distrib, hw₁, hw₂, sub_self] refine hs.1 ?_ have ha' := ha s (w₁ - w₂) hw₁w₂ hz i his rwa [Pi.sub_apply, sub_eq_zero] at ha' #align sbtw.affine_combination_of_mem_affine_span_pair Sbtw.affineCombination_of_mem_affineSpan_pair end OrderedRing section StrictOrderedCommRing variable [StrictOrderedCommRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} theorem Wbtw.sameRay_vsub {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ y) := by rcases h with ⟨t, ⟨ht0, ht1⟩, rfl⟩ simp_rw [lineMap_apply] rcases ht0.lt_or_eq with (ht0' | rfl); swap; · simp rcases ht1.lt_or_eq with (ht1' | rfl); swap; · simp refine Or.inr (Or.inr ⟨1 - t, t, sub_pos.2 ht1', ht0', ?_⟩) simp only [vadd_vsub, smul_smul, vsub_vadd_eq_vsub_sub, smul_sub, ← sub_smul] ring_nf #align wbtw.same_ray_vsub Wbtw.sameRay_vsub theorem Wbtw.sameRay_vsub_left {x y z : P} (h : Wbtw R x y z) : SameRay R (y -ᵥ x) (z -ᵥ x) := by rcases h with ⟨t, ⟨ht0, _⟩, rfl⟩ simpa [lineMap_apply] using SameRay.sameRay_nonneg_smul_left (z -ᵥ x) ht0 #align wbtw.same_ray_vsub_left Wbtw.sameRay_vsub_left theorem Wbtw.sameRay_vsub_right {x y z : P} (h : Wbtw R x y z) : SameRay R (z -ᵥ x) (z -ᵥ y) := by rcases h with ⟨t, ⟨_, ht1⟩, rfl⟩ simpa [lineMap_apply, vsub_vadd_eq_vsub_sub, sub_smul] using SameRay.sameRay_nonneg_smul_right (z -ᵥ x) (sub_nonneg.2 ht1) #align wbtw.same_ray_vsub_right Wbtw.sameRay_vsub_right end StrictOrderedCommRing section LinearOrderedRing variable [LinearOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} /-- Suppose lines from two vertices of a triangle to interior points of the opposite side meet at `p`. Then `p` lies in the interior of the first (and by symmetry the other) segment from a vertex to the point on the opposite side. -/ theorem sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair [NoZeroSMulDivisors R V] {t : Affine.Triangle R P} {i₁ i₂ i₃ : Fin 3} (h₁₂ : i₁ ≠ i₂) {p₁ p₂ p : P} (h₁ : Sbtw R (t.points i₂) p₁ (t.points i₃)) (h₂ : Sbtw R (t.points i₁) p₂ (t.points i₃)) (h₁' : p ∈ line[R, t.points i₁, p₁]) (h₂' : p ∈ line[R, t.points i₂, p₂]) : Sbtw R (t.points i₁) p p₁ := by -- Should not be needed; see comments on local instances in `Data.Sign`. letI : DecidableRel ((· < ·) : R → R → Prop) := LinearOrderedRing.decidableLT have h₁₃ : i₁ ≠ i₃ := by rintro rfl simp at h₂ have h₂₃ : i₂ ≠ i₃ := by rintro rfl simp at h₁ have h3 : ∀ i : Fin 3, i = i₁ ∨ i = i₂ ∨ i = i₃ := by clear h₁ h₂ h₁' h₂' -- Porting note: Originally `decide!` intro i fin_cases i <;> fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp at h₁₂ h₁₃ h₂₃ ⊢ have hu : (Finset.univ : Finset (Fin 3)) = {i₁, i₂, i₃} := by clear h₁ h₂ h₁' h₂' -- Porting note: Originally `decide!` fin_cases i₁ <;> fin_cases i₂ <;> fin_cases i₃ <;> simp (config := {decide := true}) at h₁₂ h₁₃ h₂₃ ⊢ have hp : p ∈ affineSpan R (Set.range t.points) := by have hle : line[R, t.points i₁, p₁] ≤ affineSpan R (Set.range t.points) := by refine affineSpan_pair_le_of_mem_of_mem (mem_affineSpan R (Set.mem_range_self _)) ?_ have hle : line[R, t.points i₂, t.points i₃] ≤ affineSpan R (Set.range t.points) := by refine affineSpan_mono R ?_ simp [Set.insert_subset_iff] rw [AffineSubspace.le_def'] at hle exact hle _ h₁.wbtw.mem_affineSpan rw [AffineSubspace.le_def'] at hle exact hle _ h₁' have h₁i := h₁.mem_image_Ioo have h₂i := h₂.mem_image_Ioo rw [Set.mem_image] at h₁i h₂i rcases h₁i with ⟨r₁, ⟨hr₁0, hr₁1⟩, rfl⟩ rcases h₂i with ⟨r₂, ⟨hr₂0, hr₂1⟩, rfl⟩ rcases eq_affineCombination_of_mem_affineSpan_of_fintype hp with ⟨w, hw, rfl⟩ have h₁s := sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _) (Finset.mem_univ _) (Finset.mem_univ _) h₁₂ h₁₃ h₂₃ hr₁0 hr₁1 h₁' have h₂s := sign_eq_of_affineCombination_mem_affineSpan_single_lineMap t.independent hw (Finset.mem_univ _) (Finset.mem_univ _) (Finset.mem_univ _) h₁₂.symm h₂₃ h₁₃ hr₂0 hr₂1 h₂' rw [← Finset.univ.affineCombination_affineCombinationSingleWeights R t.points (Finset.mem_univ i₁), ← Finset.univ.affineCombination_affineCombinationLineMapWeights t.points (Finset.mem_univ _) (Finset.mem_univ _)] at h₁' ⊢ refine Sbtw.affineCombination_of_mem_affineSpan_pair t.independent hw (Finset.univ.sum_affineCombinationSingleWeights R (Finset.mem_univ _)) (Finset.univ.sum_affineCombinationLineMapWeights (Finset.mem_univ _) (Finset.mem_univ _) _) h₁' (Finset.mem_univ i₁) ?_ rw [Finset.affineCombinationSingleWeights_apply_self, Finset.affineCombinationLineMapWeights_apply_of_ne h₁₂ h₁₃, sbtw_one_zero_iff] have hs : ∀ i : Fin 3, SignType.sign (w i) = SignType.sign (w i₃) := by intro i rcases h3 i with (rfl | rfl | rfl) · exact h₂s · exact h₁s · rfl have hss : SignType.sign (∑ i, w i) = 1 := by simp [hw] have hs' := sign_sum Finset.univ_nonempty (SignType.sign (w i₃)) fun i _ => hs i rw [hs'] at hss simp_rw [hss, sign_eq_one_iff] at hs refine ⟨hs i₁, ?_⟩ rw [hu] at hw rw [Finset.sum_insert, Finset.sum_insert, Finset.sum_singleton] at hw · by_contra hle rw [not_lt] at hle exact (hle.trans_lt (lt_add_of_pos_right _ (Left.add_pos (hs i₂) (hs i₃)))).ne' hw · simpa using h₂₃ · simpa [not_or] using ⟨h₁₂, h₁₃⟩ #align sbtw_of_sbtw_of_sbtw_of_mem_affine_span_pair sbtw_of_sbtw_of_sbtw_of_mem_affineSpan_pair end LinearOrderedRing section LinearOrderedField variable [LinearOrderedField R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable {R} theorem wbtw_iff_left_eq_or_right_mem_image_Ici {x y z : P} : Wbtw R x y z ↔ x = y ∨ z ∈ lineMap x y '' Set.Ici (1 : R) := by refine ⟨fun h => ?_, fun h => ?_⟩ · rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩ rcases hr0.lt_or_eq with (hr0' | rfl) · rw [Set.mem_image] refine Or.inr ⟨r⁻¹, one_le_inv hr0' hr1, ?_⟩ simp only [lineMap_apply, smul_smul, vadd_vsub] rw [inv_mul_cancel hr0'.ne', one_smul, vsub_vadd] · simp · rcases h with (rfl | ⟨r, ⟨hr, rfl⟩⟩) · exact wbtw_self_left _ _ _ · rw [Set.mem_Ici] at hr refine ⟨r⁻¹, ⟨inv_nonneg.2 (zero_le_one.trans hr), inv_le_one hr⟩, ?_⟩ simp only [lineMap_apply, smul_smul, vadd_vsub] rw [inv_mul_cancel (one_pos.trans_le hr).ne', one_smul, vsub_vadd] #align wbtw_iff_left_eq_or_right_mem_image_Ici wbtw_iff_left_eq_or_right_mem_image_Ici theorem Wbtw.right_mem_image_Ici_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) : z ∈ lineMap x y '' Set.Ici (1 : R) := (wbtw_iff_left_eq_or_right_mem_image_Ici.1 h).resolve_left hne #align wbtw.right_mem_image_Ici_of_left_ne Wbtw.right_mem_image_Ici_of_left_ne
Mathlib/Analysis/Convex/Between.lean
693
696
theorem Wbtw.right_mem_affineSpan_of_left_ne {x y z : P} (h : Wbtw R x y z) (hne : x ≠ y) : z ∈ line[R, x, y] := by
rcases h.right_mem_image_Ici_of_left_ne hne with ⟨r, ⟨-, rfl⟩⟩ exact lineMap_mem_affineSpan_pair _ _ _
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Order.SupIndep import Mathlib.Order.Atoms #align_import order.partition.finpartition from "leanprover-community/mathlib"@"d6fad0e5bf2d6f48da9175d25c3dc5706b3834ce" /-! # Finite partitions In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise disjoint parts `parts : Finset α` which does not contain `⊥` and whose supremum is `a`. Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied purely order theoretically in Sperner theory. ## Constructions We provide many ways to build finpartitions: * `Finpartition.ofErase`: Builds a finpartition by erasing `⊥` for you. * `Finpartition.ofSubset`: Builds a finpartition from a subset of the parts of a previous finpartition. * `Finpartition.empty`: The empty finpartition of `⊥`. * `Finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single part. * `Finpartition.discrete`: The discrete finpartition of `s : Finset α` made of singletons. * `Finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new finpartition. * `Finpartition.ofSetoid`: With `Fintype α`, constructs the finpartition of `univ : Finset α` induced by the equivalence classes of `s : Setoid α`. * `Finpartition.atomise`: Makes a finpartition of `s : Finset α` by breaking `s` along all finsets in `F : Finset (Finset α)`. Two elements of `s` belong to the same part iff they belong to the same elements of `F`. `Finpartition.indiscrete` and `Finpartition.bind` together form the monadic structure of `Finpartition`. ## Implementation notes Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning operations on `Finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing `⊥` to be a part makes `Finpartition.bind` uglier and doesn't rid us of the need of `Finpartition.ofErase`. ## TODO The order is the wrong way around to make `Finpartition a` a graded order. Is it bad to depart from the literature and turn the order around? -/ open Finset Function variable {α : Type*} /-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is `a`. We forbid `⊥` as a part. -/ @[ext] structure Finpartition [Lattice α] [OrderBot α] (a : α) where -- Porting note: Docstrings added /-- The elements of the finite partition of `a` -/ parts : Finset α /-- The partition is supremum-independent -/ supIndep : parts.SupIndep id /-- The supremum of the partition is `a` -/ sup_parts : parts.sup id = a /-- No element of the partition is bottom-/ not_bot_mem : ⊥ ∉ parts deriving DecidableEq #align finpartition Finpartition #align finpartition.parts Finpartition.parts #align finpartition.sup_indep Finpartition.supIndep #align finpartition.sup_parts Finpartition.sup_parts #align finpartition.not_bot_mem Finpartition.not_bot_mem -- Porting note: attribute [protected] doesn't work -- attribute [protected] Finpartition.supIndep namespace Finpartition section Lattice variable [Lattice α] [OrderBot α] /-- A `Finpartition` constructor which does not insist on `⊥` not being a part. -/ @[simps] def ofErase [DecidableEq α] {a : α} (parts : Finset α) (sup_indep : parts.SupIndep id) (sup_parts : parts.sup id = a) : Finpartition a where parts := parts.erase ⊥ supIndep := sup_indep.subset (erase_subset _ _) sup_parts := (sup_erase_bot _).trans sup_parts not_bot_mem := not_mem_erase _ _ #align finpartition.of_erase Finpartition.ofErase /-- A `Finpartition` constructor from a bigger existing finpartition. -/ @[simps] def ofSubset {a b : α} (P : Finpartition a) {parts : Finset α} (subset : parts ⊆ P.parts) (sup_parts : parts.sup id = b) : Finpartition b := { parts := parts supIndep := P.supIndep.subset subset sup_parts := sup_parts not_bot_mem := fun h ↦ P.not_bot_mem (subset h) } #align finpartition.of_subset Finpartition.ofSubset /-- Changes the type of a finpartition to an equal one. -/ @[simps] def copy {a b : α} (P : Finpartition a) (h : a = b) : Finpartition b where parts := P.parts supIndep := P.supIndep sup_parts := h ▸ P.sup_parts not_bot_mem := P.not_bot_mem #align finpartition.copy Finpartition.copy /-- Transfer a finpartition over an order isomorphism. -/ def map {β : Type*} [Lattice β] [OrderBot β] {a : α} (e : α ≃o β) (P : Finpartition a) : Finpartition (e a) where parts := P.parts.map e supIndep u hu _ hb hbu _ hx hxu := by rw [← map_symm_subset] at hu simp only [mem_map_equiv] at hb have := P.supIndep hu hb (by simp [hbu]) (map_rel e.symm hx) ?_ · rw [← e.symm.map_bot] at this exact e.symm.map_rel_iff.mp this · convert e.symm.map_rel_iff.mpr hxu rw [map_finset_sup, sup_map] rfl sup_parts := by simp [← P.sup_parts] not_bot_mem := by rw [mem_map_equiv] convert P.not_bot_mem exact e.symm.map_bot @[simp] theorem parts_map {β : Type*} [Lattice β] [OrderBot β] {a : α} {e : α ≃o β} {P : Finpartition a} : (P.map e).parts = P.parts.map e := rfl variable (α) /-- The empty finpartition. -/ @[simps] protected def empty : Finpartition (⊥ : α) where parts := ∅ supIndep := supIndep_empty _ sup_parts := Finset.sup_empty not_bot_mem := not_mem_empty ⊥ #align finpartition.empty Finpartition.empty instance : Inhabited (Finpartition (⊥ : α)) := ⟨Finpartition.empty α⟩ @[simp] theorem default_eq_empty : (default : Finpartition (⊥ : α)) = Finpartition.empty α := rfl #align finpartition.default_eq_empty Finpartition.default_eq_empty variable {α} {a : α} /-- The finpartition in one part, aka indiscrete finpartition. -/ @[simps] def indiscrete (ha : a ≠ ⊥) : Finpartition a where parts := {a} supIndep := supIndep_singleton _ _ sup_parts := Finset.sup_singleton not_bot_mem h := ha (mem_singleton.1 h).symm #align finpartition.indiscrete Finpartition.indiscrete variable (P : Finpartition a) protected theorem le {b : α} (hb : b ∈ P.parts) : b ≤ a := (le_sup hb).trans P.sup_parts.le #align finpartition.le Finpartition.le theorem ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := by intro h refine P.not_bot_mem (?_) rw [h] at hb exact hb #align finpartition.ne_bot Finpartition.ne_bot protected theorem disjoint : (P.parts : Set α).PairwiseDisjoint id := P.supIndep.pairwiseDisjoint #align finpartition.disjoint Finpartition.disjoint variable {P} theorem parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ := by simp_rw [← P.sup_parts] refine ⟨fun h ↦ ?_, fun h ↦ eq_empty_iff_forall_not_mem.2 fun b hb ↦ P.not_bot_mem ?_⟩ · rw [h] exact Finset.sup_empty · rwa [← le_bot_iff.1 ((le_sup hb).trans h.le)] #align finpartition.parts_eq_empty_iff Finpartition.parts_eq_empty_iff theorem parts_nonempty_iff : P.parts.Nonempty ↔ a ≠ ⊥ := by rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff] #align finpartition.parts_nonempty_iff Finpartition.parts_nonempty_iff theorem parts_nonempty (P : Finpartition a) (ha : a ≠ ⊥) : P.parts.Nonempty := parts_nonempty_iff.2 ha #align finpartition.parts_nonempty Finpartition.parts_nonempty instance : Unique (Finpartition (⊥ : α)) := { (inferInstance : Inhabited (Finpartition (⊥ : α))) with uniq := fun P ↦ by ext a exact iff_of_false (fun h ↦ P.ne_bot h <| le_bot_iff.1 <| P.le h) (not_mem_empty a) } -- See note [reducible non instances] /-- There's a unique partition of an atom. -/ abbrev _root_.IsAtom.uniqueFinpartition (ha : IsAtom a) : Unique (Finpartition a) where default := indiscrete ha.1 uniq P := by have h : ∀ b ∈ P.parts, b = a := fun _ hb ↦ (ha.le_iff.mp <| P.le hb).resolve_left (P.ne_bot hb) ext b refine Iff.trans ⟨h b, ?_⟩ mem_singleton.symm rintro rfl obtain ⟨c, hc⟩ := P.parts_nonempty ha.1 simp_rw [← h c hc] exact hc #align is_atom.unique_finpartition IsAtom.uniqueFinpartition instance [Fintype α] [DecidableEq α] (a : α) : Fintype (Finpartition a) := @Fintype.ofSurjective { p : Finset α // p.SupIndep id ∧ p.sup id = a ∧ ⊥ ∉ p } (Finpartition a) _ (Subtype.fintype _) (fun i ↦ ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) fun ⟨_, y, z, w⟩ ↦ ⟨⟨_, y, z, w⟩, rfl⟩ /-! ### Refinement order -/ section Order /-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/ instance : LE (Finpartition a) := ⟨fun P Q ↦ ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩ instance : PartialOrder (Finpartition a) := { (inferInstance : LE (Finpartition a)) with le_refl := fun P b hb ↦ ⟨b, hb, le_rfl⟩ le_trans := fun P Q R hPQ hQR b hb ↦ by obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hcd⟩ := hQR hc exact ⟨d, hd, hbc.trans hcd⟩ le_antisymm := fun P Q hPQ hQP ↦ by ext b refine ⟨fun hb ↦ ?_, fun hb ↦ ?_⟩ · obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hcd⟩ := hQP hc rwa [hbc.antisymm] rwa [P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd)] · obtain ⟨c, hc, hbc⟩ := hQP hb obtain ⟨d, hd, hcd⟩ := hPQ hc rwa [hbc.antisymm] rwa [Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd)] } instance [Decidable (a = ⊥)] : OrderTop (Finpartition a) where top := if ha : a = ⊥ then (Finpartition.empty α).copy ha.symm else indiscrete ha le_top P := by split_ifs with h · intro x hx simpa [h, P.ne_bot hx] using P.le hx · exact fun b hb ↦ ⟨a, mem_singleton_self _, P.le hb⟩ theorem parts_top_subset (a : α) [Decidable (a = ⊥)] : (⊤ : Finpartition a).parts ⊆ {a} := by intro b hb have hb : b ∈ Finpartition.parts (dite _ _ _) := hb split_ifs at hb · simp only [copy_parts, empty_parts, not_mem_empty] at hb · exact hb #align finpartition.parts_top_subset Finpartition.parts_top_subset theorem parts_top_subsingleton (a : α) [Decidable (a = ⊥)] : ((⊤ : Finpartition a).parts : Set α).Subsingleton := Set.subsingleton_of_subset_singleton fun _ hb ↦ mem_singleton.1 <| parts_top_subset _ hb #align finpartition.parts_top_subsingleton Finpartition.parts_top_subsingleton end Order end Lattice section DistribLattice variable [DistribLattice α] [OrderBot α] section Inf variable [DecidableEq α] {a b c : α} instance : Inf (Finpartition a) := ⟨fun P Q ↦ ofErase ((P.parts ×ˢ Q.parts).image fun bc ↦ bc.1 ⊓ bc.2) (by rw [supIndep_iff_disjoint_erase] simp only [mem_image, and_imp, exists_prop, forall_exists_index, id, Prod.exists, mem_product, Finset.disjoint_sup_right, mem_erase, Ne] rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl rcases eq_or_ne x₁ x₂ with (rfl | xdiff) · refine Disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ ?_) intro t simp [t] at h exact Disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff)) (by rw [sup_image, id_comp, sup_product_left] trans P.parts.sup id ⊓ Q.parts.sup id · simp_rw [Finset.sup_inf_distrib_right, Finset.sup_inf_distrib_left] rfl · rw [P.sup_parts, Q.sup_parts, inf_idem])⟩ @[simp] theorem parts_inf (P Q : Finpartition a) : (P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image fun bc : α × α ↦ bc.1 ⊓ bc.2).erase ⊥ := rfl #align finpartition.parts_inf Finpartition.parts_inf instance : SemilatticeInf (Finpartition a) := { (inferInstance : PartialOrder (Finpartition a)), (inferInstance : Inf (Finpartition a)) with inf_le_left := fun P Q b hb ↦ by obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb) rw [mem_product] at hc exact ⟨c.1, hc.1, inf_le_left⟩ inf_le_right := fun P Q b hb ↦ by obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb) rw [mem_product] at hc exact ⟨c.2, hc.2, inf_le_right⟩ le_inf := fun P Q R hPQ hPR b hb ↦ by obtain ⟨c, hc, hbc⟩ := hPQ hb obtain ⟨d, hd, hbd⟩ := hPR hb have h := _root_.le_inf hbc hbd refine ⟨c ⊓ d, mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h) (mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩), h⟩ } end Inf
Mathlib/Order/Partition/Finpartition.lean
343
353
theorem exists_le_of_le {a b : α} {P Q : Finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) : ∃ c ∈ P.parts, c ≤ b := by
by_contra H refine Q.ne_bot hb (disjoint_self.1 <| Disjoint.mono_right (Q.le hb) ?_) rw [← P.sup_parts, Finset.disjoint_sup_right] rintro c hc obtain ⟨d, hd, hcd⟩ := h hc refine (Q.disjoint hb hd ?_).mono_right hcd rintro rfl simp only [not_exists, not_and] at H exact H _ hc hcd
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Filippo A. E. Nuccio -/ import Mathlib.RingTheory.Localization.Integer import Mathlib.RingTheory.Localization.Submodule #align_import ring_theory.fractional_ideal from "leanprover-community/mathlib"@"ed90a7d327c3a5caf65a6faf7e8a0d63c4605df7" /-! # Fractional ideals This file defines fractional ideals of an integral domain and proves basic facts about them. ## Main definitions Let `S` be a submonoid of an integral domain `R` and `P` the localization of `R` at `S`. * `IsFractional` defines which `R`-submodules of `P` are fractional ideals * `FractionalIdeal S P` is the type of fractional ideals in `P` * a coercion `coeIdeal : Ideal R → FractionalIdeal S P` * `CommSemiring (FractionalIdeal S P)` instance: the typical ideal operations generalized to fractional ideals * `Lattice (FractionalIdeal S P)` instance ## Main statements * `mul_left_mono` and `mul_right_mono` state that ideal multiplication is monotone * `mul_div_self_cancel_iff` states that `1 / I` is the inverse of `I` if one exists ## Implementation notes Fractional ideals are considered equal when they contain the same elements, independent of the denominator `a : R` such that `a I ⊆ R`. Thus, we define `FractionalIdeal` to be the subtype of the predicate `IsFractional`, instead of having `FractionalIdeal` be a structure of which `a` is a field. Most definitions in this file specialize operations from submodules to fractional ideals, proving that the result of this operation is fractional if the input is fractional. Exceptions to this rule are defining `(+) := (⊔)` and `⊥ := 0`, in order to re-use their respective proof terms. We can still use `simp` to show `↑I + ↑J = ↑(I + J)` and `↑⊥ = ↑0`. Many results in fact do not need that `P` is a localization, only that `P` is an `R`-algebra. We omit the `IsLocalization` parameter whenever this is practical. Similarly, we don't assume that the localization is a field until we need it to define ideal quotients. When this assumption is needed, we replace `S` with `R⁰`, making the localization a field. ## References * https://en.wikipedia.org/wiki/Fractional_ideal ## Tags fractional ideal, fractional ideals, invertible ideal -/ open IsLocalization Pointwise nonZeroDivisors section Defs variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] variable (S) /-- A submodule `I` is a fractional ideal if `a I ⊆ R` for some `a ≠ 0`. -/ def IsFractional (I : Submodule R P) := ∃ a ∈ S, ∀ b ∈ I, IsInteger R (a • b) #align is_fractional IsFractional variable (P) /-- The fractional ideals of a domain `R` are ideals of `R` divided by some `a ∈ R`. More precisely, let `P` be a localization of `R` at some submonoid `S`, then a fractional ideal `I ⊆ P` is an `R`-submodule of `P`, such that there is a nonzero `a : R` with `a I ⊆ R`. -/ def FractionalIdeal := { I : Submodule R P // IsFractional S I } #align fractional_ideal FractionalIdeal end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R P] [loc : IsLocalization S P] /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This implements the coercion `FractionalIdeal S P → Submodule R P`. -/ @[coe] def coeToSubmodule (I : FractionalIdeal S P) : Submodule R P := I.val /-- Map a fractional ideal `I` to a submodule by forgetting that `∃ a, a I ⊆ R`. This coercion is typically called `coeToSubmodule` in lemma names (or `coe` when the coercion is clear from the context), not to be confused with `IsLocalization.coeSubmodule : Ideal R → Submodule R P` (which we use to define `coe : Ideal R → FractionalIdeal S P`). -/ instance : CoeOut (FractionalIdeal S P) (Submodule R P) := ⟨coeToSubmodule⟩ protected theorem isFractional (I : FractionalIdeal S P) : IsFractional S (I : Submodule R P) := I.prop #align fractional_ideal.is_fractional FractionalIdeal.isFractional /-- An element of `S` such that `I.den • I = I.num`, see `FractionalIdeal.num` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def den (I : FractionalIdeal S P) : S := ⟨I.2.choose, I.2.choose_spec.1⟩ /-- An ideal of `R` such that `I.den • I = I.num`, see `FractionalIdeal.den` and `FractionalIdeal.den_mul_self_eq_num`. -/ noncomputable def num (I : FractionalIdeal S P) : Ideal R := (I.den • (I : Submodule R P)).comap (Algebra.linearMap R P) theorem den_mul_self_eq_num (I : FractionalIdeal S P) : I.den • (I : Submodule R P) = Submodule.map (Algebra.linearMap R P) I.num := by rw [den, num, Submodule.map_comap_eq] refine (inf_of_le_right ?_).symm rintro _ ⟨a, ha, rfl⟩ exact I.2.choose_spec.2 a ha /-- The linear equivalence between the fractional ideal `I` and the integral ideal `I.num` defined by mapping `x` to `den I • x`. -/ noncomputable def equivNum [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) : I ≃ₗ[R] I.num := by refine LinearEquiv.trans (LinearEquiv.ofBijective ((DistribMulAction.toLinearMap R P I.den).restrict fun _ hx ↦ ?_) ⟨fun _ _ hxy ↦ ?_, fun ⟨y, hy⟩ ↦ ?_⟩) (Submodule.equivMapOfInjective (Algebra.linearMap R P) (NoZeroSMulDivisors.algebraMap_injective R P) (num I)).symm · rw [← den_mul_self_eq_num] exact Submodule.smul_mem_pointwise_smul _ _ _ hx · simp_rw [LinearMap.restrict_apply, DistribMulAction.toLinearMap_apply, Subtype.mk.injEq] at hxy rwa [Submonoid.smul_def, Submonoid.smul_def, smul_right_inj h_nz, SetCoe.ext_iff] at hxy · rw [← den_mul_self_eq_num] at hy obtain ⟨x, hx, hxy⟩ := hy exact ⟨⟨x, hx⟩, by simp_rw [LinearMap.restrict_apply, Subtype.ext_iff, ← hxy]; rfl⟩ section SetLike instance : SetLike (FractionalIdeal S P) P where coe I := ↑(I : Submodule R P) coe_injective' := SetLike.coe_injective.comp Subtype.coe_injective @[simp] theorem mem_coe {I : FractionalIdeal S P} {x : P} : x ∈ (I : Submodule R P) ↔ x ∈ I := Iff.rfl #align fractional_ideal.mem_coe FractionalIdeal.mem_coe @[ext] theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := SetLike.ext #align fractional_ideal.ext FractionalIdeal.ext @[simp] theorem equivNum_apply [Nontrivial P] [NoZeroSMulDivisors R P] {I : FractionalIdeal S P} (h_nz : (I.den : R) ≠ 0) (x : I) : algebraMap R P (equivNum h_nz x) = I.den • x := by change Algebra.linearMap R P _ = _ rw [equivNum, LinearEquiv.trans_apply, LinearEquiv.ofBijective_apply, LinearMap.restrict_apply, Submodule.map_equivMapOfInjective_symm_apply, Subtype.coe_mk, DistribMulAction.toLinearMap_apply] /-- Copy of a `FractionalIdeal` with a new underlying set equal to the old one. Useful to fix definitional equalities. -/ protected def copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : FractionalIdeal S P := ⟨Submodule.copy p s hs, by convert p.isFractional ext simp only [hs] rfl⟩ #align fractional_ideal.copy FractionalIdeal.copy @[simp] theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s := rfl #align fractional_ideal.coe_copy FractionalIdeal.coe_copy theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs #align fractional_ideal.coe_eq FractionalIdeal.coe_eq end SetLike -- Porting note: this seems to be needed a lot more than in Lean 3 @[simp] theorem val_eq_coe (I : FractionalIdeal S P) : I.val = I := rfl #align fractional_ideal.val_eq_coe FractionalIdeal.val_eq_coe -- Porting note: had to rephrase this to make it clear to `simp` what was going on. @[simp, norm_cast] theorem coe_mk (I : Submodule R P) (hI : IsFractional S I) : coeToSubmodule ⟨I, hI⟩ = I := rfl #align fractional_ideal.coe_mk FractionalIdeal.coe_mk -- Porting note (#10756): added lemma because Lean can't see through the composition of coercions. theorem coeToSet_coeToSubmodule (I : FractionalIdeal S P) : ((I : Submodule R P) : Set P) = I := rfl /-! Transfer instances from `Submodule R P` to `FractionalIdeal S P`. -/ instance (I : FractionalIdeal S P) : Module R I := Submodule.module (I : Submodule R P) theorem coeToSubmodule_injective : Function.Injective (fun (I : FractionalIdeal S P) ↦ (I : Submodule R P)) := Subtype.coe_injective #align fractional_ideal.coe_to_submodule_injective FractionalIdeal.coeToSubmodule_injective theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J := coeToSubmodule_injective.eq_iff #align fractional_ideal.coe_to_submodule_inj FractionalIdeal.coeToSubmodule_inj theorem isFractional_of_le_one (I : Submodule R P) (h : I ≤ 1) : IsFractional S I := by use 1, S.one_mem intro b hb rw [one_smul] obtain ⟨b', b'_mem, rfl⟩ := h hb exact Set.mem_range_self b' #align fractional_ideal.is_fractional_of_le_one FractionalIdeal.isFractional_of_le_one theorem isFractional_of_le {I : Submodule R P} {J : FractionalIdeal S P} (hIJ : I ≤ J) : IsFractional S I := by obtain ⟨a, a_mem, ha⟩ := J.isFractional use a, a_mem intro b b_mem exact ha b (hIJ b_mem) #align fractional_ideal.is_fractional_of_le FractionalIdeal.isFractional_of_le /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is the function that implements the coercion `Ideal R → FractionalIdeal S P`. -/ @[coe] def coeIdeal (I : Ideal R) : FractionalIdeal S P := ⟨coeSubmodule P I, isFractional_of_le_one _ <| by simpa using coeSubmodule_mono P (le_top : I ≤ ⊤)⟩ -- Is a `CoeTC` rather than `Coe` to speed up failing inference, see library note [use has_coe_t] /-- Map an ideal `I` to a fractional ideal by forgetting `I` is integral. This is a bundled version of `IsLocalization.coeSubmodule : Ideal R → Submodule R P`, which is not to be confused with the `coe : FractionalIdeal S P → Submodule R P`, also called `coeToSubmodule` in theorem names. This map is available as a ring hom, called `FractionalIdeal.coeIdealHom`. -/ instance : CoeTC (Ideal R) (FractionalIdeal S P) := ⟨fun I => coeIdeal I⟩ @[simp, norm_cast] theorem coe_coeIdeal (I : Ideal R) : ((I : FractionalIdeal S P) : Submodule R P) = coeSubmodule P I := rfl #align fractional_ideal.coe_coe_ideal FractionalIdeal.coe_coeIdeal variable (S) @[simp] theorem mem_coeIdeal {x : P} {I : Ideal R} : x ∈ (I : FractionalIdeal S P) ↔ ∃ x', x' ∈ I ∧ algebraMap R P x' = x := mem_coeSubmodule _ _ #align fractional_ideal.mem_coe_ideal FractionalIdeal.mem_coeIdeal theorem mem_coeIdeal_of_mem {x : R} {I : Ideal R} (hx : x ∈ I) : algebraMap R P x ∈ (I : FractionalIdeal S P) := (mem_coeIdeal S).mpr ⟨x, hx, rfl⟩ #align fractional_ideal.mem_coe_ideal_of_mem FractionalIdeal.mem_coeIdeal_of_mem theorem coeIdeal_le_coeIdeal' [IsLocalization S P] (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) ≤ J ↔ I ≤ J := coeSubmodule_le_coeSubmodule h #align fractional_ideal.coe_ideal_le_coe_ideal' FractionalIdeal.coeIdeal_le_coeIdeal' @[simp] theorem coeIdeal_le_coeIdeal (K : Type*) [CommRing K] [Algebra R K] [IsFractionRing R K] {I J : Ideal R} : (I : FractionalIdeal R⁰ K) ≤ J ↔ I ≤ J := IsFractionRing.coeSubmodule_le_coeSubmodule #align fractional_ideal.coe_ideal_le_coe_ideal FractionalIdeal.coeIdeal_le_coeIdeal instance : Zero (FractionalIdeal S P) := ⟨(0 : Ideal R)⟩ @[simp] theorem mem_zero_iff {x : P} : x ∈ (0 : FractionalIdeal S P) ↔ x = 0 := ⟨fun ⟨x', x'_mem_zero, x'_eq_x⟩ => by have x'_eq_zero : x' = 0 := x'_mem_zero simp [x'_eq_x.symm, x'_eq_zero], fun hx => ⟨0, rfl, by simp [hx]⟩⟩ #align fractional_ideal.mem_zero_iff FractionalIdeal.mem_zero_iff variable {S} @[simp, norm_cast] theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) := Submodule.ext fun _ => mem_zero_iff S #align fractional_ideal.coe_zero FractionalIdeal.coe_zero @[simp, norm_cast] theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 := rfl #align fractional_ideal.coe_ideal_bot FractionalIdeal.coeIdeal_bot variable (P) @[simp] theorem exists_mem_algebraMap_eq {x : R} {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (∃ x', x' ∈ I ∧ algebraMap R P x' = algebraMap R P x) ↔ x ∈ I := ⟨fun ⟨_, hx', Eq⟩ => IsLocalization.injective _ h Eq ▸ hx', fun h => ⟨x, h, rfl⟩⟩ #align fractional_ideal.exists_mem_to_map_eq FractionalIdeal.exists_mem_algebraMap_eq variable {P} theorem coeIdeal_injective' (h : S ≤ nonZeroDivisors R) : Function.Injective (fun (I : Ideal R) ↦ (I : FractionalIdeal S P)) := fun _ _ h' => ((coeIdeal_le_coeIdeal' S h).mp h'.le).antisymm ((coeIdeal_le_coeIdeal' S h).mp h'.ge) #align fractional_ideal.coe_ideal_injective' FractionalIdeal.coeIdeal_injective' theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) = J ↔ I = J := (coeIdeal_injective' h).eq_iff #align fractional_ideal.coe_ideal_inj' FractionalIdeal.coeIdeal_inj' -- Porting note: doesn't need to be @[simp] because it can be proved by coeIdeal_eq_zero theorem coeIdeal_eq_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) = 0 ↔ I = (⊥ : Ideal R) := coeIdeal_inj' h #align fractional_ideal.coe_ideal_eq_zero' FractionalIdeal.coeIdeal_eq_zero' theorem coeIdeal_ne_zero' {I : Ideal R} (h : S ≤ nonZeroDivisors R) : (I : FractionalIdeal S P) ≠ 0 ↔ I ≠ (⊥ : Ideal R) := not_iff_not.mpr <| coeIdeal_eq_zero' h #align fractional_ideal.coe_ideal_ne_zero' FractionalIdeal.coeIdeal_ne_zero' theorem coeToSubmodule_eq_bot {I : FractionalIdeal S P} : (I : Submodule R P) = ⊥ ↔ I = 0 := ⟨fun h => coeToSubmodule_injective (by simp [h]), fun h => by simp [h]⟩ #align fractional_ideal.coe_to_submodule_eq_bot FractionalIdeal.coeToSubmodule_eq_bot theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 := not_iff_not.mpr coeToSubmodule_eq_bot #align fractional_ideal.coe_to_submodule_ne_bot FractionalIdeal.coeToSubmodule_ne_bot instance : Inhabited (FractionalIdeal S P) := ⟨0⟩ instance : One (FractionalIdeal S P) := ⟨(⊤ : Ideal R)⟩ theorem zero_of_num_eq_bot [NoZeroSMulDivisors R P] (hS : 0 ∉ S) {I : FractionalIdeal S P} (hI : I.num = ⊥) : I = 0 := by rw [← coeToSubmodule_eq_bot, eq_bot_iff] intro x hx suffices (den I : R) • x = 0 from (smul_eq_zero.mp this).resolve_left (ne_of_mem_of_not_mem (SetLike.coe_mem _) hS) have h_eq : I.den • (I : Submodule R P) = ⊥ := by rw [den_mul_self_eq_num, hI, Submodule.map_bot] exact (Submodule.eq_bot_iff _).mp h_eq (den I • x) ⟨x, hx, rfl⟩ theorem num_zero_eq (h_inj : Function.Injective (algebraMap R P)) : num (0 : FractionalIdeal S P) = 0 := by simpa [num, LinearMap.ker_eq_bot] using h_inj variable (S) @[simp, norm_cast] theorem coeIdeal_top : ((⊤ : Ideal R) : FractionalIdeal S P) = 1 := rfl #align fractional_ideal.coe_ideal_top FractionalIdeal.coeIdeal_top theorem mem_one_iff {x : P} : x ∈ (1 : FractionalIdeal S P) ↔ ∃ x' : R, algebraMap R P x' = x := Iff.intro (fun ⟨x', _, h⟩ => ⟨x', h⟩) fun ⟨x', h⟩ => ⟨x', ⟨⟩, h⟩ #align fractional_ideal.mem_one_iff FractionalIdeal.mem_one_iff theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨x, rfl⟩ #align fractional_ideal.coe_mem_one FractionalIdeal.coe_mem_one theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨1, RingHom.map_one _⟩ #align fractional_ideal.one_mem_one FractionalIdeal.one_mem_one variable {S} /-- `(1 : FractionalIdeal S P)` is defined as the R-submodule `f(R) ≤ P`. However, this is not definitionally equal to `1 : Submodule R P`, which is proved in the actual `simp` lemma `coe_one`. -/ theorem coe_one_eq_coeSubmodule_top : ↑(1 : FractionalIdeal S P) = coeSubmodule P (⊤ : Ideal R) := rfl #align fractional_ideal.coe_one_eq_coe_submodule_top FractionalIdeal.coe_one_eq_coeSubmodule_top @[simp, norm_cast] theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top] #align fractional_ideal.coe_one FractionalIdeal.coe_one section Lattice /-! ### `Lattice` section Defines the order on fractional ideals as inclusion of their underlying sets, and ports the lattice structure on submodules to fractional ideals. -/ @[simp] theorem coe_le_coe {I J : FractionalIdeal S P} : (I : Submodule R P) ≤ (J : Submodule R P) ↔ I ≤ J := Iff.rfl #align fractional_ideal.coe_le_coe FractionalIdeal.coe_le_coe theorem zero_le (I : FractionalIdeal S P) : 0 ≤ I := by intro x hx -- Porting note: changed the proof from convert; simp into rw; exact rw [(mem_zero_iff _).mp hx] exact zero_mem (I : Submodule R P) #align fractional_ideal.zero_le FractionalIdeal.zero_le instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le #align fractional_ideal.order_bot FractionalIdeal.orderBot @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl #align fractional_ideal.bot_eq_zero FractionalIdeal.bot_eq_zero @[simp] theorem le_zero_iff {I : FractionalIdeal S P} : I ≤ 0 ↔ I = 0 := le_bot_iff #align fractional_ideal.le_zero_iff FractionalIdeal.le_zero_iff theorem eq_zero_iff {I : FractionalIdeal S P} : I = 0 ↔ ∀ x ∈ I, x = (0 : P) := ⟨fun h x hx => by simpa [h, mem_zero_iff] using hx, fun h => le_bot_iff.mp fun x hx => (mem_zero_iff S).mpr (h x hx)⟩ #align fractional_ideal.eq_zero_iff FractionalIdeal.eq_zero_iff theorem _root_.IsFractional.sup {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I ⊔ J) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by rcases mem_sup.mp hb with ⟨bI, hbI, bJ, hbJ, rfl⟩ rw [smul_add] apply isInteger_add · rw [mul_smul, smul_comm] exact isInteger_smul (hI bI hbI) · rw [mul_smul] exact isInteger_smul (hJ bJ hbJ)⟩ #align is_fractional.sup IsFractional.sup theorem _root_.IsFractional.inf_right {I : Submodule R P} : IsFractional S I → ∀ J, IsFractional S (I ⊓ J) | ⟨aI, haI, hI⟩, J => ⟨aI, haI, fun b hb => by rcases mem_inf.mp hb with ⟨hbI, _⟩ exact hI b hbI⟩ #align is_fractional.inf_right IsFractional.inf_right instance : Inf (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊓ J, I.isFractional.inf_right J⟩⟩ @[simp, norm_cast] theorem coe_inf (I J : FractionalIdeal S P) : ↑(I ⊓ J) = (I ⊓ J : Submodule R P) := rfl #align fractional_ideal.coe_inf FractionalIdeal.coe_inf instance : Sup (FractionalIdeal S P) := ⟨fun I J => ⟨I ⊔ J, I.isFractional.sup J.isFractional⟩⟩ @[norm_cast] theorem coe_sup (I J : FractionalIdeal S P) : ↑(I ⊔ J) = (I ⊔ J : Submodule R P) := rfl #align fractional_ideal.coe_sup FractionalIdeal.coe_sup instance lattice : Lattice (FractionalIdeal S P) := Function.Injective.lattice _ Subtype.coe_injective coe_sup coe_inf #align fractional_ideal.lattice FractionalIdeal.lattice instance : SemilatticeSup (FractionalIdeal S P) := { FractionalIdeal.lattice with } end Lattice section Semiring instance : Add (FractionalIdeal S P) := ⟨(· ⊔ ·)⟩ @[simp] theorem sup_eq_add (I J : FractionalIdeal S P) : I ⊔ J = I + J := rfl #align fractional_ideal.sup_eq_add FractionalIdeal.sup_eq_add @[simp, norm_cast] theorem coe_add (I J : FractionalIdeal S P) : (↑(I + J) : Submodule R P) = I + J := rfl #align fractional_ideal.coe_add FractionalIdeal.coe_add @[simp, norm_cast] theorem coeIdeal_sup (I J : Ideal R) : ↑(I ⊔ J) = (I + J : FractionalIdeal S P) := coeToSubmodule_injective <| coeSubmodule_sup _ _ _ #align fractional_ideal.coe_ideal_sup FractionalIdeal.coeIdeal_sup theorem _root_.IsFractional.nsmul {I : Submodule R P} : ∀ n : ℕ, IsFractional S I → IsFractional S (n • I : Submodule R P) | 0, _ => by rw [zero_smul] convert ((0 : Ideal R) : FractionalIdeal S P).isFractional simp | n + 1, h => by rw [succ_nsmul] exact (IsFractional.nsmul n h).sup h #align is_fractional.nsmul IsFractional.nsmul instance : SMul ℕ (FractionalIdeal S P) where smul n I := ⟨n • ↑I, I.isFractional.nsmul n⟩ @[norm_cast] theorem coe_nsmul (n : ℕ) (I : FractionalIdeal S P) : (↑(n • I) : Submodule R P) = n • (I : Submodule R P) := rfl #align fractional_ideal.coe_nsmul FractionalIdeal.coe_nsmul theorem _root_.IsFractional.mul {I J : Submodule R P} : IsFractional S I → IsFractional S J → IsFractional S (I * J : Submodule R P) | ⟨aI, haI, hI⟩, ⟨aJ, haJ, hJ⟩ => ⟨aI * aJ, S.mul_mem haI haJ, fun b hb => by refine Submodule.mul_induction_on hb ?_ ?_ · intro m hm n hn obtain ⟨n', hn'⟩ := hJ n hn rw [mul_smul, mul_comm m, ← smul_mul_assoc, ← hn', ← Algebra.smul_def] apply hI exact Submodule.smul_mem _ _ hm · intro x y hx hy rw [smul_add] apply isInteger_add hx hy⟩ #align is_fractional.mul IsFractional.mul theorem _root_.IsFractional.pow {I : Submodule R P} (h : IsFractional S I) : ∀ n : ℕ, IsFractional S (I ^ n : Submodule R P) | 0 => isFractional_of_le_one _ (pow_zero _).le | n + 1 => (pow_succ I n).symm ▸ (IsFractional.pow h n).mul h #align is_fractional.pow IsFractional.pow /-- `FractionalIdeal.mul` is the product of two fractional ideals, used to define the `Mul` instance. This is only an auxiliary definition: the preferred way of writing `I.mul J` is `I * J`. Elaborated terms involving `FractionalIdeal` tend to grow quite large, so by making definitions irreducible, we hope to avoid deep unfolds. -/ irreducible_def mul (lemma := mul_def') (I J : FractionalIdeal S P) : FractionalIdeal S P := ⟨I * J, I.isFractional.mul J.isFractional⟩ #align fractional_ideal.mul FractionalIdeal.mul -- local attribute [semireducible] mul instance : Mul (FractionalIdeal S P) := ⟨fun I J => mul I J⟩ @[simp] theorem mul_eq_mul (I J : FractionalIdeal S P) : mul I J = I * J := rfl #align fractional_ideal.mul_eq_mul FractionalIdeal.mul_eq_mul theorem mul_def (I J : FractionalIdeal S P) : I * J = ⟨I * J, I.isFractional.mul J.isFractional⟩ := by simp only [← mul_eq_mul, mul] #align fractional_ideal.mul_def FractionalIdeal.mul_def @[simp, norm_cast] theorem coe_mul (I J : FractionalIdeal S P) : (↑(I * J) : Submodule R P) = I * J := by simp only [mul_def, coe_mk] #align fractional_ideal.coe_mul FractionalIdeal.coe_mul @[simp, norm_cast] theorem coeIdeal_mul (I J : Ideal R) : (↑(I * J) : FractionalIdeal S P) = I * J := by simp only [mul_def] exact coeToSubmodule_injective (coeSubmodule_mul _ _ _) #align fractional_ideal.coe_ideal_mul FractionalIdeal.coeIdeal_mul theorem mul_left_mono (I : FractionalIdeal S P) : Monotone (I * ·) := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul hx (h hy) #align fractional_ideal.mul_left_mono FractionalIdeal.mul_left_mono theorem mul_right_mono (I : FractionalIdeal S P) : Monotone fun J => J * I := by intro J J' h simp only [mul_def] exact mul_le.mpr fun x hx y hy => mul_mem_mul (h hx) hy #align fractional_ideal.mul_right_mono FractionalIdeal.mul_right_mono
Mathlib/RingTheory/FractionalIdeal/Basic.lean
605
608
theorem mul_mem_mul {I J : FractionalIdeal S P} {i j : P} (hi : i ∈ I) (hj : j ∈ J) : i * j ∈ I * J := by
simp only [mul_def] exact Submodule.mul_mem_mul hi hj
/- 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.NullMeasurable import Mathlib.MeasureTheory.MeasurableSpace.Basic import Mathlib.Topology.Algebra.Order.LiminfLimsup #align_import measure_theory.measure.measure_space from "leanprover-community/mathlib"@"343e80208d29d2d15f8050b929aa50fe4ce71b55" /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace open scoped Classical symmDiff open Topology Filter ENNReal NNReal Interval MeasureTheory variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ #align measure_theory.ae_is_measurably_generated MeasureTheory.ae_isMeasurablyGenerated /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] #align measure_theory.ae_uIoc_iff MeasureTheory.ae_uIoc_iff theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union MeasureTheory.measure_union theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint #align measure_theory.measure_union' MeasureTheory.measure_union' theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet #align measure_theory.measure_inter_add_diff MeasureTheory.measure_inter_add_diff theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) #align measure_theory.measure_diff_add_inter MeasureTheory.measure_diff_add_inter theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl #align measure_theory.measure_union_add_inter MeasureTheory.measure_union_add_inter theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] #align measure_theory.measure_union_add_inter' MeasureTheory.measure_union_add_inter' lemma measure_symmDiff_eq (hs : MeasurableSet s) (ht : MeasurableSet t) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union disjoint_sdiff_sdiff (ht.diff hs) lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet #align measure_theory.measure_add_measure_compl MeasureTheory.measure_add_measure_compl theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 #align measure_theory.measure_bUnion₀ MeasureTheory.measure_biUnion₀ theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet #align measure_theory.measure_bUnion MeasureTheory.measure_biUnion theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] #align measure_theory.measure_sUnion₀ MeasureTheory.measure_sUnion₀ theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] #align measure_theory.measure_sUnion MeasureTheory.measure_sUnion theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm #align measure_theory.measure_bUnion_finset₀ MeasureTheory.measure_biUnion_finset₀ theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet #align measure_theory.measure_bUnion_finset MeasureTheory.measure_biUnion_finset /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} [MeasurableSpace α] (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) #align measure_theory.tsum_meas_le_meas_Union_of_disjoint MeasureTheory.tsum_meas_le_meas_iUnion_of_disjoint /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] #align measure_theory.tsum_measure_preimage_singleton MeasureTheory.tsum_measure_preimage_singleton lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] #align measure_theory.sum_measure_preimage_singleton MeasureTheory.sum_measure_preimage_singleton theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h #align measure_theory.measure_diff_null' MeasureTheory.measure_diff_null' theorem measure_add_diff (hs : MeasurableSet s) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union' disjoint_sdiff_right hs, union_diff_self] #align measure_theory.measure_add_diff MeasureTheory.measure_add_diff theorem measure_diff' (s : Set α) (hm : MeasurableSet t) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := Eq.symm <| ENNReal.sub_eq_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] #align measure_theory.measure_diff' MeasureTheory.measure_diff' theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : MeasurableSet s₂) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] #align measure_theory.measure_diff MeasureTheory.measure_diff theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right #align measure_theory.le_measure_diff MeasureTheory.le_measure_diff /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := (WithTop.sub_eq_top_iff.2 ⟨hμu, hμv⟩).symm _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h #align measure_theory.measure_diff_lt_of_lt_add MeasureTheory.measure_diff_lt_of_lt_add theorem measure_diff_le_iff_le_add (hs : MeasurableSet s) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] #align measure_theory.measure_diff_le_iff_le_add MeasureTheory.measure_diff_le_iff_le_add theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) #align measure_theory.measure_eq_measure_of_null_diff MeasureTheory.measure_eq_measure_of_null_diff theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ #align measure_theory.measure_eq_measure_of_between_null_diff MeasureTheory.measure_eq_measure_of_between_null_diff theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 #align measure_theory.measure_eq_measure_smaller_of_between_null_diff MeasureTheory.measure_eq_measure_smaller_of_between_null_diff theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 #align measure_theory.measure_eq_measure_larger_of_between_null_diff MeasureTheory.measure_eq_measure_larger_of_between_null_diff lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin #align measure_theory.measure_compl MeasureTheory.measure_compl lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ #align measure_theory.union_ae_eq_left_iff_ae_subset MeasureTheory.union_ae_eq_left_iff_ae_subset @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] #align measure_theory.union_ae_eq_right_iff_ae_subset MeasureTheory.union_ae_eq_right_iff_ae_subset theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] #align measure_theory.ae_eq_of_ae_subset_of_measure_ge MeasureTheory.ae_eq_of_ae_subset_of_measure_ge /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : MeasurableSet s) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht #align measure_theory.ae_eq_of_subset_of_measure_ge MeasureTheory.ae_eq_of_subset_of_measure_ge theorem measure_iUnion_congr_of_subset [Countable β] {s : β → Set α} {t : β → Set α} (hsub : ∀ b, s b ⊆ t b) (h_le : ∀ b, μ (t b) ≤ μ (s b)) : μ (⋃ b, s b) = μ (⋃ b, t b) := by rcases Classical.em (∃ b, μ (t b) = ∞) with (⟨b, hb⟩ | htop) · calc μ (⋃ b, s b) = ∞ := top_unique (hb ▸ (h_le b).trans <| measure_mono <| subset_iUnion _ _) _ = μ (⋃ b, t b) := Eq.symm <| top_unique <| hb ▸ measure_mono (subset_iUnion _ _) push_neg at htop refine le_antisymm (measure_mono (iUnion_mono hsub)) ?_ set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · exact (measurableSet_toMeasurable _ _).inter (measurableSet_toMeasurable _ _) · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ #align measure_theory.measure_Union_congr_of_subset MeasureTheory.measure_iUnion_congr_of_subset theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) #align measure_theory.measure_union_congr_of_subset MeasureTheory.measure_union_congr_of_subset @[simp] theorem measure_iUnion_toMeasurable [Countable β] (s : β → Set α) : μ (⋃ b, toMeasurable μ (s b)) = μ (⋃ b, s b) := Eq.symm <| measure_iUnion_congr_of_subset (fun _b => subset_toMeasurable _ _) fun _b => (measure_toMeasurable _).le #align measure_theory.measure_Union_to_measurable MeasureTheory.measure_iUnion_toMeasurable theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] #align measure_theory.measure_bUnion_to_measurable MeasureTheory.measure_biUnion_toMeasurable @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl #align measure_theory.measure_to_measurable_union MeasureTheory.measure_toMeasurable_union @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le #align measure_theory.measure_union_to_measurable MeasureTheory.measure_union_toMeasurable theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : Set.PairwiseDisjoint (↑s) t) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset H h] exact measure_mono (subset_univ _) #align measure_theory.sum_measure_le_measure_univ MeasureTheory.sum_measure_le_measure_univ theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : Pairwise (Disjoint on s)) : (∑' i, μ (s i)) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij #align measure_theory.tsum_measure_le_measure_univ MeasureTheory.tsum_measure_le_measure_univ /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, MeasurableSet (s i)) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact disjoint_iff_inter_eq_empty.mpr (H i j hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_tsum_measure /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, MeasurableSet (t i)) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij) #align measure_theory.exists_nonempty_inter_of_measure_univ_lt_sum_measure MeasureTheory.exists_nonempty_inter_of_measure_univ_lt_sum_measure /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) #align measure_theory.nonempty_inter_of_measure_lt_add MeasureTheory.nonempty_inter_of_measure_lt_add /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
460
465
theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by
rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h
/- 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.Basic #align_import analysis.box_integral.partition.tagged from "leanprover-community/mathlib"@"6ca1a09bc9aa75824bf97388c9e3b441fc4ccf3f" /-! # Tagged partitions A tagged (pre)partition is a (pre)partition `π` enriched with a tagged point for each box of `π`. For simplicity we require that the function `BoxIntegral.TaggedPrepartition.tag` is defined on all boxes `J : Box ι` but use its values only on boxes of the partition. Given `π : BoxIntegral.TaggedPrepartition I`, we require that each `BoxIntegral.TaggedPrepartition π J` belongs to `BoxIntegral.Box.Icc I`. If for every `J ∈ π`, `π.tag J` belongs to `J.Icc`, then `π` is called a *Henstock* partition. We do not include this assumption into the definition of a tagged (pre)partition because McShane integral is defined as a limit along tagged partitions without this requirement. ## Tags rectangular box, box partition -/ noncomputable section open scoped Classical open ENNReal NNReal open Set Function namespace BoxIntegral variable {ι : Type*} /-- A tagged prepartition is a prepartition enriched with a tagged point for each box of the prepartition. For simplicity we require that `tag` is defined for all boxes in `ι → ℝ` but we will use only the values of `tag` on the boxes of the partition. -/ structure TaggedPrepartition (I : Box ι) extends Prepartition I where /-- Choice of tagged point of each box in this prepartition: we extend this to a total function, on all boxes in `ι → ℝ`. -/ tag : Box ι → ι → ℝ /-- Each tagged point belongs to `I` -/ tag_mem_Icc : ∀ J, tag J ∈ Box.Icc I #align box_integral.tagged_prepartition BoxIntegral.TaggedPrepartition namespace TaggedPrepartition variable {I J J₁ J₂ : Box ι} (π : TaggedPrepartition I) {x : ι → ℝ} instance : Membership (Box ι) (TaggedPrepartition I) := ⟨fun J π => J ∈ π.boxes⟩ @[simp] theorem mem_toPrepartition {π : TaggedPrepartition I} : J ∈ π.toPrepartition ↔ J ∈ π := Iff.rfl #align box_integral.tagged_prepartition.mem_to_prepartition BoxIntegral.TaggedPrepartition.mem_toPrepartition @[simp] theorem mem_mk (π : Prepartition I) (f h) : J ∈ mk π f h ↔ J ∈ π := Iff.rfl #align box_integral.tagged_prepartition.mem_mk BoxIntegral.TaggedPrepartition.mem_mk /-- Union of all boxes of a tagged prepartition. -/ def iUnion : Set (ι → ℝ) := π.toPrepartition.iUnion #align box_integral.tagged_prepartition.Union BoxIntegral.TaggedPrepartition.iUnion theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl #align box_integral.tagged_prepartition.Union_def BoxIntegral.TaggedPrepartition.iUnion_def @[simp] theorem iUnion_mk (π : Prepartition I) (f h) : (mk π f h).iUnion = π.iUnion := rfl #align box_integral.tagged_prepartition.Union_mk BoxIntegral.TaggedPrepartition.iUnion_mk @[simp] theorem iUnion_toPrepartition : π.toPrepartition.iUnion = π.iUnion := rfl #align box_integral.tagged_prepartition.Union_to_prepartition BoxIntegral.TaggedPrepartition.iUnion_toPrepartition -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, mem_toPrepartition, exists_prop] #align box_integral.tagged_prepartition.mem_Union BoxIntegral.TaggedPrepartition.mem_iUnion theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h #align box_integral.tagged_prepartition.subset_Union BoxIntegral.TaggedPrepartition.subset_iUnion theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' #align box_integral.tagged_prepartition.Union_subset BoxIntegral.TaggedPrepartition.iUnion_subset /-- A tagged prepartition is a partition if it covers the whole box. -/ def IsPartition := π.toPrepartition.IsPartition #align box_integral.tagged_prepartition.is_partition BoxIntegral.TaggedPrepartition.IsPartition theorem isPartition_iff_iUnion_eq : IsPartition π ↔ π.iUnion = I := Prepartition.isPartition_iff_iUnion_eq #align box_integral.tagged_prepartition.is_partition_iff_Union_eq BoxIntegral.TaggedPrepartition.isPartition_iff_iUnion_eq /-- The tagged partition made of boxes of `π` that satisfy predicate `p`. -/ @[simps! (config := .asFn)] def filter (p : Box ι → Prop) : TaggedPrepartition I := ⟨π.1.filter p, π.2, π.3⟩ #align box_integral.tagged_prepartition.filter BoxIntegral.TaggedPrepartition.filter @[simp] theorem mem_filter {p : Box ι → Prop} : J ∈ π.filter p ↔ J ∈ π ∧ p J := Finset.mem_filter #align box_integral.tagged_prepartition.mem_filter BoxIntegral.TaggedPrepartition.mem_filter @[simp] theorem iUnion_filter_not (π : TaggedPrepartition I) (p : Box ι → Prop) : (π.filter fun J => ¬p J).iUnion = π.iUnion \ (π.filter p).iUnion := π.toPrepartition.iUnion_filter_not p #align box_integral.tagged_prepartition.Union_filter_not BoxIntegral.TaggedPrepartition.iUnion_filter_not end TaggedPrepartition namespace Prepartition variable {I J : Box ι} /-- Given a partition `π` of `I : BoxIntegral.Box ι` and a collection of tagged partitions `πi J` of all boxes `J ∈ π`, returns the tagged partition of `I` into all the boxes of `πi J` with tags coming from `(πi J).tag`. -/ def biUnionTagged (π : Prepartition I) (πi : ∀ J : Box ι, TaggedPrepartition J) : TaggedPrepartition I where toPrepartition := π.biUnion fun J => (πi J).toPrepartition tag J := (πi (π.biUnionIndex (fun J => (πi J).toPrepartition) J)).tag J tag_mem_Icc _ := Box.le_iff_Icc.1 (π.biUnionIndex_le _ _) ((πi _).tag_mem_Icc _) #align box_integral.prepartition.bUnion_tagged BoxIntegral.Prepartition.biUnionTagged @[simp] theorem mem_biUnionTagged (π : Prepartition I) {πi : ∀ J, TaggedPrepartition J} : J ∈ π.biUnionTagged πi ↔ ∃ J' ∈ π, J ∈ πi J' := π.mem_biUnion #align box_integral.prepartition.mem_bUnion_tagged BoxIntegral.Prepartition.mem_biUnionTagged theorem tag_biUnionTagged (π : Prepartition I) {πi : ∀ J, TaggedPrepartition J} (hJ : J ∈ π) {J'} (hJ' : J' ∈ πi J) : (π.biUnionTagged πi).tag J' = (πi J).tag J' := by rw [← π.biUnionIndex_of_mem (πi := fun J => (πi J).toPrepartition) hJ hJ'] rfl #align box_integral.prepartition.tag_bUnion_tagged BoxIntegral.Prepartition.tag_biUnionTagged @[simp] theorem iUnion_biUnionTagged (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : (π.biUnionTagged πi).iUnion = ⋃ J ∈ π, (πi J).iUnion := iUnion_biUnion _ _ #align box_integral.prepartition.Union_bUnion_tagged BoxIntegral.Prepartition.iUnion_biUnionTagged theorem forall_biUnionTagged (p : (ι → ℝ) → Box ι → Prop) (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : (∀ J ∈ π.biUnionTagged πi, p ((π.biUnionTagged πi).tag J) J) ↔ ∀ J ∈ π, ∀ J' ∈ πi J, p ((πi J).tag J') J' := by simp only [mem_biUnionTagged] refine ⟨fun H J hJ J' hJ' => ?_, fun H J' ⟨J, hJ, hJ'⟩ => ?_⟩ · rw [← π.tag_biUnionTagged hJ hJ'] exact H J' ⟨J, hJ, hJ'⟩ · rw [π.tag_biUnionTagged hJ hJ'] exact H J hJ J' hJ' #align box_integral.prepartition.forall_bUnion_tagged BoxIntegral.Prepartition.forall_biUnionTagged theorem IsPartition.biUnionTagged {π : Prepartition I} (h : IsPartition π) {πi : ∀ J, TaggedPrepartition J} (hi : ∀ J ∈ π, (πi J).IsPartition) : (π.biUnionTagged πi).IsPartition := h.biUnion hi #align box_integral.prepartition.is_partition.bUnion_tagged BoxIntegral.Prepartition.IsPartition.biUnionTagged end Prepartition namespace TaggedPrepartition variable {I J : Box ι} {π π₁ π₂ : TaggedPrepartition I} {x : ι → ℝ} /-- Given a tagged partition `π` of `I` and a (not tagged) partition `πi J hJ` of each `J ∈ π`, returns the tagged partition of `I` into all the boxes of all `πi J hJ`. The tag of a box `J` is defined to be the `π.tag` of the box of the partition `π` that includes `J`. Note that usually the result is not a Henstock partition. -/ @[simps (config := .asFn) tag] def biUnionPrepartition (π : TaggedPrepartition I) (πi : ∀ J : Box ι, Prepartition J) : TaggedPrepartition I where toPrepartition := π.toPrepartition.biUnion πi tag J := π.tag (π.toPrepartition.biUnionIndex πi J) tag_mem_Icc _ := π.tag_mem_Icc _ #align box_integral.tagged_prepartition.bUnion_prepartition BoxIntegral.TaggedPrepartition.biUnionPrepartition theorem IsPartition.biUnionPrepartition {π : TaggedPrepartition I} (h : IsPartition π) {πi : ∀ J, Prepartition J} (hi : ∀ J ∈ π, (πi J).IsPartition) : (π.biUnionPrepartition πi).IsPartition := h.biUnion hi #align box_integral.tagged_prepartition.is_partition.bUnion_prepartition BoxIntegral.TaggedPrepartition.IsPartition.biUnionPrepartition /-- Given two partitions `π₁` and `π₁`, one of them tagged and the other is not, returns the tagged partition with `toPrepartition = π₁.toPrepartition ⊓ π₂` and tags coming from `π₁`. Note that usually the result is not a Henstock partition. -/ def infPrepartition (π : TaggedPrepartition I) (π' : Prepartition I) : TaggedPrepartition I := π.biUnionPrepartition fun J => π'.restrict J #align box_integral.tagged_prepartition.inf_prepartition BoxIntegral.TaggedPrepartition.infPrepartition @[simp] theorem infPrepartition_toPrepartition (π : TaggedPrepartition I) (π' : Prepartition I) : (π.infPrepartition π').toPrepartition = π.toPrepartition ⊓ π' := rfl #align box_integral.tagged_prepartition.inf_prepartition_to_prepartition BoxIntegral.TaggedPrepartition.infPrepartition_toPrepartition theorem mem_infPrepartition_comm : J ∈ π₁.infPrepartition π₂.toPrepartition ↔ J ∈ π₂.infPrepartition π₁.toPrepartition := by simp only [← mem_toPrepartition, infPrepartition_toPrepartition, inf_comm] #align box_integral.tagged_prepartition.mem_inf_prepartition_comm BoxIntegral.TaggedPrepartition.mem_infPrepartition_comm theorem IsPartition.infPrepartition (h₁ : π₁.IsPartition) {π₂ : Prepartition I} (h₂ : π₂.IsPartition) : (π₁.infPrepartition π₂).IsPartition := h₁.inf h₂ #align box_integral.tagged_prepartition.is_partition.inf_prepartition BoxIntegral.TaggedPrepartition.IsPartition.infPrepartition open Metric /-- A tagged partition is said to be a Henstock partition if for each `J ∈ π`, the tag of `J` belongs to `J.Icc`. -/ def IsHenstock (π : TaggedPrepartition I) : Prop := ∀ J ∈ π, π.tag J ∈ Box.Icc J set_option linter.uppercaseLean3 false in #align box_integral.tagged_prepartition.is_Henstock BoxIntegral.TaggedPrepartition.IsHenstock @[simp] theorem isHenstock_biUnionTagged {π : Prepartition I} {πi : ∀ J, TaggedPrepartition J} : IsHenstock (π.biUnionTagged πi) ↔ ∀ J ∈ π, (πi J).IsHenstock := π.forall_biUnionTagged (fun x J => x ∈ Box.Icc J) πi set_option linter.uppercaseLean3 false in #align box_integral.tagged_prepartition.is_Henstock_bUnion_tagged BoxIntegral.TaggedPrepartition.isHenstock_biUnionTagged /-- In a Henstock prepartition, there are at most `2 ^ Fintype.card ι` boxes with a given tag. -/
Mathlib/Analysis/BoxIntegral/Partition/Tagged.lean
239
247
theorem IsHenstock.card_filter_tag_eq_le [Fintype ι] (h : π.IsHenstock) (x : ι → ℝ) : (π.boxes.filter fun J => π.tag J = x).card ≤ 2 ^ Fintype.card ι := calc (π.boxes.filter fun J => π.tag J = x).card ≤ (π.boxes.filter fun J : Box ι => x ∈ Box.Icc J).card := by
refine Finset.card_le_card fun J hJ => ?_ rw [Finset.mem_filter] at hJ ⊢; rcases hJ with ⟨hJ, rfl⟩ exact ⟨hJ, h J hJ⟩ _ ≤ 2 ^ Fintype.card ι := π.toPrepartition.card_filter_mem_Icc_le x
/- Copyright (c) 2021 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import Mathlib.Combinatorics.SimpleGraph.Subgraph import Mathlib.Data.List.Rotate #align_import combinatorics.simple_graph.connectivity from "leanprover-community/mathlib"@"b99e2d58a5e6861833fa8de11e51a81144258db4" /-! # Graph connectivity In a simple graph, * A *walk* is a finite sequence of adjacent vertices, and can be thought of equally well as a sequence of directed edges. * A *trail* is a walk whose edges each appear no more than once. * A *path* is a trail whose vertices appear no more than once. * A *cycle* is a nonempty trail whose first and last vertices are the same and whose vertices except for the first appear no more than once. **Warning:** graph theorists mean something different by "path" than do homotopy theorists. A "walk" in graph theory is a "path" in homotopy theory. Another warning: some graph theorists use "path" and "simple path" for "walk" and "path." Some definitions and theorems have inspiration from multigraph counterparts in [Chou1994]. ## Main definitions * `SimpleGraph.Walk` (with accompanying pattern definitions `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'`) * `SimpleGraph.Walk.IsTrail`, `SimpleGraph.Walk.IsPath`, and `SimpleGraph.Walk.IsCycle`. * `SimpleGraph.Path` * `SimpleGraph.Walk.map` and `SimpleGraph.Path.map` for the induced map on walks, given an (injective) graph homomorphism. * `SimpleGraph.Reachable` for the relation of whether there exists a walk between a given pair of vertices * `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates on simple graphs for whether every vertex can be reached from every other, and in the latter case, whether the vertex type is nonempty. * `SimpleGraph.ConnectedComponent` is the type of connected components of a given graph. * `SimpleGraph.IsBridge` for whether an edge is a bridge edge ## Main statements * `SimpleGraph.isBridge_iff_mem_and_forall_cycle_not_mem` characterizes bridge edges in terms of there being no cycle containing them. ## Tags walks, trails, paths, circuits, cycles, bridge edges -/ open Function universe u v w namespace SimpleGraph variable {V : Type u} {V' : Type v} {V'' : Type w} variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'') /-- A walk is a sequence of adjacent vertices. For vertices `u v : V`, the type `walk u v` consists of all walks starting at `u` and ending at `v`. We say that a walk *visits* the vertices it contains. The set of vertices a walk visits is `SimpleGraph.Walk.support`. See `SimpleGraph.Walk.nil'` and `SimpleGraph.Walk.cons'` for patterns that can be useful in definitions since they make the vertices explicit. -/ inductive Walk : V → V → Type u | nil {u : V} : Walk u u | cons {u v w : V} (h : G.Adj u v) (p : Walk v w) : Walk u w deriving DecidableEq #align simple_graph.walk SimpleGraph.Walk attribute [refl] Walk.nil @[simps] instance Walk.instInhabited (v : V) : Inhabited (G.Walk v v) := ⟨Walk.nil⟩ #align simple_graph.walk.inhabited SimpleGraph.Walk.instInhabited /-- The one-edge walk associated to a pair of adjacent vertices. -/ @[match_pattern, reducible] def Adj.toWalk {G : SimpleGraph V} {u v : V} (h : G.Adj u v) : G.Walk u v := Walk.cons h Walk.nil #align simple_graph.adj.to_walk SimpleGraph.Adj.toWalk namespace Walk variable {G} /-- Pattern to get `Walk.nil` with the vertex as an explicit argument. -/ @[match_pattern] abbrev nil' (u : V) : G.Walk u u := Walk.nil #align simple_graph.walk.nil' SimpleGraph.Walk.nil' /-- Pattern to get `Walk.cons` with the vertices as explicit arguments. -/ @[match_pattern] abbrev cons' (u v w : V) (h : G.Adj u v) (p : G.Walk v w) : G.Walk u w := Walk.cons h p #align simple_graph.walk.cons' SimpleGraph.Walk.cons' /-- Change the endpoints of a walk using equalities. This is helpful for relaxing definitional equality constraints and to be able to state otherwise difficult-to-state lemmas. While this is a simple wrapper around `Eq.rec`, it gives a canonical way to write it. The simp-normal form is for the `copy` to be pushed outward. That way calculations can occur within the "copy context." -/ protected def copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : G.Walk u' v' := hu ▸ hv ▸ p #align simple_graph.walk.copy SimpleGraph.Walk.copy @[simp] theorem copy_rfl_rfl {u v} (p : G.Walk u v) : p.copy rfl rfl = p := rfl #align simple_graph.walk.copy_rfl_rfl SimpleGraph.Walk.copy_rfl_rfl @[simp] theorem copy_copy {u v u' v' u'' v''} (p : G.Walk u v) (hu : u = u') (hv : v = v') (hu' : u' = u'') (hv' : v' = v'') : (p.copy hu hv).copy hu' hv' = p.copy (hu.trans hu') (hv.trans hv') := by subst_vars rfl #align simple_graph.walk.copy_copy SimpleGraph.Walk.copy_copy @[simp] theorem copy_nil {u u'} (hu : u = u') : (Walk.nil : G.Walk u u).copy hu hu = Walk.nil := by subst_vars rfl #align simple_graph.walk.copy_nil SimpleGraph.Walk.copy_nil theorem copy_cons {u v w u' w'} (h : G.Adj u v) (p : G.Walk v w) (hu : u = u') (hw : w = w') : (Walk.cons h p).copy hu hw = Walk.cons (hu ▸ h) (p.copy rfl hw) := by subst_vars rfl #align simple_graph.walk.copy_cons SimpleGraph.Walk.copy_cons @[simp] theorem cons_copy {u v w v' w'} (h : G.Adj u v) (p : G.Walk v' w') (hv : v' = v) (hw : w' = w) : Walk.cons h (p.copy hv hw) = (Walk.cons (hv ▸ h) p).copy rfl hw := by subst_vars rfl #align simple_graph.walk.cons_copy SimpleGraph.Walk.cons_copy theorem exists_eq_cons_of_ne {u v : V} (hne : u ≠ v) : ∀ (p : G.Walk u v), ∃ (w : V) (h : G.Adj u w) (p' : G.Walk w v), p = cons h p' | nil => (hne rfl).elim | cons h p' => ⟨_, h, p', rfl⟩ #align simple_graph.walk.exists_eq_cons_of_ne SimpleGraph.Walk.exists_eq_cons_of_ne /-- The length of a walk is the number of edges/darts along it. -/ def length {u v : V} : G.Walk u v → ℕ | nil => 0 | cons _ q => q.length.succ #align simple_graph.walk.length SimpleGraph.Walk.length /-- The concatenation of two compatible walks. -/ @[trans] def append {u v w : V} : G.Walk u v → G.Walk v w → G.Walk u w | nil, q => q | cons h p, q => cons h (p.append q) #align simple_graph.walk.append SimpleGraph.Walk.append /-- The reversed version of `SimpleGraph.Walk.cons`, concatenating an edge to the end of a walk. -/ def concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : G.Walk u w := p.append (cons h nil) #align simple_graph.walk.concat SimpleGraph.Walk.concat theorem concat_eq_append {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : p.concat h = p.append (cons h nil) := rfl #align simple_graph.walk.concat_eq_append SimpleGraph.Walk.concat_eq_append /-- The concatenation of the reverse of the first walk with the second walk. -/ protected def reverseAux {u v w : V} : G.Walk u v → G.Walk u w → G.Walk v w | nil, q => q | cons h p, q => Walk.reverseAux p (cons (G.symm h) q) #align simple_graph.walk.reverse_aux SimpleGraph.Walk.reverseAux /-- The walk in reverse. -/ @[symm] def reverse {u v : V} (w : G.Walk u v) : G.Walk v u := w.reverseAux nil #align simple_graph.walk.reverse SimpleGraph.Walk.reverse /-- Get the `n`th vertex from a walk, where `n` is generally expected to be between `0` and `p.length`, inclusive. If `n` is greater than or equal to `p.length`, the result is the path's endpoint. -/ def getVert {u v : V} : G.Walk u v → ℕ → V | nil, _ => u | cons _ _, 0 => u | cons _ q, n + 1 => q.getVert n #align simple_graph.walk.get_vert SimpleGraph.Walk.getVert @[simp] theorem getVert_zero {u v} (w : G.Walk u v) : w.getVert 0 = u := by cases w <;> rfl #align simple_graph.walk.get_vert_zero SimpleGraph.Walk.getVert_zero theorem getVert_of_length_le {u v} (w : G.Walk u v) {i : ℕ} (hi : w.length ≤ i) : w.getVert i = v := by induction w generalizing i with | nil => rfl | cons _ _ ih => cases i · cases hi · exact ih (Nat.succ_le_succ_iff.1 hi) #align simple_graph.walk.get_vert_of_length_le SimpleGraph.Walk.getVert_of_length_le @[simp] theorem getVert_length {u v} (w : G.Walk u v) : w.getVert w.length = v := w.getVert_of_length_le rfl.le #align simple_graph.walk.get_vert_length SimpleGraph.Walk.getVert_length theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) : G.Adj (w.getVert i) (w.getVert (i + 1)) := by induction w generalizing i with | nil => cases hi | cons hxy _ ih => cases i · simp [getVert, hxy] · exact ih (Nat.succ_lt_succ_iff.1 hi) #align simple_graph.walk.adj_get_vert_succ SimpleGraph.Walk.adj_getVert_succ @[simp] theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) : (cons h p).append q = cons h (p.append q) := rfl #align simple_graph.walk.cons_append SimpleGraph.Walk.cons_append @[simp] theorem cons_nil_append {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h nil).append p = cons h p := rfl #align simple_graph.walk.cons_nil_append SimpleGraph.Walk.cons_nil_append @[simp] theorem append_nil {u v : V} (p : G.Walk u v) : p.append nil = p := by induction p with | nil => rfl | cons _ _ ih => rw [cons_append, ih] #align simple_graph.walk.append_nil SimpleGraph.Walk.append_nil @[simp] theorem nil_append {u v : V} (p : G.Walk u v) : nil.append p = p := rfl #align simple_graph.walk.nil_append SimpleGraph.Walk.nil_append theorem append_assoc {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk w x) : p.append (q.append r) = (p.append q).append r := by induction p with | nil => rfl | cons h p' ih => dsimp only [append] rw [ih] #align simple_graph.walk.append_assoc SimpleGraph.Walk.append_assoc @[simp] theorem append_copy_copy {u v w u' v' w'} (p : G.Walk u v) (q : G.Walk v w) (hu : u = u') (hv : v = v') (hw : w = w') : (p.copy hu hv).append (q.copy hv hw) = (p.append q).copy hu hw := by subst_vars rfl #align simple_graph.walk.append_copy_copy SimpleGraph.Walk.append_copy_copy theorem concat_nil {u v : V} (h : G.Adj u v) : nil.concat h = cons h nil := rfl #align simple_graph.walk.concat_nil SimpleGraph.Walk.concat_nil @[simp] theorem concat_cons {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (h' : G.Adj w x) : (cons h p).concat h' = cons h (p.concat h') := rfl #align simple_graph.walk.concat_cons SimpleGraph.Walk.concat_cons theorem append_concat {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (h : G.Adj w x) : p.append (q.concat h) = (p.append q).concat h := append_assoc _ _ _ #align simple_graph.walk.append_concat SimpleGraph.Walk.append_concat theorem concat_append {u v w x : V} (p : G.Walk u v) (h : G.Adj v w) (q : G.Walk w x) : (p.concat h).append q = p.append (cons h q) := by rw [concat_eq_append, ← append_assoc, cons_nil_append] #align simple_graph.walk.concat_append SimpleGraph.Walk.concat_append /-- A non-trivial `cons` walk is representable as a `concat` walk. -/ theorem exists_cons_eq_concat {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : ∃ (x : V) (q : G.Walk u x) (h' : G.Adj x w), cons h p = q.concat h' := by induction p generalizing u with | nil => exact ⟨_, nil, h, rfl⟩ | cons h' p ih => obtain ⟨y, q, h'', hc⟩ := ih h' refine ⟨y, cons h q, h'', ?_⟩ rw [concat_cons, hc] #align simple_graph.walk.exists_cons_eq_concat SimpleGraph.Walk.exists_cons_eq_concat /-- A non-trivial `concat` walk is representable as a `cons` walk. -/ theorem exists_concat_eq_cons {u v w : V} : ∀ (p : G.Walk u v) (h : G.Adj v w), ∃ (x : V) (h' : G.Adj u x) (q : G.Walk x w), p.concat h = cons h' q | nil, h => ⟨_, h, nil, rfl⟩ | cons h' p, h => ⟨_, h', Walk.concat p h, concat_cons _ _ _⟩ #align simple_graph.walk.exists_concat_eq_cons SimpleGraph.Walk.exists_concat_eq_cons @[simp] theorem reverse_nil {u : V} : (nil : G.Walk u u).reverse = nil := rfl #align simple_graph.walk.reverse_nil SimpleGraph.Walk.reverse_nil theorem reverse_singleton {u v : V} (h : G.Adj u v) : (cons h nil).reverse = cons (G.symm h) nil := rfl #align simple_graph.walk.reverse_singleton SimpleGraph.Walk.reverse_singleton @[simp] theorem cons_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk w x) (h : G.Adj w u) : (cons h p).reverseAux q = p.reverseAux (cons (G.symm h) q) := rfl #align simple_graph.walk.cons_reverse_aux SimpleGraph.Walk.cons_reverseAux @[simp] protected theorem append_reverseAux {u v w x : V} (p : G.Walk u v) (q : G.Walk v w) (r : G.Walk u x) : (p.append q).reverseAux r = q.reverseAux (p.reverseAux r) := by induction p with | nil => rfl | cons h _ ih => exact ih q (cons (G.symm h) r) #align simple_graph.walk.append_reverse_aux SimpleGraph.Walk.append_reverseAux @[simp] protected theorem reverseAux_append {u v w x : V} (p : G.Walk u v) (q : G.Walk u w) (r : G.Walk w x) : (p.reverseAux q).append r = p.reverseAux (q.append r) := by induction p with | nil => rfl | cons h _ ih => simp [ih (cons (G.symm h) q)] #align simple_graph.walk.reverse_aux_append SimpleGraph.Walk.reverseAux_append protected theorem reverseAux_eq_reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : p.reverseAux q = p.reverse.append q := by simp [reverse] #align simple_graph.walk.reverse_aux_eq_reverse_append SimpleGraph.Walk.reverseAux_eq_reverse_append @[simp] theorem reverse_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).reverse = p.reverse.append (cons (G.symm h) nil) := by simp [reverse] #align simple_graph.walk.reverse_cons SimpleGraph.Walk.reverse_cons @[simp] theorem reverse_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).reverse = p.reverse.copy hv hu := by subst_vars rfl #align simple_graph.walk.reverse_copy SimpleGraph.Walk.reverse_copy @[simp] theorem reverse_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).reverse = q.reverse.append p.reverse := by simp [reverse] #align simple_graph.walk.reverse_append SimpleGraph.Walk.reverse_append @[simp] theorem reverse_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).reverse = cons (G.symm h) p.reverse := by simp [concat_eq_append] #align simple_graph.walk.reverse_concat SimpleGraph.Walk.reverse_concat @[simp] theorem reverse_reverse {u v : V} (p : G.Walk u v) : p.reverse.reverse = p := by induction p with | nil => rfl | cons _ _ ih => simp [ih] #align simple_graph.walk.reverse_reverse SimpleGraph.Walk.reverse_reverse @[simp] theorem length_nil {u : V} : (nil : G.Walk u u).length = 0 := rfl #align simple_graph.walk.length_nil SimpleGraph.Walk.length_nil @[simp] theorem length_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).length = p.length + 1 := rfl #align simple_graph.walk.length_cons SimpleGraph.Walk.length_cons @[simp] theorem length_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).length = p.length := by subst_vars rfl #align simple_graph.walk.length_copy SimpleGraph.Walk.length_copy @[simp] theorem length_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : (p.append q).length = p.length + q.length := by induction p with | nil => simp | cons _ _ ih => simp [ih, add_comm, add_left_comm, add_assoc] #align simple_graph.walk.length_append SimpleGraph.Walk.length_append @[simp] theorem length_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).length = p.length + 1 := length_append _ _ #align simple_graph.walk.length_concat SimpleGraph.Walk.length_concat @[simp] protected theorem length_reverseAux {u v w : V} (p : G.Walk u v) (q : G.Walk u w) : (p.reverseAux q).length = p.length + q.length := by induction p with | nil => simp! | cons _ _ ih => simp [ih, Nat.succ_add, Nat.add_assoc] #align simple_graph.walk.length_reverse_aux SimpleGraph.Walk.length_reverseAux @[simp] theorem length_reverse {u v : V} (p : G.Walk u v) : p.reverse.length = p.length := by simp [reverse] #align simple_graph.walk.length_reverse SimpleGraph.Walk.length_reverse theorem eq_of_length_eq_zero {u v : V} : ∀ {p : G.Walk u v}, p.length = 0 → u = v | nil, _ => rfl #align simple_graph.walk.eq_of_length_eq_zero SimpleGraph.Walk.eq_of_length_eq_zero theorem adj_of_length_eq_one {u v : V} : ∀ {p : G.Walk u v}, p.length = 1 → G.Adj u v | cons h nil, _ => h @[simp] theorem exists_length_eq_zero_iff {u v : V} : (∃ p : G.Walk u v, p.length = 0) ↔ u = v := by constructor · rintro ⟨p, hp⟩ exact eq_of_length_eq_zero hp · rintro rfl exact ⟨nil, rfl⟩ #align simple_graph.walk.exists_length_eq_zero_iff SimpleGraph.Walk.exists_length_eq_zero_iff @[simp] theorem length_eq_zero_iff {u : V} {p : G.Walk u u} : p.length = 0 ↔ p = nil := by cases p <;> simp #align simple_graph.walk.length_eq_zero_iff SimpleGraph.Walk.length_eq_zero_iff theorem getVert_append {u v w : V} (p : G.Walk u v) (q : G.Walk v w) (i : ℕ) : (p.append q).getVert i = if i < p.length then p.getVert i else q.getVert (i - p.length) := by induction p generalizing i with | nil => simp | cons h p ih => cases i <;> simp [getVert, ih, Nat.succ_lt_succ_iff] theorem getVert_reverse {u v : V} (p : G.Walk u v) (i : ℕ) : p.reverse.getVert i = p.getVert (p.length - i) := by induction p with | nil => rfl | cons h p ih => simp only [reverse_cons, getVert_append, length_reverse, ih, length_cons] split_ifs next hi => rw [Nat.succ_sub hi.le] simp [getVert] next hi => obtain rfl | hi' := Nat.eq_or_lt_of_not_lt hi · simp [getVert] · rw [Nat.eq_add_of_sub_eq (Nat.sub_pos_of_lt hi') rfl, Nat.sub_eq_zero_of_le hi'] simp [getVert] section ConcatRec variable {motive : ∀ u v : V, G.Walk u v → Sort*} (Hnil : ∀ {u : V}, motive u u nil) (Hconcat : ∀ {u v w : V} (p : G.Walk u v) (h : G.Adj v w), motive u v p → motive u w (p.concat h)) /-- Auxiliary definition for `SimpleGraph.Walk.concatRec` -/ def concatRecAux {u v : V} : (p : G.Walk u v) → motive v u p.reverse | nil => Hnil | cons h p => reverse_cons h p ▸ Hconcat p.reverse h.symm (concatRecAux p) #align simple_graph.walk.concat_rec_aux SimpleGraph.Walk.concatRecAux /-- Recursor on walks by inducting on `SimpleGraph.Walk.concat`. This is inducting from the opposite end of the walk compared to `SimpleGraph.Walk.rec`, which inducts on `SimpleGraph.Walk.cons`. -/ @[elab_as_elim] def concatRec {u v : V} (p : G.Walk u v) : motive u v p := reverse_reverse p ▸ concatRecAux @Hnil @Hconcat p.reverse #align simple_graph.walk.concat_rec SimpleGraph.Walk.concatRec @[simp] theorem concatRec_nil (u : V) : @concatRec _ _ motive @Hnil @Hconcat _ _ (nil : G.Walk u u) = Hnil := rfl #align simple_graph.walk.concat_rec_nil SimpleGraph.Walk.concatRec_nil @[simp] theorem concatRec_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : @concatRec _ _ motive @Hnil @Hconcat _ _ (p.concat h) = Hconcat p h (concatRec @Hnil @Hconcat p) := by simp only [concatRec] apply eq_of_heq apply rec_heq_of_heq trans concatRecAux @Hnil @Hconcat (cons h.symm p.reverse) · congr simp · rw [concatRecAux, rec_heq_iff_heq] congr <;> simp [heq_rec_iff_heq] #align simple_graph.walk.concat_rec_concat SimpleGraph.Walk.concatRec_concat end ConcatRec theorem concat_ne_nil {u v : V} (p : G.Walk u v) (h : G.Adj v u) : p.concat h ≠ nil := by cases p <;> simp [concat] #align simple_graph.walk.concat_ne_nil SimpleGraph.Walk.concat_ne_nil theorem concat_inj {u v v' w : V} {p : G.Walk u v} {h : G.Adj v w} {p' : G.Walk u v'} {h' : G.Adj v' w} (he : p.concat h = p'.concat h') : ∃ hv : v = v', p.copy rfl hv = p' := by induction p with | nil => cases p' · exact ⟨rfl, rfl⟩ · exfalso simp only [concat_nil, concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he simp only [heq_iff_eq] at he exact concat_ne_nil _ _ he.symm | cons _ _ ih => rw [concat_cons] at he cases p' · exfalso simp only [concat_nil, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he exact concat_ne_nil _ _ he · rw [concat_cons, cons.injEq] at he obtain ⟨rfl, he⟩ := he rw [heq_iff_eq] at he obtain ⟨rfl, rfl⟩ := ih he exact ⟨rfl, rfl⟩ #align simple_graph.walk.concat_inj SimpleGraph.Walk.concat_inj /-- The `support` of a walk is the list of vertices it visits in order. -/ def support {u v : V} : G.Walk u v → List V | nil => [u] | cons _ p => u :: p.support #align simple_graph.walk.support SimpleGraph.Walk.support /-- The `darts` of a walk is the list of darts it visits in order. -/ def darts {u v : V} : G.Walk u v → List G.Dart | nil => [] | cons h p => ⟨(u, _), h⟩ :: p.darts #align simple_graph.walk.darts SimpleGraph.Walk.darts /-- The `edges` of a walk is the list of edges it visits in order. This is defined to be the list of edges underlying `SimpleGraph.Walk.darts`. -/ def edges {u v : V} (p : G.Walk u v) : List (Sym2 V) := p.darts.map Dart.edge #align simple_graph.walk.edges SimpleGraph.Walk.edges @[simp] theorem support_nil {u : V} : (nil : G.Walk u u).support = [u] := rfl #align simple_graph.walk.support_nil SimpleGraph.Walk.support_nil @[simp] theorem support_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).support = u :: p.support := rfl #align simple_graph.walk.support_cons SimpleGraph.Walk.support_cons @[simp] theorem support_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).support = p.support.concat w := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.support_concat SimpleGraph.Walk.support_concat @[simp] theorem support_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).support = p.support := by subst_vars rfl #align simple_graph.walk.support_copy SimpleGraph.Walk.support_copy theorem support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support = p.support ++ p'.support.tail := by induction p <;> cases p' <;> simp [*] #align simple_graph.walk.support_append SimpleGraph.Walk.support_append @[simp] theorem support_reverse {u v : V} (p : G.Walk u v) : p.reverse.support = p.support.reverse := by induction p <;> simp [support_append, *] #align simple_graph.walk.support_reverse SimpleGraph.Walk.support_reverse @[simp] theorem support_ne_nil {u v : V} (p : G.Walk u v) : p.support ≠ [] := by cases p <;> simp #align simple_graph.walk.support_ne_nil SimpleGraph.Walk.support_ne_nil theorem tail_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').support.tail = p.support.tail ++ p'.support.tail := by rw [support_append, List.tail_append_of_ne_nil _ _ (support_ne_nil _)] #align simple_graph.walk.tail_support_append SimpleGraph.Walk.tail_support_append theorem support_eq_cons {u v : V} (p : G.Walk u v) : p.support = u :: p.support.tail := by cases p <;> simp #align simple_graph.walk.support_eq_cons SimpleGraph.Walk.support_eq_cons @[simp] theorem start_mem_support {u v : V} (p : G.Walk u v) : u ∈ p.support := by cases p <;> simp #align simple_graph.walk.start_mem_support SimpleGraph.Walk.start_mem_support @[simp] theorem end_mem_support {u v : V} (p : G.Walk u v) : v ∈ p.support := by induction p <;> simp [*] #align simple_graph.walk.end_mem_support SimpleGraph.Walk.end_mem_support @[simp] theorem support_nonempty {u v : V} (p : G.Walk u v) : { w | w ∈ p.support }.Nonempty := ⟨u, by simp⟩ #align simple_graph.walk.support_nonempty SimpleGraph.Walk.support_nonempty theorem mem_support_iff {u v w : V} (p : G.Walk u v) : w ∈ p.support ↔ w = u ∨ w ∈ p.support.tail := by cases p <;> simp #align simple_graph.walk.mem_support_iff SimpleGraph.Walk.mem_support_iff theorem mem_support_nil_iff {u v : V} : u ∈ (nil : G.Walk v v).support ↔ u = v := by simp #align simple_graph.walk.mem_support_nil_iff SimpleGraph.Walk.mem_support_nil_iff @[simp] theorem mem_tail_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support.tail ↔ t ∈ p.support.tail ∨ t ∈ p'.support.tail := by rw [tail_support_append, List.mem_append] #align simple_graph.walk.mem_tail_support_append_iff SimpleGraph.Walk.mem_tail_support_append_iff @[simp] theorem end_mem_tail_support_of_ne {u v : V} (h : u ≠ v) (p : G.Walk u v) : v ∈ p.support.tail := by obtain ⟨_, _, _, rfl⟩ := exists_eq_cons_of_ne h p simp #align simple_graph.walk.end_mem_tail_support_of_ne SimpleGraph.Walk.end_mem_tail_support_of_ne @[simp, nolint unusedHavesSuffices] theorem mem_support_append_iff {t u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : t ∈ (p.append p').support ↔ t ∈ p.support ∨ t ∈ p'.support := by simp only [mem_support_iff, mem_tail_support_append_iff] obtain rfl | h := eq_or_ne t v <;> obtain rfl | h' := eq_or_ne t u <;> -- this `have` triggers the unusedHavesSuffices linter: (try have := h'.symm) <;> simp [*] #align simple_graph.walk.mem_support_append_iff SimpleGraph.Walk.mem_support_append_iff @[simp] theorem subset_support_append_left {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : p.support ⊆ (p.append q).support := by simp only [Walk.support_append, List.subset_append_left] #align simple_graph.walk.subset_support_append_left SimpleGraph.Walk.subset_support_append_left @[simp] theorem subset_support_append_right {V : Type u} {G : SimpleGraph V} {u v w : V} (p : G.Walk u v) (q : G.Walk v w) : q.support ⊆ (p.append q).support := by intro h simp (config := { contextual := true }) only [mem_support_append_iff, or_true_iff, imp_true_iff] #align simple_graph.walk.subset_support_append_right SimpleGraph.Walk.subset_support_append_right theorem coe_support {u v : V} (p : G.Walk u v) : (p.support : Multiset V) = {u} + p.support.tail := by cases p <;> rfl #align simple_graph.walk.coe_support SimpleGraph.Walk.coe_support theorem coe_support_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = {u} + p.support.tail + p'.support.tail := by rw [support_append, ← Multiset.coe_add, coe_support] #align simple_graph.walk.coe_support_append SimpleGraph.Walk.coe_support_append theorem coe_support_append' [DecidableEq V] {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : ((p.append p').support : Multiset V) = p.support + p'.support - {v} := by rw [support_append, ← Multiset.coe_add] simp only [coe_support] rw [add_comm ({v} : Multiset V)] simp only [← add_assoc, add_tsub_cancel_right] #align simple_graph.walk.coe_support_append' SimpleGraph.Walk.coe_support_append' theorem chain_adj_support {u v w : V} (h : G.Adj u v) : ∀ (p : G.Walk v w), List.Chain G.Adj u p.support | nil => List.Chain.cons h List.Chain.nil | cons h' p => List.Chain.cons h (chain_adj_support h' p) #align simple_graph.walk.chain_adj_support SimpleGraph.Walk.chain_adj_support theorem chain'_adj_support {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.Adj p.support | nil => List.Chain.nil | cons h p => chain_adj_support h p #align simple_graph.walk.chain'_adj_support SimpleGraph.Walk.chain'_adj_support theorem chain_dartAdj_darts {d : G.Dart} {v w : V} (h : d.snd = v) (p : G.Walk v w) : List.Chain G.DartAdj d p.darts := by induction p generalizing d with | nil => exact List.Chain.nil -- Porting note: needed to defer `h` and `rfl` to help elaboration | cons h' p ih => exact List.Chain.cons (by exact h) (ih (by rfl)) #align simple_graph.walk.chain_dart_adj_darts SimpleGraph.Walk.chain_dartAdj_darts theorem chain'_dartAdj_darts {u v : V} : ∀ (p : G.Walk u v), List.Chain' G.DartAdj p.darts | nil => trivial -- Porting note: needed to defer `rfl` to help elaboration | cons h p => chain_dartAdj_darts (by rfl) p #align simple_graph.walk.chain'_dart_adj_darts SimpleGraph.Walk.chain'_dartAdj_darts /-- Every edge in a walk's edge list is an edge of the graph. It is written in this form (rather than using `⊆`) to avoid unsightly coercions. -/ theorem edges_subset_edgeSet {u v : V} : ∀ (p : G.Walk u v) ⦃e : Sym2 V⦄, e ∈ p.edges → e ∈ G.edgeSet | cons h' p', e, h => by cases h · exact h' next h' => exact edges_subset_edgeSet p' h' #align simple_graph.walk.edges_subset_edge_set SimpleGraph.Walk.edges_subset_edgeSet theorem adj_of_mem_edges {u v x y : V} (p : G.Walk u v) (h : s(x, y) ∈ p.edges) : G.Adj x y := edges_subset_edgeSet p h #align simple_graph.walk.adj_of_mem_edges SimpleGraph.Walk.adj_of_mem_edges @[simp] theorem darts_nil {u : V} : (nil : G.Walk u u).darts = [] := rfl #align simple_graph.walk.darts_nil SimpleGraph.Walk.darts_nil @[simp] theorem darts_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).darts = ⟨(u, v), h⟩ :: p.darts := rfl #align simple_graph.walk.darts_cons SimpleGraph.Walk.darts_cons @[simp] theorem darts_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).darts = p.darts.concat ⟨(v, w), h⟩ := by induction p <;> simp [*, concat_nil] #align simple_graph.walk.darts_concat SimpleGraph.Walk.darts_concat @[simp] theorem darts_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).darts = p.darts := by subst_vars rfl #align simple_graph.walk.darts_copy SimpleGraph.Walk.darts_copy @[simp] theorem darts_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').darts = p.darts ++ p'.darts := by induction p <;> simp [*] #align simple_graph.walk.darts_append SimpleGraph.Walk.darts_append @[simp] theorem darts_reverse {u v : V} (p : G.Walk u v) : p.reverse.darts = (p.darts.map Dart.symm).reverse := by induction p <;> simp [*, Sym2.eq_swap] #align simple_graph.walk.darts_reverse SimpleGraph.Walk.darts_reverse theorem mem_darts_reverse {u v : V} {d : G.Dart} {p : G.Walk u v} : d ∈ p.reverse.darts ↔ d.symm ∈ p.darts := by simp #align simple_graph.walk.mem_darts_reverse SimpleGraph.Walk.mem_darts_reverse theorem cons_map_snd_darts {u v : V} (p : G.Walk u v) : (u :: p.darts.map (·.snd)) = p.support := by induction p <;> simp! [*] #align simple_graph.walk.cons_map_snd_darts SimpleGraph.Walk.cons_map_snd_darts theorem map_snd_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.snd) = p.support.tail := by simpa using congr_arg List.tail (cons_map_snd_darts p) #align simple_graph.walk.map_snd_darts SimpleGraph.Walk.map_snd_darts theorem map_fst_darts_append {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) ++ [v] = p.support := by induction p <;> simp! [*] #align simple_graph.walk.map_fst_darts_append SimpleGraph.Walk.map_fst_darts_append theorem map_fst_darts {u v : V} (p : G.Walk u v) : p.darts.map (·.fst) = p.support.dropLast := by simpa! using congr_arg List.dropLast (map_fst_darts_append p) #align simple_graph.walk.map_fst_darts SimpleGraph.Walk.map_fst_darts @[simp] theorem edges_nil {u : V} : (nil : G.Walk u u).edges = [] := rfl #align simple_graph.walk.edges_nil SimpleGraph.Walk.edges_nil @[simp] theorem edges_cons {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).edges = s(u, v) :: p.edges := rfl #align simple_graph.walk.edges_cons SimpleGraph.Walk.edges_cons @[simp] theorem edges_concat {u v w : V} (p : G.Walk u v) (h : G.Adj v w) : (p.concat h).edges = p.edges.concat s(v, w) := by simp [edges] #align simple_graph.walk.edges_concat SimpleGraph.Walk.edges_concat @[simp] theorem edges_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).edges = p.edges := by subst_vars rfl #align simple_graph.walk.edges_copy SimpleGraph.Walk.edges_copy @[simp] theorem edges_append {u v w : V} (p : G.Walk u v) (p' : G.Walk v w) : (p.append p').edges = p.edges ++ p'.edges := by simp [edges] #align simple_graph.walk.edges_append SimpleGraph.Walk.edges_append @[simp] theorem edges_reverse {u v : V} (p : G.Walk u v) : p.reverse.edges = p.edges.reverse := by simp [edges, List.map_reverse] #align simple_graph.walk.edges_reverse SimpleGraph.Walk.edges_reverse @[simp] theorem length_support {u v : V} (p : G.Walk u v) : p.support.length = p.length + 1 := by induction p <;> simp [*] #align simple_graph.walk.length_support SimpleGraph.Walk.length_support @[simp] theorem length_darts {u v : V} (p : G.Walk u v) : p.darts.length = p.length := by induction p <;> simp [*] #align simple_graph.walk.length_darts SimpleGraph.Walk.length_darts @[simp] theorem length_edges {u v : V} (p : G.Walk u v) : p.edges.length = p.length := by simp [edges] #align simple_graph.walk.length_edges SimpleGraph.Walk.length_edges theorem dart_fst_mem_support_of_mem_darts {u v : V} : ∀ (p : G.Walk u v) {d : G.Dart}, d ∈ p.darts → d.fst ∈ p.support | cons h p', d, hd => by simp only [support_cons, darts_cons, List.mem_cons] at hd ⊢ rcases hd with (rfl | hd) · exact Or.inl rfl · exact Or.inr (dart_fst_mem_support_of_mem_darts _ hd) #align simple_graph.walk.dart_fst_mem_support_of_mem_darts SimpleGraph.Walk.dart_fst_mem_support_of_mem_darts theorem dart_snd_mem_support_of_mem_darts {u v : V} (p : G.Walk u v) {d : G.Dart} (h : d ∈ p.darts) : d.snd ∈ p.support := by simpa using p.reverse.dart_fst_mem_support_of_mem_darts (by simp [h] : d.symm ∈ p.reverse.darts) #align simple_graph.walk.dart_snd_mem_support_of_mem_darts SimpleGraph.Walk.dart_snd_mem_support_of_mem_darts theorem fst_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : t ∈ p.support := by obtain ⟨d, hd, he⟩ := List.mem_map.mp he rw [dart_edge_eq_mk'_iff'] at he rcases he with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) · exact dart_fst_mem_support_of_mem_darts _ hd · exact dart_snd_mem_support_of_mem_darts _ hd #align simple_graph.walk.fst_mem_support_of_mem_edges SimpleGraph.Walk.fst_mem_support_of_mem_edges theorem snd_mem_support_of_mem_edges {t u v w : V} (p : G.Walk v w) (he : s(t, u) ∈ p.edges) : u ∈ p.support := by rw [Sym2.eq_swap] at he exact p.fst_mem_support_of_mem_edges he #align simple_graph.walk.snd_mem_support_of_mem_edges SimpleGraph.Walk.snd_mem_support_of_mem_edges theorem darts_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.darts.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [darts_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (dart_fst_mem_support_of_mem_darts p' h'), ih h.2⟩ #align simple_graph.walk.darts_nodup_of_support_nodup SimpleGraph.Walk.darts_nodup_of_support_nodup theorem edges_nodup_of_support_nodup {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.edges.Nodup := by induction p with | nil => simp | cons _ p' ih => simp only [edges_cons, support_cons, List.nodup_cons] at h ⊢ exact ⟨fun h' => h.1 (fst_mem_support_of_mem_edges p' h'), ih h.2⟩ #align simple_graph.walk.edges_nodup_of_support_nodup SimpleGraph.Walk.edges_nodup_of_support_nodup /-- Predicate for the empty walk. Solves the dependent type problem where `p = G.Walk.nil` typechecks only if `p` has defeq endpoints. -/ inductive Nil : {v w : V} → G.Walk v w → Prop | nil {u : V} : Nil (nil : G.Walk u u) variable {u v w : V} @[simp] lemma nil_nil : (nil : G.Walk u u).Nil := Nil.nil @[simp] lemma not_nil_cons {h : G.Adj u v} {p : G.Walk v w} : ¬ (cons h p).Nil := nofun instance (p : G.Walk v w) : Decidable p.Nil := match p with | nil => isTrue .nil | cons _ _ => isFalse nofun protected lemma Nil.eq {p : G.Walk v w} : p.Nil → v = w | .nil => rfl lemma not_nil_of_ne {p : G.Walk v w} : v ≠ w → ¬ p.Nil := mt Nil.eq lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by cases p <;> simp lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by cases p <;> simp lemma not_nil_iff {p : G.Walk v w} : ¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by cases p <;> simp [*] /-- A walk with its endpoints defeq is `Nil` if and only if it is equal to `nil`. -/ lemma nil_iff_eq_nil : ∀ {p : G.Walk v v}, p.Nil ↔ p = nil | .nil | .cons _ _ => by simp alias ⟨Nil.eq_nil, _⟩ := nil_iff_eq_nil @[elab_as_elim] def notNilRec {motive : {u w : V} → (p : G.Walk u w) → (h : ¬ p.Nil) → Sort*} (cons : {u v w : V} → (h : G.Adj u v) → (q : G.Walk v w) → motive (cons h q) not_nil_cons) (p : G.Walk u w) : (hp : ¬ p.Nil) → motive p hp := match p with | nil => fun hp => absurd .nil hp | .cons h q => fun _ => cons h q /-- The second vertex along a non-nil walk. -/ def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil) : V := p.notNilRec (@fun _ u _ _ _ => u) hp @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) : G.Adj v (p.sndOfNotNil hp) := p.notNilRec (fun h _ => h) hp /-- The walk obtained by removing the first dart of a non-nil walk. -/ def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v := p.notNilRec (fun _ q => q) hp /-- The first dart of a walk. -/ @[simps] def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where fst := v snd := p.sndOfNotNil hp adj := p.adj_sndOfNotNil hp lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : (p.firstDart hp).edge = s(v, p.sndOfNotNil hp) := rfl variable {x y : V} -- TODO: rename to u, v, w instead? @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) : cons (p.adj_sndOfNotNil hp) (p.tail hp) = p := p.notNilRec (fun _ _ => rfl) hp @[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) : x :: (p.tail hp).support = p.support := by rw [← support_cons, cons_tail_eq] @[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) : (p.tail hp).length + 1 = p.length := by rw [← length_cons, cons_tail_eq] @[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') : (p.copy hx hy).Nil = p.Nil := by subst_vars; rfl @[simp] lemma support_tail (p : G.Walk v v) (hp) : (p.tail hp).support = p.support.tail := by rw [← cons_support_tail p hp, List.tail_cons] /-! ### Trails, paths, circuits, cycles -/ /-- A *trail* is a walk with no repeating edges. -/ @[mk_iff isTrail_def] structure IsTrail {u v : V} (p : G.Walk u v) : Prop where edges_nodup : p.edges.Nodup #align simple_graph.walk.is_trail SimpleGraph.Walk.IsTrail #align simple_graph.walk.is_trail_def SimpleGraph.Walk.isTrail_def /-- A *path* is a walk with no repeating vertices. Use `SimpleGraph.Walk.IsPath.mk'` for a simpler constructor. -/ structure IsPath {u v : V} (p : G.Walk u v) extends IsTrail p : Prop where support_nodup : p.support.Nodup #align simple_graph.walk.is_path SimpleGraph.Walk.IsPath -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsPath.isTrail {p : Walk G u v}(h : IsPath p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_path.to_trail SimpleGraph.Walk.IsPath.isTrail /-- A *circuit* at `u : V` is a nonempty trail beginning and ending at `u`. -/ @[mk_iff isCircuit_def] structure IsCircuit {u : V} (p : G.Walk u u) extends IsTrail p : Prop where ne_nil : p ≠ nil #align simple_graph.walk.is_circuit SimpleGraph.Walk.IsCircuit #align simple_graph.walk.is_circuit_def SimpleGraph.Walk.isCircuit_def -- Porting note: used to use `extends to_trail : is_trail p` in structure protected lemma IsCircuit.isTrail {p : Walk G u u} (h : IsCircuit p) : IsTrail p := h.toIsTrail #align simple_graph.walk.is_circuit.to_trail SimpleGraph.Walk.IsCircuit.isTrail /-- A *cycle* at `u : V` is a circuit at `u` whose only repeating vertex is `u` (which appears exactly twice). -/ structure IsCycle {u : V} (p : G.Walk u u) extends IsCircuit p : Prop where support_nodup : p.support.tail.Nodup #align simple_graph.walk.is_cycle SimpleGraph.Walk.IsCycle -- Porting note: used to use `extends to_circuit : is_circuit p` in structure protected lemma IsCycle.isCircuit {p : Walk G u u} (h : IsCycle p) : IsCircuit p := h.toIsCircuit #align simple_graph.walk.is_cycle.to_circuit SimpleGraph.Walk.IsCycle.isCircuit @[simp] theorem isTrail_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsTrail ↔ p.IsTrail := by subst_vars rfl #align simple_graph.walk.is_trail_copy SimpleGraph.Walk.isTrail_copy theorem IsPath.mk' {u v : V} {p : G.Walk u v} (h : p.support.Nodup) : p.IsPath := ⟨⟨edges_nodup_of_support_nodup h⟩, h⟩ #align simple_graph.walk.is_path.mk' SimpleGraph.Walk.IsPath.mk' theorem isPath_def {u v : V} (p : G.Walk u v) : p.IsPath ↔ p.support.Nodup := ⟨IsPath.support_nodup, IsPath.mk'⟩ #align simple_graph.walk.is_path_def SimpleGraph.Walk.isPath_def @[simp] theorem isPath_copy {u v u' v'} (p : G.Walk u v) (hu : u = u') (hv : v = v') : (p.copy hu hv).IsPath ↔ p.IsPath := by subst_vars rfl #align simple_graph.walk.is_path_copy SimpleGraph.Walk.isPath_copy @[simp] theorem isCircuit_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCircuit ↔ p.IsCircuit := by subst_vars rfl #align simple_graph.walk.is_circuit_copy SimpleGraph.Walk.isCircuit_copy lemma IsCircuit.not_nil {p : G.Walk v v} (hp : IsCircuit p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) theorem isCycle_def {u : V} (p : G.Walk u u) : p.IsCycle ↔ p.IsTrail ∧ p ≠ nil ∧ p.support.tail.Nodup := Iff.intro (fun h => ⟨h.1.1, h.1.2, h.2⟩) fun h => ⟨⟨h.1, h.2.1⟩, h.2.2⟩ #align simple_graph.walk.is_cycle_def SimpleGraph.Walk.isCycle_def @[simp] theorem isCycle_copy {u u'} (p : G.Walk u u) (hu : u = u') : (p.copy hu hu).IsCycle ↔ p.IsCycle := by subst_vars rfl #align simple_graph.walk.is_cycle_copy SimpleGraph.Walk.isCycle_copy lemma IsCycle.not_nil {p : G.Walk v v} (hp : IsCycle p) : ¬ p.Nil := (hp.ne_nil ·.eq_nil) @[simp] theorem IsTrail.nil {u : V} : (nil : G.Walk u u).IsTrail := ⟨by simp [edges]⟩ #align simple_graph.walk.is_trail.nil SimpleGraph.Walk.IsTrail.nil theorem IsTrail.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsTrail → p.IsTrail := by simp [isTrail_def] #align simple_graph.walk.is_trail.of_cons SimpleGraph.Walk.IsTrail.of_cons @[simp] theorem cons_isTrail_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsTrail ↔ p.IsTrail ∧ s(u, v) ∉ p.edges := by simp [isTrail_def, and_comm] #align simple_graph.walk.cons_is_trail_iff SimpleGraph.Walk.cons_isTrail_iff theorem IsTrail.reverse {u v : V} (p : G.Walk u v) (h : p.IsTrail) : p.reverse.IsTrail := by simpa [isTrail_def] using h #align simple_graph.walk.is_trail.reverse SimpleGraph.Walk.IsTrail.reverse @[simp] theorem reverse_isTrail_iff {u v : V} (p : G.Walk u v) : p.reverse.IsTrail ↔ p.IsTrail := by constructor <;> · intro h convert h.reverse _ try rw [reverse_reverse] #align simple_graph.walk.reverse_is_trail_iff SimpleGraph.Walk.reverse_isTrail_iff theorem IsTrail.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : p.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.1⟩ #align simple_graph.walk.is_trail.of_append_left SimpleGraph.Walk.IsTrail.of_append_left theorem IsTrail.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsTrail) : q.IsTrail := by rw [isTrail_def, edges_append, List.nodup_append] at h exact ⟨h.2.1⟩ #align simple_graph.walk.is_trail.of_append_right SimpleGraph.Walk.IsTrail.of_append_right theorem IsTrail.count_edges_le_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) (e : Sym2 V) : p.edges.count e ≤ 1 := List.nodup_iff_count_le_one.mp h.edges_nodup e #align simple_graph.walk.is_trail.count_edges_le_one SimpleGraph.Walk.IsTrail.count_edges_le_one theorem IsTrail.count_edges_eq_one [DecidableEq V] {u v : V} {p : G.Walk u v} (h : p.IsTrail) {e : Sym2 V} (he : e ∈ p.edges) : p.edges.count e = 1 := List.count_eq_one_of_mem h.edges_nodup he #align simple_graph.walk.is_trail.count_edges_eq_one SimpleGraph.Walk.IsTrail.count_edges_eq_one theorem IsPath.nil {u : V} : (nil : G.Walk u u).IsPath := by constructor <;> simp #align simple_graph.walk.is_path.nil SimpleGraph.Walk.IsPath.nil theorem IsPath.of_cons {u v w : V} {h : G.Adj u v} {p : G.Walk v w} : (cons h p).IsPath → p.IsPath := by simp [isPath_def] #align simple_graph.walk.is_path.of_cons SimpleGraph.Walk.IsPath.of_cons @[simp] theorem cons_isPath_iff {u v w : V} (h : G.Adj u v) (p : G.Walk v w) : (cons h p).IsPath ↔ p.IsPath ∧ u ∉ p.support := by constructor <;> simp (config := { contextual := true }) [isPath_def] #align simple_graph.walk.cons_is_path_iff SimpleGraph.Walk.cons_isPath_iff protected lemma IsPath.cons {p : Walk G v w} (hp : p.IsPath) (hu : u ∉ p.support) {h : G.Adj u v} : (cons h p).IsPath := (cons_isPath_iff _ _).2 ⟨hp, hu⟩ @[simp] theorem isPath_iff_eq_nil {u : V} (p : G.Walk u u) : p.IsPath ↔ p = nil := by cases p <;> simp [IsPath.nil] #align simple_graph.walk.is_path_iff_eq_nil SimpleGraph.Walk.isPath_iff_eq_nil theorem IsPath.reverse {u v : V} {p : G.Walk u v} (h : p.IsPath) : p.reverse.IsPath := by simpa [isPath_def] using h #align simple_graph.walk.is_path.reverse SimpleGraph.Walk.IsPath.reverse @[simp] theorem isPath_reverse_iff {u v : V} (p : G.Walk u v) : p.reverse.IsPath ↔ p.IsPath := by constructor <;> intro h <;> convert h.reverse; simp #align simple_graph.walk.is_path_reverse_iff SimpleGraph.Walk.isPath_reverse_iff theorem IsPath.of_append_left {u v w : V} {p : G.Walk u v} {q : G.Walk v w} : (p.append q).IsPath → p.IsPath := by simp only [isPath_def, support_append] exact List.Nodup.of_append_left #align simple_graph.walk.is_path.of_append_left SimpleGraph.Walk.IsPath.of_append_left theorem IsPath.of_append_right {u v w : V} {p : G.Walk u v} {q : G.Walk v w} (h : (p.append q).IsPath) : q.IsPath := by rw [← isPath_reverse_iff] at h ⊢ rw [reverse_append] at h apply h.of_append_left #align simple_graph.walk.is_path.of_append_right SimpleGraph.Walk.IsPath.of_append_right @[simp] theorem IsCycle.not_of_nil {u : V} : ¬(nil : G.Walk u u).IsCycle := fun h => h.ne_nil rfl #align simple_graph.walk.is_cycle.not_of_nil SimpleGraph.Walk.IsCycle.not_of_nil lemma IsCycle.ne_bot : ∀ {p : G.Walk u u}, p.IsCycle → G ≠ ⊥ | nil, hp => by cases hp.ne_nil rfl | cons h _, hp => by rintro rfl; exact h lemma IsCycle.three_le_length {v : V} {p : G.Walk v v} (hp : p.IsCycle) : 3 ≤ p.length := by have ⟨⟨hp, hp'⟩, _⟩ := hp match p with | .nil => simp at hp' | .cons h .nil => simp at h | .cons _ (.cons _ .nil) => simp at hp | .cons _ (.cons _ (.cons _ _)) => simp_rw [SimpleGraph.Walk.length_cons]; omega theorem cons_isCycle_iff {u v : V} (p : G.Walk v u) (h : G.Adj u v) : (Walk.cons h p).IsCycle ↔ p.IsPath ∧ ¬s(u, v) ∈ p.edges := by simp only [Walk.isCycle_def, Walk.isPath_def, Walk.isTrail_def, edges_cons, List.nodup_cons, support_cons, List.tail_cons] have : p.support.Nodup → p.edges.Nodup := edges_nodup_of_support_nodup tauto #align simple_graph.walk.cons_is_cycle_iff SimpleGraph.Walk.cons_isCycle_iff lemma IsPath.tail {p : G.Walk u v} (hp : p.IsPath) (hp' : ¬ p.Nil) : (p.tail hp').IsPath := by rw [Walk.isPath_def] at hp ⊢ rw [← cons_support_tail _ hp', List.nodup_cons] at hp exact hp.2 /-! ### About paths -/ instance [DecidableEq V] {u v : V} (p : G.Walk u v) : Decidable p.IsPath := by rw [isPath_def] infer_instance theorem IsPath.length_lt [Fintype V] {u v : V} {p : G.Walk u v} (hp : p.IsPath) : p.length < Fintype.card V := by rw [Nat.lt_iff_add_one_le, ← length_support] exact hp.support_nodup.length_le_card #align simple_graph.walk.is_path.length_lt SimpleGraph.Walk.IsPath.length_lt /-! ### Walk decompositions -/ section WalkDecomp variable [DecidableEq V] /-- Given a vertex in the support of a path, give the path up until (and including) that vertex. -/ def takeUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk v u | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u; exact Walk.nil else cons r (takeUntil p u <| by cases h · exact (hx rfl).elim · assumption) #align simple_graph.walk.take_until SimpleGraph.Walk.takeUntil /-- Given a vertex in the support of a path, give the path from (and including) that vertex to the end. In other words, drop vertices from the front of a path until (and not including) that vertex. -/ def dropUntil {v w : V} : ∀ (p : G.Walk v w) (u : V), u ∈ p.support → G.Walk u w | nil, u, h => by rw [mem_support_nil_iff.mp h] | cons r p, u, h => if hx : v = u then by subst u exact cons r p else dropUntil p u <| by cases h · exact (hx rfl).elim · assumption #align simple_graph.walk.drop_until SimpleGraph.Walk.dropUntil /-- The `takeUntil` and `dropUntil` functions split a walk into two pieces. The lemma `SimpleGraph.Walk.count_support_takeUntil_eq_one` specifies where this split occurs. -/ @[simp] theorem take_spec {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).append (p.dropUntil u h) = p := by induction p · rw [mem_support_nil_iff] at h subst u rfl · cases h · simp! · simp! only split_ifs with h' <;> subst_vars <;> simp [*] #align simple_graph.walk.take_spec SimpleGraph.Walk.take_spec theorem mem_support_iff_exists_append {V : Type u} {G : SimpleGraph V} {u v w : V} {p : G.Walk u v} : w ∈ p.support ↔ ∃ (q : G.Walk u w) (r : G.Walk w v), p = q.append r := by classical constructor · exact fun h => ⟨_, _, (p.take_spec h).symm⟩ · rintro ⟨q, r, rfl⟩ simp only [mem_support_append_iff, end_mem_support, start_mem_support, or_self_iff] #align simple_graph.walk.mem_support_iff_exists_append SimpleGraph.Walk.mem_support_iff_exists_append @[simp]
Mathlib/Combinatorics/SimpleGraph/Connectivity.lean
1,216
1,225
theorem count_support_takeUntil_eq_one {u v w : V} (p : G.Walk v w) (h : u ∈ p.support) : (p.takeUntil u h).support.count u = 1 := by
induction p · rw [mem_support_nil_iff] at h subst u simp! · cases h · simp! · simp! only split_ifs with h' <;> rw [eq_comm] at h' <;> subst_vars <;> simp! [*, List.count_cons]
/- 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.Order.Interval.Set.Basic import Mathlib.Data.Set.NAry import Mathlib.Order.Directed #align_import order.bounds.basic from "leanprover-community/mathlib"@"b1abe23ae96fef89ad30d9f4362c307f72a55010" /-! # Upper / lower bounds In this file we define: * `upperBounds`, `lowerBounds` : the set of upper bounds (resp., lower bounds) of a set; * `BddAbove s`, `BddBelow s` : the set `s` is bounded above (resp., below), i.e., the set of upper (resp., lower) bounds of `s` is nonempty; * `IsLeast s a`, `IsGreatest s a` : `a` is a least (resp., greatest) element of `s`; for a partial order, it is unique if exists; * `IsLUB s a`, `IsGLB s a` : `a` is a least upper bound (resp., a greatest lower bound) of `s`; for a partial order, it is unique if exists. We also prove various lemmas about monotonicity, behaviour under `∪`, `∩`, `insert`, and provide formulas for `∅`, `univ`, and intervals. -/ open Function Set open OrderDual (toDual ofDual) universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} section variable [Preorder α] [Preorder β] {s t : Set α} {a b : α} /-! ### Definitions -/ /-- The set of upper bounds of a set. -/ def upperBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → a ≤ x } #align upper_bounds upperBounds /-- The set of lower bounds of a set. -/ def lowerBounds (s : Set α) : Set α := { x | ∀ ⦃a⦄, a ∈ s → x ≤ a } #align lower_bounds lowerBounds /-- A set is bounded above if there exists an upper bound. -/ def BddAbove (s : Set α) := (upperBounds s).Nonempty #align bdd_above BddAbove /-- A set is bounded below if there exists a lower bound. -/ def BddBelow (s : Set α) := (lowerBounds s).Nonempty #align bdd_below BddBelow /-- `a` is a least element of a set `s`; for a partial order, it is unique if exists. -/ def IsLeast (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ lowerBounds s #align is_least IsLeast /-- `a` is a greatest element of a set `s`; for a partial order, it is unique if exists. -/ def IsGreatest (s : Set α) (a : α) : Prop := a ∈ s ∧ a ∈ upperBounds s #align is_greatest IsGreatest /-- `a` is a least upper bound of a set `s`; for a partial order, it is unique if exists. -/ def IsLUB (s : Set α) : α → Prop := IsLeast (upperBounds s) #align is_lub IsLUB /-- `a` is a greatest lower bound of a set `s`; for a partial order, it is unique if exists. -/ def IsGLB (s : Set α) : α → Prop := IsGreatest (lowerBounds s) #align is_glb IsGLB theorem mem_upperBounds : a ∈ upperBounds s ↔ ∀ x ∈ s, x ≤ a := Iff.rfl #align mem_upper_bounds mem_upperBounds theorem mem_lowerBounds : a ∈ lowerBounds s ↔ ∀ x ∈ s, a ≤ x := Iff.rfl #align mem_lower_bounds mem_lowerBounds lemma mem_upperBounds_iff_subset_Iic : a ∈ upperBounds s ↔ s ⊆ Iic a := Iff.rfl #align mem_upper_bounds_iff_subset_Iic mem_upperBounds_iff_subset_Iic lemma mem_lowerBounds_iff_subset_Ici : a ∈ lowerBounds s ↔ s ⊆ Ici a := Iff.rfl #align mem_lower_bounds_iff_subset_Ici mem_lowerBounds_iff_subset_Ici theorem bddAbove_def : BddAbove s ↔ ∃ x, ∀ y ∈ s, y ≤ x := Iff.rfl #align bdd_above_def bddAbove_def theorem bddBelow_def : BddBelow s ↔ ∃ x, ∀ y ∈ s, x ≤ y := Iff.rfl #align bdd_below_def bddBelow_def theorem bot_mem_lowerBounds [OrderBot α] (s : Set α) : ⊥ ∈ lowerBounds s := fun _ _ => bot_le #align bot_mem_lower_bounds bot_mem_lowerBounds theorem top_mem_upperBounds [OrderTop α] (s : Set α) : ⊤ ∈ upperBounds s := fun _ _ => le_top #align top_mem_upper_bounds top_mem_upperBounds @[simp] theorem isLeast_bot_iff [OrderBot α] : IsLeast s ⊥ ↔ ⊥ ∈ s := and_iff_left <| bot_mem_lowerBounds _ #align is_least_bot_iff isLeast_bot_iff @[simp] theorem isGreatest_top_iff [OrderTop α] : IsGreatest s ⊤ ↔ ⊤ ∈ s := and_iff_left <| top_mem_upperBounds _ #align is_greatest_top_iff isGreatest_top_iff /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` such that `x` is not greater than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(y ≤ x)`. A version for linear orders is called `not_bddAbove_iff`. -/ theorem not_bddAbove_iff' : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, ¬y ≤ x := by simp [BddAbove, upperBounds, Set.Nonempty] #align not_bdd_above_iff' not_bddAbove_iff' /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` such that `x` is not less than or equal to `y`. This version only assumes `Preorder` structure and uses `¬(x ≤ y)`. A version for linear orders is called `not_bddBelow_iff`. -/ theorem not_bddBelow_iff' : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, ¬x ≤ y := @not_bddAbove_iff' αᵒᵈ _ _ #align not_bdd_below_iff' not_bddBelow_iff' /-- A set `s` is not bounded above if and only if for each `x` there exists `y ∈ s` that is greater than `x`. A version for preorders is called `not_bddAbove_iff'`. -/ theorem not_bddAbove_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddAbove s ↔ ∀ x, ∃ y ∈ s, x < y := by simp only [not_bddAbove_iff', not_le] #align not_bdd_above_iff not_bddAbove_iff /-- A set `s` is not bounded below if and only if for each `x` there exists `y ∈ s` that is less than `x`. A version for preorders is called `not_bddBelow_iff'`. -/ theorem not_bddBelow_iff {α : Type*} [LinearOrder α] {s : Set α} : ¬BddBelow s ↔ ∀ x, ∃ y ∈ s, y < x := @not_bddAbove_iff αᵒᵈ _ _ #align not_bdd_below_iff not_bddBelow_iff @[simp] lemma bddBelow_preimage_ofDual {s : Set α} : BddBelow (ofDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_ofDual {s : Set α} : BddAbove (ofDual ⁻¹' s) ↔ BddBelow s := Iff.rfl @[simp] lemma bddBelow_preimage_toDual {s : Set αᵒᵈ} : BddBelow (toDual ⁻¹' s) ↔ BddAbove s := Iff.rfl @[simp] lemma bddAbove_preimage_toDual {s : Set αᵒᵈ} : BddAbove (toDual ⁻¹' s) ↔ BddBelow s := Iff.rfl theorem BddAbove.dual (h : BddAbove s) : BddBelow (ofDual ⁻¹' s) := h #align bdd_above.dual BddAbove.dual theorem BddBelow.dual (h : BddBelow s) : BddAbove (ofDual ⁻¹' s) := h #align bdd_below.dual BddBelow.dual theorem IsLeast.dual (h : IsLeast s a) : IsGreatest (ofDual ⁻¹' s) (toDual a) := h #align is_least.dual IsLeast.dual theorem IsGreatest.dual (h : IsGreatest s a) : IsLeast (ofDual ⁻¹' s) (toDual a) := h #align is_greatest.dual IsGreatest.dual theorem IsLUB.dual (h : IsLUB s a) : IsGLB (ofDual ⁻¹' s) (toDual a) := h #align is_lub.dual IsLUB.dual theorem IsGLB.dual (h : IsGLB s a) : IsLUB (ofDual ⁻¹' s) (toDual a) := h #align is_glb.dual IsGLB.dual /-- If `a` is the least element of a set `s`, then subtype `s` is an order with bottom element. -/ abbrev IsLeast.orderBot (h : IsLeast s a) : OrderBot s where bot := ⟨a, h.1⟩ bot_le := Subtype.forall.2 h.2 #align is_least.order_bot IsLeast.orderBot /-- If `a` is the greatest element of a set `s`, then subtype `s` is an order with top element. -/ abbrev IsGreatest.orderTop (h : IsGreatest s a) : OrderTop s where top := ⟨a, h.1⟩ le_top := Subtype.forall.2 h.2 #align is_greatest.order_top IsGreatest.orderTop /-! ### Monotonicity -/ theorem upperBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : upperBounds t ⊆ upperBounds s := fun _ hb _ h => hb <| hst h #align upper_bounds_mono_set upperBounds_mono_set theorem lowerBounds_mono_set ⦃s t : Set α⦄ (hst : s ⊆ t) : lowerBounds t ⊆ lowerBounds s := fun _ hb _ h => hb <| hst h #align lower_bounds_mono_set lowerBounds_mono_set theorem upperBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds s → b ∈ upperBounds s := fun ha _ h => le_trans (ha h) hab #align upper_bounds_mono_mem upperBounds_mono_mem theorem lowerBounds_mono_mem ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds s → a ∈ lowerBounds s := fun hb _ h => le_trans hab (hb h) #align lower_bounds_mono_mem lowerBounds_mono_mem theorem upperBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : a ∈ upperBounds t → b ∈ upperBounds s := fun ha => upperBounds_mono_set hst <| upperBounds_mono_mem hab ha #align upper_bounds_mono upperBounds_mono theorem lowerBounds_mono ⦃s t : Set α⦄ (hst : s ⊆ t) ⦃a b⦄ (hab : a ≤ b) : b ∈ lowerBounds t → a ∈ lowerBounds s := fun hb => lowerBounds_mono_set hst <| lowerBounds_mono_mem hab hb #align lower_bounds_mono lowerBounds_mono /-- If `s ⊆ t` and `t` is bounded above, then so is `s`. -/ theorem BddAbove.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddAbove t → BddAbove s := Nonempty.mono <| upperBounds_mono_set h #align bdd_above.mono BddAbove.mono /-- If `s ⊆ t` and `t` is bounded below, then so is `s`. -/ theorem BddBelow.mono ⦃s t : Set α⦄ (h : s ⊆ t) : BddBelow t → BddBelow s := Nonempty.mono <| lowerBounds_mono_set h #align bdd_below.mono BddBelow.mono /-- If `a` is a least upper bound for sets `s` and `p`, then it is a least upper bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsLUB.of_subset_of_superset {s t p : Set α} (hs : IsLUB s a) (hp : IsLUB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsLUB t a := ⟨upperBounds_mono_set htp hp.1, lowerBounds_mono_set (upperBounds_mono_set hst) hs.2⟩ #align is_lub.of_subset_of_superset IsLUB.of_subset_of_superset /-- If `a` is a greatest lower bound for sets `s` and `p`, then it is a greater lower bound for any set `t`, `s ⊆ t ⊆ p`. -/ theorem IsGLB.of_subset_of_superset {s t p : Set α} (hs : IsGLB s a) (hp : IsGLB p a) (hst : s ⊆ t) (htp : t ⊆ p) : IsGLB t a := hs.dual.of_subset_of_superset hp hst htp #align is_glb.of_subset_of_superset IsGLB.of_subset_of_superset theorem IsLeast.mono (ha : IsLeast s a) (hb : IsLeast t b) (hst : s ⊆ t) : b ≤ a := hb.2 (hst ha.1) #align is_least.mono IsLeast.mono theorem IsGreatest.mono (ha : IsGreatest s a) (hb : IsGreatest t b) (hst : s ⊆ t) : a ≤ b := hb.2 (hst ha.1) #align is_greatest.mono IsGreatest.mono theorem IsLUB.mono (ha : IsLUB s a) (hb : IsLUB t b) (hst : s ⊆ t) : a ≤ b := IsLeast.mono hb ha <| upperBounds_mono_set hst #align is_lub.mono IsLUB.mono theorem IsGLB.mono (ha : IsGLB s a) (hb : IsGLB t b) (hst : s ⊆ t) : b ≤ a := IsGreatest.mono hb ha <| lowerBounds_mono_set hst #align is_glb.mono IsGLB.mono theorem subset_lowerBounds_upperBounds (s : Set α) : s ⊆ lowerBounds (upperBounds s) := fun _ hx _ hy => hy hx #align subset_lower_bounds_upper_bounds subset_lowerBounds_upperBounds theorem subset_upperBounds_lowerBounds (s : Set α) : s ⊆ upperBounds (lowerBounds s) := fun _ hx _ hy => hy hx #align subset_upper_bounds_lower_bounds subset_upperBounds_lowerBounds theorem Set.Nonempty.bddAbove_lowerBounds (hs : s.Nonempty) : BddAbove (lowerBounds s) := hs.mono (subset_upperBounds_lowerBounds s) #align set.nonempty.bdd_above_lower_bounds Set.Nonempty.bddAbove_lowerBounds theorem Set.Nonempty.bddBelow_upperBounds (hs : s.Nonempty) : BddBelow (upperBounds s) := hs.mono (subset_lowerBounds_upperBounds s) #align set.nonempty.bdd_below_upper_bounds Set.Nonempty.bddBelow_upperBounds /-! ### Conversions -/ theorem IsLeast.isGLB (h : IsLeast s a) : IsGLB s a := ⟨h.2, fun _ hb => hb h.1⟩ #align is_least.is_glb IsLeast.isGLB theorem IsGreatest.isLUB (h : IsGreatest s a) : IsLUB s a := ⟨h.2, fun _ hb => hb h.1⟩ #align is_greatest.is_lub IsGreatest.isLUB theorem IsLUB.upperBounds_eq (h : IsLUB s a) : upperBounds s = Ici a := Set.ext fun _ => ⟨fun hb => h.2 hb, fun hb => upperBounds_mono_mem hb h.1⟩ #align is_lub.upper_bounds_eq IsLUB.upperBounds_eq theorem IsGLB.lowerBounds_eq (h : IsGLB s a) : lowerBounds s = Iic a := h.dual.upperBounds_eq #align is_glb.lower_bounds_eq IsGLB.lowerBounds_eq theorem IsLeast.lowerBounds_eq (h : IsLeast s a) : lowerBounds s = Iic a := h.isGLB.lowerBounds_eq #align is_least.lower_bounds_eq IsLeast.lowerBounds_eq theorem IsGreatest.upperBounds_eq (h : IsGreatest s a) : upperBounds s = Ici a := h.isLUB.upperBounds_eq #align is_greatest.upper_bounds_eq IsGreatest.upperBounds_eq -- Porting note (#10756): new lemma theorem IsGreatest.lt_iff (h : IsGreatest s a) : a < b ↔ ∀ x ∈ s, x < b := ⟨fun hlt _x hx => (h.2 hx).trans_lt hlt, fun h' => h' _ h.1⟩ -- Porting note (#10756): new lemma theorem IsLeast.lt_iff (h : IsLeast s a) : b < a ↔ ∀ x ∈ s, b < x := h.dual.lt_iff theorem isLUB_le_iff (h : IsLUB s a) : a ≤ b ↔ b ∈ upperBounds s := by rw [h.upperBounds_eq] rfl #align is_lub_le_iff isLUB_le_iff theorem le_isGLB_iff (h : IsGLB s a) : b ≤ a ↔ b ∈ lowerBounds s := by rw [h.lowerBounds_eq] rfl #align le_is_glb_iff le_isGLB_iff theorem isLUB_iff_le_iff : IsLUB s a ↔ ∀ b, a ≤ b ↔ b ∈ upperBounds s := ⟨fun h _ => isLUB_le_iff h, fun H => ⟨(H _).1 le_rfl, fun b hb => (H b).2 hb⟩⟩ #align is_lub_iff_le_iff isLUB_iff_le_iff theorem isGLB_iff_le_iff : IsGLB s a ↔ ∀ b, b ≤ a ↔ b ∈ lowerBounds s := @isLUB_iff_le_iff αᵒᵈ _ _ _ #align is_glb_iff_le_iff isGLB_iff_le_iff /-- If `s` has a least upper bound, then it is bounded above. -/ theorem IsLUB.bddAbove (h : IsLUB s a) : BddAbove s := ⟨a, h.1⟩ #align is_lub.bdd_above IsLUB.bddAbove /-- If `s` has a greatest lower bound, then it is bounded below. -/ theorem IsGLB.bddBelow (h : IsGLB s a) : BddBelow s := ⟨a, h.1⟩ #align is_glb.bdd_below IsGLB.bddBelow /-- If `s` has a greatest element, then it is bounded above. -/ theorem IsGreatest.bddAbove (h : IsGreatest s a) : BddAbove s := ⟨a, h.2⟩ #align is_greatest.bdd_above IsGreatest.bddAbove /-- If `s` has a least element, then it is bounded below. -/ theorem IsLeast.bddBelow (h : IsLeast s a) : BddBelow s := ⟨a, h.2⟩ #align is_least.bdd_below IsLeast.bddBelow theorem IsLeast.nonempty (h : IsLeast s a) : s.Nonempty := ⟨a, h.1⟩ #align is_least.nonempty IsLeast.nonempty theorem IsGreatest.nonempty (h : IsGreatest s a) : s.Nonempty := ⟨a, h.1⟩ #align is_greatest.nonempty IsGreatest.nonempty /-! ### Union and intersection -/ @[simp] theorem upperBounds_union : upperBounds (s ∪ t) = upperBounds s ∩ upperBounds t := Subset.antisymm (fun _ hb => ⟨fun _ hx => hb (Or.inl hx), fun _ hx => hb (Or.inr hx)⟩) fun _ hb _ hx => hx.elim (fun hs => hb.1 hs) fun ht => hb.2 ht #align upper_bounds_union upperBounds_union @[simp] theorem lowerBounds_union : lowerBounds (s ∪ t) = lowerBounds s ∩ lowerBounds t := @upperBounds_union αᵒᵈ _ s t #align lower_bounds_union lowerBounds_union theorem union_upperBounds_subset_upperBounds_inter : upperBounds s ∪ upperBounds t ⊆ upperBounds (s ∩ t) := union_subset (upperBounds_mono_set inter_subset_left) (upperBounds_mono_set inter_subset_right) #align union_upper_bounds_subset_upper_bounds_inter union_upperBounds_subset_upperBounds_inter theorem union_lowerBounds_subset_lowerBounds_inter : lowerBounds s ∪ lowerBounds t ⊆ lowerBounds (s ∩ t) := @union_upperBounds_subset_upperBounds_inter αᵒᵈ _ s t #align union_lower_bounds_subset_lower_bounds_inter union_lowerBounds_subset_lowerBounds_inter theorem isLeast_union_iff {a : α} {s t : Set α} : IsLeast (s ∪ t) a ↔ IsLeast s a ∧ a ∈ lowerBounds t ∨ a ∈ lowerBounds s ∧ IsLeast t a := by simp [IsLeast, lowerBounds_union, or_and_right, and_comm (a := a ∈ t), and_assoc] #align is_least_union_iff isLeast_union_iff theorem isGreatest_union_iff : IsGreatest (s ∪ t) a ↔ IsGreatest s a ∧ a ∈ upperBounds t ∨ a ∈ upperBounds s ∧ IsGreatest t a := @isLeast_union_iff αᵒᵈ _ a s t #align is_greatest_union_iff isGreatest_union_iff /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_left (h : BddAbove s) : BddAbove (s ∩ t) := h.mono inter_subset_left #align bdd_above.inter_of_left BddAbove.inter_of_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddAbove.inter_of_right (h : BddAbove t) : BddAbove (s ∩ t) := h.mono inter_subset_right #align bdd_above.inter_of_right BddAbove.inter_of_right /-- If `s` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_left (h : BddBelow s) : BddBelow (s ∩ t) := h.mono inter_subset_left #align bdd_below.inter_of_left BddBelow.inter_of_left /-- If `t` is bounded, then so is `s ∩ t` -/ theorem BddBelow.inter_of_right (h : BddBelow t) : BddBelow (s ∩ t) := h.mono inter_subset_right #align bdd_below.inter_of_right BddBelow.inter_of_right /-- In a directed order, the union of bounded above sets is bounded above. -/ theorem BddAbove.union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove s → BddAbove t → BddAbove (s ∪ t) := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hca, hcb⟩ := exists_ge_ge a b rw [BddAbove, upperBounds_union] exact ⟨c, upperBounds_mono_mem hca ha, upperBounds_mono_mem hcb hb⟩ #align bdd_above.union BddAbove.union /-- In a directed order, the union of two sets is bounded above if and only if both sets are. -/ theorem bddAbove_union [IsDirected α (· ≤ ·)] {s t : Set α} : BddAbove (s ∪ t) ↔ BddAbove s ∧ BddAbove t := ⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h => h.1.union h.2⟩ #align bdd_above_union bddAbove_union /-- In a codirected order, the union of bounded below sets is bounded below. -/ theorem BddBelow.union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow s → BddBelow t → BddBelow (s ∪ t) := @BddAbove.union αᵒᵈ _ _ _ _ #align bdd_below.union BddBelow.union /-- In a codirected order, the union of two sets is bounded below if and only if both sets are. -/ theorem bddBelow_union [IsDirected α (· ≥ ·)] {s t : Set α} : BddBelow (s ∪ t) ↔ BddBelow s ∧ BddBelow t := @bddAbove_union αᵒᵈ _ _ _ _ #align bdd_below_union bddBelow_union /-- If `a` is the least upper bound of `s` and `b` is the least upper bound of `t`, then `a ⊔ b` is the least upper bound of `s ∪ t`. -/ theorem IsLUB.union [SemilatticeSup γ] {a b : γ} {s t : Set γ} (hs : IsLUB s a) (ht : IsLUB t b) : IsLUB (s ∪ t) (a ⊔ b) := ⟨fun _ h => h.casesOn (fun h => le_sup_of_le_left <| hs.left h) fun h => le_sup_of_le_right <| ht.left h, fun _ hc => sup_le (hs.right fun _ hd => hc <| Or.inl hd) (ht.right fun _ hd => hc <| Or.inr hd)⟩ #align is_lub.union IsLUB.union /-- If `a` is the greatest lower bound of `s` and `b` is the greatest lower bound of `t`, then `a ⊓ b` is the greatest lower bound of `s ∪ t`. -/ theorem IsGLB.union [SemilatticeInf γ] {a₁ a₂ : γ} {s t : Set γ} (hs : IsGLB s a₁) (ht : IsGLB t a₂) : IsGLB (s ∪ t) (a₁ ⊓ a₂) := hs.dual.union ht #align is_glb.union IsGLB.union /-- If `a` is the least element of `s` and `b` is the least element of `t`, then `min a b` is the least element of `s ∪ t`. -/ theorem IsLeast.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsLeast s a) (hb : IsLeast t b) : IsLeast (s ∪ t) (min a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isGLB.union hb.isGLB).1⟩ #align is_least.union IsLeast.union /-- If `a` is the greatest element of `s` and `b` is the greatest element of `t`, then `max a b` is the greatest element of `s ∪ t`. -/ theorem IsGreatest.union [LinearOrder γ] {a b : γ} {s t : Set γ} (ha : IsGreatest s a) (hb : IsGreatest t b) : IsGreatest (s ∪ t) (max a b) := ⟨by rcases le_total a b with h | h <;> simp [h, ha.1, hb.1], (ha.isLUB.union hb.isLUB).1⟩ #align is_greatest.union IsGreatest.union theorem IsLUB.inter_Ici_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsLUB s a) (hb : b ∈ s) : IsLUB (s ∩ Ici b) a := ⟨fun _ hx => ha.1 hx.1, fun c hc => have hbc : b ≤ c := hc ⟨hb, le_rfl⟩ ha.2 fun x hx => ((le_total x b).elim fun hxb => hxb.trans hbc) fun hbx => hc ⟨hx, hbx⟩⟩ #align is_lub.inter_Ici_of_mem IsLUB.inter_Ici_of_mem theorem IsGLB.inter_Iic_of_mem [LinearOrder γ] {s : Set γ} {a b : γ} (ha : IsGLB s a) (hb : b ∈ s) : IsGLB (s ∩ Iic b) a := ha.dual.inter_Ici_of_mem hb #align is_glb.inter_Iic_of_mem IsGLB.inter_Iic_of_mem theorem bddAbove_iff_exists_ge [SemilatticeSup γ] {s : Set γ} (x₀ : γ) : BddAbove s ↔ ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := by rw [bddAbove_def, exists_ge_and_iff_exists] exact Monotone.ball fun x _ => monotone_le #align bdd_above_iff_exists_ge bddAbove_iff_exists_ge theorem bddBelow_iff_exists_le [SemilatticeInf γ] {s : Set γ} (x₀ : γ) : BddBelow s ↔ ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := bddAbove_iff_exists_ge (toDual x₀) #align bdd_below_iff_exists_le bddBelow_iff_exists_le theorem BddAbove.exists_ge [SemilatticeSup γ] {s : Set γ} (hs : BddAbove s) (x₀ : γ) : ∃ x, x₀ ≤ x ∧ ∀ y ∈ s, y ≤ x := (bddAbove_iff_exists_ge x₀).mp hs #align bdd_above.exists_ge BddAbove.exists_ge theorem BddBelow.exists_le [SemilatticeInf γ] {s : Set γ} (hs : BddBelow s) (x₀ : γ) : ∃ x, x ≤ x₀ ∧ ∀ y ∈ s, x ≤ y := (bddBelow_iff_exists_le x₀).mp hs #align bdd_below.exists_le BddBelow.exists_le /-! ### Specific sets #### Unbounded intervals -/ theorem isLeast_Ici : IsLeast (Ici a) a := ⟨left_mem_Ici, fun _ => id⟩ #align is_least_Ici isLeast_Ici theorem isGreatest_Iic : IsGreatest (Iic a) a := ⟨right_mem_Iic, fun _ => id⟩ #align is_greatest_Iic isGreatest_Iic theorem isLUB_Iic : IsLUB (Iic a) a := isGreatest_Iic.isLUB #align is_lub_Iic isLUB_Iic theorem isGLB_Ici : IsGLB (Ici a) a := isLeast_Ici.isGLB #align is_glb_Ici isGLB_Ici theorem upperBounds_Iic : upperBounds (Iic a) = Ici a := isLUB_Iic.upperBounds_eq #align upper_bounds_Iic upperBounds_Iic theorem lowerBounds_Ici : lowerBounds (Ici a) = Iic a := isGLB_Ici.lowerBounds_eq #align lower_bounds_Ici lowerBounds_Ici theorem bddAbove_Iic : BddAbove (Iic a) := isLUB_Iic.bddAbove #align bdd_above_Iic bddAbove_Iic theorem bddBelow_Ici : BddBelow (Ici a) := isGLB_Ici.bddBelow #align bdd_below_Ici bddBelow_Ici theorem bddAbove_Iio : BddAbove (Iio a) := ⟨a, fun _ hx => le_of_lt hx⟩ #align bdd_above_Iio bddAbove_Iio theorem bddBelow_Ioi : BddBelow (Ioi a) := ⟨a, fun _ hx => le_of_lt hx⟩ #align bdd_below_Ioi bddBelow_Ioi theorem lub_Iio_le (a : α) (hb : IsLUB (Iio a) b) : b ≤ a := (isLUB_le_iff hb).mpr fun _ hk => le_of_lt hk #align lub_Iio_le lub_Iio_le theorem le_glb_Ioi (a : α) (hb : IsGLB (Ioi a) b) : a ≤ b := @lub_Iio_le αᵒᵈ _ _ a hb #align le_glb_Ioi le_glb_Ioi theorem lub_Iio_eq_self_or_Iio_eq_Iic [PartialOrder γ] {j : γ} (i : γ) (hj : IsLUB (Iio i) j) : j = i ∨ Iio i = Iic j := by cases' eq_or_lt_of_le (lub_Iio_le i hj) with hj_eq_i hj_lt_i · exact Or.inl hj_eq_i · right exact Set.ext fun k => ⟨fun hk_lt => hj.1 hk_lt, fun hk_le_j => lt_of_le_of_lt hk_le_j hj_lt_i⟩ #align lub_Iio_eq_self_or_Iio_eq_Iic lub_Iio_eq_self_or_Iio_eq_Iic theorem glb_Ioi_eq_self_or_Ioi_eq_Ici [PartialOrder γ] {j : γ} (i : γ) (hj : IsGLB (Ioi i) j) : j = i ∨ Ioi i = Ici j := @lub_Iio_eq_self_or_Iio_eq_Iic γᵒᵈ _ j i hj #align glb_Ioi_eq_self_or_Ioi_eq_Ici glb_Ioi_eq_self_or_Ioi_eq_Ici section variable [LinearOrder γ] theorem exists_lub_Iio (i : γ) : ∃ j, IsLUB (Iio i) j := by by_cases h_exists_lt : ∃ j, j ∈ upperBounds (Iio i) ∧ j < i · obtain ⟨j, hj_ub, hj_lt_i⟩ := h_exists_lt exact ⟨j, hj_ub, fun k hk_ub => hk_ub hj_lt_i⟩ · refine ⟨i, fun j hj => le_of_lt hj, ?_⟩ rw [mem_lowerBounds] by_contra h refine h_exists_lt ?_ push_neg at h exact h #align exists_lub_Iio exists_lub_Iio theorem exists_glb_Ioi (i : γ) : ∃ j, IsGLB (Ioi i) j := @exists_lub_Iio γᵒᵈ _ i #align exists_glb_Ioi exists_glb_Ioi variable [DenselyOrdered γ] theorem isLUB_Iio {a : γ} : IsLUB (Iio a) a := ⟨fun _ hx => le_of_lt hx, fun _ hy => le_of_forall_ge_of_dense hy⟩ #align is_lub_Iio isLUB_Iio theorem isGLB_Ioi {a : γ} : IsGLB (Ioi a) a := @isLUB_Iio γᵒᵈ _ _ a #align is_glb_Ioi isGLB_Ioi theorem upperBounds_Iio {a : γ} : upperBounds (Iio a) = Ici a := isLUB_Iio.upperBounds_eq #align upper_bounds_Iio upperBounds_Iio theorem lowerBounds_Ioi {a : γ} : lowerBounds (Ioi a) = Iic a := isGLB_Ioi.lowerBounds_eq #align lower_bounds_Ioi lowerBounds_Ioi end /-! #### Singleton -/ theorem isGreatest_singleton : IsGreatest {a} a := ⟨mem_singleton a, fun _ hx => le_of_eq <| eq_of_mem_singleton hx⟩ #align is_greatest_singleton isGreatest_singleton theorem isLeast_singleton : IsLeast {a} a := @isGreatest_singleton αᵒᵈ _ a #align is_least_singleton isLeast_singleton theorem isLUB_singleton : IsLUB {a} a := isGreatest_singleton.isLUB #align is_lub_singleton isLUB_singleton theorem isGLB_singleton : IsGLB {a} a := isLeast_singleton.isGLB #align is_glb_singleton isGLB_singleton @[simp] lemma bddAbove_singleton : BddAbove ({a} : Set α) := isLUB_singleton.bddAbove #align bdd_above_singleton bddAbove_singleton @[simp] lemma bddBelow_singleton : BddBelow ({a} : Set α) := isGLB_singleton.bddBelow #align bdd_below_singleton bddBelow_singleton @[simp] theorem upperBounds_singleton : upperBounds {a} = Ici a := isLUB_singleton.upperBounds_eq #align upper_bounds_singleton upperBounds_singleton @[simp] theorem lowerBounds_singleton : lowerBounds {a} = Iic a := isGLB_singleton.lowerBounds_eq #align lower_bounds_singleton lowerBounds_singleton /-! #### Bounded intervals -/ theorem bddAbove_Icc : BddAbove (Icc a b) := ⟨b, fun _ => And.right⟩ #align bdd_above_Icc bddAbove_Icc theorem bddBelow_Icc : BddBelow (Icc a b) := ⟨a, fun _ => And.left⟩ #align bdd_below_Icc bddBelow_Icc theorem bddAbove_Ico : BddAbove (Ico a b) := bddAbove_Icc.mono Ico_subset_Icc_self #align bdd_above_Ico bddAbove_Ico theorem bddBelow_Ico : BddBelow (Ico a b) := bddBelow_Icc.mono Ico_subset_Icc_self #align bdd_below_Ico bddBelow_Ico theorem bddAbove_Ioc : BddAbove (Ioc a b) := bddAbove_Icc.mono Ioc_subset_Icc_self #align bdd_above_Ioc bddAbove_Ioc theorem bddBelow_Ioc : BddBelow (Ioc a b) := bddBelow_Icc.mono Ioc_subset_Icc_self #align bdd_below_Ioc bddBelow_Ioc theorem bddAbove_Ioo : BddAbove (Ioo a b) := bddAbove_Icc.mono Ioo_subset_Icc_self #align bdd_above_Ioo bddAbove_Ioo theorem bddBelow_Ioo : BddBelow (Ioo a b) := bddBelow_Icc.mono Ioo_subset_Icc_self #align bdd_below_Ioo bddBelow_Ioo theorem isGreatest_Icc (h : a ≤ b) : IsGreatest (Icc a b) b := ⟨right_mem_Icc.2 h, fun _ => And.right⟩ #align is_greatest_Icc isGreatest_Icc theorem isLUB_Icc (h : a ≤ b) : IsLUB (Icc a b) b := (isGreatest_Icc h).isLUB #align is_lub_Icc isLUB_Icc theorem upperBounds_Icc (h : a ≤ b) : upperBounds (Icc a b) = Ici b := (isLUB_Icc h).upperBounds_eq #align upper_bounds_Icc upperBounds_Icc theorem isLeast_Icc (h : a ≤ b) : IsLeast (Icc a b) a := ⟨left_mem_Icc.2 h, fun _ => And.left⟩ #align is_least_Icc isLeast_Icc theorem isGLB_Icc (h : a ≤ b) : IsGLB (Icc a b) a := (isLeast_Icc h).isGLB #align is_glb_Icc isGLB_Icc theorem lowerBounds_Icc (h : a ≤ b) : lowerBounds (Icc a b) = Iic a := (isGLB_Icc h).lowerBounds_eq #align lower_bounds_Icc lowerBounds_Icc theorem isGreatest_Ioc (h : a < b) : IsGreatest (Ioc a b) b := ⟨right_mem_Ioc.2 h, fun _ => And.right⟩ #align is_greatest_Ioc isGreatest_Ioc theorem isLUB_Ioc (h : a < b) : IsLUB (Ioc a b) b := (isGreatest_Ioc h).isLUB #align is_lub_Ioc isLUB_Ioc theorem upperBounds_Ioc (h : a < b) : upperBounds (Ioc a b) = Ici b := (isLUB_Ioc h).upperBounds_eq #align upper_bounds_Ioc upperBounds_Ioc theorem isLeast_Ico (h : a < b) : IsLeast (Ico a b) a := ⟨left_mem_Ico.2 h, fun _ => And.left⟩ #align is_least_Ico isLeast_Ico theorem isGLB_Ico (h : a < b) : IsGLB (Ico a b) a := (isLeast_Ico h).isGLB #align is_glb_Ico isGLB_Ico theorem lowerBounds_Ico (h : a < b) : lowerBounds (Ico a b) = Iic a := (isGLB_Ico h).lowerBounds_eq #align lower_bounds_Ico lowerBounds_Ico section variable [SemilatticeSup γ] [DenselyOrdered γ] theorem isGLB_Ioo {a b : γ} (h : a < b) : IsGLB (Ioo a b) a := ⟨fun x hx => hx.1.le, fun x hx => by cases' eq_or_lt_of_le (le_sup_right : a ≤ x ⊔ a) with h₁ h₂ · exact h₁.symm ▸ le_sup_left obtain ⟨y, lty, ylt⟩ := exists_between h₂ apply (not_lt_of_le (sup_le (hx ⟨lty, ylt.trans_le (sup_le _ h.le)⟩) lty.le) ylt).elim obtain ⟨u, au, ub⟩ := exists_between h apply (hx ⟨au, ub⟩).trans ub.le⟩ #align is_glb_Ioo isGLB_Ioo theorem lowerBounds_Ioo {a b : γ} (hab : a < b) : lowerBounds (Ioo a b) = Iic a := (isGLB_Ioo hab).lowerBounds_eq #align lower_bounds_Ioo lowerBounds_Ioo theorem isGLB_Ioc {a b : γ} (hab : a < b) : IsGLB (Ioc a b) a := (isGLB_Ioo hab).of_subset_of_superset (isGLB_Icc hab.le) Ioo_subset_Ioc_self Ioc_subset_Icc_self #align is_glb_Ioc isGLB_Ioc theorem lowerBounds_Ioc {a b : γ} (hab : a < b) : lowerBounds (Ioc a b) = Iic a := (isGLB_Ioc hab).lowerBounds_eq #align lower_bound_Ioc lowerBounds_Ioc end section variable [SemilatticeInf γ] [DenselyOrdered γ]
Mathlib/Order/Bounds/Basic.lean
778
779
theorem isLUB_Ioo {a b : γ} (hab : a < b) : IsLUB (Ioo a b) b := by
simpa only [dual_Ioo] using isGLB_Ioo hab.dual
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Algebra.Subalgebra.Basic import Mathlib.Data.Set.UnionLift #align_import algebra.algebra.subalgebra.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Subalgebras and directed Unions of sets ## Main results * `Subalgebra.coe_iSup_of_directed`: a directed supremum consists of the union of the algebras * `Subalgebra.iSupLift`: define an algebra homomorphism on a directed supremum of subalgebras by defining it on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/ namespace Subalgebra open Algebra variable {R A B : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B] [Algebra R B] variable (S : Subalgebra R A) variable {ι : Type*} [Nonempty ι] {K : ι → Subalgebra R A} (dir : Directed (· ≤ ·) K) theorem coe_iSup_of_directed : ↑(iSup K) = ⋃ i, (K i : Set A) := let s : Subalgebra R A := { __ := Subsemiring.copy _ _ (Subsemiring.coe_iSup_of_directed dir).symm algebraMap_mem' := fun _ ↦ Set.mem_iUnion.2 ⟨Classical.arbitrary ι, Subalgebra.algebraMap_mem _ _⟩ } have : iSup K = s := le_antisymm (iSup_le fun i ↦ le_iSup (fun i ↦ (K i : Set A)) i) (Set.iUnion_subset fun _ ↦ le_iSup K _) this.symm ▸ rfl #align subalgebra.coe_supr_of_directed Subalgebra.coe_iSup_of_directed variable (K) variable (f : ∀ i, K i →ₐ[R] B) (hf : ∀ (i j : ι) (h : K i ≤ K j), f i = (f j).comp (inclusion h)) (T : Subalgebra R A) (hT : T = iSup K) -- Porting note (#11215): TODO: turn `hT` into an assumption `T ≤ iSup K`. -- That's what `Set.iUnionLift` needs -- Porting note: the proofs of `map_{zero,one,add,mul}` got a bit uglier, probably unification trbls /-- Define an algebra homomorphism on a directed supremum of subalgebras by defining it on each subalgebra, and proving that it agrees on the intersection of subalgebras. -/ noncomputable def iSupLift : ↥T →ₐ[R] B := { toFun := Set.iUnionLift (fun i => ↑(K i)) (fun i x => f i x) (fun i j x hxi hxj => by let ⟨k, hik, hjk⟩ := dir i j dsimp rw [hf i k hik, hf j k hjk] rfl) T (by rw [hT, coe_iSup_of_directed dir]) map_one' := by apply Set.iUnionLift_const _ (fun _ => 1) <;> simp map_zero' := by dsimp; apply Set.iUnionLift_const _ (fun _ => 0) <;> simp map_mul' := by subst hT; dsimp apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· * ·)) on_goal 3 => rw [coe_iSup_of_directed dir] all_goals simp map_add' := by subst hT; dsimp apply Set.iUnionLift_binary (coe_iSup_of_directed dir) dir _ (fun _ => (· + ·)) on_goal 3 => rw [coe_iSup_of_directed dir] all_goals simp commutes' := fun r => by dsimp apply Set.iUnionLift_const _ (fun _ => algebraMap R _ r) <;> simp } #align subalgebra.supr_lift Subalgebra.iSupLift variable {K dir f hf T hT} @[simp]
Mathlib/Algebra/Algebra/Subalgebra/Directed.lean
78
81
theorem iSupLift_inclusion {i : ι} (x : K i) (h : K i ≤ T) : iSupLift K dir f hf T hT (inclusion h x) = f i x := by
dsimp [iSupLift, inclusion] rw [Set.iUnionLift_inclusion]
/- 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.Compactness.SigmaCompact import Mathlib.Topology.Connected.TotallyDisconnected import Mathlib.Topology.Inseparable #align_import topology.separation from "leanprover-community/mathlib"@"d91e7f7a7f1c7e9f0e18fdb6bde4f652004c735d" /-! # Separation properties of topological spaces. This file defines the predicate `SeparatedNhds`, and common separation axioms (under the Kolmogorov classification). ## Main definitions * `SeparatedNhds`: Two `Set`s are separated by neighbourhoods if they are contained in disjoint open sets. * `T0Space`: A T₀/Kolmogorov space is a space where, for every two points `x ≠ y`, there is an open set that contains one, but not the other. * `R0Space`: An R₀ space (sometimes called a *symmetric space*) is a topological space such that the `Specializes` relation is symmetric. * `T1Space`: A T₁/Fréchet space is a space where every singleton set is closed. This is equivalent to, for every pair `x ≠ y`, there existing an open set containing `x` but not `y` (`t1Space_iff_exists_open` shows that these conditions are equivalent.) T₁ implies T₀ and R₀. * `R1Space`: An R₁/preregular space is a space where any two topologically distinguishable points have disjoint neighbourhoods. R₁ implies R₀. * `T2Space`: A T₂/Hausdorff space is a space where, for every two points `x ≠ y`, there is two disjoint open sets, one containing `x`, and the other `y`. T₂ implies T₁ and R₁. * `T25Space`: A T₂.₅/Urysohn space is a space where, for every two points `x ≠ y`, there is two open sets, one containing `x`, and the other `y`, whose closures are disjoint. T₂.₅ implies T₂. * `RegularSpace`: A regular space is one where, given any closed `C` and `x ∉ C`, there are disjoint open sets containing `x` and `C` respectively. Such a space is not necessarily Hausdorff. * `T3Space`: A T₃ space is a regular T₀ space. T₃ implies T₂.₅. * `NormalSpace`: A normal space, is one where given two disjoint closed sets, we can find two open sets that separate them. Such a space is not necessarily Hausdorff, even if it is T₀. * `T4Space`: A T₄ space is a normal T₁ space. T₄ implies T₃. * `CompletelyNormalSpace`: A completely normal space is one in which for any two sets `s`, `t` such that if both `closure s` is disjoint with `t`, and `s` is disjoint with `closure t`, then there exist disjoint neighbourhoods of `s` and `t`. `Embedding.completelyNormalSpace` allows us to conclude that this is equivalent to all subspaces being normal. Such a space is not necessarily Hausdorff or regular, even if it is T₀. * `T5Space`: A T₅ space is a completely normal T₁ space. T₅ implies T₄. Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but occasionally the literature swaps definitions for e.g. T₃ and regular. ## Main results ### T₀ spaces * `IsClosed.exists_closed_singleton`: Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. * `exists_isOpen_singleton_of_isOpen_finite`: Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. ### T₁ spaces * `isClosedMap_const`: The constant map is a closed map. * `discrete_of_t1_of_finite`: A finite T₁ space must have the discrete topology. ### T₂ spaces * `t2_iff_nhds`: A space is T₂ iff the neighbourhoods of distinct points generate the bottom filter. * `t2_iff_isClosed_diagonal`: A space is T₂ iff the `diagonal` of `X` (that is, the set of all points of the form `(a, a) : X × X`) is closed under the product topology. * `separatedNhds_of_finset_finset`: Any two disjoint finsets are `SeparatedNhds`. * Most topological constructions preserve Hausdorffness; these results are part of the typeclass inference system (e.g. `Embedding.t2Space`) * `Set.EqOn.closure`: If two functions are equal on some set `s`, they are equal on its closure. * `IsCompact.isClosed`: All compact sets are closed. * `WeaklyLocallyCompactSpace.locallyCompactSpace`: If a topological space is both weakly locally compact (i.e., each point has a compact neighbourhood) and is T₂, then it is locally compact. * `totallySeparatedSpace_of_t1_of_basis_clopen`: If `X` has a clopen basis, then it is a `TotallySeparatedSpace`. * `loc_compact_t2_tot_disc_iff_tot_sep`: A locally compact T₂ space is totally disconnected iff it is totally separated. * `t2Quotient`: the largest T2 quotient of a given topological space. If the space is also compact: * `normalOfCompactT2`: A compact T₂ space is a `NormalSpace`. * `connectedComponent_eq_iInter_isClopen`: The connected component of a point is the intersection of all its clopen neighbourhoods. * `compact_t2_tot_disc_iff_tot_sep`: Being a `TotallyDisconnectedSpace` is equivalent to being a `TotallySeparatedSpace`. * `ConnectedComponents.t2`: `ConnectedComponents X` is T₂ for `X` T₂ and compact. ### T₃ spaces * `disjoint_nested_nhds`: Given two points `x ≠ y`, we can find neighbourhoods `x ∈ V₁ ⊆ U₁` and `y ∈ V₂ ⊆ U₂`, with the `Vₖ` closed and the `Uₖ` open, such that the `Uₖ` are disjoint. ## References https://en.wikipedia.org/wiki/Separation_axiom -/ open Function Set Filter Topology TopologicalSpace open scoped Classical universe u v variable {X : Type*} {Y : Type*} [TopologicalSpace X] section Separation /-- `SeparatedNhds` is a predicate on pairs of sub`Set`s of a topological space. It holds if the two sub`Set`s are contained in disjoint open sets. -/ def SeparatedNhds : Set X → Set X → Prop := fun s t : Set X => ∃ U V : Set X, IsOpen U ∧ IsOpen V ∧ s ⊆ U ∧ t ⊆ V ∧ Disjoint U V #align separated_nhds SeparatedNhds theorem separatedNhds_iff_disjoint {s t : Set X} : SeparatedNhds s t ↔ Disjoint (𝓝ˢ s) (𝓝ˢ t) := by simp only [(hasBasis_nhdsSet s).disjoint_iff (hasBasis_nhdsSet t), SeparatedNhds, exists_prop, ← exists_and_left, and_assoc, and_comm, and_left_comm] #align separated_nhds_iff_disjoint separatedNhds_iff_disjoint alias ⟨SeparatedNhds.disjoint_nhdsSet, _⟩ := separatedNhds_iff_disjoint namespace SeparatedNhds variable {s s₁ s₂ t t₁ t₂ u : Set X} @[symm] theorem symm : SeparatedNhds s t → SeparatedNhds t s := fun ⟨U, V, oU, oV, aU, bV, UV⟩ => ⟨V, U, oV, oU, bV, aU, Disjoint.symm UV⟩ #align separated_nhds.symm SeparatedNhds.symm theorem comm (s t : Set X) : SeparatedNhds s t ↔ SeparatedNhds t s := ⟨symm, symm⟩ #align separated_nhds.comm SeparatedNhds.comm theorem preimage [TopologicalSpace Y] {f : X → Y} {s t : Set Y} (h : SeparatedNhds s t) (hf : Continuous f) : SeparatedNhds (f ⁻¹' s) (f ⁻¹' t) := let ⟨U, V, oU, oV, sU, tV, UV⟩ := h ⟨f ⁻¹' U, f ⁻¹' V, oU.preimage hf, oV.preimage hf, preimage_mono sU, preimage_mono tV, UV.preimage f⟩ #align separated_nhds.preimage SeparatedNhds.preimage protected theorem disjoint (h : SeparatedNhds s t) : Disjoint s t := let ⟨_, _, _, _, hsU, htV, hd⟩ := h; hd.mono hsU htV #align separated_nhds.disjoint SeparatedNhds.disjoint theorem disjoint_closure_left (h : SeparatedNhds s t) : Disjoint (closure s) t := let ⟨_U, _V, _, hV, hsU, htV, hd⟩ := h (hd.closure_left hV).mono (closure_mono hsU) htV #align separated_nhds.disjoint_closure_left SeparatedNhds.disjoint_closure_left theorem disjoint_closure_right (h : SeparatedNhds s t) : Disjoint s (closure t) := h.symm.disjoint_closure_left.symm #align separated_nhds.disjoint_closure_right SeparatedNhds.disjoint_closure_right @[simp] theorem empty_right (s : Set X) : SeparatedNhds s ∅ := ⟨_, _, isOpen_univ, isOpen_empty, fun a _ => mem_univ a, Subset.rfl, disjoint_empty _⟩ #align separated_nhds.empty_right SeparatedNhds.empty_right @[simp] theorem empty_left (s : Set X) : SeparatedNhds ∅ s := (empty_right _).symm #align separated_nhds.empty_left SeparatedNhds.empty_left theorem mono (h : SeparatedNhds s₂ t₂) (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : SeparatedNhds s₁ t₁ := let ⟨U, V, hU, hV, hsU, htV, hd⟩ := h ⟨U, V, hU, hV, hs.trans hsU, ht.trans htV, hd⟩ #align separated_nhds.mono SeparatedNhds.mono theorem union_left : SeparatedNhds s u → SeparatedNhds t u → SeparatedNhds (s ∪ t) u := by simpa only [separatedNhds_iff_disjoint, nhdsSet_union, disjoint_sup_left] using And.intro #align separated_nhds.union_left SeparatedNhds.union_left theorem union_right (ht : SeparatedNhds s t) (hu : SeparatedNhds s u) : SeparatedNhds s (t ∪ u) := (ht.symm.union_left hu.symm).symm #align separated_nhds.union_right SeparatedNhds.union_right end SeparatedNhds /-- A T₀ space, also known as a Kolmogorov space, is a topological space such that for every pair `x ≠ y`, there is an open set containing one but not the other. We formulate the definition in terms of the `Inseparable` relation. -/ class T0Space (X : Type u) [TopologicalSpace X] : Prop where /-- Two inseparable points in a T₀ space are equal. -/ t0 : ∀ ⦃x y : X⦄, Inseparable x y → x = y #align t0_space T0Space theorem t0Space_iff_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ ∀ x y : X, Inseparable x y → x = y := ⟨fun ⟨h⟩ => h, fun h => ⟨h⟩⟩ #align t0_space_iff_inseparable t0Space_iff_inseparable theorem t0Space_iff_not_inseparable (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y : X => ¬Inseparable x y := by simp only [t0Space_iff_inseparable, Ne, not_imp_not, Pairwise] #align t0_space_iff_not_inseparable t0Space_iff_not_inseparable theorem Inseparable.eq [T0Space X] {x y : X} (h : Inseparable x y) : x = y := T0Space.t0 h #align inseparable.eq Inseparable.eq /-- A topology `Inducing` map from a T₀ space is injective. -/ protected theorem Inducing.injective [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Injective f := fun _ _ h => (hf.inseparable_iff.1 <| .of_eq h).eq #align inducing.injective Inducing.injective /-- A topology `Inducing` map from a T₀ space is a topological embedding. -/ protected theorem Inducing.embedding [TopologicalSpace Y] [T0Space X] {f : X → Y} (hf : Inducing f) : Embedding f := ⟨hf, hf.injective⟩ #align inducing.embedding Inducing.embedding lemma embedding_iff_inducing [TopologicalSpace Y] [T0Space X] {f : X → Y} : Embedding f ↔ Inducing f := ⟨Embedding.toInducing, Inducing.embedding⟩ #align embedding_iff_inducing embedding_iff_inducing theorem t0Space_iff_nhds_injective (X : Type u) [TopologicalSpace X] : T0Space X ↔ Injective (𝓝 : X → Filter X) := t0Space_iff_inseparable X #align t0_space_iff_nhds_injective t0Space_iff_nhds_injective theorem nhds_injective [T0Space X] : Injective (𝓝 : X → Filter X) := (t0Space_iff_nhds_injective X).1 ‹_› #align nhds_injective nhds_injective theorem inseparable_iff_eq [T0Space X] {x y : X} : Inseparable x y ↔ x = y := nhds_injective.eq_iff #align inseparable_iff_eq inseparable_iff_eq @[simp] theorem nhds_eq_nhds_iff [T0Space X] {a b : X} : 𝓝 a = 𝓝 b ↔ a = b := nhds_injective.eq_iff #align nhds_eq_nhds_iff nhds_eq_nhds_iff @[simp] theorem inseparable_eq_eq [T0Space X] : Inseparable = @Eq X := funext₂ fun _ _ => propext inseparable_iff_eq #align inseparable_eq_eq inseparable_eq_eq theorem TopologicalSpace.IsTopologicalBasis.inseparable_iff {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : Inseparable x y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := ⟨fun h s hs ↦ inseparable_iff_forall_open.1 h _ (hb.isOpen hs), fun h ↦ hb.nhds_hasBasis.eq_of_same_basis <| by convert hb.nhds_hasBasis using 2 exact and_congr_right (h _)⟩ theorem TopologicalSpace.IsTopologicalBasis.eq_iff [T0Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} : x = y ↔ ∀ s ∈ b, (x ∈ s ↔ y ∈ s) := inseparable_iff_eq.symm.trans hb.inseparable_iff theorem t0Space_iff_exists_isOpen_xor'_mem (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := by simp only [t0Space_iff_not_inseparable, xor_iff_not_iff, not_forall, exists_prop, inseparable_iff_forall_open, Pairwise] #align t0_space_iff_exists_is_open_xor_mem t0Space_iff_exists_isOpen_xor'_mem theorem exists_isOpen_xor'_mem [T0Space X] {x y : X} (h : x ≠ y) : ∃ U : Set X, IsOpen U ∧ Xor' (x ∈ U) (y ∈ U) := (t0Space_iff_exists_isOpen_xor'_mem X).1 ‹_› h #align exists_is_open_xor_mem exists_isOpen_xor'_mem /-- Specialization forms a partial order on a t0 topological space. -/ def specializationOrder (X) [TopologicalSpace X] [T0Space X] : PartialOrder X := { specializationPreorder X, PartialOrder.lift (OrderDual.toDual ∘ 𝓝) nhds_injective with } #align specialization_order specializationOrder instance SeparationQuotient.instT0Space : T0Space (SeparationQuotient X) := ⟨fun x y => Quotient.inductionOn₂' x y fun _ _ h => SeparationQuotient.mk_eq_mk.2 <| SeparationQuotient.inducing_mk.inseparable_iff.1 h⟩ theorem minimal_nonempty_closed_subsingleton [T0Space X] {s : Set X} (hs : IsClosed s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · refine this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s \ U = s := hmin (s \ U) diff_subset ⟨y, hy, hyU⟩ (hs.sdiff hUo) exact (this.symm.subset hx).2 hxU #align minimal_nonempty_closed_subsingleton minimal_nonempty_closed_subsingleton theorem minimal_nonempty_closed_eq_singleton [T0Space X] {s : Set X} (hs : IsClosed s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsClosed t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_closed_subsingleton hs hmin⟩ #align minimal_nonempty_closed_eq_singleton minimal_nonempty_closed_eq_singleton /-- Given a closed set `S` in a compact T₀ space, there is some `x ∈ S` such that `{x}` is closed. -/ theorem IsClosed.exists_closed_singleton [T0Space X] [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ x : X, x ∈ S ∧ IsClosed ({x} : Set X) := by obtain ⟨V, Vsub, Vne, Vcls, hV⟩ := hS.exists_minimal_nonempty_closed_subset hne rcases minimal_nonempty_closed_eq_singleton Vcls Vne hV with ⟨x, rfl⟩ exact ⟨x, Vsub (mem_singleton x), Vcls⟩ #align is_closed.exists_closed_singleton IsClosed.exists_closed_singleton theorem minimal_nonempty_open_subsingleton [T0Space X] {s : Set X} (hs : IsOpen s) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : s.Subsingleton := by clear Y -- Porting note: added refine fun x hx y hy => of_not_not fun hxy => ?_ rcases exists_isOpen_xor'_mem hxy with ⟨U, hUo, hU⟩ wlog h : x ∈ U ∧ y ∉ U · exact this hs hmin y hy x hx (Ne.symm hxy) U hUo hU.symm (hU.resolve_left h) cases' h with hxU hyU have : s ∩ U = s := hmin (s ∩ U) inter_subset_left ⟨x, hx, hxU⟩ (hs.inter hUo) exact hyU (this.symm.subset hy).2 #align minimal_nonempty_open_subsingleton minimal_nonempty_open_subsingleton theorem minimal_nonempty_open_eq_singleton [T0Space X] {s : Set X} (hs : IsOpen s) (hne : s.Nonempty) (hmin : ∀ t, t ⊆ s → t.Nonempty → IsOpen t → t = s) : ∃ x, s = {x} := exists_eq_singleton_iff_nonempty_subsingleton.2 ⟨hne, minimal_nonempty_open_subsingleton hs hmin⟩ #align minimal_nonempty_open_eq_singleton minimal_nonempty_open_eq_singleton /-- Given an open finite set `S` in a T₀ space, there is some `x ∈ S` such that `{x}` is open. -/ theorem exists_isOpen_singleton_of_isOpen_finite [T0Space X] {s : Set X} (hfin : s.Finite) (hne : s.Nonempty) (ho : IsOpen s) : ∃ x ∈ s, IsOpen ({x} : Set X) := by lift s to Finset X using hfin induction' s using Finset.strongInductionOn with s ihs rcases em (∃ t, t ⊂ s ∧ t.Nonempty ∧ IsOpen (t : Set X)) with (⟨t, hts, htne, hto⟩ | ht) · rcases ihs t hts htne hto with ⟨x, hxt, hxo⟩ exact ⟨x, hts.1 hxt, hxo⟩ · -- Porting note: was `rcases minimal_nonempty_open_eq_singleton ho hne _ with ⟨x, hx⟩` -- https://github.com/leanprover/std4/issues/116 rsuffices ⟨x, hx⟩ : ∃ x, s.toSet = {x} · exact ⟨x, hx.symm ▸ rfl, hx ▸ ho⟩ refine minimal_nonempty_open_eq_singleton ho hne ?_ refine fun t hts htne hto => of_not_not fun hts' => ht ?_ lift t to Finset X using s.finite_toSet.subset hts exact ⟨t, ssubset_iff_subset_ne.2 ⟨hts, mt Finset.coe_inj.2 hts'⟩, htne, hto⟩ #align exists_open_singleton_of_open_finite exists_isOpen_singleton_of_isOpen_finite theorem exists_open_singleton_of_finite [T0Space X] [Finite X] [Nonempty X] : ∃ x : X, IsOpen ({x} : Set X) := let ⟨x, _, h⟩ := exists_isOpen_singleton_of_isOpen_finite (Set.toFinite _) univ_nonempty isOpen_univ ⟨x, h⟩ #align exists_open_singleton_of_fintype exists_open_singleton_of_finite theorem t0Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T0Space Y] : T0Space X := ⟨fun _ _ h => hf <| (h.map hf').eq⟩ #align t0_space_of_injective_of_continuous t0Space_of_injective_of_continuous protected theorem Embedding.t0Space [TopologicalSpace Y] [T0Space Y] {f : X → Y} (hf : Embedding f) : T0Space X := t0Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t0_space Embedding.t0Space instance Subtype.t0Space [T0Space X] {p : X → Prop} : T0Space (Subtype p) := embedding_subtype_val.t0Space #align subtype.t0_space Subtype.t0Space theorem t0Space_iff_or_not_mem_closure (X : Type u) [TopologicalSpace X] : T0Space X ↔ Pairwise fun a b : X => a ∉ closure ({b} : Set X) ∨ b ∉ closure ({a} : Set X) := by simp only [t0Space_iff_not_inseparable, inseparable_iff_mem_closure, not_and_or] #align t0_space_iff_or_not_mem_closure t0Space_iff_or_not_mem_closure instance Prod.instT0Space [TopologicalSpace Y] [T0Space X] [T0Space Y] : T0Space (X × Y) := ⟨fun _ _ h => Prod.ext (h.map continuous_fst).eq (h.map continuous_snd).eq⟩ instance Pi.instT0Space {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T0Space (X i)] : T0Space (∀ i, X i) := ⟨fun _ _ h => funext fun i => (h.map (continuous_apply i)).eq⟩ #align pi.t0_space Pi.instT0Space instance ULift.instT0Space [T0Space X] : T0Space (ULift X) := embedding_uLift_down.t0Space theorem T0Space.of_cover (h : ∀ x y, Inseparable x y → ∃ s : Set X, x ∈ s ∧ y ∈ s ∧ T0Space s) : T0Space X := by refine ⟨fun x y hxy => ?_⟩ rcases h x y hxy with ⟨s, hxs, hys, hs⟩ lift x to s using hxs; lift y to s using hys rw [← subtype_inseparable_iff] at hxy exact congr_arg Subtype.val hxy.eq #align t0_space.of_cover T0Space.of_cover theorem T0Space.of_open_cover (h : ∀ x, ∃ s : Set X, x ∈ s ∧ IsOpen s ∧ T0Space s) : T0Space X := T0Space.of_cover fun x _ hxy => let ⟨s, hxs, hso, hs⟩ := h x ⟨s, hxs, (hxy.mem_open_iff hso).1 hxs, hs⟩ #align t0_space.of_open_cover T0Space.of_open_cover /-- A topological space is called an R₀ space, if `Specializes` relation is symmetric. In other words, given two points `x y : X`, if every neighborhood of `y` contains `x`, then every neighborhood of `x` contains `y`. -/ @[mk_iff] class R0Space (X : Type u) [TopologicalSpace X] : Prop where /-- In an R₀ space, the `Specializes` relation is symmetric. -/ specializes_symmetric : Symmetric (Specializes : X → X → Prop) export R0Space (specializes_symmetric) section R0Space variable [R0Space X] {x y : X} /-- In an R₀ space, the `Specializes` relation is symmetric, dot notation version. -/ theorem Specializes.symm (h : x ⤳ y) : y ⤳ x := specializes_symmetric h #align specializes.symm Specializes.symm /-- In an R₀ space, the `Specializes` relation is symmetric, `Iff` version. -/ theorem specializes_comm : x ⤳ y ↔ y ⤳ x := ⟨Specializes.symm, Specializes.symm⟩ #align specializes_comm specializes_comm /-- In an R₀ space, `Specializes` is equivalent to `Inseparable`. -/ theorem specializes_iff_inseparable : x ⤳ y ↔ Inseparable x y := ⟨fun h ↦ h.antisymm h.symm, Inseparable.specializes⟩ #align specializes_iff_inseparable specializes_iff_inseparable /-- In an R₀ space, `Specializes` implies `Inseparable`. -/ alias ⟨Specializes.inseparable, _⟩ := specializes_iff_inseparable theorem Inducing.r0Space [TopologicalSpace Y] {f : Y → X} (hf : Inducing f) : R0Space Y where specializes_symmetric a b := by simpa only [← hf.specializes_iff] using Specializes.symm instance {p : X → Prop} : R0Space {x // p x} := inducing_subtype_val.r0Space instance [TopologicalSpace Y] [R0Space Y] : R0Space (X × Y) where specializes_symmetric _ _ h := h.fst.symm.prod h.snd.symm instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, R0Space (X i)] : R0Space (∀ i, X i) where specializes_symmetric _ _ h := specializes_pi.2 fun i ↦ (specializes_pi.1 h i).symm /-- In an R₀ space, the closure of a singleton is a compact set. -/ theorem isCompact_closure_singleton : IsCompact (closure {x}) := by refine isCompact_of_finite_subcover fun U hUo hxU ↦ ?_ obtain ⟨i, hi⟩ : ∃ i, x ∈ U i := mem_iUnion.1 <| hxU <| subset_closure rfl refine ⟨{i}, fun y hy ↦ ?_⟩ rw [← specializes_iff_mem_closure, specializes_comm] at hy simpa using hy.mem_open (hUo i) hi theorem Filter.coclosedCompact_le_cofinite : coclosedCompact X ≤ cofinite := le_cofinite_iff_compl_singleton_mem.2 fun _ ↦ compl_mem_coclosedCompact.2 isCompact_closure_singleton #align filter.coclosed_compact_le_cofinite Filter.coclosedCompact_le_cofinite variable (X) /-- In an R₀ space, relatively compact sets form a bornology. Its cobounded filter is `Filter.coclosedCompact`. See also `Bornology.inCompact` the bornology of sets contained in a compact set. -/ def Bornology.relativelyCompact : Bornology X where cobounded' := Filter.coclosedCompact X le_cofinite' := Filter.coclosedCompact_le_cofinite #align bornology.relatively_compact Bornology.relativelyCompact variable {X} theorem Bornology.relativelyCompact.isBounded_iff {s : Set X} : @Bornology.IsBounded _ (Bornology.relativelyCompact X) s ↔ IsCompact (closure s) := compl_mem_coclosedCompact #align bornology.relatively_compact.is_bounded_iff Bornology.relativelyCompact.isBounded_iff /-- In an R₀ space, the closure of a finite set is a compact set. -/ theorem Set.Finite.isCompact_closure {s : Set X} (hs : s.Finite) : IsCompact (closure s) := let _ : Bornology X := .relativelyCompact X Bornology.relativelyCompact.isBounded_iff.1 hs.isBounded end R0Space /-- A T₁ space, also known as a Fréchet space, is a topological space where every singleton set is closed. Equivalently, for every pair `x ≠ y`, there is an open set containing `x` and not `y`. -/ class T1Space (X : Type u) [TopologicalSpace X] : Prop where /-- A singleton in a T₁ space is a closed set. -/ t1 : ∀ x, IsClosed ({x} : Set X) #align t1_space T1Space theorem isClosed_singleton [T1Space X] {x : X} : IsClosed ({x} : Set X) := T1Space.t1 x #align is_closed_singleton isClosed_singleton theorem isOpen_compl_singleton [T1Space X] {x : X} : IsOpen ({x}ᶜ : Set X) := isClosed_singleton.isOpen_compl #align is_open_compl_singleton isOpen_compl_singleton theorem isOpen_ne [T1Space X] {x : X} : IsOpen { y | y ≠ x } := isOpen_compl_singleton #align is_open_ne isOpen_ne @[to_additive] theorem Continuous.isOpen_mulSupport [T1Space X] [One X] [TopologicalSpace Y] {f : Y → X} (hf : Continuous f) : IsOpen (mulSupport f) := isOpen_ne.preimage hf #align continuous.is_open_mul_support Continuous.isOpen_mulSupport #align continuous.is_open_support Continuous.isOpen_support theorem Ne.nhdsWithin_compl_singleton [T1Space X] {x y : X} (h : x ≠ y) : 𝓝[{y}ᶜ] x = 𝓝 x := isOpen_ne.nhdsWithin_eq h #align ne.nhds_within_compl_singleton Ne.nhdsWithin_compl_singleton theorem Ne.nhdsWithin_diff_singleton [T1Space X] {x y : X} (h : x ≠ y) (s : Set X) : 𝓝[s \ {y}] x = 𝓝[s] x := by rw [diff_eq, inter_comm, nhdsWithin_inter_of_mem] exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h) #align ne.nhds_within_diff_singleton Ne.nhdsWithin_diff_singleton lemma nhdsWithin_compl_singleton_le [T1Space X] (x y : X) : 𝓝[{x}ᶜ] x ≤ 𝓝[{y}ᶜ] x := by rcases eq_or_ne x y with rfl|hy · exact Eq.le rfl · rw [Ne.nhdsWithin_compl_singleton hy] exact nhdsWithin_le_nhds theorem isOpen_setOf_eventually_nhdsWithin [T1Space X] {p : X → Prop} : IsOpen { x | ∀ᶠ y in 𝓝[≠] x, p y } := by refine isOpen_iff_mem_nhds.mpr fun a ha => ?_ filter_upwards [eventually_nhds_nhdsWithin.mpr ha] with b hb rcases eq_or_ne a b with rfl | h · exact hb · rw [h.symm.nhdsWithin_compl_singleton] at hb exact hb.filter_mono nhdsWithin_le_nhds #align is_open_set_of_eventually_nhds_within isOpen_setOf_eventually_nhdsWithin protected theorem Set.Finite.isClosed [T1Space X] {s : Set X} (hs : Set.Finite s) : IsClosed s := by rw [← biUnion_of_singleton s] exact hs.isClosed_biUnion fun i _ => isClosed_singleton #align set.finite.is_closed Set.Finite.isClosed theorem TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne [T1Space X] {b : Set (Set X)} (hb : IsTopologicalBasis b) {x y : X} (h : x ≠ y) : ∃ a ∈ b, x ∈ a ∧ y ∉ a := by rcases hb.isOpen_iff.1 isOpen_ne x h with ⟨a, ab, xa, ha⟩ exact ⟨a, ab, xa, fun h => ha h rfl⟩ #align topological_space.is_topological_basis.exists_mem_of_ne TopologicalSpace.IsTopologicalBasis.exists_mem_of_ne protected theorem Finset.isClosed [T1Space X] (s : Finset X) : IsClosed (s : Set X) := s.finite_toSet.isClosed #align finset.is_closed Finset.isClosed theorem t1Space_TFAE (X : Type u) [TopologicalSpace X] : List.TFAE [T1Space X, ∀ x, IsClosed ({ x } : Set X), ∀ x, IsOpen ({ x }ᶜ : Set X), Continuous (@CofiniteTopology.of X), ∀ ⦃x y : X⦄, x ≠ y → {y}ᶜ ∈ 𝓝 x, ∀ ⦃x y : X⦄, x ≠ y → ∃ s ∈ 𝓝 x, y ∉ s, ∀ ⦃x y : X⦄, x ≠ y → ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U, ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y), ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y), ∀ ⦃x y : X⦄, x ⤳ y → x = y] := by tfae_have 1 ↔ 2 · exact ⟨fun h => h.1, fun h => ⟨h⟩⟩ tfae_have 2 ↔ 3 · simp only [isOpen_compl_iff] tfae_have 5 ↔ 3 · refine forall_swap.trans ?_ simp only [isOpen_iff_mem_nhds, mem_compl_iff, mem_singleton_iff] tfae_have 5 ↔ 6 · simp only [← subset_compl_singleton_iff, exists_mem_subset_iff] tfae_have 5 ↔ 7 · simp only [(nhds_basis_opens _).mem_iff, subset_compl_singleton_iff, exists_prop, and_assoc, and_left_comm] tfae_have 5 ↔ 8 · simp only [← principal_singleton, disjoint_principal_right] tfae_have 8 ↔ 9 · exact forall_swap.trans (by simp only [disjoint_comm, ne_comm]) tfae_have 1 → 4 · simp only [continuous_def, CofiniteTopology.isOpen_iff'] rintro H s (rfl | hs) exacts [isOpen_empty, compl_compl s ▸ (@Set.Finite.isClosed _ _ H _ hs).isOpen_compl] tfae_have 4 → 2 · exact fun h x => (CofiniteTopology.isClosed_iff.2 <| Or.inr (finite_singleton _)).preimage h tfae_have 2 ↔ 10 · simp only [← closure_subset_iff_isClosed, specializes_iff_mem_closure, subset_def, mem_singleton_iff, eq_comm] tfae_finish #align t1_space_tfae t1Space_TFAE theorem t1Space_iff_continuous_cofinite_of : T1Space X ↔ Continuous (@CofiniteTopology.of X) := (t1Space_TFAE X).out 0 3 #align t1_space_iff_continuous_cofinite_of t1Space_iff_continuous_cofinite_of theorem CofiniteTopology.continuous_of [T1Space X] : Continuous (@CofiniteTopology.of X) := t1Space_iff_continuous_cofinite_of.mp ‹_› #align cofinite_topology.continuous_of CofiniteTopology.continuous_of theorem t1Space_iff_exists_open : T1Space X ↔ Pairwise fun x y => ∃ U : Set X, IsOpen U ∧ x ∈ U ∧ y ∉ U := (t1Space_TFAE X).out 0 6 #align t1_space_iff_exists_open t1Space_iff_exists_open theorem t1Space_iff_disjoint_pure_nhds : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (pure x) (𝓝 y) := (t1Space_TFAE X).out 0 8 #align t1_space_iff_disjoint_pure_nhds t1Space_iff_disjoint_pure_nhds theorem t1Space_iff_disjoint_nhds_pure : T1Space X ↔ ∀ ⦃x y : X⦄, x ≠ y → Disjoint (𝓝 x) (pure y) := (t1Space_TFAE X).out 0 7 #align t1_space_iff_disjoint_nhds_pure t1Space_iff_disjoint_nhds_pure theorem t1Space_iff_specializes_imp_eq : T1Space X ↔ ∀ ⦃x y : X⦄, x ⤳ y → x = y := (t1Space_TFAE X).out 0 9 #align t1_space_iff_specializes_imp_eq t1Space_iff_specializes_imp_eq theorem disjoint_pure_nhds [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (pure x) (𝓝 y) := t1Space_iff_disjoint_pure_nhds.mp ‹_› h #align disjoint_pure_nhds disjoint_pure_nhds theorem disjoint_nhds_pure [T1Space X] {x y : X} (h : x ≠ y) : Disjoint (𝓝 x) (pure y) := t1Space_iff_disjoint_nhds_pure.mp ‹_› h #align disjoint_nhds_pure disjoint_nhds_pure theorem Specializes.eq [T1Space X] {x y : X} (h : x ⤳ y) : x = y := t1Space_iff_specializes_imp_eq.1 ‹_› h #align specializes.eq Specializes.eq theorem specializes_iff_eq [T1Space X] {x y : X} : x ⤳ y ↔ x = y := ⟨Specializes.eq, fun h => h ▸ specializes_rfl⟩ #align specializes_iff_eq specializes_iff_eq @[simp] theorem specializes_eq_eq [T1Space X] : (· ⤳ ·) = @Eq X := funext₂ fun _ _ => propext specializes_iff_eq #align specializes_eq_eq specializes_eq_eq @[simp] theorem pure_le_nhds_iff [T1Space X] {a b : X} : pure a ≤ 𝓝 b ↔ a = b := specializes_iff_pure.symm.trans specializes_iff_eq #align pure_le_nhds_iff pure_le_nhds_iff @[simp] theorem nhds_le_nhds_iff [T1Space X] {a b : X} : 𝓝 a ≤ 𝓝 b ↔ a = b := specializes_iff_eq #align nhds_le_nhds_iff nhds_le_nhds_iff instance (priority := 100) [T1Space X] : R0Space X where specializes_symmetric _ _ := by rw [specializes_iff_eq, specializes_iff_eq]; exact Eq.symm instance : T1Space (CofiniteTopology X) := t1Space_iff_continuous_cofinite_of.mpr continuous_id theorem t1Space_antitone : Antitone (@T1Space X) := fun a _ h _ => @T1Space.mk _ a fun x => (T1Space.t1 x).mono h #align t1_space_antitone t1Space_antitone theorem continuousWithinAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousWithinAt (Function.update f x y) s x' ↔ ContinuousWithinAt f s x' := EventuallyEq.congr_continuousWithinAt (mem_nhdsWithin_of_mem_nhds <| mem_of_superset (isOpen_ne.mem_nhds hne) fun _y' hy' => Function.update_noteq hy' _ _) (Function.update_noteq hne _ _) #align continuous_within_at_update_of_ne continuousWithinAt_update_of_ne theorem continuousAt_update_of_ne [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {x x' : X} {y : Y} (hne : x' ≠ x) : ContinuousAt (Function.update f x y) x' ↔ ContinuousAt f x' := by simp only [← continuousWithinAt_univ, continuousWithinAt_update_of_ne hne] #align continuous_at_update_of_ne continuousAt_update_of_ne theorem continuousOn_update_iff [T1Space X] [DecidableEq X] [TopologicalSpace Y] {f : X → Y} {s : Set X} {x : X} {y : Y} : ContinuousOn (Function.update f x y) s ↔ ContinuousOn f (s \ {x}) ∧ (x ∈ s → Tendsto f (𝓝[s \ {x}] x) (𝓝 y)) := by rw [ContinuousOn, ← and_forall_ne x, and_comm] refine and_congr ⟨fun H z hz => ?_, fun H z hzx hzs => ?_⟩ (forall_congr' fun _ => ?_) · specialize H z hz.2 hz.1 rw [continuousWithinAt_update_of_ne hz.2] at H exact H.mono diff_subset · rw [continuousWithinAt_update_of_ne hzx] refine (H z ⟨hzs, hzx⟩).mono_of_mem (inter_mem_nhdsWithin _ ?_) exact isOpen_ne.mem_nhds hzx · exact continuousWithinAt_update_same #align continuous_on_update_iff continuousOn_update_iff theorem t1Space_of_injective_of_continuous [TopologicalSpace Y] {f : X → Y} (hf : Function.Injective f) (hf' : Continuous f) [T1Space Y] : T1Space X := t1Space_iff_specializes_imp_eq.2 fun _ _ h => hf (h.map hf').eq #align t1_space_of_injective_of_continuous t1Space_of_injective_of_continuous protected theorem Embedding.t1Space [TopologicalSpace Y] [T1Space Y] {f : X → Y} (hf : Embedding f) : T1Space X := t1Space_of_injective_of_continuous hf.inj hf.continuous #align embedding.t1_space Embedding.t1Space instance Subtype.t1Space {X : Type u} [TopologicalSpace X] [T1Space X] {p : X → Prop} : T1Space (Subtype p) := embedding_subtype_val.t1Space #align subtype.t1_space Subtype.t1Space instance [TopologicalSpace Y] [T1Space X] [T1Space Y] : T1Space (X × Y) := ⟨fun ⟨a, b⟩ => @singleton_prod_singleton _ _ a b ▸ isClosed_singleton.prod isClosed_singleton⟩ instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, T1Space (X i)] : T1Space (∀ i, X i) := ⟨fun f => univ_pi_singleton f ▸ isClosed_set_pi fun _ _ => isClosed_singleton⟩ instance ULift.instT1Space [T1Space X] : T1Space (ULift X) := embedding_uLift_down.t1Space -- see Note [lower instance priority] instance (priority := 100) TotallyDisconnectedSpace.t1Space [h: TotallyDisconnectedSpace X] : T1Space X := by rw [((t1Space_TFAE X).out 0 1 :)] intro x rw [← totallyDisconnectedSpace_iff_connectedComponent_singleton.mp h x] exact isClosed_connectedComponent -- see Note [lower instance priority] instance (priority := 100) T1Space.t0Space [T1Space X] : T0Space X := ⟨fun _ _ h => h.specializes.eq⟩ #align t1_space.t0_space T1Space.t0Space @[simp] theorem compl_singleton_mem_nhds_iff [T1Space X] {x y : X} : {x}ᶜ ∈ 𝓝 y ↔ y ≠ x := isOpen_compl_singleton.mem_nhds_iff #align compl_singleton_mem_nhds_iff compl_singleton_mem_nhds_iff theorem compl_singleton_mem_nhds [T1Space X] {x y : X} (h : y ≠ x) : {x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds_iff.mpr h #align compl_singleton_mem_nhds compl_singleton_mem_nhds @[simp] theorem closure_singleton [T1Space X] {x : X} : closure ({x} : Set X) = {x} := isClosed_singleton.closure_eq #align closure_singleton closure_singleton -- Porting note (#11215): TODO: the proof was `hs.induction_on (by simp) fun x => by simp` theorem Set.Subsingleton.closure [T1Space X] {s : Set X} (hs : s.Subsingleton) : (closure s).Subsingleton := by rcases hs.eq_empty_or_singleton with (rfl | ⟨x, rfl⟩) <;> simp #align set.subsingleton.closure Set.Subsingleton.closure @[simp] theorem subsingleton_closure [T1Space X] {s : Set X} : (closure s).Subsingleton ↔ s.Subsingleton := ⟨fun h => h.anti subset_closure, fun h => h.closure⟩ #align subsingleton_closure subsingleton_closure theorem isClosedMap_const {X Y} [TopologicalSpace X] [TopologicalSpace Y] [T1Space Y] {y : Y} : IsClosedMap (Function.const X y) := IsClosedMap.of_nonempty fun s _ h2s => by simp_rw [const, h2s.image_const, isClosed_singleton] #align is_closed_map_const isClosedMap_const theorem nhdsWithin_insert_of_ne [T1Space X] {x y : X} {s : Set X} (hxy : x ≠ y) : 𝓝[insert y s] x = 𝓝[s] x := by refine le_antisymm (Filter.le_def.2 fun t ht => ?_) (nhdsWithin_mono x <| subset_insert y s) obtain ⟨o, ho, hxo, host⟩ := mem_nhdsWithin.mp ht refine mem_nhdsWithin.mpr ⟨o \ {y}, ho.sdiff isClosed_singleton, ⟨hxo, hxy⟩, ?_⟩ rw [inter_insert_of_not_mem <| not_mem_diff_of_mem (mem_singleton y)] exact (inter_subset_inter diff_subset Subset.rfl).trans host #align nhds_within_insert_of_ne nhdsWithin_insert_of_ne /-- If `t` is a subset of `s`, except for one point, then `insert x s` is a neighborhood of `x` within `t`. -/ theorem insert_mem_nhdsWithin_of_subset_insert [T1Space X] {x y : X} {s t : Set X} (hu : t ⊆ insert y s) : insert x s ∈ 𝓝[t] x := by rcases eq_or_ne x y with (rfl | h) · exact mem_of_superset self_mem_nhdsWithin hu refine nhdsWithin_mono x hu ?_ rw [nhdsWithin_insert_of_ne h] exact mem_of_superset self_mem_nhdsWithin (subset_insert x s) #align insert_mem_nhds_within_of_subset_insert insert_mem_nhdsWithin_of_subset_insert @[simp] theorem ker_nhds [T1Space X] (x : X) : (𝓝 x).ker = {x} := by simp [ker_nhds_eq_specializes] theorem biInter_basis_nhds [T1Space X] {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {x : X} (h : (𝓝 x).HasBasis p s) : ⋂ (i) (_ : p i), s i = {x} := by rw [← h.ker, ker_nhds] #align bInter_basis_nhds biInter_basis_nhds @[simp] theorem compl_singleton_mem_nhdsSet_iff [T1Space X] {x : X} {s : Set X} : {x}ᶜ ∈ 𝓝ˢ s ↔ x ∉ s := by rw [isOpen_compl_singleton.mem_nhdsSet, subset_compl_singleton_iff] #align compl_singleton_mem_nhds_set_iff compl_singleton_mem_nhdsSet_iff @[simp] theorem nhdsSet_le_iff [T1Space X] {s t : Set X} : 𝓝ˢ s ≤ 𝓝ˢ t ↔ s ⊆ t := by refine ⟨?_, fun h => monotone_nhdsSet h⟩ simp_rw [Filter.le_def]; intro h x hx specialize h {x}ᶜ simp_rw [compl_singleton_mem_nhdsSet_iff] at h by_contra hxt exact h hxt hx #align nhds_set_le_iff nhdsSet_le_iff @[simp] theorem nhdsSet_inj_iff [T1Space X] {s t : Set X} : 𝓝ˢ s = 𝓝ˢ t ↔ s = t := by simp_rw [le_antisymm_iff] exact and_congr nhdsSet_le_iff nhdsSet_le_iff #align nhds_set_inj_iff nhdsSet_inj_iff theorem injective_nhdsSet [T1Space X] : Function.Injective (𝓝ˢ : Set X → Filter X) := fun _ _ hst => nhdsSet_inj_iff.mp hst #align injective_nhds_set injective_nhdsSet theorem strictMono_nhdsSet [T1Space X] : StrictMono (𝓝ˢ : Set X → Filter X) := monotone_nhdsSet.strictMono_of_injective injective_nhdsSet #align strict_mono_nhds_set strictMono_nhdsSet @[simp] theorem nhds_le_nhdsSet_iff [T1Space X] {s : Set X} {x : X} : 𝓝 x ≤ 𝓝ˢ s ↔ x ∈ s := by rw [← nhdsSet_singleton, nhdsSet_le_iff, singleton_subset_iff] #align nhds_le_nhds_set_iff nhds_le_nhdsSet_iff /-- Removing a non-isolated point from a dense set, one still obtains a dense set. -/ theorem Dense.diff_singleton [T1Space X] {s : Set X} (hs : Dense s) (x : X) [NeBot (𝓝[≠] x)] : Dense (s \ {x}) := hs.inter_of_isOpen_right (dense_compl_singleton x) isOpen_compl_singleton #align dense.diff_singleton Dense.diff_singleton /-- Removing a finset from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finset [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) (t : Finset X) : Dense (s \ t) := by induction t using Finset.induction_on with | empty => simpa using hs | insert _ ih => rw [Finset.coe_insert, ← union_singleton, ← diff_diff] exact ih.diff_singleton _ #align dense.diff_finset Dense.diff_finset /-- Removing a finite set from a dense set in a space without isolated points, one still obtains a dense set. -/ theorem Dense.diff_finite [T1Space X] [∀ x : X, NeBot (𝓝[≠] x)] {s : Set X} (hs : Dense s) {t : Set X} (ht : t.Finite) : Dense (s \ t) := by convert hs.diff_finset ht.toFinset exact (Finite.coe_toFinset _).symm #align dense.diff_finite Dense.diff_finite /-- If a function to a `T1Space` tends to some limit `y` at some point `x`, then necessarily `y = f x`. -/ theorem eq_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : f x = y := by_contra fun hfa : f x ≠ y => have fact₁ : {f x}ᶜ ∈ 𝓝 y := compl_singleton_mem_nhds hfa.symm have fact₂ : Tendsto f (pure x) (𝓝 y) := h.comp (tendsto_id'.2 <| pure_le_nhds x) fact₂ fact₁ (Eq.refl <| f x) #align eq_of_tendsto_nhds eq_of_tendsto_nhds theorem Filter.Tendsto.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {l : Filter X} {b₁ b₂ : Y} (hg : Tendsto g l (𝓝 b₁)) (hb : b₁ ≠ b₂) : ∀ᶠ z in l, g z ≠ b₂ := hg.eventually (isOpen_compl_singleton.eventually_mem hb) #align filter.tendsto.eventually_ne Filter.Tendsto.eventually_ne theorem ContinuousAt.eventually_ne [TopologicalSpace Y] [T1Space Y] {g : X → Y} {x : X} {y : Y} (hg1 : ContinuousAt g x) (hg2 : g x ≠ y) : ∀ᶠ z in 𝓝 x, g z ≠ y := hg1.tendsto.eventually_ne hg2 #align continuous_at.eventually_ne ContinuousAt.eventually_ne theorem eventually_ne_nhds [T1Space X] {a b : X} (h : a ≠ b) : ∀ᶠ x in 𝓝 a, x ≠ b := IsOpen.eventually_mem isOpen_ne h theorem eventually_ne_nhdsWithin [T1Space X] {a b : X} {s : Set X} (h : a ≠ b) : ∀ᶠ x in 𝓝[s] a, x ≠ b := Filter.Eventually.filter_mono nhdsWithin_le_nhds <| eventually_ne_nhds h /-- To prove a function to a `T1Space` is continuous at some point `x`, it suffices to prove that `f` admits *some* limit at `x`. -/ theorem continuousAt_of_tendsto_nhds [TopologicalSpace Y] [T1Space Y] {f : X → Y} {x : X} {y : Y} (h : Tendsto f (𝓝 x) (𝓝 y)) : ContinuousAt f x := by rwa [ContinuousAt, eq_of_tendsto_nhds h] #align continuous_at_of_tendsto_nhds continuousAt_of_tendsto_nhds @[simp] theorem tendsto_const_nhds_iff [T1Space X] {l : Filter Y} [NeBot l] {c d : X} : Tendsto (fun _ => c) l (𝓝 d) ↔ c = d := by simp_rw [Tendsto, Filter.map_const, pure_le_nhds_iff] #align tendsto_const_nhds_iff tendsto_const_nhds_iff /-- A point with a finite neighborhood has to be isolated. -/ theorem isOpen_singleton_of_finite_mem_nhds [T1Space X] (x : X) {s : Set X} (hs : s ∈ 𝓝 x) (hsf : s.Finite) : IsOpen ({x} : Set X) := by have A : {x} ⊆ s := by simp only [singleton_subset_iff, mem_of_mem_nhds hs] have B : IsClosed (s \ {x}) := (hsf.subset diff_subset).isClosed have C : (s \ {x})ᶜ ∈ 𝓝 x := B.isOpen_compl.mem_nhds fun h => h.2 rfl have D : {x} ∈ 𝓝 x := by simpa only [← diff_eq, diff_diff_cancel_left A] using inter_mem hs C rwa [← mem_interior_iff_mem_nhds, ← singleton_subset_iff, subset_interior_iff_isOpen] at D #align is_open_singleton_of_finite_mem_nhds isOpen_singleton_of_finite_mem_nhds /-- If the punctured neighborhoods of a point form a nontrivial filter, then any neighborhood is infinite. -/ theorem infinite_of_mem_nhds {X} [TopologicalSpace X] [T1Space X] (x : X) [hx : NeBot (𝓝[≠] x)] {s : Set X} (hs : s ∈ 𝓝 x) : Set.Infinite s := by refine fun hsf => hx.1 ?_ rw [← isOpen_singleton_iff_punctured_nhds] exact isOpen_singleton_of_finite_mem_nhds x hs hsf #align infinite_of_mem_nhds infinite_of_mem_nhds theorem discrete_of_t1_of_finite [T1Space X] [Finite X] : DiscreteTopology X := by apply singletons_open_iff_discrete.mp intro x rw [← isClosed_compl_iff] exact (Set.toFinite _).isClosed #align discrete_of_t1_of_finite discrete_of_t1_of_finite
Mathlib/Topology/Separation.lean
901
906
theorem PreconnectedSpace.trivial_of_discrete [PreconnectedSpace X] [DiscreteTopology X] : Subsingleton X := by
rw [← not_nontrivial_iff_subsingleton] rintro ⟨x, y, hxy⟩ rw [Ne, ← mem_singleton_iff, (isClopen_discrete _).eq_univ <| singleton_nonempty y] at hxy exact hxy (mem_univ x)
/- 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.MeasureTheory.Function.EssSup import Mathlib.MeasureTheory.Function.AEEqFun import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic #align_import measure_theory.function.lp_seminorm from "leanprover-community/mathlib"@"c4015acc0a223449d44061e27ddac1835a3852b9" /-! # ℒp space This file describes properties of almost everywhere strongly measurable functions with finite `p`-seminorm, denoted by `snorm f p μ` and defined for `p:ℝ≥0∞` as `0` if `p=0`, `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and `essSup ‖f‖ μ` for `p=∞`. The Prop-valued `Memℒp f p μ` states that a function `f : α → E` has finite `p`-seminorm and is almost everywhere strongly measurable. ## Main definitions * `snorm' f p μ` : `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `f : α → F` and `p : ℝ`, where `α` is a measurable space and `F` is a normed group. * `snormEssSup f μ` : seminorm in `ℒ∞`, equal to the essential supremum `ess_sup ‖f‖ μ`. * `snorm f p μ` : for `p : ℝ≥0∞`, seminorm in `ℒp`, equal to `0` for `p=0`, to `snorm' f p μ` for `0 < p < ∞` and to `snormEssSup f μ` for `p = ∞`. * `Memℒp f p μ` : property that the function `f` is almost everywhere strongly measurable and has finite `p`-seminorm for the measure `μ` (`snorm f p μ < ∞`) -/ noncomputable section set_option linter.uppercaseLean3 false open TopologicalSpace MeasureTheory Filter open scoped NNReal ENNReal Topology variable {α E F G : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ ν : Measure α} [NormedAddCommGroup E] [NormedAddCommGroup F] [NormedAddCommGroup G] namespace MeasureTheory section ℒp /-! ### ℒp seminorm We define the ℒp seminorm, denoted by `snorm f p μ`. For real `p`, it is given by an integral formula (for which we use the notation `snorm' f p μ`), and for `p = ∞` it is the essential supremum (for which we use the notation `snormEssSup f μ`). We also define a predicate `Memℒp f p μ`, requesting that a function is almost everywhere measurable and has finite `snorm f p μ`. This paragraph is devoted to the basic properties of these definitions. It is constructed as follows: for a given property, we prove it for `snorm'` and `snormEssSup` when it makes sense, deduce it for `snorm`, and translate it in terms of `Memℒp`. -/ section ℒpSpaceDefinition /-- `(∫ ‖f a‖^q ∂μ) ^ (1/q)`, which is a seminorm on the space of measurable functions for which this quantity is finite -/ def snorm' {_ : MeasurableSpace α} (f : α → F) (q : ℝ) (μ : Measure α) : ℝ≥0∞ := (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) ^ (1 / q) #align measure_theory.snorm' MeasureTheory.snorm' /-- seminorm for `ℒ∞`, equal to the essential supremum of `‖f‖`. -/ def snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) := essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ #align measure_theory.snorm_ess_sup MeasureTheory.snormEssSup /-- `ℒp` seminorm, equal to `0` for `p=0`, to `(∫ ‖f a‖^p ∂μ) ^ (1/p)` for `0 < p < ∞` and to `essSup ‖f‖ μ` for `p = ∞`. -/ def snorm {_ : MeasurableSpace α} (f : α → F) (p : ℝ≥0∞) (μ : Measure α) : ℝ≥0∞ := if p = 0 then 0 else if p = ∞ then snormEssSup f μ else snorm' f (ENNReal.toReal p) μ #align measure_theory.snorm MeasureTheory.snorm theorem snorm_eq_snorm' (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = snorm' f (ENNReal.toReal p) μ := by simp [snorm, hp_ne_zero, hp_ne_top] #align measure_theory.snorm_eq_snorm' MeasureTheory.snorm_eq_snorm' theorem snorm_eq_lintegral_rpow_nnnorm (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} : snorm f p μ = (∫⁻ x, (‖f x‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) ^ (1 / p.toReal) := by rw [snorm_eq_snorm' hp_ne_zero hp_ne_top, snorm'] #align measure_theory.snorm_eq_lintegral_rpow_nnnorm MeasureTheory.snorm_eq_lintegral_rpow_nnnorm theorem snorm_one_eq_lintegral_nnnorm {f : α → F} : snorm f 1 μ = ∫⁻ x, ‖f x‖₊ ∂μ := by simp_rw [snorm_eq_lintegral_rpow_nnnorm one_ne_zero ENNReal.coe_ne_top, ENNReal.one_toReal, one_div_one, ENNReal.rpow_one] #align measure_theory.snorm_one_eq_lintegral_nnnorm MeasureTheory.snorm_one_eq_lintegral_nnnorm @[simp] theorem snorm_exponent_top {f : α → F} : snorm f ∞ μ = snormEssSup f μ := by simp [snorm] #align measure_theory.snorm_exponent_top MeasureTheory.snorm_exponent_top /-- The property that `f:α→E` is ae strongly measurable and `(∫ ‖f a‖^p ∂μ)^(1/p)` is finite if `p < ∞`, or `essSup f < ∞` if `p = ∞`. -/ def Memℒp {α} {_ : MeasurableSpace α} (f : α → E) (p : ℝ≥0∞) (μ : Measure α := by volume_tac) : Prop := AEStronglyMeasurable f μ ∧ snorm f p μ < ∞ #align measure_theory.mem_ℒp MeasureTheory.Memℒp theorem Memℒp.aestronglyMeasurable {f : α → E} {p : ℝ≥0∞} (h : Memℒp f p μ) : AEStronglyMeasurable f μ := h.1 #align measure_theory.mem_ℒp.ae_strongly_measurable MeasureTheory.Memℒp.aestronglyMeasurable theorem lintegral_rpow_nnnorm_eq_rpow_snorm' {f : α → F} (hq0_lt : 0 < q) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) = snorm' f q μ ^ q := by rw [snorm', ← ENNReal.rpow_mul, one_div, inv_mul_cancel, ENNReal.rpow_one] exact (ne_of_lt hq0_lt).symm #align measure_theory.lintegral_rpow_nnnorm_eq_rpow_snorm' MeasureTheory.lintegral_rpow_nnnorm_eq_rpow_snorm' end ℒpSpaceDefinition section Top theorem Memℒp.snorm_lt_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ < ∞ := hfp.2 #align measure_theory.mem_ℒp.snorm_lt_top MeasureTheory.Memℒp.snorm_lt_top theorem Memℒp.snorm_ne_top {f : α → E} (hfp : Memℒp f p μ) : snorm f p μ ≠ ∞ := ne_of_lt hfp.2 #align measure_theory.mem_ℒp.snorm_ne_top MeasureTheory.Memℒp.snorm_ne_top theorem lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top {f : α → F} (hq0_lt : 0 < q) (hfq : snorm' f q μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ q ∂μ) < ∞ := by rw [lintegral_rpow_nnnorm_eq_rpow_snorm' hq0_lt] exact ENNReal.rpow_lt_top_of_nonneg (le_of_lt hq0_lt) (ne_of_lt hfq) #align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top theorem lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) (hfp : snorm f p μ < ∞) : (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := by apply lintegral_rpow_nnnorm_lt_top_of_snorm'_lt_top · exact ENNReal.toReal_pos hp_ne_zero hp_ne_top · simpa [snorm_eq_snorm' hp_ne_zero hp_ne_top] using hfp #align measure_theory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top MeasureTheory.lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top theorem snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top {f : α → F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : snorm f p μ < ∞ ↔ (∫⁻ a, (‖f a‖₊ : ℝ≥0∞) ^ p.toReal ∂μ) < ∞ := ⟨lintegral_rpow_nnnorm_lt_top_of_snorm_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 [snorm_eq_lintegral_rpow_nnnorm hp_ne_zero hp_ne_top] using ENNReal.rpow_lt_top_of_nonneg (le_of_lt this) (ne_of_lt h)⟩ #align measure_theory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top MeasureTheory.snorm_lt_top_iff_lintegral_rpow_nnnorm_lt_top end Top section Zero @[simp] theorem snorm'_exponent_zero {f : α → F} : snorm' f 0 μ = 1 := by rw [snorm', div_zero, ENNReal.rpow_zero] #align measure_theory.snorm'_exponent_zero MeasureTheory.snorm'_exponent_zero @[simp] theorem snorm_exponent_zero {f : α → F} : snorm f 0 μ = 0 := by simp [snorm] #align measure_theory.snorm_exponent_zero MeasureTheory.snorm_exponent_zero @[simp] theorem memℒp_zero_iff_aestronglyMeasurable {f : α → E} : Memℒp f 0 μ ↔ AEStronglyMeasurable f μ := by simp [Memℒp, snorm_exponent_zero] #align measure_theory.mem_ℒp_zero_iff_ae_strongly_measurable MeasureTheory.memℒp_zero_iff_aestronglyMeasurable @[simp] theorem snorm'_zero (hp0_lt : 0 < q) : snorm' (0 : α → F) q μ = 0 := by simp [snorm', hp0_lt] #align measure_theory.snorm'_zero MeasureTheory.snorm'_zero @[simp] theorem snorm'_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) : snorm' (0 : α → F) q μ = 0 := by rcases le_or_lt 0 q with hq0 | hq_neg · exact snorm'_zero (lt_of_le_of_ne hq0 hq0_ne.symm) · simp [snorm', ENNReal.rpow_eq_zero_iff, hμ, hq_neg] #align measure_theory.snorm'_zero' MeasureTheory.snorm'_zero' @[simp] theorem snormEssSup_zero : snormEssSup (0 : α → F) μ = 0 := by simp_rw [snormEssSup, Pi.zero_apply, nnnorm_zero, ENNReal.coe_zero, ← ENNReal.bot_eq_zero] exact essSup_const_bot #align measure_theory.snorm_ess_sup_zero MeasureTheory.snormEssSup_zero @[simp] theorem snorm_zero : snorm (0 : α → F) p μ = 0 := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp only [h_top, snorm_exponent_top, snormEssSup_zero] rw [← Ne] at h0 simp [snorm_eq_snorm' h0 h_top, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_zero MeasureTheory.snorm_zero @[simp] theorem snorm_zero' : snorm (fun _ : α => (0 : F)) p μ = 0 := by convert snorm_zero (F := F) #align measure_theory.snorm_zero' MeasureTheory.snorm_zero' theorem zero_memℒp : Memℒp (0 : α → E) p μ := ⟨aestronglyMeasurable_zero, by rw [snorm_zero] exact ENNReal.coe_lt_top⟩ #align measure_theory.zero_mem_ℒp MeasureTheory.zero_memℒp theorem zero_mem_ℒp' : Memℒp (fun _ : α => (0 : E)) p μ := zero_memℒp (E := E) #align measure_theory.zero_mem_ℒp' MeasureTheory.zero_mem_ℒp' variable [MeasurableSpace α] theorem snorm'_measure_zero_of_pos {f : α → F} (hq_pos : 0 < q) : snorm' f q (0 : Measure α) = 0 := by simp [snorm', hq_pos] #align measure_theory.snorm'_measure_zero_of_pos MeasureTheory.snorm'_measure_zero_of_pos theorem snorm'_measure_zero_of_exponent_zero {f : α → F} : snorm' f 0 (0 : Measure α) = 1 := by simp [snorm'] #align measure_theory.snorm'_measure_zero_of_exponent_zero MeasureTheory.snorm'_measure_zero_of_exponent_zero theorem snorm'_measure_zero_of_neg {f : α → F} (hq_neg : q < 0) : snorm' f q (0 : Measure α) = ∞ := by simp [snorm', hq_neg] #align measure_theory.snorm'_measure_zero_of_neg MeasureTheory.snorm'_measure_zero_of_neg @[simp] theorem snormEssSup_measure_zero {f : α → F} : snormEssSup f (0 : Measure α) = 0 := by simp [snormEssSup] #align measure_theory.snorm_ess_sup_measure_zero MeasureTheory.snormEssSup_measure_zero @[simp] theorem snorm_measure_zero {f : α → F} : snorm 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 [snorm_eq_snorm' h0 h_top, snorm', ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_measure_zero MeasureTheory.snorm_measure_zero end Zero section Neg @[simp] theorem snorm'_neg {f : α → F} : snorm' (-f) q μ = snorm' f q μ := by simp [snorm'] #align measure_theory.snorm'_neg MeasureTheory.snorm'_neg @[simp] theorem snorm_neg {f : α → F} : snorm (-f) p μ = snorm f p μ := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · simp [h_top, snormEssSup] simp [snorm_eq_snorm' h0 h_top] #align measure_theory.snorm_neg MeasureTheory.snorm_neg theorem Memℒp.neg {f : α → E} (hf : Memℒp f p μ) : Memℒp (-f) p μ := ⟨AEStronglyMeasurable.neg hf.1, by simp [hf.right]⟩ #align measure_theory.mem_ℒp.neg MeasureTheory.Memℒp.neg theorem memℒp_neg_iff {f : α → E} : Memℒp (-f) p μ ↔ Memℒp f p μ := ⟨fun h => neg_neg f ▸ h.neg, Memℒp.neg⟩ #align measure_theory.mem_ℒp_neg_iff MeasureTheory.memℒp_neg_iff end Neg section Const theorem snorm'_const (c : F) (hq_pos : 0 < q) : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by rw [snorm', lintegral_const, ENNReal.mul_rpow_of_nonneg _ _ (by simp [hq_pos.le] : 0 ≤ 1 / q)] congr rw [← ENNReal.rpow_mul] suffices hq_cancel : q * (1 / q) = 1 by rw [hq_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel (ne_of_lt hq_pos).symm] #align measure_theory.snorm'_const MeasureTheory.snorm'_const theorem snorm'_const' [IsFiniteMeasure μ] (c : F) (hc_ne_zero : c ≠ 0) (hq_ne_zero : q ≠ 0) : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / q) := by rw [snorm', lintegral_const, ENNReal.mul_rpow_of_ne_top _ (measure_ne_top μ Set.univ)] · congr rw [← ENNReal.rpow_mul] suffices hp_cancel : q * (1 / q) = 1 by rw [hp_cancel, ENNReal.rpow_one] rw [one_div, mul_inv_cancel hq_ne_zero] · rw [Ne, ENNReal.rpow_eq_top_iff, not_or, not_and_or, not_and_or] constructor · left rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] · exact Or.inl ENNReal.coe_ne_top #align measure_theory.snorm'_const' MeasureTheory.snorm'_const' theorem snormEssSup_const (c : F) (hμ : μ ≠ 0) : snormEssSup (fun _ : α => c) μ = (‖c‖₊ : ℝ≥0∞) := by rw [snormEssSup, essSup_const _ hμ] #align measure_theory.snorm_ess_sup_const MeasureTheory.snormEssSup_const theorem snorm'_const_of_isProbabilityMeasure (c : F) (hq_pos : 0 < q) [IsProbabilityMeasure μ] : snorm' (fun _ : α => c) q μ = (‖c‖₊ : ℝ≥0∞) := by simp [snorm'_const c hq_pos, measure_univ] #align measure_theory.snorm'_const_of_is_probability_measure MeasureTheory.snorm'_const_of_isProbabilityMeasure theorem snorm_const (c : F) (h0 : p ≠ 0) (hμ : μ ≠ 0) : snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by by_cases h_top : p = ∞ · simp [h_top, snormEssSup_const c hμ] simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_const MeasureTheory.snorm_const theorem snorm_const' (c : F) (h0 : p ≠ 0) (h_top : p ≠ ∞) : snorm (fun _ : α => c) p μ = (‖c‖₊ : ℝ≥0∞) * μ Set.univ ^ (1 / ENNReal.toReal p) := by simp [snorm_eq_snorm' h0 h_top, snorm'_const, ENNReal.toReal_pos h0 h_top] #align measure_theory.snorm_const' MeasureTheory.snorm_const' theorem snorm_const_lt_top_iff {p : ℝ≥0∞} {c : F} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : snorm (fun _ : α => c) p μ < ∞ ↔ c = 0 ∨ μ Set.univ < ∞ := by have hp : 0 < p.toReal := ENNReal.toReal_pos hp_ne_zero hp_ne_top by_cases hμ : μ = 0 · simp only [hμ, Measure.coe_zero, Pi.zero_apply, or_true_iff, ENNReal.zero_lt_top, snorm_measure_zero] by_cases hc : c = 0 · simp only [hc, true_or_iff, eq_self_iff_true, ENNReal.zero_lt_top, snorm_zero'] rw [snorm_const' c hp_ne_zero hp_ne_top] by_cases hμ_top : μ Set.univ = ∞ · simp [hc, hμ_top, hp] rw [ENNReal.mul_lt_top_iff] simp only [true_and_iff, one_div, ENNReal.rpow_eq_zero_iff, hμ, false_or_iff, or_false_iff, ENNReal.coe_lt_top, nnnorm_eq_zero, ENNReal.coe_eq_zero, MeasureTheory.Measure.measure_univ_eq_zero, hp, inv_lt_zero, hc, and_false_iff, false_and_iff, inv_pos, or_self_iff, hμ_top, Ne.lt_top hμ_top, iff_true_iff] exact ENNReal.rpow_lt_top_of_nonneg (inv_nonneg.mpr hp.le) hμ_top #align measure_theory.snorm_const_lt_top_iff MeasureTheory.snorm_const_lt_top_iff theorem memℒp_const (c : E) [IsFiniteMeasure μ] : Memℒp (fun _ : α => c) p μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h0 : p = 0 · simp [h0] by_cases hμ : μ = 0 · simp [hμ] rw [snorm_const c h0 hμ] refine ENNReal.mul_lt_top ENNReal.coe_ne_top ?_ refine (ENNReal.rpow_lt_top_of_nonneg ?_ (measure_ne_top μ Set.univ)).ne simp #align measure_theory.mem_ℒp_const MeasureTheory.memℒp_const theorem memℒp_top_const (c : E) : Memℒp (fun _ : α => c) ∞ μ := by refine ⟨aestronglyMeasurable_const, ?_⟩ by_cases h : μ = 0 · simp only [h, snorm_measure_zero, ENNReal.zero_lt_top] · rw [snorm_const _ ENNReal.top_ne_zero h] simp only [ENNReal.top_toReal, div_zero, ENNReal.rpow_zero, mul_one, ENNReal.coe_lt_top] #align measure_theory.mem_ℒp_top_const MeasureTheory.memℒp_top_const theorem memℒp_const_iff {p : ℝ≥0∞} {c : E} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) : Memℒp (fun _ : α => c) p μ ↔ c = 0 ∨ μ Set.univ < ∞ := by rw [← snorm_const_lt_top_iff hp_ne_zero hp_ne_top] exact ⟨fun h => h.2, fun h => ⟨aestronglyMeasurable_const, h⟩⟩ #align measure_theory.mem_ℒp_const_iff MeasureTheory.memℒp_const_iff end Const theorem snorm'_mono_nnnorm_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snorm' f q μ ≤ snorm' g q μ := by simp only [snorm'] gcongr ?_ ^ (1/q) refine lintegral_mono_ae (h.mono fun x hx => ?_) gcongr #align measure_theory.snorm'_mono_nnnorm_ae MeasureTheory.snorm'_mono_nnnorm_ae theorem snorm'_mono_ae {f : α → F} {g : α → G} (hq : 0 ≤ q) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : snorm' f q μ ≤ snorm' g q μ := snorm'_mono_nnnorm_ae hq h #align measure_theory.snorm'_mono_ae MeasureTheory.snorm'_mono_ae theorem snorm'_congr_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : snorm' f q μ = snorm' g q μ := by have : (fun x => (‖f x‖₊ : ℝ≥0∞) ^ q) =ᵐ[μ] fun x => (‖g x‖₊ : ℝ≥0∞) ^ q := hfg.mono fun x hx => by simp_rw [hx] simp only [snorm', lintegral_congr_ae this] #align measure_theory.snorm'_congr_nnnorm_ae MeasureTheory.snorm'_congr_nnnorm_ae theorem snorm'_congr_norm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : snorm' f q μ = snorm' g q μ := snorm'_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx #align measure_theory.snorm'_congr_norm_ae MeasureTheory.snorm'_congr_norm_ae theorem snorm'_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm' f q μ = snorm' g q μ := snorm'_congr_nnnorm_ae (hfg.fun_comp _) #align measure_theory.snorm'_congr_ae MeasureTheory.snorm'_congr_ae theorem snormEssSup_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snormEssSup f μ = snormEssSup g μ := essSup_congr_ae (hfg.fun_comp (((↑) : ℝ≥0 → ℝ≥0∞) ∘ nnnorm)) #align measure_theory.snorm_ess_sup_congr_ae MeasureTheory.snormEssSup_congr_ae theorem snormEssSup_mono_nnnorm_ae {f g : α → F} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snormEssSup f μ ≤ snormEssSup g μ := essSup_mono_ae <| hfg.mono fun _x hx => ENNReal.coe_le_coe.mpr hx #align measure_theory.snorm_ess_sup_mono_nnnorm_ae MeasureTheory.snormEssSup_mono_nnnorm_ae theorem snorm_mono_nnnorm_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖g x‖₊) : snorm f p μ ≤ snorm g p μ := by simp only [snorm] split_ifs · exact le_rfl · exact essSup_mono_ae (h.mono fun x hx => ENNReal.coe_le_coe.mpr hx) · exact snorm'_mono_nnnorm_ae ENNReal.toReal_nonneg h #align measure_theory.snorm_mono_nnnorm_ae MeasureTheory.snorm_mono_nnnorm_ae theorem snorm_mono_ae {f : α → F} {g : α → G} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : snorm f p μ ≤ snorm g p μ := snorm_mono_nnnorm_ae h #align measure_theory.snorm_mono_ae MeasureTheory.snorm_mono_ae theorem snorm_mono_ae_real {f : α → F} {g : α → ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae <| h.mono fun _x hx => hx.trans ((le_abs_self _).trans (Real.norm_eq_abs _).symm.le) #align measure_theory.snorm_mono_ae_real MeasureTheory.snorm_mono_ae_real theorem snorm_mono_nnnorm {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖₊ ≤ ‖g x‖₊) : snorm f p μ ≤ snorm g p μ := snorm_mono_nnnorm_ae (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono_nnnorm MeasureTheory.snorm_mono_nnnorm theorem snorm_mono {f : α → F} {g : α → G} (h : ∀ x, ‖f x‖ ≤ ‖g x‖) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono MeasureTheory.snorm_mono theorem snorm_mono_real {f : α → F} {g : α → ℝ} (h : ∀ x, ‖f x‖ ≤ g x) : snorm f p μ ≤ snorm g p μ := snorm_mono_ae_real (eventually_of_forall fun x => h x) #align measure_theory.snorm_mono_real MeasureTheory.snorm_mono_real theorem snormEssSup_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snormEssSup f μ ≤ C := essSup_le_of_ae_le (C : ℝ≥0∞) <| hfC.mono fun _x hx => ENNReal.coe_le_coe.mpr hx #align measure_theory.snorm_ess_sup_le_of_ae_nnnorm_bound MeasureTheory.snormEssSup_le_of_ae_nnnorm_bound theorem snormEssSup_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snormEssSup f μ ≤ ENNReal.ofReal C := snormEssSup_le_of_ae_nnnorm_bound <| hfC.mono fun _x hx => hx.trans C.le_coe_toNNReal #align measure_theory.snorm_ess_sup_le_of_ae_bound MeasureTheory.snormEssSup_le_of_ae_bound theorem snormEssSup_lt_top_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snormEssSup f μ < ∞ := (snormEssSup_le_of_ae_nnnorm_bound hfC).trans_lt ENNReal.coe_lt_top #align measure_theory.snorm_ess_sup_lt_top_of_ae_nnnorm_bound MeasureTheory.snormEssSup_lt_top_of_ae_nnnorm_bound theorem snormEssSup_lt_top_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snormEssSup f μ < ∞ := (snormEssSup_le_of_ae_bound hfC).trans_lt ENNReal.ofReal_lt_top #align measure_theory.snorm_ess_sup_lt_top_of_ae_bound MeasureTheory.snormEssSup_lt_top_of_ae_bound theorem snorm_le_of_ae_nnnorm_bound {f : α → F} {C : ℝ≥0} (hfC : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ C) : snorm f p μ ≤ C • μ Set.univ ^ p.toReal⁻¹ := by rcases eq_zero_or_neZero μ with rfl | hμ · simp by_cases hp : p = 0 · simp [hp] have : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ ‖(C : ℝ)‖₊ := hfC.mono fun x hx => hx.trans_eq C.nnnorm_eq.symm refine (snorm_mono_ae this).trans_eq ?_ rw [snorm_const _ hp (NeZero.ne μ), C.nnnorm_eq, one_div, ENNReal.smul_def, smul_eq_mul] #align measure_theory.snorm_le_of_ae_nnnorm_bound MeasureTheory.snorm_le_of_ae_nnnorm_bound theorem snorm_le_of_ae_bound {f : α → F} {C : ℝ} (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : snorm f p μ ≤ μ Set.univ ^ p.toReal⁻¹ * ENNReal.ofReal C := by rw [← mul_comm] exact snorm_le_of_ae_nnnorm_bound (hfC.mono fun x hx => hx.trans C.le_coe_toNNReal) #align measure_theory.snorm_le_of_ae_bound MeasureTheory.snorm_le_of_ae_bound theorem snorm_congr_nnnorm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ = ‖g x‖₊) : snorm f p μ = snorm g p μ := le_antisymm (snorm_mono_nnnorm_ae <| EventuallyEq.le hfg) (snorm_mono_nnnorm_ae <| (EventuallyEq.symm hfg).le) #align measure_theory.snorm_congr_nnnorm_ae MeasureTheory.snorm_congr_nnnorm_ae theorem snorm_congr_norm_ae {f : α → F} {g : α → G} (hfg : ∀ᵐ x ∂μ, ‖f x‖ = ‖g x‖) : snorm f p μ = snorm g p μ := snorm_congr_nnnorm_ae <| hfg.mono fun _x hx => NNReal.eq hx #align measure_theory.snorm_congr_norm_ae MeasureTheory.snorm_congr_norm_ae open scoped symmDiff in theorem snorm_indicator_sub_indicator (s t : Set α) (f : α → E) : snorm (s.indicator f - t.indicator f) p μ = snorm ((s ∆ t).indicator f) p μ := snorm_congr_norm_ae <| ae_of_all _ fun x ↦ by simp only [Pi.sub_apply, Set.apply_indicator_symmDiff norm_neg] @[simp] theorem snorm'_norm {f : α → F} : snorm' (fun a => ‖f a‖) q μ = snorm' f q μ := by simp [snorm'] #align measure_theory.snorm'_norm MeasureTheory.snorm'_norm @[simp] theorem snorm_norm (f : α → F) : snorm (fun x => ‖f x‖) p μ = snorm f p μ := snorm_congr_norm_ae <| eventually_of_forall fun _ => norm_norm _ #align measure_theory.snorm_norm MeasureTheory.snorm_norm theorem snorm'_norm_rpow (f : α → F) (p q : ℝ) (hq_pos : 0 < q) : snorm' (fun x => ‖f x‖ ^ q) p μ = snorm' f (p * q) μ ^ q := by simp_rw [snorm'] rw [← ENNReal.rpow_mul, ← one_div_mul_one_div] simp_rw [one_div] rw [mul_assoc, inv_mul_cancel hq_pos.ne.symm, mul_one] congr ext1 x simp_rw [← ofReal_norm_eq_coe_nnnorm] rw [Real.norm_eq_abs, abs_eq_self.mpr (Real.rpow_nonneg (norm_nonneg _) _), mul_comm, ← ENNReal.ofReal_rpow_of_nonneg (norm_nonneg _) hq_pos.le, ENNReal.rpow_mul] #align measure_theory.snorm'_norm_rpow MeasureTheory.snorm'_norm_rpow theorem snorm_norm_rpow (f : α → F) (hq_pos : 0 < q) : snorm (fun x => ‖f x‖ ^ q) p μ = snorm f (p * ENNReal.ofReal q) μ ^ q := by by_cases h0 : p = 0 · simp [h0, ENNReal.zero_rpow_of_pos hq_pos] by_cases hp_top : p = ∞ · simp only [hp_top, snorm_exponent_top, ENNReal.top_mul', hq_pos.not_le, ENNReal.ofReal_eq_zero, if_false, snorm_exponent_top, snormEssSup] have h_rpow : essSup (fun x : α => (‖‖f x‖ ^ q‖₊ : ℝ≥0∞)) μ = essSup (fun x : α => (‖f x‖₊ : ℝ≥0∞) ^ q) μ := by congr ext1 x conv_rhs => rw [← nnnorm_norm] rw [ENNReal.coe_rpow_of_nonneg _ hq_pos.le, ENNReal.coe_inj] ext push_cast rw [Real.norm_rpow_of_nonneg (norm_nonneg _)] rw [h_rpow] have h_rpow_mono := ENNReal.strictMono_rpow_of_pos hq_pos have h_rpow_surj := (ENNReal.rpow_left_bijective hq_pos.ne.symm).2 let iso := h_rpow_mono.orderIsoOfSurjective _ h_rpow_surj exact (iso.essSup_apply (fun x => (‖f x‖₊ : ℝ≥0∞)) μ).symm rw [snorm_eq_snorm' h0 hp_top, snorm_eq_snorm' _ _] swap; · refine mul_ne_zero h0 ?_ rwa [Ne, ENNReal.ofReal_eq_zero, not_le] swap; · exact ENNReal.mul_ne_top hp_top ENNReal.ofReal_ne_top rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal hq_pos.le] exact snorm'_norm_rpow f p.toReal q hq_pos #align measure_theory.snorm_norm_rpow MeasureTheory.snorm_norm_rpow theorem snorm_congr_ae {f g : α → F} (hfg : f =ᵐ[μ] g) : snorm f p μ = snorm g p μ := snorm_congr_norm_ae <| hfg.mono fun _x hx => hx ▸ rfl #align measure_theory.snorm_congr_ae MeasureTheory.snorm_congr_ae theorem memℒp_congr_ae {f g : α → E} (hfg : f =ᵐ[μ] g) : Memℒp f p μ ↔ Memℒp g p μ := by simp only [Memℒp, snorm_congr_ae hfg, aestronglyMeasurable_congr hfg] #align measure_theory.mem_ℒp_congr_ae MeasureTheory.memℒp_congr_ae theorem Memℒp.ae_eq {f g : α → E} (hfg : f =ᵐ[μ] g) (hf_Lp : Memℒp f p μ) : Memℒp g p μ := (memℒp_congr_ae hfg).1 hf_Lp #align measure_theory.mem_ℒp.ae_eq MeasureTheory.Memℒp.ae_eq theorem Memℒp.of_le {f : α → E} {g : α → F} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ) (hfg : ∀ᵐ x ∂μ, ‖f x‖ ≤ ‖g x‖) : Memℒp f p μ := ⟨hf, (snorm_mono_ae hfg).trans_lt hg.snorm_lt_top⟩ #align measure_theory.mem_ℒp.of_le MeasureTheory.Memℒp.of_le alias Memℒp.mono := Memℒp.of_le #align measure_theory.mem_ℒp.mono MeasureTheory.Memℒp.mono theorem Memℒp.mono' {f : α → E} {g : α → ℝ} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ) (h : ∀ᵐ a ∂μ, ‖f a‖ ≤ g a) : Memℒp f p μ := hg.mono hf <| h.mono fun _x hx => le_trans hx (le_abs_self _) #align measure_theory.mem_ℒp.mono' MeasureTheory.Memℒp.mono' theorem Memℒp.congr_norm {f : α → E} {g : α → F} (hf : Memℒp f p μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Memℒp g p μ := hf.mono hg <| EventuallyEq.le <| EventuallyEq.symm h #align measure_theory.mem_ℒp.congr_norm MeasureTheory.Memℒp.congr_norm theorem memℒp_congr_norm {f : α → E} {g : α → F} (hf : AEStronglyMeasurable f μ) (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ a ∂μ, ‖f a‖ = ‖g a‖) : Memℒp f p μ ↔ Memℒp g p μ := ⟨fun h2f => h2f.congr_norm hg h, fun h2g => h2g.congr_norm hf <| EventuallyEq.symm h⟩ #align measure_theory.mem_ℒp_congr_norm MeasureTheory.memℒp_congr_norm theorem memℒp_top_of_bound {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : Memℒp f ∞ μ := ⟨hf, by rw [snorm_exponent_top] exact snormEssSup_lt_top_of_ae_bound hfC⟩ #align measure_theory.mem_ℒp_top_of_bound MeasureTheory.memℒp_top_of_bound theorem Memℒp.of_bound [IsFiniteMeasure μ] {f : α → E} (hf : AEStronglyMeasurable f μ) (C : ℝ) (hfC : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : Memℒp f p μ := (memℒp_const C).of_le hf (hfC.mono fun _x hx => le_trans hx (le_abs_self _)) #align measure_theory.mem_ℒp.of_bound MeasureTheory.Memℒp.of_bound @[mono] theorem snorm'_mono_measure (f : α → F) (hμν : ν ≤ μ) (hq : 0 ≤ q) : snorm' f q ν ≤ snorm' f q μ := by simp_rw [snorm'] gcongr exact lintegral_mono' hμν le_rfl #align measure_theory.snorm'_mono_measure MeasureTheory.snorm'_mono_measure @[mono] theorem snormEssSup_mono_measure (f : α → F) (hμν : ν ≪ μ) : snormEssSup f ν ≤ snormEssSup f μ := by simp_rw [snormEssSup] exact essSup_mono_measure hμν #align measure_theory.snorm_ess_sup_mono_measure MeasureTheory.snormEssSup_mono_measure @[mono] theorem snorm_mono_measure (f : α → F) (hμν : ν ≤ μ) : snorm f p ν ≤ snorm f p μ := by by_cases hp0 : p = 0 · simp [hp0] by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_mono_measure f (Measure.absolutelyContinuous_of_le hμν)] simp_rw [snorm_eq_snorm' hp0 hp_top] exact snorm'_mono_measure f hμν ENNReal.toReal_nonneg #align measure_theory.snorm_mono_measure MeasureTheory.snorm_mono_measure theorem Memℒp.mono_measure {f : α → E} (hμν : ν ≤ μ) (hf : Memℒp f p μ) : Memℒp f p ν := ⟨hf.1.mono_measure hμν, (snorm_mono_measure f hμν).trans_lt hf.2⟩ #align measure_theory.mem_ℒp.mono_measure MeasureTheory.Memℒp.mono_measure lemma snorm_restrict_le (f : α → F) (p : ℝ≥0∞) (μ : Measure α) (s : Set α) : snorm f p (μ.restrict s) ≤ snorm f p μ := snorm_mono_measure f Measure.restrict_le_self theorem Memℒp.restrict (s : Set α) {f : α → E} (hf : Memℒp f p μ) : Memℒp f p (μ.restrict s) := hf.mono_measure Measure.restrict_le_self #align measure_theory.mem_ℒp.restrict MeasureTheory.Memℒp.restrict theorem snorm'_smul_measure {p : ℝ} (hp : 0 ≤ p) {f : α → F} (c : ℝ≥0∞) : snorm' f p (c • μ) = c ^ (1 / p) * snorm' f p μ := by rw [snorm', lintegral_smul_measure, ENNReal.mul_rpow_of_nonneg, snorm'] simp [hp] #align measure_theory.snorm'_smul_measure MeasureTheory.snorm'_smul_measure theorem snormEssSup_smul_measure {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) : snormEssSup f (c • μ) = snormEssSup f μ := by simp_rw [snormEssSup] exact essSup_smul_measure hc #align measure_theory.snorm_ess_sup_smul_measure MeasureTheory.snormEssSup_smul_measure /-- Use `snorm_smul_measure_of_ne_top` instead. -/ private theorem snorm_smul_measure_of_ne_zero_of_ne_top {p : ℝ≥0∞} (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) : snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by simp_rw [snorm_eq_snorm' hp_ne_zero hp_ne_top] rw [snorm'_smul_measure ENNReal.toReal_nonneg] congr simp_rw [one_div] rw [ENNReal.toReal_inv] theorem snorm_smul_measure_of_ne_zero {p : ℝ≥0∞} {f : α → F} {c : ℝ≥0∞} (hc : c ≠ 0) : snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by by_cases hp0 : p = 0 · simp [hp0] by_cases hp_top : p = ∞ · simp [hp_top, snormEssSup_smul_measure hc] exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_top c #align measure_theory.snorm_smul_measure_of_ne_zero MeasureTheory.snorm_smul_measure_of_ne_zero theorem snorm_smul_measure_of_ne_top {p : ℝ≥0∞} (hp_ne_top : p ≠ ∞) {f : α → F} (c : ℝ≥0∞) : snorm f p (c • μ) = c ^ (1 / p).toReal • snorm f p μ := by by_cases hp0 : p = 0 · simp [hp0] · exact snorm_smul_measure_of_ne_zero_of_ne_top hp0 hp_ne_top c #align measure_theory.snorm_smul_measure_of_ne_top MeasureTheory.snorm_smul_measure_of_ne_top theorem snorm_one_smul_measure {f : α → F} (c : ℝ≥0∞) : snorm f 1 (c • μ) = c * snorm f 1 μ := by rw [@snorm_smul_measure_of_ne_top _ _ _ μ _ 1 (@ENNReal.coe_ne_top 1) f c] simp #align measure_theory.snorm_one_smul_measure MeasureTheory.snorm_one_smul_measure theorem Memℒp.of_measure_le_smul {μ' : Measure α} (c : ℝ≥0∞) (hc : c ≠ ∞) (hμ'_le : μ' ≤ c • μ) {f : α → E} (hf : Memℒp f p μ) : Memℒp f p μ' := by refine ⟨hf.1.mono_ac (Measure.absolutelyContinuous_of_le_smul hμ'_le), ?_⟩ refine (snorm_mono_measure f hμ'_le).trans_lt ?_ by_cases hc0 : c = 0 · simp [hc0] rw [snorm_smul_measure_of_ne_zero hc0, smul_eq_mul] refine ENNReal.mul_lt_top ?_ hf.2.ne simp [hc, hc0] #align measure_theory.mem_ℒp.of_measure_le_smul MeasureTheory.Memℒp.of_measure_le_smul theorem Memℒp.smul_measure {f : α → E} {c : ℝ≥0∞} (hf : Memℒp f p μ) (hc : c ≠ ∞) : Memℒp f p (c • μ) := hf.of_measure_le_smul c hc le_rfl #align measure_theory.mem_ℒp.smul_measure MeasureTheory.Memℒp.smul_measure theorem snorm_one_add_measure (f : α → F) (μ ν : Measure α) : snorm f 1 (μ + ν) = snorm f 1 μ + snorm f 1 ν := by simp_rw [snorm_one_eq_lintegral_nnnorm] rw [lintegral_add_measure _ μ ν] #align measure_theory.snorm_one_add_measure MeasureTheory.snorm_one_add_measure theorem snorm_le_add_measure_right (f : α → F) (μ ν : Measure α) {p : ℝ≥0∞} : snorm f p μ ≤ snorm f p (μ + ν) := snorm_mono_measure f <| Measure.le_add_right <| le_refl _ #align measure_theory.snorm_le_add_measure_right MeasureTheory.snorm_le_add_measure_right theorem snorm_le_add_measure_left (f : α → F) (μ ν : Measure α) {p : ℝ≥0∞} : snorm f p ν ≤ snorm f p (μ + ν) := snorm_mono_measure f <| Measure.le_add_left <| le_refl _ #align measure_theory.snorm_le_add_measure_left MeasureTheory.snorm_le_add_measure_left theorem Memℒp.left_of_add_measure {f : α → E} (h : Memℒp f p (μ + ν)) : Memℒp f p μ := h.mono_measure <| Measure.le_add_right <| le_refl _ #align measure_theory.mem_ℒp.left_of_add_measure MeasureTheory.Memℒp.left_of_add_measure theorem Memℒp.right_of_add_measure {f : α → E} (h : Memℒp f p (μ + ν)) : Memℒp f p ν := h.mono_measure <| Measure.le_add_left <| le_refl _ #align measure_theory.mem_ℒp.right_of_add_measure MeasureTheory.Memℒp.right_of_add_measure theorem Memℒp.norm {f : α → E} (h : Memℒp f p μ) : Memℒp (fun x => ‖f x‖) p μ := h.of_le h.aestronglyMeasurable.norm (eventually_of_forall fun x => by simp) #align measure_theory.mem_ℒp.norm MeasureTheory.Memℒp.norm theorem memℒp_norm_iff {f : α → E} (hf : AEStronglyMeasurable f μ) : Memℒp (fun x => ‖f x‖) p μ ↔ Memℒp f p μ := ⟨fun h => ⟨hf, by rw [← snorm_norm]; exact h.2⟩, fun h => h.norm⟩ #align measure_theory.mem_ℒp_norm_iff MeasureTheory.memℒp_norm_iff theorem snorm'_eq_zero_of_ae_zero {f : α → F} (hq0_lt : 0 < q) (hf_zero : f =ᵐ[μ] 0) : snorm' f q μ = 0 := by rw [snorm'_congr_ae hf_zero, snorm'_zero hq0_lt] #align measure_theory.snorm'_eq_zero_of_ae_zero MeasureTheory.snorm'_eq_zero_of_ae_zero theorem snorm'_eq_zero_of_ae_zero' (hq0_ne : q ≠ 0) (hμ : μ ≠ 0) {f : α → F} (hf_zero : f =ᵐ[μ] 0) : snorm' f q μ = 0 := by rw [snorm'_congr_ae hf_zero, snorm'_zero' hq0_ne hμ] #align measure_theory.snorm'_eq_zero_of_ae_zero' MeasureTheory.snorm'_eq_zero_of_ae_zero' theorem ae_eq_zero_of_snorm'_eq_zero {f : α → E} (hq0 : 0 ≤ q) (hf : AEStronglyMeasurable f μ) (h : snorm' f q μ = 0) : f =ᵐ[μ] 0 := by rw [snorm', ENNReal.rpow_eq_zero_iff] at h cases h with | inl h => rw [lintegral_eq_zero_iff' (hf.ennnorm.pow_const q)] at h refine h.left.mono fun x hx => ?_ rw [Pi.zero_apply, ENNReal.rpow_eq_zero_iff] at hx cases hx with | inl hx => cases' hx with hx _ rwa [← ENNReal.coe_zero, ENNReal.coe_inj, nnnorm_eq_zero] at hx | inr hx => exact absurd hx.left ENNReal.coe_ne_top | inr h => exfalso rw [one_div, inv_lt_zero] at h exact hq0.not_lt h.right #align measure_theory.ae_eq_zero_of_snorm'_eq_zero MeasureTheory.ae_eq_zero_of_snorm'_eq_zero theorem snorm'_eq_zero_iff (hq0_lt : 0 < q) {f : α → E} (hf : AEStronglyMeasurable f μ) : snorm' f q μ = 0 ↔ f =ᵐ[μ] 0 := ⟨ae_eq_zero_of_snorm'_eq_zero (le_of_lt hq0_lt) hf, snorm'_eq_zero_of_ae_zero hq0_lt⟩ #align measure_theory.snorm'_eq_zero_iff MeasureTheory.snorm'_eq_zero_iff theorem coe_nnnorm_ae_le_snormEssSup {_ : MeasurableSpace α} (f : α → F) (μ : Measure α) : ∀ᵐ x ∂μ, (‖f x‖₊ : ℝ≥0∞) ≤ snormEssSup f μ := ENNReal.ae_le_essSup fun x => (‖f x‖₊ : ℝ≥0∞) #align measure_theory.coe_nnnorm_ae_le_snorm_ess_sup MeasureTheory.coe_nnnorm_ae_le_snormEssSup @[simp] theorem snormEssSup_eq_zero_iff {f : α → F} : snormEssSup f μ = 0 ↔ f =ᵐ[μ] 0 := by simp [EventuallyEq, snormEssSup] #align measure_theory.snorm_ess_sup_eq_zero_iff MeasureTheory.snormEssSup_eq_zero_iff theorem snorm_eq_zero_iff {f : α → E} (hf : AEStronglyMeasurable f μ) (h0 : p ≠ 0) : snorm f p μ = 0 ↔ f =ᵐ[μ] 0 := by by_cases h_top : p = ∞ · rw [h_top, snorm_exponent_top, snormEssSup_eq_zero_iff] rw [snorm_eq_snorm' h0 h_top] exact snorm'_eq_zero_iff (ENNReal.toReal_pos h0 h_top) hf #align measure_theory.snorm_eq_zero_iff MeasureTheory.snorm_eq_zero_iff theorem ae_le_snormEssSup {f : α → F} : ∀ᵐ y ∂μ, ‖f y‖₊ ≤ snormEssSup f μ := ae_le_essSup #align measure_theory.ae_le_snorm_ess_sup MeasureTheory.ae_le_snormEssSup theorem meas_snormEssSup_lt {f : α → F} : μ { y | snormEssSup f μ < ‖f y‖₊ } = 0 := meas_essSup_lt #align measure_theory.meas_snorm_ess_sup_lt MeasureTheory.meas_snormEssSup_lt lemma snormEssSup_piecewise {s : Set α} (f g : α → E) [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : snormEssSup (Set.piecewise s f g) μ = max (snormEssSup f (μ.restrict s)) (snormEssSup g (μ.restrict sᶜ)) := by simp only [snormEssSup, ← ENNReal.essSup_piecewise hs] congr with x by_cases hx : x ∈ s <;> simp [hx] lemma snorm_top_piecewise {s : Set α} (f g : α → E) [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : snorm (Set.piecewise s f g) ∞ μ = max (snorm f ∞ (μ.restrict s)) (snorm g ∞ (μ.restrict sᶜ)) := snormEssSup_piecewise f g hs section MapMeasure variable {β : Type*} {mβ : MeasurableSpace β} {f : α → β} {g : β → E} theorem snormEssSup_map_measure (hg : AEStronglyMeasurable g (Measure.map f μ)) (hf : AEMeasurable f μ) : snormEssSup g (Measure.map f μ) = snormEssSup (g ∘ f) μ := essSup_map_measure hg.ennnorm hf #align measure_theory.snorm_ess_sup_map_measure MeasureTheory.snormEssSup_map_measure theorem snorm_map_measure (hg : AEStronglyMeasurable g (Measure.map f μ)) (hf : AEMeasurable f μ) : snorm g p (Measure.map f μ) = snorm (g ∘ f) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, snorm_exponent_zero] by_cases hp_top : p = ∞ · simp_rw [hp_top, snorm_exponent_top] exact snormEssSup_map_measure hg hf simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp_top] rw [lintegral_map' (hg.ennnorm.pow_const p.toReal) hf] rfl #align measure_theory.snorm_map_measure MeasureTheory.snorm_map_measure theorem memℒp_map_measure_iff (hg : AEStronglyMeasurable g (Measure.map f μ)) (hf : AEMeasurable f μ) : Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ := by simp [Memℒp, snorm_map_measure hg hf, hg.comp_aemeasurable hf, hg] #align measure_theory.mem_ℒp_map_measure_iff MeasureTheory.memℒp_map_measure_iff theorem Memℒp.comp_of_map (hg : Memℒp g p (Measure.map f μ)) (hf : AEMeasurable f μ) : Memℒp (g ∘ f) p μ := (memℒp_map_measure_iff hg.aestronglyMeasurable hf).1 hg theorem snorm_comp_measurePreserving {ν : MeasureTheory.Measure β} (hg : AEStronglyMeasurable g ν) (hf : MeasurePreserving f μ ν) : snorm (g ∘ f) p μ = snorm g p ν := Eq.symm <| hf.map_eq ▸ snorm_map_measure (hf.map_eq ▸ hg) hf.aemeasurable theorem AEEqFun.snorm_compMeasurePreserving {ν : MeasureTheory.Measure β} (g : β →ₘ[ν] E) (hf : MeasurePreserving f μ ν) : snorm (g.compMeasurePreserving f hf) p μ = snorm g p ν := by rw [snorm_congr_ae (g.coeFn_compMeasurePreserving _)] exact snorm_comp_measurePreserving g.aestronglyMeasurable hf theorem Memℒp.comp_measurePreserving {ν : MeasureTheory.Measure β} (hg : Memℒp g p ν) (hf : MeasurePreserving f μ ν) : Memℒp (g ∘ f) p μ := .comp_of_map (hf.map_eq.symm ▸ hg) hf.aemeasurable theorem _root_.MeasurableEmbedding.snormEssSup_map_measure {g : β → F} (hf : MeasurableEmbedding f) : snormEssSup g (Measure.map f μ) = snormEssSup (g ∘ f) μ := hf.essSup_map_measure #align measurable_embedding.snorm_ess_sup_map_measure MeasurableEmbedding.snormEssSup_map_measure theorem _root_.MeasurableEmbedding.snorm_map_measure {g : β → F} (hf : MeasurableEmbedding f) : snorm g p (Measure.map f μ) = snorm (g ∘ f) p μ := by by_cases hp_zero : p = 0 · simp only [hp_zero, snorm_exponent_zero] by_cases hp : p = ∞ · simp_rw [hp, snorm_exponent_top] exact hf.essSup_map_measure · simp_rw [snorm_eq_lintegral_rpow_nnnorm hp_zero hp] rw [hf.lintegral_map] rfl #align measurable_embedding.snorm_map_measure MeasurableEmbedding.snorm_map_measure theorem _root_.MeasurableEmbedding.memℒp_map_measure_iff {g : β → F} (hf : MeasurableEmbedding f) : Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ := by simp_rw [Memℒp, hf.aestronglyMeasurable_map_iff, hf.snorm_map_measure] #align measurable_embedding.mem_ℒp_map_measure_iff MeasurableEmbedding.memℒp_map_measure_iff theorem _root_.MeasurableEquiv.memℒp_map_measure_iff (f : α ≃ᵐ β) {g : β → F} : Memℒp g p (Measure.map f μ) ↔ Memℒp (g ∘ f) p μ := f.measurableEmbedding.memℒp_map_measure_iff #align measurable_equiv.mem_ℒp_map_measure_iff MeasurableEquiv.memℒp_map_measure_iff end MapMeasure section Monotonicity theorem snorm'_le_nnreal_smul_snorm'_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) {p : ℝ} (hp : 0 < p) : snorm' f p μ ≤ c • snorm' g p μ := by simp_rw [snorm'] rw [← ENNReal.rpow_le_rpow_iff hp, ENNReal.smul_def, smul_eq_mul, ENNReal.mul_rpow_of_nonneg _ _ hp.le] simp_rw [← ENNReal.rpow_mul, one_div, inv_mul_cancel hp.ne.symm, ENNReal.rpow_one, ENNReal.coe_rpow_of_nonneg _ hp.le, ← lintegral_const_mul' _ _ ENNReal.coe_ne_top, ← ENNReal.coe_mul] apply lintegral_mono_ae simp_rw [ENNReal.coe_le_coe, ← NNReal.mul_rpow, NNReal.rpow_le_rpow_iff hp] exact h #align measure_theory.snorm'_le_nnreal_smul_snorm'_of_ae_le_mul MeasureTheory.snorm'_le_nnreal_smul_snorm'_of_ae_le_mul theorem snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : snormEssSup f μ ≤ c • snormEssSup g μ := calc essSup (fun x => (‖f x‖₊ : ℝ≥0∞)) μ ≤ essSup (fun x => (↑(c * ‖g x‖₊) : ℝ≥0∞)) μ := essSup_mono_ae <| h.mono fun x hx => ENNReal.coe_le_coe.mpr hx _ = essSup (fun x => (c * ‖g x‖₊ : ℝ≥0∞)) μ := by simp_rw [ENNReal.coe_mul] _ = c • essSup (fun x => (‖g x‖₊ : ℝ≥0∞)) μ := ENNReal.essSup_const_mul #align measure_theory.snorm_ess_sup_le_nnreal_smul_snorm_ess_sup_of_ae_le_mul MeasureTheory.snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul theorem snorm_le_nnreal_smul_snorm_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ≥0} (h : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) (p : ℝ≥0∞) : snorm f p μ ≤ c • snorm g p μ := by by_cases h0 : p = 0 · simp [h0] by_cases h_top : p = ∞ · rw [h_top] exact snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul h simp_rw [snorm_eq_snorm' h0 h_top] exact snorm'_le_nnreal_smul_snorm'_of_ae_le_mul h (ENNReal.toReal_pos h0 h_top) #align measure_theory.snorm_le_nnreal_smul_snorm_of_ae_le_mul MeasureTheory.snorm_le_nnreal_smul_snorm_of_ae_le_mul -- TODO: add the whole family of lemmas? private theorem le_mul_iff_eq_zero_of_nonneg_of_neg_of_nonneg {α} [LinearOrderedSemiring α] {a b c : α} (ha : 0 ≤ a) (hb : b < 0) (hc : 0 ≤ c) : a ≤ b * c ↔ a = 0 ∧ c = 0 := by constructor · intro h exact ⟨(h.trans (mul_nonpos_of_nonpos_of_nonneg hb.le hc)).antisymm ha, (nonpos_of_mul_nonneg_right (ha.trans h) hb).antisymm hc⟩ · rintro ⟨rfl, rfl⟩ rw [mul_zero] /-- When `c` is negative, `‖f x‖ ≤ c * ‖g x‖` is nonsense and forces both `f` and `g` to have an `snorm` of `0`. -/ theorem snorm_eq_zero_and_zero_of_ae_le_mul_neg {f : α → F} {g : α → G} {c : ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) (hc : c < 0) (p : ℝ≥0∞) : snorm f p μ = 0 ∧ snorm g p μ = 0 := by simp_rw [le_mul_iff_eq_zero_of_nonneg_of_neg_of_nonneg (norm_nonneg _) hc (norm_nonneg _), norm_eq_zero, eventually_and] at h change f =ᵐ[μ] 0 ∧ g =ᵐ[μ] 0 at h simp [snorm_congr_ae h.1, snorm_congr_ae h.2] #align measure_theory.snorm_eq_zero_and_zero_of_ae_le_mul_neg MeasureTheory.snorm_eq_zero_and_zero_of_ae_le_mul_neg theorem snorm_le_mul_snorm_of_ae_le_mul {f : α → F} {g : α → G} {c : ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) (p : ℝ≥0∞) : snorm f p μ ≤ ENNReal.ofReal c * snorm g p μ := snorm_le_nnreal_smul_snorm_of_ae_le_mul (h.mono fun _x hx => hx.trans <| mul_le_mul_of_nonneg_right c.le_coe_toNNReal (norm_nonneg _)) _ #align measure_theory.snorm_le_mul_snorm_of_ae_le_mul MeasureTheory.snorm_le_mul_snorm_of_ae_le_mul theorem Memℒp.of_nnnorm_le_mul {f : α → E} {g : α → F} {c : ℝ≥0} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ) (hfg : ∀ᵐ x ∂μ, ‖f x‖₊ ≤ c * ‖g x‖₊) : Memℒp f p μ := ⟨hf, (snorm_le_nnreal_smul_snorm_of_ae_le_mul hfg p).trans_lt <| ENNReal.mul_lt_top ENNReal.coe_ne_top hg.snorm_ne_top⟩ #align measure_theory.mem_ℒp.of_nnnorm_le_mul MeasureTheory.Memℒp.of_nnnorm_le_mul theorem Memℒp.of_le_mul {f : α → E} {g : α → F} {c : ℝ} (hg : Memℒp g p μ) (hf : AEStronglyMeasurable f μ) (hfg : ∀ᵐ x ∂μ, ‖f x‖ ≤ c * ‖g x‖) : Memℒp f p μ := ⟨hf, (snorm_le_mul_snorm_of_ae_le_mul hfg p).trans_lt <| ENNReal.mul_lt_top ENNReal.ofReal_ne_top hg.snorm_ne_top⟩ #align measure_theory.mem_ℒp.of_le_mul MeasureTheory.Memℒp.of_le_mul end Monotonicity /-! ### Bounded actions by normed rings In this section we show inequalities on the norm. -/ section BoundedSMul variable {𝕜 : Type*} [NormedRing 𝕜] [MulActionWithZero 𝕜 E] [MulActionWithZero 𝕜 F] variable [BoundedSMul 𝕜 E] [BoundedSMul 𝕜 F] theorem snorm'_const_smul_le (c : 𝕜) (f : α → F) (hq_pos : 0 < q) : snorm' (c • f) q μ ≤ ‖c‖₊ • snorm' f q μ := snorm'_le_nnreal_smul_snorm'_of_ae_le_mul (eventually_of_forall fun _ => nnnorm_smul_le _ _) hq_pos #align measure_theory.snorm'_const_smul_le MeasureTheory.snorm'_const_smul_le theorem snormEssSup_const_smul_le (c : 𝕜) (f : α → F) : snormEssSup (c • f) μ ≤ ‖c‖₊ • snormEssSup f μ := snormEssSup_le_nnreal_smul_snormEssSup_of_ae_le_mul (eventually_of_forall fun _ => by simp [nnnorm_smul_le]) #align measure_theory.snorm_ess_sup_const_smul_le MeasureTheory.snormEssSup_const_smul_le theorem snorm_const_smul_le (c : 𝕜) (f : α → F) : snorm (c • f) p μ ≤ ‖c‖₊ • snorm f p μ := snorm_le_nnreal_smul_snorm_of_ae_le_mul (eventually_of_forall fun _ => by simp [nnnorm_smul_le]) _ #align measure_theory.snorm_const_smul_le MeasureTheory.snorm_const_smul_le theorem Memℒp.const_smul {f : α → E} (hf : Memℒp f p μ) (c : 𝕜) : Memℒp (c • f) p μ := ⟨AEStronglyMeasurable.const_smul hf.1 c, (snorm_const_smul_le c f).trans_lt (ENNReal.mul_lt_top ENNReal.coe_ne_top hf.2.ne)⟩ #align measure_theory.mem_ℒp.const_smul MeasureTheory.Memℒp.const_smul theorem Memℒp.const_mul {R} [NormedRing R] {f : α → R} (hf : Memℒp f p μ) (c : R) : Memℒp (fun x => c * f x) p μ := hf.const_smul c #align measure_theory.mem_ℒp.const_mul MeasureTheory.Memℒp.const_mul end BoundedSMul /-! ### Bounded actions by normed division rings The inequalities in the previous section are now tight. -/ section NormedSpace variable {𝕜 : Type*} [NormedDivisionRing 𝕜] [MulActionWithZero 𝕜 E] [Module 𝕜 F] variable [BoundedSMul 𝕜 E] [BoundedSMul 𝕜 F] theorem snorm'_const_smul {f : α → F} (c : 𝕜) (hq_pos : 0 < q) : snorm' (c • f) q μ = ‖c‖₊ • snorm' f q μ := by obtain rfl | hc := eq_or_ne c 0 · simp [snorm', hq_pos] refine le_antisymm (snorm'_const_smul_le _ _ hq_pos) ?_ have : snorm' _ q μ ≤ _ := snorm'_const_smul_le c⁻¹ (c • f) hq_pos rwa [inv_smul_smul₀ hc, nnnorm_inv, le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this #align measure_theory.snorm'_const_smul MeasureTheory.snorm'_const_smul theorem snormEssSup_const_smul (c : 𝕜) (f : α → F) : snormEssSup (c • f) μ = (‖c‖₊ : ℝ≥0∞) * snormEssSup f μ := by simp_rw [snormEssSup, Pi.smul_apply, nnnorm_smul, ENNReal.coe_mul, ENNReal.essSup_const_mul] #align measure_theory.snorm_ess_sup_const_smul MeasureTheory.snormEssSup_const_smul theorem snorm_const_smul (c : 𝕜) (f : α → F) : snorm (c • f) p μ = (‖c‖₊ : ℝ≥0∞) * snorm f p μ := by obtain rfl | hc := eq_or_ne c 0 · simp refine le_antisymm (snorm_const_smul_le _ _) ?_ have : snorm _ p μ ≤ _ := snorm_const_smul_le c⁻¹ (c • f) rwa [inv_smul_smul₀ hc, nnnorm_inv, le_inv_smul_iff_of_pos (nnnorm_pos.2 hc)] at this #align measure_theory.snorm_const_smul MeasureTheory.snorm_const_smul end NormedSpace theorem snorm_indicator_ge_of_bdd_below (hp : p ≠ 0) (hp' : p ≠ ∞) {f : α → F} (C : ℝ≥0) {s : Set α} (hs : MeasurableSet s) (hf : ∀ᵐ x ∂μ, x ∈ s → C ≤ ‖s.indicator f x‖₊) : C • μ s ^ (1 / p.toReal) ≤ snorm (s.indicator f) p μ := by rw [ENNReal.smul_def, smul_eq_mul, snorm_eq_lintegral_rpow_nnnorm hp hp', ENNReal.le_rpow_one_div_iff (ENNReal.toReal_pos hp hp'), ENNReal.mul_rpow_of_nonneg _ _ ENNReal.toReal_nonneg, ← ENNReal.rpow_mul, one_div_mul_cancel (ENNReal.toReal_pos hp hp').ne.symm, ENNReal.rpow_one, ← set_lintegral_const, ← lintegral_indicator _ hs] refine lintegral_mono_ae ?_ filter_upwards [hf] with x hx rw [nnnorm_indicator_eq_indicator_nnnorm] by_cases hxs : x ∈ s · simp only [Set.indicator_of_mem hxs] at hx ⊢ gcongr exact hx hxs · simp [Set.indicator_of_not_mem hxs] #align measure_theory.snorm_indicator_ge_of_bdd_below MeasureTheory.snorm_indicator_ge_of_bdd_below section RCLike variable {𝕜 : Type*} [RCLike 𝕜] {f : α → 𝕜}
Mathlib/MeasureTheory/Function/LpSeminorm/Basic.lean
1,038
1,044
theorem Memℒp.re (hf : Memℒp f p μ) : Memℒp (fun x => RCLike.re (f x)) p μ := by
have : ∀ x, ‖RCLike.re (f x)‖ ≤ 1 * ‖f x‖ := by intro x rw [one_mul] exact RCLike.norm_re_le_norm (f x) refine hf.of_le_mul ?_ (eventually_of_forall this) exact RCLike.continuous_re.comp_aestronglyMeasurable hf.1
/- 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, Sébastien Gouëzel, Rémy Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.NNReal #align_import analysis.special_functions.pow.asymptotics from "leanprover-community/mathlib"@"0b9eaaa7686280fad8cce467f5c3c57ee6ce77f8" /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x → 0` (those which are not just continuity statements) are also located here. -/ set_option linter.uppercaseLean3 false noncomputable section open scoped Classical open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/
Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
36
46
theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by
rw [tendsto_atTop_atTop] intro b use max b 0 ^ (1 / y) intro x hx exact le_of_max_le_left (by convert rpow_le_rpow (rpow_nonneg (le_max_right b 0) (1 / y)) hx (le_of_lt hy) using 1 rw [← rpow_mul (le_max_right b 0), (eq_div_iff (ne_of_gt hy)).mp rfl, Real.rpow_one])
/- 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, Patrick Massot -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Compactness.Compact import Mathlib.Topology.NhdsSet import Mathlib.Algebra.Group.Defs #align_import topology.uniform_space.basic from "leanprover-community/mathlib"@"195fcd60ff2bfe392543bceb0ec2adcdb472db4c" /-! # Uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * uniform continuity (in this file) * completeness (in `Cauchy.lean`) * extension of uniform continuous functions to complete spaces (in `UniformEmbedding.lean`) * totally bounded sets (in `Cauchy.lean`) * totally bounded complete sets are compact (in `Cauchy.lean`) A uniform structure on a type `X` is a filter `𝓤 X` on `X × X` satisfying some conditions which makes it reasonable to say that `∀ᶠ (p : X × X) in 𝓤 X, ...` means "for all p.1 and p.2 in X close enough, ...". Elements of this filter are called entourages of `X`. The two main examples are: * If `X` is a metric space, `V ∈ 𝓤 X ↔ ∃ ε > 0, { p | dist p.1 p.2 < ε } ⊆ V` * If `G` is an additive topological group, `V ∈ 𝓤 G ↔ ∃ U ∈ 𝓝 (0 : G), {p | p.2 - p.1 ∈ U} ⊆ V` Those examples are generalizations in two different directions of the elementary example where `X = ℝ` and `V ∈ 𝓤 ℝ ↔ ∃ ε > 0, { p | |p.2 - p.1| < ε } ⊆ V` which features both the topological group structure on `ℝ` and its metric space structure. Each uniform structure on `X` induces a topology on `X` characterized by > `nhds_eq_comap_uniformity : ∀ {x : X}, 𝓝 x = comap (Prod.mk x) (𝓤 X)` where `Prod.mk x : X → X × X := (fun y ↦ (x, y))` is the partial evaluation of the product constructor. The dictionary with metric spaces includes: * an upper bound for `dist x y` translates into `(x, y) ∈ V` for some `V ∈ 𝓤 X` * a ball `ball x r` roughly corresponds to `UniformSpace.ball x V := {y | (x, y) ∈ V}` for some `V ∈ 𝓤 X`, but the later is more general (it includes in particular both open and closed balls for suitable `V`). In particular we have: `isOpen_iff_ball_subset {s : Set X} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 X, ball x V ⊆ s` The triangle inequality is abstracted to a statement involving the composition of relations in `X`. First note that the triangle inequality in a metric space is equivalent to `∀ (x y z : X) (r r' : ℝ), dist x y ≤ r → dist y z ≤ r' → dist x z ≤ r + r'`. Then, for any `V` and `W` with type `Set (X × X)`, the composition `V ○ W : Set (X × X)` is defined as `{ p : X × X | ∃ z, (p.1, z) ∈ V ∧ (z, p.2) ∈ W }`. In the metric space case, if `V = { p | dist p.1 p.2 ≤ r }` and `W = { p | dist p.1 p.2 ≤ r' }` then the triangle inequality, as reformulated above, says `V ○ W` is contained in `{p | dist p.1 p.2 ≤ r + r'}` which is the entourage associated to the radius `r + r'`. In general we have `mem_ball_comp (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W)`. Note that this discussion does not depend on any axiom imposed on the uniformity filter, it is simply captured by the definition of composition. The uniform space axioms ask the filter `𝓤 X` to satisfy the following: * every `V ∈ 𝓤 X` contains the diagonal `idRel = { p | p.1 = p.2 }`. This abstracts the fact that `dist x x ≤ r` for every non-negative radius `r` in the metric space case and also that `x - x` belongs to every neighborhood of zero in the topological group case. * `V ∈ 𝓤 X → Prod.swap '' V ∈ 𝓤 X`. This is tightly related the fact that `dist x y = dist y x` in a metric space, and to continuity of negation in the topological group case. * `∀ V ∈ 𝓤 X, ∃ W ∈ 𝓤 X, W ○ W ⊆ V`. In the metric space case, it corresponds to cutting the radius of a ball in half and applying the triangle inequality. In the topological group case, it comes from continuity of addition at `(0, 0)`. These three axioms are stated more abstractly in the definition below, in terms of operations on filters, without directly manipulating entourages. ## Main definitions * `UniformSpace X` is a uniform space structure on a type `X` * `UniformContinuous f` is a predicate saying a function `f : α → β` between uniform spaces is uniformly continuous : `∀ r ∈ 𝓤 β, ∀ᶠ (x : α × α) in 𝓤 α, (f x.1, f x.2) ∈ r` In this file we also define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## Implementation notes There is already a theory of relations in `Data/Rel.lean` where the main definition is `def Rel (α β : Type*) := α → β → Prop`. The relations used in the current file involve only one type, but this is not the reason why we don't reuse `Data/Rel.lean`. We use `Set (α × α)` instead of `Rel α α` because we really need sets to use the filter library, and elements of filters on `α × α` have type `Set (α × α)`. The structure `UniformSpace X` bundles a uniform structure on `X`, a topology on `X` and an assumption saying those are compatible. This may not seem mathematically reasonable at first, but is in fact an instance of the forgetful inheritance pattern. See Note [forgetful inheritance] below. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def idRel {α : Type*} := { p : α × α | p.1 = p.2 } #align id_rel idRel @[simp] theorem mem_idRel {a b : α} : (a, b) ∈ @idRel α ↔ a = b := Iff.rfl #align mem_id_rel mem_idRel @[simp] theorem idRel_subset {s : Set (α × α)} : idRel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def] #align id_rel_subset idRel_subset /-- The composition of relations -/ def compRel (r₁ r₂ : Set (α × α)) := { p : α × α | ∃ z : α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂ } #align comp_rel compRel @[inherit_doc] scoped[Uniformity] infixl:62 " ○ " => compRel open Uniformity @[simp] theorem mem_compRel {α : Type u} {r₁ r₂ : Set (α × α)} {x y : α} : (x, y) ∈ r₁ ○ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := Iff.rfl #align mem_comp_rel mem_compRel @[simp] theorem swap_idRel : Prod.swap '' idRel = @idRel α := Set.ext fun ⟨a, b⟩ => by simpa [image_swap_eq_preimage_swap] using eq_comm #align swap_id_rel swap_idRel theorem Monotone.compRel [Preorder β] {f g : β → Set (α × α)} (hf : Monotone f) (hg : Monotone g) : Monotone fun x => f x ○ g x := fun _ _ h _ ⟨z, h₁, h₂⟩ => ⟨z, hf h h₁, hg h h₂⟩ #align monotone.comp_rel Monotone.compRel @[mono] theorem compRel_mono {f g h k : Set (α × α)} (h₁ : f ⊆ h) (h₂ : g ⊆ k) : f ○ g ⊆ h ○ k := fun _ ⟨z, h, h'⟩ => ⟨z, h₁ h, h₂ h'⟩ #align comp_rel_mono compRel_mono theorem prod_mk_mem_compRel {a b c : α} {s t : Set (α × α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) : (a, b) ∈ s ○ t := ⟨c, h₁, h₂⟩ #align prod_mk_mem_comp_rel prod_mk_mem_compRel @[simp] theorem id_compRel {r : Set (α × α)} : idRel ○ r = r := Set.ext fun ⟨a, b⟩ => by simp #align id_comp_rel id_compRel theorem compRel_assoc {r s t : Set (α × α)} : r ○ s ○ t = r ○ (s ○ t) := by ext ⟨a, b⟩; simp only [mem_compRel]; tauto #align comp_rel_assoc compRel_assoc theorem left_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ t) : s ⊆ s ○ t := fun ⟨_x, y⟩ xy_in => ⟨y, xy_in, h <| rfl⟩ #align left_subset_comp_rel left_subset_compRel theorem right_subset_compRel {s t : Set (α × α)} (h : idRel ⊆ s) : t ⊆ s ○ t := fun ⟨x, _y⟩ xy_in => ⟨x, h <| rfl, xy_in⟩ #align right_subset_comp_rel right_subset_compRel theorem subset_comp_self {s : Set (α × α)} (h : idRel ⊆ s) : s ⊆ s ○ s := left_subset_compRel h #align subset_comp_self subset_comp_self theorem subset_iterate_compRel {s t : Set (α × α)} (h : idRel ⊆ s) (n : ℕ) : t ⊆ (s ○ ·)^[n] t := by induction' n with n ihn generalizing t exacts [Subset.rfl, (right_subset_compRel h).trans ihn] #align subset_iterate_comp_rel subset_iterate_compRel /-- The relation is invariant under swapping factors. -/ def SymmetricRel (V : Set (α × α)) : Prop := Prod.swap ⁻¹' V = V #align symmetric_rel SymmetricRel /-- The maximal symmetric relation contained in a given relation. -/ def symmetrizeRel (V : Set (α × α)) : Set (α × α) := V ∩ Prod.swap ⁻¹' V #align symmetrize_rel symmetrizeRel theorem symmetric_symmetrizeRel (V : Set (α × α)) : SymmetricRel (symmetrizeRel V) := by simp [SymmetricRel, symmetrizeRel, preimage_inter, inter_comm, ← preimage_comp] #align symmetric_symmetrize_rel symmetric_symmetrizeRel theorem symmetrizeRel_subset_self (V : Set (α × α)) : symmetrizeRel V ⊆ V := sep_subset _ _ #align symmetrize_rel_subset_self symmetrizeRel_subset_self @[mono] theorem symmetrize_mono {V W : Set (α × α)} (h : V ⊆ W) : symmetrizeRel V ⊆ symmetrizeRel W := inter_subset_inter h <| preimage_mono h #align symmetrize_mono symmetrize_mono theorem SymmetricRel.mk_mem_comm {V : Set (α × α)} (hV : SymmetricRel V) {x y : α} : (x, y) ∈ V ↔ (y, x) ∈ V := Set.ext_iff.1 hV (y, x) #align symmetric_rel.mk_mem_comm SymmetricRel.mk_mem_comm theorem SymmetricRel.eq {U : Set (α × α)} (hU : SymmetricRel U) : Prod.swap ⁻¹' U = U := hU #align symmetric_rel.eq SymmetricRel.eq theorem SymmetricRel.inter {U V : Set (α × α)} (hU : SymmetricRel U) (hV : SymmetricRel V) : SymmetricRel (U ∩ V) := by rw [SymmetricRel, preimage_inter, hU.eq, hV.eq] #align symmetric_rel.inter SymmetricRel.inter /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure UniformSpace.Core (α : Type u) where /-- The uniformity filter. Once `UniformSpace` is defined, `𝓤 α` (`_root_.uniformity`) becomes the normal form. -/ uniformity : Filter (α × α) /-- Every set in the uniformity filter includes the diagonal. -/ refl : 𝓟 idRel ≤ uniformity /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity #align uniform_space.core UniformSpace.Core protected theorem UniformSpace.Core.comp_mem_uniformity_sets {c : Core α} {s : Set (α × α)} (hs : s ∈ c.uniformity) : ∃ t ∈ c.uniformity, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| c.comp hs /-- An alternative constructor for `UniformSpace.Core`. This version unfolds various `Filter`-related definitions. -/ def UniformSpace.Core.mk' {α : Type u} (U : Filter (α × α)) (refl : ∀ r ∈ U, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ U, Prod.swap ⁻¹' r ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, t ○ t ⊆ r) : UniformSpace.Core α := ⟨U, fun _r ru => idRel_subset.2 (refl _ ru), symm, fun _r ru => let ⟨_s, hs, hsr⟩ := comp _ ru mem_of_superset (mem_lift' hs) hsr⟩ #align uniform_space.core.mk' UniformSpace.Core.mk' /-- Defining a `UniformSpace.Core` from a filter basis satisfying some uniformity-like axioms. -/ def UniformSpace.Core.mkOfBasis {α : Type u} (B : FilterBasis (α × α)) (refl : ∀ r ∈ B, ∀ (x), (x, x) ∈ r) (symm : ∀ r ∈ B, ∃ t ∈ B, t ⊆ Prod.swap ⁻¹' r) (comp : ∀ r ∈ B, ∃ t ∈ B, t ○ t ⊆ r) : UniformSpace.Core α where uniformity := B.filter refl := B.hasBasis.ge_iff.mpr fun _r ru => idRel_subset.2 <| refl _ ru symm := (B.hasBasis.tendsto_iff B.hasBasis).mpr symm comp := (HasBasis.le_basis_iff (B.hasBasis.lift' (monotone_id.compRel monotone_id)) B.hasBasis).2 comp #align uniform_space.core.mk_of_basis UniformSpace.Core.mkOfBasis /-- A uniform space generates a topological space -/ def UniformSpace.Core.toTopologicalSpace {α : Type u} (u : UniformSpace.Core α) : TopologicalSpace α := .mkOfNhds fun x ↦ .comap (Prod.mk x) u.uniformity #align uniform_space.core.to_topological_space UniformSpace.Core.toTopologicalSpace theorem UniformSpace.Core.ext : ∀ {u₁ u₂ : UniformSpace.Core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align uniform_space.core_eq UniformSpace.Core.ext theorem UniformSpace.Core.nhds_toTopologicalSpace {α : Type u} (u : Core α) (x : α) : @nhds α u.toTopologicalSpace x = comap (Prod.mk x) u.uniformity := by apply TopologicalSpace.nhds_mkOfNhds_of_hasBasis (fun _ ↦ (basis_sets _).comap _) · exact fun a U hU ↦ u.refl hU rfl · intro a U hU rcases u.comp_mem_uniformity_sets hU with ⟨V, hV, hVU⟩ filter_upwards [preimage_mem_comap hV] with b hb filter_upwards [preimage_mem_comap hV] with c hc exact hVU ⟨b, hb, hc⟩ -- the topological structure is embedded in the uniform structure -- to avoid instance diamond issues. See Note [forgetful inheritance]. /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class UniformSpace (α : Type u) extends TopologicalSpace α where /-- The uniformity filter. -/ protected uniformity : Filter (α × α) /-- If `s ∈ uniformity`, then `Prod.swap ⁻¹' s ∈ uniformity`. -/ protected symm : Tendsto Prod.swap uniformity uniformity /-- For every set `u ∈ uniformity`, there exists `v ∈ uniformity` such that `v ○ v ⊆ u`. -/ protected comp : (uniformity.lift' fun s => s ○ s) ≤ uniformity /-- The uniformity agrees with the topology: the neighborhoods filter of each point `x` is equal to `Filter.comap (Prod.mk x) (𝓤 α)`. -/ protected nhds_eq_comap_uniformity (x : α) : 𝓝 x = comap (Prod.mk x) uniformity #align uniform_space UniformSpace #noalign uniform_space.mk' -- Can't be a `match_pattern`, so not useful anymore /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity (α : Type u) [UniformSpace α] : Filter (α × α) := @UniformSpace.uniformity α _ #align uniformity uniformity /-- Notation for the uniformity filter with respect to a non-standard `UniformSpace` instance. -/ scoped[Uniformity] notation "𝓤[" u "]" => @uniformity _ u @[inherit_doc] -- Porting note (#11215): TODO: should we drop the `uniformity` def? scoped[Uniformity] notation "𝓤" => uniformity /-- Construct a `UniformSpace` from a `u : UniformSpace.Core` and a `TopologicalSpace` structure that is equal to `u.toTopologicalSpace`. -/ abbrev UniformSpace.ofCoreEq {α : Type u} (u : UniformSpace.Core α) (t : TopologicalSpace α) (h : t = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := t nhds_eq_comap_uniformity x := by rw [h, u.nhds_toTopologicalSpace] #align uniform_space.of_core_eq UniformSpace.ofCoreEq /-- Construct a `UniformSpace` from a `UniformSpace.Core`. -/ abbrev UniformSpace.ofCore {α : Type u} (u : UniformSpace.Core α) : UniformSpace α := .ofCoreEq u _ rfl #align uniform_space.of_core UniformSpace.ofCore /-- Construct a `UniformSpace.Core` from a `UniformSpace`. -/ abbrev UniformSpace.toCore (u : UniformSpace α) : UniformSpace.Core α where __ := u refl := by rintro U hU ⟨x, y⟩ (rfl : x = y) have : Prod.mk x ⁻¹' U ∈ 𝓝 x := by rw [UniformSpace.nhds_eq_comap_uniformity] exact preimage_mem_comap hU convert mem_of_mem_nhds this theorem UniformSpace.toCore_toTopologicalSpace (u : UniformSpace α) : u.toCore.toTopologicalSpace = u.toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by rw [u.nhds_eq_comap_uniformity, u.toCore.nhds_toTopologicalSpace] #align uniform_space.to_core_to_topological_space UniformSpace.toCore_toTopologicalSpace /-- Build a `UniformSpace` from a `UniformSpace.Core` and a compatible topology. Use `UniformSpace.mk` instead to avoid proving the unnecessary assumption `UniformSpace.Core.refl`. The main constructor used to use a different compatibility assumption. This definition was created as a step towards porting to a new definition. Now the main definition is ported, so this constructor will be removed in a few months. -/ @[deprecated UniformSpace.mk (since := "2024-03-20")] def UniformSpace.ofNhdsEqComap (u : UniformSpace.Core α) (_t : TopologicalSpace α) (h : ∀ x, 𝓝 x = u.uniformity.comap (Prod.mk x)) : UniformSpace α where __ := u nhds_eq_comap_uniformity := h @[ext] protected theorem UniformSpace.ext {u₁ u₂ : UniformSpace α} (h : 𝓤[u₁] = 𝓤[u₂]) : u₁ = u₂ := by have : u₁.toTopologicalSpace = u₂.toTopologicalSpace := TopologicalSpace.ext_nhds fun x ↦ by rw [u₁.nhds_eq_comap_uniformity, u₂.nhds_eq_comap_uniformity] exact congr_arg (comap _) h cases u₁; cases u₂; congr #align uniform_space_eq UniformSpace.ext protected theorem UniformSpace.ext_iff {u₁ u₂ : UniformSpace α} : u₁ = u₂ ↔ ∀ s, s ∈ 𝓤[u₁] ↔ s ∈ 𝓤[u₂] := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem UniformSpace.ofCoreEq_toCore (u : UniformSpace α) (t : TopologicalSpace α) (h : t = u.toCore.toTopologicalSpace) : .ofCoreEq u.toCore t h = u := UniformSpace.ext rfl #align uniform_space.of_core_eq_to_core UniformSpace.ofCoreEq_toCore /-- Replace topology in a `UniformSpace` instance with a propositionally (but possibly not definitionally) equal one. -/ abbrev UniformSpace.replaceTopology {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : UniformSpace α where __ := u toTopologicalSpace := i nhds_eq_comap_uniformity x := by rw [h, u.nhds_eq_comap_uniformity] #align uniform_space.replace_topology UniformSpace.replaceTopology theorem UniformSpace.replaceTopology_eq {α : Type*} [i : TopologicalSpace α] (u : UniformSpace α) (h : i = u.toTopologicalSpace) : u.replaceTopology h = u := UniformSpace.ext rfl #align uniform_space.replace_topology_eq UniformSpace.replaceTopology_eq -- Porting note: rfc: use `UniformSpace.Core.mkOfBasis`? This will change defeq here and there /-- Define a `UniformSpace` using a "distance" function. The function can be, e.g., the distance in a (usual or extended) metric space or an absolute value on a ring. -/ def UniformSpace.ofFun {α : Type u} {β : Type v} [OrderedAddCommMonoid β] (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) : UniformSpace α := .ofCore { uniformity := ⨅ r > 0, 𝓟 { x | d x.1 x.2 < r } refl := le_iInf₂ fun r hr => principal_mono.2 <| idRel_subset.2 fun x => by simpa [refl] symm := tendsto_iInf_iInf fun r => tendsto_iInf_iInf fun _ => tendsto_principal_principal.2 fun x hx => by rwa [mem_setOf, symm] comp := le_iInf₂ fun r hr => let ⟨δ, h0, hδr⟩ := half r hr; le_principal_iff.2 <| mem_of_superset (mem_lift' <| mem_iInf_of_mem δ <| mem_iInf_of_mem h0 <| mem_principal_self _) fun (x, z) ⟨y, h₁, h₂⟩ => (triangle _ _ _).trans_lt (hδr _ h₁ _ h₂) } #align uniform_space.of_fun UniformSpace.ofFun theorem UniformSpace.hasBasis_ofFun {α : Type u} {β : Type v} [LinearOrderedAddCommMonoid β] (h₀ : ∃ x : β, 0 < x) (d : α → α → β) (refl : ∀ x, d x x = 0) (symm : ∀ x y, d x y = d y x) (triangle : ∀ x y z, d x z ≤ d x y + d y z) (half : ∀ ε > (0 : β), ∃ δ > (0 : β), ∀ x < δ, ∀ y < δ, x + y < ε) : 𝓤[.ofFun d refl symm triangle half].HasBasis ((0 : β) < ·) (fun ε => { x | d x.1 x.2 < ε }) := hasBasis_biInf_principal' (fun ε₁ h₁ ε₂ h₂ => ⟨min ε₁ ε₂, lt_min h₁ h₂, fun _x hx => lt_of_lt_of_le hx (min_le_left _ _), fun _x hx => lt_of_lt_of_le hx (min_le_right _ _)⟩) h₀ #align uniform_space.has_basis_of_fun UniformSpace.hasBasis_ofFun section UniformSpace variable [UniformSpace α] theorem nhds_eq_comap_uniformity {x : α} : 𝓝 x = (𝓤 α).comap (Prod.mk x) := UniformSpace.nhds_eq_comap_uniformity x #align nhds_eq_comap_uniformity nhds_eq_comap_uniformity theorem isOpen_uniformity {s : Set α} : IsOpen s ↔ ∀ x ∈ s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap_prod_mk] #align is_open_uniformity isOpen_uniformity theorem refl_le_uniformity : 𝓟 idRel ≤ 𝓤 α := (@UniformSpace.toCore α _).refl #align refl_le_uniformity refl_le_uniformity instance uniformity.neBot [Nonempty α] : NeBot (𝓤 α) := diagonal_nonempty.principal_neBot.mono refl_le_uniformity #align uniformity.ne_bot uniformity.neBot theorem refl_mem_uniformity {x : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s := refl_le_uniformity h rfl #align refl_mem_uniformity refl_mem_uniformity theorem mem_uniformity_of_eq {x y : α} {s : Set (α × α)} (h : s ∈ 𝓤 α) (hx : x = y) : (x, y) ∈ s := refl_le_uniformity h hx #align mem_uniformity_of_eq mem_uniformity_of_eq theorem symm_le_uniformity : map (@Prod.swap α α) (𝓤 _) ≤ 𝓤 _ := UniformSpace.symm #align symm_le_uniformity symm_le_uniformity theorem comp_le_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) ≤ 𝓤 α := UniformSpace.comp #align comp_le_uniformity comp_le_uniformity theorem lift'_comp_uniformity : ((𝓤 α).lift' fun s : Set (α × α) => s ○ s) = 𝓤 α := comp_le_uniformity.antisymm <| le_lift'.2 fun _s hs ↦ mem_of_superset hs <| subset_comp_self <| idRel_subset.2 fun _ ↦ refl_mem_uniformity hs theorem tendsto_swap_uniformity : Tendsto (@Prod.swap α α) (𝓤 α) (𝓤 α) := symm_le_uniformity #align tendsto_swap_uniformity tendsto_swap_uniformity theorem comp_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ t ⊆ s := (mem_lift'_sets <| monotone_id.compRel monotone_id).mp <| comp_le_uniformity hs #align comp_mem_uniformity_sets comp_mem_uniformity_sets /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction' n with n ihn generalizing s · simpa rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ #align eventually_uniformity_iterate_comp_subset eventually_uniformity_iterate_comp_subset /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 #align eventually_uniformity_comp_subset eventually_uniformity_comp_subset /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is transitive. -/ theorem Filter.Tendsto.uniformity_trans {l : Filter β} {f₁ f₂ f₃ : β → α} (h₁₂ : Tendsto (fun x => (f₁ x, f₂ x)) l (𝓤 α)) (h₂₃ : Tendsto (fun x => (f₂ x, f₃ x)) l (𝓤 α)) : Tendsto (fun x => (f₁ x, f₃ x)) l (𝓤 α) := by refine le_trans (le_lift'.2 fun s hs => mem_map.2 ?_) comp_le_uniformity filter_upwards [mem_map.1 (h₁₂ hs), mem_map.1 (h₂₃ hs)] with x hx₁₂ hx₂₃ using ⟨_, hx₁₂, hx₂₃⟩ #align filter.tendsto.uniformity_trans Filter.Tendsto.uniformity_trans /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is symmetric. -/ theorem Filter.Tendsto.uniformity_symm {l : Filter β} {f : β → α × α} (h : Tendsto f l (𝓤 α)) : Tendsto (fun x => ((f x).2, (f x).1)) l (𝓤 α) := tendsto_swap_uniformity.comp h #align filter.tendsto.uniformity_symm Filter.Tendsto.uniformity_symm /-- Relation `fun f g ↦ Tendsto (fun x ↦ (f x, g x)) l (𝓤 α)` is reflexive. -/ theorem tendsto_diag_uniformity (f : β → α) (l : Filter β) : Tendsto (fun x => (f x, f x)) l (𝓤 α) := fun _s hs => mem_map.2 <| univ_mem' fun _ => refl_mem_uniformity hs #align tendsto_diag_uniformity tendsto_diag_uniformity theorem tendsto_const_uniformity {a : α} {f : Filter β} : Tendsto (fun _ => (a, a)) f (𝓤 α) := tendsto_diag_uniformity (fun _ => a) f #align tendsto_const_uniformity tendsto_const_uniformity theorem symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have : preimage Prod.swap s ∈ 𝓤 α := symm_le_uniformity hs ⟨s ∩ preimage Prod.swap s, inter_mem hs this, fun _ _ ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩, inter_subset_left⟩ #align symm_of_uniformity symm_of_uniformity theorem comp_symm_of_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀ {a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ t ○ t ⊆ s := let ⟨_t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ ⟨t', ht', ht'₁ _ _, Subset.trans (monotone_id.compRel monotone_id ht'₂) ht₂⟩ #align comp_symm_of_uniformity comp_symm_of_uniformity theorem uniformity_le_symm : 𝓤 α ≤ @Prod.swap α α <$> 𝓤 α := by rw [map_swap_eq_comap_swap]; exact tendsto_swap_uniformity.le_comap #align uniformity_le_symm uniformity_le_symm theorem uniformity_eq_symm : 𝓤 α = @Prod.swap α α <$> 𝓤 α := le_antisymm uniformity_le_symm symm_le_uniformity #align uniformity_eq_symm uniformity_eq_symm @[simp] theorem comap_swap_uniformity : comap (@Prod.swap α α) (𝓤 α) = 𝓤 α := (congr_arg _ uniformity_eq_symm).trans <| comap_map Prod.swap_injective #align comap_swap_uniformity comap_swap_uniformity theorem symmetrize_mem_uniformity {V : Set (α × α)} (h : V ∈ 𝓤 α) : symmetrizeRel V ∈ 𝓤 α := by apply (𝓤 α).inter_sets h rw [← image_swap_eq_preimage_swap, uniformity_eq_symm] exact image_mem_map h #align symmetrize_mem_uniformity symmetrize_mem_uniformity /-- Symmetric entourages form a basis of `𝓤 α` -/ theorem UniformSpace.hasBasis_symmetric : (𝓤 α).HasBasis (fun s : Set (α × α) => s ∈ 𝓤 α ∧ SymmetricRel s) id := hasBasis_self.2 fun t t_in => ⟨symmetrizeRel t, symmetrize_mem_uniformity t_in, symmetric_symmetrizeRel t, symmetrizeRel_subset_self t⟩ #align uniform_space.has_basis_symmetric UniformSpace.hasBasis_symmetric theorem uniformity_lift_le_swap {g : Set (α × α) → Filter β} {f : Filter β} (hg : Monotone g) (h : ((𝓤 α).lift fun s => g (preimage Prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f := calc (𝓤 α).lift g ≤ (Filter.map (@Prod.swap α α) <| 𝓤 α).lift g := lift_mono uniformity_le_symm le_rfl _ ≤ _ := by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h #align uniformity_lift_le_swap uniformity_lift_le_swap theorem uniformity_lift_le_comp {f : Set (α × α) → Filter β} (h : Monotone f) : ((𝓤 α).lift fun s => f (s ○ s)) ≤ (𝓤 α).lift f := calc ((𝓤 α).lift fun s => f (s ○ s)) = ((𝓤 α).lift' fun s : Set (α × α) => s ○ s).lift f := by rw [lift_lift'_assoc] · exact monotone_id.compRel monotone_id · exact h _ ≤ (𝓤 α).lift f := lift_mono comp_le_uniformity le_rfl #align uniformity_lift_le_comp uniformity_lift_le_comp -- Porting note (#10756): new lemma theorem comp3_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, t ○ (t ○ t) ⊆ s := let ⟨_t', ht', ht's⟩ := comp_mem_uniformity_sets hs let ⟨t, ht, htt'⟩ := comp_mem_uniformity_sets ht' ⟨t, ht, (compRel_mono ((subset_comp_self (refl_le_uniformity ht)).trans htt') htt').trans ht's⟩ /-- See also `comp3_mem_uniformity`. -/ theorem comp_le_uniformity3 : ((𝓤 α).lift' fun s : Set (α × α) => s ○ (s ○ s)) ≤ 𝓤 α := fun _ h => let ⟨_t, htU, ht⟩ := comp3_mem_uniformity h mem_of_superset (mem_lift' htU) ht #align comp_le_uniformity3 comp_le_uniformity3 /-- See also `comp_open_symm_mem_uniformity_sets`. -/ theorem comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨w, w_in, w_sub⟩ : ∃ w ∈ 𝓤 α, w ○ w ⊆ s := comp_mem_uniformity_sets hs use symmetrizeRel w, symmetrize_mem_uniformity w_in, symmetric_symmetrizeRel w have : symmetrizeRel w ⊆ w := symmetrizeRel_subset_self w calc symmetrizeRel w ○ symmetrizeRel w _ ⊆ w ○ w := by mono _ ⊆ s := w_sub #align comp_symm_mem_uniformity_sets comp_symm_mem_uniformity_sets theorem subset_comp_self_of_mem_uniformity {s : Set (α × α)} (h : s ∈ 𝓤 α) : s ⊆ s ○ s := subset_comp_self (refl_le_uniformity h) #align subset_comp_self_of_mem_uniformity subset_comp_self_of_mem_uniformity theorem comp_comp_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, SymmetricRel t ∧ t ○ t ○ t ⊆ s := by rcases comp_symm_mem_uniformity_sets hs with ⟨w, w_in, _, w_sub⟩ rcases comp_symm_mem_uniformity_sets w_in with ⟨t, t_in, t_symm, t_sub⟩ use t, t_in, t_symm have : t ⊆ t ○ t := subset_comp_self_of_mem_uniformity t_in -- Porting note: Needed the following `have`s to make `mono` work have ht := Subset.refl t have hw := Subset.refl w calc t ○ t ○ t ⊆ w ○ t := by mono _ ⊆ w ○ (t ○ t) := by mono _ ⊆ w ○ w := by mono _ ⊆ s := w_sub #align comp_comp_symm_mem_uniformity_sets comp_comp_symm_mem_uniformity_sets /-! ### Balls in uniform spaces -/ /-- The ball around `(x : β)` with respect to `(V : Set (β × β))`. Intended to be used for `V ∈ 𝓤 β`, but this is not needed for the definition. Recovers the notions of metric space ball when `V = {p | dist p.1 p.2 < r }`. -/ def UniformSpace.ball (x : β) (V : Set (β × β)) : Set β := Prod.mk x ⁻¹' V #align uniform_space.ball UniformSpace.ball open UniformSpace (ball) theorem UniformSpace.mem_ball_self (x : α) {V : Set (α × α)} (hV : V ∈ 𝓤 α) : x ∈ ball x V := refl_mem_uniformity hV #align uniform_space.mem_ball_self UniformSpace.mem_ball_self /-- The triangle inequality for `UniformSpace.ball` -/ theorem mem_ball_comp {V W : Set (β × β)} {x y z} (h : y ∈ ball x V) (h' : z ∈ ball y W) : z ∈ ball x (V ○ W) := prod_mk_mem_compRel h h' #align mem_ball_comp mem_ball_comp theorem ball_subset_of_comp_subset {V W : Set (β × β)} {x y} (h : x ∈ ball y W) (h' : W ○ W ⊆ V) : ball x W ⊆ ball y V := fun _z z_in => h' (mem_ball_comp h z_in) #align ball_subset_of_comp_subset ball_subset_of_comp_subset theorem ball_mono {V W : Set (β × β)} (h : V ⊆ W) (x : β) : ball x V ⊆ ball x W := preimage_mono h #align ball_mono ball_mono theorem ball_inter (x : β) (V W : Set (β × β)) : ball x (V ∩ W) = ball x V ∩ ball x W := preimage_inter #align ball_inter ball_inter theorem ball_inter_left (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x V := ball_mono inter_subset_left x #align ball_inter_left ball_inter_left theorem ball_inter_right (x : β) (V W : Set (β × β)) : ball x (V ∩ W) ⊆ ball x W := ball_mono inter_subset_right x #align ball_inter_right ball_inter_right theorem mem_ball_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x y} : x ∈ ball y V ↔ y ∈ ball x V := show (x, y) ∈ Prod.swap ⁻¹' V ↔ (x, y) ∈ V by unfold SymmetricRel at hV rw [hV] #align mem_ball_symmetry mem_ball_symmetry theorem ball_eq_of_symmetry {V : Set (β × β)} (hV : SymmetricRel V) {x} : ball x V = { y | (y, x) ∈ V } := by ext y rw [mem_ball_symmetry hV] exact Iff.rfl #align ball_eq_of_symmetry ball_eq_of_symmetry theorem mem_comp_of_mem_ball {V W : Set (β × β)} {x y z : β} (hV : SymmetricRel V) (hx : x ∈ ball z V) (hy : y ∈ ball z W) : (x, y) ∈ V ○ W := by rw [mem_ball_symmetry hV] at hx exact ⟨z, hx, hy⟩ #align mem_comp_of_mem_ball mem_comp_of_mem_ball theorem UniformSpace.isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id #align uniform_space.is_open_ball UniformSpace.isOpen_ball theorem UniformSpace.isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| continuous_const.prod_mk continuous_id theorem mem_comp_comp {V W M : Set (β × β)} (hW' : SymmetricRel W) {p : β × β} : p ∈ V ○ M ○ W ↔ (ball p.1 V ×ˢ ball p.2 W ∩ M).Nonempty := by cases' p with x y constructor · rintro ⟨z, ⟨w, hpw, hwz⟩, hzy⟩ exact ⟨(w, z), ⟨hpw, by rwa [mem_ball_symmetry hW']⟩, hwz⟩ · rintro ⟨⟨w, z⟩, ⟨w_in, z_in⟩, hwz⟩ rw [mem_ball_symmetry hW'] at z_in exact ⟨z, ⟨w, w_in, hwz⟩, z_in⟩ #align mem_comp_comp mem_comp_comp /-! ### Neighborhoods in uniform spaces -/ theorem mem_nhds_uniformity_iff_right {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α := by simp only [nhds_eq_comap_uniformity, mem_comap_prod_mk] #align mem_nhds_uniformity_iff_right mem_nhds_uniformity_iff_right theorem mem_nhds_uniformity_iff_left {x : α} {s : Set α} : s ∈ 𝓝 x ↔ { p : α × α | p.2 = x → p.1 ∈ s } ∈ 𝓤 α := by rw [uniformity_eq_symm, mem_nhds_uniformity_iff_right] simp only [map_def, mem_map, preimage_setOf_eq, Prod.snd_swap, Prod.fst_swap] #align mem_nhds_uniformity_iff_left mem_nhds_uniformity_iff_left theorem nhdsWithin_eq_comap_uniformity_of_mem {x : α} {T : Set α} (hx : x ∈ T) (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (T ×ˢ S)).comap (Prod.mk x) := by simp [nhdsWithin, nhds_eq_comap_uniformity, hx] theorem nhdsWithin_eq_comap_uniformity {x : α} (S : Set α) : 𝓝[S] x = (𝓤 α ⊓ 𝓟 (univ ×ˢ S)).comap (Prod.mk x) := nhdsWithin_eq_comap_uniformity_of_mem (mem_univ _) S /-- See also `isOpen_iff_open_ball_subset`. -/ theorem isOpen_iff_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, ball x V ⊆ s := by simp_rw [isOpen_iff_mem_nhds, nhds_eq_comap_uniformity, mem_comap, ball] #align is_open_iff_ball_subset isOpen_iff_ball_subset
Mathlib/Topology/UniformSpace/Basic.lean
746
749
theorem nhds_basis_uniformity' {p : ι → Prop} {s : ι → Set (α × α)} (h : (𝓤 α).HasBasis p s) {x : α} : (𝓝 x).HasBasis p fun i => ball x (s i) := by
rw [nhds_eq_comap_uniformity] exact h.comap (Prod.mk x)
/- Copyright (c) 2021 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Martin Zinkevich, Rémy Degenne -/ import Mathlib.Logic.Encodable.Lattice import Mathlib.MeasureTheory.MeasurableSpace.Defs #align_import measure_theory.pi_system from "leanprover-community/mathlib"@"98e83c3d541c77cdb7da20d79611a780ff8e7d90" /-! # Induction principles for measurable sets, related to π-systems and λ-systems. ## Main statements * The main theorem of this file is Dynkin's π-λ theorem, which appears here as an induction principle `induction_on_inter`. Suppose `s` is a collection of subsets of `α` such that the intersection of two members of `s` belongs to `s` whenever it is nonempty. Let `m` be the σ-algebra generated by `s`. In order to check that a predicate `C` holds on every member of `m`, it suffices to check that `C` holds on the members of `s` and that `C` is preserved by complementation and *disjoint* countable unions. * The proof of this theorem relies on the notion of `IsPiSystem`, i.e., a collection of sets which is closed under binary non-empty intersections. Note that this is a small variation around the usual notion in the literature, which often requires that a π-system is non-empty, and closed also under disjoint intersections. This variation turns out to be convenient for the formalization. * The proof of Dynkin's π-λ theorem also requires the notion of `DynkinSystem`, i.e., a collection of sets which contains the empty set, is closed under complementation and under countable union of pairwise disjoint sets. The disjointness condition is the only difference with `σ`-algebras. * `generatePiSystem g` gives the minimal π-system containing `g`. This can be considered a Galois insertion into both measurable spaces and sets. * `generateFrom_generatePiSystem_eq` proves that if you start from a collection of sets `g`, take the generated π-system, and then the generated σ-algebra, you get the same result as the σ-algebra generated from `g`. This is useful because there are connections between independent sets that are π-systems and the generated independent spaces. * `mem_generatePiSystem_iUnion_elim` and `mem_generatePiSystem_iUnion_elim'` show that any element of the π-system generated from the union of a set of π-systems can be represented as the intersection of a finite number of elements from these sets. * `piiUnionInter` defines a new π-system from a family of π-systems `π : ι → Set (Set α)` and a set of indices `S : Set ι`. `piiUnionInter π S` is the set of sets that can be written as `⋂ x ∈ t, f x` for some finset `t ∈ S` and sets `f x ∈ π x`. ## Implementation details * `IsPiSystem` is a predicate, not a type. Thus, we don't explicitly define the galois insertion, nor do we define a complete lattice. In theory, we could define a complete lattice and galois insertion on the subtype corresponding to `IsPiSystem`. -/ open MeasurableSpace Set open scoped Classical open MeasureTheory /-- A π-system is a collection of subsets of `α` that is closed under binary intersection of non-disjoint sets. Usually it is also required that the collection is nonempty, but we don't do that here. -/ def IsPiSystem {α} (C : Set (Set α)) : Prop := ∀ᵉ (s ∈ C) (t ∈ C), (s ∩ t : Set α).Nonempty → s ∩ t ∈ C #align is_pi_system IsPiSystem namespace MeasurableSpace theorem isPiSystem_measurableSet {α : Type*} [MeasurableSpace α] : IsPiSystem { s : Set α | MeasurableSet s } := fun _ hs _ ht _ => hs.inter ht #align measurable_space.is_pi_system_measurable_set MeasurableSpace.isPiSystem_measurableSet end MeasurableSpace theorem IsPiSystem.singleton {α} (S : Set α) : IsPiSystem ({S} : Set (Set α)) := by intro s h_s t h_t _ rw [Set.mem_singleton_iff.1 h_s, Set.mem_singleton_iff.1 h_t, Set.inter_self, Set.mem_singleton_iff] #align is_pi_system.singleton IsPiSystem.singleton theorem IsPiSystem.insert_empty {α} {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert ∅ S) := by intro s hs t ht hst cases' hs with hs hs · simp [hs] · cases' ht with ht ht · simp [ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) #align is_pi_system.insert_empty IsPiSystem.insert_empty theorem IsPiSystem.insert_univ {α} {S : Set (Set α)} (h_pi : IsPiSystem S) : IsPiSystem (insert Set.univ S) := by intro s hs t ht hst cases' hs with hs hs · cases' ht with ht ht <;> simp [hs, ht] · cases' ht with ht ht · simp [hs, ht] · exact Set.mem_insert_of_mem _ (h_pi s hs t ht hst) #align is_pi_system.insert_univ IsPiSystem.insert_univ theorem IsPiSystem.comap {α β} {S : Set (Set β)} (h_pi : IsPiSystem S) (f : α → β) : IsPiSystem { s : Set α | ∃ t ∈ S, f ⁻¹' t = s } := by rintro _ ⟨s, hs_mem, rfl⟩ _ ⟨t, ht_mem, rfl⟩ hst rw [← Set.preimage_inter] at hst ⊢ exact ⟨s ∩ t, h_pi s hs_mem t ht_mem (nonempty_of_nonempty_preimage hst), rfl⟩ #align is_pi_system.comap IsPiSystem.comap theorem isPiSystem_iUnion_of_directed_le {α ι} (p : ι → Set (Set α)) (hp_pi : ∀ n, IsPiSystem (p n)) (hp_directed : Directed (· ≤ ·) p) : IsPiSystem (⋃ n, p n) := by intro t1 ht1 t2 ht2 h rw [Set.mem_iUnion] at ht1 ht2 ⊢ cases' ht1 with n ht1 cases' ht2 with m ht2 obtain ⟨k, hpnk, hpmk⟩ : ∃ k, p n ≤ p k ∧ p m ≤ p k := hp_directed n m exact ⟨k, hp_pi k t1 (hpnk ht1) t2 (hpmk ht2) h⟩ #align is_pi_system_Union_of_directed_le isPiSystem_iUnion_of_directed_le theorem isPiSystem_iUnion_of_monotone {α ι} [SemilatticeSup ι] (p : ι → Set (Set α)) (hp_pi : ∀ n, IsPiSystem (p n)) (hp_mono : Monotone p) : IsPiSystem (⋃ n, p n) := isPiSystem_iUnion_of_directed_le p hp_pi (Monotone.directed_le hp_mono) #align is_pi_system_Union_of_monotone isPiSystem_iUnion_of_monotone section Order variable {α : Type*} {ι ι' : Sort*} [LinearOrder α] theorem isPiSystem_image_Iio (s : Set α) : IsPiSystem (Iio '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ - exact ⟨a ⊓ b, inf_ind a b ha hb, Iio_inter_Iio.symm⟩ #align is_pi_system_image_Iio isPiSystem_image_Iio theorem isPiSystem_Iio : IsPiSystem (range Iio : Set (Set α)) := @image_univ α _ Iio ▸ isPiSystem_image_Iio univ #align is_pi_system_Iio isPiSystem_Iio theorem isPiSystem_image_Ioi (s : Set α) : IsPiSystem (Ioi '' s) := @isPiSystem_image_Iio αᵒᵈ _ s #align is_pi_system_image_Ioi isPiSystem_image_Ioi theorem isPiSystem_Ioi : IsPiSystem (range Ioi : Set (Set α)) := @image_univ α _ Ioi ▸ isPiSystem_image_Ioi univ #align is_pi_system_Ioi isPiSystem_Ioi
Mathlib/MeasureTheory/PiSystem.lean
149
151
theorem isPiSystem_image_Iic (s : Set α) : IsPiSystem (Iic '' s) := by
rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ - exact ⟨a ⊓ b, inf_ind a b ha hb, Iic_inter_Iic.symm⟩
/- Copyright (c) 2022 Pim Otte. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller, Pim Otte -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Data.Nat.Choose.Sum import Mathlib.Data.Nat.Factorial.BigOperators import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Finset.Sym import Mathlib.Data.Finsupp.Multiset #align_import data.nat.choose.multinomial from "leanprover-community/mathlib"@"2738d2ca56cbc63be80c3bd48e9ed90ad94e947d" /-! # Multinomial This file defines the multinomial coefficient and several small lemma's for manipulating it. ## Main declarations - `Nat.multinomial`: the multinomial coefficient ## Main results - `Finset.sum_pow`: The expansion of `(s.sum x) ^ n` using multinomial coefficients -/ open Finset open scoped Nat namespace Nat variable {α : Type*} (s : Finset α) (f : α → ℕ) {a b : α} (n : ℕ) /-- The multinomial coefficient. Gives the number of strings consisting of symbols from `s`, where `c ∈ s` appears with multiplicity `f c`. Defined as `(∑ i ∈ s, f i)! / ∏ i ∈ s, (f i)!`. -/ def multinomial : ℕ := (∑ i ∈ s, f i)! / ∏ i ∈ s, (f i)! #align nat.multinomial Nat.multinomial theorem multinomial_pos : 0 < multinomial s f := Nat.div_pos (le_of_dvd (factorial_pos _) (prod_factorial_dvd_factorial_sum s f)) (prod_factorial_pos s f) #align nat.multinomial_pos Nat.multinomial_pos theorem multinomial_spec : (∏ i ∈ s, (f i)!) * multinomial s f = (∑ i ∈ s, f i)! := Nat.mul_div_cancel' (prod_factorial_dvd_factorial_sum s f) #align nat.multinomial_spec Nat.multinomial_spec @[simp] lemma multinomial_empty : multinomial ∅ f = 1 := by simp [multinomial] #align nat.multinomial_nil Nat.multinomial_empty @[deprecated (since := "2024-06-01")] alias multinomial_nil := multinomial_empty variable {s f} lemma multinomial_cons (ha : a ∉ s) (f : α → ℕ) : multinomial (s.cons a ha) f = (f a + ∑ i ∈ s, f i).choose (f a) * multinomial s f := by rw [multinomial, Nat.div_eq_iff_eq_mul_left _ (prod_factorial_dvd_factorial_sum _ _), prod_cons, multinomial, mul_assoc, mul_left_comm _ (f a)!, Nat.div_mul_cancel (prod_factorial_dvd_factorial_sum _ _), ← mul_assoc, Nat.choose_symm_add, Nat.add_choose_mul_factorial_mul_factorial, Finset.sum_cons] positivity lemma multinomial_insert [DecidableEq α] (ha : a ∉ s) (f : α → ℕ) : multinomial (insert a s) f = (f a + ∑ i ∈ s, f i).choose (f a) * multinomial s f := by rw [← cons_eq_insert _ _ ha, multinomial_cons] #align nat.multinomial_insert Nat.multinomial_insert @[simp] lemma multinomial_singleton (a : α) (f : α → ℕ) : multinomial {a} f = 1 := by rw [← cons_empty, multinomial_cons]; simp #align nat.multinomial_singleton Nat.multinomial_singleton @[simp] theorem multinomial_insert_one [DecidableEq α] (h : a ∉ s) (h₁ : f a = 1) : multinomial (insert a s) f = (s.sum f).succ * multinomial s f := by simp only [multinomial, one_mul, factorial] rw [Finset.sum_insert h, Finset.prod_insert h, h₁, add_comm, ← succ_eq_add_one, factorial_succ] simp only [factorial_one, one_mul, Function.comp_apply, factorial, mul_one, ← one_eq_succ_zero] rw [Nat.mul_div_assoc _ (prod_factorial_dvd_factorial_sum _ _)] #align nat.multinomial_insert_one Nat.multinomial_insert_one theorem multinomial_congr {f g : α → ℕ} (h : ∀ a ∈ s, f a = g a) : multinomial s f = multinomial s g := by simp only [multinomial]; congr 1 · rw [Finset.sum_congr rfl h] · exact Finset.prod_congr rfl fun a ha => by rw [h a ha] #align nat.multinomial_congr Nat.multinomial_congr /-! ### Connection to binomial coefficients When `Nat.multinomial` is applied to a `Finset` of two elements `{a, b}`, the result a binomial coefficient. We use `binomial` in the names of lemmas that involves `Nat.multinomial {a, b}`. -/ theorem binomial_eq [DecidableEq α] (h : a ≠ b) : multinomial {a, b} f = (f a + f b)! / ((f a)! * (f b)!) := by simp [multinomial, Finset.sum_pair h, Finset.prod_pair h] #align nat.binomial_eq Nat.binomial_eq theorem binomial_eq_choose [DecidableEq α] (h : a ≠ b) : multinomial {a, b} f = (f a + f b).choose (f a) := by simp [binomial_eq h, choose_eq_factorial_div_factorial (Nat.le_add_right _ _)] #align nat.binomial_eq_choose Nat.binomial_eq_choose
Mathlib/Data/Nat/Choose/Multinomial.lean
112
114
theorem binomial_spec [DecidableEq α] (hab : a ≠ b) : (f a)! * (f b)! * multinomial {a, b} f = (f a + f b)! := by
simpa [Finset.sum_pair hab, Finset.prod_pair hab] using multinomial_spec {a, b} f
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Data.Int.Interval import Mathlib.RingTheory.Binomial import Mathlib.RingTheory.HahnSeries.PowerSeries import Mathlib.RingTheory.HahnSeries.Summable import Mathlib.FieldTheory.RatFunc.AsPolynomial import Mathlib.RingTheory.Localization.FractionRing #align_import ring_theory.laurent_series from "leanprover-community/mathlib"@"831c494092374cfe9f50591ed0ac81a25efc5b86" /-! # Laurent Series ## Main Definitions * Defines `LaurentSeries` as an abbreviation for `HahnSeries ℤ`. * Defines `hasseDeriv` of a Laurent series with coefficients in a module over a ring. * Provides a coercion `PowerSeries R` into `LaurentSeries R` given by `HahnSeries.ofPowerSeries`. * Defines `LaurentSeries.powerSeriesPart` * Defines the localization map `LaurentSeries.of_powerSeries_localization` which evaluates to `HahnSeries.ofPowerSeries`. * Embedding of rational functions into Laurent series, provided as a coercion, utilizing the underlying `RatFunc.coeAlgHom`. ## Main Results * Basic properties of Hasse derivatives -/ universe u open scoped Classical open HahnSeries Polynomial noncomputable section /-- A `LaurentSeries` is implemented as a `HahnSeries` with value group `ℤ`. -/ abbrev LaurentSeries (R : Type u) [Zero R] := HahnSeries ℤ R #align laurent_series LaurentSeries variable {R : Type*} namespace LaurentSeries section HasseDeriv /-- The Hasse derivative of Laurent series, as a linear map. -/ @[simps] def hasseDeriv (R : Type*) {V : Type*} [AddCommGroup V] [Semiring R] [Module R V] (k : ℕ) : LaurentSeries V →ₗ[R] LaurentSeries V where toFun f := HahnSeries.ofSuppBddBelow (fun (n : ℤ) => (Ring.choose (n + k) k) • f.coeff (n + k)) (forallLTEqZero_supp_BddBelow _ (f.order - k : ℤ) (fun _ h_lt ↦ by rw [coeff_eq_zero_of_lt_order <| lt_sub_iff_add_lt.mp h_lt, smul_zero])) map_add' f g := by ext simp only [ofSuppBddBelow, add_coeff', Pi.add_apply, smul_add] map_smul' r f := by ext simp only [ofSuppBddBelow, smul_coeff, RingHom.id_apply, smul_comm r] variable [Semiring R] {V : Type*} [AddCommGroup V] [Module R V] theorem hasseDeriv_coeff (k : ℕ) (f : LaurentSeries V) (n : ℤ) : (hasseDeriv R k f).coeff n = Ring.choose (n + k) k • f.coeff (n + k) := rfl end HasseDeriv section Semiring variable [Semiring R] instance : Coe (PowerSeries R) (LaurentSeries R) := ⟨HahnSeries.ofPowerSeries ℤ R⟩ /- Porting note: now a syntactic tautology and not needed elsewhere theorem coe_powerSeries (x : PowerSeries R) : (x : LaurentSeries R) = HahnSeries.ofPowerSeries ℤ R x := rfl -/ #noalign laurent_series.coe_power_series @[simp] theorem coeff_coe_powerSeries (x : PowerSeries R) (n : ℕ) : HahnSeries.coeff (x : LaurentSeries R) n = PowerSeries.coeff R n x := by rw [ofPowerSeries_apply_coeff] #align laurent_series.coeff_coe_power_series LaurentSeries.coeff_coe_powerSeries /-- This is a power series that can be multiplied by an integer power of `X` to give our Laurent series. If the Laurent series is nonzero, `powerSeriesPart` has a nonzero constant term. -/ def powerSeriesPart (x : LaurentSeries R) : PowerSeries R := PowerSeries.mk fun n => x.coeff (x.order + n) #align laurent_series.power_series_part LaurentSeries.powerSeriesPart @[simp] theorem powerSeriesPart_coeff (x : LaurentSeries R) (n : ℕ) : PowerSeries.coeff R n x.powerSeriesPart = x.coeff (x.order + n) := PowerSeries.coeff_mk _ _ #align laurent_series.power_series_part_coeff LaurentSeries.powerSeriesPart_coeff @[simp] theorem powerSeriesPart_zero : powerSeriesPart (0 : LaurentSeries R) = 0 := by ext simp [(PowerSeries.coeff _ _).map_zero] -- Note: this doesn't get picked up any more #align laurent_series.power_series_part_zero LaurentSeries.powerSeriesPart_zero @[simp] theorem powerSeriesPart_eq_zero (x : LaurentSeries R) : x.powerSeriesPart = 0 ↔ x = 0 := by constructor · contrapose! simp only [ne_eq] intro h rw [PowerSeries.ext_iff, not_forall] refine ⟨0, ?_⟩ simp [coeff_order_ne_zero h] · rintro rfl simp #align laurent_series.power_series_part_eq_zero LaurentSeries.powerSeriesPart_eq_zero @[simp] theorem single_order_mul_powerSeriesPart (x : LaurentSeries R) : (single x.order 1 : LaurentSeries R) * x.powerSeriesPart = x := by ext n rw [← sub_add_cancel n x.order, single_mul_coeff_add, sub_add_cancel, one_mul] by_cases h : x.order ≤ n · rw [Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), coeff_coe_powerSeries, powerSeriesPart_coeff, ← Int.eq_natAbs_of_zero_le (sub_nonneg_of_le h), add_sub_cancel] · rw [ofPowerSeries_apply, embDomain_notin_range] · contrapose! h exact order_le_of_coeff_ne_zero h.symm · contrapose! h simp only [Set.mem_range, RelEmbedding.coe_mk, Function.Embedding.coeFn_mk] at h obtain ⟨m, hm⟩ := h rw [← sub_nonneg, ← hm] simp only [Nat.cast_nonneg] #align laurent_series.single_order_mul_power_series_part LaurentSeries.single_order_mul_powerSeriesPart theorem ofPowerSeries_powerSeriesPart (x : LaurentSeries R) : ofPowerSeries ℤ R x.powerSeriesPart = single (-x.order) 1 * x := by refine Eq.trans ?_ (congr rfl x.single_order_mul_powerSeriesPart) rw [← mul_assoc, single_mul_single, neg_add_self, mul_one, ← C_apply, C_one, one_mul] #align laurent_series.of_power_series_power_series_part LaurentSeries.ofPowerSeries_powerSeriesPart end Semiring instance [CommSemiring R] : Algebra (PowerSeries R) (LaurentSeries R) := (HahnSeries.ofPowerSeries ℤ R).toAlgebra @[simp] theorem coe_algebraMap [CommSemiring R] : ⇑(algebraMap (PowerSeries R) (LaurentSeries R)) = HahnSeries.ofPowerSeries ℤ R := rfl #align laurent_series.coe_algebra_map LaurentSeries.coe_algebraMap /-- The localization map from power series to Laurent series. -/ @[simps (config := { rhsMd := .all, simpRhs := true })] instance of_powerSeries_localization [CommRing R] : IsLocalization (Submonoid.powers (PowerSeries.X : PowerSeries R)) (LaurentSeries R) where map_units' := by rintro ⟨_, n, rfl⟩ refine ⟨⟨single (n : ℤ) 1, single (-n : ℤ) 1, ?_, ?_⟩, ?_⟩ · simp only [single_mul_single, mul_one, add_right_neg] rfl · simp only [single_mul_single, mul_one, add_left_neg] rfl · dsimp; rw [ofPowerSeries_X_pow] surj' z := by by_cases h : 0 ≤ z.order · refine ⟨⟨PowerSeries.X ^ Int.natAbs z.order * powerSeriesPart z, 1⟩, ?_⟩ simp only [RingHom.map_one, mul_one, RingHom.map_mul, coe_algebraMap, ofPowerSeries_X_pow, Submonoid.coe_one] rw [Int.natAbs_of_nonneg h, single_order_mul_powerSeriesPart] · refine ⟨⟨powerSeriesPart z, PowerSeries.X ^ Int.natAbs z.order, ⟨_, rfl⟩⟩, ?_⟩ simp only [coe_algebraMap, ofPowerSeries_powerSeriesPart] rw [mul_comm _ z] refine congr rfl ?_ rw [ofPowerSeries_X_pow, Int.ofNat_natAbs_of_nonpos] exact le_of_not_ge h exists_of_eq {x y} := by rw [coe_algebraMap, ofPowerSeries_injective.eq_iff] rintro rfl exact ⟨1, rfl⟩ #align laurent_series.of_power_series_localization LaurentSeries.of_powerSeries_localization instance {K : Type*} [Field K] : IsFractionRing (PowerSeries K) (LaurentSeries K) := IsLocalization.of_le (Submonoid.powers (PowerSeries.X : PowerSeries K)) _ (powers_le_nonZeroDivisors_of_noZeroDivisors PowerSeries.X_ne_zero) fun _ hf => isUnit_of_mem_nonZeroDivisors <| map_mem_nonZeroDivisors _ HahnSeries.ofPowerSeries_injective hf end LaurentSeries namespace PowerSeries open LaurentSeries variable {R' : Type*} [Semiring R] [Ring R'] (f g : PowerSeries R) (f' g' : PowerSeries R') @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_zero : ((0 : PowerSeries R) : LaurentSeries R) = 0 := (ofPowerSeries ℤ R).map_zero #align power_series.coe_zero PowerSeries.coe_zero @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_one : ((1 : PowerSeries R) : LaurentSeries R) = 1 := (ofPowerSeries ℤ R).map_one #align power_series.coe_one PowerSeries.coe_one @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_add : ((f + g : PowerSeries R) : LaurentSeries R) = f + g := (ofPowerSeries ℤ R).map_add _ _ #align power_series.coe_add PowerSeries.coe_add @[norm_cast] theorem coe_sub : ((f' - g' : PowerSeries R') : LaurentSeries R') = f' - g' := (ofPowerSeries ℤ R').map_sub _ _ #align power_series.coe_sub PowerSeries.coe_sub @[norm_cast] theorem coe_neg : ((-f' : PowerSeries R') : LaurentSeries R') = -f' := (ofPowerSeries ℤ R').map_neg _ #align power_series.coe_neg PowerSeries.coe_neg @[norm_cast] -- Porting note (#10618): simp can prove this theorem coe_mul : ((f * g : PowerSeries R) : LaurentSeries R) = f * g := (ofPowerSeries ℤ R).map_mul _ _ #align power_series.coe_mul PowerSeries.coe_mul theorem coeff_coe (i : ℤ) : ((f : PowerSeries R) : LaurentSeries R).coeff i = if i < 0 then 0 else PowerSeries.coeff R i.natAbs f := by cases i · rw [Int.ofNat_eq_coe, coeff_coe_powerSeries, if_neg (Int.natCast_nonneg _).not_lt, Int.natAbs_ofNat] · rw [ofPowerSeries_apply, embDomain_notin_image_support, if_pos (Int.negSucc_lt_zero _)] simp only [not_exists, RelEmbedding.coe_mk, Set.mem_image, not_and, Function.Embedding.coeFn_mk, Ne, toPowerSeries_symm_apply_coeff, mem_support, imp_true_iff, not_false_iff] #align power_series.coeff_coe PowerSeries.coeff_coe -- Porting note (#10618): simp can prove this -- Porting note: removed norm_cast attribute theorem coe_C (r : R) : ((C R r : PowerSeries R) : LaurentSeries R) = HahnSeries.C r := ofPowerSeries_C _ set_option linter.uppercaseLean3 false in #align power_series.coe_C PowerSeries.coe_C -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_X : ((X : PowerSeries R) : LaurentSeries R) = single 1 1 := ofPowerSeries_X set_option linter.uppercaseLean3 false in #align power_series.coe_X PowerSeries.coe_X @[simp, norm_cast] theorem coe_smul {S : Type*} [Semiring S] [Module R S] (r : R) (x : PowerSeries S) : ((r • x : PowerSeries S) : LaurentSeries S) = r • (ofPowerSeries ℤ S x) := by ext simp [coeff_coe, coeff_smul, smul_ite] #align power_series.coe_smul PowerSeries.coe_smul -- Porting note: RingHom.map_bit0 and RingHom.map_bit1 no longer exist #noalign power_series.coe_bit0 #noalign power_series.coe_bit1 @[norm_cast] theorem coe_pow (n : ℕ) : ((f ^ n : PowerSeries R) : LaurentSeries R) = (ofPowerSeries ℤ R f) ^ n := (ofPowerSeries ℤ R).map_pow _ _ #align power_series.coe_pow PowerSeries.coe_pow end PowerSeries namespace RatFunc section RatFunc open RatFunc variable {F : Type u} [Field F] (p q : F[X]) (f g : RatFunc F) /-- The coercion `RatFunc F → LaurentSeries F` as bundled alg hom. -/ def coeAlgHom (F : Type u) [Field F] : RatFunc F →ₐ[F[X]] LaurentSeries F := liftAlgHom (Algebra.ofId _ _) <| nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ <| Polynomial.algebraMap_hahnSeries_injective _ #align ratfunc.coe_alg_hom RatFunc.coeAlgHom /-- The coercion `RatFunc F → LaurentSeries F` as a function. This is the implementation of `coeToLaurentSeries`. -/ @[coe] def coeToLaurentSeries_fun {F : Type u} [Field F] : RatFunc F → LaurentSeries F := coeAlgHom F instance coeToLaurentSeries : Coe (RatFunc F) (LaurentSeries F) := ⟨coeToLaurentSeries_fun⟩ #align ratfunc.coe_to_laurent_series RatFunc.coeToLaurentSeries theorem coe_def : (f : LaurentSeries F) = coeAlgHom F f := rfl #align ratfunc.coe_def RatFunc.coe_def theorem coe_num_denom : (f : LaurentSeries F) = f.num / f.denom := liftAlgHom_apply _ _ f #align ratfunc.coe_num_denom RatFunc.coe_num_denom theorem coe_injective : Function.Injective ((↑) : RatFunc F → LaurentSeries F) := liftAlgHom_injective _ (Polynomial.algebraMap_hahnSeries_injective _) #align ratfunc.coe_injective RatFunc.coe_injective -- Porting note: removed the `norm_cast` tag: -- `norm_cast: badly shaped lemma, rhs can't start with coe `↑(coeAlgHom F) f` @[simp] theorem coe_apply : coeAlgHom F f = f := rfl #align ratfunc.coe_apply RatFunc.coe_apply theorem coe_coe (P : Polynomial F) : (P : LaurentSeries F) = (P : RatFunc F) := by simp only [coePolynomial, coe_def, AlgHom.commutes, algebraMap_hahnSeries_apply] @[simp, norm_cast] theorem coe_zero : ((0 : RatFunc F) : LaurentSeries F) = 0 := (coeAlgHom F).map_zero #align ratfunc.coe_zero RatFunc.coe_zero theorem coe_ne_zero {f : Polynomial F} (hf : f ≠ 0) : (↑f : PowerSeries F) ≠ 0 := by simp only [ne_eq, Polynomial.coe_eq_zero_iff, hf, not_false_eq_true] @[simp, norm_cast] theorem coe_one : ((1 : RatFunc F) : LaurentSeries F) = 1 := (coeAlgHom F).map_one #align ratfunc.coe_one RatFunc.coe_one @[simp, norm_cast] theorem coe_add : ((f + g : RatFunc F) : LaurentSeries F) = f + g := (coeAlgHom F).map_add _ _ #align ratfunc.coe_add RatFunc.coe_add @[simp, norm_cast] theorem coe_sub : ((f - g : RatFunc F) : LaurentSeries F) = f - g := (coeAlgHom F).map_sub _ _ #align ratfunc.coe_sub RatFunc.coe_sub @[simp, norm_cast] theorem coe_neg : ((-f : RatFunc F) : LaurentSeries F) = -f := (coeAlgHom F).map_neg _ #align ratfunc.coe_neg RatFunc.coe_neg @[simp, norm_cast] theorem coe_mul : ((f * g : RatFunc F) : LaurentSeries F) = f * g := (coeAlgHom F).map_mul _ _ #align ratfunc.coe_mul RatFunc.coe_mul @[simp, norm_cast] theorem coe_pow (n : ℕ) : ((f ^ n : RatFunc F) : LaurentSeries F) = (f : LaurentSeries F) ^ n := (coeAlgHom F).map_pow _ _ #align ratfunc.coe_pow RatFunc.coe_pow @[simp, norm_cast] theorem coe_div : ((f / g : RatFunc F) : LaurentSeries F) = (f : LaurentSeries F) / (g : LaurentSeries F) := map_div₀ (coeAlgHom F) _ _ #align ratfunc.coe_div RatFunc.coe_div @[simp, norm_cast] theorem coe_C (r : F) : ((RatFunc.C r : RatFunc F) : LaurentSeries F) = HahnSeries.C r := by rw [coe_num_denom, num_C, denom_C, Polynomial.coe_C, -- Porting note: removed `coe_C` Polynomial.coe_one, PowerSeries.coe_one, div_one] simp only [algebraMap_eq_C, ofPowerSeries_C, C_apply] -- Porting note: added set_option linter.uppercaseLean3 false in #align ratfunc.coe_C RatFunc.coe_C -- TODO: generalize over other modules @[simp, norm_cast] theorem coe_smul (r : F) : ((r • f : RatFunc F) : LaurentSeries F) = r • (f : LaurentSeries F) := by rw [RatFunc.smul_eq_C_mul, ← C_mul_eq_smul, coe_mul, coe_C] #align ratfunc.coe_smul RatFunc.coe_smul -- Porting note: removed `norm_cast` because "badly shaped lemma, rhs can't start with coe" -- even though `single 1 1` is a bundled function application, not a "real" coercion @[simp, nolint simpNF] -- Added `simpNF` to avoid timeout #8386
Mathlib/RingTheory/LaurentSeries.lean
386
390
theorem coe_X : ((X : RatFunc F) : LaurentSeries F) = single 1 1 := by
rw [coe_num_denom, num_X, denom_X, Polynomial.coe_X, -- Porting note: removed `coe_C` Polynomial.coe_one, PowerSeries.coe_one, div_one] simp only [ofPowerSeries_X] -- Porting note: added
/- 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 Submodule Set FiniteDimensional 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 `FiniteDimensional.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 _ #align basis.of_rank_eq_zero Basis.ofRankEqZero @[simp] theorem Basis.ofRankEqZero_apply [Module.Free K V] {ι : Type*} [IsEmpty ι] (hV : Module.rank K V = 0) (i : ι) : Basis.ofRankEqZero hV i = 0 := rfl #align basis.of_rank_eq_zero_apply Basis.ofRankEqZero_apply theorem le_rank_iff_exists_linearIndependent [Module.Free K V] {c : Cardinal} : c ≤ Module.rank K V ↔ ∃ s : Set V, #s = c ∧ LinearIndependent K ((↑) : s → V) := by haveI := nontrivial_of_invariantBasisNumber K constructor · intro h obtain ⟨κ, t'⟩ := Module.Free.exists_basis (R := K) (M := V) let t := t'.reindexRange have : LinearIndependent K ((↑) : Set.range t' → V) := by convert t.linearIndependent ext; exact (Basis.reindexRange_apply _ _).symm 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 #align le_rank_iff_exists_linear_independent le_rank_iff_exists_linearIndependent 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⟩ #align le_rank_iff_exists_linear_independent_finset le_rank_iff_exists_linearIndependent_finset /-- 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 #align rank_le_one_iff rank_le_one_iff /-- 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] #align rank_submodule_le_one_iff rank_submodule_le_one_iff /-- 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 [h'] at H, fun v hv ↦ ?_⟩, fun ⟨v₀, hv₀, H, h⟩ ↦ ⟨⟨v₀, hv₀⟩, fun h' ↦ H (by simpa using 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₀}) #align rank_submodule_le_one_iff' rank_submodule_le_one_iff' 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)⟩⟩ #align submodule.rank_le_one_iff_is_principal Submodule.rank_le_one_iff_isPrincipal 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] #align module.rank_le_one_iff_top_is_principal Module.rank_le_one_iff_top_isPrincipal /-- A module has dimension 1 iff there is some `v : V` so `{v}` is a basis. -/
Mathlib/LinearAlgebra/Dimension/FreeAndStrongRankCondition.lean
192
198
theorem finrank_eq_one_iff [Module.Free K V] (ι : Type*) [Unique ι] : finrank K V = 1 ↔ Nonempty (Basis ι K V) := by
constructor · intro h exact ⟨basisUnique ι h⟩ · rintro ⟨b⟩ simpa using finrank_eq_card_basis b
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Sphere.Basic import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional import Mathlib.Tactic.DeriveFintype #align_import geometry.euclidean.circumcenter from "leanprover-community/mathlib"@"2de9c37fa71dde2f1c6feff19876dd6a7b1519f0" /-! # Circumcenter and circumradius This file proves some lemmas on points equidistant from a set of points, and defines the circumradius and circumcenter of a simplex. There are also some definitions for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. ## Main definitions * `circumcenter` and `circumradius` are the circumcenter and circumradius of a simplex. ## References * https://en.wikipedia.org/wiki/Circumscribed_circle -/ noncomputable section open scoped Classical open RealInnerProductSpace namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] open AffineSubspace /-- `p` is equidistant from two points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {p1 p2 : P} (p3 : P) (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : dist p1 p3 = dist p2 p3 ↔ dist p1 (orthogonalProjection s p3) = dist p2 (orthogonalProjection s p3) := by rw [← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, ← mul_self_inj_of_nonneg dist_nonneg dist_nonneg, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp1, dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p3 hp2] simp #align euclidean_geometry.dist_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_eq_iff_dist_orthogonalProjection_eq /-- `p` is equidistant from a set of points in `s` if and only if its `orthogonalProjection` is. -/ theorem dist_set_eq_iff_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (Set.Pairwise ps fun p1 p2 => dist p1 p = dist p2 p) ↔ Set.Pairwise ps fun p1 p2 => dist p1 (orthogonalProjection s p) = dist p2 (orthogonalProjection s p) := ⟨fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).1 (h hp1 hp2 hne), fun h _ hp1 _ hp2 hne => (dist_eq_iff_dist_orthogonalProjection_eq p (hps hp1) (hps hp2)).2 (h hp1 hp2 hne)⟩ #align euclidean_geometry.dist_set_eq_iff_dist_orthogonal_projection_eq EuclideanGeometry.dist_set_eq_iff_dist_orthogonalProjection_eq /-- There exists `r` such that `p` has distance `r` from all the points of a set of points in `s` if and only if there exists (possibly different) `r` such that its `orthogonalProjection` has that distance from all the points in that set. -/ theorem exists_dist_eq_iff_exists_dist_orthogonalProjection_eq {s : AffineSubspace ℝ P} [Nonempty s] [HasOrthogonalProjection s.direction] {ps : Set P} (hps : ps ⊆ s) (p : P) : (∃ r, ∀ p1 ∈ ps, dist p1 p = r) ↔ ∃ r, ∀ p1 ∈ ps, dist p1 ↑(orthogonalProjection s p) = r := by have h := dist_set_eq_iff_dist_orthogonalProjection_eq hps p simp_rw [Set.pairwise_eq_iff_exists_eq] at h exact h #align euclidean_geometry.exists_dist_eq_iff_exists_dist_orthogonal_projection_eq EuclideanGeometry.exists_dist_eq_iff_exists_dist_orthogonalProjection_eq /-- The induction step for the existence and uniqueness of the circumcenter. Given a nonempty set of points in a nonempty affine subspace whose direction is complete, such that there is a unique (circumcenter, circumradius) pair for those points in that subspace, and a point `p` not in that subspace, there is a unique (circumcenter, circumradius) pair for the set with `p` added, in the span of the subspace with `p` added. -/ theorem existsUnique_dist_eq_of_insert {s : AffineSubspace ℝ P} [HasOrthogonalProjection s.direction] {ps : Set P} (hnps : ps.Nonempty) {p : P} (hps : ps ⊆ s) (hp : p ∉ s) (hu : ∃! cs : Sphere P, cs.center ∈ s ∧ ps ⊆ (cs : Set P)) : ∃! cs₂ : Sphere P, cs₂.center ∈ affineSpan ℝ (insert p (s : Set P)) ∧ insert p ps ⊆ (cs₂ : Set P) := by haveI : Nonempty s := Set.Nonempty.to_subtype (hnps.mono hps) rcases hu with ⟨⟨cc, cr⟩, ⟨hcc, hcr⟩, hcccru⟩ simp only at hcc hcr hcccru let x := dist cc (orthogonalProjection s p) let y := dist p (orthogonalProjection s p) have hy0 : y ≠ 0 := dist_orthogonalProjection_ne_zero_of_not_mem hp let ycc₂ := (x * x + y * y - cr * cr) / (2 * y) let cc₂ := (ycc₂ / y) • (p -ᵥ orthogonalProjection s p : V) +ᵥ cc let cr₂ := √(cr * cr + ycc₂ * ycc₂) use ⟨cc₂, cr₂⟩ simp (config := { zeta := false, proj := false }) only have hpo : p = (1 : ℝ) • (p -ᵥ orthogonalProjection s p : V) +ᵥ (orthogonalProjection s p : P) := by simp constructor · constructor · refine vadd_mem_of_mem_direction ?_ (mem_affineSpan ℝ (Set.mem_insert_of_mem _ hcc)) rw [direction_affineSpan] exact Submodule.smul_mem _ _ (vsub_mem_vectorSpan ℝ (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (orthogonalProjection_mem _))) · intro p1 hp1 rw [Sphere.mem_coe, mem_sphere, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] cases' hp1 with hp1 hp1 · rw [hp1] rw [hpo, dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), ← dist_eq_norm_vsub V p, dist_comm _ cc] field_simp [ycc₂, hy0] ring · rw [dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp1), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc, Subtype.coe_mk, dist_of_mem_subset_mk_sphere hp1 hcr, dist_eq_norm_vsub V cc₂ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V, Real.norm_eq_abs, abs_div, abs_of_nonneg dist_nonneg, div_mul_cancel₀ _ hy0, abs_mul_abs_self] · rintro ⟨cc₃, cr₃⟩ ⟨hcc₃, hcr₃⟩ simp only at hcc₃ hcr₃ obtain ⟨t₃, cc₃', hcc₃', hcc₃''⟩ : ∃ r : ℝ, ∃ p0 ∈ s, cc₃ = r • (p -ᵥ ↑((orthogonalProjection s) p)) +ᵥ p0 := by rwa [mem_affineSpan_insert_iff (orthogonalProjection_mem p)] at hcc₃ have hcr₃' : ∃ r, ∀ p1 ∈ ps, dist p1 cc₃ = r := ⟨cr₃, fun p1 hp1 => dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp1) hcr₃⟩ rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq hps cc₃, hcc₃'', orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃'] at hcr₃' cases' hcr₃' with cr₃' hcr₃' have hu := hcccru ⟨cc₃', cr₃'⟩ simp only at hu replace hu := hu ⟨hcc₃', hcr₃'⟩ -- Porting note: was -- cases' hu with hucc hucr -- substs hucc hucr cases' hu have hcr₃val : cr₃ = √(cr * cr + t₃ * y * (t₃ * y)) := by cases' hnps with p0 hp0 have h' : ↑(⟨cc, hcc₃'⟩ : s) = cc := rfl rw [← dist_of_mem_subset_mk_sphere (Set.mem_insert_of_mem _ hp0) hcr₃, hcc₃'', ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)), dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq _ (hps hp0), orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ hcc₃', h', dist_of_mem_subset_mk_sphere hp0 hcr, dist_eq_norm_vsub V _ cc, vadd_vsub, norm_smul, ← dist_eq_norm_vsub V p, Real.norm_eq_abs, ← mul_assoc, mul_comm _ |t₃|, ← mul_assoc, abs_mul_abs_self] ring replace hcr₃ := dist_of_mem_subset_mk_sphere (Set.mem_insert _ _) hcr₃ rw [hpo, hcc₃'', hcr₃val, ← mul_self_inj_of_nonneg dist_nonneg (Real.sqrt_nonneg _), dist_sq_smul_orthogonal_vadd_smul_orthogonal_vadd (orthogonalProjection_mem p) hcc₃' _ _ (vsub_orthogonalProjection_mem_direction_orthogonal s p), dist_comm, ← dist_eq_norm_vsub V p, Real.mul_self_sqrt (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _))] at hcr₃ change x * x + _ * (y * y) = _ at hcr₃ rw [show x * x + (1 - t₃) * (1 - t₃) * (y * y) = x * x + y * y - 2 * y * (t₃ * y) + t₃ * y * (t₃ * y) by ring, add_left_inj] at hcr₃ have ht₃ : t₃ = ycc₂ / y := by field_simp [ycc₂, ← hcr₃, hy0] subst ht₃ change cc₃ = cc₂ at hcc₃'' congr rw [hcr₃val] congr 2 field_simp [hy0] #align euclidean_geometry.exists_unique_dist_eq_of_insert EuclideanGeometry.existsUnique_dist_eq_of_insert /-- Given a finite nonempty affinely independent family of points, there is a unique (circumcenter, circumradius) pair for those points in the affine subspace they span. -/ theorem _root_.AffineIndependent.existsUnique_dist_eq {ι : Type*} [hne : Nonempty ι] [Finite ι] {p : ι → P} (ha : AffineIndependent ℝ p) : ∃! cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range p) ∧ Set.range p ⊆ (cs : Set P) := by cases nonempty_fintype ι induction' hn : Fintype.card ι with m hm generalizing ι · exfalso have h := Fintype.card_pos_iff.2 hne rw [hn] at h exact lt_irrefl 0 h · cases' m with m · rw [Fintype.card_eq_one_iff] at hn cases' hn with i hi haveI : Unique ι := ⟨⟨i⟩, hi⟩ use ⟨p i, 0⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] constructor · simp_rw [hi default, Set.singleton_subset_iff] exact ⟨⟨⟩, by simp only [Metric.sphere_zero, Set.mem_singleton_iff]⟩ · rintro ⟨cc, cr⟩ simp only rintro ⟨rfl, hdist⟩ simp? [Set.singleton_subset_iff] at hdist says simp only [Set.singleton_subset_iff, Metric.mem_sphere, dist_self] at hdist rw [hi default, hdist] · have i := hne.some let ι2 := { x // x ≠ i } have hc : Fintype.card ι2 = m + 1 := by rw [Fintype.card_of_subtype (Finset.univ.filter fun x => x ≠ i)] · rw [Finset.filter_not] -- Porting note: removed `simp_rw [eq_comm]` and used `filter_eq'` instead of `filter_eq` rw [Finset.filter_eq' _ i, if_pos (Finset.mem_univ _), Finset.card_sdiff (Finset.subset_univ _), Finset.card_singleton, Finset.card_univ, hn] simp · simp haveI : Nonempty ι2 := Fintype.card_pos_iff.1 (hc.symm ▸ Nat.zero_lt_succ _) have ha2 : AffineIndependent ℝ fun i2 : ι2 => p i2 := ha.subtype _ replace hm := hm ha2 _ hc have hr : Set.range p = insert (p i) (Set.range fun i2 : ι2 => p i2) := by change _ = insert _ (Set.range fun i2 : { x | x ≠ i } => p i2) rw [← Set.image_eq_range, ← Set.image_univ, ← Set.image_insert_eq] congr with j simp [Classical.em] rw [hr, ← affineSpan_insert_affineSpan] refine existsUnique_dist_eq_of_insert (Set.range_nonempty _) (subset_spanPoints ℝ _) ?_ hm convert ha.not_mem_affineSpan_diff i Set.univ change (Set.range fun i2 : { x | x ≠ i } => p i2) = _ rw [← Set.image_eq_range] congr with j simp #align affine_independent.exists_unique_dist_eq AffineIndependent.existsUnique_dist_eq end EuclideanGeometry namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The circumsphere of a simplex. -/ def circumsphere {n : ℕ} (s : Simplex ℝ P n) : Sphere P := s.independent.existsUnique_dist_eq.choose #align affine.simplex.circumsphere Affine.Simplex.circumsphere /-- The property satisfied by the circumsphere. -/ theorem circumsphere_unique_dist_eq {n : ℕ} (s : Simplex ℝ P n) : (s.circumsphere.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ s.circumsphere) ∧ ∀ cs : Sphere P, cs.center ∈ affineSpan ℝ (Set.range s.points) ∧ Set.range s.points ⊆ cs → cs = s.circumsphere := s.independent.existsUnique_dist_eq.choose_spec #align affine.simplex.circumsphere_unique_dist_eq Affine.Simplex.circumsphere_unique_dist_eq /-- The circumcenter of a simplex. -/ def circumcenter {n : ℕ} (s : Simplex ℝ P n) : P := s.circumsphere.center #align affine.simplex.circumcenter Affine.Simplex.circumcenter /-- The circumradius of a simplex. -/ def circumradius {n : ℕ} (s : Simplex ℝ P n) : ℝ := s.circumsphere.radius #align affine.simplex.circumradius Affine.Simplex.circumradius /-- The center of the circumsphere is the circumcenter. -/ @[simp] theorem circumsphere_center {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.center = s.circumcenter := rfl #align affine.simplex.circumsphere_center Affine.Simplex.circumsphere_center /-- The radius of the circumsphere is the circumradius. -/ @[simp] theorem circumsphere_radius {n : ℕ} (s : Simplex ℝ P n) : s.circumsphere.radius = s.circumradius := rfl #align affine.simplex.circumsphere_radius Affine.Simplex.circumsphere_radius /-- The circumcenter lies in the affine span. -/ theorem circumcenter_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.circumcenter ∈ affineSpan ℝ (Set.range s.points) := s.circumsphere_unique_dist_eq.1.1 #align affine.simplex.circumcenter_mem_affine_span Affine.Simplex.circumcenter_mem_affineSpan /-- All points have distance from the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : dist (s.points i) s.circumcenter = s.circumradius := dist_of_mem_subset_sphere (Set.mem_range_self _) s.circumsphere_unique_dist_eq.1.2 #align affine.simplex.dist_circumcenter_eq_circumradius Affine.Simplex.dist_circumcenter_eq_circumradius /-- All points lie in the circumsphere. -/ theorem mem_circumsphere {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i ∈ s.circumsphere := s.dist_circumcenter_eq_circumradius i #align affine.simplex.mem_circumsphere Affine.Simplex.mem_circumsphere /-- All points have distance to the circumcenter equal to the circumradius. -/ @[simp] theorem dist_circumcenter_eq_circumradius' {n : ℕ} (s : Simplex ℝ P n) : ∀ i, dist s.circumcenter (s.points i) = s.circumradius := by intro i rw [dist_comm] exact dist_circumcenter_eq_circumradius _ _ #align affine.simplex.dist_circumcenter_eq_circumradius' Affine.Simplex.dist_circumcenter_eq_circumradius' /-- Given a point in the affine span from which all the points are equidistant, that point is the circumcenter. -/ theorem eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : p = s.circumcenter := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and] at h exact h.1 #align affine.simplex.eq_circumcenter_of_dist_eq Affine.Simplex.eq_circumcenter_of_dist_eq /-- Given a point in the affine span from which all the points are equidistant, that distance is the circumradius. -/ theorem eq_circumradius_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hp : p ∈ affineSpan ℝ (Set.range s.points)) {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : r = s.circumradius := by have h := s.circumsphere_unique_dist_eq.2 ⟨p, r⟩ simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h -- Porting note: added the next three lines (`simp` less powerful) rw [subset_sphere (s := ⟨p, r⟩)] at h simp only [hp, hr, forall_const, eq_self_iff_true, subset_sphere, Sphere.ext_iff, Set.forall_mem_range, mem_sphere, true_and_iff] at h exact h.2 #align affine.simplex.eq_circumradius_of_dist_eq Affine.Simplex.eq_circumradius_of_dist_eq /-- The circumradius is non-negative. -/ theorem circumradius_nonneg {n : ℕ} (s : Simplex ℝ P n) : 0 ≤ s.circumradius := s.dist_circumcenter_eq_circumradius 0 ▸ dist_nonneg #align affine.simplex.circumradius_nonneg Affine.Simplex.circumradius_nonneg /-- The circumradius of a simplex with at least two points is positive. -/ theorem circumradius_pos {n : ℕ} (s : Simplex ℝ P (n + 1)) : 0 < s.circumradius := by refine lt_of_le_of_ne s.circumradius_nonneg ?_ intro h have hr := s.dist_circumcenter_eq_circumradius simp_rw [← h, dist_eq_zero] at hr have h01 := s.independent.injective.ne (by simp : (0 : Fin (n + 2)) ≠ 1) simp [hr] at h01 #align affine.simplex.circumradius_pos Affine.Simplex.circumradius_pos /-- The circumcenter of a 0-simplex equals its unique point. -/ theorem circumcenter_eq_point (s : Simplex ℝ P 0) (i : Fin 1) : s.circumcenter = s.points i := by have h := s.circumcenter_mem_affineSpan have : Unique (Fin 1) := ⟨⟨0, by decide⟩, fun a => by simp only [Fin.eq_zero]⟩ simp only [Set.range_unique, AffineSubspace.mem_affineSpan_singleton] at h rw [h] congr simp only [eq_iff_true_of_subsingleton] #align affine.simplex.circumcenter_eq_point Affine.Simplex.circumcenter_eq_point /-- The circumcenter of a 1-simplex equals its centroid. -/ theorem circumcenter_eq_centroid (s : Simplex ℝ P 1) : s.circumcenter = Finset.univ.centroid ℝ s.points := by have hr : Set.Pairwise Set.univ fun i j : Fin 2 => dist (s.points i) (Finset.univ.centroid ℝ s.points) = dist (s.points j) (Finset.univ.centroid ℝ s.points) := by intro i hi j hj hij rw [Finset.centroid_pair_fin, dist_eq_norm_vsub V (s.points i), dist_eq_norm_vsub V (s.points j), vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, ← one_smul ℝ (s.points i -ᵥ s.points 0), ← one_smul ℝ (s.points j -ᵥ s.points 0)] fin_cases i <;> fin_cases j <;> simp [-one_smul, ← sub_smul] <;> norm_num rw [Set.pairwise_eq_iff_exists_eq] at hr cases' hr with r hr exact (s.eq_circumcenter_of_dist_eq (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (Finset.card_fin 2)) fun i => hr i (Set.mem_univ _)).symm #align affine.simplex.circumcenter_eq_centroid Affine.Simplex.circumcenter_eq_centroid /-- Reindexing a simplex along an `Equiv` of index types does not change the circumsphere. -/ @[simp] theorem circumsphere_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumsphere = s.circumsphere := by refine s.circumsphere_unique_dist_eq.2 _ ⟨?_, ?_⟩ <;> rw [← s.reindex_range_points e] · exact (s.reindex e).circumsphere_unique_dist_eq.1.1 · exact (s.reindex e).circumsphere_unique_dist_eq.1.2 #align affine.simplex.circumsphere_reindex Affine.Simplex.circumsphere_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumcenter. -/ @[simp] theorem circumcenter_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumcenter = s.circumcenter := by simp_rw [circumcenter, circumsphere_reindex] #align affine.simplex.circumcenter_reindex Affine.Simplex.circumcenter_reindex /-- Reindexing a simplex along an `Equiv` of index types does not change the circumradius. -/ @[simp] theorem circumradius_reindex {m n : ℕ} (s : Simplex ℝ P m) (e : Fin (m + 1) ≃ Fin (n + 1)) : (s.reindex e).circumradius = s.circumradius := by simp_rw [circumradius, circumsphere_reindex] #align affine.simplex.circumradius_reindex Affine.Simplex.circumradius_reindex attribute [local instance] AffineSubspace.toAddTorsor /-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/ def orthogonalProjectionSpan {n : ℕ} (s : Simplex ℝ P n) : P →ᵃ[ℝ] affineSpan ℝ (Set.range s.points) := orthogonalProjection (affineSpan ℝ (Set.range s.points)) #align affine.simplex.orthogonal_projection_span Affine.Simplex.orthogonalProjectionSpan /-- Adding a vector to a point in the given subspace, then taking the orthogonal projection, produces the original point if the vector is a multiple of the result of subtracting a point's orthogonal projection from that point. -/ theorem orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (r : ℝ) (hp : p1 ∈ affineSpan ℝ (Set.range s.points)) : s.orthogonalProjectionSpan (r • (p2 -ᵥ s.orthogonalProjectionSpan p2 : V) +ᵥ p1) = ⟨p1, hp⟩ := EuclideanGeometry.orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ #align affine.simplex.orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection {n : ℕ} {r₁ : ℝ} (s : Simplex ℝ P n) {p p₁o : P} (hp₁o : p₁o ∈ affineSpan ℝ (Set.range s.points)) : ↑(s.orthogonalProjectionSpan (r₁ • (p -ᵥ ↑(s.orthogonalProjectionSpan p)) +ᵥ p₁o)) = p₁o := congrArg ((↑) : _ → P) (orthogonalProjection_vadd_smul_vsub_orthogonalProjection _ _ _ hp₁o) #align affine.simplex.coe_orthogonal_projection_vadd_smul_vsub_orthogonal_projection Affine.Simplex.coe_orthogonalProjection_vadd_smul_vsub_orthogonalProjection theorem dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq {n : ℕ} (s : Simplex ℝ P n) {p1 : P} (p2 : P) (hp1 : p1 ∈ affineSpan ℝ (Set.range s.points)) : dist p1 p2 * dist p1 p2 = dist p1 (s.orthogonalProjectionSpan p2) * dist p1 (s.orthogonalProjectionSpan p2) + dist p2 (s.orthogonalProjectionSpan p2) * dist p2 (s.orthogonalProjectionSpan p2) := by rw [PseudoMetricSpace.dist_comm p2 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V p1 _, dist_eq_norm_vsub V _ p2, ← vsub_add_vsub_cancel p1 (s.orthogonalProjectionSpan p2) p2, norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact Submodule.inner_right_of_mem_orthogonal (vsub_orthogonalProjection_mem_direction p2 hp1) (orthogonalProjection_vsub_mem_direction_orthogonal _ p2) #align affine.simplex.dist_sq_eq_dist_orthogonal_projection_sq_add_dist_orthogonal_projection_sq Affine.Simplex.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq theorem dist_circumcenter_sq_eq_sq_sub_circumradius {n : ℕ} {r : ℝ} (s : Simplex ℝ P n) {p₁ : P} (h₁ : ∀ i : Fin (n + 1), dist (s.points i) p₁ = r) (h₁' : ↑(s.orthogonalProjectionSpan p₁) = s.circumcenter) (h : s.points 0 ∈ affineSpan ℝ (Set.range s.points)) : dist p₁ s.circumcenter * dist p₁ s.circumcenter = r * r - s.circumradius * s.circumradius := by rw [dist_comm, ← h₁ 0, s.dist_sq_eq_dist_orthogonalProjection_sq_add_dist_orthogonalProjection_sq p₁ h] simp only [h₁', dist_comm p₁, add_sub_cancel_left, Simplex.dist_circumcenter_eq_circumradius] #align affine.simplex.dist_circumcenter_sq_eq_sq_sub_circumradius Affine.Simplex.dist_circumcenter_sq_eq_sq_sub_circumradius /-- If there exists a distance that a point has from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_exists_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} (hr : ∃ r, ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := by change ∃ r : ℝ, ∀ i, (fun x => dist x p = r) (s.points i) at hr have hr : ∃ (r : ℝ), ∀ (a : P), a ∈ Set.range (fun (i : Fin (n + 1)) => s.points i) → dist a p = r := by cases' hr with r hr use r refine Set.forall_mem_range.mpr ?_ exact hr rw [exists_dist_eq_iff_exists_dist_orthogonalProjection_eq (subset_affineSpan ℝ _) p] at hr cases' hr with r hr exact s.eq_circumcenter_of_dist_eq (orthogonalProjection_mem p) fun i => hr _ (Set.mem_range_self i) #align affine.simplex.orthogonal_projection_eq_circumcenter_of_exists_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_exists_dist_eq /-- If a point has the same distance from all vertices of a simplex, the orthogonal projection of that point onto the subspace spanned by that simplex is its circumcenter. -/ theorem orthogonalProjection_eq_circumcenter_of_dist_eq {n : ℕ} (s : Simplex ℝ P n) {p : P} {r : ℝ} (hr : ∀ i, dist (s.points i) p = r) : ↑(s.orthogonalProjectionSpan p) = s.circumcenter := s.orthogonalProjection_eq_circumcenter_of_exists_dist_eq ⟨r, hr⟩ #align affine.simplex.orthogonal_projection_eq_circumcenter_of_dist_eq Affine.Simplex.orthogonalProjection_eq_circumcenter_of_dist_eq /-- The orthogonal projection of the circumcenter onto a face is the circumcenter of that face. -/ theorem orthogonalProjection_circumcenter {n : ℕ} (s : Simplex ℝ P n) {fs : Finset (Fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : ↑((s.face h).orthogonalProjectionSpan s.circumcenter) = (s.face h).circumcenter := haveI hr : ∃ r, ∀ i, dist ((s.face h).points i) s.circumcenter = r := by use s.circumradius simp [face_points] orthogonalProjection_eq_circumcenter_of_exists_dist_eq _ hr #align affine.simplex.orthogonal_projection_circumcenter Affine.Simplex.orthogonalProjection_circumcenter /-- Two simplices with the same points have the same circumcenter. -/ theorem circumcenter_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.circumcenter = s₂.circumcenter := by have hs : s₁.circumcenter ∈ affineSpan ℝ (Set.range s₂.points) := h ▸ s₁.circumcenter_mem_affineSpan have hr : ∀ i, dist (s₂.points i) s₁.circumcenter = s₁.circumradius := by intro i have hi : s₂.points i ∈ Set.range s₂.points := Set.mem_range_self _ rw [← h, Set.mem_range] at hi rcases hi with ⟨j, hj⟩ rw [← hj, s₁.dist_circumcenter_eq_circumradius j] exact s₂.eq_circumcenter_of_dist_eq hs hr #align affine.simplex.circumcenter_eq_of_range_eq Affine.Simplex.circumcenter_eq_of_range_eq /-- An index type for the vertices of a simplex plus its circumcenter. This is for use in calculations where it is convenient to work with affine combinations of vertices together with the circumcenter. (An equivalent form sometimes used in the literature is placing the circumcenter at the origin and working with vectors for the vertices.) -/ inductive PointsWithCircumcenterIndex (n : ℕ) | pointIndex : Fin (n + 1) → PointsWithCircumcenterIndex n | circumcenterIndex : PointsWithCircumcenterIndex n deriving Fintype #align affine.simplex.points_with_circumcenter_index Affine.Simplex.PointsWithCircumcenterIndex open PointsWithCircumcenterIndex instance pointsWithCircumcenterIndexInhabited (n : ℕ) : Inhabited (PointsWithCircumcenterIndex n) := ⟨circumcenterIndex⟩ #align affine.simplex.points_with_circumcenter_index_inhabited Affine.Simplex.pointsWithCircumcenterIndexInhabited /-- `pointIndex` as an embedding. -/ def pointIndexEmbedding (n : ℕ) : Fin (n + 1) ↪ PointsWithCircumcenterIndex n := ⟨fun i => pointIndex i, fun _ _ h => by injection h⟩ #align affine.simplex.point_index_embedding Affine.Simplex.pointIndexEmbedding /-- The sum of a function over `PointsWithCircumcenterIndex`. -/ theorem sum_pointsWithCircumcenter {α : Type*} [AddCommMonoid α] {n : ℕ} (f : PointsWithCircumcenterIndex n → α) : ∑ i, f i = (∑ i : Fin (n + 1), f (pointIndex i)) + f circumcenterIndex := by have h : univ = insert circumcenterIndex (univ.map (pointIndexEmbedding n)) := by ext x refine ⟨fun h => ?_, fun _ => mem_univ _⟩ cases' x with i · exact mem_insert_of_mem (mem_map_of_mem _ (mem_univ i)) · exact mem_insert_self _ _ change _ = (∑ i, f (pointIndexEmbedding n i)) + _ rw [add_comm, h, ← sum_map, sum_insert] simp_rw [Finset.mem_map, not_exists] rintro x ⟨_, h⟩ injection h #align affine.simplex.sum_points_with_circumcenter Affine.Simplex.sum_pointsWithCircumcenter /-- The vertices of a simplex plus its circumcenter. -/ def pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) : PointsWithCircumcenterIndex n → P | pointIndex i => s.points i | circumcenterIndex => s.circumcenter #align affine.simplex.points_with_circumcenter Affine.Simplex.pointsWithCircumcenter /-- `pointsWithCircumcenter`, applied to a `pointIndex` value, equals `points` applied to that value. -/ @[simp] theorem pointsWithCircumcenter_point {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.pointsWithCircumcenter (pointIndex i) = s.points i := rfl #align affine.simplex.points_with_circumcenter_point Affine.Simplex.pointsWithCircumcenter_point /-- `pointsWithCircumcenter`, applied to `circumcenterIndex`, equals the circumcenter. -/ @[simp] theorem pointsWithCircumcenter_eq_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.pointsWithCircumcenter circumcenterIndex = s.circumcenter := rfl #align affine.simplex.points_with_circumcenter_eq_circumcenter Affine.Simplex.pointsWithCircumcenter_eq_circumcenter /-- The weights for a single vertex of a simplex, in terms of `pointsWithCircumcenter`. -/ def pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : PointsWithCircumcenterIndex n → ℝ | pointIndex j => if j = i then 1 else 0 | circumcenterIndex => 0 #align affine.simplex.point_weights_with_circumcenter Affine.Simplex.pointWeightsWithCircumcenter /-- `point_weights_with_circumcenter` sums to 1. -/ @[simp] theorem sum_pointWeightsWithCircumcenter {n : ℕ} (i : Fin (n + 1)) : ∑ j, pointWeightsWithCircumcenter i j = 1 := by convert sum_ite_eq' univ (pointIndex i) (Function.const _ (1 : ℝ)) with j · cases j <;> simp [pointWeightsWithCircumcenter] · simp #align affine.simplex.sum_point_weights_with_circumcenter Affine.Simplex.sum_pointWeightsWithCircumcenter /-- A single vertex, in terms of `pointsWithCircumcenter`. -/ theorem point_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P n) (i : Fin (n + 1)) : s.points i = (univ : Finset (PointsWithCircumcenterIndex n)).affineCombination ℝ s.pointsWithCircumcenter (pointWeightsWithCircumcenter i) := by rw [← pointsWithCircumcenter_point] symm refine affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_univ _) (by simp [pointWeightsWithCircumcenter]) ?_ intro i hi hn cases i · have h : _ ≠ i := fun h => hn (h ▸ rfl) simp [pointWeightsWithCircumcenter, h] · rfl #align affine.simplex.point_eq_affine_combination_of_points_with_circumcenter Affine.Simplex.point_eq_affineCombination_of_pointsWithCircumcenter /-- The weights for the centroid of some vertices of a simplex, in terms of `pointsWithCircumcenter`. -/ def centroidWeightsWithCircumcenter {n : ℕ} (fs : Finset (Fin (n + 1))) : PointsWithCircumcenterIndex n → ℝ | pointIndex i => if i ∈ fs then (card fs : ℝ)⁻¹ else 0 | circumcenterIndex => 0 #align affine.simplex.centroid_weights_with_circumcenter Affine.Simplex.centroidWeightsWithCircumcenter /-- `centroidWeightsWithCircumcenter` sums to 1, if the `Finset` is nonempty. -/ @[simp]
Mathlib/Geometry/Euclidean/Circumcenter.lean
615
619
theorem sum_centroidWeightsWithCircumcenter {n : ℕ} {fs : Finset (Fin (n + 1))} (h : fs.Nonempty) : ∑ i, centroidWeightsWithCircumcenter fs i = 1 := by
simp_rw [sum_pointsWithCircumcenter, centroidWeightsWithCircumcenter, add_zero, ← fs.sum_centroidWeights_eq_one_of_nonempty ℝ h, ← sum_indicator_subset _ fs.subset_univ] rcongr
/- Copyright (c) 2023 Dagur Asgeirsson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson -/ import Mathlib.Algebra.Category.ModuleCat.Free import Mathlib.Topology.Category.Profinite.CofilteredLimit import Mathlib.Topology.Category.Profinite.Product import Mathlib.Topology.LocallyConstant.Algebra import Mathlib.Init.Data.Bool.Lemmas /-! # Nöbeling's theorem This file proves Nöbeling's theorem. ## Main result * `LocallyConstant.freeOfProfinite`: Nöbeling's theorem. For `S : Profinite`, the `ℤ`-module `LocallyConstant S ℤ` is free. ## Proof idea We follow the proof of theorem 5.4 in [scholze2019condensed], in which the idea is to embed `S` in a product of `I` copies of `Bool` for some sufficiently large `I`, and then to choose a well-ordering on `I` and use ordinal induction over that well-order. Here we can let `I` be the set of clopen subsets of `S` since `S` is totally separated. The above means it suffices to prove the following statement: For a closed subset `C` of `I → Bool`, the `ℤ`-module `LocallyConstant C ℤ` is free. For `i : I`, let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. The basis will consist of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. We call this set `GoodProducts C` What is proved by ordinal induction is that this set is linearly independent. The fact that it spans can be proved directly. ## References - [scholze2019condensed], Theorem 5.4. -/ universe u namespace Profinite namespace NobelingProof variable {I : Type u} [LinearOrder I] [IsWellOrder I (·<·)] (C : Set (I → Bool)) open Profinite ContinuousMap CategoryTheory Limits Opposite Submodule section Projections /-! ## Projection maps The purpose of this section is twofold. Firstly, in the proof that the set `GoodProducts C` spans the whole module `LocallyConstant C ℤ`, we need to project `C` down to finite discrete subsets and write `C` as a cofiltered limit of those. Secondly, in the inductive argument, we need to project `C` down to "smaller" sets satisfying the inductive hypothesis. In this section we define the relevant projection maps and prove some compatibility results. ### Main definitions * Let `J : I → Prop`. Then `Proj J : (I → Bool) → (I → Bool)` is the projection mapping everything that satisfies `J i` to itself, and everything else to `false`. * The image of `C` under `Proj J` is denoted `π C J` and the corresponding map `C → π C J` is called `ProjRestrict`. If `J` implies `K` we have a map `ProjRestricts : π C K → π C J`. * `spanCone_isLimit` establishes that when `C` is compact, it can be written as a limit of its images under the maps `Proj (· ∈ s)` where `s : Finset I`. -/ variable (J K L : I → Prop) [∀ i, Decidable (J i)] [∀ i, Decidable (K i)] [∀ i, Decidable (L i)] /-- The projection mapping everything that satisfies `J i` to itself, and everything else to `false` -/ def Proj : (I → Bool) → (I → Bool) := fun c i ↦ if J i then c i else false @[simp] theorem continuous_proj : Continuous (Proj J : (I → Bool) → (I → Bool)) := by dsimp (config := { unfoldPartialApp := true }) [Proj] apply continuous_pi intro i split · apply continuous_apply · apply continuous_const /-- The image of `Proj π J` -/ def π : Set (I → Bool) := (Proj J) '' C /-- The restriction of `Proj π J` to a subset, mapping to its image. -/ @[simps!] def ProjRestrict : C → π C J := Set.MapsTo.restrict (Proj J) _ _ (Set.mapsTo_image _ _) @[simp] theorem continuous_projRestrict : Continuous (ProjRestrict C J) := Continuous.restrict _ (continuous_proj _) theorem proj_eq_self {x : I → Bool} (h : ∀ i, x i ≠ false → J i) : Proj J x = x := by ext i simp only [Proj, ite_eq_left_iff] contrapose! simpa only [ne_comm] using h i theorem proj_prop_eq_self (hh : ∀ i x, x ∈ C → x i ≠ false → J i) : π C J = C := by ext x refine ⟨fun ⟨y, hy, h⟩ ↦ ?_, fun h ↦ ⟨x, h, ?_⟩⟩ · rwa [← h, proj_eq_self]; exact (hh · y hy) · rw [proj_eq_self]; exact (hh · x h) theorem proj_comp_of_subset (h : ∀ i, J i → K i) : (Proj J ∘ Proj K) = (Proj J : (I → Bool) → (I → Bool)) := by ext x i; dsimp [Proj]; aesop theorem proj_eq_of_subset (h : ∀ i, J i → K i) : π (π C K) J = π C J := by ext x refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · obtain ⟨y, ⟨z, hz, rfl⟩, rfl⟩ := h refine ⟨z, hz, (?_ : _ = (Proj J ∘ Proj K) z)⟩ rw [proj_comp_of_subset J K h] · obtain ⟨y, hy, rfl⟩ := h dsimp [π] rw [← Set.image_comp] refine ⟨y, hy, ?_⟩ rw [proj_comp_of_subset J K h] variable {J K L} /-- A variant of `ProjRestrict` with domain of the form `π C K` -/ @[simps!] def ProjRestricts (h : ∀ i, J i → K i) : π C K → π C J := Homeomorph.setCongr (proj_eq_of_subset C J K h) ∘ ProjRestrict (π C K) J @[simp] theorem continuous_projRestricts (h : ∀ i, J i → K i) : Continuous (ProjRestricts C h) := Continuous.comp (Homeomorph.continuous _) (continuous_projRestrict _ _) theorem surjective_projRestricts (h : ∀ i, J i → K i) : Function.Surjective (ProjRestricts C h) := (Homeomorph.surjective _).comp (Set.surjective_mapsTo_image_restrict _ _) variable (J) in theorem projRestricts_eq_id : ProjRestricts C (fun i (h : J i) ↦ h) = id := by ext ⟨x, y, hy, rfl⟩ i simp (config := { contextual := true }) only [π, Proj, ProjRestricts_coe, id_eq, if_true] theorem projRestricts_eq_comp (hJK : ∀ i, J i → K i) (hKL : ∀ i, K i → L i) : ProjRestricts C hJK ∘ ProjRestricts C hKL = ProjRestricts C (fun i ↦ hKL i ∘ hJK i) := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe] aesop theorem projRestricts_comp_projRestrict (h : ∀ i, J i → K i) : ProjRestricts C h ∘ ProjRestrict C K = ProjRestrict C J := by ext x i simp only [π, Proj, Function.comp_apply, ProjRestricts_coe, ProjRestrict_coe] aesop variable (J) /-- The objectwise map in the isomorphism `spanFunctor ≅ Profinite.indexFunctor`. -/ def iso_map : C(π C J, (IndexFunctor.obj C J)) := ⟨fun x ↦ ⟨fun i ↦ x.val i.val, by rcases x with ⟨x, y, hy, rfl⟩ refine ⟨y, hy, ?_⟩ ext ⟨i, hi⟩ simp [precomp, Proj, hi]⟩, by refine Continuous.subtype_mk (continuous_pi fun i ↦ ?_) _ exact (continuous_apply i.val).comp continuous_subtype_val⟩ lemma iso_map_bijective : Function.Bijective (iso_map C J) := by refine ⟨fun a b h ↦ ?_, fun a ↦ ?_⟩ · ext i rw [Subtype.ext_iff] at h by_cases hi : J i · exact congr_fun h ⟨i, hi⟩ · rcases a with ⟨_, c, hc, rfl⟩ rcases b with ⟨_, d, hd, rfl⟩ simp only [Proj, if_neg hi] · refine ⟨⟨fun i ↦ if hi : J i then a.val ⟨i, hi⟩ else false, ?_⟩, ?_⟩ · rcases a with ⟨_, y, hy, rfl⟩ exact ⟨y, hy, rfl⟩ · ext i exact dif_pos i.prop variable {C} (hC : IsCompact C) /-- For a given compact subset `C` of `I → Bool`, `spanFunctor` is the functor from the poset of finsets of `I` to `Profinite`, sending a finite subset set `J` to the image of `C` under the projection `Proj J`. -/ noncomputable def spanFunctor [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : (Finset I)ᵒᵖ ⥤ Profinite.{u} where obj s := @Profinite.of (π C (· ∈ (unop s))) _ (by rw [← isCompact_iff_compactSpace]; exact hC.image (continuous_proj _)) _ _ map h := ⟨(ProjRestricts C (leOfHom h.unop)), continuous_projRestricts _ _⟩ map_id J := by simp only [projRestricts_eq_id C (· ∈ (unop J))]; rfl map_comp _ _ := by dsimp; congr; dsimp; rw [projRestricts_eq_comp] /-- The limit cone on `spanFunctor` with point `C`. -/ noncomputable def spanCone [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : Cone (spanFunctor hC) where pt := @Profinite.of C _ (by rwa [← isCompact_iff_compactSpace]) _ _ π := { app := fun s ↦ ⟨ProjRestrict C (· ∈ unop s), continuous_projRestrict _ _⟩ naturality := by intro X Y h simp only [Functor.const_obj_obj, Homeomorph.setCongr, Homeomorph.homeomorph_mk_coe, Functor.const_obj_map, Category.id_comp, ← projRestricts_comp_projRestrict C (leOfHom h.unop)] rfl } /-- `spanCone` is a limit cone. -/ noncomputable def spanCone_isLimit [∀ (s : Finset I) (i : I), Decidable (i ∈ s)] : CategoryTheory.Limits.IsLimit (spanCone hC) := by refine (IsLimit.postcomposeHomEquiv (NatIso.ofComponents (fun s ↦ (Profinite.isoOfBijective _ (iso_map_bijective C (· ∈ unop s)))) ?_) (spanCone hC)) (IsLimit.ofIsoLimit (indexCone_isLimit hC) (Cones.ext (Iso.refl _) ?_)) · intro ⟨s⟩ ⟨t⟩ ⟨⟨⟨f⟩⟩⟩ ext x have : iso_map C (· ∈ t) ∘ ProjRestricts C f = IndexFunctor.map C f ∘ iso_map C (· ∈ s) := by ext _ i; exact dif_pos i.prop exact congr_fun this x · intro ⟨s⟩ ext x have : iso_map C (· ∈ s) ∘ ProjRestrict C (· ∈ s) = IndexFunctor.π_app C (· ∈ s) := by ext _ i; exact dif_pos i.prop erw [← this] rfl end Projections section Products /-! ## Defining the basis Our proposed basis consists of products `e C iᵣ * ⋯ * e C i₁` with `iᵣ > ⋯ > i₁` which cannot be written as linear combinations of lexicographically smaller products. See below for the definition of `e`. ### Main definitions * For `i : I`, we let `e C i : LocallyConstant C ℤ` denote the map `fun f ↦ (if f.val i then 1 else 0)`. * `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂,..., iᵣ]` with `i₁ > i₂ > ... > iᵣ`. * `Products.eval C` is the `C`-evaluation of a list. It takes a term `[i₁, i₂,..., iᵣ] : Products I` and returns the actual product `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ`. * `GoodProducts C` is the set of `Products I` such that their `C`-evaluation cannot be written as a linear combination of evaluations of lexicographically smaller lists. ### Main results * `Products.evalFacProp` and `Products.evalFacProps` establish the fact that `Products.eval`  interacts nicely with the projection maps from the previous section. * `GoodProducts.span_iff_products`: the good products span `LocallyConstant C ℤ` iff all the products span `LocallyConstant C ℤ`. -/ /-- `e C i` is the locally constant map from `C : Set (I → Bool)` to `ℤ` sending `f` to 1 if `f.val i = true`, and 0 otherwise. -/ def e (i : I) : LocallyConstant C ℤ where toFun := fun f ↦ (if f.val i then 1 else 0) isLocallyConstant := by rw [IsLocallyConstant.iff_continuous] exact (continuous_of_discreteTopology (f := fun (a : Bool) ↦ (if a then (1 : ℤ) else 0))).comp ((continuous_apply i).comp continuous_subtype_val) /-- `Products I` is the type of lists of decreasing elements of `I`, so a typical element is `[i₁, i₂, ...]` with `i₁ > i₂ > ...`. We order `Products I` lexicographically, so `[] < [i₁, ...]`, and `[i₁, i₂, ...] < [j₁, j₂, ...]` if either `i₁ < j₁`, or `i₁ = j₁` and `[i₂, ...] < [j₂, ...]`. Terms `m = [i₁, i₂, ..., iᵣ]` of this type will be used to represent products of the form `e C i₁ ··· e C iᵣ : LocallyConstant C ℤ` . The function associated to `m` is `m.eval`. -/ def Products (I : Type*) [LinearOrder I] := {l : List I // l.Chain' (·>·)} namespace Products instance : LinearOrder (Products I) := inferInstanceAs (LinearOrder {l : List I // l.Chain' (·>·)}) @[simp] theorem lt_iff_lex_lt (l m : Products I) : l < m ↔ List.Lex (·<·) l.val m.val := by cases l; cases m; rw [Subtype.mk_lt_mk]; exact Iff.rfl instance : IsWellFounded (Products I) (·<·) := by have : (· < · : Products I → _ → _) = (fun l m ↦ List.Lex (·<·) l.val m.val) := by ext; exact lt_iff_lex_lt _ _ rw [this] dsimp [Products] rw [(by rfl : (·>· : I → _) = flip (·<·))] infer_instance /-- The evaluation `e C i₁ ··· e C iᵣ : C → ℤ` of a formal product `[i₁, i₂, ..., iᵣ]`. -/ def eval (l : Products I) := (l.1.map (e C)).prod /-- The predicate on products which we prove picks out a basis of `LocallyConstant C ℤ`. We call such a product "good". -/ def isGood (l : Products I) : Prop := l.eval C ∉ Submodule.span ℤ ((Products.eval C) '' {m | m < l}) theorem rel_head!_of_mem [Inhabited I] {i : I} {l : Products I} (hi : i ∈ l.val) : i ≤ l.val.head! := List.Sorted.le_head! (List.chain'_iff_pairwise.mp l.prop) hi theorem head!_le_of_lt [Inhabited I] {q l : Products I} (h : q < l) (hq : q.val ≠ []) : q.val.head! ≤ l.val.head! := List.head!_le_of_lt l.val q.val h hq end Products /-- The set of good products. -/ def GoodProducts := {l : Products I | l.isGood C} namespace GoodProducts /-- Evaluation of good products. -/ def eval (l : {l : Products I // l.isGood C}) : LocallyConstant C ℤ := Products.eval C l.1 theorem injective : Function.Injective (eval C) := by intro ⟨a, ha⟩ ⟨b, hb⟩ h dsimp [eval] at h rcases lt_trichotomy a b with (h'|rfl|h') · exfalso; apply hb; rw [← h] exact Submodule.subset_span ⟨a, h', rfl⟩ · rfl · exfalso; apply ha; rw [h] exact Submodule.subset_span ⟨b, ⟨h',rfl⟩⟩ /-- The image of the good products in the module `LocallyConstant C ℤ`. -/ def range := Set.range (GoodProducts.eval C) /-- The type of good products is equivalent to its image. -/ noncomputable def equiv_range : GoodProducts C ≃ range C := Equiv.ofInjective (eval C) (injective C) theorem equiv_toFun_eq_eval : (equiv_range C).toFun = Set.rangeFactorization (eval C) := rfl theorem linearIndependent_iff_range : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : range C) ↦ p.1) := by rw [← @Set.rangeFactorization_eq _ _ (GoodProducts.eval C), ← equiv_toFun_eq_eval C] exact linearIndependent_equiv (equiv_range C) end GoodProducts namespace Products theorem eval_eq (l : Products I) (x : C) : l.eval C x = if ∀ i, i ∈ l.val → (x.val i = true) then 1 else 0 := by change LocallyConstant.evalMonoidHom x (l.eval C) = _ rw [eval, map_list_prod] split_ifs with h · simp only [List.map_map] apply List.prod_eq_one simp only [List.mem_map, Function.comp_apply] rintro _ ⟨i, hi, rfl⟩ exact if_pos (h i hi) · simp only [List.map_map, List.prod_eq_zero_iff, List.mem_map, Function.comp_apply] push_neg at h convert h with i dsimp [LocallyConstant.evalMonoidHom, e] simp only [ite_eq_right_iff, one_ne_zero] theorem evalFacProp {l : Products I} (J : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] : l.eval (π C J) ∘ ProjRestrict C J = l.eval C := by ext x dsimp [ProjRestrict] rw [Products.eval_eq, Products.eval_eq] congr apply forall_congr; intro i apply forall_congr; intro hi simp [h i hi, Proj] theorem evalFacProps {l : Products I} (J K : I → Prop) (h : ∀ a, a ∈ l.val → J a) [∀ j, Decidable (J j)] [∀ j, Decidable (K j)] (hJK : ∀ i, J i → K i) : l.eval (π C J) ∘ ProjRestricts C hJK = l.eval (π C K) := by have : l.eval (π C J) ∘ Homeomorph.setCongr (proj_eq_of_subset C J K hJK) = l.eval (π (π C K) J) := by ext; simp [Homeomorph.setCongr, Products.eval_eq] rw [ProjRestricts, ← Function.comp.assoc, this, ← evalFacProp (π C K) J h] theorem prop_of_isGood {l : Products I} (J : I → Prop) [∀ j, Decidable (J j)] (h : l.isGood (π C J)) : ∀ a, a ∈ l.val → J a := by intro i hi by_contra h' apply h suffices eval (π C J) l = 0 by rw [this] exact Submodule.zero_mem _ ext ⟨_, _, _, rfl⟩ rw [eval_eq, if_neg fun h ↦ ?_, LocallyConstant.zero_apply] simpa [Proj, h'] using h i hi end Products /-- The good products span `LocallyConstant C ℤ` if and only all the products do. -/ theorem GoodProducts.span_iff_products : ⊤ ≤ span ℤ (Set.range (eval C)) ↔ ⊤ ≤ span ℤ (Set.range (Products.eval C)) := by refine ⟨fun h ↦ le_trans h (span_mono (fun a ⟨b, hb⟩ ↦ ⟨b.val, hb⟩)), fun h ↦ le_trans h ?_⟩ rw [span_le] rintro f ⟨l, rfl⟩ let L : Products I → Prop := fun m ↦ m.eval C ∈ span ℤ (Set.range (GoodProducts.eval C)) suffices L l by assumption apply IsWellFounded.induction (·<· : Products I → Products I → Prop) intro l h dsimp by_cases hl : l.isGood C · apply subset_span exact ⟨⟨l, hl⟩, rfl⟩ · simp only [Products.isGood, not_not] at hl suffices Products.eval C '' {m | m < l} ⊆ span ℤ (Set.range (GoodProducts.eval C)) by rw [← span_le] at this exact this hl rintro a ⟨m, hm, rfl⟩ exact h m hm end Products section Span /-! ## The good products span Most of the argument is developing an API for `π C (· ∈ s)` when `s : Finset I`; then the image of `C` is finite with the discrete topology. In this case, there is a direct argument that the good products span. The general result is deduced from this. ### Main theorems * `GoodProducts.spanFin` : The good products span the locally constant functions on `π C (· ∈ s)` if `s` is finite. * `GoodProducts.span` : The good products span `LocallyConstant C ℤ` for every closed subset `C`. -/ section Fin variable (s : Finset I) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (· ∈ s)`. -/ noncomputable def πJ : LocallyConstant (π C (· ∈ s)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨_, (continuous_projRestrict C (· ∈ s))⟩ theorem eval_eq_πJ (l : Products I) (hl : l.isGood (π C (· ∈ s))) : l.eval C = πJ C s (l.eval (π C (· ∈ s))) := by ext f simp only [πJ, LocallyConstant.comapₗ, LinearMap.coe_mk, AddHom.coe_mk, (continuous_projRestrict C (· ∈ s)), LocallyConstant.coe_comap, Function.comp_apply] exact (congr_fun (Products.evalFacProp C (· ∈ s) (Products.prop_of_isGood C (· ∈ s) hl)) _).symm /-- `π C (· ∈ s)` is finite for a finite set `s`. -/ noncomputable instance : Fintype (π C (· ∈ s)) := by let f : π C (· ∈ s) → (s → Bool) := fun x j ↦ x.val j.val refine Fintype.ofInjective f ?_ intro ⟨_, x, hx, rfl⟩ ⟨_, y, hy, rfl⟩ h ext i by_cases hi : i ∈ s · exact congrFun h ⟨i, hi⟩ · simp only [Proj, if_neg hi] open scoped Classical in /-- The Kronecker delta as a locally constant map from `π C (· ∈ s)` to `ℤ`. -/ noncomputable def spanFinBasis (x : π C (· ∈ s)) : LocallyConstant (π C (· ∈ s)) ℤ where toFun := fun y ↦ if y = x then 1 else 0 isLocallyConstant := haveI : DiscreteTopology (π C (· ∈ s)) := discrete_of_t1_of_finite IsLocallyConstant.of_discrete _ open scoped Classical in theorem spanFinBasis.span : ⊤ ≤ Submodule.span ℤ (Set.range (spanFinBasis C s)) := by intro f _ rw [Finsupp.mem_span_range_iff_exists_finsupp] use Finsupp.onFinset (Finset.univ) f.toFun (fun _ _ ↦ Finset.mem_univ _) ext x change LocallyConstant.evalₗ ℤ x _ = _ simp only [zsmul_eq_mul, map_finsupp_sum, LocallyConstant.evalₗ_apply, LocallyConstant.coe_mul, Pi.mul_apply, spanFinBasis, LocallyConstant.coe_mk, mul_ite, mul_one, mul_zero, Finsupp.sum_ite_eq, Finsupp.mem_support_iff, ne_eq, ite_not] split_ifs with h <;> [exact h.symm; rfl] /-- A certain explicit list of locally constant maps. The theorem `factors_prod_eq_basis` shows that the product of the elements in this list is the delta function `spanFinBasis C s x`. -/ def factors (x : π C (· ∈ s)) : List (LocallyConstant (π C (· ∈ s)) ℤ) := List.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i))) (s.sort (·≥·)) theorem list_prod_apply (x : C) (l : List (LocallyConstant C ℤ)) : l.prod x = (l.map (LocallyConstant.evalMonoidHom x)).prod := by rw [← map_list_prod (LocallyConstant.evalMonoidHom x) l] rfl theorem factors_prod_eq_basis_of_eq {x y : (π C fun x ↦ x ∈ s)} (h : y = x) : (factors C s x).prod y = 1 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_one simp only [h, List.mem_map, LocallyConstant.evalMonoidHom, factors] rintro _ ⟨a, ⟨b, _, rfl⟩, rfl⟩ dsimp split_ifs with hh · rw [e, LocallyConstant.coe_mk, if_pos hh] · rw [LocallyConstant.sub_apply, e, LocallyConstant.coe_mk, LocallyConstant.coe_mk, if_neg hh] simp only [LocallyConstant.toFun_eq_coe, LocallyConstant.coe_one, Pi.one_apply, sub_zero] theorem e_mem_of_eq_true {x : (π C (· ∈ s))} {a : I} (hx : x.val a = true) : e (π C (· ∈ s)) a ∈ factors C s x := by rcases x with ⟨_, z, hz, rfl⟩ simp only [factors, List.mem_map, Finset.mem_sort] refine ⟨a, ?_, if_pos hx⟩ aesop (add simp Proj) theorem one_sub_e_mem_of_false {x y : (π C (· ∈ s))} {a : I} (ha : y.val a = true) (hx : x.val a = false) : 1 - e (π C (· ∈ s)) a ∈ factors C s x := by simp only [factors, List.mem_map, Finset.mem_sort] use a simp only [hx, ite_false, and_true] rcases y with ⟨_, z, hz, rfl⟩ aesop (add simp Proj) theorem factors_prod_eq_basis_of_ne {x y : (π C (· ∈ s))} (h : y ≠ x) : (factors C s x).prod y = 0 := by rw [list_prod_apply (π C (· ∈ s)) y _] apply List.prod_eq_zero simp only [List.mem_map] obtain ⟨a, ha⟩ : ∃ a, y.val a ≠ x.val a := by contrapose! h; ext; apply h cases hx : x.val a · rw [hx, ne_eq, Bool.not_eq_false] at ha refine ⟨1 - (e (π C (· ∈ s)) a), ⟨one_sub_e_mem_of_false _ _ ha hx, ?_⟩⟩ rw [e, LocallyConstant.evalMonoidHom_apply, LocallyConstant.sub_apply, LocallyConstant.coe_one, Pi.one_apply, LocallyConstant.coe_mk, if_pos ha, sub_self] · refine ⟨e (π C (· ∈ s)) a, ⟨e_mem_of_eq_true _ _ hx, ?_⟩⟩ rw [hx] at ha rw [LocallyConstant.evalMonoidHom_apply, e, LocallyConstant.coe_mk, if_neg ha] /-- If `s` is finite, the product of the elements of the list `factors C s x` is the delta function at `x`. -/ theorem factors_prod_eq_basis (x : π C (· ∈ s)) : (factors C s x).prod = spanFinBasis C s x := by ext y dsimp [spanFinBasis] split_ifs with h <;> [exact factors_prod_eq_basis_of_eq _ _ h; exact factors_prod_eq_basis_of_ne _ _ h] theorem GoodProducts.finsupp_sum_mem_span_eval {a : I} {as : List I} (ha : List.Chain' (· > ·) (a :: as)) {c : Products I →₀ ℤ} (hc : (c.support : Set (Products I)) ⊆ {m | m.val ≤ as}) : (Finsupp.sum c fun a_1 b ↦ e (π C (· ∈ s)) a * b • Products.eval (π C (· ∈ s)) a_1) ∈ Submodule.span ℤ (Products.eval (π C (· ∈ s)) '' {m | m.val ≤ a :: as}) := by apply Submodule.finsupp_sum_mem intro m hm have hsm := (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)).map_smul dsimp at hsm rw [hsm] apply Submodule.smul_mem apply Submodule.subset_span have hmas : m.val ≤ as := by apply hc simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm refine ⟨⟨a :: m.val, ha.cons_of_le m.prop hmas⟩, ⟨List.cons_le_cons a hmas, ?_⟩⟩ simp only [Products.eval, List.map, List.prod_cons] /-- If `s` is a finite subset of `I`, then the good products span. -/ theorem GoodProducts.spanFin : ⊤ ≤ Submodule.span ℤ (Set.range (eval (π C (· ∈ s)))) := by rw [span_iff_products] refine le_trans (spanFinBasis.span C s) ?_ rw [Submodule.span_le] rintro _ ⟨x, rfl⟩ rw [← factors_prod_eq_basis] let l := s.sort (·≥·) dsimp [factors] suffices l.Chain' (·>·) → (l.map (fun i ↦ if x.val i = true then e (π C (· ∈ s)) i else (1 - (e (π C (· ∈ s)) i)))).prod ∈ Submodule.span ℤ ((Products.eval (π C (· ∈ s))) '' {m | m.val ≤ l}) from Submodule.span_mono (Set.image_subset_range _ _) (this (Finset.sort_sorted_gt _).chain') induction l with | nil => intro _ apply Submodule.subset_span exact ⟨⟨[], List.chain'_nil⟩,⟨Or.inl rfl, rfl⟩⟩ | cons a as ih => rw [List.map_cons, List.prod_cons] intro ha specialize ih (by rw [List.chain'_cons'] at ha; exact ha.2) rw [Finsupp.mem_span_image_iff_total] at ih simp only [Finsupp.mem_supported, Finsupp.total_apply] at ih obtain ⟨c, hc, hc'⟩ := ih rw [← hc']; clear hc' have hmap := fun g ↦ map_finsupp_sum (LinearMap.mulLeft ℤ (e (π C (· ∈ s)) a)) c g dsimp at hmap ⊢ split_ifs · rw [hmap] exact finsupp_sum_mem_span_eval _ _ ha hc · ring_nf rw [hmap] apply Submodule.add_mem · apply Submodule.neg_mem exact finsupp_sum_mem_span_eval _ _ ha hc · apply Submodule.finsupp_sum_mem intro m hm apply Submodule.smul_mem apply Submodule.subset_span refine ⟨m, ⟨?_, rfl⟩⟩ simp only [Set.mem_setOf_eq] have hmas : m.val ≤ as := hc (by simpa only [Finset.mem_coe, Finsupp.mem_support_iff] using hm) refine le_trans hmas ?_ cases as with | nil => exact (List.nil_lt_cons a []).le | cons b bs => apply le_of_lt rw [List.chain'_cons] at ha have hlex := List.lt.head bs (b :: bs) ha.1 exact (List.lt_iff_lex_lt _ _).mp hlex end Fin theorem fin_comap_jointlySurjective (hC : IsClosed C) (f : LocallyConstant C ℤ) : ∃ (s : Finset I) (g : LocallyConstant (π C (· ∈ s)) ℤ), f = g.comap ⟨(ProjRestrict C (· ∈ s)), continuous_projRestrict _ _⟩ := by obtain ⟨J, g, h⟩ := @Profinite.exists_locallyConstant.{0, u, u} (Finset I)ᵒᵖ _ _ _ (spanCone hC.isCompact) ℤ (spanCone_isLimit hC.isCompact) f exact ⟨(Opposite.unop J), g, h⟩ /-- The good products span all of `LocallyConstant C ℤ` if `C` is closed. -/ theorem GoodProducts.span (hC : IsClosed C) : ⊤ ≤ Submodule.span ℤ (Set.range (eval C)) := by rw [span_iff_products] intro f _ obtain ⟨K, f', rfl⟩ : ∃ K f', f = πJ C K f' := fin_comap_jointlySurjective C hC f refine Submodule.span_mono ?_ <| Submodule.apply_mem_span_image_of_mem_span (πJ C K) <| spanFin C K (Submodule.mem_top : f' ∈ ⊤) rintro l ⟨y, ⟨m, rfl⟩, rfl⟩ exact ⟨m.val, eval_eq_πJ C K m.val m.prop⟩ end Span section Ordinal /-! ## Relating elements of the well-order `I` with ordinals We choose a well-ordering on `I`. This amounts to regarding `I` as an ordinal, and as such it can be regarded as the set of all strictly smaller ordinals, allowing to apply ordinal induction. ### Main definitions * `ord I i` is the term `i` of `I` regarded as an ordinal. * `term I ho` is a sufficiently small ordinal regarded as a term of `I`. * `contained C o` is a predicate saying that `C` is "small" enough in relation to the ordinal `o` to satisfy the inductive hypothesis. * `P I` is the predicate on ordinals about linear independence of good products, which the rest of this file is spent on proving by induction. -/ variable (I) /-- A term of `I` regarded as an ordinal. -/ def ord (i : I) : Ordinal := Ordinal.typein ((·<·) : I → I → Prop) i /-- An ordinal regarded as a term of `I`. -/ noncomputable def term {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) : I := Ordinal.enum ((·<·) : I → I → Prop) o ho variable {I} theorem term_ord_aux {i : I} (ho : ord I i < Ordinal.type ((·<·) : I → I → Prop)) : term I ho = i := by simp only [term, ord, Ordinal.enum_typein] @[simp] theorem ord_term_aux {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) : ord I (term I ho) = o := by simp only [ord, term, Ordinal.typein_enum] theorem ord_term {o : Ordinal} (ho : o < Ordinal.type ((·<·) : I → I → Prop)) (i : I) : ord I i = o ↔ term I ho = i := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · subst h exact term_ord_aux ho · subst h exact ord_term_aux ho /-- A predicate saying that `C` is "small" enough to satisfy the inductive hypothesis. -/ def contained (o : Ordinal) : Prop := ∀ f, f ∈ C → ∀ (i : I), f i = true → ord I i < o variable (I) in /-- The predicate on ordinals which we prove by induction, see `GoodProducts.P0`, `GoodProducts.Plimit` and `GoodProducts.linearIndependentAux` in the section `Induction` below -/ def P (o : Ordinal) : Prop := o ≤ Ordinal.type (·<· : I → I → Prop) → (∀ (C : Set (I → Bool)), IsClosed C → contained C o → LinearIndependent ℤ (GoodProducts.eval C)) theorem Products.prop_of_isGood_of_contained {l : Products I} (o : Ordinal) (h : l.isGood C) (hsC : contained C o) (i : I) (hi : i ∈ l.val) : ord I i < o := by by_contra h' apply h suffices eval C l = 0 by simp [this, Submodule.zero_mem] ext x simp only [eval_eq, LocallyConstant.coe_zero, Pi.zero_apply, ite_eq_right_iff, one_ne_zero] contrapose! h' exact hsC x.val x.prop i (h'.1 i hi) end Ordinal section Zero /-! ## The zero case of the induction In this case, we have `contained C 0` which means that `C` is either empty or a singleton. -/ instance : Subsingleton (LocallyConstant (∅ : Set (I → Bool)) ℤ) := subsingleton_iff.mpr (fun _ _ ↦ LocallyConstant.ext isEmptyElim) instance : IsEmpty { l // Products.isGood (∅ : Set (I → Bool)) l } := isEmpty_iff.mpr fun ⟨l, hl⟩ ↦ hl <| by rw [subsingleton_iff.mp inferInstance (Products.eval ∅ l) 0] exact Submodule.zero_mem _ theorem GoodProducts.linearIndependentEmpty : LinearIndependent ℤ (eval (∅ : Set (I → Bool))) := linearIndependent_empty_type /-- The empty list as a `Products` -/ def Products.nil : Products I := ⟨[], by simp only [List.chain'_nil]⟩ theorem Products.lt_nil_empty : { m : Products I | m < Products.nil } = ∅ := by ext ⟨m, hm⟩ refine ⟨fun h ↦ ?_, by tauto⟩ simp only [Set.mem_setOf_eq, lt_iff_lex_lt, nil, List.Lex.not_nil_right] at h instance {α : Type*} [TopologicalSpace α] [Nonempty α] : Nontrivial (LocallyConstant α ℤ) := ⟨0, 1, ne_of_apply_ne DFunLike.coe <| (Function.const_injective (β := ℤ)).ne zero_ne_one⟩ set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Products.isGood_nil : Products.isGood ({fun _ ↦ false} : Set (I → Bool)) Products.nil := by intro h simp only [Products.lt_nil_empty, Products.eval, List.map, List.prod_nil, Set.image_empty, Submodule.span_empty, Submodule.mem_bot, one_ne_zero] at h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Products.span_nil_eq_top : Submodule.span ℤ (eval ({fun _ ↦ false} : Set (I → Bool)) '' {nil}) = ⊤ := by rw [Set.image_singleton, eq_top_iff] intro f _ rw [Submodule.mem_span_singleton] refine ⟨f default, ?_⟩ simp only [eval, List.map, List.prod_nil, zsmul_eq_mul, mul_one] ext x obtain rfl : x = default := by simp only [Set.default_coe_singleton, eq_iff_true_of_subsingleton] rfl /-- There is a unique `GoodProducts` for the singleton `{fun _ ↦ false}`. -/ noncomputable instance : Unique { l // Products.isGood ({fun _ ↦ false} : Set (I → Bool)) l } where default := ⟨Products.nil, Products.isGood_nil⟩ uniq := by intro ⟨⟨l, hl⟩, hll⟩ ext apply Subtype.ext apply (List.Lex.nil_left_or_eq_nil l (r := (·<·))).resolve_left intro _ apply hll have he : {Products.nil} ⊆ {m | m < ⟨l,hl⟩} := by simpa only [Products.nil, Products.lt_iff_lex_lt, Set.singleton_subset_iff, Set.mem_setOf_eq] apply Submodule.span_mono (Set.image_subset _ he) rw [Products.span_nil_eq_top] exact Submodule.mem_top instance (α : Type*) [TopologicalSpace α] : NoZeroSMulDivisors ℤ (LocallyConstant α ℤ) := by constructor intro c f h rw [or_iff_not_imp_left] intro hc ext x apply mul_right_injective₀ hc simp [LocallyConstant.ext_iff] at h ⊢ exact h x set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem GoodProducts.linearIndependentSingleton : LinearIndependent ℤ (eval ({fun _ ↦ false} : Set (I → Bool))) := by refine linearIndependent_unique (eval ({fun _ ↦ false} : Set (I → Bool))) ?_ simp only [eval, Products.eval, List.map, List.prod_nil, ne_eq, one_ne_zero, not_false_eq_true] end Zero section Maps /-! ## `ℤ`-linear maps induced by projections We define injective `ℤ`-linear maps between modules of the form `LocallyConstant C ℤ` induced by precomposition with the projections defined in the section `Projections`. ### Main definitions * `πs` and `πs'` are the `ℤ`-linear maps corresponding to `ProjRestrict` and `ProjRestricts`  respectively. ### Main result * We prove that `πs` and `πs'` interact well with `Products.eval` and the main application is the theorem `isGood_mono` which says that the property `isGood` is "monotone" on ordinals. -/ theorem contained_eq_proj (o : Ordinal) (h : contained C o) : C = π C (ord I · < o) := by have := proj_prop_eq_self C (ord I · < o) simp [π, Bool.not_eq_false] at this exact (this (fun i x hx ↦ h x hx i)).symm theorem isClosed_proj (o : Ordinal) (hC : IsClosed C) : IsClosed (π C (ord I · < o)) := (continuous_proj (ord I · < o)).isClosedMap C hC theorem contained_proj (o : Ordinal) : contained (π C (ord I · < o)) o := by intro x ⟨_, _, h⟩ j hj aesop (add simp Proj) /-- The `ℤ`-linear map induced by precomposition of the projection `C → π C (ord I · < o)`. -/ @[simps!] noncomputable def πs (o : Ordinal) : LocallyConstant (π C (ord I · < o)) ℤ →ₗ[ℤ] LocallyConstant C ℤ := LocallyConstant.comapₗ ℤ ⟨(ProjRestrict C (ord I · < o)), (continuous_projRestrict _ _)⟩ theorem coe_πs (o : Ordinal) (f : LocallyConstant (π C (ord I · < o)) ℤ) : πs C o f = f ∘ ProjRestrict C (ord I · < o) := by rfl theorem injective_πs (o : Ordinal) : Function.Injective (πs C o) := LocallyConstant.comap_injective ⟨_, (continuous_projRestrict _ _)⟩ (Set.surjective_mapsTo_image_restrict _ _) /-- The `ℤ`-linear map induced by precomposition of the projection `π C (ord I · < o₂) → π C (ord I · < o₁)` for `o₁ ≤ o₂`. -/ @[simps!] noncomputable def πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : LocallyConstant (π C (ord I · < o₁)) ℤ →ₗ[ℤ] LocallyConstant (π C (ord I · < o₂)) ℤ := LocallyConstant.comapₗ ℤ ⟨(ProjRestricts C (fun _ hh ↦ lt_of_lt_of_le hh h)), (continuous_projRestricts _ _)⟩ theorem coe_πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (f : LocallyConstant (π C (ord I · < o₁)) ℤ) : (πs' C h f).toFun = f.toFun ∘ (ProjRestricts C (fun _ hh ↦ lt_of_lt_of_le hh h)) := by rfl theorem injective_πs' {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : Function.Injective (πs' C h) := LocallyConstant.comap_injective ⟨_, (continuous_projRestricts _ _)⟩ (surjective_projRestricts _ fun _ hi ↦ lt_of_lt_of_le hi h) namespace Products theorem lt_ord_of_lt {l m : Products I} {o : Ordinal} (h₁ : m < l) (h₂ : ∀ i ∈ l.val, ord I i < o) : ∀ i ∈ m.val, ord I i < o := List.Sorted.lt_ord_of_lt (List.chain'_iff_pairwise.mp l.2) (List.chain'_iff_pairwise.mp m.2) h₁ h₂ theorem eval_πs {l : Products I} {o : Ordinal} (hlt : ∀ i ∈ l.val, ord I i < o) : πs C o (l.eval (π C (ord I · < o))) = l.eval C := by simpa only [← LocallyConstant.coe_inj] using evalFacProp C (ord I · < o) hlt theorem eval_πs' {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hlt : ∀ i ∈ l.val, ord I i < o₁) : πs' C h (l.eval (π C (ord I · < o₁))) = l.eval (π C (ord I · < o₂)) := by rw [← LocallyConstant.coe_inj, ← LocallyConstant.toFun_eq_coe] exact evalFacProps C (fun (i : I) ↦ ord I i < o₁) (fun (i : I) ↦ ord I i < o₂) hlt (fun _ hh ↦ lt_of_lt_of_le hh h) theorem eval_πs_image {l : Products I} {o : Ordinal} (hl : ∀ i ∈ l.val, ord I i < o) : eval C '' { m | m < l } = (πs C o) '' (eval (π C (ord I · < o)) '' { m | m < l }) := by ext f simp only [Set.mem_image, Set.mem_setOf_eq, exists_exists_and_eq_and] apply exists_congr; intro m apply and_congr_right; intro hm rw [eval_πs C (lt_ord_of_lt hm hl)] theorem eval_πs_image' {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hl : ∀ i ∈ l.val, ord I i < o₁) : eval (π C (ord I · < o₂)) '' { m | m < l } = (πs' C h) '' (eval (π C (ord I · < o₁)) '' { m | m < l }) := by ext f simp only [Set.mem_image, Set.mem_setOf_eq, exists_exists_and_eq_and] apply exists_congr; intro m apply and_congr_right; intro hm rw [eval_πs' C h (lt_ord_of_lt hm hl)] theorem head_lt_ord_of_isGood [Inhabited I] {l : Products I} {o : Ordinal} (h : l.isGood (π C (ord I · < o))) (hn : l.val ≠ []) : ord I (l.val.head!) < o := prop_of_isGood C (ord I · < o) h l.val.head! (List.head!_mem_self hn) /-- If `l` is good w.r.t. `π C (ord I · < o₁)` and `o₁ ≤ o₂`, then it is good w.r.t. `π C (ord I · < o₂)` -/ theorem isGood_mono {l : Products I} {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) (hl : l.isGood (π C (ord I · < o₁))) : l.isGood (π C (ord I · < o₂)) := by intro hl' apply hl rwa [eval_πs_image' C h (prop_of_isGood C _ hl), ← eval_πs' C h (prop_of_isGood C _ hl), Submodule.apply_mem_span_image_iff_mem_span (injective_πs' C h)] at hl' end Products end Maps section Limit /-! ## The limit case of the induction We relate linear independence in `LocallyConstant (π C (ord I · < o')) ℤ` with linear independence in `LocallyConstant C ℤ`, where `contained C o` and `o' < o`. When `o` is a limit ordinal, we prove that the good products in `LocallyConstant C ℤ` are linearly independent if and only if a certain directed union is linearly independent. Each term in this directed union is in bijection with the good products w.r.t. `π C (ord I · < o')` for an ordinal `o' < o`, and these are linearly independent by the inductive hypothesis. ### Main definitions * `GoodProducts.smaller` is the image of good products coming from a smaller ordinal. * `GoodProducts.range_equiv`: The image of the `GoodProducts` in `C` is equivalent to the union of `smaller C o'` over all ordinals `o' < o`. ### Main results * `Products.limitOrdinal`: for `o` a limit ordinal such that `contained C o`, a product `l` is good w.r.t. `C` iff it there exists an ordinal `o' < o` such that `l` is good w.r.t. `π C (ord I · < o')`. * `GoodProducts.linearIndependent_iff_union_smaller` is the result mentioned above, that the good products are linearly independent iff a directed union is. -/ namespace GoodProducts /-- The image of the `GoodProducts` for `π C (ord I · < o)` in `LocallyConstant C ℤ`. The name `smaller` refers to the setting in which we will use this, when we are mapping in `GoodProducts` from a smaller set, i.e. when `o` is a smaller ordinal than the one `C` is "contained" in. -/ def smaller (o : Ordinal) : Set (LocallyConstant C ℤ) := (πs C o) '' (range (π C (ord I · < o))) /-- The map from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller_toFun (o : Ordinal) (x : range (π C (ord I · < o))) : smaller C o := ⟨πs C o ↑x, x.val, x.property, rfl⟩ theorem range_equiv_smaller_toFun_bijective (o : Ordinal) : Function.Bijective (range_equiv_smaller_toFun C o) := by dsimp (config := { unfoldPartialApp := true }) [range_equiv_smaller_toFun] refine ⟨fun a b hab ↦ ?_, fun ⟨a, b, hb⟩ ↦ ?_⟩ · ext1 simp only [Subtype.mk.injEq] at hab exact injective_πs C o hab · use ⟨b, hb.1⟩ simpa only [Subtype.mk.injEq] using hb.2 /-- The equivalence from the image of the `GoodProducts` in `LocallyConstant (π C (ord I · < o)) ℤ` to `smaller C o` -/ noncomputable def range_equiv_smaller (o : Ordinal) : range (π C (ord I · < o)) ≃ smaller C o := Equiv.ofBijective (range_equiv_smaller_toFun C o) (range_equiv_smaller_toFun_bijective C o) theorem smaller_factorization (o : Ordinal) : (fun (p : smaller C o) ↦ p.1) ∘ (range_equiv_smaller C o).toFun = (πs C o) ∘ (fun (p : range (π C (ord I · < o))) ↦ p.1) := by rfl theorem linearIndependent_iff_smaller (o : Ordinal) : LinearIndependent ℤ (GoodProducts.eval (π C (ord I · < o))) ↔ LinearIndependent ℤ (fun (p : smaller C o) ↦ p.1) := by rw [GoodProducts.linearIndependent_iff_range, ← LinearMap.linearIndependent_iff (πs C o) (LinearMap.ker_eq_bot_of_injective (injective_πs _ _)), ← smaller_factorization C o] exact linearIndependent_equiv _ theorem smaller_mono {o₁ o₂ : Ordinal} (h : o₁ ≤ o₂) : smaller C o₁ ⊆ smaller C o₂ := by rintro f ⟨g, hg, rfl⟩ simp only [smaller, Set.mem_image] use πs' C h g obtain ⟨⟨l, gl⟩, rfl⟩ := hg refine ⟨?_, ?_⟩ · use ⟨l, Products.isGood_mono C h gl⟩ ext x rw [eval, ← Products.eval_πs' _ h (Products.prop_of_isGood C _ gl), eval] · rw [← LocallyConstant.coe_inj, coe_πs C o₂, ← LocallyConstant.toFun_eq_coe, coe_πs', Function.comp.assoc, projRestricts_comp_projRestrict C _, coe_πs] rfl end GoodProducts variable {o : Ordinal} (ho : o.IsLimit) (hsC : contained C o) theorem Products.limitOrdinal (l : Products I) : l.isGood (π C (ord I · < o)) ↔ ∃ (o' : Ordinal), o' < o ∧ l.isGood (π C (ord I · < o')) := by refine ⟨fun h ↦ ?_, fun ⟨o', ⟨ho', hl⟩⟩ ↦ isGood_mono C (le_of_lt ho') hl⟩ use Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) have ha : ⊥ < o := by rw [Ordinal.bot_eq_zero, Ordinal.pos_iff_ne_zero]; exact ho.1 have hslt : Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) < o := by simp only [Finset.sup_lt_iff ha, List.mem_toFinset] exact fun b hb ↦ ho.2 _ (prop_of_isGood C (ord I · < o) h b hb) refine ⟨hslt, fun he ↦ h ?_⟩ have hlt : ∀ i ∈ l.val, ord I i < Finset.sup l.val.toFinset (fun a ↦ Order.succ (ord I a)) := by intro i hi simp only [Finset.lt_sup_iff, List.mem_toFinset, Order.lt_succ_iff] exact ⟨i, hi, le_rfl⟩ rwa [eval_πs_image' C (le_of_lt hslt) hlt, ← eval_πs' C (le_of_lt hslt) hlt, Submodule.apply_mem_span_image_iff_mem_span (injective_πs' C _)] theorem GoodProducts.union : range C = ⋃ (e : {o' // o' < o}), (smaller C e.val) := by ext p simp only [smaller, range, Set.mem_iUnion, Set.mem_image, Set.mem_range, Subtype.exists] refine ⟨fun hp ↦ ?_, fun hp ↦ ?_⟩ · obtain ⟨l, hl, rfl⟩ := hp rw [contained_eq_proj C o hsC, Products.limitOrdinal C ho] at hl obtain ⟨o', ho'⟩ := hl refine ⟨o', ho'.1, eval (π C (ord I · < o')) ⟨l, ho'.2⟩, ⟨l, ho'.2, rfl⟩, ?_⟩ exact Products.eval_πs C (Products.prop_of_isGood C _ ho'.2) · obtain ⟨o', h, _, ⟨l, hl, rfl⟩, rfl⟩ := hp refine ⟨l, ?_, (Products.eval_πs C (Products.prop_of_isGood C _ hl)).symm⟩ rw [contained_eq_proj C o hsC] exact Products.isGood_mono C (le_of_lt h) hl /-- The image of the `GoodProducts` in `C` is equivalent to the union of `smaller C o'` over all ordinals `o' < o`. -/ def GoodProducts.range_equiv : range C ≃ ⋃ (e : {o' // o' < o}), (smaller C e.val) := Equiv.Set.ofEq (union C ho hsC) theorem GoodProducts.range_equiv_factorization : (fun (p : ⋃ (e : {o' // o' < o}), (smaller C e.val)) ↦ p.1) ∘ (range_equiv C ho hsC).toFun = (fun (p : range C) ↦ (p.1 : LocallyConstant C ℤ)) := rfl theorem GoodProducts.linearIndependent_iff_union_smaller {o : Ordinal} (ho : o.IsLimit) (hsC : contained C o) : LinearIndependent ℤ (GoodProducts.eval C) ↔ LinearIndependent ℤ (fun (p : ⋃ (e : {o' // o' < o}), (smaller C e.val)) ↦ p.1) := by rw [GoodProducts.linearIndependent_iff_range, ← range_equiv_factorization C ho hsC] exact linearIndependent_equiv (range_equiv C ho hsC) end Limit section Successor /-! ## The successor case in the induction Here we assume that `o` is an ordinal such that `contained C (o+1)` and `o < I`. The element in `I` corresponding to `o` is called `term I ho`, but in this informal docstring we refer to it simply as `o`. This section follows the proof in [scholze2019condensed] quite closely. A translation of the notation there is as follows: ``` [scholze2019condensed] | This file `S₀` |`C0` `S₁` |`C1` `\overline{S}` |`π C (ord I · < o) `\overline{S}'` |`C'` The left map in the exact sequence |`πs` The right map in the exact sequence |`Linear_CC'` ``` When comparing the proof of the successor case in Theorem 5.4 in [scholze2019condensed] with this proof, one should read the phrase "is a basis" as "is linearly independent". Also, the short exact sequence in [scholze2019condensed] is only proved to be left exact here (indeed, that is enough since we are only proving linear independence). This section is split into two sections. The first one, `ExactSequence` defines the left exact sequence mentioned in the previous paragraph (see `succ_mono` and `succ_exact`). It corresponds to the penultimate paragraph of the proof in [scholze2019condensed]. The second one, `GoodProducts` corresponds to the last paragraph in the proof in [scholze2019condensed]. ### Main definitions The main definitions in the section `ExactSequence` are all just notation explained in the table above. The main definitions in the section `GoodProducts` are as follows: * `MaxProducts`: the set of good products that contain the ordinal `o` (since we have `contained C (o+1)`, these all start with `o`). * `GoodProducts.sum_equiv`: the equivalence between `GoodProducts C` and the disjoint union of `MaxProducts C` and `GoodProducts (π C (ord I · < o))`. ### Main results * The main results in the section `ExactSequence` are `succ_mono` and `succ_exact` which together say that the secuence given by `πs` and `Linear_CC'` is left exact: ``` f g 0 --→ LocallyConstant (π C (ord I · < o)) ℤ --→ LocallyConstant C ℤ --→ LocallyConstant C' ℤ ``` where `f` is `πs` and `g` is `Linear_CC'`. The main results in the section `GoodProducts` are as follows: * `Products.max_eq_eval` says that the linear map on the right in the exact sequence, i.e. `Linear_CC'`, takes the evaluation of a term of `MaxProducts` to the evaluation of the corresponding list with the leading `o` removed. * `GoodProducts.maxTail_isGood` says that removing the leading `o` from a term of `MaxProducts C`  yields a list which `isGood` with respect to `C'`. -/ variable {o : Ordinal} (hC : IsClosed C) (hsC : contained C (Order.succ o)) (ho : o < Ordinal.type (·<· : I → I → Prop)) section ExactSequence /-- The subset of `C` consisting of those elements whose `o`-th entry is `false`. -/ def C0 := C ∩ {f | f (term I ho) = false} /-- The subset of `C` consisting of those elements whose `o`-th entry is `true`. -/ def C1 := C ∩ {f | f (term I ho) = true} theorem isClosed_C0 : IsClosed (C0 C ho) := by refine hC.inter ?_ have h : Continuous (fun (f : I → Bool) ↦ f (term I ho)) := continuous_apply (term I ho) exact IsClosed.preimage h (t := {false}) (isClosed_discrete _) theorem isClosed_C1 : IsClosed (C1 C ho) := by refine hC.inter ?_ have h : Continuous (fun (f : I → Bool) ↦ f (term I ho)) := continuous_apply (term I ho) exact IsClosed.preimage h (t := {true}) (isClosed_discrete _) theorem contained_C1 : contained (π (C1 C ho) (ord I · < o)) o := contained_proj _ _ theorem union_C0C1_eq : (C0 C ho) ∪ (C1 C ho) = C := by ext x simp only [C0, C1, Set.mem_union, Set.mem_inter_iff, Set.mem_setOf_eq, ← and_or_left, and_iff_left_iff_imp, Bool.dichotomy (x (term I ho)), implies_true] /-- The intersection of `C0` and the projection of `C1`. We will apply the inductive hypothesis to this set. -/ def C' := C0 C ho ∩ π (C1 C ho) (ord I · < o) theorem isClosed_C' : IsClosed (C' C ho) := IsClosed.inter (isClosed_C0 _ hC _) (isClosed_proj _ _ (isClosed_C1 _ hC _)) theorem contained_C' : contained (C' C ho) o := fun f hf i hi ↦ contained_C1 C ho f hf.2 i hi variable (o) /-- Swapping the `o`-th coordinate to `true`. -/ noncomputable def SwapTrue : (I → Bool) → I → Bool := fun f i ↦ if ord I i = o then true else f i theorem continuous_swapTrue : Continuous (SwapTrue o : (I → Bool) → I → Bool) := by dsimp (config := { unfoldPartialApp := true }) [SwapTrue] apply continuous_pi intro i apply Continuous.comp' · apply continuous_bot · apply continuous_apply variable {o} theorem swapTrue_mem_C1 (f : π (C1 C ho) (ord I · < o)) : SwapTrue o f.val ∈ C1 C ho := by obtain ⟨f, g, hg, rfl⟩ := f convert hg dsimp (config := { unfoldPartialApp := true }) [SwapTrue] ext i split_ifs with h · rw [ord_term ho] at h simpa only [← h] using hg.2.symm · simp only [Proj, ite_eq_left_iff, not_lt, @eq_comm _ false, ← Bool.not_eq_true] specialize hsC g hg.1 i intro h' contrapose! hsC exact ⟨hsC, Order.succ_le_of_lt (h'.lt_of_ne' h)⟩ /-- The first way to map `C'` into `C`. -/ def CC'₀ : C' C ho → C := fun g ↦ ⟨g.val,g.prop.1.1⟩ /-- The second way to map `C'` into `C`. -/ noncomputable def CC'₁ : C' C ho → C := fun g ↦ ⟨SwapTrue o g.val, (swapTrue_mem_C1 C hsC ho ⟨g.val,g.prop.2⟩).1⟩ theorem continuous_CC'₀ : Continuous (CC'₀ C ho) := Continuous.subtype_mk continuous_subtype_val _ theorem continuous_CC'₁ : Continuous (CC'₁ C hsC ho) := Continuous.subtype_mk (Continuous.comp (continuous_swapTrue o) continuous_subtype_val) _ /-- The `ℤ`-linear map induced by precomposing with `CC'₀` -/ noncomputable def Linear_CC'₀ : LocallyConstant C ℤ →ₗ[ℤ] LocallyConstant (C' C ho) ℤ := LocallyConstant.comapₗ ℤ ⟨(CC'₀ C ho), (continuous_CC'₀ C ho)⟩ /-- The `ℤ`-linear map induced by precomposing with `CC'₁` -/ noncomputable def Linear_CC'₁ : LocallyConstant C ℤ →ₗ[ℤ] LocallyConstant (C' C ho) ℤ := LocallyConstant.comapₗ ℤ ⟨(CC'₁ C hsC ho), (continuous_CC'₁ C hsC ho)⟩ /-- The difference between `Linear_CC'₁` and `Linear_CC'₀`. -/ noncomputable def Linear_CC' : LocallyConstant C ℤ →ₗ[ℤ] LocallyConstant (C' C ho) ℤ := Linear_CC'₁ C hsC ho - Linear_CC'₀ C ho theorem CC_comp_zero : ∀ y, (Linear_CC' C hsC ho) ((πs C o) y) = 0 := by intro y ext x dsimp [Linear_CC', Linear_CC'₀, Linear_CC'₁, LocallyConstant.sub_apply] simp only [continuous_CC'₀, continuous_CC'₁, LocallyConstant.coe_comap, continuous_projRestrict, Function.comp_apply, sub_eq_zero] congr 1 ext i dsimp [CC'₀, CC'₁, ProjRestrict, Proj] apply if_ctx_congr Iff.rfl _ (fun _ ↦ rfl) simp only [SwapTrue, ite_eq_right_iff] intro h₁ h₂ exact (h₁.ne h₂).elim theorem C0_projOrd {x : I → Bool} (hx : x ∈ C0 C ho) : Proj (ord I · < o) x = x := by ext i simp only [Proj, Set.mem_setOf, ite_eq_left_iff, not_lt] intro hi rw [le_iff_lt_or_eq] at hi cases' hi with hi hi · specialize hsC x hx.1 i rw [← not_imp_not] at hsC simp only [not_lt, Bool.not_eq_true, Order.succ_le_iff] at hsC exact (hsC hi).symm · simp only [C0, Set.mem_inter_iff, Set.mem_setOf_eq] at hx rw [eq_comm, ord_term ho] at hi rw [← hx.2, hi] theorem C1_projOrd {x : I → Bool} (hx : x ∈ C1 C ho) : SwapTrue o (Proj (ord I · < o) x) = x := by ext i dsimp [SwapTrue, Proj] split_ifs with hi h · rw [ord_term ho] at hi rw [← hx.2, hi] · rfl · simp only [not_lt] at h have h' : o < ord I i := lt_of_le_of_ne h (Ne.symm hi) specialize hsC x hx.1 i rw [← not_imp_not] at hsC simp only [not_lt, Bool.not_eq_true, Order.succ_le_iff] at hsC exact (hsC h').symm open scoped Classical in theorem CC_exact {f : LocallyConstant C ℤ} (hf : Linear_CC' C hsC ho f = 0) : ∃ y, πs C o y = f := by dsimp [Linear_CC', Linear_CC'₀, Linear_CC'₁] at hf simp only [sub_eq_zero, ← LocallyConstant.coe_inj, LocallyConstant.coe_comap, continuous_CC'₀, continuous_CC'₁] at hf let C₀C : C0 C ho → C := fun x ↦ ⟨x.val, x.prop.1⟩ have h₀ : Continuous C₀C := Continuous.subtype_mk continuous_induced_dom _ let C₁C : π (C1 C ho) (ord I · < o) → C := fun x ↦ ⟨SwapTrue o x.val, (swapTrue_mem_C1 C hsC ho x).1⟩ have h₁ : Continuous C₁C := Continuous.subtype_mk ((continuous_swapTrue o).comp continuous_subtype_val) _ refine ⟨LocallyConstant.piecewise' ?_ (isClosed_C0 C hC ho) (isClosed_proj _ o (isClosed_C1 C hC ho)) (f.comap ⟨C₀C, h₀⟩) (f.comap ⟨C₁C, h₁⟩) ?_, ?_⟩ · rintro _ ⟨y, hyC, rfl⟩ simp only [Set.mem_union, Set.mem_setOf_eq, Set.mem_univ, iff_true] rw [← union_C0C1_eq C ho] at hyC refine hyC.imp (fun hyC ↦ ?_) (fun hyC ↦ ⟨y, hyC, rfl⟩) rwa [C0_projOrd C hsC ho hyC] · intro x hx simpa only [h₀, h₁, LocallyConstant.coe_comap] using (congrFun hf ⟨x, hx⟩).symm · ext ⟨x, hx⟩ rw [← union_C0C1_eq C ho] at hx cases' hx with hx₀ hx₁ · have hx₀' : ProjRestrict C (ord I · < o) ⟨x, hx⟩ = x := by simpa only [ProjRestrict, Set.MapsTo.val_restrict_apply] using C0_projOrd C hsC ho hx₀ simp only [πs_apply_apply, hx₀', hx₀, LocallyConstant.piecewise'_apply_left, LocallyConstant.coe_comap, ContinuousMap.coe_mk, Function.comp_apply] · have hx₁' : (ProjRestrict C (ord I · < o) ⟨x, hx⟩).val ∈ π (C1 C ho) (ord I · < o) := by simpa only [ProjRestrict, Set.MapsTo.val_restrict_apply] using ⟨x, hx₁, rfl⟩ simp only [C₁C, πs_apply_apply, continuous_projRestrict, LocallyConstant.coe_comap, Function.comp_apply, hx₁', LocallyConstant.piecewise'_apply_right, h₁] congr simp only [ContinuousMap.coe_mk, Subtype.mk.injEq] exact C1_projOrd C hsC ho hx₁ variable (o) in theorem succ_mono : CategoryTheory.Mono (ModuleCat.ofHom (πs C o)) := by rw [ModuleCat.mono_iff_injective] exact injective_πs _ _ theorem succ_exact : (ShortComplex.mk (ModuleCat.ofHom (πs C o)) (ModuleCat.ofHom (Linear_CC' C hsC ho)) (by ext; apply CC_comp_zero)).Exact := by rw [ShortComplex.moduleCat_exact_iff] intro f exact CC_exact C hC hsC ho end ExactSequence section GoodProducts namespace GoodProducts /-- The `GoodProducts` in `C` that contain `o` (they necessarily start with `o`, see `GoodProducts.head!_eq_o_of_maxProducts`) -/ def MaxProducts : Set (Products I) := {l | l.isGood C ∧ term I ho ∈ l.val} theorem union_succ : GoodProducts C = GoodProducts (π C (ord I · < o)) ∪ MaxProducts C ho := by ext l simp only [GoodProducts, MaxProducts, Set.mem_union, Set.mem_setOf_eq] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · by_cases hh : term I ho ∈ l.val · exact Or.inr ⟨h, hh⟩ · left intro he apply h have h' := Products.prop_of_isGood_of_contained C _ h hsC simp only [Order.lt_succ_iff] at h' simp only [not_imp_not] at hh have hh' : ∀ a ∈ l.val, ord I a < o := by intro a ha refine (h' a ha).lt_of_ne ?_ rw [ne_eq, ord_term ho a] rintro rfl contradiction rwa [Products.eval_πs_image C hh', ← Products.eval_πs C hh', Submodule.apply_mem_span_image_iff_mem_span (injective_πs _ _)] · refine h.elim (fun hh ↦ ?_) And.left have := Products.isGood_mono C (Order.lt_succ o).le hh rwa [contained_eq_proj C (Order.succ o) hsC] /-- The inclusion map from the sum of `GoodProducts (π C (ord I · < o))` and `(MaxProducts C ho)` to `Products I`. -/ def sum_to : (GoodProducts (π C (ord I · < o))) ⊕ (MaxProducts C ho) → Products I := Sum.elim Subtype.val Subtype.val theorem injective_sum_to : Function.Injective (sum_to C ho) := by refine Function.Injective.sum_elim Subtype.val_injective Subtype.val_injective (fun ⟨a,ha⟩ ⟨b,hb⟩ ↦ (fun (hab : a = b) ↦ ?_)) rw [← hab] at hb have ha' := Products.prop_of_isGood C _ ha (term I ho) hb.2 simp only [ord_term_aux, lt_self_iff_false] at ha' theorem sum_to_range : Set.range (sum_to C ho) = GoodProducts (π C (ord I · < o)) ∪ MaxProducts C ho := by have h : Set.range (sum_to C ho) = _ ∪ _ := Set.Sum.elim_range _ _; rw [h]; congr<;> ext l · exact ⟨fun ⟨m,hm⟩ ↦ by rw [← hm]; exact m.prop, fun hl ↦ ⟨⟨l,hl⟩, rfl⟩⟩ · exact ⟨fun ⟨m,hm⟩ ↦ by rw [← hm]; exact m.prop, fun hl ↦ ⟨⟨l,hl⟩, rfl⟩⟩ /-- The equivalence from the sum of `GoodProducts (π C (ord I · < o))` and `(MaxProducts C ho)` to `GoodProducts C`. -/ noncomputable def sum_equiv : GoodProducts (π C (ord I · < o)) ⊕ (MaxProducts C ho) ≃ GoodProducts C := calc _ ≃ Set.range (sum_to C ho) := Equiv.ofInjective (sum_to C ho) (injective_sum_to C ho) _ ≃ _ := Equiv.Set.ofEq <| by rw [sum_to_range C ho, union_succ C hsC ho] theorem sum_equiv_comp_eval_eq_elim : eval C ∘ (sum_equiv C hsC ho).toFun = (Sum.elim (fun (l : GoodProducts (π C (ord I · < o))) ↦ Products.eval C l.1) (fun (l : MaxProducts C ho) ↦ Products.eval C l.1)) := by ext ⟨_,_⟩ <;> [rfl; rfl] /-- Let `N := LocallyConstant (π C (ord I · < o)) ℤ` `M := LocallyConstant C ℤ` `P := LocallyConstant (C' C ho) ℤ` `ι := GoodProducts (π C (ord I · < o))` `ι' := GoodProducts (C' C ho')` `v : ι → N := GoodProducts.eval (π C (ord I · < o))` Then `SumEval C ho` is the map `u` in the diagram below. It is linearly independent if and only if `GoodProducts.eval C` is, see `linearIndependent_iff_sum`. The top row is the exact sequence given by `succ_exact` and `succ_mono`. The left square commutes by `GoodProducts.square_commutes`. ``` 0 --→ N --→ M --→ P ↑ ↑ ↑ v| u| | ι → ι ⊕ ι' ← ι' ``` -/ def SumEval : GoodProducts (π C (ord I · < o)) ⊕ MaxProducts C ho → LocallyConstant C ℤ := Sum.elim (fun l ↦ l.1.eval C) (fun l ↦ l.1.eval C) theorem linearIndependent_iff_sum : LinearIndependent ℤ (eval C) ↔ LinearIndependent ℤ (SumEval C ho) := by rw [← linearIndependent_equiv (sum_equiv C hsC ho), SumEval, ← sum_equiv_comp_eval_eq_elim C hsC ho] exact Iff.rfl theorem span_sum : Set.range (eval C) = Set.range (Sum.elim (fun (l : GoodProducts (π C (ord I · < o))) ↦ Products.eval C l.1) (fun (l : MaxProducts C ho) ↦ Products.eval C l.1)) := by rw [← sum_equiv_comp_eval_eq_elim C hsC ho, Equiv.toFun_as_coe, EquivLike.range_comp (e := sum_equiv C hsC ho)] theorem square_commutes : SumEval C ho ∘ Sum.inl = ModuleCat.ofHom (πs C o) ∘ eval (π C (ord I · < o)) := by ext l dsimp [SumEval] rw [← Products.eval_πs C (Products.prop_of_isGood _ _ l.prop)] rfl end GoodProducts theorem swapTrue_eq_true (x : I → Bool) : SwapTrue o x (term I ho) = true := by simp only [SwapTrue, ord_term_aux, ite_true] theorem mem_C'_eq_false : ∀ x, x ∈ C' C ho → x (term I ho) = false := by rintro x ⟨_, y, _, rfl⟩ simp only [Proj, ord_term_aux, lt_self_iff_false, ite_false] /-- `List.tail` as a `Products`. -/ def Products.Tail (l : Products I) : Products I := ⟨l.val.tail, List.Chain'.tail l.prop⟩ theorem Products.max_eq_o_cons_tail [Inhabited I] (l : Products I) (hl : l.val ≠ []) (hlh : l.val.head! = term I ho) : l.val = term I ho :: l.Tail.val := by rw [← List.cons_head!_tail hl, hlh] rfl theorem Products.max_eq_o_cons_tail' [Inhabited I] (l : Products I) (hl : l.val ≠ []) (hlh : l.val.head! = term I ho) (hlc : List.Chain' (·>·) (term I ho :: l.Tail.val)) : l = ⟨term I ho :: l.Tail.val, hlc⟩ := by simp_rw [← max_eq_o_cons_tail ho l hl hlh] rfl theorem GoodProducts.head!_eq_o_of_maxProducts [Inhabited I] (l : ↑(MaxProducts C ho)) : l.val.val.head! = term I ho := by rw [eq_comm, ← ord_term ho] have hm := l.prop.2 have := Products.prop_of_isGood_of_contained C _ l.prop.1 hsC l.val.val.head! (List.head!_mem_self (List.ne_nil_of_mem hm)) simp only [Order.lt_succ_iff] at this refine eq_of_le_of_not_lt this (not_lt.mpr ?_) have h : ord I (term I ho) ≤ ord I l.val.val.head! := by simp only [← ord_term_aux, ord, Ordinal.typein_le_typein, not_lt] exact Products.rel_head!_of_mem hm rwa [ord_term_aux] at h theorem GoodProducts.max_eq_o_cons_tail (l : MaxProducts C ho) : l.val.val = (term I ho) :: l.val.Tail.val := have : Inhabited I := ⟨term I ho⟩ Products.max_eq_o_cons_tail ho l.val (List.ne_nil_of_mem l.prop.2) (head!_eq_o_of_maxProducts _ hsC ho l)
Mathlib/Topology/Category/Profinite/Nobeling.lean
1,508
1,511
theorem Products.evalCons {l : List I} {a : I} (hla : (a::l).Chain' (·>·)) : Products.eval C ⟨a::l,hla⟩ = (e C a) * Products.eval C ⟨l,List.Chain'.sublist hla (List.tail_sublist (a::l))⟩ := by
simp only [eval.eq_1, List.map, List.prod_cons]
/- Copyright (c) 2021 Shing Tak Lam. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Shing Tak Lam -/ import Mathlib.Topology.Order.ProjIcc import Mathlib.Topology.ContinuousFunction.Ordered import Mathlib.Topology.CompactOpen import Mathlib.Topology.UnitInterval #align_import topology.homotopy.basic from "leanprover-community/mathlib"@"11c53f174270aa43140c0b26dabce5fc4a253e80" /-! # Homotopy between functions In this file, we define a homotopy between two functions `f₀` and `f₁`. First we define `ContinuousMap.Homotopy` between the two functions, with no restrictions on the intermediate maps. Then, as in the formalisation in HOL-Analysis, we define `ContinuousMap.HomotopyWith f₀ f₁ P`, for homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. Finally, we define `ContinuousMap.HomotopyRel f₀ f₁ S`, for homotopies between `f₀` and `f₁` which are fixed on `S`. ## Definitions * `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies between `f₀` and `f₁`. * `ContinuousMap.HomotopyWith f₀ f₁ P` is the type of homotopies between `f₀` and `f₁`, where the intermediate maps satisfy the predicate `P`. * `ContinuousMap.HomotopyRel f₀ f₁ S` is the type of homotopies between `f₀` and `f₁` which are fixed on `S`. For each of the above, we have * `refl f`, which is the constant homotopy from `f` to `f`. * `symm F`, which reverses the homotopy `F`. For example, if `F : ContinuousMap.Homotopy f₀ f₁`, then `F.symm : ContinuousMap.Homotopy f₁ f₀`. * `trans F G`, which concatenates the homotopies `F` and `G`. For example, if `F : ContinuousMap.Homotopy f₀ f₁` and `G : ContinuousMap.Homotopy f₁ f₂`, then `F.trans G : ContinuousMap.Homotopy f₀ f₂`. We also define the relations * `ContinuousMap.Homotopic f₀ f₁` is defined to be `Nonempty (ContinuousMap.Homotopy f₀ f₁)` * `ContinuousMap.HomotopicWith f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyWith f₀ f₁ P)` * `ContinuousMap.HomotopicRel f₀ f₁ P` is defined to be `Nonempty (ContinuousMap.HomotopyRel f₀ f₁ P)` and for `ContinuousMap.homotopic` and `ContinuousMap.homotopic_rel`, we also define the `setoid` and `quotient` in `C(X, Y)` by these relations. ## References - [HOL-Analysis formalisation](https://isabelle.in.tum.de/library/HOL/HOL-Analysis/Homotopy.html) -/ noncomputable section universe u v w x variable {F : Type*} {X : Type u} {Y : Type v} {Z : Type w} {Z' : Type x} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace Z'] open unitInterval namespace ContinuousMap /-- `ContinuousMap.Homotopy f₀ f₁` is the type of homotopies from `f₀` to `f₁`. When possible, instead of parametrizing results over `(f : Homotopy f₀ f₁)`, you should parametrize over `{F : Type*} [HomotopyLike F f₀ f₁] (f : F)`. When you extend this structure, make sure to extend `ContinuousMap.HomotopyLike`. -/ structure Homotopy (f₀ f₁ : C(X, Y)) extends C(I × X, Y) where /-- value of the homotopy at 0 -/ map_zero_left : ∀ x, toFun (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left : ∀ x, toFun (1, x) = f₁ x #align continuous_map.homotopy ContinuousMap.Homotopy section /-- `ContinuousMap.HomotopyLike F f₀ f₁` states that `F` is a type of homotopies between `f₀` and `f₁`. You should extend this class when you extend `ContinuousMap.Homotopy`. -/ class HomotopyLike {X Y : outParam Type*} [TopologicalSpace X] [TopologicalSpace Y] (F : Type*) (f₀ f₁ : outParam <| C(X, Y)) [FunLike F (I × X) Y] extends ContinuousMapClass F (I × X) Y : Prop where /-- value of the homotopy at 0 -/ map_zero_left (f : F) : ∀ x, f (0, x) = f₀ x /-- value of the homotopy at 1 -/ map_one_left (f : F) : ∀ x, f (1, x) = f₁ x #align continuous_map.homotopy_like ContinuousMap.HomotopyLike end namespace Homotopy section variable {f₀ f₁ : C(X, Y)} instance instFunLike : FunLike (Homotopy f₀ f₁) (I × X) Y where coe f := f.toFun coe_injective' f g h := by obtain ⟨⟨_, _⟩, _⟩ := f obtain ⟨⟨_, _⟩, _⟩ := g congr instance : HomotopyLike (Homotopy f₀ f₁) f₀ f₁ where map_continuous f := f.continuous_toFun map_zero_left f := f.map_zero_left map_one_left f := f.map_one_left @[ext] theorem ext {F G : Homotopy f₀ f₁} (h : ∀ x, F x = G x) : F = G := DFunLike.ext _ _ h #align continuous_map.homotopy.ext ContinuousMap.Homotopy.ext /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (F : Homotopy f₀ f₁) : I × X → Y := F #align continuous_map.homotopy.simps.apply ContinuousMap.Homotopy.Simps.apply initialize_simps_projections Homotopy (toFun → apply, -toContinuousMap) /-- Deprecated. Use `map_continuous` instead. -/ protected theorem continuous (F : Homotopy f₀ f₁) : Continuous F := F.continuous_toFun #align continuous_map.homotopy.continuous ContinuousMap.Homotopy.continuous @[simp] theorem apply_zero (F : Homotopy f₀ f₁) (x : X) : F (0, x) = f₀ x := F.map_zero_left x #align continuous_map.homotopy.apply_zero ContinuousMap.Homotopy.apply_zero @[simp] theorem apply_one (F : Homotopy f₀ f₁) (x : X) : F (1, x) = f₁ x := F.map_one_left x #align continuous_map.homotopy.apply_one ContinuousMap.Homotopy.apply_one @[simp] theorem coe_toContinuousMap (F : Homotopy f₀ f₁) : ⇑F.toContinuousMap = F := rfl #align continuous_map.homotopy.coe_to_continuous_map ContinuousMap.Homotopy.coe_toContinuousMap /-- Currying a homotopy to a continuous function from `I` to `C(X, Y)`. -/ def curry (F : Homotopy f₀ f₁) : C(I, C(X, Y)) := F.toContinuousMap.curry #align continuous_map.homotopy.curry ContinuousMap.Homotopy.curry @[simp] theorem curry_apply (F : Homotopy f₀ f₁) (t : I) (x : X) : F.curry t x = F (t, x) := rfl #align continuous_map.homotopy.curry_apply ContinuousMap.Homotopy.curry_apply /-- Continuously extending a curried homotopy to a function from `ℝ` to `C(X, Y)`. -/ def extend (F : Homotopy f₀ f₁) : C(ℝ, C(X, Y)) := F.curry.IccExtend zero_le_one #align continuous_map.homotopy.extend ContinuousMap.Homotopy.extend theorem extend_apply_of_le_zero (F : Homotopy f₀ f₁) {t : ℝ} (ht : t ≤ 0) (x : X) : F.extend t x = f₀ x := by rw [← F.apply_zero] exact ContinuousMap.congr_fun (Set.IccExtend_of_le_left (zero_le_one' ℝ) F.curry ht) x #align continuous_map.homotopy.extend_apply_of_le_zero ContinuousMap.Homotopy.extend_apply_of_le_zero theorem extend_apply_of_one_le (F : Homotopy f₀ f₁) {t : ℝ} (ht : 1 ≤ t) (x : X) : F.extend t x = f₁ x := by rw [← F.apply_one] exact ContinuousMap.congr_fun (Set.IccExtend_of_right_le (zero_le_one' ℝ) F.curry ht) x #align continuous_map.homotopy.extend_apply_of_one_le ContinuousMap.Homotopy.extend_apply_of_one_le @[simp] theorem extend_apply_coe (F : Homotopy f₀ f₁) (t : I) (x : X) : F.extend t x = F (t, x) := ContinuousMap.congr_fun (Set.IccExtend_val (zero_le_one' ℝ) F.curry t) x #align continuous_map.homotopy.extend_apply_coe ContinuousMap.Homotopy.extend_apply_coe @[simp] theorem extend_apply_of_mem_I (F : Homotopy f₀ f₁) {t : ℝ} (ht : t ∈ I) (x : X) : F.extend t x = F (⟨t, ht⟩, x) := ContinuousMap.congr_fun (Set.IccExtend_of_mem (zero_le_one' ℝ) F.curry ht) x set_option linter.uppercaseLean3 false in #align continuous_map.homotopy.extend_apply_of_mem_I ContinuousMap.Homotopy.extend_apply_of_mem_I theorem congr_fun {F G : Homotopy f₀ f₁} (h : F = G) (x : I × X) : F x = G x := ContinuousMap.congr_fun (congr_arg _ h) x #align continuous_map.homotopy.congr_fun ContinuousMap.Homotopy.congr_fun theorem congr_arg (F : Homotopy f₀ f₁) {x y : I × X} (h : x = y) : F x = F y := F.toContinuousMap.congr_arg h #align continuous_map.homotopy.congr_arg ContinuousMap.Homotopy.congr_arg end /-- Given a continuous function `f`, we can define a `Homotopy f f` by `F (t, x) = f x` -/ @[simps] def refl (f : C(X, Y)) : Homotopy f f where toFun x := f x.2 map_zero_left _ := rfl map_one_left _ := rfl #align continuous_map.homotopy.refl ContinuousMap.Homotopy.refl instance : Inhabited (Homotopy (ContinuousMap.id X) (ContinuousMap.id X)) := ⟨Homotopy.refl _⟩ /-- Given a `Homotopy f₀ f₁`, we can define a `Homotopy f₁ f₀` by reversing the homotopy. -/ @[simps] def symm {f₀ f₁ : C(X, Y)} (F : Homotopy f₀ f₁) : Homotopy f₁ f₀ where toFun x := F (σ x.1, x.2) map_zero_left := by norm_num map_one_left := by norm_num #align continuous_map.homotopy.symm ContinuousMap.Homotopy.symm @[simp] theorem symm_symm {f₀ f₁ : C(X, Y)} (F : Homotopy f₀ f₁) : F.symm.symm = F := by ext simp #align continuous_map.homotopy.symm_symm ContinuousMap.Homotopy.symm_symm theorem symm_bijective {f₀ f₁ : C(X, Y)} : Function.Bijective (Homotopy.symm : Homotopy f₀ f₁ → Homotopy f₁ f₀) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- Given `Homotopy f₀ f₁` and `Homotopy f₁ f₂`, we can define a `Homotopy f₀ f₂` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) : Homotopy f₀ f₂ where toFun x := if (x.1 : ℝ) ≤ 1 / 2 then F.extend (2 * x.1) x.2 else G.extend (2 * x.1 - 1) x.2 continuous_toFun := by refine continuous_if_le (continuous_induced_dom.comp continuous_fst) continuous_const (F.continuous.comp (by continuity)).continuousOn (G.continuous.comp (by continuity)).continuousOn ?_ rintro x hx norm_num [hx] map_zero_left x := by set_option tactic.skipAssignedInstances false in norm_num map_one_left x := by set_option tactic.skipAssignedInstances false in norm_num #align continuous_map.homotopy.trans ContinuousMap.Homotopy.trans theorem trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) (x : I × X) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := show ite _ _ _ = _ by split_ifs <;> · rw [extend, ContinuousMap.coe_IccExtend, Set.IccExtend_of_mem] rfl #align continuous_map.homotopy.trans_apply ContinuousMap.Homotopy.trans_apply theorem symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : Homotopy f₀ f₁) (G : Homotopy f₁ f₂) : (F.trans G).symm = G.symm.trans F.symm := by ext ⟨t, _⟩ rw [trans_apply, symm_apply, trans_apply] simp only [coe_symm_eq, symm_apply] split_ifs with h₁ h₂ h₂ · have ht : (t : ℝ) = 1 / 2 := by linarith norm_num [ht] · congr 2 apply Subtype.ext simp only [coe_symm_eq] linarith · congr 2 apply Subtype.ext simp only [coe_symm_eq] linarith · exfalso linarith #align continuous_map.homotopy.symm_trans ContinuousMap.Homotopy.symm_trans /-- Casting a `Homotopy f₀ f₁` to a `Homotopy g₀ g₁` where `f₀ = g₀` and `f₁ = g₁`. -/ @[simps] def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : Homotopy f₀ f₁) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) : Homotopy g₀ g₁ where toFun := F map_zero_left := by simp [← h₀] map_one_left := by simp [← h₁] #align continuous_map.homotopy.cast ContinuousMap.Homotopy.cast /-- Composition of a `Homotopy g₀ g₁` and `f : C(X, Y)` as a homotopy between `g₀.comp f` and `g₁.comp f`. -/ @[simps!] def compContinuousMap {g₀ g₁ : C(Y, Z)} (G : Homotopy g₀ g₁) (f : C(X, Y)) : Homotopy (g₀.comp f) (g₁.comp f) where toContinuousMap := G.comp (.prodMap (.id _) f) map_zero_left _ := G.map_zero_left _ map_one_left _ := G.map_one_left _ /-- If we have a `Homotopy f₀ f₁` and a `Homotopy g₀ g₁`, then we can compose them and get a `Homotopy (g₀.comp f₀) (g₁.comp f₁)`. -/ @[simps] def hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) : Homotopy (g₀.comp f₀) (g₁.comp f₁) where toFun x := G (x.1, F x) map_zero_left := by simp map_one_left := by simp #align continuous_map.homotopy.hcomp ContinuousMap.Homotopy.hcomp /-- Let `F` be a homotopy between `f₀ : C(X, Y)` and `f₁ : C(X, Y)`. Let `G` be a homotopy between `g₀ : C(X, Z)` and `g₁ : C(X, Z)`. Then `F.prodMk G` is the homotopy between `f₀.prodMk g₀` and `f₁.prodMk g₁` that sends `p` to `(F p, G p)`. -/ nonrec def prodMk {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(X, Z)} (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) : Homotopy (f₀.prodMk g₀) (f₁.prodMk g₁) where toContinuousMap := F.prodMk G map_zero_left _ := Prod.ext (F.map_zero_left _) (G.map_zero_left _) map_one_left _ := Prod.ext (F.map_one_left _) (G.map_one_left _) /-- Let `F` be a homotopy between `f₀ : C(X, Y)` and `f₁ : C(X, Y)`. Let `G` be a homotopy between `g₀ : C(Z, Z')` and `g₁ : C(Z, Z')`. Then `F.prodMap G` is the homotopy between `f₀.prodMap g₀` and `f₁.prodMap g₁` that sends `(t, x, z)` to `(F (t, x), G (t, z))`. -/ def prodMap {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Z, Z')} (F : Homotopy f₀ f₁) (G : Homotopy g₀ g₁) : Homotopy (f₀.prodMap g₀) (f₁.prodMap g₁) := .prodMk (.hcomp (.refl .fst) F) (.hcomp (.refl .snd) G) /-- Given a family of homotopies `F i` between `f₀ i : C(X, Y i)` and `f₁ i : C(X, Y i)`, returns a homotopy between `ContinuousMap.pi f₀` and `ContinuousMap.pi f₁`. -/ protected def pi {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f₀ f₁ : ∀ i, C(X, Y i)} (F : ∀ i, Homotopy (f₀ i) (f₁ i)) : Homotopy (.pi f₀) (.pi f₁) where toContinuousMap := .pi fun i ↦ F i map_zero_left x := funext fun i ↦ (F i).map_zero_left x map_one_left x := funext fun i ↦ (F i).map_one_left x /-- Given a family of homotopies `F i` between `f₀ i : C(X i, Y i)` and `f₁ i : C(X i, Y i)`, returns a homotopy between `ContinuousMap.piMap f₀` and `ContinuousMap.piMap f₁`. -/ protected def piMap {X Y : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, TopologicalSpace (Y i)] {f₀ f₁ : ∀ i, C(X i, Y i)} (F : ∀ i, Homotopy (f₀ i) (f₁ i)) : Homotopy (.piMap f₀) (.piMap f₁) := .pi fun i ↦ .hcomp (.refl <| .eval i) (F i) end Homotopy /-- Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic if there exists a `Homotopy f₀ f₁`. -/ def Homotopic (f₀ f₁ : C(X, Y)) : Prop := Nonempty (Homotopy f₀ f₁) #align continuous_map.homotopic ContinuousMap.Homotopic namespace Homotopic @[refl] theorem refl (f : C(X, Y)) : Homotopic f f := ⟨Homotopy.refl f⟩ #align continuous_map.homotopic.refl ContinuousMap.Homotopic.refl @[symm] theorem symm ⦃f g : C(X, Y)⦄ (h : Homotopic f g) : Homotopic g f := h.map Homotopy.symm #align continuous_map.homotopic.symm ContinuousMap.Homotopic.symm @[trans] theorem trans ⦃f g h : C(X, Y)⦄ (h₀ : Homotopic f g) (h₁ : Homotopic g h) : Homotopic f h := h₀.map2 Homotopy.trans h₁ #align continuous_map.homotopic.trans ContinuousMap.Homotopic.trans theorem hcomp {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Y, Z)} (h₀ : Homotopic f₀ f₁) (h₁ : Homotopic g₀ g₁) : Homotopic (g₀.comp f₀) (g₁.comp f₁) := h₀.map2 Homotopy.hcomp h₁ #align continuous_map.homotopic.hcomp ContinuousMap.Homotopic.hcomp theorem equivalence : Equivalence (@Homotopic X Y _ _) := ⟨refl, by apply symm, by apply trans⟩ #align continuous_map.homotopic.equivalence ContinuousMap.Homotopic.equivalence nonrec theorem prodMk {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(X, Z)} : Homotopic f₀ f₁ → Homotopic g₀ g₁ → Homotopic (f₀.prodMk g₀) (f₁.prodMk g₁) | ⟨F⟩, ⟨G⟩ => ⟨F.prodMk G⟩ nonrec theorem prodMap {f₀ f₁ : C(X, Y)} {g₀ g₁ : C(Z, Z')} : Homotopic f₀ f₁ → Homotopic g₀ g₁ → Homotopic (f₀.prodMap g₀) (f₁.prodMap g₁) | ⟨F⟩, ⟨G⟩ => ⟨F.prodMap G⟩ /-- If each `f₀ i : C(X, Y i)` is homotopic to `f₁ i : C(X, Y i)`, then `ContinuousMap.pi f₀` is homotopic to `ContinuousMap.pi f₁`. -/ protected theorem pi {Y : ι → Type*} [∀ i, TopologicalSpace (Y i)] {f₀ f₁ : ∀ i, C(X, Y i)} (F : ∀ i, Homotopic (f₀ i) (f₁ i)) : Homotopic (.pi f₀) (.pi f₁) := ⟨.pi fun i ↦ (F i).some⟩ /-- If each `f₀ i : C(X, Y i)` is homotopic to `f₁ i : C(X, Y i)`, then `ContinuousMap.pi f₀` is homotopic to `ContinuousMap.pi f₁`. -/ protected theorem piMap {X Y : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, TopologicalSpace (Y i)] {f₀ f₁ : ∀ i, C(X i, Y i)} (F : ∀ i, Homotopic (f₀ i) (f₁ i)) : Homotopic (.piMap f₀) (.piMap f₁) := .pi fun i ↦ .hcomp (.refl <| .eval i) (F i) end Homotopic /-- The type of homotopies between `f₀ f₁ : C(X, Y)`, where the intermediate maps satisfy the predicate `P : C(X, Y) → Prop` -/ structure HomotopyWith (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) extends Homotopy f₀ f₁ where -- Porting note (#11215): TODO: use `toHomotopy.curry t` /-- the intermediate maps of the homotopy satisfy the property -/ prop' : ∀ t, P ⟨fun x => toFun (t, x), Continuous.comp continuous_toFun (continuous_const.prod_mk continuous_id')⟩ #align continuous_map.homotopy_with ContinuousMap.HomotopyWith namespace HomotopyWith section variable {f₀ f₁ : C(X, Y)} {P : C(X, Y) → Prop} instance instFunLike : FunLike (HomotopyWith f₀ f₁ P) (I × X) Y where coe F := ⇑F.toHomotopy coe_injective' | ⟨⟨⟨_, _⟩, _, _⟩, _⟩, ⟨⟨⟨_, _⟩, _, _⟩, _⟩, rfl => rfl instance : HomotopyLike (HomotopyWith f₀ f₁ P) f₀ f₁ where map_continuous F := F.continuous_toFun map_zero_left F := F.map_zero_left map_one_left F := F.map_one_left theorem coeFn_injective : @Function.Injective (HomotopyWith f₀ f₁ P) (I × X → Y) (⇑) := DFunLike.coe_injective' #align continuous_map.homotopy_with.coe_fn_injective ContinuousMap.HomotopyWith.coeFn_injective @[ext] theorem ext {F G : HomotopyWith f₀ f₁ P} (h : ∀ x, F x = G x) : F = G := DFunLike.ext F G h #align continuous_map.homotopy_with.ext ContinuousMap.HomotopyWith.ext /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (F : HomotopyWith f₀ f₁ P) : I × X → Y := F #align continuous_map.homotopy_with.simps.apply ContinuousMap.HomotopyWith.Simps.apply initialize_simps_projections HomotopyWith (toHomotopy_toContinuousMap_toFun → apply, -toHomotopy_toContinuousMap) @[continuity] protected theorem continuous (F : HomotopyWith f₀ f₁ P) : Continuous F := F.continuous_toFun #align continuous_map.homotopy_with.continuous ContinuousMap.HomotopyWith.continuous @[simp] theorem apply_zero (F : HomotopyWith f₀ f₁ P) (x : X) : F (0, x) = f₀ x := F.map_zero_left x #align continuous_map.homotopy_with.apply_zero ContinuousMap.HomotopyWith.apply_zero @[simp] theorem apply_one (F : HomotopyWith f₀ f₁ P) (x : X) : F (1, x) = f₁ x := F.map_one_left x #align continuous_map.homotopy_with.apply_one ContinuousMap.HomotopyWith.apply_one -- Porting note: removed `simp` theorem coe_toContinuousMap (F : HomotopyWith f₀ f₁ P) : ⇑F.toContinuousMap = F := rfl #align continuous_map.homotopy_with.coe_to_continuous_map ContinuousMap.HomotopyWith.coe_toContinuousMap @[simp] theorem coe_toHomotopy (F : HomotopyWith f₀ f₁ P) : ⇑F.toHomotopy = F := rfl #align continuous_map.homotopy_with.coe_to_homotopy ContinuousMap.HomotopyWith.coe_toHomotopy theorem prop (F : HomotopyWith f₀ f₁ P) (t : I) : P (F.toHomotopy.curry t) := F.prop' t #align continuous_map.homotopy_with.prop ContinuousMap.HomotopyWith.prop theorem extendProp (F : HomotopyWith f₀ f₁ P) (t : ℝ) : P (F.toHomotopy.extend t) := F.prop _ #align continuous_map.homotopy_with.extend_prop ContinuousMap.HomotopyWith.extendProp end variable {P : C(X, Y) → Prop} /-- Given a continuous function `f`, and a proof `h : P f`, we can define a `HomotopyWith f f P` by `F (t, x) = f x` -/ @[simps!] def refl (f : C(X, Y)) (hf : P f) : HomotopyWith f f P where toHomotopy := Homotopy.refl f prop' := fun _ => hf #align continuous_map.homotopy_with.refl ContinuousMap.HomotopyWith.refl instance : Inhabited (HomotopyWith (ContinuousMap.id X) (ContinuousMap.id X) fun _ => True) := ⟨HomotopyWith.refl _ trivial⟩ /-- Given a `HomotopyWith f₀ f₁ P`, we can define a `HomotopyWith f₁ f₀ P` by reversing the homotopy. -/ @[simps!] def symm {f₀ f₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) : HomotopyWith f₁ f₀ P where toHomotopy := F.toHomotopy.symm prop' := fun t => F.prop (σ t) #align continuous_map.homotopy_with.symm ContinuousMap.HomotopyWith.symm @[simp] theorem symm_symm {f₀ f₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) : F.symm.symm = F := ext <| Homotopy.congr_fun <| Homotopy.symm_symm _ #align continuous_map.homotopy_with.symm_symm ContinuousMap.HomotopyWith.symm_symm theorem symm_bijective {f₀ f₁ : C(X, Y)} : Function.Bijective (HomotopyWith.symm : HomotopyWith f₀ f₁ P → HomotopyWith f₁ f₀ P) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- Given `HomotopyWith f₀ f₁ P` and `HomotopyWith f₁ f₂ P`, we can define a `HomotopyWith f₀ f₂ P` by putting the first homotopy on `[0, 1/2]` and the second on `[1/2, 1]`. -/ def trans {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) : HomotopyWith f₀ f₂ P := { F.toHomotopy.trans G.toHomotopy with prop' := fun t => by simp only [Homotopy.trans] change P ⟨fun _ => ite ((t : ℝ) ≤ _) _ _, _⟩ split_ifs · exact F.extendProp _ · exact G.extendProp _ } #align continuous_map.homotopy_with.trans ContinuousMap.HomotopyWith.trans theorem trans_apply {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) (x : I × X) : (F.trans G) x = if h : (x.1 : ℝ) ≤ 1 / 2 then F (⟨2 * x.1, (unitInterval.mul_pos_mem_iff zero_lt_two).2 ⟨x.1.2.1, h⟩⟩, x.2) else G (⟨2 * x.1 - 1, unitInterval.two_mul_sub_one_mem_iff.2 ⟨(not_le.1 h).le, x.1.2.2⟩⟩, x.2) := Homotopy.trans_apply _ _ _ #align continuous_map.homotopy_with.trans_apply ContinuousMap.HomotopyWith.trans_apply theorem symm_trans {f₀ f₁ f₂ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (G : HomotopyWith f₁ f₂ P) : (F.trans G).symm = G.symm.trans F.symm := ext <| Homotopy.congr_fun <| Homotopy.symm_trans _ _ #align continuous_map.homotopy_with.symm_trans ContinuousMap.HomotopyWith.symm_trans /-- Casting a `HomotopyWith f₀ f₁ P` to a `HomotopyWith g₀ g₁ P` where `f₀ = g₀` and `f₁ = g₁`. -/ @[simps!] def cast {f₀ f₁ g₀ g₁ : C(X, Y)} (F : HomotopyWith f₀ f₁ P) (h₀ : f₀ = g₀) (h₁ : f₁ = g₁) : HomotopyWith g₀ g₁ P where toHomotopy := F.toHomotopy.cast h₀ h₁ prop' := F.prop #align continuous_map.homotopy_with.cast ContinuousMap.HomotopyWith.cast end HomotopyWith /-- Given continuous maps `f₀` and `f₁`, we say `f₀` and `f₁` are homotopic with respect to the predicate `P` if there exists a `HomotopyWith f₀ f₁ P`. -/ def HomotopicWith (f₀ f₁ : C(X, Y)) (P : C(X, Y) → Prop) : Prop := Nonempty (HomotopyWith f₀ f₁ P) #align continuous_map.homotopic_with ContinuousMap.HomotopicWith namespace HomotopicWith variable {P : C(X, Y) → Prop} -- Porting note: removed @[refl] theorem refl (f : C(X, Y)) (hf : P f) : HomotopicWith f f P := ⟨HomotopyWith.refl f hf⟩ #align continuous_map.homotopic_with.refl ContinuousMap.HomotopicWith.refl @[symm] theorem symm ⦃f g : C(X, Y)⦄ (h : HomotopicWith f g P) : HomotopicWith g f P := ⟨h.some.symm⟩ #align continuous_map.homotopic_with.symm ContinuousMap.HomotopicWith.symm -- Note: this was formerly tagged with `@[trans]`, and although the `trans` attribute accepted it -- the `trans` tactic could not use it. -- An update to the trans tactic coming in mathlib4#7014 will reject this attribute. -- It could be restored by changing the argument order to `HomotopicWith P f g`. @[trans] theorem trans ⦃f g h : C(X, Y)⦄ (h₀ : HomotopicWith f g P) (h₁ : HomotopicWith g h P) : HomotopicWith f h P := ⟨h₀.some.trans h₁.some⟩ #align continuous_map.homotopic_with.trans ContinuousMap.HomotopicWith.trans end HomotopicWith /-- A `HomotopyRel f₀ f₁ S` is a homotopy between `f₀` and `f₁` which is fixed on the points in `S`. -/ abbrev HomotopyRel (f₀ f₁ : C(X, Y)) (S : Set X) := HomotopyWith f₀ f₁ fun f ↦ ∀ x ∈ S, f x = f₀ x #align continuous_map.homotopy_rel ContinuousMap.HomotopyRel namespace HomotopyRel section variable {f₀ f₁ : C(X, Y)} {S : Set X} theorem eq_fst (F : HomotopyRel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) : F (t, x) = f₀ x := F.prop t x hx #align continuous_map.homotopy_rel.eq_fst ContinuousMap.HomotopyRel.eq_fst
Mathlib/Topology/Homotopy/Basic.lean
600
601
theorem eq_snd (F : HomotopyRel f₀ f₁ S) (t : I) {x : X} (hx : x ∈ S) : F (t, x) = f₁ x := by
rw [F.eq_fst t hx, ← F.eq_fst 1 hx, F.apply_one]
/- 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, Scott Morrison, Apurva Nakade -/ import Mathlib.Algebra.Ring.Int import Mathlib.SetTheory.Game.PGame import Mathlib.Tactic.Abel #align_import set_theory.game.basic from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # 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 open 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 #align game SetTheory.Game namespace Game -- Porting note (#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 add_left_neg := Quotient.ind <| fun x => Quot.sound (add_left_neg_equiv x) add_comm := by rintro ⟨x⟩ ⟨y⟩ exact Quot.sound add_comm_equiv nsmul := nsmulRec zsmul := zsmulRec instance : Inhabited Game := ⟨0⟩ instance instPartialOrderGame : PartialOrder Game where le := Quotient.lift₂ (· ≤ ·) fun x₁ y₁ x₂ y₂ 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 x₁ y₁ x₂ y₂ 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) #align game.lf SetTheory.Game.LF local infixl:50 " ⧏ " => LF /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_le : ∀ {x y : Game}, ¬x ≤ y ↔ y ⧏ x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_le #align game.not_le SetTheory.Game.not_le /-- On `Game`, simp-normal inequalities should use as few negations as possible. -/ @[simp] theorem not_lf : ∀ {x y : Game}, ¬x ⧏ y ↔ y ≤ x := by rintro ⟨x⟩ ⟨y⟩ exact PGame.not_lf #align game.not_lf SetTheory.Game.not_lf -- 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. -/ -- Porting note: In a lot of places, I had to add explicitely 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 PGame.le_iff_game_le {x y : PGame} : x ≤ y ↔ (⟦x⟧ : Game) ≤ ⟦y⟧ := Iff.rfl #align game.pgame.le_iff_game_le SetTheory.Game.PGame.le_iff_game_le theorem PGame.lf_iff_game_lf {x y : PGame} : PGame.LF x y ↔ ⟦x⟧ ⧏ ⟦y⟧ := Iff.rfl #align game.pgame.lf_iff_game_lf SetTheory.Game.PGame.lf_iff_game_lf theorem PGame.lt_iff_game_lt {x y : PGame} : x < y ↔ (⟦x⟧ : Game) < ⟦y⟧ := Iff.rfl #align game.pgame.lt_iff_game_lt SetTheory.Game.PGame.lt_iff_game_lt theorem PGame.equiv_iff_game_eq {x y : PGame} : x ≈ y ↔ (⟦x⟧ : Game) = ⟦y⟧ := (@Quotient.eq' _ _ x y).symm #align game.pgame.equiv_iff_game_eq SetTheory.Game.PGame.equiv_iff_game_eq /-- 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) #align game.fuzzy SetTheory.Game.Fuzzy local infixl:50 " ‖ " => Fuzzy theorem PGame.fuzzy_iff_game_fuzzy {x y : PGame} : PGame.Fuzzy x y ↔ ⟦x⟧ ‖ ⟦y⟧ := Iff.rfl #align game.pgame.fuzzy_iff_game_fuzzy SetTheory.Game.PGame.fuzzy_iff_game_fuzzy instance covariantClass_add_le : CovariantClass Game Game (· + ·) (· ≤ ·) := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_left _ _ _ _ b c h a⟩ #align game.covariant_class_add_le SetTheory.Game.covariantClass_add_le instance covariantClass_swap_add_le : CovariantClass Game Game (swap (· + ·)) (· ≤ ·) := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_le_add_right _ _ _ _ b c h a⟩ #align game.covariant_class_swap_add_le SetTheory.Game.covariantClass_swap_add_le instance covariantClass_add_lt : CovariantClass Game Game (· + ·) (· < ·) := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_left _ _ _ _ b c h a⟩ #align game.covariant_class_add_lt SetTheory.Game.covariantClass_add_lt instance covariantClass_swap_add_lt : CovariantClass Game Game (swap (· + ·)) (· < ·) := ⟨by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h exact @add_lt_add_right _ _ _ _ b c h a⟩ #align game.covariant_class_swap_add_lt SetTheory.Game.covariantClass_swap_add_lt 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 #align game.add_lf_add_right SetTheory.Game.add_lf_add_right 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 #align game.add_lf_add_left SetTheory.Game.add_lf_add_left instance orderedAddCommGroup : OrderedAddCommGroup Game := { Game.instAddCommGroupWithOneGame, Game.instPartialOrderGame with add_le_add_left := @add_le_add_left _ _ _ Game.covariantClass_add_le } #align game.ordered_add_comm_group SetTheory.Game.orderedAddCommGroup /-- 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}) #align game.bdd_above_of_small SetTheory.Game.bddAbove_of_small /-- 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}) #align game.bdd_below_of_small SetTheory.Game.bddBelow_of_small end Game namespace PGame @[simp] theorem quot_neg (a : PGame) : (⟦-a⟧ : Game) = -⟦a⟧ := rfl #align pgame.quot_neg SetTheory.PGame.quot_neg @[simp] theorem quot_add (a b : PGame) : ⟦a + b⟧ = (⟦a⟧ : Game) + ⟦b⟧ := rfl #align pgame.quot_add SetTheory.PGame.quot_add @[simp] theorem quot_sub (a b : PGame) : ⟦a - b⟧ = (⟦a⟧ : Game) - ⟦b⟧ := rfl #align pgame.quot_sub SetTheory.PGame.quot_sub 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⟧ := by exact Quot.sound (equiv_of_mk_equiv L R (fun _ => Game.PGame.equiv_iff_game_eq.2 (hl _)) (fun _ => Game.PGame.equiv_iff_game_eq.2 (hr _))) #align pgame.quot_eq_of_mk_quot_eq SetTheory.PGame.quot_eq_of_mk'_quot_eq /-! 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, x*yL + xR*y - xR*yL }`. -/ instance : Mul PGame.{u} := ⟨fun x y => by induction' x with xl xr _ _ IHxl IHxr generalizing y induction' y with yl yr yL yR IHyl IHyr have y := mk yl yr yL yR refine ⟨Sum (xl × yl) (xr × yr), Sum (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 = Sum (x.LeftMoves × y.LeftMoves) (x.RightMoves × y.RightMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl #align pgame.left_moves_mul SetTheory.PGame.leftMoves_mul theorem rightMoves_mul : ∀ x y : PGame.{u}, (x * y).RightMoves = Sum (x.LeftMoves × y.RightMoves) (x.RightMoves × y.LeftMoves) | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl #align pgame.right_moves_mul SetTheory.PGame.rightMoves_mul /-- 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} : Sum (x.LeftMoves × y.LeftMoves) (x.RightMoves × y.RightMoves) ≃ (x * y).LeftMoves := Equiv.cast (leftMoves_mul x y).symm #align pgame.to_left_moves_mul SetTheory.PGame.toLeftMovesMul /-- 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} : Sum (x.LeftMoves × y.RightMoves) (x.RightMoves × y.LeftMoves) ≃ (x * y).RightMoves := Equiv.cast (rightMoves_mul x y).symm #align pgame.to_right_moves_mul SetTheory.PGame.toRightMovesMul @[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 #align pgame.mk_mul_move_left_inl SetTheory.PGame.mk_mul_moveLeft_inl @[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 #align pgame.mul_move_left_inl SetTheory.PGame.mul_moveLeft_inl @[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 #align pgame.mk_mul_move_left_inr SetTheory.PGame.mk_mul_moveLeft_inr @[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 #align pgame.mul_move_left_inr SetTheory.PGame.mul_moveLeft_inr @[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 #align pgame.mk_mul_move_right_inl SetTheory.PGame.mk_mul_moveRight_inl @[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 #align pgame.mul_move_right_inl SetTheory.PGame.mul_moveRight_inl @[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 #align pgame.mk_mul_move_right_inr SetTheory.PGame.mk_mul_moveRight_inr @[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 #align pgame.mul_move_right_inr SetTheory.PGame.mul_moveRight_inr -- @[simp] -- Porting note: simpNF linter complains 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 #align pgame.neg_mk_mul_move_left_inl SetTheory.PGame.neg_mk_mul_moveLeft_inl -- @[simp] -- Porting note: simpNF linter complains 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 #align pgame.neg_mk_mul_move_left_inr SetTheory.PGame.neg_mk_mul_moveLeft_inr -- @[simp] -- Porting note: simpNF linter complains 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 #align pgame.neg_mk_mul_move_right_inl SetTheory.PGame.neg_mk_mul_moveRight_inl -- @[simp] -- Porting note: simpNF linter complains 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 #align pgame.neg_mk_mul_move_right_inr SetTheory.PGame.neg_mk_mul_moveRight_inr 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 #align pgame.left_moves_mul_cases SetTheory.PGame.leftMoves_mul_cases
Mathlib/SetTheory/Game/Basic.lean
404
410
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
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.MvPolynomial.Basic #align_import ring_theory.algebraic_independent from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Algebraic Independence This file defines algebraic independence of a family of element of an `R` algebra. ## Main definitions * `AlgebraicIndependent` - `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. * `AlgebraicIndependent.repr` - The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. ## References * [Stacks: Transcendence](https://stacks.math.columbia.edu/tag/030D) ## TODO Define the transcendence degree and show it is independent of the choice of a transcendence basis. ## Tags transcendence basis, transcendence degree, transcendence -/ noncomputable section open Function Set Subalgebra MvPolynomial Algebra open scoped Classical universe x u v w variable {ι : Type*} {ι' : Type*} (R : Type*) {K : Type*} variable {A : Type*} {A' A'' : Type*} {V : Type u} {V' : Type*} variable (x : ι → A) variable [CommRing R] [CommRing A] [CommRing A'] [CommRing A''] variable [Algebra R A] [Algebra R A'] [Algebra R A''] variable {a b : R} /-- `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. -/ def AlgebraicIndependent : Prop := Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) #align algebraic_independent AlgebraicIndependent variable {R} {x} theorem algebraicIndependent_iff_ker_eq_bot : AlgebraicIndependent R x ↔ RingHom.ker (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom = ⊥ := RingHom.injective_iff_ker_eq_bot _ #align algebraic_independent_iff_ker_eq_bot algebraicIndependent_iff_ker_eq_bot theorem algebraicIndependent_iff : AlgebraicIndependent R x ↔ ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := injective_iff_map_eq_zero _ #align algebraic_independent_iff algebraicIndependent_iff theorem AlgebraicIndependent.eq_zero_of_aeval_eq_zero (h : AlgebraicIndependent R x) : ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := algebraicIndependent_iff.1 h #align algebraic_independent.eq_zero_of_aeval_eq_zero AlgebraicIndependent.eq_zero_of_aeval_eq_zero theorem algebraicIndependent_iff_injective_aeval : AlgebraicIndependent R x ↔ Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) := Iff.rfl #align algebraic_independent_iff_injective_aeval algebraicIndependent_iff_injective_aeval @[simp] theorem algebraicIndependent_empty_type_iff [IsEmpty ι] : AlgebraicIndependent R x ↔ Injective (algebraMap R A) := by have : aeval x = (Algebra.ofId R A).comp (@isEmptyAlgEquiv R ι _ _).toAlgHom := by ext i exact IsEmpty.elim' ‹IsEmpty ι› i rw [AlgebraicIndependent, this, ← Injective.of_comp_iff' _ (@isEmptyAlgEquiv R ι _ _).bijective] rfl #align algebraic_independent_empty_type_iff algebraicIndependent_empty_type_iff namespace AlgebraicIndependent variable (hx : AlgebraicIndependent R x) theorem algebraMap_injective : Injective (algebraMap R A) := by simpa [Function.comp] using (Injective.of_comp_iff (algebraicIndependent_iff_injective_aeval.1 hx) MvPolynomial.C).2 (MvPolynomial.C_injective _ _) #align algebraic_independent.algebra_map_injective AlgebraicIndependent.algebraMap_injective theorem linearIndependent : LinearIndependent R x := by rw [linearIndependent_iff_injective_total] have : Finsupp.total ι A R x = (MvPolynomial.aeval x).toLinearMap.comp (Finsupp.total ι _ R X) := by ext simp rw [this] refine hx.comp ?_ rw [← linearIndependent_iff_injective_total] exact linearIndependent_X _ _ #align algebraic_independent.linear_independent AlgebraicIndependent.linearIndependent protected theorem injective [Nontrivial R] : Injective x := hx.linearIndependent.injective #align algebraic_independent.injective AlgebraicIndependent.injective theorem ne_zero [Nontrivial R] (i : ι) : x i ≠ 0 := hx.linearIndependent.ne_zero i #align algebraic_independent.ne_zero AlgebraicIndependent.ne_zero theorem comp (f : ι' → ι) (hf : Function.Injective f) : AlgebraicIndependent R (x ∘ f) := by intro p q simpa [aeval_rename, (rename_injective f hf).eq_iff] using @hx (rename f p) (rename f q) #align algebraic_independent.comp AlgebraicIndependent.comp theorem coe_range : AlgebraicIndependent R ((↑) : range x → A) := by simpa using hx.comp _ (rangeSplitting_injective x) #align algebraic_independent.coe_range AlgebraicIndependent.coe_range theorem map {f : A →ₐ[R] A'} (hf_inj : Set.InjOn f (adjoin R (range x))) : AlgebraicIndependent R (f ∘ x) := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp have h : ∀ p : MvPolynomial ι R, aeval x p ∈ (@aeval R _ _ _ _ _ ((↑) : range x → A)).range := by intro p rw [AlgHom.mem_range] refine ⟨MvPolynomial.rename (codRestrict x (range x) mem_range_self) p, ?_⟩ simp [Function.comp, aeval_rename] intro x y hxy rw [this] at hxy rw [adjoin_eq_range] at hf_inj exact hx (hf_inj (h x) (h y) hxy) #align algebraic_independent.map AlgebraicIndependent.map theorem map' {f : A →ₐ[R] A'} (hf_inj : Injective f) : AlgebraicIndependent R (f ∘ x) := hx.map hf_inj.injOn #align algebraic_independent.map' AlgebraicIndependent.map' theorem of_comp (f : A →ₐ[R] A') (hfv : AlgebraicIndependent R (f ∘ x)) : AlgebraicIndependent R x := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp rw [AlgebraicIndependent, this, AlgHom.coe_comp] at hfv exact hfv.of_comp #align algebraic_independent.of_comp AlgebraicIndependent.of_comp end AlgebraicIndependent open AlgebraicIndependent theorem AlgHom.algebraicIndependent_iff (f : A →ₐ[R] A') (hf : Injective f) : AlgebraicIndependent R (f ∘ x) ↔ AlgebraicIndependent R x := ⟨fun h => h.of_comp f, fun h => h.map hf.injOn⟩ #align alg_hom.algebraic_independent_iff AlgHom.algebraicIndependent_iff @[nontriviality] theorem algebraicIndependent_of_subsingleton [Subsingleton R] : AlgebraicIndependent R x := algebraicIndependent_iff.2 fun _ _ => Subsingleton.elim _ _ #align algebraic_independent_of_subsingleton algebraicIndependent_of_subsingleton theorem algebraicIndependent_equiv (e : ι ≃ ι') {f : ι' → A} : AlgebraicIndependent R (f ∘ e) ↔ AlgebraicIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align algebraic_independent_equiv algebraicIndependent_equiv theorem algebraicIndependent_equiv' (e : ι ≃ ι') {f : ι' → A} {g : ι → A} (h : f ∘ e = g) : AlgebraicIndependent R g ↔ AlgebraicIndependent R f := h ▸ algebraicIndependent_equiv e #align algebraic_independent_equiv' algebraicIndependent_equiv' theorem algebraicIndependent_subtype_range {ι} {f : ι → A} (hf : Injective f) : AlgebraicIndependent R ((↑) : range f → A) ↔ AlgebraicIndependent R f := Iff.symm <| algebraicIndependent_equiv' (Equiv.ofInjective f hf) rfl #align algebraic_independent_subtype_range algebraicIndependent_subtype_range alias ⟨AlgebraicIndependent.of_subtype_range, _⟩ := algebraicIndependent_subtype_range #align algebraic_independent.of_subtype_range AlgebraicIndependent.of_subtype_range theorem algebraicIndependent_image {ι} {s : Set ι} {f : ι → A} (hf : Set.InjOn f s) : (AlgebraicIndependent R fun x : s => f x) ↔ AlgebraicIndependent R fun x : f '' s => (x : A) := algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align algebraic_independent_image algebraicIndependent_image theorem algebraicIndependent_adjoin (hs : AlgebraicIndependent R x) : @AlgebraicIndependent ι R (adjoin R (range x)) (fun i : ι => ⟨x i, subset_adjoin (mem_range_self i)⟩) _ _ _ := AlgebraicIndependent.of_comp (adjoin R (range x)).val hs #align algebraic_independent_adjoin algebraicIndependent_adjoin /-- A set of algebraically independent elements in an algebra `A` over a ring `K` is also algebraically independent over a subring `R` of `K`. -/ theorem AlgebraicIndependent.restrictScalars {K : Type*} [CommRing K] [Algebra R K] [Algebra K A] [IsScalarTower R K A] (hinj : Function.Injective (algebraMap R K)) (ai : AlgebraicIndependent K x) : AlgebraicIndependent R x := by have : (aeval x : MvPolynomial ι K →ₐ[K] A).toRingHom.comp (MvPolynomial.map (algebraMap R K)) = (aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom := by ext <;> simp [algebraMap_eq_smul_one] show Injective (aeval x).toRingHom rw [← this, RingHom.coe_comp] exact Injective.comp ai (MvPolynomial.map_injective _ hinj) #align algebraic_independent.restrict_scalars AlgebraicIndependent.restrictScalars /-- Every finite subset of an algebraically independent set is algebraically independent. -/ theorem algebraicIndependent_finset_map_embedding_subtype (s : Set A) (li : AlgebraicIndependent R ((↑) : s → A)) (t : Finset s) : AlgebraicIndependent R ((↑) : Finset.map (Embedding.subtype s) t → A) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert AlgebraicIndependent.comp li f _ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _, rfl⟩ := hx obtain ⟨b, _, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align algebraic_independent_finset_map_embedding_subtype algebraicIndependent_finset_map_embedding_subtype /-- If every finite set of algebraically independent element has cardinality at most `n`, then the same is true for arbitrary sets of algebraically independent elements. -/ theorem algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded {n : ℕ} (H : ∀ s : Finset A, (AlgebraicIndependent R fun i : s => (i : A)) → s.card ≤ n) : ∀ s : Set A, AlgebraicIndependent R ((↑) : s → A) → Cardinal.mk s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply algebraicIndependent_finset_map_embedding_subtype _ li #align algebraic_independent_bounded_of_finset_algebraic_independent_bounded algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded section Subtype theorem AlgebraicIndependent.restrict_of_comp_subtype {s : Set ι} (hs : AlgebraicIndependent R (x ∘ (↑) : s → A)) : AlgebraicIndependent R (s.restrict x) := hs #align algebraic_independent.restrict_of_comp_subtype AlgebraicIndependent.restrict_of_comp_subtype variable (R A) theorem algebraicIndependent_empty_iff : AlgebraicIndependent R ((↑) : (∅ : Set A) → A) ↔ Injective (algebraMap R A) := by simp #align algebraic_independent_empty_iff algebraicIndependent_empty_iff variable {R A} theorem AlgebraicIndependent.mono {t s : Set A} (h : t ⊆ s) (hx : AlgebraicIndependent R ((↑) : s → A)) : AlgebraicIndependent R ((↑) : t → A) := by simpa [Function.comp] using hx.comp (inclusion h) (inclusion_injective h) #align algebraic_independent.mono AlgebraicIndependent.mono end Subtype theorem AlgebraicIndependent.to_subtype_range {ι} {f : ι → A} (hf : AlgebraicIndependent R f) : AlgebraicIndependent R ((↑) : range f → A) := by nontriviality R rwa [algebraicIndependent_subtype_range hf.injective] #align algebraic_independent.to_subtype_range AlgebraicIndependent.to_subtype_range theorem AlgebraicIndependent.to_subtype_range' {ι} {f : ι → A} (hf : AlgebraicIndependent R f) {t} (ht : range f = t) : AlgebraicIndependent R ((↑) : t → A) := ht ▸ hf.to_subtype_range #align algebraic_independent.to_subtype_range' AlgebraicIndependent.to_subtype_range' theorem algebraicIndependent_comp_subtype {s : Set ι} : AlgebraicIndependent R (x ∘ (↑) : s → A) ↔ ∀ p ∈ MvPolynomial.supported R s, aeval x p = 0 → p = 0 := by have : (aeval (x ∘ (↑) : s → A) : _ →ₐ[R] _) = (aeval x).comp (rename (↑)) := by ext; simp have : ∀ p : MvPolynomial s R, rename ((↑) : s → ι) p = 0 ↔ p = 0 := (injective_iff_map_eq_zero' (rename ((↑) : s → ι) : MvPolynomial s R →ₐ[R] _).toRingHom).1 (rename_injective _ Subtype.val_injective) simp [algebraicIndependent_iff, supported_eq_range_rename, *] #align algebraic_independent_comp_subtype algebraicIndependent_comp_subtype theorem algebraicIndependent_subtype {s : Set A} : AlgebraicIndependent R ((↑) : s → A) ↔ ∀ p : MvPolynomial A R, p ∈ MvPolynomial.supported R s → aeval id p = 0 → p = 0 := by apply @algebraicIndependent_comp_subtype _ _ _ id #align algebraic_independent_subtype algebraicIndependent_subtype theorem algebraicIndependent_of_finite (s : Set A) (H : ∀ t ⊆ s, t.Finite → AlgebraicIndependent R ((↑) : t → A)) : AlgebraicIndependent R ((↑) : s → A) := algebraicIndependent_subtype.2 fun p hp => algebraicIndependent_subtype.1 (H _ (mem_supported.1 hp) (Finset.finite_toSet _)) _ (by simp) #align algebraic_independent_of_finite algebraicIndependent_of_finite theorem AlgebraicIndependent.image_of_comp {ι ι'} (s : Set ι) (f : ι → ι') (g : ι' → A) (hs : AlgebraicIndependent R fun x : s => g (f x)) : AlgebraicIndependent R fun x : f '' s => g x := by nontriviality R have : InjOn f s := injOn_iff_injective.2 hs.injective.of_comp exact (algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn f s this) rfl).1 hs #align algebraic_independent.image_of_comp AlgebraicIndependent.image_of_comp theorem AlgebraicIndependent.image {ι} {s : Set ι} {f : ι → A} (hs : AlgebraicIndependent R fun x : s => f x) : AlgebraicIndependent R fun x : f '' s => (x : A) := by convert AlgebraicIndependent.image_of_comp s f id hs #align algebraic_independent.image AlgebraicIndependent.image theorem algebraicIndependent_iUnion_of_directed {η : Type*} [Nonempty η] {s : η → Set A} (hs : Directed (· ⊆ ·) s) (h : ∀ i, AlgebraicIndependent R ((↑) : s i → A)) : AlgebraicIndependent R ((↑) : (⋃ i, s i) → A) := by refine algebraicIndependent_of_finite (⋃ i, s i) fun t ht ft => ?_ rcases finite_subset_iUnion ft ht with ⟨I, fi, hI⟩ rcases hs.finset_le fi.toFinset with ⟨i, hi⟩ exact (h i).mono (Subset.trans hI <| iUnion₂_subset fun j hj => hi j (fi.mem_toFinset.2 hj)) #align algebraic_independent_Union_of_directed algebraicIndependent_iUnion_of_directed theorem algebraicIndependent_sUnion_of_directed {s : Set (Set A)} (hsn : s.Nonempty) (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, AlgebraicIndependent R ((↑) : a → A)) : AlgebraicIndependent R ((↑) : ⋃₀ s → A) := by letI : Nonempty s := Nonempty.to_subtype hsn rw [sUnion_eq_iUnion] exact algebraicIndependent_iUnion_of_directed hs.directed_val (by simpa using h) #align algebraic_independent_sUnion_of_directed algebraicIndependent_sUnion_of_directed
Mathlib/RingTheory/AlgebraicIndependent.lean
338
356
theorem exists_maximal_algebraicIndependent (s t : Set A) (hst : s ⊆ t) (hs : AlgebraicIndependent R ((↑) : s → A)) : ∃ u : Set A, AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t ∧ ∀ x : Set A, AlgebraicIndependent R ((↑) : x → A) → u ⊆ x → x ⊆ t → x = u := by
rcases zorn_subset_nonempty { u : Set A | AlgebraicIndependent R ((↑) : u → A) ∧ s ⊆ u ∧ u ⊆ t } (fun c hc chainc hcn => ⟨⋃₀ c, by refine ⟨⟨algebraicIndependent_sUnion_of_directed hcn chainc.directedOn fun a ha => (hc ha).1, ?_, ?_⟩, ?_⟩ · cases' hcn with x hx exact subset_sUnion_of_subset _ x (hc hx).2.1 hx · exact sUnion_subset fun x hx => (hc hx).2.2 · intro s exact subset_sUnion_of_mem⟩) s ⟨hs, Set.Subset.refl s, hst⟩ with ⟨u, ⟨huai, _, hut⟩, hsu, hx⟩ use u, huai, hsu, hut intro x hxai huv hxt exact hx _ ⟨hxai, _root_.trans hsu huv, hxt⟩ huv
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.Dual /-! # Perfect pairings of modules A perfect pairing of two (left) modules may be defined either as: 1. A bilinear map `M × N → R` such that the induced maps `M → Dual R N` and `N → Dual R M` are both bijective. It follows from this that both `M` and `N` are reflexive modules. 2. A linear equivalence `N ≃ Dual R M` for which `M` is reflexive. (It then follows that `N` is reflexive.) In this file we provide a `PerfectPairing` definition corresponding to 1 above, together with logic to connect 1 and 2. ## Main definitions * `PerfectPairing` * `PerfectPairing.flip` * `PerfectPairing.toDualLeft` * `PerfectPairing.toDualRight` * `LinearEquiv.flip` * `LinearEquiv.isReflexive_of_equiv_dual_of_isReflexive` * `LinearEquiv.toPerfectPairing` -/ open Function Module variable (R M N : Type*) [CommRing R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] /-- A perfect pairing of two (left) modules over a commutative ring. -/ structure PerfectPairing := toLin : M →ₗ[R] N →ₗ[R] R bijectiveLeft : Bijective toLin bijectiveRight : Bijective toLin.flip attribute [nolint docBlame] PerfectPairing.toLin variable {R M N} namespace PerfectPairing instance instFunLike : FunLike (PerfectPairing R M N) M (N →ₗ[R] R) where coe f := f.toLin coe_injective' x y h := by cases x; cases y; simpa using h variable (p : PerfectPairing R M N) /-- Given a perfect pairing between `M` and `N`, we may interchange the roles of `M` and `N`. -/ protected def flip : PerfectPairing R N M where toLin := p.toLin.flip bijectiveLeft := p.bijectiveRight bijectiveRight := p.bijectiveLeft @[simp] lemma flip_flip : p.flip.flip = p := rfl /-- The linear equivalence from `M` to `Dual R N` induced by a perfect pairing. -/ noncomputable def toDualLeft : M ≃ₗ[R] Dual R N := LinearEquiv.ofBijective p.toLin p.bijectiveLeft @[simp] theorem toDualLeft_apply (a : M) : p.toDualLeft a = p a := rfl @[simp] theorem apply_toDualLeft_symm_apply (f : Dual R N) (x : N) : p (p.toDualLeft.symm f) x = f x := by have h := LinearEquiv.apply_symm_apply p.toDualLeft f rw [toDualLeft_apply] at h exact congrFun (congrArg DFunLike.coe h) x /-- The linear equivalence from `N` to `Dual R M` induced by a perfect pairing. -/ noncomputable def toDualRight : N ≃ₗ[R] Dual R M := toDualLeft p.flip @[simp] theorem toDualRight_apply (a : N) : p.toDualRight a = p.flip a := rfl @[simp] theorem apply_apply_toDualRight_symm (x : M) (f : Dual R M) : (p x) (p.toDualRight.symm f) = f x := by have h := LinearEquiv.apply_symm_apply p.toDualRight f rw [toDualRight_apply] at h exact congrFun (congrArg DFunLike.coe h) x theorem toDualLeft_of_toDualRight_symm (x : M) (f : Dual R M) : (p.toDualLeft x) (p.toDualRight.symm f) = f x := by rw [@toDualLeft_apply] exact apply_apply_toDualRight_symm p x f
Mathlib/LinearAlgebra/PerfectPairing.lean
96
100
theorem toDualRight_symm_toDualLeft (x : M) : p.toDualRight.symm.dualMap (p.toDualLeft x) = Dual.eval R M x := by
ext f simp only [LinearEquiv.dualMap_apply, Dual.eval_apply] exact toDualLeft_of_toDualRight_symm p x f
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Monoidal.Category import Mathlib.CategoryTheory.Adjunction.FullyFaithful import Mathlib.CategoryTheory.Products.Basic #align_import category_theory.monoidal.functor from "leanprover-community/mathlib"@"3d7987cda72abc473c7cdbbb075170e9ac620042" /-! # (Lax) monoidal functors A lax monoidal functor `F` between monoidal categories `C` and `D` is a functor between the underlying categories equipped with morphisms * `ε : 𝟙_ D ⟶ F.obj (𝟙_ C)` (called the unit morphism) * `μ X Y : (F.obj X) ⊗ (F.obj Y) ⟶ F.obj (X ⊗ Y)` (called the tensorator, or strength). satisfying various axioms. A monoidal functor is a lax monoidal functor for which `ε` and `μ` are isomorphisms. We show that the composition of (lax) monoidal functors gives a (lax) monoidal functor. See also `CategoryTheory.Monoidal.Functorial` for a typeclass decorating an object-level function with the additional data of a monoidal functor. This is useful when stating that a pre-existing functor is monoidal. See `CategoryTheory.Monoidal.NaturalTransformation` for monoidal natural transformations. We show in `CategoryTheory.Monoidal.Mon_` that lax monoidal functors take monoid objects to monoid objects. ## References See <https://stacks.math.columbia.edu/tag/0FFL>. -/ open CategoryTheory universe v₁ v₂ v₃ u₁ u₂ u₃ open CategoryTheory.Category open CategoryTheory.Functor namespace CategoryTheory section open MonoidalCategory variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] (D : Type u₂) [Category.{v₂} D] [MonoidalCategory.{v₂} D] -- The direction of `left_unitality` and `right_unitality` as simp lemmas may look strange: -- remember the rule of thumb that component indices of natural transformations -- "weigh more" than structural maps. -- (However by this argument `associativity` is currently stated backwards!) /-- A lax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `ε : 𝟙 _D ⟶ F.obj (𝟙_ C)` and `μ X Y : F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)`, satisfying the appropriate coherences. -/ structure LaxMonoidalFunctor extends C ⥤ D where /-- unit morphism -/ ε : 𝟙_ D ⟶ obj (𝟙_ C) /-- tensorator -/ μ : ∀ X Y : C, obj X ⊗ obj Y ⟶ obj (X ⊗ Y) μ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), map f ▷ obj X' ≫ μ Y X' = μ X X' ≫ map (f ▷ X') := by aesop_cat μ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , obj X' ◁ map f ≫ μ X' Y = μ X' X ≫ map (X' ◁ f) := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, μ X Y ▷ obj Z ≫ μ (X ⊗ Y) Z ≫ map (α_ X Y Z).hom = (α_ (obj X) (obj Y) (obj Z)).hom ≫ obj X ◁ μ Y Z ≫ μ X (Y ⊗ Z) := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).hom = ε ▷ obj X ≫ μ (𝟙_ C) X ≫ map (λ_ X).hom := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).hom = obj X ◁ ε ≫ μ X (𝟙_ C) ≫ map (ρ_ X).hom := by aesop_cat #align category_theory.lax_monoidal_functor CategoryTheory.LaxMonoidalFunctor -- Porting note (#11215): TODO: remove this configuration and use the default configuration. -- We keep this to be consistent with Lean 3. -- See also `initialize_simps_projections MonoidalFunctor` below. -- This may require waiting on https://github.com/leanprover-community/mathlib4/pull/2936 initialize_simps_projections LaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_left attribute [reassoc (attr := simp)] LaxMonoidalFunctor.μ_natural_right attribute [simp] LaxMonoidalFunctor.left_unitality attribute [simp] LaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] LaxMonoidalFunctor.associativity -- When `rewrite_search` lands, add @[search] attributes to -- LaxMonoidalFunctor.μ_natural LaxMonoidalFunctor.left_unitality -- LaxMonoidalFunctor.right_unitality LaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.μ_natural (F : LaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : (F.map f ⊗ F.map g) ≫ F.μ Y Y' = F.μ X X' ≫ F.map (f ⊗ g) := by simp [tensorHom_def] /-- A constructor for lax monoidal functors whose axioms are described by `tensorHom` instead of `whiskerLeft` and `whiskerRight`. -/ @[simps] def LaxMonoidalFunctor.ofTensorHom (F : C ⥤ D) /- unit morphism -/ (ε : 𝟙_ D ⟶ F.obj (𝟙_ C)) /- tensorator -/ (μ : ∀ X Y : C, F.obj X ⊗ F.obj Y ⟶ F.obj (X ⊗ Y)) (μ_natural : ∀ {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y'), (F.map f ⊗ F.map g) ≫ μ Y Y' = μ X X' ≫ F.map (f ⊗ g) := by aesop_cat) /- associativity of the tensorator -/ (associativity : ∀ X Y Z : C, (μ X Y ⊗ 𝟙 (F.obj Z)) ≫ μ (X ⊗ Y) Z ≫ F.map (α_ X Y Z).hom = (α_ (F.obj X) (F.obj Y) (F.obj Z)).hom ≫ (𝟙 (F.obj X) ⊗ μ Y Z) ≫ μ X (Y ⊗ Z) := by aesop_cat) /- unitality -/ (left_unitality : ∀ X : C, (λ_ (F.obj X)).hom = (ε ⊗ 𝟙 (F.obj X)) ≫ μ (𝟙_ C) X ≫ F.map (λ_ X).hom := by aesop_cat) (right_unitality : ∀ X : C, (ρ_ (F.obj X)).hom = (𝟙 (F.obj X) ⊗ ε) ≫ μ X (𝟙_ C) ≫ F.map (ρ_ X).hom := by aesop_cat) : LaxMonoidalFunctor C D where obj := F.obj map := F.map map_id := F.map_id map_comp := F.map_comp ε := ε μ := μ μ_natural_left := fun f X' => by simp_rw [← tensorHom_id, ← F.map_id, μ_natural] μ_natural_right := fun X' f => by simp_rw [← id_tensorHom, ← F.map_id, μ_natural] associativity := fun X Y Z => by simp_rw [← tensorHom_id, ← id_tensorHom, associativity] left_unitality := fun X => by simp_rw [← tensorHom_id, left_unitality] right_unitality := fun X => by simp_rw [← id_tensorHom, right_unitality] @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.left_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (λ_ (F.obj X)).inv ≫ F.ε ▷ F.obj X ≫ F.μ (𝟙_ C) X = F.map (λ_ X).inv := by rw [Iso.inv_comp_eq, F.left_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.left_unitality_inv CategoryTheory.LaxMonoidalFunctor.left_unitality_inv @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.right_unitality_inv (F : LaxMonoidalFunctor C D) (X : C) : (ρ_ (F.obj X)).inv ≫ F.obj X ◁ F.ε ≫ F.μ X (𝟙_ C) = F.map (ρ_ X).inv := by rw [Iso.inv_comp_eq, F.right_unitality, Category.assoc, Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.right_unitality_inv CategoryTheory.LaxMonoidalFunctor.right_unitality_inv @[reassoc (attr := simp)] theorem LaxMonoidalFunctor.associativity_inv (F : LaxMonoidalFunctor C D) (X Y Z : C) : F.obj X ◁ F.μ Y Z ≫ F.μ X (Y ⊗ Z) ≫ F.map (α_ X Y Z).inv = (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv ≫ F.μ X Y ▷ F.obj Z ≫ F.μ (X ⊗ Y) Z := by rw [Iso.eq_inv_comp, ← F.associativity_assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, comp_id] #align category_theory.lax_monoidal_functor.associativity_inv CategoryTheory.LaxMonoidalFunctor.associativity_inv end /-- A oplax monoidal functor is a functor `F : C ⥤ D` between monoidal categories, equipped with morphisms `η : F.obj (𝟙_ C) ⟶ 𝟙 _D` and `δ X Y : F.obj (X ⊗ Y) ⟶ F.obj X ⊗ F.obj Y`, satisfying the appropriate coherences. -/ structure OplaxMonoidalFunctor extends C ⥤ D where /-- counit morphism -/ η : obj (𝟙_ C) ⟶ 𝟙_ D /-- cotensorator -/ δ : ∀ X Y : C, obj (X ⊗ Y) ⟶ obj X ⊗ obj Y δ_natural_left : ∀ {X Y : C} (f : X ⟶ Y) (X' : C), δ X X' ≫ map f ▷ obj X' = map (f ▷ X') ≫ δ Y X' := by aesop_cat δ_natural_right : ∀ {X Y : C} (X' : C) (f : X ⟶ Y) , δ X' X ≫ obj X' ◁ map f = map (X' ◁ f) ≫ δ X' Y := by aesop_cat /-- associativity of the tensorator -/ associativity : ∀ X Y Z : C, δ (X ⊗ Y) Z ≫ δ X Y ▷ obj Z ≫ (α_ (obj X) (obj Y) (obj Z)).hom = map (α_ X Y Z).hom ≫ δ X (Y ⊗ Z) ≫ obj X ◁ δ Y Z := by aesop_cat -- unitality left_unitality : ∀ X : C, (λ_ (obj X)).inv = map (λ_ X).inv ≫ δ (𝟙_ C) X ≫ η ▷ obj X := by aesop_cat right_unitality : ∀ X : C, (ρ_ (obj X)).inv = map (ρ_ X).inv ≫ δ X (𝟙_ C) ≫ obj X ◁ η := by aesop_cat initialize_simps_projections OplaxMonoidalFunctor (+toFunctor, -obj, -map) attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_left attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.δ_natural_right attribute [simp] OplaxMonoidalFunctor.left_unitality attribute [simp] OplaxMonoidalFunctor.right_unitality attribute [reassoc (attr := simp)] OplaxMonoidalFunctor.associativity section variable {C D} @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.δ_natural (F : OplaxMonoidalFunctor C D) {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.δ X X' ≫ (F.map f ⊗ F.map g) = F.map (f ⊗ g) ≫ F.δ Y Y' := by simp [tensorHom_def] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.left_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ (𝟙_ C) X ≫ F.η ▷ F.obj X ≫ (λ_ (F.obj X)).hom = F.map (λ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.left_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.right_unitality_hom (F : OplaxMonoidalFunctor C D) (X : C) : F.δ X (𝟙_ C) ≫ F.obj X ◁ F.η ≫ (ρ_ (F.obj X)).hom = F.map (ρ_ X).hom := by rw [← Category.assoc, ← Iso.eq_comp_inv, F.right_unitality, ← Category.assoc, ← F.toFunctor.map_comp, Iso.hom_inv_id, F.toFunctor.map_id, id_comp] @[reassoc (attr := simp)] theorem OplaxMonoidalFunctor.associativity_inv (F : OplaxMonoidalFunctor C D) (X Y Z : C) : F.δ X (Y ⊗ Z) ≫ F.obj X ◁ F.δ Y Z ≫ (α_ (F.obj X) (F.obj Y) (F.obj Z)).inv = F.map (α_ X Y Z).inv ≫ F.δ (X ⊗ Y) Z ≫ F.δ X Y ▷ F.obj Z := by rw [← Category.assoc, Iso.comp_inv_eq, Category.assoc, Category.assoc, F.associativity, ← Category.assoc, ← F.toFunctor.map_comp, Iso.inv_hom_id, F.toFunctor.map_id, id_comp] end /-- A monoidal functor is a lax monoidal functor for which the tensorator and unitor are isomorphisms. See <https://stacks.math.columbia.edu/tag/0FFL>. -/ structure MonoidalFunctor extends LaxMonoidalFunctor.{v₁, v₂} C D where ε_isIso : IsIso ε := by infer_instance μ_isIso : ∀ X Y : C, IsIso (μ X Y) := by infer_instance #align category_theory.monoidal_functor CategoryTheory.MonoidalFunctor -- See porting note on `initialize_simps_projections LaxMonoidalFunctor` initialize_simps_projections MonoidalFunctor (+toLaxMonoidalFunctor, -obj, -map, -ε, -μ) attribute [instance] MonoidalFunctor.ε_isIso MonoidalFunctor.μ_isIso variable {C D} /-- The unit morphism of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.εIso (F : MonoidalFunctor.{v₁, v₂} C D) : 𝟙_ D ≅ F.obj (𝟙_ C) := asIso F.ε #align category_theory.monoidal_functor.ε_iso CategoryTheory.MonoidalFunctor.εIso /-- The tensorator of a (strong) monoidal functor as an isomorphism. -/ noncomputable def MonoidalFunctor.μIso (F : MonoidalFunctor.{v₁, v₂} C D) (X Y : C) : F.obj X ⊗ F.obj Y ≅ F.obj (X ⊗ Y) := asIso (F.μ X Y) #align category_theory.monoidal_functor.μ_iso CategoryTheory.MonoidalFunctor.μIso /-- The underlying oplax monoidal functor of a (strong) monoidal functor. -/ @[simps] noncomputable def MonoidalFunctor.toOplaxMonoidalFunctor (F : MonoidalFunctor C D) : OplaxMonoidalFunctor C D := { F with η := inv F.ε, δ := fun X Y => inv (F.μ X Y), δ_natural_left := by aesop_cat δ_natural_right := by aesop_cat associativity := by intros X Y Z dsimp rw [IsIso.inv_comp_eq, ← inv_whiskerRight, IsIso.inv_comp_eq] slice_rhs 1 3 => rw [F.associativity] simp left_unitality := by intros X dsimp apply Iso.inv_ext rw [F.left_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp [inv_whiskerRight] right_unitality := by intros X dsimp apply Iso.inv_ext rw [F.right_unitality] slice_lhs 3 4 => rw [← F.map_comp, Iso.hom_inv_id, F.map_id] simp } end open MonoidalCategory namespace LaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : LaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } #align category_theory.lax_monoidal_functor.id CategoryTheory.LaxMonoidalFunctor.id instance : Inhabited (LaxMonoidalFunctor C C) := ⟨id C⟩ end LaxMonoidalFunctor namespace OplaxMonoidalFunctor variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity lax monoidal functor. -/ @[simps] def id : OplaxMonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with η := 𝟙 _ δ := fun X Y => 𝟙 _ } instance : Inhabited (OplaxMonoidalFunctor C C) := ⟨id C⟩ end OplaxMonoidalFunctor namespace MonoidalFunctor section variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable (F : MonoidalFunctor.{v₁, v₂} C D) @[reassoc] theorem map_tensor {X Y X' Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : F.map (f ⊗ g) = inv (F.μ X X') ≫ (F.map f ⊗ F.map g) ≫ F.μ Y Y' := by simp #align category_theory.monoidal_functor.map_tensor CategoryTheory.MonoidalFunctor.map_tensor @[reassoc] theorem map_whiskerLeft (X : C) {Y Z : C} (f : Y ⟶ Z) : F.map (X ◁ f) = inv (F.μ X Y) ≫ F.obj X ◁ F.map f ≫ F.μ X Z := by simp @[reassoc] theorem map_whiskerRight {X Y : C} (f : X ⟶ Y) (Z : C) : F.map (f ▷ Z) = inv (F.μ X Z) ≫ F.map f ▷ F.obj Z ≫ F.μ Y Z := by simp @[reassoc] theorem map_leftUnitor (X : C) : F.map (λ_ X).hom = inv (F.μ (𝟙_ C) X) ≫ inv F.ε ▷ F.obj X ≫ (λ_ (F.obj X)).hom := by simp only [LaxMonoidalFunctor.left_unitality] slice_rhs 2 3 => rw [← comp_whiskerRight] simp simp #align category_theory.monoidal_functor.map_left_unitor CategoryTheory.MonoidalFunctor.map_leftUnitor @[reassoc] theorem map_rightUnitor (X : C) : F.map (ρ_ X).hom = inv (F.μ X (𝟙_ C)) ≫ F.obj X ◁ inv F.ε ≫ (ρ_ (F.obj X)).hom := by simp only [LaxMonoidalFunctor.right_unitality] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp] simp simp #align category_theory.monoidal_functor.map_right_unitor CategoryTheory.MonoidalFunctor.map_rightUnitor /-- The tensorator as a natural isomorphism. -/ noncomputable def μNatIso : Functor.prod F.toFunctor F.toFunctor ⋙ tensor D ≅ tensor C ⋙ F.toFunctor := NatIso.ofComponents (by intros apply F.μIso) (by intros apply F.toLaxMonoidalFunctor.μ_natural) #align category_theory.monoidal_functor.μ_nat_iso CategoryTheory.MonoidalFunctor.μNatIso @[simp] theorem μIso_hom (X Y : C) : (F.μIso X Y).hom = F.μ X Y := rfl #align category_theory.monoidal_functor.μ_iso_hom CategoryTheory.MonoidalFunctor.μIso_hom @[reassoc (attr := simp)] theorem μ_inv_hom_id (X Y : C) : (F.μIso X Y).inv ≫ F.μ X Y = 𝟙 _ := (F.μIso X Y).inv_hom_id #align category_theory.monoidal_functor.μ_inv_hom_id CategoryTheory.MonoidalFunctor.μ_inv_hom_id @[simp] theorem μ_hom_inv_id (X Y : C) : F.μ X Y ≫ (F.μIso X Y).inv = 𝟙 _ := (F.μIso X Y).hom_inv_id #align category_theory.monoidal_functor.μ_hom_inv_id CategoryTheory.MonoidalFunctor.μ_hom_inv_id @[simp] theorem εIso_hom : F.εIso.hom = F.ε := rfl #align category_theory.monoidal_functor.ε_iso_hom CategoryTheory.MonoidalFunctor.εIso_hom @[reassoc (attr := simp)] theorem ε_inv_hom_id : F.εIso.inv ≫ F.ε = 𝟙 _ := F.εIso.inv_hom_id #align category_theory.monoidal_functor.ε_inv_hom_id CategoryTheory.MonoidalFunctor.ε_inv_hom_id @[simp] theorem ε_hom_inv_id : F.ε ≫ F.εIso.inv = 𝟙 _ := F.εIso.hom_inv_id #align category_theory.monoidal_functor.ε_hom_inv_id CategoryTheory.MonoidalFunctor.ε_hom_inv_id /-- Monoidal functors commute with left tensoring up to isomorphism -/ @[simps!] noncomputable def commTensorLeft (X : C) : F.toFunctor ⋙ tensorLeft (F.toFunctor.obj X) ≅ tensorLeft X ⋙ F.toFunctor := NatIso.ofComponents (fun Y => F.μIso X Y) fun f => F.μ_natural_right X f #align category_theory.monoidal_functor.comm_tensor_left CategoryTheory.MonoidalFunctor.commTensorLeft /-- Monoidal functors commute with right tensoring up to isomorphism -/ @[simps!] noncomputable def commTensorRight (X : C) : F.toFunctor ⋙ tensorRight (F.toFunctor.obj X) ≅ tensorRight X ⋙ F.toFunctor := NatIso.ofComponents (fun Y => F.μIso Y X) fun f => F.μ_natural_left f X #align category_theory.monoidal_functor.comm_tensor_right CategoryTheory.MonoidalFunctor.commTensorRight end section variable (C : Type u₁) [Category.{v₁} C] [MonoidalCategory.{v₁} C] /-- The identity monoidal functor. -/ @[simps] def id : MonoidalFunctor.{v₁, v₁} C C := { 𝟭 C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } #align category_theory.monoidal_functor.id CategoryTheory.MonoidalFunctor.id instance : Inhabited (MonoidalFunctor C C) := ⟨id C⟩ end end MonoidalFunctor variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] variable {D : Type u₂} [Category.{v₂} D] [MonoidalCategory.{v₂} D] variable {E : Type u₃} [Category.{v₃} E] [MonoidalCategory.{v₃} E] namespace LaxMonoidalFunctor variable (F : LaxMonoidalFunctor.{v₁, v₂} C D) (G : LaxMonoidalFunctor.{v₂, v₃} D E) /-- The composition of two lax monoidal functors is again lax monoidal. -/ @[simps] def comp : LaxMonoidalFunctor.{v₁, v₃} C E := { F.toFunctor ⋙ G.toFunctor with ε := G.ε ≫ G.map F.ε μ := fun X Y => G.μ (F.obj X) (F.obj Y) ≫ G.map (F.μ X Y) μ_natural_left := by intro X Y f X' simp_rw [comp_obj, F.comp_map, μ_natural_left_assoc, assoc, ← G.map_comp, μ_natural_left] μ_natural_right := by intro X Y f X' simp_rw [comp_obj, F.comp_map, μ_natural_right_assoc, assoc, ← G.map_comp, μ_natural_right] associativity := fun X Y Z => by dsimp simp_rw [comp_whiskerRight, assoc, μ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, assoc, μ_natural_right_assoc] slice_rhs 1 3 => rw [← G.associativity] simp_rw [Category.assoc, ← G.toFunctor.map_comp, F.associativity] } #align category_theory.lax_monoidal_functor.comp CategoryTheory.LaxMonoidalFunctor.comp @[inherit_doc] infixr:80 " ⊗⋙ " => comp end LaxMonoidalFunctor namespace OplaxMonoidalFunctor variable (F : OplaxMonoidalFunctor.{v₁, v₂} C D) (G : OplaxMonoidalFunctor.{v₂, v₃} D E) /-- The composition of two oplax monoidal functors is again oplax monoidal. -/ @[simps] def comp : OplaxMonoidalFunctor.{v₁, v₃} C E := { F.toFunctor ⋙ G.toFunctor with η := G.map F.η ≫ G.η δ := fun X Y => G.map (F.δ X Y) ≫ G.δ (F.obj X) (F.obj Y) δ_natural_left := by intro X Y f X' simp_rw [comp_obj, Functor.comp_map, ← G.map_comp_assoc, ← F.δ_natural_left, assoc, G.δ_natural_left, ← G.map_comp_assoc] δ_natural_right := by intro X Y f X' simp_rw [comp_obj, Functor.comp_map, ← G.map_comp_assoc, ← F.δ_natural_right, assoc, G.δ_natural_right, ← G.map_comp_assoc] associativity := fun X Y Z => by dsimp simp_rw [comp_whiskerRight, assoc, δ_natural_left_assoc, MonoidalCategory.whiskerLeft_comp, δ_natural_right_assoc] slice_rhs 1 3 => simp only [← G.toFunctor.map_comp] rw [← F.associativity] rw [G.associativity] simp only [G.map_comp, Category.assoc] } @[inherit_doc] infixr:80 " ⊗⋙ " => comp end OplaxMonoidalFunctor namespace LaxMonoidalFunctor universe v₀ u₀ variable {B : Type u₀} [Category.{v₀} B] [MonoidalCategory.{v₀} B] variable (F : LaxMonoidalFunctor.{v₀, v₁} B C) (G : LaxMonoidalFunctor.{v₂, v₃} D E) attribute [local simp] μ_natural associativity left_unitality right_unitality /-- The cartesian product of two lax monoidal functors is lax monoidal. -/ @[simps] def prod : LaxMonoidalFunctor (B × D) (C × E) := { F.toFunctor.prod G.toFunctor with ε := (ε F, ε G) μ := fun X Y => (μ F X.1 Y.1, μ G X.2 Y.2) } #align category_theory.lax_monoidal_functor.prod CategoryTheory.LaxMonoidalFunctor.prod end LaxMonoidalFunctor namespace MonoidalFunctor variable (C) /-- The diagonal functor as a monoidal functor. -/ @[simps] def diag : MonoidalFunctor C (C × C) := { Functor.diag C with ε := 𝟙 _ μ := fun X Y => 𝟙 _ } #align category_theory.monoidal_functor.diag CategoryTheory.MonoidalFunctor.diag end MonoidalFunctor namespace LaxMonoidalFunctor variable (F : LaxMonoidalFunctor.{v₁, v₂} C D) (G : LaxMonoidalFunctor.{v₁, v₃} C E) /-- The cartesian product of two lax monoidal functors starting from the same monoidal category `C` is lax monoidal. -/ def prod' : LaxMonoidalFunctor C (D × E) := (MonoidalFunctor.diag C).toLaxMonoidalFunctor ⊗⋙ F.prod G #align category_theory.lax_monoidal_functor.prod' CategoryTheory.LaxMonoidalFunctor.prod' @[simp] theorem prod'_toFunctor : (F.prod' G).toFunctor = F.toFunctor.prod' G.toFunctor := rfl #align category_theory.lax_monoidal_functor.prod'_to_functor CategoryTheory.LaxMonoidalFunctor.prod'_toFunctor @[simp] theorem prod'_ε : (F.prod' G).ε = (F.ε, G.ε) := by dsimp [prod'] simp #align category_theory.lax_monoidal_functor.prod'_ε CategoryTheory.LaxMonoidalFunctor.prod'_ε @[simp]
Mathlib/CategoryTheory/Monoidal/Functor.lean
597
599
theorem prod'_μ (X Y : C) : (F.prod' G).μ X Y = (F.μ X Y, G.μ X Y) := by
dsimp [prod'] simp
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Best, Riccardo Brasca, Eric Rodriguez -/ import Mathlib.Data.PNat.Prime import Mathlib.Algebra.IsPrimePow import Mathlib.NumberTheory.Cyclotomic.Basic import Mathlib.RingTheory.Adjoin.PowerBasis import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval import Mathlib.RingTheory.Norm import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand #align_import number_theory.cyclotomic.primitive_roots from "leanprover-community/mathlib"@"5bfbcca0a7ffdd21cf1682e59106d6c942434a32" /-! # Primitive roots in cyclotomic fields If `IsCyclotomicExtension {n} A B`, we define an element `zeta n A B : B` that is a primitive `n`th-root of unity in `B` and we study its properties. We also prove related theorems under the more general assumption of just being a primitive root, for reasons described in the implementation details section. ## Main definitions * `IsCyclotomicExtension.zeta n A B`: if `IsCyclotomicExtension {n} A B`, than `zeta n A B` is a primitive `n`-th root of unity in `B`. * `IsPrimitiveRoot.powerBasis`: if `K` and `L` are fields such that `IsCyclotomicExtension {n} K L`, then `IsPrimitiveRoot.powerBasis` gives a `K`-power basis for `L` given a primitive root `ζ`. * `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A` and `primitiveroots n A` given by the choice of `ζ`. ## Main results * `IsCyclotomicExtension.zeta_spec`: `zeta n A B` is a primitive `n`-th root of unity. * `IsCyclotomicExtension.finrank`: if `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the `finrank` of a cyclotomic extension is `n.totient`. * `IsPrimitiveRoot.norm_eq_one`: if `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of a primitive root is `1` if `n ≠ 2`. * `IsPrimitiveRoot.sub_one_norm_eq_eval_cyclotomic`: if `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of `ζ - 1` is `eval 1 (cyclotomic n ℤ)`, for a primitive root `ζ`. We also prove the analogous of this result for `zeta`. * `IsPrimitiveRoot.norm_pow_sub_one_of_prime_pow_ne_two` : if `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime, then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` `p ^ (k - s + 1) ≠ 2`. See the following lemmas for similar results. We also prove the analogous of this result for `zeta`. * `IsPrimitiveRoot.norm_sub_one_of_prime_ne_two` : if `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. We also prove the analogous of this result for `zeta`. * `IsPrimitiveRoot.embeddingsEquivPrimitiveRoots`: the equivalence between `L →ₐ[K] A` and `primitiveRoots n A` given by the choice of `ζ`. ## Implementation details `zeta n A B` is defined as any primitive root of unity in `B`, - this must exist, by definition of `IsCyclotomicExtension`. It is not true in general that it is a root of `cyclotomic n B`, but this holds if `isDomain B` and `NeZero (↑n : B)`. `zeta n A B` is defined using `Exists.choose`, which means we cannot control it. For example, in normal mathematics, we can demand that `(zeta p ℤ ℤ[ζₚ] : ℚ(ζₚ))` is equal to `zeta p ℚ ℚ(ζₚ)`, as we are just choosing "an arbitrary primitive root" and we can internally specify that our choices agree. This is not the case here, and it is indeed impossible to prove that these two are equal. Therefore, whenever possible, we prove our results for any primitive root, and only at the "final step", when we need to provide an "explicit" primitive root, we use `zeta`. -/ open Polynomial Algebra Finset FiniteDimensional IsCyclotomicExtension Nat PNat Set open scoped IntermediateField universe u v w z variable {p n : ℕ+} (A : Type w) (B : Type z) (K : Type u) {L : Type v} (C : Type w) variable [CommRing A] [CommRing B] [Algebra A B] [IsCyclotomicExtension {n} A B] section Zeta namespace IsCyclotomicExtension variable (n) /-- If `B` is an `n`-th cyclotomic extension of `A`, then `zeta n A B` is a primitive root of unity in `B`. -/ noncomputable def zeta : B := (exists_prim_root A <| Set.mem_singleton n : ∃ r : B, IsPrimitiveRoot r n).choose #align is_cyclotomic_extension.zeta IsCyclotomicExtension.zeta /-- `zeta n A B` is a primitive `n`-th root of unity. -/ @[simp] theorem zeta_spec : IsPrimitiveRoot (zeta n A B) n := Classical.choose_spec (exists_prim_root A (Set.mem_singleton n) : ∃ r : B, IsPrimitiveRoot r n) #align is_cyclotomic_extension.zeta_spec IsCyclotomicExtension.zeta_spec theorem aeval_zeta [IsDomain B] [NeZero ((n : ℕ) : B)] : aeval (zeta n A B) (cyclotomic n A) = 0 := by rw [aeval_def, ← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff] exact zeta_spec n A B #align is_cyclotomic_extension.aeval_zeta IsCyclotomicExtension.aeval_zeta theorem zeta_isRoot [IsDomain B] [NeZero ((n : ℕ) : B)] : IsRoot (cyclotomic n B) (zeta n A B) := by convert aeval_zeta n A B using 0 rw [IsRoot.def, aeval_def, eval₂_eq_eval_map, map_cyclotomic] #align is_cyclotomic_extension.zeta_is_root IsCyclotomicExtension.zeta_isRoot theorem zeta_pow : zeta n A B ^ (n : ℕ) = 1 := (zeta_spec n A B).pow_eq_one #align is_cyclotomic_extension.zeta_pow IsCyclotomicExtension.zeta_pow end IsCyclotomicExtension end Zeta section NoOrder variable [Field K] [CommRing L] [IsDomain L] [Algebra K L] [IsCyclotomicExtension {n} K L] {ζ : L} (hζ : IsPrimitiveRoot ζ n) namespace IsPrimitiveRoot variable {C} /-- The `PowerBasis` given by a primitive root `η`. -/ @[simps!] protected noncomputable def powerBasis : PowerBasis K L := PowerBasis.map (Algebra.adjoin.powerBasis <| (integral {n} K L).isIntegral ζ) <| (Subalgebra.equivOfEq _ _ (IsCyclotomicExtension.adjoin_primitive_root_eq_top hζ)).trans Subalgebra.topEquiv #align is_primitive_root.power_basis IsPrimitiveRoot.powerBasis theorem powerBasis_gen_mem_adjoin_zeta_sub_one : (hζ.powerBasis K).gen ∈ adjoin K ({ζ - 1} : Set L) := by rw [powerBasis_gen, adjoin_singleton_eq_range_aeval, AlgHom.mem_range] exact ⟨X + 1, by simp⟩ #align is_primitive_root.power_basis_gen_mem_adjoin_zeta_sub_one IsPrimitiveRoot.powerBasis_gen_mem_adjoin_zeta_sub_one /-- The `PowerBasis` given by `η - 1`. -/ @[simps!] noncomputable def subOnePowerBasis : PowerBasis K L := (hζ.powerBasis K).ofGenMemAdjoin (((integral {n} K L).isIntegral ζ).sub isIntegral_one) (hζ.powerBasis_gen_mem_adjoin_zeta_sub_one _) #align is_primitive_root.sub_one_power_basis IsPrimitiveRoot.subOnePowerBasis variable {K} (C) -- We are not using @[simps] to avoid a timeout. /-- The equivalence between `L →ₐ[K] C` and `primitiveRoots n C` given by a primitive root `ζ`. -/ noncomputable def embeddingsEquivPrimitiveRoots (C : Type*) [CommRing C] [IsDomain C] [Algebra K C] (hirr : Irreducible (cyclotomic n K)) : (L →ₐ[K] C) ≃ primitiveRoots n C := (hζ.powerBasis K).liftEquiv.trans { toFun := fun x => by haveI := IsCyclotomicExtension.neZero' n K L haveI hn := NeZero.of_noZeroSMulDivisors K C n refine ⟨x.1, ?_⟩ cases x rwa [mem_primitiveRoots n.pos, ← isRoot_cyclotomic_iff, IsRoot.def, ← map_cyclotomic _ (algebraMap K C), hζ.minpoly_eq_cyclotomic_of_irreducible hirr, ← eval₂_eq_eval_map, ← aeval_def] invFun := fun x => by haveI := IsCyclotomicExtension.neZero' n K L haveI hn := NeZero.of_noZeroSMulDivisors K C n refine ⟨x.1, ?_⟩ cases x rwa [aeval_def, eval₂_eq_eval_map, hζ.powerBasis_gen K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, map_cyclotomic, ← IsRoot.def, isRoot_cyclotomic_iff, ← mem_primitiveRoots n.pos] left_inv := fun x => Subtype.ext rfl right_inv := fun x => Subtype.ext rfl } #align is_primitive_root.embeddings_equiv_primitive_roots IsPrimitiveRoot.embeddingsEquivPrimitiveRoots -- Porting note: renamed argument `φ`: "expected '_' or identifier" @[simp] theorem embeddingsEquivPrimitiveRoots_apply_coe (C : Type*) [CommRing C] [IsDomain C] [Algebra K C] (hirr : Irreducible (cyclotomic n K)) (φ' : L →ₐ[K] C) : (hζ.embeddingsEquivPrimitiveRoots C hirr φ' : C) = φ' ζ := rfl #align is_primitive_root.embeddings_equiv_primitive_roots_apply_coe IsPrimitiveRoot.embeddingsEquivPrimitiveRoots_apply_coe end IsPrimitiveRoot namespace IsCyclotomicExtension variable {K} (L) /-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the `finrank` of a cyclotomic extension is `n.totient`. -/ theorem finrank (hirr : Irreducible (cyclotomic n K)) : finrank K L = (n : ℕ).totient := by haveI := IsCyclotomicExtension.neZero' n K L rw [((zeta_spec n K L).powerBasis K).finrank, IsPrimitiveRoot.powerBasis_dim, ← (zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic] #align is_cyclotomic_extension.finrank IsCyclotomicExtension.finrank variable {L} in /-- If `L` contains both a primitive `p`-th root of unity and `q`-th root of unity, and `Irreducible (cyclotomic (lcm p q) K)` (in particular for `K = ℚ`), then the `finrank K L` is at least `(lcm p q).totient`. -/ theorem _root_.IsPrimitiveRoot.lcm_totient_le_finrank [FiniteDimensional K L] {p q : ℕ} {x y : L} (hx : IsPrimitiveRoot x p) (hy : IsPrimitiveRoot y q) (hirr : Irreducible (cyclotomic (Nat.lcm p q) K)) : (Nat.lcm p q).totient ≤ FiniteDimensional.finrank K L := by rcases Nat.eq_zero_or_pos p with (rfl | hppos) · simp rcases Nat.eq_zero_or_pos q with (rfl | hqpos) · simp let z := x ^ (p / factorizationLCMLeft p q) * y ^ (q / factorizationLCMRight p q) let k := PNat.lcm ⟨p, hppos⟩ ⟨q, hqpos⟩ have : IsPrimitiveRoot z k := hx.pow_mul_pow_lcm hy hppos.ne' hqpos.ne' haveI := IsPrimitiveRoot.adjoin_isCyclotomicExtension K this convert Submodule.finrank_le (Subalgebra.toSubmodule (adjoin K {z})) rw [show Nat.lcm p q = (k : ℕ) from rfl] at hirr simpa using (IsCyclotomicExtension.finrank (Algebra.adjoin K {z}) hirr).symm end IsCyclotomicExtension end NoOrder section Norm namespace IsPrimitiveRoot section Field variable {K} [Field K] [NumberField K] variable (n) in /-- If a `n`-th cyclotomic extension of `ℚ` contains a primitive `l`-th root of unity, then `l ∣ 2 * n`. -/ theorem dvd_of_isCyclotomicExtension [NumberField K] [IsCyclotomicExtension {n} ℚ K] {ζ : K} {l : ℕ} (hζ : IsPrimitiveRoot ζ l) (hl : l ≠ 0) : l ∣ 2 * n := by have hl : NeZero l := ⟨hl⟩ have hroot := IsCyclotomicExtension.zeta_spec n ℚ K have key := IsPrimitiveRoot.lcm_totient_le_finrank hζ hroot (cyclotomic.irreducible_rat <| Nat.lcm_pos (Nat.pos_of_ne_zero hl.1) n.2) rw [IsCyclotomicExtension.finrank K (cyclotomic.irreducible_rat n.2)] at key rcases _root_.dvd_lcm_right l n with ⟨r, hr⟩ have ineq := Nat.totient_super_multiplicative n r rw [← hr] at ineq replace key := (mul_le_iff_le_one_right (Nat.totient_pos.2 n.2)).mp (le_trans ineq key) have rpos : 0 < r := by refine Nat.pos_of_ne_zero (fun h ↦ ?_) simp only [h, mul_zero, _root_.lcm_eq_zero_iff, PNat.ne_zero, or_false] at hr exact hl.1 hr replace key := (Nat.dvd_prime Nat.prime_two).1 (Nat.dvd_two_of_totient_le_one rpos key) rcases key with (key | key) · rw [key, mul_one] at hr rw [← hr] exact dvd_mul_of_dvd_right (_root_.dvd_lcm_left l ↑n) 2 · rw [key, mul_comm] at hr simpa [← hr] using _root_.dvd_lcm_left _ _ /-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of `ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exist `r` such that `x = (-ζ)^r`. -/ theorem exists_neg_pow_of_isOfFinOrder [NumberField K] [IsCyclotomicExtension {n} ℚ K] (hno : Odd (n : ℕ)) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) : ∃ r : ℕ, x = (-ζ) ^ r := by have hnegζ : IsPrimitiveRoot (-ζ) (2 * n) := by convert IsPrimitiveRoot.orderOf (-ζ) rw [neg_eq_neg_one_mul, (Commute.all _ _).orderOf_mul_eq_mul_orderOf_of_coprime] · simp [hζ.eq_orderOf] · simp [← hζ.eq_orderOf, Nat.odd_iff_not_even.1 hno] obtain ⟨k, hkpos, hkn⟩ := isOfFinOrder_iff_pow_eq_one.1 hx obtain ⟨l, hl, hlroot⟩ := (isRoot_of_unity_iff hkpos _).1 hkn have hlzero : NeZero l := ⟨fun h ↦ by simp [h] at hl⟩ have : NeZero (l : K) := ⟨NeZero.natCast_ne l K⟩ rw [isRoot_cyclotomic_iff] at hlroot obtain ⟨a, ha⟩ := hlroot.dvd_of_isCyclotomicExtension n hlzero.1 replace hlroot : x ^ (2 * (n : ℕ)) = 1 := by rw [ha, pow_mul, hlroot.pow_eq_one, one_pow] obtain ⟨s, -, hs⟩ := hnegζ.eq_pow_of_pow_eq_one hlroot (by simp) exact ⟨s, hs.symm⟩ /-- If `x` is a root of unity (spelled as `IsOfFinOrder x`) in an `n`-th cyclotomic extension of `ℚ`, where `n` is odd, and `ζ` is a primitive `n`-th root of unity, then there exists `r < n` such that `x = ζ^r` or `x = -ζ^r`. -/ theorem exists_pow_or_neg_mul_pow_of_isOfFinOrder [NumberField K] [IsCyclotomicExtension {n} ℚ K] (hno : Odd (n : ℕ)) {ζ x : K} (hζ : IsPrimitiveRoot ζ n) (hx : IsOfFinOrder x) : ∃ r : ℕ, r < n ∧ (x = ζ ^ r ∨ x = -ζ ^ r) := by obtain ⟨r, hr⟩ := hζ.exists_neg_pow_of_isOfFinOrder hno hx refine ⟨r % n, Nat.mod_lt _ n.2, ?_⟩ rw [show ζ ^ (r % ↑n) = ζ ^ r from (IsPrimitiveRoot.eq_orderOf hζ).symm ▸ pow_mod_orderOf .., hr] rcases Nat.even_or_odd r with (h | h) <;> simp [neg_pow, h.neg_one_pow] end Field section CommRing variable [CommRing L] {ζ : L} (hζ : IsPrimitiveRoot ζ n) variable {K} [Field K] [Algebra K L] /-- This mathematically trivial result is complementary to `norm_eq_one` below. -/ theorem norm_eq_neg_one_pow (hζ : IsPrimitiveRoot ζ 2) [IsDomain L] : norm K ζ = (-1 : K) ^ finrank K L := by rw [hζ.eq_neg_one_of_two_right, show -1 = algebraMap K L (-1) by simp, Algebra.norm_algebraMap] #align is_primitive_root.norm_eq_neg_one_pow IsPrimitiveRoot.norm_eq_neg_one_pow /-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), the norm of a primitive root is `1` if `n ≠ 2`. -/ theorem norm_eq_one [IsDomain L] [IsCyclotomicExtension {n} K L] (hn : n ≠ 2) (hirr : Irreducible (cyclotomic n K)) : norm K ζ = 1 := by haveI := IsCyclotomicExtension.neZero' n K L by_cases h1 : n = 1 · rw [h1, one_coe, one_right_iff] at hζ rw [hζ, show 1 = algebraMap K L 1 by simp, Algebra.norm_algebraMap, one_pow] · replace h1 : 2 ≤ n := by by_contra! h exact h1 (PNat.eq_one_of_lt_two h) -- Porting note: specyfing the type of `cyclotomic_coeff_zero K h1` was not needed. rw [← hζ.powerBasis_gen K, PowerBasis.norm_gen_eq_coeff_zero_minpoly, hζ.powerBasis_gen K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, (cyclotomic_coeff_zero K h1 : coeff (cyclotomic n K) 0 = 1), mul_one, hζ.powerBasis_dim K, ← hζ.minpoly_eq_cyclotomic_of_irreducible hirr, natDegree_cyclotomic] exact (totient_even <| h1.lt_of_ne hn.symm).neg_one_pow #align is_primitive_root.norm_eq_one IsPrimitiveRoot.norm_eq_one /-- If `K` is linearly ordered, the norm of a primitive root is `1` if `n` is odd. -/ theorem norm_eq_one_of_linearly_ordered {K : Type*} [LinearOrderedField K] [Algebra K L] (hodd : Odd (n : ℕ)) : norm K ζ = 1 := by have hz := congr_arg (norm K) ((IsPrimitiveRoot.iff_def _ n).1 hζ).1 rw [← (algebraMap K L).map_one, Algebra.norm_algebraMap, one_pow, map_pow, ← one_pow ↑n] at hz exact StrictMono.injective hodd.strictMono_pow hz #align is_primitive_root.norm_eq_one_of_linearly_ordered IsPrimitiveRoot.norm_eq_one_of_linearly_ordered theorem norm_of_cyclotomic_irreducible [IsDomain L] [IsCyclotomicExtension {n} K L] (hirr : Irreducible (cyclotomic n K)) : norm K ζ = ite (n = 2) (-1) 1 := by split_ifs with hn · subst hn convert norm_eq_neg_one_pow (K := K) hζ erw [IsCyclotomicExtension.finrank _ hirr, totient_two, pow_one] · exact hζ.norm_eq_one hn hirr #align is_primitive_root.norm_of_cyclotomic_irreducible IsPrimitiveRoot.norm_of_cyclotomic_irreducible end CommRing section Field variable [Field L] {ζ : L} (hζ : IsPrimitiveRoot ζ n) variable {K} [Field K] [Algebra K L] /-- If `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of `ζ - 1` is `eval 1 (cyclotomic n ℤ)`. -/ theorem sub_one_norm_eq_eval_cyclotomic [IsCyclotomicExtension {n} K L] (h : 2 < (n : ℕ)) (hirr : Irreducible (cyclotomic n K)) : norm K (ζ - 1) = ↑(eval 1 (cyclotomic n ℤ)) := by haveI := IsCyclotomicExtension.neZero' n K L let E := AlgebraicClosure L obtain ⟨z, hz⟩ := IsAlgClosed.exists_root _ (degree_cyclotomic_pos n E n.pos).ne.symm apply (algebraMap K E).injective letI := IsCyclotomicExtension.finiteDimensional {n} K L letI := IsCyclotomicExtension.isGalois n K L rw [norm_eq_prod_embeddings] conv_lhs => congr rfl ext rw [← neg_sub, AlgHom.map_neg, AlgHom.map_sub, AlgHom.map_one, neg_eq_neg_one_mul] rw [prod_mul_distrib, prod_const, card_univ, AlgHom.card, IsCyclotomicExtension.finrank L hirr, (totient_even h).neg_one_pow, one_mul] have Hprod : (Finset.univ.prod fun σ : L →ₐ[K] E => 1 - σ ζ) = eval 1 (cyclotomic' n E) := by rw [cyclotomic', eval_prod, ← @Finset.prod_attach E E, ← univ_eq_attach] refine Fintype.prod_equiv (hζ.embeddingsEquivPrimitiveRoots E hirr) _ _ fun σ => ?_ simp haveI : NeZero ((n : ℕ) : E) := NeZero.of_noZeroSMulDivisors K _ (n : ℕ) rw [Hprod, cyclotomic', ← cyclotomic_eq_prod_X_sub_primitiveRoots (isRoot_cyclotomic_iff.1 hz), ← map_cyclotomic_int, _root_.map_intCast, ← Int.cast_one, eval_intCast_map, eq_intCast, Int.cast_id] #align is_primitive_root.sub_one_norm_eq_eval_cyclotomic IsPrimitiveRoot.sub_one_norm_eq_eval_cyclotomic /-- If `IsPrimePow (n : ℕ)`, `n ≠ 2` and `Irreducible (cyclotomic n K)` (in particular for `K = ℚ`), then the norm of `ζ - 1` is `(n : ℕ).minFac`. -/ theorem sub_one_norm_isPrimePow (hn : IsPrimePow (n : ℕ)) [IsCyclotomicExtension {n} K L] (hirr : Irreducible (cyclotomic (n : ℕ) K)) (h : n ≠ 2) : norm K (ζ - 1) = (n : ℕ).minFac := by have := (coe_lt_coe 2 _).1 (lt_of_le_of_ne (succ_le_of_lt (IsPrimePow.one_lt hn)) (Function.Injective.ne PNat.coe_injective h).symm) letI hprime : Fact (n : ℕ).minFac.Prime := ⟨minFac_prime (IsPrimePow.ne_one hn)⟩ rw [sub_one_norm_eq_eval_cyclotomic hζ this hirr] nth_rw 1 [← IsPrimePow.minFac_pow_factorization_eq hn] obtain ⟨k, hk⟩ : ∃ k, (n : ℕ).factorization (n : ℕ).minFac = k + 1 := exists_eq_succ_of_ne_zero (((n : ℕ).factorization.mem_support_toFun (n : ℕ).minFac).1 <| mem_primeFactors_iff_mem_factors.2 <| (mem_factors (IsPrimePow.ne_zero hn)).2 ⟨hprime.out, minFac_dvd _⟩) simp [hk, sub_one_norm_eq_eval_cyclotomic hζ this hirr] #align is_primitive_root.sub_one_norm_is_prime_pow IsPrimitiveRoot.sub_one_norm_isPrimePow variable {A} theorem minpoly_sub_one_eq_cyclotomic_comp [Algebra K A] [IsDomain A] {ζ : A} [IsCyclotomicExtension {n} K A] (hζ : IsPrimitiveRoot ζ n) (h : Irreducible (Polynomial.cyclotomic n K)) : minpoly K (ζ - 1) = (cyclotomic n K).comp (X + 1) := by haveI := IsCyclotomicExtension.neZero' n K A rw [show ζ - 1 = ζ + algebraMap K A (-1) by simp [sub_eq_add_neg], minpoly.add_algebraMap ((integral {n} K A).isIntegral ζ), hζ.minpoly_eq_cyclotomic_of_irreducible h] simp #align is_primitive_root.minpoly_sub_one_eq_cyclotomic_comp IsPrimitiveRoot.minpoly_sub_one_eq_cyclotomic_comp open scoped Cyclotomic /-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime, then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ^ (k - s + 1) ≠ 2`. See the next lemmas for similar results. -/ theorem norm_pow_sub_one_of_prime_pow_ne_two {k s : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) [hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L] (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hs : s ≤ k) (htwo : p ^ (k - s + 1) ≠ 2) : norm K (ζ ^ (p : ℕ) ^ s - 1) = (p : K) ^ (p : ℕ) ^ s := by -- Porting note: `by simp` was `by linarith` that now fails. have hirr₁ : Irreducible (cyclotomic ((p : ℕ) ^ (k - s + 1)) K) := cyclotomic_irreducible_pow_of_irreducible_pow hpri.1 (by simp) hirr rw [← PNat.pow_coe] at hirr₁ set η := ζ ^ (p : ℕ) ^ s - 1 let η₁ : K⟮η⟯ := IntermediateField.AdjoinSimple.gen K η have hη : IsPrimitiveRoot (η + 1) ((p : ℕ) ^ (k + 1 - s)) := by rw [sub_add_cancel] refine IsPrimitiveRoot.pow (p ^ (k + 1)).pos hζ ?_ rw [PNat.pow_coe, ← pow_add, add_comm s, Nat.sub_add_cancel (le_trans hs (Nat.le_succ k))] have : IsCyclotomicExtension {p ^ (k - s + 1)} K K⟮η⟯ := by suffices IsCyclotomicExtension {p ^ (k - s + 1)} K K⟮η + 1⟯.toSubalgebra by have H : K⟮η + 1⟯.toSubalgebra = K⟮η⟯.toSubalgebra := by simp only [IntermediateField.adjoin_simple_toSubalgebra_of_integral ((integral {p ^ (k + 1)} K L).isIntegral _)] refine Subalgebra.ext fun x => ⟨fun hx => adjoin_le ?_ hx, fun hx => adjoin_le ?_ hx⟩ · simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.add_mem _ (subset_adjoin (mem_singleton η)) (Subalgebra.one_mem _) · simp only [Set.singleton_subset_iff, SetLike.mem_coe] nth_rw 1 [← add_sub_cancel_right η 1] exact Subalgebra.sub_mem _ (subset_adjoin (mem_singleton _)) (Subalgebra.one_mem _) -- Porting note: the previous proof was `rw [H] at this; exact this` but it now fails. exact IsCyclotomicExtension.equiv _ _ _ (Subalgebra.equivOfEq _ _ H) -- Porting note: the next `refine` was `rw [H]`, abusing defeq, and it now fails. have H := IntermediateField.adjoin_simple_toSubalgebra_of_integral ((integral {p ^ (k + 1)} K L).isIntegral (η + 1)) refine @IsCyclotomicExtension.equiv _ _ _ _ _ _ _ _ _ ?_ (Subalgebra.equivOfEq _ _ H).symm have hη' : IsPrimitiveRoot (η + 1) ↑(p ^ (k + 1 - s)) := by simpa using hη -- Porting note: `using 1` was not needed. convert hη'.adjoin_isCyclotomicExtension K using 1 rw [Nat.sub_add_comm hs] replace hη : IsPrimitiveRoot (η₁ + 1) ↑(p ^ (k - s + 1)) := by apply coe_submonoidClass_iff.1 convert hη using 1 rw [Nat.sub_add_comm hs, pow_coe] -- Porting note: the following `haveI` were not needed because the locale `cyclotomic` set them -- as instances. haveI := IsCyclotomicExtension.finiteDimensional {p ^ (k + 1)} K L haveI := IsCyclotomicExtension.isGalois (p ^ (k + 1)) K L rw [norm_eq_norm_adjoin K] have H := hη.sub_one_norm_isPrimePow ?_ hirr₁ htwo swap; · rw [PNat.pow_coe]; exact hpri.1.isPrimePow.pow (Nat.succ_ne_zero _) rw [add_sub_cancel_right] at H rw [H] congr · rw [PNat.pow_coe, Nat.pow_minFac, hpri.1.minFac_eq] exact Nat.succ_ne_zero _ have := FiniteDimensional.finrank_mul_finrank K K⟮η⟯ L rw [IsCyclotomicExtension.finrank L hirr, IsCyclotomicExtension.finrank K⟮η⟯ hirr₁, PNat.pow_coe, PNat.pow_coe, Nat.totient_prime_pow hpri.out (k - s).succ_pos, Nat.totient_prime_pow hpri.out k.succ_pos, mul_comm _ ((p : ℕ) - 1), mul_assoc, mul_comm ((p : ℕ) ^ (k.succ - 1))] at this replace this := mul_left_cancel₀ (tsub_pos_iff_lt.2 hpri.out.one_lt).ne' this have Hex : k.succ - 1 = (k - s).succ - 1 + s := by simp only [Nat.succ_sub_succ_eq_sub, tsub_zero] exact (Nat.sub_add_cancel hs).symm rw [Hex, pow_add] at this exact mul_left_cancel₀ (pow_ne_zero _ hpri.out.ne_zero) this #align is_primitive_root.pow_sub_one_norm_prime_pow_ne_two IsPrimitiveRoot.norm_pow_sub_one_of_prime_pow_ne_two /-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime, then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `p ≠ 2`. -/ theorem norm_pow_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) [hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L] (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) {s : ℕ} (hs : s ≤ k) (hodd : p ≠ 2) : norm K (ζ ^ (p : ℕ) ^ s - 1) = (p : K) ^ (p : ℕ) ^ s := by refine hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs fun h => ?_ have coe_two : ((2 : ℕ+) : ℕ) = 2 := by norm_cast rw [← PNat.coe_inj, coe_two, PNat.pow_coe, ← pow_one 2] at h -- Porting note: the proof is slightly different because of coercions. replace h := eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (k - s).succ_pos h exact hodd (PNat.coe_injective h) #align is_primitive_root.pow_sub_one_norm_prime_ne_two IsPrimitiveRoot.norm_pow_sub_one_of_prime_ne_two /-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. -/ theorem norm_sub_one_of_prime_ne_two {k : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) [hpri : Fact (p : ℕ).Prime] [IsCyclotomicExtension {p ^ (k + 1)} K L] (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by simpa using hζ.norm_pow_sub_one_of_prime_ne_two hirr k.zero_le h #align is_primitive_root.sub_one_norm_prime_ne_two IsPrimitiveRoot.norm_sub_one_of_prime_ne_two /-- If `Irreducible (cyclotomic p K)` (in particular for `K = ℚ`) and `p` is an odd prime, then the norm of `ζ - 1` is `p`. -/ theorem norm_sub_one_of_prime_ne_two' [hpri : Fact (p : ℕ).Prime] [hcyc : IsCyclotomicExtension {p} K L] (hζ : IsPrimitiveRoot ζ p) (hirr : Irreducible (cyclotomic p K)) (h : p ≠ 2) : norm K (ζ - 1) = p := by replace hirr : Irreducible (cyclotomic (p ^ (0 + 1) : ℕ) K) := by simp [hirr] replace hζ : IsPrimitiveRoot ζ (p ^ (0 + 1) : ℕ) := by simp [hζ] haveI : IsCyclotomicExtension {p ^ (0 + 1)} K L := by simp [hcyc] simpa using norm_sub_one_of_prime_ne_two hζ hirr h #align is_primitive_root.sub_one_norm_prime IsPrimitiveRoot.norm_sub_one_of_prime_ne_two' /-- If `Irreducible (cyclotomic (2 ^ (k + 1)) K)` (in particular for `K = ℚ`), then the norm of `ζ ^ (2 ^ k) - 1` is `(-2) ^ (2 ^ k)`. -/ -- Porting note: writing `(2 : ℕ+)` was not needed (similarly everywhere). theorem norm_pow_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ (k + 1))) [IsCyclotomicExtension {(2 : ℕ+) ^ (k + 1)} K L] (hirr : Irreducible (cyclotomic (2 ^ (k + 1)) K)) : norm K (ζ ^ 2 ^ k - 1) = (-2 : K) ^ 2 ^ k := by have := hζ.pow_of_dvd (fun h => two_ne_zero (pow_eq_zero h)) (pow_dvd_pow 2 (le_succ k)) rw [Nat.pow_div (le_succ k) zero_lt_two, Nat.succ_sub (le_refl k), Nat.sub_self, pow_one] at this have H : (-1 : L) - (1 : L) = algebraMap K L (-2) := by simp only [map_neg, map_ofNat] ring -- Porting note: `simpa using hirr` was `simp [hirr]`. replace hirr : Irreducible (cyclotomic ((2 : ℕ+) ^ (k + 1) : ℕ+) K) := by simpa using hirr -- Porting note: the proof is slightly different because of coercions. rw [this.eq_neg_one_of_two_right, H, Algebra.norm_algebraMap, IsCyclotomicExtension.finrank L hirr, pow_coe, show ((2 : ℕ+) : ℕ) = 2 from rfl, totient_prime_pow Nat.prime_two (zero_lt_succ k), succ_sub_succ_eq_sub, tsub_zero] simp #align is_primitive_root.pow_sub_one_norm_two IsPrimitiveRoot.norm_pow_sub_one_two /-- If `Irreducible (cyclotomic (2 ^ k) K)` (in particular for `K = ℚ`) and `k` is at least `2`, then the norm of `ζ - 1` is `2`. -/ theorem norm_sub_one_two {k : ℕ} (hζ : IsPrimitiveRoot ζ (2 ^ k)) (hk : 2 ≤ k) [H : IsCyclotomicExtension {(2 : ℕ+) ^ k} K L] (hirr : Irreducible (cyclotomic (2 ^ k) K)) : norm K (ζ - 1) = 2 := by have : 2 < (2 : ℕ+) ^ k := by simp only [← coe_lt_coe, one_coe, pow_coe] nth_rw 1 [← pow_one 2] exact pow_lt_pow_right one_lt_two (lt_of_lt_of_le one_lt_two hk) -- Porting note: `simpa using hirr` was `simp [hirr]`_ replace hirr : Irreducible (cyclotomic ((2 : ℕ+) ^ k : ℕ+) K) := by simpa using hirr -- Porting note: `simpa using hζ` was `simp [hζ]`_ replace hζ : IsPrimitiveRoot ζ (2 ^ k : ℕ+) := by simpa using hζ obtain ⟨k₁, hk₁⟩ := exists_eq_succ_of_ne_zero (lt_of_lt_of_le zero_lt_two hk).ne.symm -- Porting note: the proof is slightly different because of coercions. simpa [hk₁, show ((2 : ℕ+) : ℕ) = 2 from rfl] using sub_one_norm_eq_eval_cyclotomic hζ this hirr #align is_primitive_root.sub_one_norm_two IsPrimitiveRoot.norm_sub_one_two /-- If `Irreducible (cyclotomic (p ^ (k + 1)) K)` (in particular for `K = ℚ`) and `p` is a prime, then the norm of `ζ ^ (p ^ s) - 1` is `p ^ (p ^ s)` if `k ≠ 0` and `s ≤ k`. -/
Mathlib/NumberTheory/Cyclotomic/PrimitiveRoots.lean
542
565
theorem norm_pow_sub_one_eq_prime_pow_of_ne_zero {k s : ℕ} (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) [hpri : Fact (p : ℕ).Prime] [hcycl : IsCyclotomicExtension {p ^ (k + 1)} K L] (hirr : Irreducible (cyclotomic (↑(p ^ (k + 1)) : ℕ) K)) (hs : s ≤ k) (hk : k ≠ 0) : norm K (ζ ^ (p : ℕ) ^ s - 1) = (p : K) ^ (p : ℕ) ^ s := by
by_cases htwo : p ^ (k - s + 1) = 2 · have hp : p = 2 := by rw [← PNat.coe_inj, PNat.pow_coe, ← pow_one 2] at htwo replace htwo := eq_of_prime_pow_eq (prime_iff.1 hpri.out) (prime_iff.1 Nat.prime_two) (succ_pos _) htwo rwa [show 2 = ((2 : ℕ+) : ℕ) by decide, PNat.coe_inj] at htwo replace hs : s = k := by rw [hp, ← PNat.coe_inj, PNat.pow_coe] at htwo nth_rw 2 [← pow_one 2] at htwo replace htwo := Nat.pow_right_injective rfl.le htwo rw [add_left_eq_self, Nat.sub_eq_zero_iff_le] at htwo exact le_antisymm hs htwo simp only [hs, hp, one_coe, cast_one, pow_coe, show ((2 : ℕ+) : ℕ) = 2 from rfl] at hζ hirr hcycl ⊢ obtain ⟨k₁, hk₁⟩ := Nat.exists_eq_succ_of_ne_zero hk -- Porting note: the proof is slightly different because of coercions. rw [hζ.norm_pow_sub_one_two hirr, hk₁, _root_.pow_succ', pow_mul, neg_eq_neg_one_mul, mul_pow, neg_one_sq, one_mul, ← pow_mul, ← _root_.pow_succ'] simp · exact hζ.norm_pow_sub_one_of_prime_pow_ne_two hirr hs htwo
/- Copyright (c) 2021 Aaron Anderson, Jesse Michael Han, Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jesse Michael Han, Floris van Doorn -/ import Mathlib.Data.Finset.Basic import Mathlib.ModelTheory.Syntax import Mathlib.Data.List.ProdSigma #align_import model_theory.semantics from "leanprover-community/mathlib"@"d565b3df44619c1498326936be16f1a935df0728" /-! # Basics on First-Order Semantics This file defines the interpretations of first-order terms, formulas, sentences, and theories in a style inspired by the [Flypitch project](https://flypitch.github.io/). ## Main Definitions * `FirstOrder.Language.Term.realize` is defined so that `t.realize v` is the term `t` evaluated at variables `v`. * `FirstOrder.Language.BoundedFormula.Realize` is defined so that `φ.Realize v xs` is the bounded formula `φ` evaluated at tuples of variables `v` and `xs`. * `FirstOrder.Language.Formula.Realize` is defined so that `φ.Realize v` is the formula `φ` evaluated at variables `v`. * `FirstOrder.Language.Sentence.Realize` is defined so that `φ.Realize M` is the sentence `φ` evaluated in the structure `M`. Also denoted `M ⊨ φ`. * `FirstOrder.Language.Theory.Model` is defined so that `T.Model M` is true if and only if every sentence of `T` is realized in `M`. Also denoted `T ⊨ φ`. ## Main Results * `FirstOrder.Language.BoundedFormula.realize_toPrenex` shows that the prenex normal form of a formula has the same realization as the original formula. * Several results in this file show that syntactic constructions such as `relabel`, `castLE`, `liftAt`, `subst`, and the actions of language maps commute with realization of terms, formulas, sentences, and theories. ## Implementation Notes * Formulas use a modified version of de Bruijn variables. Specifically, a `L.BoundedFormula α n` is a formula with some variables indexed by a type `α`, which cannot be quantified over, and some indexed by `Fin n`, which can. For any `φ : L.BoundedFormula α (n + 1)`, we define the formula `∀' φ : L.BoundedFormula α n` by universally quantifying over the variable indexed by `n : Fin (n + 1)`. ## References For the Flypitch project: - [J. Han, F. van Doorn, *A formal proof of the independence of the continuum hypothesis*] [flypitch_cpp] - [J. Han, F. van Doorn, *A formalization of forcing and the unprovability of the continuum hypothesis*][flypitch_itp] -/ universe u v w u' v' namespace FirstOrder namespace Language variable {L : Language.{u, v}} {L' : Language} variable {M : Type w} {N P : Type*} [L.Structure M] [L.Structure N] [L.Structure P] variable {α : Type u'} {β : Type v'} {γ : Type*} open FirstOrder Cardinal open Structure Cardinal Fin namespace Term -- Porting note: universes in different order /-- A term `t` with variables indexed by `α` can be evaluated by giving a value to each variable. -/ def realize (v : α → M) : ∀ _t : L.Term α, M | var k => v k | func f ts => funMap f fun i => (ts i).realize v #align first_order.language.term.realize FirstOrder.Language.Term.realize /- Porting note: The equation lemma of `realize` is too strong; it simplifies terms like the LHS of `realize_functions_apply₁`. Even `eqns` can't fix this. We removed `simp` attr from `realize` and prepare new simp lemmas for `realize`. -/ @[simp] theorem realize_var (v : α → M) (k) : realize v (var k : L.Term α) = v k := rfl @[simp] theorem realize_func (v : α → M) {n} (f : L.Functions n) (ts) : realize v (func f ts : L.Term α) = funMap f fun i => (ts i).realize v := rfl @[simp] theorem realize_relabel {t : L.Term α} {g : α → β} {v : β → M} : (t.relabel g).realize v = t.realize (v ∘ g) := by induction' t with _ n f ts ih · rfl · simp [ih] #align first_order.language.term.realize_relabel FirstOrder.Language.Term.realize_relabel @[simp] theorem realize_liftAt {n n' m : ℕ} {t : L.Term (Sum α (Fin n))} {v : Sum α (Fin (n + n')) → M} : (t.liftAt n' m).realize v = t.realize (v ∘ Sum.map id fun i : Fin _ => if ↑i < m then Fin.castAdd n' i else Fin.addNat i n') := realize_relabel #align first_order.language.term.realize_lift_at FirstOrder.Language.Term.realize_liftAt @[simp] theorem realize_constants {c : L.Constants} {v : α → M} : c.term.realize v = c := funMap_eq_coe_constants #align first_order.language.term.realize_constants FirstOrder.Language.Term.realize_constants @[simp] theorem realize_functions_apply₁ {f : L.Functions 1} {t : L.Term α} {v : α → M} : (f.apply₁ t).realize v = funMap f ![t.realize v] := by rw [Functions.apply₁, Term.realize] refine congr rfl (funext fun i => ?_) simp only [Matrix.cons_val_fin_one] #align first_order.language.term.realize_functions_apply₁ FirstOrder.Language.Term.realize_functions_apply₁ @[simp] theorem realize_functions_apply₂ {f : L.Functions 2} {t₁ t₂ : L.Term α} {v : α → M} : (f.apply₂ t₁ t₂).realize v = funMap f ![t₁.realize v, t₂.realize v] := by rw [Functions.apply₂, Term.realize] refine congr rfl (funext (Fin.cases ?_ ?_)) · simp only [Matrix.cons_val_zero] · simp only [Matrix.cons_val_succ, Matrix.cons_val_fin_one, forall_const] #align first_order.language.term.realize_functions_apply₂ FirstOrder.Language.Term.realize_functions_apply₂ theorem realize_con {A : Set M} {a : A} {v : α → M} : (L.con a).term.realize v = a := rfl #align first_order.language.term.realize_con FirstOrder.Language.Term.realize_con @[simp] theorem realize_subst {t : L.Term α} {tf : α → L.Term β} {v : β → M} : (t.subst tf).realize v = t.realize fun a => (tf a).realize v := by induction' t with _ _ _ _ ih · rfl · simp [ih] #align first_order.language.term.realize_subst FirstOrder.Language.Term.realize_subst @[simp] theorem realize_restrictVar [DecidableEq α] {t : L.Term α} {s : Set α} (h : ↑t.varFinset ⊆ s) {v : α → M} : (t.restrictVar (Set.inclusion h)).realize (v ∘ (↑)) = t.realize v := by induction' t with _ _ _ _ ih · rfl · simp_rw [varFinset, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var FirstOrder.Language.Term.realize_restrictVar @[simp] theorem realize_restrictVarLeft [DecidableEq α] {γ : Type*} {t : L.Term (Sum α γ)} {s : Set α} (h : ↑t.varFinsetLeft ⊆ s) {v : α → M} {xs : γ → M} : (t.restrictVarLeft (Set.inclusion h)).realize (Sum.elim (v ∘ (↑)) xs) = t.realize (Sum.elim v xs) := by induction' t with a _ _ _ ih · cases a <;> rfl · simp_rw [varFinsetLeft, Finset.coe_biUnion, Set.iUnion_subset_iff] at h exact congr rfl (funext fun i => ih i (h i (Finset.mem_univ i))) #align first_order.language.term.realize_restrict_var_left FirstOrder.Language.Term.realize_restrictVarLeft @[simp] theorem realize_constantsToVars [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L[[α]].Term β} {v : β → M} : t.constantsToVars.realize (Sum.elim (fun a => ↑(L.con a)) v) = t.realize v := by induction' t with _ n f ts ih · simp · cases n · cases f · simp only [realize, ih, Nat.zero_eq, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · simp only [realize, constantsToVars, Sum.elim_inl, funMap_eq_coe_constants] rfl · cases' f with _ f · simp only [realize, ih, constantsOn, mk₂_Functions] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] · exact isEmptyElim f #align first_order.language.term.realize_constants_to_vars FirstOrder.Language.Term.realize_constantsToVars @[simp] theorem realize_varsToConstants [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {t : L.Term (Sum α β)} {v : β → M} : t.varsToConstants.realize v = t.realize (Sum.elim (fun a => ↑(L.con a)) v) := by induction' t with ab n f ts ih · cases' ab with a b -- Porting note: both cases were `simp [Language.con]` · simp [Language.con, realize, funMap_eq_coe_constants] · simp [realize, constantMap] · simp only [realize, constantsOn, mk₂_Functions, ih] -- Porting note: below lemma does not work with simp for some reason rw [withConstants_funMap_sum_inl] #align first_order.language.term.realize_vars_to_constants FirstOrder.Language.Term.realize_varsToConstants theorem realize_constantsVarsEquivLeft [L[[α]].Structure M] [(lhomWithConstants L α).IsExpansionOn M] {n} {t : L[[α]].Term (Sum β (Fin n))} {v : β → M} {xs : Fin n → M} : (constantsVarsEquivLeft t).realize (Sum.elim (Sum.elim (fun a => ↑(L.con a)) v) xs) = t.realize (Sum.elim v xs) := by simp only [constantsVarsEquivLeft, realize_relabel, Equiv.coe_trans, Function.comp_apply, constantsVarsEquiv_apply, relabelEquiv_symm_apply] refine _root_.trans ?_ realize_constantsToVars rcongr x rcases x with (a | (b | i)) <;> simp #align first_order.language.term.realize_constants_vars_equiv_left FirstOrder.Language.Term.realize_constantsVarsEquivLeft end Term namespace LHom @[simp] theorem realize_onTerm [L'.Structure M] (φ : L →ᴸ L') [φ.IsExpansionOn M] (t : L.Term α) (v : α → M) : (φ.onTerm t).realize v = t.realize v := by induction' t with _ n f ts ih · rfl · simp only [Term.realize, LHom.onTerm, LHom.map_onFunction, ih] set_option linter.uppercaseLean3 false in #align first_order.language.Lhom.realize_on_term FirstOrder.Language.LHom.realize_onTerm end LHom @[simp] theorem Hom.realize_term (g : M →[L] N) {t : L.Term α} {v : α → M} : t.realize (g ∘ v) = g (t.realize v) := by induction t · rfl · rw [Term.realize, Term.realize, g.map_fun] refine congr rfl ?_ ext x simp [*] #align first_order.language.hom.realize_term FirstOrder.Language.Hom.realize_term @[simp] theorem Embedding.realize_term {v : α → M} (t : L.Term α) (g : M ↪[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.embedding.realize_term FirstOrder.Language.Embedding.realize_term @[simp] theorem Equiv.realize_term {v : α → M} (t : L.Term α) (g : M ≃[L] N) : t.realize (g ∘ v) = g (t.realize v) := g.toHom.realize_term #align first_order.language.equiv.realize_term FirstOrder.Language.Equiv.realize_term variable {n : ℕ} namespace BoundedFormula open Term -- Porting note: universes in different order /-- A bounded formula can be evaluated as true or false by giving values to each free variable. -/ def Realize : ∀ {l} (_f : L.BoundedFormula α l) (_v : α → M) (_xs : Fin l → M), Prop | _, falsum, _v, _xs => False | _, equal t₁ t₂, v, xs => t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) | _, rel R ts, v, xs => RelMap R fun i => (ts i).realize (Sum.elim v xs) | _, imp f₁ f₂, v, xs => Realize f₁ v xs → Realize f₂ v xs | _, all f, v, xs => ∀ x : M, Realize f v (snoc xs x) #align first_order.language.bounded_formula.realize FirstOrder.Language.BoundedFormula.Realize variable {l : ℕ} {φ ψ : L.BoundedFormula α l} {θ : L.BoundedFormula α l.succ} variable {v : α → M} {xs : Fin l → M} @[simp] theorem realize_bot : (⊥ : L.BoundedFormula α l).Realize v xs ↔ False := Iff.rfl #align first_order.language.bounded_formula.realize_bot FirstOrder.Language.BoundedFormula.realize_bot @[simp] theorem realize_not : φ.not.Realize v xs ↔ ¬φ.Realize v xs := Iff.rfl #align first_order.language.bounded_formula.realize_not FirstOrder.Language.BoundedFormula.realize_not @[simp] theorem realize_bdEqual (t₁ t₂ : L.Term (Sum α (Fin l))) : (t₁.bdEqual t₂).Realize v xs ↔ t₁.realize (Sum.elim v xs) = t₂.realize (Sum.elim v xs) := Iff.rfl #align first_order.language.bounded_formula.realize_bd_equal FirstOrder.Language.BoundedFormula.realize_bdEqual @[simp]
Mathlib/ModelTheory/Semantics.lean
277
277
theorem realize_top : (⊤ : L.BoundedFormula α l).Realize v xs ↔ True := by
simp [Top.top]
/- 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.Topology.UniformSpace.Basic import Mathlib.Topology.Separation import Mathlib.Order.Filter.CountableInter #align_import topology.G_delta from "leanprover-community/mathlib"@"b9e46fe101fc897fb2e7edaf0bf1f09ea49eb81a" /-! # `Gδ` sets In this file we define `Gδ` sets and prove their basic properties. ## Main definitions * `IsGδ`: a set `s` is a `Gδ` set if it can be represented as an intersection of countably many open sets; * `residual`: the σ-filter of residual sets. A set `s` is called *residual* if it includes a countable intersection of dense open sets. * `IsNowhereDense`: a set is called *nowhere dense* iff its closure has empty interior * `IsMeagre`: a set `s` is called *meagre* iff its complement is residual ## Main results We prove that finite or countable intersections of Gδ sets are Gδ sets. We also prove that the continuity set of a function from a topological space to an (e)metric space is a Gδ set. - `isClosed_isNowhereDense_iff_compl`: a closed set is nowhere dense iff its complement is open and dense - `isMeagre_iff_countable_union_isNowhereDense`: a set is meagre iff it is contained in a countable union of nowhere dense sets - subsets of meagre sets are meagre; countable unions of meagre sets are meagre ## Tags Gδ set, residual set, nowhere dense set, meagre set -/ noncomputable section open Topology TopologicalSpace Filter Encodable Set open scoped Uniformity variable {X Y ι : Type*} {ι' : Sort*} set_option linter.uppercaseLean3 false section IsGδ variable [TopologicalSpace X] /-- A Gδ set is a countable intersection of open sets. -/ def IsGδ (s : Set X) : Prop := ∃ T : Set (Set X), (∀ t ∈ T, IsOpen t) ∧ T.Countable ∧ s = ⋂₀ T #align is_Gδ IsGδ /-- An open set is a Gδ set. -/ theorem IsOpen.isGδ {s : Set X} (h : IsOpen s) : IsGδ s := ⟨{s}, by simp [h], countable_singleton _, (Set.sInter_singleton _).symm⟩ #align is_open.is_Gδ IsOpen.isGδ @[simp] protected theorem IsGδ.empty : IsGδ (∅ : Set X) := isOpen_empty.isGδ #align is_Gδ_empty IsGδ.empty @[deprecated (since := "2024-02-15")] alias isGδ_empty := IsGδ.empty @[simp] protected theorem IsGδ.univ : IsGδ (univ : Set X) := isOpen_univ.isGδ #align is_Gδ_univ IsGδ.univ @[deprecated (since := "2024-02-15")] alias isGδ_univ := IsGδ.univ theorem IsGδ.biInter_of_isOpen {I : Set ι} (hI : I.Countable) {f : ι → Set X} (hf : ∀ i ∈ I, IsOpen (f i)) : IsGδ (⋂ i ∈ I, f i) := ⟨f '' I, by rwa [forall_mem_image], hI.image _, by rw [sInter_image]⟩ #align is_Gδ_bInter_of_open IsGδ.biInter_of_isOpen @[deprecated (since := "2024-02-15")] alias isGδ_biInter_of_isOpen := IsGδ.biInter_of_isOpen theorem IsGδ.iInter_of_isOpen [Countable ι'] {f : ι' → Set X} (hf : ∀ i, IsOpen (f i)) : IsGδ (⋂ i, f i) := ⟨range f, by rwa [forall_mem_range], countable_range _, by rw [sInter_range]⟩ #align is_Gδ_Inter_of_open IsGδ.iInter_of_isOpen @[deprecated (since := "2024-02-15")] alias isGδ_iInter_of_isOpen := IsGδ.iInter_of_isOpen lemma isGδ_iff_eq_iInter_nat {s : Set X} : IsGδ s ↔ ∃ (f : ℕ → Set X), (∀ n, IsOpen (f n)) ∧ s = ⋂ n, f n := by refine ⟨?_, ?_⟩ · rintro ⟨T, hT, T_count, rfl⟩ rcases Set.eq_empty_or_nonempty T with rfl|hT · exact ⟨fun _n ↦ univ, fun _n ↦ isOpen_univ, by simp⟩ · obtain ⟨f, hf⟩ : ∃ (f : ℕ → Set X), T = range f := Countable.exists_eq_range T_count hT exact ⟨f, by aesop, by simp [hf]⟩ · rintro ⟨f, hf, rfl⟩ exact .iInter_of_isOpen hf alias ⟨IsGδ.eq_iInter_nat, _⟩ := isGδ_iff_eq_iInter_nat /-- The intersection of an encodable family of Gδ sets is a Gδ set. -/ protected theorem IsGδ.iInter [Countable ι'] {s : ι' → Set X} (hs : ∀ i, IsGδ (s i)) : IsGδ (⋂ i, s i) := by choose T hTo hTc hTs using hs obtain rfl : s = fun i => ⋂₀ T i := funext hTs refine ⟨⋃ i, T i, ?_, countable_iUnion hTc, (sInter_iUnion _).symm⟩ simpa [@forall_swap ι'] using hTo #align is_Gδ_Inter IsGδ.iInter @[deprecated] alias isGδ_iInter := IsGδ.iInter theorem IsGδ.biInter {s : Set ι} (hs : s.Countable) {t : ∀ i ∈ s, Set X} (ht : ∀ (i) (hi : i ∈ s), IsGδ (t i hi)) : IsGδ (⋂ i ∈ s, t i ‹_›) := by rw [biInter_eq_iInter] haveI := hs.to_subtype exact .iInter fun x => ht x x.2 #align is_Gδ_bInter IsGδ.biInter @[deprecated (since := "2024-02-15")] alias isGδ_biInter := IsGδ.biInter /-- A countable intersection of Gδ sets is a Gδ set. -/ theorem IsGδ.sInter {S : Set (Set X)} (h : ∀ s ∈ S, IsGδ s) (hS : S.Countable) : IsGδ (⋂₀ S) := by simpa only [sInter_eq_biInter] using IsGδ.biInter hS h #align is_Gδ_sInter IsGδ.sInter @[deprecated (since := "2024-02-15")] alias isGδ_sInter := IsGδ.sInter
Mathlib/Topology/GDelta.lean
136
138
theorem IsGδ.inter {s t : Set X} (hs : IsGδ s) (ht : IsGδ t) : IsGδ (s ∩ t) := by
rw [inter_eq_iInter] exact .iInter (Bool.forall_bool.2 ⟨ht, hs⟩)
/- 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.Order.CauSeq.BigOperators import Mathlib.Data.Complex.Abs import Mathlib.Data.Complex.BigOperators import Mathlib.Data.Nat.Choose.Sum #align_import data.complex.exponential from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Exponential, trigonometric and hyperbolic trigonometric functions This file contains the definitions of the real and complex exponential, sine, cosine, tangent, hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions. -/ open CauSeq Finset IsAbsoluteValue open scoped Classical ComplexConjugate namespace Complex theorem isCauSeq_abs_exp (z : ℂ) : IsCauSeq _root_.abs fun n => ∑ m ∈ range n, abs (z ^ m / m.factorial) := let ⟨n, hn⟩ := exists_nat_gt (abs z) have hn0 : (0 : ℝ) < n := lt_of_le_of_lt (abs.nonneg _) hn IsCauSeq.series_ratio_test n (abs z / n) (div_nonneg (abs.nonneg _) (le_of_lt hn0)) (by rwa [div_lt_iff hn0, one_mul]) fun m hm => by rw [abs_abs, abs_abs, Nat.factorial_succ, pow_succ', mul_comm m.succ, Nat.cast_mul, ← div_div, mul_div_assoc, mul_div_right_comm, map_mul, map_div₀, abs_natCast] gcongr exact le_trans hm (Nat.le_succ _) #align complex.is_cau_abs_exp Complex.isCauSeq_abs_exp noncomputable section theorem isCauSeq_exp (z : ℂ) : IsCauSeq abs fun n => ∑ m ∈ range n, z ^ m / m.factorial := (isCauSeq_abs_exp z).of_abv #align complex.is_cau_exp Complex.isCauSeq_exp /-- The Cauchy sequence consisting of partial sums of the Taylor series of the complex exponential function -/ -- Porting note (#11180): removed `@[pp_nodot]` def exp' (z : ℂ) : CauSeq ℂ Complex.abs := ⟨fun n => ∑ m ∈ range n, z ^ m / m.factorial, isCauSeq_exp z⟩ #align complex.exp' Complex.exp' /-- The complex exponential function, defined via its Taylor series -/ -- Porting note (#11180): removed `@[pp_nodot]` -- Porting note: removed `irreducible` attribute, so I can prove things def exp (z : ℂ) : ℂ := CauSeq.lim (exp' z) #align complex.exp Complex.exp /-- The complex sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / 2 #align complex.sin Complex.sin /-- The complex cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / 2 #align complex.cos Complex.cos /-- The complex tangent function, defined as `sin z / cos z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tan (z : ℂ) : ℂ := sin z / cos z #align complex.tan Complex.tan /-- The complex cotangent function, defined as `cos z / sin z` -/ def cot (z : ℂ) : ℂ := cos z / sin z /-- The complex hyperbolic sine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / 2 #align complex.sinh Complex.sinh /-- The complex hyperbolic cosine function, defined via `exp` -/ -- Porting note (#11180): removed `@[pp_nodot]` def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / 2 #align complex.cosh Complex.cosh /-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/ -- Porting note (#11180): removed `@[pp_nodot]` def tanh (z : ℂ) : ℂ := sinh z / cosh z #align complex.tanh Complex.tanh /-- 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 -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def exp (x : ℝ) : ℝ := (exp x).re #align real.exp Real.exp /-- The real sine function, defined as the real part of the complex sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sin (x : ℝ) : ℝ := (sin x).re #align real.sin Real.sin /-- The real cosine function, defined as the real part of the complex cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cos (x : ℝ) : ℝ := (cos x).re #align real.cos Real.cos /-- The real tangent function, defined as the real part of the complex tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tan (x : ℝ) : ℝ := (tan x).re #align real.tan Real.tan /-- The real cotangent function, defined as the real part of the complex cotangent -/ nonrec def cot (x : ℝ) : ℝ := (cot x).re /-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def sinh (x : ℝ) : ℝ := (sinh x).re #align real.sinh Real.sinh /-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def cosh (x : ℝ) : ℝ := (cosh x).re #align real.cosh Real.cosh /-- The real hypebolic tangent function, defined as the real part of the complex hyperbolic tangent -/ -- Porting note (#11180): removed `@[pp_nodot]` nonrec def tanh (x : ℝ) : ℝ := (tanh x).re #align real.tanh Real.tanh /-- 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 -- Porting note: ε0 : ε > 0 but goal is _ < ε cases' j with j 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 #align complex.exp_zero Complex.exp_zero 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_abs_exp x) (isCauSeq_exp y) #align complex.exp_add Complex.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℂ` to `ℂ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℂ) ℂ := { toFun := fun z => exp (Multiplicative.toAdd z), 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 #align complex.exp_list_sum Complex.exp_list_sum theorem exp_multiset_sum (s : Multiset ℂ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℂ) ℂ _ _ expMonoidHom s #align complex.exp_multiset_sum Complex.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℂ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℂ) expMonoidHom f s #align complex.exp_sum Complex.exp_sum 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] #align complex.exp_nat_mul Complex.exp_nat_mul theorem exp_ne_zero : exp x ≠ 0 := fun h => zero_ne_one <| by rw [← exp_zero, ← add_neg_self x, exp_add, h]; simp #align complex.exp_ne_zero Complex.exp_ne_zero 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)] #align complex.exp_neg Complex.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] #align complex.exp_sub Complex.exp_sub 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] #align complex.exp_int_mul Complex.exp_int_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] #align complex.exp_conj Complex.exp_conj @[simp] theorem ofReal_exp_ofReal_re (x : ℝ) : ((exp x).re : ℂ) = exp x := conj_eq_iff_re.1 <| by rw [← exp_conj, conj_ofReal] #align complex.of_real_exp_of_real_re Complex.ofReal_exp_ofReal_re @[simp, norm_cast] theorem ofReal_exp (x : ℝ) : (Real.exp x : ℂ) = exp x := ofReal_exp_ofReal_re _ #align complex.of_real_exp Complex.ofReal_exp @[simp] theorem exp_ofReal_im (x : ℝ) : (exp x).im = 0 := by rw [← ofReal_exp_ofReal_re, ofReal_im] #align complex.exp_of_real_im Complex.exp_ofReal_im theorem exp_ofReal_re (x : ℝ) : (exp x).re = Real.exp x := rfl #align complex.exp_of_real_re Complex.exp_ofReal_re theorem two_sinh : 2 * sinh x = exp x - exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_sinh Complex.two_sinh theorem two_cosh : 2 * cosh x = exp x + exp (-x) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cosh Complex.two_cosh @[simp] theorem sinh_zero : sinh 0 = 0 := by simp [sinh] #align complex.sinh_zero Complex.sinh_zero @[simp] theorem sinh_neg : sinh (-x) = -sinh x := by simp [sinh, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sinh_neg Complex.sinh_neg private theorem sinh_add_aux {a b c d : ℂ} : (a - b) * (c + d) + (a + b) * (c - d) = 2 * (a * c - b * d) := by ring theorem sinh_add : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_sinh, mul_left_comm, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, ← mul_assoc, two_cosh] exact sinh_add_aux #align complex.sinh_add Complex.sinh_add @[simp] theorem cosh_zero : cosh 0 = 1 := by simp [cosh] #align complex.cosh_zero Complex.cosh_zero @[simp] theorem cosh_neg : cosh (-x) = cosh x := by simp [add_comm, cosh, exp_neg] #align complex.cosh_neg Complex.cosh_neg private theorem cosh_add_aux {a b c d : ℂ} : (a + b) * (c + d) + (a - b) * (c - d) = 2 * (a * c + b * d) := by ring theorem cosh_add : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, exp_add, neg_add, exp_add, eq_comm, mul_add, ← mul_assoc, two_cosh, ← mul_assoc, two_sinh, ← mul_right_inj' (two_ne_zero' ℂ), mul_add, mul_left_comm, two_cosh, mul_left_comm, two_sinh] exact cosh_add_aux #align complex.cosh_add Complex.cosh_add theorem sinh_sub : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := by simp [sub_eq_add_neg, sinh_add, sinh_neg, cosh_neg] #align complex.sinh_sub Complex.sinh_sub theorem cosh_sub : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := by simp [sub_eq_add_neg, cosh_add, sinh_neg, cosh_neg] #align complex.cosh_sub Complex.cosh_sub theorem sinh_conj : sinh (conj x) = conj (sinh x) := by rw [sinh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_sub, sinh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.sinh_conj Complex.sinh_conj @[simp] theorem ofReal_sinh_ofReal_re (x : ℝ) : ((sinh x).re : ℂ) = sinh x := conj_eq_iff_re.1 <| by rw [← sinh_conj, conj_ofReal] #align complex.of_real_sinh_of_real_re Complex.ofReal_sinh_ofReal_re @[simp, norm_cast] theorem ofReal_sinh (x : ℝ) : (Real.sinh x : ℂ) = sinh x := ofReal_sinh_ofReal_re _ #align complex.of_real_sinh Complex.ofReal_sinh @[simp] theorem sinh_ofReal_im (x : ℝ) : (sinh x).im = 0 := by rw [← ofReal_sinh_ofReal_re, ofReal_im] #align complex.sinh_of_real_im Complex.sinh_ofReal_im theorem sinh_ofReal_re (x : ℝ) : (sinh x).re = Real.sinh x := rfl #align complex.sinh_of_real_re Complex.sinh_ofReal_re theorem cosh_conj : cosh (conj x) = conj (cosh x) := by rw [cosh, ← RingHom.map_neg, exp_conj, exp_conj, ← RingHom.map_add, cosh, map_div₀] -- Porting note: not nice simp [← one_add_one_eq_two] #align complex.cosh_conj Complex.cosh_conj theorem ofReal_cosh_ofReal_re (x : ℝ) : ((cosh x).re : ℂ) = cosh x := conj_eq_iff_re.1 <| by rw [← cosh_conj, conj_ofReal] #align complex.of_real_cosh_of_real_re Complex.ofReal_cosh_ofReal_re @[simp, norm_cast] theorem ofReal_cosh (x : ℝ) : (Real.cosh x : ℂ) = cosh x := ofReal_cosh_ofReal_re _ #align complex.of_real_cosh Complex.ofReal_cosh @[simp] theorem cosh_ofReal_im (x : ℝ) : (cosh x).im = 0 := by rw [← ofReal_cosh_ofReal_re, ofReal_im] #align complex.cosh_of_real_im Complex.cosh_ofReal_im @[simp] theorem cosh_ofReal_re (x : ℝ) : (cosh x).re = Real.cosh x := rfl #align complex.cosh_of_real_re Complex.cosh_ofReal_re theorem tanh_eq_sinh_div_cosh : tanh x = sinh x / cosh x := rfl #align complex.tanh_eq_sinh_div_cosh Complex.tanh_eq_sinh_div_cosh @[simp] theorem tanh_zero : tanh 0 = 0 := by simp [tanh] #align complex.tanh_zero Complex.tanh_zero @[simp] theorem tanh_neg : tanh (-x) = -tanh x := by simp [tanh, neg_div] #align complex.tanh_neg Complex.tanh_neg theorem tanh_conj : tanh (conj x) = conj (tanh x) := by rw [tanh, sinh_conj, cosh_conj, ← map_div₀, tanh] #align complex.tanh_conj Complex.tanh_conj @[simp] theorem ofReal_tanh_ofReal_re (x : ℝ) : ((tanh x).re : ℂ) = tanh x := conj_eq_iff_re.1 <| by rw [← tanh_conj, conj_ofReal] #align complex.of_real_tanh_of_real_re Complex.ofReal_tanh_ofReal_re @[simp, norm_cast] theorem ofReal_tanh (x : ℝ) : (Real.tanh x : ℂ) = tanh x := ofReal_tanh_ofReal_re _ #align complex.of_real_tanh Complex.ofReal_tanh @[simp] theorem tanh_ofReal_im (x : ℝ) : (tanh x).im = 0 := by rw [← ofReal_tanh_ofReal_re, ofReal_im] #align complex.tanh_of_real_im Complex.tanh_ofReal_im theorem tanh_ofReal_re (x : ℝ) : (tanh x).re = Real.tanh x := rfl #align complex.tanh_of_real_re Complex.tanh_ofReal_re @[simp] theorem cosh_add_sinh : cosh x + sinh x = exp x := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_add, two_cosh, two_sinh, add_add_sub_cancel, two_mul] #align complex.cosh_add_sinh Complex.cosh_add_sinh @[simp] theorem sinh_add_cosh : sinh x + cosh x = exp x := by rw [add_comm, cosh_add_sinh] #align complex.sinh_add_cosh Complex.sinh_add_cosh @[simp] theorem exp_sub_cosh : exp x - cosh x = sinh x := sub_eq_iff_eq_add.2 (sinh_add_cosh x).symm #align complex.exp_sub_cosh Complex.exp_sub_cosh @[simp] theorem exp_sub_sinh : exp x - sinh x = cosh x := sub_eq_iff_eq_add.2 (cosh_add_sinh x).symm #align complex.exp_sub_sinh Complex.exp_sub_sinh @[simp] theorem cosh_sub_sinh : cosh x - sinh x = exp (-x) := by rw [← mul_right_inj' (two_ne_zero' ℂ), mul_sub, two_cosh, two_sinh, add_sub_sub_cancel, two_mul] #align complex.cosh_sub_sinh Complex.cosh_sub_sinh @[simp] theorem sinh_sub_cosh : sinh x - cosh x = -exp (-x) := by rw [← neg_sub, cosh_sub_sinh] #align complex.sinh_sub_cosh Complex.sinh_sub_cosh @[simp] theorem cosh_sq_sub_sinh_sq : cosh x ^ 2 - sinh x ^ 2 = 1 := by rw [sq_sub_sq, cosh_add_sinh, cosh_sub_sinh, ← exp_add, add_neg_self, exp_zero] #align complex.cosh_sq_sub_sinh_sq Complex.cosh_sq_sub_sinh_sq theorem cosh_sq : cosh x ^ 2 = sinh x ^ 2 + 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.cosh_sq Complex.cosh_sq theorem sinh_sq : sinh x ^ 2 = cosh x ^ 2 - 1 := by rw [← cosh_sq_sub_sinh_sq x] ring #align complex.sinh_sq Complex.sinh_sq theorem cosh_two_mul : cosh (2 * x) = cosh x ^ 2 + sinh x ^ 2 := by rw [two_mul, cosh_add, sq, sq] #align complex.cosh_two_mul Complex.cosh_two_mul theorem sinh_two_mul : sinh (2 * x) = 2 * sinh x * cosh x := by rw [two_mul, sinh_add] ring #align complex.sinh_two_mul Complex.sinh_two_mul theorem cosh_three_mul : cosh (3 * x) = 4 * cosh x ^ 3 - 3 * cosh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cosh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : sinh x * (2 * sinh x * cosh x) = 2 * cosh x * sinh x ^ 2 := by ring rw [h2, sinh_sq] ring #align complex.cosh_three_mul Complex.cosh_three_mul theorem sinh_three_mul : sinh (3 * x) = 4 * sinh x ^ 3 + 3 * sinh x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sinh_add x (2 * x)] simp only [cosh_two_mul, sinh_two_mul] have h2 : cosh x * (2 * sinh x * cosh x) = 2 * sinh x * cosh x ^ 2 := by ring rw [h2, cosh_sq] ring #align complex.sinh_three_mul Complex.sinh_three_mul @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align complex.sin_zero Complex.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, sub_eq_add_neg, exp_neg, (neg_div _ _).symm, add_mul] #align complex.sin_neg Complex.sin_neg theorem two_sin : 2 * sin x = (exp (-x * I) - exp (x * I)) * I := mul_div_cancel₀ _ two_ne_zero #align complex.two_sin Complex.two_sin theorem two_cos : 2 * cos x = exp (x * I) + exp (-x * I) := mul_div_cancel₀ _ two_ne_zero #align complex.two_cos Complex.two_cos theorem sinh_mul_I : sinh (x * I) = sin x * I := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_sinh, ← mul_assoc, two_sin, mul_assoc, I_mul_I, mul_neg_one, neg_sub, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.sinh_mul_I Complex.sinh_mul_I theorem cosh_mul_I : cosh (x * I) = cos x := by rw [← mul_right_inj' (two_ne_zero' ℂ), two_cosh, two_cos, neg_mul_eq_neg_mul] set_option linter.uppercaseLean3 false in #align complex.cosh_mul_I Complex.cosh_mul_I theorem tanh_mul_I : tanh (x * I) = tan x * I := by rw [tanh_eq_sinh_div_cosh, cosh_mul_I, sinh_mul_I, mul_div_right_comm, tan] set_option linter.uppercaseLean3 false in #align complex.tanh_mul_I Complex.tanh_mul_I theorem cos_mul_I : cos (x * I) = cosh x := by rw [← cosh_mul_I]; ring_nf; simp set_option linter.uppercaseLean3 false in #align complex.cos_mul_I Complex.cos_mul_I theorem sin_mul_I : sin (x * I) = sinh x * I := by have h : I * sin (x * I) = -sinh x := by rw [mul_comm, ← sinh_mul_I] ring_nf simp rw [← neg_neg (sinh x), ← h] apply Complex.ext <;> simp set_option linter.uppercaseLean3 false in #align complex.sin_mul_I Complex.sin_mul_I theorem tan_mul_I : tan (x * I) = tanh x * I := by rw [tan, sin_mul_I, cos_mul_I, mul_div_right_comm, tanh_eq_sinh_div_cosh] set_option linter.uppercaseLean3 false in #align complex.tan_mul_I Complex.tan_mul_I theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, add_mul, add_mul, mul_right_comm, ← sinh_mul_I, mul_assoc, ← sinh_mul_I, ← cosh_mul_I, ← cosh_mul_I, sinh_add] #align complex.sin_add Complex.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align complex.cos_zero Complex.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, sub_eq_add_neg, exp_neg, add_comm] #align complex.cos_neg Complex.cos_neg private theorem cos_add_aux {a b c d : ℂ} : (a + b) * (c + d) - (b - a) * (d - c) * -1 = 2 * (a * c + b * d) := by ring theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := by rw [← cosh_mul_I, add_mul, cosh_add, cosh_mul_I, cosh_mul_I, sinh_mul_I, sinh_mul_I, mul_mul_mul_comm, I_mul_I, mul_neg_one, sub_eq_add_neg] #align complex.cos_add Complex.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align complex.sin_sub Complex.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align complex.cos_sub Complex.cos_sub theorem sin_add_mul_I (x y : ℂ) : sin (x + y * I) = sin x * cosh y + cos x * sinh y * I := by rw [sin_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.sin_add_mul_I Complex.sin_add_mul_I theorem sin_eq (z : ℂ) : sin z = sin z.re * cosh z.im + cos z.re * sinh z.im * I := by convert sin_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.sin_eq Complex.sin_eq theorem cos_add_mul_I (x y : ℂ) : cos (x + y * I) = cos x * cosh y - sin x * sinh y * I := by rw [cos_add, cos_mul_I, sin_mul_I, mul_assoc] set_option linter.uppercaseLean3 false in #align complex.cos_add_mul_I Complex.cos_add_mul_I theorem cos_eq (z : ℂ) : cos z = cos z.re * cosh z.im - sin z.re * sinh z.im * I := by convert cos_add_mul_I z.re z.im; exact (re_add_im z).symm #align complex.cos_eq Complex.cos_eq theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := by have s1 := sin_add ((x + y) / 2) ((x - y) / 2) have s2 := sin_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.sin_sub_sin Complex.sin_sub_sin theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := by have s1 := cos_add ((x + y) / 2) ((x - y) / 2) have s2 := cos_sub ((x + y) / 2) ((x - y) / 2) rw [div_add_div_same, add_sub, add_right_comm, add_sub_cancel_right, half_add_self] at s1 rw [div_sub_div_same, ← sub_add, add_sub_cancel_left, half_add_self] at s2 rw [s1, s2] ring #align complex.cos_sub_cos Complex.cos_sub_cos theorem sin_add_sin : sin x + sin y = 2 * sin ((x + y) / 2) * cos ((x - y) / 2) := by simpa using sin_sub_sin x (-y) theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := by calc cos x + cos y = cos ((x + y) / 2 + (x - y) / 2) + cos ((x + y) / 2 - (x - y) / 2) := ?_ _ = cos ((x + y) / 2) * cos ((x - y) / 2) - sin ((x + y) / 2) * sin ((x - y) / 2) + (cos ((x + y) / 2) * cos ((x - y) / 2) + sin ((x + y) / 2) * sin ((x - y) / 2)) := ?_ _ = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ?_ · congr <;> field_simp · rw [cos_add, cos_sub] ring #align complex.cos_add_cos Complex.cos_add_cos theorem sin_conj : sin (conj x) = conj (sin x) := by rw [← mul_left_inj' I_ne_zero, ← sinh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← RingHom.map_mul, sinh_conj, mul_neg, sinh_neg, sinh_mul_I, mul_neg] #align complex.sin_conj Complex.sin_conj @[simp] theorem ofReal_sin_ofReal_re (x : ℝ) : ((sin x).re : ℂ) = sin x := conj_eq_iff_re.1 <| by rw [← sin_conj, conj_ofReal] #align complex.of_real_sin_of_real_re Complex.ofReal_sin_ofReal_re @[simp, norm_cast] theorem ofReal_sin (x : ℝ) : (Real.sin x : ℂ) = sin x := ofReal_sin_ofReal_re _ #align complex.of_real_sin Complex.ofReal_sin @[simp] theorem sin_ofReal_im (x : ℝ) : (sin x).im = 0 := by rw [← ofReal_sin_ofReal_re, ofReal_im] #align complex.sin_of_real_im Complex.sin_ofReal_im theorem sin_ofReal_re (x : ℝ) : (sin x).re = Real.sin x := rfl #align complex.sin_of_real_re Complex.sin_ofReal_re theorem cos_conj : cos (conj x) = conj (cos x) := by rw [← cosh_mul_I, ← conj_neg_I, ← RingHom.map_mul, ← cosh_mul_I, cosh_conj, mul_neg, cosh_neg] #align complex.cos_conj Complex.cos_conj @[simp] theorem ofReal_cos_ofReal_re (x : ℝ) : ((cos x).re : ℂ) = cos x := conj_eq_iff_re.1 <| by rw [← cos_conj, conj_ofReal] #align complex.of_real_cos_of_real_re Complex.ofReal_cos_ofReal_re @[simp, norm_cast] theorem ofReal_cos (x : ℝ) : (Real.cos x : ℂ) = cos x := ofReal_cos_ofReal_re _ #align complex.of_real_cos Complex.ofReal_cos @[simp] theorem cos_ofReal_im (x : ℝ) : (cos x).im = 0 := by rw [← ofReal_cos_ofReal_re, ofReal_im] #align complex.cos_of_real_im Complex.cos_ofReal_im theorem cos_ofReal_re (x : ℝ) : (cos x).re = Real.cos x := rfl #align complex.cos_of_real_re Complex.cos_ofReal_re @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align complex.tan_zero Complex.tan_zero theorem tan_eq_sin_div_cos : tan x = sin x / cos x := rfl #align complex.tan_eq_sin_div_cos Complex.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℂ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align complex.tan_mul_cos Complex.tan_mul_cos @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align complex.tan_neg Complex.tan_neg theorem tan_conj : tan (conj x) = conj (tan x) := by rw [tan, sin_conj, cos_conj, ← map_div₀, tan] #align complex.tan_conj Complex.tan_conj @[simp] theorem ofReal_tan_ofReal_re (x : ℝ) : ((tan x).re : ℂ) = tan x := conj_eq_iff_re.1 <| by rw [← tan_conj, conj_ofReal] #align complex.of_real_tan_of_real_re Complex.ofReal_tan_ofReal_re @[simp, norm_cast] theorem ofReal_tan (x : ℝ) : (Real.tan x : ℂ) = tan x := ofReal_tan_ofReal_re _ #align complex.of_real_tan Complex.ofReal_tan @[simp] theorem tan_ofReal_im (x : ℝ) : (tan x).im = 0 := by rw [← ofReal_tan_ofReal_re, ofReal_im] #align complex.tan_of_real_im Complex.tan_ofReal_im theorem tan_ofReal_re (x : ℝ) : (tan x).re = Real.tan x := rfl #align complex.tan_of_real_re Complex.tan_ofReal_re theorem cos_add_sin_I : cos x + sin x * I = exp (x * I) := by rw [← cosh_add_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_I Complex.cos_add_sin_I theorem cos_sub_sin_I : cos x - sin x * I = exp (-x * I) := by rw [neg_mul, ← cosh_sub_sinh, sinh_mul_I, cosh_mul_I] set_option linter.uppercaseLean3 false in #align complex.cos_sub_sin_I Complex.cos_sub_sin_I @[simp] theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := Eq.trans (by rw [cosh_mul_I, sinh_mul_I, mul_pow, I_sq, mul_neg_one, sub_neg_eq_add, add_comm]) (cosh_sq_sub_sinh_sq (x * I)) #align complex.sin_sq_add_cos_sq Complex.sin_sq_add_cos_sq @[simp] theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by rw [add_comm, sin_sq_add_cos_sq] #align complex.cos_sq_add_sin_sq Complex.cos_sq_add_sin_sq theorem cos_two_mul' : cos (2 * x) = cos x ^ 2 - sin x ^ 2 := by rw [two_mul, cos_add, ← sq, ← sq] #align complex.cos_two_mul' Complex.cos_two_mul' theorem cos_two_mul : cos (2 * x) = 2 * cos x ^ 2 - 1 := by rw [cos_two_mul', eq_sub_iff_add_eq.2 (sin_sq_add_cos_sq x), ← sub_add, sub_add_eq_add_sub, two_mul] #align complex.cos_two_mul Complex.cos_two_mul theorem sin_two_mul : sin (2 * x) = 2 * sin x * cos x := by rw [two_mul, sin_add, two_mul, add_mul, mul_comm] #align complex.sin_two_mul Complex.sin_two_mul theorem cos_sq : cos x ^ 2 = 1 / 2 + cos (2 * x) / 2 := by simp [cos_two_mul, div_add_div_same, mul_div_cancel_left₀, two_ne_zero, -one_div] #align complex.cos_sq Complex.cos_sq theorem cos_sq' : cos x ^ 2 = 1 - sin x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_left] #align complex.cos_sq' Complex.cos_sq' theorem sin_sq : sin x ^ 2 = 1 - cos x ^ 2 := by rw [← sin_sq_add_cos_sq x, add_sub_cancel_right] #align complex.sin_sq Complex.sin_sq theorem inv_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : (1 + tan x ^ 2)⁻¹ = cos x ^ 2 := by rw [tan_eq_sin_div_cos, div_pow] field_simp #align complex.inv_one_add_tan_sq Complex.inv_one_add_tan_sq theorem tan_sq_div_one_add_tan_sq {x : ℂ} (hx : cos x ≠ 0) : tan x ^ 2 / (1 + tan x ^ 2) = sin x ^ 2 := by simp only [← tan_mul_cos hx, mul_pow, ← inv_one_add_tan_sq hx, div_eq_mul_inv, one_mul] #align complex.tan_sq_div_one_add_tan_sq Complex.tan_sq_div_one_add_tan_sq theorem cos_three_mul : cos (3 * x) = 4 * cos x ^ 3 - 3 * cos x := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, cos_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, mul_add, mul_sub, mul_one, sq] have h2 : 4 * cos x ^ 3 = 2 * cos x * cos x * cos x + 2 * cos x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.cos_three_mul Complex.cos_three_mul theorem sin_three_mul : sin (3 * x) = 3 * sin x - 4 * sin x ^ 3 := by have h1 : x + 2 * x = 3 * x := by ring rw [← h1, sin_add x (2 * x)] simp only [cos_two_mul, sin_two_mul, cos_sq'] have h2 : cos x * (2 * sin x * cos x) = 2 * sin x * cos x ^ 2 := by ring rw [h2, cos_sq'] ring #align complex.sin_three_mul Complex.sin_three_mul theorem exp_mul_I : exp (x * I) = cos x + sin x * I := (cos_add_sin_I _).symm set_option linter.uppercaseLean3 false in #align complex.exp_mul_I Complex.exp_mul_I theorem exp_add_mul_I : exp (x + y * I) = exp x * (cos y + sin y * I) := by rw [exp_add, exp_mul_I] set_option linter.uppercaseLean3 false in #align complex.exp_add_mul_I Complex.exp_add_mul_I theorem exp_eq_exp_re_mul_sin_add_cos : exp x = exp x.re * (cos x.im + sin x.im * I) := by rw [← exp_add_mul_I, re_add_im] #align complex.exp_eq_exp_re_mul_sin_add_cos Complex.exp_eq_exp_re_mul_sin_add_cos theorem exp_re : (exp x).re = Real.exp x.re * Real.cos x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, cos_ofReal_re] #align complex.exp_re Complex.exp_re theorem exp_im : (exp x).im = Real.exp x.re * Real.sin x.im := by rw [exp_eq_exp_re_mul_sin_add_cos] simp [exp_ofReal_re, sin_ofReal_re] #align complex.exp_im Complex.exp_im @[simp] theorem exp_ofReal_mul_I_re (x : ℝ) : (exp (x * I)).re = Real.cos x := by simp [exp_mul_I, cos_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_re Complex.exp_ofReal_mul_I_re @[simp] theorem exp_ofReal_mul_I_im (x : ℝ) : (exp (x * I)).im = Real.sin x := by simp [exp_mul_I, sin_ofReal_re] set_option linter.uppercaseLean3 false in #align complex.exp_of_real_mul_I_im Complex.exp_ofReal_mul_I_im /-- **De Moivre's formula** -/ theorem cos_add_sin_mul_I_pow (n : ℕ) (z : ℂ) : (cos z + sin z * I) ^ n = cos (↑n * z) + sin (↑n * z) * I := by rw [← exp_mul_I, ← exp_mul_I] induction' n with n ih · rw [pow_zero, Nat.cast_zero, zero_mul, zero_mul, exp_zero] · rw [pow_succ, ih, Nat.cast_succ, add_mul, add_mul, one_mul, exp_add] set_option linter.uppercaseLean3 false in #align complex.cos_add_sin_mul_I_pow Complex.cos_add_sin_mul_I_pow end Complex namespace Real open Complex variable (x y : ℝ) @[simp] theorem exp_zero : exp 0 = 1 := by simp [Real.exp] #align real.exp_zero Real.exp_zero nonrec theorem exp_add : exp (x + y) = exp x * exp y := by simp [exp_add, exp] #align real.exp_add Real.exp_add -- Porting note (#11445): new definition /-- the exponential function as a monoid hom from `Multiplicative ℝ` to `ℝ` -/ noncomputable def expMonoidHom : MonoidHom (Multiplicative ℝ) ℝ := { toFun := fun x => exp (Multiplicative.toAdd x), 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 #align real.exp_list_sum Real.exp_list_sum theorem exp_multiset_sum (s : Multiset ℝ) : exp s.sum = (s.map exp).prod := @MonoidHom.map_multiset_prod (Multiplicative ℝ) ℝ _ _ expMonoidHom s #align real.exp_multiset_sum Real.exp_multiset_sum theorem exp_sum {α : Type*} (s : Finset α) (f : α → ℝ) : exp (∑ x ∈ s, f x) = ∏ x ∈ s, exp (f x) := map_prod (β := Multiplicative ℝ) expMonoidHom f s #align real.exp_sum Real.exp_sum 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]) #align real.exp_nat_mul Real.exp_nat_mul nonrec theorem exp_ne_zero : exp x ≠ 0 := fun h => exp_ne_zero x <| by rw [exp, ← ofReal_inj] at h; simp_all #align real.exp_ne_zero Real.exp_ne_zero nonrec theorem exp_neg : exp (-x) = (exp x)⁻¹ := ofReal_injective <| by simp [exp_neg] #align real.exp_neg Real.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] #align real.exp_sub Real.exp_sub @[simp] theorem sin_zero : sin 0 = 0 := by simp [sin] #align real.sin_zero Real.sin_zero @[simp] theorem sin_neg : sin (-x) = -sin x := by simp [sin, exp_neg, (neg_div _ _).symm, add_mul] #align real.sin_neg Real.sin_neg nonrec theorem sin_add : sin (x + y) = sin x * cos y + cos x * sin y := ofReal_injective <| by simp [sin_add] #align real.sin_add Real.sin_add @[simp] theorem cos_zero : cos 0 = 1 := by simp [cos] #align real.cos_zero Real.cos_zero @[simp] theorem cos_neg : cos (-x) = cos x := by simp [cos, exp_neg] #align real.cos_neg Real.cos_neg @[simp] theorem cos_abs : cos |x| = cos x := by cases le_total x 0 <;> simp only [*, _root_.abs_of_nonneg, abs_of_nonpos, cos_neg] #align real.cos_abs Real.cos_abs nonrec theorem cos_add : cos (x + y) = cos x * cos y - sin x * sin y := ofReal_injective <| by simp [cos_add] #align real.cos_add Real.cos_add theorem sin_sub : sin (x - y) = sin x * cos y - cos x * sin y := by simp [sub_eq_add_neg, sin_add, sin_neg, cos_neg] #align real.sin_sub Real.sin_sub theorem cos_sub : cos (x - y) = cos x * cos y + sin x * sin y := by simp [sub_eq_add_neg, cos_add, sin_neg, cos_neg] #align real.cos_sub Real.cos_sub nonrec theorem sin_sub_sin : sin x - sin y = 2 * sin ((x - y) / 2) * cos ((x + y) / 2) := ofReal_injective <| by simp [sin_sub_sin] #align real.sin_sub_sin Real.sin_sub_sin nonrec theorem cos_sub_cos : cos x - cos y = -2 * sin ((x + y) / 2) * sin ((x - y) / 2) := ofReal_injective <| by simp [cos_sub_cos] #align real.cos_sub_cos Real.cos_sub_cos nonrec theorem cos_add_cos : cos x + cos y = 2 * cos ((x + y) / 2) * cos ((x - y) / 2) := ofReal_injective <| by simp [cos_add_cos] #align real.cos_add_cos Real.cos_add_cos nonrec theorem tan_eq_sin_div_cos : tan x = sin x / cos x := ofReal_injective <| by simp [tan_eq_sin_div_cos] #align real.tan_eq_sin_div_cos Real.tan_eq_sin_div_cos theorem tan_mul_cos {x : ℝ} (hx : cos x ≠ 0) : tan x * cos x = sin x := by rw [tan_eq_sin_div_cos, div_mul_cancel₀ _ hx] #align real.tan_mul_cos Real.tan_mul_cos @[simp] theorem tan_zero : tan 0 = 0 := by simp [tan] #align real.tan_zero Real.tan_zero @[simp] theorem tan_neg : tan (-x) = -tan x := by simp [tan, neg_div] #align real.tan_neg Real.tan_neg @[simp] nonrec theorem sin_sq_add_cos_sq : sin x ^ 2 + cos x ^ 2 = 1 := ofReal_injective (by simp [sin_sq_add_cos_sq]) #align real.sin_sq_add_cos_sq Real.sin_sq_add_cos_sq @[simp]
Mathlib/Data/Complex/Exponential.lean
940
940
theorem cos_sq_add_sin_sq : cos x ^ 2 + sin x ^ 2 = 1 := by
rw [add_comm, sin_sq_add_cos_sq]
/- Copyright (c) 2018 Louis Carlin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Louis Carlin, Mario Carneiro -/ import Mathlib.Algebra.Divisibility.Basic import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Ring.Defs #align_import algebra.euclidean_domain.defs from "leanprover-community/mathlib"@"ee7b9f9a9ac2a8d9f04ea39bbfe6b1a3be053b38" /-! # Euclidean domains This file introduces Euclidean domains and provides the extended Euclidean algorithm. To be precise, a slightly more general version is provided which is sometimes called a transfinite Euclidean domain and differs in the fact that the degree function need not take values in `ℕ` but can take values in any well-ordered set. Transfinite Euclidean domains were introduced by Motzkin and examples which don't satisfy the classical notion were provided independently by Hiblot and Nagata. ## Main definitions * `EuclideanDomain`: Defines Euclidean domain with functions `quotient` and `remainder`. Instances of `Div` and `Mod` are provided, so that one can write `a = b * (a / b) + a % b`. * `gcd`: defines the greatest common divisors of two elements of a Euclidean domain. * `xgcd`: given two elements `a b : R`, `xgcd a b` defines the pair `(x, y)` such that `x * a + y * b = gcd a b`. * `lcm`: defines the lowest common multiple of two elements `a` and `b` of a Euclidean domain as `a * b / (gcd a b)` ## Main statements See `Algebra.EuclideanDomain.Basic` for most of the theorems about Euclidean domains, including Bézout's lemma. See `Algebra.EuclideanDomain.Instances` for the fact that `ℤ` is a Euclidean domain, as is any field. ## Notation `≺` denotes the well founded relation on the Euclidean domain, e.g. in the example of the polynomial ring over a field, `p ≺ q` for polynomials `p` and `q` if and only if the degree of `p` is less than the degree of `q`. ## Implementation details Instead of working with a valuation, `EuclideanDomain` is implemented with the existence of a well founded relation `r` on the integral domain `R`, which in the example of `ℤ` would correspond to setting `i ≺ j` for integers `i` and `j` if the absolute value of `i` is smaller than the absolute value of `j`. ## References * [Th. Motzkin, *The Euclidean algorithm*][MR32592] * [J.-J. Hiblot, *Des anneaux euclidiens dont le plus petit algorithme n'est pas à valeurs finies*] [MR399081] * [M. Nagata, *On Euclid algorithm*][MR541021] ## Tags Euclidean domain, transfinite Euclidean domain, Bézout's lemma -/ universe u /-- A `EuclideanDomain` is a non-trivial commutative ring with a division and a remainder, satisfying `b * (a / b) + a % b = a`. The definition of a Euclidean domain usually includes a valuation function `R → ℕ`. This definition is slightly generalised to include a well founded relation `r` with the property that `r (a % b) b`, instead of a valuation. -/ class EuclideanDomain (R : Type u) extends CommRing R, Nontrivial R where /-- A division function (denoted `/`) on `R`. This satisfies the property `b * (a / b) + a % b = a`, where `%` denotes `remainder`. -/ protected quotient : R → R → R /-- Division by zero should always give zero by convention. -/ protected quotient_zero : ∀ a, quotient a 0 = 0 /-- A remainder function (denoted `%`) on `R`. This satisfies the property `b * (a / b) + a % b = a`, where `/` denotes `quotient`. -/ protected remainder : R → R → R /-- The property that links the quotient and remainder functions. This allows us to compute GCDs and LCMs. -/ protected quotient_mul_add_remainder_eq : ∀ a b, b * quotient a b + remainder a b = a /-- A well-founded relation on `R`, satisfying `r (a % b) b`. This ensures that the GCD algorithm always terminates. -/ protected r : R → R → Prop /-- The relation `r` must be well-founded. This ensures that the GCD algorithm always terminates. -/ r_wellFounded : WellFounded r /-- The relation `r` satisfies `r (a % b) b`. -/ protected remainder_lt : ∀ (a) {b}, b ≠ 0 → r (remainder a b) b /-- An additional constraint on `r`. -/ mul_left_not_lt : ∀ (a) {b}, b ≠ 0 → ¬r (a * b) a #align euclidean_domain EuclideanDomain #align euclidean_domain.quotient EuclideanDomain.quotient #align euclidean_domain.quotient_zero EuclideanDomain.quotient_zero #align euclidean_domain.remainder EuclideanDomain.remainder #align euclidean_domain.quotient_mul_add_remainder_eq EuclideanDomain.quotient_mul_add_remainder_eq #align euclidean_domain.r EuclideanDomain.r #align euclidean_domain.r_well_founded EuclideanDomain.r_wellFounded #align euclidean_domain.remainder_lt EuclideanDomain.remainder_lt #align euclidean_domain.mul_left_not_lt EuclideanDomain.mul_left_not_lt namespace EuclideanDomain variable {R : Type u} [EuclideanDomain R] /-- Abbreviated notation for the well-founded relation `r` in a Euclidean domain. -/ local infixl:50 " ≺ " => EuclideanDomain.r local instance wellFoundedRelation : WellFoundedRelation R where wf := r_wellFounded -- see Note [lower instance priority] instance (priority := 70) : Div R := ⟨EuclideanDomain.quotient⟩ -- see Note [lower instance priority] instance (priority := 70) : Mod R := ⟨EuclideanDomain.remainder⟩ theorem div_add_mod (a b : R) : b * (a / b) + a % b = a := EuclideanDomain.quotient_mul_add_remainder_eq _ _ #align euclidean_domain.div_add_mod EuclideanDomain.div_add_mod theorem mod_add_div (a b : R) : a % b + b * (a / b) = a := (add_comm _ _).trans (div_add_mod _ _) #align euclidean_domain.mod_add_div EuclideanDomain.mod_add_div
Mathlib/Algebra/EuclideanDomain/Defs.lean
131
133
theorem mod_add_div' (m k : R) : m % k + m / k * k = m := by
rw [mul_comm] exact mod_add_div _ _
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sébastien Gouëzel, Yury Kudryashov, Anatole Dedecker -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Add #align_import analysis.calculus.deriv.add from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # One-dimensional derivatives of sums etc In this file we prove formulas about derivatives of `f + g`, `-f`, `f - g`, and `∑ i, f i x` for functions from the base field to a normed space over this field. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative -/ universe u v w open scoped Classical open Topology Filter ENNReal open Filter Asymptotics Set variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {f f₀ f₁ g : 𝕜 → F} variable {f' f₀' f₁' g' : F} variable {x : 𝕜} variable {s t : Set 𝕜} variable {L : Filter 𝕜} section Add /-! ### Derivative of the sum of two functions -/ nonrec theorem HasDerivAtFilter.add (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun y => f y + g y) (f' + g') x L := by simpa using (hf.add hg).hasDerivAtFilter #align has_deriv_at_filter.add HasDerivAtFilter.add nonrec theorem HasStrictDerivAt.add (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) : HasStrictDerivAt (fun y => f y + g y) (f' + g') x := by simpa using (hf.add hg).hasStrictDerivAt #align has_strict_deriv_at.add HasStrictDerivAt.add nonrec theorem HasDerivWithinAt.add (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg #align has_deriv_within_at.add HasDerivWithinAt.add nonrec theorem HasDerivAt.add (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) : HasDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg #align has_deriv_at.add HasDerivAt.add theorem derivWithin_add (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : derivWithin (fun y => f y + g y) s x = derivWithin f s x + derivWithin g s x := (hf.hasDerivWithinAt.add hg.hasDerivWithinAt).derivWithin hxs #align deriv_within_add derivWithin_add @[simp] theorem deriv_add (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : deriv (fun y => f y + g y) x = deriv f x + deriv g x := (hf.hasDerivAt.add hg.hasDerivAt).deriv #align deriv_add deriv_add -- Porting note (#10756): new theorem theorem HasStrictDerivAt.add_const (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y ↦ f y + c) f' x := add_zero f' ▸ hf.add (hasStrictDerivAt_const x c) theorem HasDerivAtFilter.add_const (hf : HasDerivAtFilter f f' x L) (c : F) : HasDerivAtFilter (fun y => f y + c) f' x L := add_zero f' ▸ hf.add (hasDerivAtFilter_const x L c) #align has_deriv_at_filter.add_const HasDerivAtFilter.add_const nonrec theorem HasDerivWithinAt.add_const (hf : HasDerivWithinAt f f' s x) (c : F) : HasDerivWithinAt (fun y => f y + c) f' s x := hf.add_const c #align has_deriv_within_at.add_const HasDerivWithinAt.add_const nonrec theorem HasDerivAt.add_const (hf : HasDerivAt f f' x) (c : F) : HasDerivAt (fun x => f x + c) f' x := hf.add_const c #align has_deriv_at.add_const HasDerivAt.add_const theorem derivWithin_add_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => f y + c) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_add_const hxs] #align deriv_within_add_const derivWithin_add_const theorem deriv_add_const (c : F) : deriv (fun y => f y + c) x = deriv f x := by simp only [deriv, fderiv_add_const] #align deriv_add_const deriv_add_const @[simp] theorem deriv_add_const' (c : F) : (deriv fun y => f y + c) = deriv f := funext fun _ => deriv_add_const c #align deriv_add_const' deriv_add_const' -- Porting note (#10756): new theorem theorem HasStrictDerivAt.const_add (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y ↦ c + f y) f' x := zero_add f' ▸ (hasStrictDerivAt_const x c).add hf theorem HasDerivAtFilter.const_add (c : F) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun y => c + f y) f' x L := zero_add f' ▸ (hasDerivAtFilter_const x L c).add hf #align has_deriv_at_filter.const_add HasDerivAtFilter.const_add nonrec theorem HasDerivWithinAt.const_add (c : F) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c + f y) f' s x := hf.const_add c #align has_deriv_within_at.const_add HasDerivWithinAt.const_add nonrec theorem HasDerivAt.const_add (c : F) (hf : HasDerivAt f f' x) : HasDerivAt (fun x => c + f x) f' x := hf.const_add c #align has_deriv_at.const_add HasDerivAt.const_add theorem derivWithin_const_add (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => c + f y) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_const_add hxs] #align deriv_within_const_add derivWithin_const_add theorem deriv_const_add (c : F) : deriv (fun y => c + f y) x = deriv f x := by simp only [deriv, fderiv_const_add] #align deriv_const_add deriv_const_add @[simp] theorem deriv_const_add' (c : F) : (deriv fun y => c + f y) = deriv f := funext fun _ => deriv_const_add c #align deriv_const_add' deriv_const_add' end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → 𝕜 → F} {A' : ι → F} theorem HasDerivAtFilter.sum (h : ∀ i ∈ u, HasDerivAtFilter (A i) (A' i) x L) : HasDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simpa [ContinuousLinearMap.sum_apply] using (HasFDerivAtFilter.sum h).hasDerivAtFilter #align has_deriv_at_filter.sum HasDerivAtFilter.sum theorem HasStrictDerivAt.sum (h : ∀ i ∈ u, HasStrictDerivAt (A i) (A' i) x) : HasStrictDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by simpa [ContinuousLinearMap.sum_apply] using (HasStrictFDerivAt.sum h).hasStrictDerivAt #align has_strict_deriv_at.sum HasStrictDerivAt.sum theorem HasDerivWithinAt.sum (h : ∀ i ∈ u, HasDerivWithinAt (A i) (A' i) s x) : HasDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasDerivAtFilter.sum h #align has_deriv_within_at.sum HasDerivWithinAt.sum theorem HasDerivAt.sum (h : ∀ i ∈ u, HasDerivAt (A i) (A' i) x) : HasDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasDerivAtFilter.sum h #align has_deriv_at.sum HasDerivAt.sum theorem derivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : derivWithin (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, derivWithin (A i) s x := (HasDerivWithinAt.sum fun i hi => (h i hi).hasDerivWithinAt).derivWithin hxs #align deriv_within_sum derivWithin_sum @[simp] theorem deriv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : deriv (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, deriv (A i) x := (HasDerivAt.sum fun i hi => (h i hi).hasDerivAt).deriv #align deriv_sum deriv_sum end Sum section Neg /-! ### Derivative of the negative of a function -/ nonrec theorem HasDerivAtFilter.neg (h : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun x => -f x) (-f') x L := by simpa using h.neg.hasDerivAtFilter #align has_deriv_at_filter.neg HasDerivAtFilter.neg nonrec theorem HasDerivWithinAt.neg (h : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => -f x) (-f') s x := h.neg #align has_deriv_within_at.neg HasDerivWithinAt.neg nonrec theorem HasDerivAt.neg (h : HasDerivAt f f' x) : HasDerivAt (fun x => -f x) (-f') x := h.neg #align has_deriv_at.neg HasDerivAt.neg nonrec theorem HasStrictDerivAt.neg (h : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => -f x) (-f') x := by simpa using h.neg.hasStrictDerivAt #align has_strict_deriv_at.neg HasStrictDerivAt.neg theorem derivWithin.neg (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin (fun y => -f y) s x = -derivWithin f s x := by simp only [derivWithin, fderivWithin_neg hxs, ContinuousLinearMap.neg_apply] #align deriv_within.neg derivWithin.neg theorem deriv.neg : deriv (fun y => -f y) x = -deriv f x := by simp only [deriv, fderiv_neg, ContinuousLinearMap.neg_apply] #align deriv.neg deriv.neg @[simp] theorem deriv.neg' : (deriv fun y => -f y) = fun x => -deriv f x := funext fun _ => deriv.neg #align deriv.neg' deriv.neg' end Neg section Neg2 /-! ### Derivative of the negation function (i.e `Neg.neg`) -/ variable (s x L) theorem hasDerivAtFilter_neg : HasDerivAtFilter Neg.neg (-1) x L := HasDerivAtFilter.neg <| hasDerivAtFilter_id _ _ #align has_deriv_at_filter_neg hasDerivAtFilter_neg theorem hasDerivWithinAt_neg : HasDerivWithinAt Neg.neg (-1) s x := hasDerivAtFilter_neg _ _ #align has_deriv_within_at_neg hasDerivWithinAt_neg theorem hasDerivAt_neg : HasDerivAt Neg.neg (-1) x := hasDerivAtFilter_neg _ _ #align has_deriv_at_neg hasDerivAt_neg theorem hasDerivAt_neg' : HasDerivAt (fun x => -x) (-1) x := hasDerivAtFilter_neg _ _ #align has_deriv_at_neg' hasDerivAt_neg' theorem hasStrictDerivAt_neg : HasStrictDerivAt Neg.neg (-1) x := HasStrictDerivAt.neg <| hasStrictDerivAt_id _ #align has_strict_deriv_at_neg hasStrictDerivAt_neg theorem deriv_neg : deriv Neg.neg x = -1 := HasDerivAt.deriv (hasDerivAt_neg x) #align deriv_neg deriv_neg @[simp] theorem deriv_neg' : deriv (Neg.neg : 𝕜 → 𝕜) = fun _ => -1 := funext deriv_neg #align deriv_neg' deriv_neg' @[simp] theorem deriv_neg'' : deriv (fun x : 𝕜 => -x) x = -1 := deriv_neg x #align deriv_neg'' deriv_neg'' theorem derivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : derivWithin Neg.neg s x = -1 := (hasDerivWithinAt_neg x s).derivWithin hxs #align deriv_within_neg derivWithin_neg theorem differentiable_neg : Differentiable 𝕜 (Neg.neg : 𝕜 → 𝕜) := Differentiable.neg differentiable_id #align differentiable_neg differentiable_neg theorem differentiableOn_neg : DifferentiableOn 𝕜 (Neg.neg : 𝕜 → 𝕜) s := DifferentiableOn.neg differentiableOn_id #align differentiable_on_neg differentiableOn_neg theorem not_differentiableAt_abs_zero : ¬ DifferentiableAt ℝ (abs : ℝ → ℝ) 0 := by intro h have h₁ : deriv abs (0 : ℝ) = 1 := (uniqueDiffOn_Ici _ _ Set.left_mem_Ici).eq_deriv _ h.hasDerivAt.hasDerivWithinAt <| (hasDerivWithinAt_id _ _).congr_of_mem (fun _ h ↦ abs_of_nonneg h) Set.left_mem_Ici have h₂ : deriv abs (0 : ℝ) = -1 := (uniqueDiffOn_Iic _ _ Set.right_mem_Iic).eq_deriv _ h.hasDerivAt.hasDerivWithinAt <| (hasDerivWithinAt_neg _ _).congr_of_mem (fun _ h ↦ abs_of_nonpos h) Set.right_mem_Iic linarith lemma differentiableAt_comp_neg_iff {a : 𝕜} : DifferentiableAt 𝕜 f (-a) ↔ DifferentiableAt 𝕜 (fun x ↦ f (-x)) a := by refine ⟨fun H ↦ H.comp a differentiable_neg.differentiableAt, fun H ↦ ?_⟩ convert ((neg_neg a).symm ▸ H).comp (-a) differentiable_neg.differentiableAt ext simp only [Function.comp_apply, neg_neg] end Neg2 section Sub /-! ### Derivative of the difference of two functions -/ theorem HasDerivAtFilter.sub (hf : HasDerivAtFilter f f' x L) (hg : HasDerivAtFilter g g' x L) : HasDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_deriv_at_filter.sub HasDerivAtFilter.sub nonrec theorem HasDerivWithinAt.sub (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) : HasDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg #align has_deriv_within_at.sub HasDerivWithinAt.sub nonrec theorem HasDerivAt.sub (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) : HasDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg #align has_deriv_at.sub HasDerivAt.sub theorem HasStrictDerivAt.sub (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) : HasStrictDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg #align has_strict_deriv_at.sub HasStrictDerivAt.sub theorem derivWithin_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : derivWithin (fun y => f y - g y) s x = derivWithin f s x - derivWithin g s x := (hf.hasDerivWithinAt.sub hg.hasDerivWithinAt).derivWithin hxs #align deriv_within_sub derivWithin_sub @[simp] theorem deriv_sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : deriv (fun y => f y - g y) x = deriv f x - deriv g x := (hf.hasDerivAt.sub hg.hasDerivAt).deriv #align deriv_sub deriv_sub theorem HasDerivAtFilter.sub_const (hf : HasDerivAtFilter f f' x L) (c : F) : HasDerivAtFilter (fun x => f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) #align has_deriv_at_filter.sub_const HasDerivAtFilter.sub_const nonrec theorem HasDerivWithinAt.sub_const (hf : HasDerivWithinAt f f' s x) (c : F) : HasDerivWithinAt (fun x => f x - c) f' s x := hf.sub_const c #align has_deriv_within_at.sub_const HasDerivWithinAt.sub_const nonrec theorem HasDerivAt.sub_const (hf : HasDerivAt f f' x) (c : F) : HasDerivAt (fun x => f x - c) f' x := hf.sub_const c #align has_deriv_at.sub_const HasDerivAt.sub_const theorem derivWithin_sub_const (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => f y - c) s x = derivWithin f s x := by simp only [derivWithin, fderivWithin_sub_const hxs] #align deriv_within_sub_const derivWithin_sub_const theorem deriv_sub_const (c : F) : deriv (fun y => f y - c) x = deriv f x := by simp only [deriv, fderiv_sub_const] #align deriv_sub_const deriv_sub_const theorem HasDerivAtFilter.const_sub (c : F) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun x => c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c #align has_deriv_at_filter.const_sub HasDerivAtFilter.const_sub nonrec theorem HasDerivWithinAt.const_sub (c : F) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun x => c - f x) (-f') s x := hf.const_sub c #align has_deriv_within_at.const_sub HasDerivWithinAt.const_sub theorem HasStrictDerivAt.const_sub (c : F) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun x => c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c #align has_strict_deriv_at.const_sub HasStrictDerivAt.const_sub nonrec theorem HasDerivAt.const_sub (c : F) (hf : HasDerivAt f f' x) : HasDerivAt (fun x => c - f x) (-f') x := hf.const_sub c #align has_deriv_at.const_sub HasDerivAt.const_sub theorem derivWithin_const_sub (hxs : UniqueDiffWithinAt 𝕜 s x) (c : F) : derivWithin (fun y => c - f y) s x = -derivWithin f s x := by simp [derivWithin, fderivWithin_const_sub hxs] #align deriv_within_const_sub derivWithin_const_sub
Mathlib/Analysis/Calculus/Deriv/Add.lean
380
382
theorem deriv_const_sub (c : F) : deriv (fun y => c - f y) x = -deriv f x := by
simp only [← derivWithin_univ, derivWithin_const_sub (uniqueDiffWithinAt_univ : UniqueDiffWithinAt 𝕜 _ _)]
/- Copyright (c) 2017 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Data.PFunctor.Univariate.Basic #align_import data.pfunctor.univariate.M from "leanprover-community/mathlib"@"8631e2d5ea77f6c13054d9151d82b83069680cb1" /-! # M-types M types are potentially infinite tree-like structures. They are defined as the greatest fixpoint of a polynomial functor. -/ universe u v w open Nat Function open List variable (F : PFunctor.{u}) -- Porting note: the ♯ tactic is never used -- local prefix:0 "♯" => cast (by first |simp [*]|cc|solve_by_elim) namespace PFunctor namespace Approx /-- `CofixA F n` is an `n` level approximation of an M-type -/ inductive CofixA : ℕ → Type u | continue : CofixA 0 | intro {n} : ∀ a, (F.B a → CofixA n) → CofixA (succ n) #align pfunctor.approx.cofix_a PFunctor.Approx.CofixA /-- default inhabitant of `CofixA` -/ protected def CofixA.default [Inhabited F.A] : ∀ n, CofixA F n | 0 => CofixA.continue | succ n => CofixA.intro default fun _ => CofixA.default n #align pfunctor.approx.cofix_a.default PFunctor.Approx.CofixA.default instance [Inhabited F.A] {n} : Inhabited (CofixA F n) := ⟨CofixA.default F n⟩ theorem cofixA_eq_zero : ∀ x y : CofixA F 0, x = y | CofixA.continue, CofixA.continue => rfl #align pfunctor.approx.cofix_a_eq_zero PFunctor.Approx.cofixA_eq_zero variable {F} /-- The label of the root of the tree for a non-trivial approximation of the cofix of a pfunctor. -/ def head' : ∀ {n}, CofixA F (succ n) → F.A | _, CofixA.intro i _ => i #align pfunctor.approx.head' PFunctor.Approx.head' /-- for a non-trivial approximation, return all the subtrees of the root -/ def children' : ∀ {n} (x : CofixA F (succ n)), F.B (head' x) → CofixA F n | _, CofixA.intro _ f => f #align pfunctor.approx.children' PFunctor.Approx.children' theorem approx_eta {n : ℕ} (x : CofixA F (n + 1)) : x = CofixA.intro (head' x) (children' x) := by cases x; rfl #align pfunctor.approx.approx_eta PFunctor.Approx.approx_eta /-- Relation between two approximations of the cofix of a pfunctor that state they both contain the same data until one of them is truncated -/ inductive Agree : ∀ {n : ℕ}, CofixA F n → CofixA F (n + 1) → Prop | continu (x : CofixA F 0) (y : CofixA F 1) : Agree x y | intro {n} {a} (x : F.B a → CofixA F n) (x' : F.B a → CofixA F (n + 1)) : (∀ i : F.B a, Agree (x i) (x' i)) → Agree (CofixA.intro a x) (CofixA.intro a x') #align pfunctor.approx.agree PFunctor.Approx.Agree /-- Given an infinite series of approximations `approx`, `AllAgree approx` states that they are all consistent with each other. -/ def AllAgree (x : ∀ n, CofixA F n) := ∀ n, Agree (x n) (x (succ n)) #align pfunctor.approx.all_agree PFunctor.Approx.AllAgree @[simp] theorem agree_trival {x : CofixA F 0} {y : CofixA F 1} : Agree x y := by constructor #align pfunctor.approx.agree_trival PFunctor.Approx.agree_trival theorem agree_children {n : ℕ} (x : CofixA F (succ n)) (y : CofixA F (succ n + 1)) {i j} (h₀ : HEq i j) (h₁ : Agree x y) : Agree (children' x i) (children' y j) := by cases' h₁ with _ _ _ _ _ _ hagree; cases h₀ apply hagree #align pfunctor.approx.agree_children PFunctor.Approx.agree_children /-- `truncate a` turns `a` into a more limited approximation -/ def truncate : ∀ {n : ℕ}, CofixA F (n + 1) → CofixA F n | 0, CofixA.intro _ _ => CofixA.continue | succ _, CofixA.intro i f => CofixA.intro i <| truncate ∘ f #align pfunctor.approx.truncate PFunctor.Approx.truncate theorem truncate_eq_of_agree {n : ℕ} (x : CofixA F n) (y : CofixA F (succ n)) (h : Agree x y) : truncate y = x := by induction n <;> cases x <;> cases y · rfl · -- cases' h with _ _ _ _ _ h₀ h₁ cases h simp only [truncate, Function.comp, true_and_iff, eq_self_iff_true, heq_iff_eq] -- Porting note: used to be `ext y` rename_i n_ih a f y h₁ suffices (fun x => truncate (y x)) = f by simp [this] funext y apply n_ih apply h₁ #align pfunctor.approx.truncate_eq_of_agree PFunctor.Approx.truncate_eq_of_agree variable {X : Type w} variable (f : X → F X) /-- `sCorec f i n` creates an approximation of height `n` of the final coalgebra of `f` -/ def sCorec : X → ∀ n, CofixA F n | _, 0 => CofixA.continue | j, succ _ => CofixA.intro (f j).1 fun i => sCorec ((f j).2 i) _ #align pfunctor.approx.s_corec PFunctor.Approx.sCorec theorem P_corec (i : X) (n : ℕ) : Agree (sCorec f i n) (sCorec f i (succ n)) := by induction' n with n n_ih generalizing i constructor cases' f i with y g constructor introv apply n_ih set_option linter.uppercaseLean3 false in #align pfunctor.approx.P_corec PFunctor.Approx.P_corec /-- `Path F` provides indices to access internal nodes in `Corec F` -/ def Path (F : PFunctor.{u}) := List F.Idx #align pfunctor.approx.path PFunctor.Approx.Path instance Path.inhabited : Inhabited (Path F) := ⟨[]⟩ #align pfunctor.approx.path.inhabited PFunctor.Approx.Path.inhabited open List Nat instance CofixA.instSubsingleton : Subsingleton (CofixA F 0) := ⟨by rintro ⟨⟩ ⟨⟩; rfl⟩ theorem head_succ' (n m : ℕ) (x : ∀ n, CofixA F n) (Hconsistent : AllAgree x) : head' (x (succ n)) = head' (x (succ m)) := by suffices ∀ n, head' (x (succ n)) = head' (x 1) by simp [this] clear m n intro n cases' h₀ : x (succ n) with _ i₀ f₀ cases' h₁ : x 1 with _ i₁ f₁ dsimp only [head'] induction' n with n n_ih · rw [h₁] at h₀ cases h₀ trivial · have H := Hconsistent (succ n) cases' h₂ : x (succ n) with _ i₂ f₂ rw [h₀, h₂] at H apply n_ih (truncate ∘ f₀) rw [h₂] cases' H with _ _ _ _ _ _ hagree congr funext j dsimp only [comp_apply] rw [truncate_eq_of_agree] apply hagree #align pfunctor.approx.head_succ' PFunctor.Approx.head_succ' end Approx open Approx /-- Internal definition for `M`. It is needed to avoid name clashes between `M.mk` and `M.cases_on` and the declarations generated for the structure -/ structure MIntl where /-- An `n`-th level approximation, for each depth `n` -/ approx : ∀ n, CofixA F n /-- Each approximation agrees with the next -/ consistent : AllAgree approx set_option linter.uppercaseLean3 false in #align pfunctor.M_intl PFunctor.MIntl /-- For polynomial functor `F`, `M F` is its final coalgebra -/ def M := MIntl F set_option linter.uppercaseLean3 false in #align pfunctor.M PFunctor.M theorem M.default_consistent [Inhabited F.A] : ∀ n, Agree (default : CofixA F n) default | 0 => Agree.continu _ _ | succ n => Agree.intro _ _ fun _ => M.default_consistent n set_option linter.uppercaseLean3 false in #align pfunctor.M.default_consistent PFunctor.M.default_consistent instance M.inhabited [Inhabited F.A] : Inhabited (M F) := ⟨{ approx := default consistent := M.default_consistent _ }⟩ set_option linter.uppercaseLean3 false in #align pfunctor.M.inhabited PFunctor.M.inhabited instance MIntl.inhabited [Inhabited F.A] : Inhabited (MIntl F) := show Inhabited (M F) by infer_instance set_option linter.uppercaseLean3 false in #align pfunctor.M_intl.inhabited PFunctor.MIntl.inhabited namespace M theorem ext' (x y : M F) (H : ∀ i : ℕ, x.approx i = y.approx i) : x = y := by cases x cases y congr with n apply H set_option linter.uppercaseLean3 false in #align pfunctor.M.ext' PFunctor.M.ext' variable {X : Type*} variable (f : X → F X) variable {F} /-- Corecursor for the M-type defined by `F`. -/ protected def corec (i : X) : M F where approx := sCorec f i consistent := P_corec _ _ set_option linter.uppercaseLean3 false in #align pfunctor.M.corec PFunctor.M.corec /-- given a tree generated by `F`, `head` gives us the first piece of data it contains -/ def head (x : M F) := head' (x.1 1) set_option linter.uppercaseLean3 false in #align pfunctor.M.head PFunctor.M.head /-- return all the subtrees of the root of a tree `x : M F` -/ def children (x : M F) (i : F.B (head x)) : M F := let H := fun n : ℕ => @head_succ' _ n 0 x.1 x.2 { approx := fun n => children' (x.1 _) (cast (congr_arg _ <| by simp only [head, H]) i) consistent := by intro n have P' := x.2 (succ n) apply agree_children _ _ _ P' trans i · apply cast_heq symm apply cast_heq } set_option linter.uppercaseLean3 false in #align pfunctor.M.children PFunctor.M.children /-- select a subtree using an `i : F.Idx` or return an arbitrary tree if `i` designates no subtree of `x` -/ def ichildren [Inhabited (M F)] [DecidableEq F.A] (i : F.Idx) (x : M F) : M F := if H' : i.1 = head x then children x (cast (congr_arg _ <| by simp only [head, H']) i.2) else default set_option linter.uppercaseLean3 false in #align pfunctor.M.ichildren PFunctor.M.ichildren theorem head_succ (n m : ℕ) (x : M F) : head' (x.approx (succ n)) = head' (x.approx (succ m)) := head_succ' n m _ x.consistent set_option linter.uppercaseLean3 false in #align pfunctor.M.head_succ PFunctor.M.head_succ theorem head_eq_head' : ∀ (x : M F) (n : ℕ), head x = head' (x.approx <| n + 1) | ⟨_, h⟩, _ => head_succ' _ _ _ h set_option linter.uppercaseLean3 false in #align pfunctor.M.head_eq_head' PFunctor.M.head_eq_head' theorem head'_eq_head : ∀ (x : M F) (n : ℕ), head' (x.approx <| n + 1) = head x | ⟨_, h⟩, _ => head_succ' _ _ _ h set_option linter.uppercaseLean3 false in #align pfunctor.M.head'_eq_head PFunctor.M.head'_eq_head theorem truncate_approx (x : M F) (n : ℕ) : truncate (x.approx <| n + 1) = x.approx n := truncate_eq_of_agree _ _ (x.consistent _) set_option linter.uppercaseLean3 false in #align pfunctor.M.truncate_approx PFunctor.M.truncate_approx /-- unfold an M-type -/ def dest : M F → F (M F) | x => ⟨head x, fun i => children x i⟩ set_option linter.uppercaseLean3 false in #align pfunctor.M.dest PFunctor.M.dest namespace Approx /-- generates the approximations needed for `M.mk` -/ protected def sMk (x : F (M F)) : ∀ n, CofixA F n | 0 => CofixA.continue | succ n => CofixA.intro x.1 fun i => (x.2 i).approx n set_option linter.uppercaseLean3 false in #align pfunctor.M.approx.s_mk PFunctor.M.Approx.sMk protected theorem P_mk (x : F (M F)) : AllAgree (Approx.sMk x) | 0 => by constructor | succ n => by constructor introv apply (x.2 i).consistent set_option linter.uppercaseLean3 false in #align pfunctor.M.approx.P_mk PFunctor.M.Approx.P_mk end Approx /-- constructor for M-types -/ protected def mk (x : F (M F)) : M F where approx := Approx.sMk x consistent := Approx.P_mk x set_option linter.uppercaseLean3 false in #align pfunctor.M.mk PFunctor.M.mk /-- `Agree' n` relates two trees of type `M F` that are the same up to depth `n` -/ inductive Agree' : ℕ → M F → M F → Prop | trivial (x y : M F) : Agree' 0 x y | step {n : ℕ} {a} (x y : F.B a → M F) {x' y'} : x' = M.mk ⟨a, x⟩ → y' = M.mk ⟨a, y⟩ → (∀ i, Agree' n (x i) (y i)) → Agree' (succ n) x' y' set_option linter.uppercaseLean3 false in #align pfunctor.M.agree' PFunctor.M.Agree' @[simp] theorem dest_mk (x : F (M F)) : dest (M.mk x) = x := rfl set_option linter.uppercaseLean3 false in #align pfunctor.M.dest_mk PFunctor.M.dest_mk @[simp] theorem mk_dest (x : M F) : M.mk (dest x) = x := by apply ext' intro n dsimp only [M.mk] induction' n with n · apply @Subsingleton.elim _ CofixA.instSubsingleton dsimp only [Approx.sMk, dest, head] cases' h : x.approx (succ n) with _ hd ch have h' : hd = head' (x.approx 1) := by rw [← head_succ' n, h, head'] · split injections · apply x.consistent revert ch rw [h'] intros ch h congr ext a dsimp only [children] generalize hh : cast _ a = a'' rw [cast_eq_iff_heq] at hh revert a'' rw [h] intros _ hh cases hh rfl set_option linter.uppercaseLean3 false in #align pfunctor.M.mk_dest PFunctor.M.mk_dest theorem mk_inj {x y : F (M F)} (h : M.mk x = M.mk y) : x = y := by rw [← dest_mk x, h, dest_mk] set_option linter.uppercaseLean3 false in #align pfunctor.M.mk_inj PFunctor.M.mk_inj /-- destructor for M-types -/ protected def cases {r : M F → Sort w} (f : ∀ x : F (M F), r (M.mk x)) (x : M F) : r x := suffices r (M.mk (dest x)) by rw [← mk_dest x] exact this f _ set_option linter.uppercaseLean3 false in #align pfunctor.M.cases PFunctor.M.cases /-- destructor for M-types -/ protected def casesOn {r : M F → Sort w} (x : M F) (f : ∀ x : F (M F), r (M.mk x)) : r x := M.cases f x set_option linter.uppercaseLean3 false in #align pfunctor.M.cases_on PFunctor.M.casesOn /-- destructor for M-types, similar to `casesOn` but also gives access directly to the root and subtrees on an M-type -/ protected def casesOn' {r : M F → Sort w} (x : M F) (f : ∀ a f, r (M.mk ⟨a, f⟩)) : r x := M.casesOn x (fun ⟨a, g⟩ => f a g) set_option linter.uppercaseLean3 false in #align pfunctor.M.cases_on' PFunctor.M.casesOn' theorem approx_mk (a : F.A) (f : F.B a → M F) (i : ℕ) : (M.mk ⟨a, f⟩).approx (succ i) = CofixA.intro a fun j => (f j).approx i := rfl set_option linter.uppercaseLean3 false in #align pfunctor.M.approx_mk PFunctor.M.approx_mk @[simp] theorem agree'_refl {n : ℕ} (x : M F) : Agree' n x x := by induction' n with _ n_ih generalizing x <;> induction x using PFunctor.M.casesOn' <;> constructor <;> try rfl intros apply n_ih set_option linter.uppercaseLean3 false in #align pfunctor.M.agree'_refl PFunctor.M.agree'_refl theorem agree_iff_agree' {n : ℕ} (x y : M F) : Agree (x.approx n) (y.approx <| n + 1) ↔ Agree' n x y := by constructor <;> intro h · induction' n with _ n_ih generalizing x y · constructor · induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' simp only [approx_mk] at h cases' h with _ _ _ _ _ _ hagree constructor <;> try rfl intro i apply n_ih apply hagree · induction' n with _ n_ih generalizing x y · constructor · cases' h with _ _ _ a x' y' induction' x using PFunctor.M.casesOn' with x_a x_f induction' y using PFunctor.M.casesOn' with y_a y_f simp only [approx_mk] have h_a_1 := mk_inj ‹M.mk ⟨x_a, x_f⟩ = M.mk ⟨a, x'⟩› cases h_a_1 replace h_a_2 := mk_inj ‹M.mk ⟨y_a, y_f⟩ = M.mk ⟨a, y'⟩› cases h_a_2 constructor intro i apply n_ih simp [*] set_option linter.uppercaseLean3 false in #align pfunctor.M.agree_iff_agree' PFunctor.M.agree_iff_agree' @[simp] theorem cases_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) : PFunctor.M.cases f (M.mk x) = f x := by dsimp only [M.mk, PFunctor.M.cases, dest, head, Approx.sMk, head'] cases x; dsimp only [Approx.sMk] simp only [Eq.mpr] apply congrFun rfl set_option linter.uppercaseLean3 false in #align pfunctor.M.cases_mk PFunctor.M.cases_mk @[simp] theorem casesOn_mk {r : M F → Sort*} (x : F (M F)) (f : ∀ x : F (M F), r (M.mk x)) : PFunctor.M.casesOn (M.mk x) f = f x := cases_mk x f set_option linter.uppercaseLean3 false in #align pfunctor.M.cases_on_mk PFunctor.M.casesOn_mk @[simp] theorem casesOn_mk' {r : M F → Sort*} {a} (x : F.B a → M F) (f : ∀ (a) (f : F.B a → M F), r (M.mk ⟨a, f⟩)) : PFunctor.M.casesOn' (M.mk ⟨a, x⟩) f = f a x := @cases_mk F r ⟨a, x⟩ (fun ⟨a, g⟩ => f a g) set_option linter.uppercaseLean3 false in #align pfunctor.M.cases_on_mk' PFunctor.M.casesOn_mk' /-- `IsPath p x` tells us if `p` is a valid path through `x` -/ inductive IsPath : Path F → M F → Prop | nil (x : M F) : IsPath [] x | cons (xs : Path F) {a} (x : M F) (f : F.B a → M F) (i : F.B a) : x = M.mk ⟨a, f⟩ → IsPath xs (f i) → IsPath (⟨a, i⟩ :: xs) x set_option linter.uppercaseLean3 false in #align pfunctor.M.is_path PFunctor.M.IsPath theorem isPath_cons {xs : Path F} {a a'} {f : F.B a → M F} {i : F.B a'} : IsPath (⟨a', i⟩ :: xs) (M.mk ⟨a, f⟩) → a = a' := by generalize h : M.mk ⟨a, f⟩ = x rintro (_ | ⟨_, _, _, _, rfl, _⟩) cases mk_inj h rfl set_option linter.uppercaseLean3 false in #align pfunctor.M.is_path_cons PFunctor.M.isPath_cons
Mathlib/Data/PFunctor/Univariate/M.lean
478
483
theorem isPath_cons' {xs : Path F} {a} {f : F.B a → M F} {i : F.B a} : IsPath (⟨a, i⟩ :: xs) (M.mk ⟨a, f⟩) → IsPath xs (f i) := by
generalize h : M.mk ⟨a, f⟩ = x rintro (_ | ⟨_, _, _, _, rfl, hp⟩) cases mk_inj h exact hp
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.NumberTheory.BernoulliPolynomials import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Analysis.Calculus.Deriv.Polynomial import Mathlib.Analysis.Fourier.AddCircle import Mathlib.Analysis.PSeries #align_import number_theory.zeta_values from "leanprover-community/mathlib"@"f0c8bf9245297a541f468be517f1bde6195105e9" /-! # Critical values of the Riemann zeta function In this file we prove formulae for the critical values of `ζ(s)`, and more generally of Hurwitz zeta functions, in terms of Bernoulli polynomials. ## Main results: * `hasSum_zeta_nat`: the final formula for zeta values, $$\zeta(2k) = \frac{(-1)^{(k + 1)} 2 ^ {2k - 1} \pi^{2k} B_{2 k}}{(2 k)!}.$$ * `hasSum_zeta_two` and `hasSum_zeta_four`: special cases given explicitly. * `hasSum_one_div_nat_pow_mul_cos`: a formula for the sum `∑ (n : ℕ), cos (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 2` even. * `hasSum_one_div_nat_pow_mul_sin`: a formula for the sum `∑ (n : ℕ), sin (2 π i n x) / n ^ k` as an explicit multiple of `Bₖ(x)`, for any `x ∈ [0, 1]` and `k ≥ 3` odd. -/ noncomputable section open scoped Nat Real Interval open Complex MeasureTheory Set intervalIntegral local notation "𝕌" => UnitAddCircle section BernoulliFunProps /-! Simple properties of the Bernoulli polynomial, as a function `ℝ → ℝ`. -/ /-- The function `x ↦ Bₖ(x) : ℝ → ℝ`. -/ def bernoulliFun (k : ℕ) (x : ℝ) : ℝ := (Polynomial.map (algebraMap ℚ ℝ) (Polynomial.bernoulli k)).eval x #align bernoulli_fun bernoulliFun theorem bernoulliFun_eval_zero (k : ℕ) : bernoulliFun k 0 = bernoulli k := by rw [bernoulliFun, Polynomial.eval_zero_map, Polynomial.bernoulli_eval_zero, eq_ratCast] #align bernoulli_fun_eval_zero bernoulliFun_eval_zero theorem bernoulliFun_endpoints_eq_of_ne_one {k : ℕ} (hk : k ≠ 1) : bernoulliFun k 1 = bernoulliFun k 0 := by rw [bernoulliFun_eval_zero, bernoulliFun, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one, bernoulli_eq_bernoulli'_of_ne_one hk, eq_ratCast] #align bernoulli_fun_endpoints_eq_of_ne_one bernoulliFun_endpoints_eq_of_ne_one theorem bernoulliFun_eval_one (k : ℕ) : bernoulliFun k 1 = bernoulliFun k 0 + ite (k = 1) 1 0 := by rw [bernoulliFun, bernoulliFun_eval_zero, Polynomial.eval_one_map, Polynomial.bernoulli_eval_one] split_ifs with h · rw [h, bernoulli_one, bernoulli'_one, eq_ratCast] push_cast; ring · rw [bernoulli_eq_bernoulli'_of_ne_one h, add_zero, eq_ratCast] #align bernoulli_fun_eval_one bernoulliFun_eval_one theorem hasDerivAt_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (bernoulliFun k) (k * bernoulliFun (k - 1) x) x := by convert ((Polynomial.bernoulli k).map <| algebraMap ℚ ℝ).hasDerivAt x using 1 simp only [bernoulliFun, Polynomial.derivative_map, Polynomial.derivative_bernoulli k, Polynomial.map_mul, Polynomial.map_natCast, Polynomial.eval_mul, Polynomial.eval_natCast] #align has_deriv_at_bernoulli_fun hasDerivAt_bernoulliFun theorem antideriv_bernoulliFun (k : ℕ) (x : ℝ) : HasDerivAt (fun x => bernoulliFun (k + 1) x / (k + 1)) (bernoulliFun k x) x := by convert (hasDerivAt_bernoulliFun (k + 1) x).div_const _ using 1 field_simp [Nat.cast_add_one_ne_zero k] #align antideriv_bernoulli_fun antideriv_bernoulliFun theorem integral_bernoulliFun_eq_zero {k : ℕ} (hk : k ≠ 0) : ∫ x : ℝ in (0)..1, bernoulliFun k x = 0 := by rw [integral_eq_sub_of_hasDerivAt (fun x _ => antideriv_bernoulliFun k x) ((Polynomial.continuous _).intervalIntegrable _ _)] rw [bernoulliFun_eval_one] split_ifs with h · exfalso; exact hk (Nat.succ_inj'.mp h) · simp #align integral_bernoulli_fun_eq_zero integral_bernoulliFun_eq_zero end BernoulliFunProps section BernoulliFourierCoeffs /-! Compute the Fourier coefficients of the Bernoulli functions via integration by parts. -/ /-- The `n`-th Fourier coefficient of the `k`-th Bernoulli function on the interval `[0, 1]`. -/ def bernoulliFourierCoeff (k : ℕ) (n : ℤ) : ℂ := fourierCoeffOn zero_lt_one (fun x => bernoulliFun k x) n #align bernoulli_fourier_coeff bernoulliFourierCoeff /-- Recurrence relation (in `k`) for the `n`-th Fourier coefficient of `Bₖ`. -/ theorem bernoulliFourierCoeff_recurrence (k : ℕ) {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff k n = 1 / (-2 * π * I * n) * (ite (k = 1) 1 0 - k * bernoulliFourierCoeff (k - 1) n) := by unfold bernoulliFourierCoeff rw [fourierCoeffOn_of_hasDerivAt zero_lt_one hn (fun x _ => (hasDerivAt_bernoulliFun k x).ofReal_comp) ((continuous_ofReal.comp <| continuous_const.mul <| Polynomial.continuous _).intervalIntegrable _ _)] simp_rw [ofReal_one, ofReal_zero, sub_zero, one_mul] rw [QuotientAddGroup.mk_zero, fourier_eval_zero, one_mul, ← ofReal_sub, bernoulliFun_eval_one, add_sub_cancel_left] congr 2 · split_ifs <;> simp only [ofReal_one, ofReal_zero, one_mul] · simp_rw [ofReal_mul, ofReal_natCast, fourierCoeffOn.const_mul] #align bernoulli_fourier_coeff_recurrence bernoulliFourierCoeff_recurrence /-- The Fourier coefficients of `B₀(x) = 1`. -/ theorem bernoulli_zero_fourier_coeff {n : ℤ} (hn : n ≠ 0) : bernoulliFourierCoeff 0 n = 0 := by simpa using bernoulliFourierCoeff_recurrence 0 hn #align bernoulli_zero_fourier_coeff bernoulli_zero_fourier_coeff /-- The `0`-th Fourier coefficient of `Bₖ(x)`. -/ theorem bernoulliFourierCoeff_zero {k : ℕ} (hk : k ≠ 0) : bernoulliFourierCoeff k 0 = 0 := by simp_rw [bernoulliFourierCoeff, fourierCoeffOn_eq_integral, neg_zero, fourier_zero, sub_zero, div_one, one_smul, intervalIntegral.integral_ofReal, integral_bernoulliFun_eq_zero hk, ofReal_zero] #align bernoulli_fourier_coeff_zero bernoulliFourierCoeff_zero theorem bernoulliFourierCoeff_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : bernoulliFourierCoeff k n = -k ! / (2 * π * I * n) ^ k := by rcases eq_or_ne n 0 with (rfl | hn) · rw [bernoulliFourierCoeff_zero hk, Int.cast_zero, mul_zero, zero_pow hk, div_zero] refine Nat.le_induction ?_ (fun k hk h'k => ?_) k (Nat.one_le_iff_ne_zero.mpr hk) · rw [bernoulliFourierCoeff_recurrence 1 hn] simp only [Nat.cast_one, tsub_self, neg_mul, one_mul, eq_self_iff_true, if_true, Nat.factorial_one, pow_one, inv_I, mul_neg] rw [bernoulli_zero_fourier_coeff hn, sub_zero, mul_one, div_neg, neg_div] · rw [bernoulliFourierCoeff_recurrence (k + 1) hn, Nat.add_sub_cancel k 1] split_ifs with h · exfalso; exact (ne_of_gt (Nat.lt_succ_iff.mpr hk)) h · rw [h'k, Nat.factorial_succ, zero_sub, Nat.cast_mul, pow_add, pow_one, neg_div, mul_neg, mul_neg, mul_neg, neg_neg, neg_mul, neg_mul, neg_mul, div_neg] field_simp [Int.cast_ne_zero.mpr hn, I_ne_zero] ring_nf #align bernoulli_fourier_coeff_eq bernoulliFourierCoeff_eq end BernoulliFourierCoeffs section BernoulliPeriodized /-! In this section we use the above evaluations of the Fourier coefficients of Bernoulli polynomials, together with the theorem `has_pointwise_sum_fourier_series_of_summable` from Fourier theory, to obtain an explicit formula for `∑ (n:ℤ), 1 / n ^ k * fourier n x`. -/ /-- The Bernoulli polynomial, extended from `[0, 1)` to the unit circle. -/ def periodizedBernoulli (k : ℕ) : 𝕌 → ℝ := AddCircle.liftIco 1 0 (bernoulliFun k) #align periodized_bernoulli periodizedBernoulli theorem periodizedBernoulli.continuous {k : ℕ} (hk : k ≠ 1) : Continuous (periodizedBernoulli k) := AddCircle.liftIco_zero_continuous (mod_cast (bernoulliFun_endpoints_eq_of_ne_one hk).symm) (Polynomial.continuous _).continuousOn #align periodized_bernoulli.continuous periodizedBernoulli.continuous
Mathlib/NumberTheory/ZetaValues.lean
171
176
theorem fourierCoeff_bernoulli_eq {k : ℕ} (hk : k ≠ 0) (n : ℤ) : fourierCoeff ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) n = -k ! / (2 * π * I * n) ^ k := by
have : ((↑) ∘ periodizedBernoulli k : 𝕌 → ℂ) = AddCircle.liftIco 1 0 ((↑) ∘ bernoulliFun k) := by ext1 x; rfl rw [this, fourierCoeff_liftIco_eq] simpa only [zero_add] using bernoulliFourierCoeff_eq hk n
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Abelian import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Algebra.Lie.Quotient #align_import algebra.lie.normalizer from "leanprover-community/mathlib"@"938fead7abdc0cbbca8eba7a1052865a169dc102" /-! # The normalizer of Lie submodules and subalgebras. Given a Lie module `M` over a Lie subalgebra `L`, the normalizer of a Lie submodule `N ⊆ M` is the Lie submodule with underlying set `{ m | ∀ (x : L), ⁅x, m⁆ ∈ N }`. The lattice of Lie submodules thus has two natural operations, the normalizer: `N ↦ N.normalizer` and the ideal operation: `N ↦ ⁅⊤, N⁆`; these are adjoint, i.e., they form a Galois connection. This adjointness is the reason that we may define nilpotency in terms of either the upper or lower central series. Given a Lie subalgebra `H ⊆ L`, we may regard `H` as a Lie submodule of `L` over `H`, and thus consider the normalizer. This turns out to be a Lie subalgebra. ## Main definitions * `LieSubmodule.normalizer` * `LieSubalgebra.normalizer` * `LieSubmodule.gc_top_lie_normalizer` ## Tags lie algebra, normalizer -/ variable {R L M M' : Type*} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup M'] [Module R M'] [LieRingModule L M'] [LieModule R L M'] namespace LieSubmodule variable (N : LieSubmodule R L M) {N₁ N₂ : LieSubmodule R L M} /-- The normalizer of a Lie submodule. See also `LieSubmodule.idealizer`. -/ def normalizer : LieSubmodule R L M where carrier := {m | ∀ x : L, ⁅x, m⁆ ∈ N} add_mem' hm₁ hm₂ x := by rw [lie_add]; exact N.add_mem' (hm₁ x) (hm₂ x) zero_mem' x := by simp smul_mem' t m hm x := by rw [lie_smul]; exact N.smul_mem' t (hm x) lie_mem {x m} hm y := by rw [leibniz_lie]; exact N.add_mem' (hm ⁅y, x⁆) (N.lie_mem (hm y)) #align lie_submodule.normalizer LieSubmodule.normalizer @[simp] theorem mem_normalizer (m : M) : m ∈ N.normalizer ↔ ∀ x : L, ⁅x, m⁆ ∈ N := Iff.rfl #align lie_submodule.mem_normalizer LieSubmodule.mem_normalizer @[simp] theorem le_normalizer : N ≤ N.normalizer := by intro m hm rw [mem_normalizer] exact fun x => N.lie_mem hm #align lie_submodule.le_normalizer LieSubmodule.le_normalizer theorem normalizer_inf : (N₁ ⊓ N₂).normalizer = N₁.normalizer ⊓ N₂.normalizer := by ext; simp [← forall_and] #align lie_submodule.normalizer_inf LieSubmodule.normalizer_inf @[mono] theorem monotone_normalizer : Monotone (normalizer : LieSubmodule R L M → LieSubmodule R L M) := by intro N₁ N₂ h m hm rw [mem_normalizer] at hm ⊢ exact fun x => h (hm x) #align lie_submodule.monotone_normalizer LieSubmodule.monotone_normalizer @[simp] theorem comap_normalizer (f : M' →ₗ⁅R,L⁆ M) : N.normalizer.comap f = (N.comap f).normalizer := by ext; simp #align lie_submodule.comap_normalizer LieSubmodule.comap_normalizer
Mathlib/Algebra/Lie/Normalizer.lean
86
87
theorem top_lie_le_iff_le_normalizer (N' : LieSubmodule R L M) : ⁅(⊤ : LieIdeal R L), N⁆ ≤ N' ↔ N ≤ N'.normalizer := by
rw [lie_le_iff]; tauto
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Paul Lezeau -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.IsAdjoinRoot #align_import number_theory.kummer_dedekind from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Kummer-Dedekind theorem This file proves the monogenic version of the Kummer-Dedekind theorem on the splitting of prime ideals in an extension of the ring of integers. This states that if `I` is a prime ideal of Dedekind domain `R` and `S = R[α]` for some `α` that is integral over `R` with minimal polynomial `f`, then the prime factorisations of `I * S` and `f mod I` have the same shape, i.e. they have the same number of prime factors, and each prime factors of `I * S` can be paired with a prime factor of `f mod I` in a way that ensures multiplicities match (in fact, this pairing can be made explicit with a formula). ## Main definitions * `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` : The bijection in the Kummer-Dedekind theorem. This is the pairing between the prime factors of `I * S` and the prime factors of `f mod I`. ## Main results * `normalized_factors_ideal_map_eq_normalized_factors_min_poly_mk_map` : The Kummer-Dedekind theorem. * `Ideal.irreducible_map_of_irreducible_minpoly` : `I.map (algebraMap R S)` is irreducible if `(map (Ideal.Quotient.mk I) (minpoly R pb.gen))` is irreducible, where `pb` is a power basis of `S` over `R`. ## TODO * Prove the Kummer-Dedekind theorem in full generality. * Prove the converse of `Ideal.irreducible_map_of_irreducible_minpoly`. * Prove that `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk` can be expressed as `normalizedFactorsMapEquivNormalizedFactorsMinPolyMk g = ⟨I, G(α)⟩` for `g` a prime factor of `f mod I` and `G` a lift of `g` to `R[X]`. ## References * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags kummer, dedekind, kummer dedekind, dedekind-kummer, dedekind kummer -/ variable (R : Type*) {S : Type*} [CommRing R] [CommRing S] [Algebra R S] open Ideal Polynomial DoubleQuot UniqueFactorizationMonoid Algebra RingHom local notation:max R "<" x:max ">" => adjoin R ({x} : Set S) /-- Let `S / R` be a ring extension and `x : S`, then the conductor of `R<x>` is the biggest ideal of `S` contained in `R<x>`. -/ def conductor (x : S) : Ideal S where carrier := {a | ∀ b : S, a * b ∈ R<x>} zero_mem' b := by simpa only [zero_mul] using Subalgebra.zero_mem _ add_mem' ha hb c := by simpa only [add_mul] using Subalgebra.add_mem _ (ha c) (hb c) smul_mem' c a ha b := by simpa only [smul_eq_mul, mul_left_comm, mul_assoc] using ha (c * b) #align conductor conductor variable {R} {x : S} theorem conductor_eq_of_eq {y : S} (h : (R<x> : Set S) = R<y>) : conductor R x = conductor R y := Ideal.ext fun _ => forall_congr' fun _ => Set.ext_iff.mp h _ #align conductor_eq_of_eq conductor_eq_of_eq theorem conductor_subset_adjoin : (conductor R x : Set S) ⊆ R<x> := fun y hy => by simpa only [mul_one] using hy 1 #align conductor_subset_adjoin conductor_subset_adjoin theorem mem_conductor_iff {y : S} : y ∈ conductor R x ↔ ∀ b : S, y * b ∈ R<x> := ⟨fun h => h, fun h => h⟩ #align mem_conductor_iff mem_conductor_iff theorem conductor_eq_top_of_adjoin_eq_top (h : R<x> = ⊤) : conductor R x = ⊤ := by simp only [Ideal.eq_top_iff_one, mem_conductor_iff, h, mem_top, forall_const] #align conductor_eq_top_of_adjoin_eq_top conductor_eq_top_of_adjoin_eq_top theorem conductor_eq_top_of_powerBasis (pb : PowerBasis R S) : conductor R pb.gen = ⊤ := conductor_eq_top_of_adjoin_eq_top pb.adjoin_gen_eq_top #align conductor_eq_top_of_power_basis conductor_eq_top_of_powerBasis open IsLocalization in lemma mem_coeSubmodule_conductor {L} [CommRing L] [Algebra S L] [Algebra R L] [IsScalarTower R S L] [NoZeroSMulDivisors S L] {x : S} {y : L} : y ∈ coeSubmodule L (conductor R x) ↔ ∀ z : S, y * (algebraMap S L) z ∈ Algebra.adjoin R {algebraMap S L x} := by cases subsingleton_or_nontrivial L · rw [Subsingleton.elim (coeSubmodule L _) ⊤, Subsingleton.elim (Algebra.adjoin R _) ⊤]; simp trans ∀ z, y * (algebraMap S L) z ∈ (Algebra.adjoin R {x}).map (IsScalarTower.toAlgHom R S L) · simp only [coeSubmodule, Submodule.mem_map, Algebra.linearMap_apply, Subalgebra.mem_map, IsScalarTower.coe_toAlgHom'] constructor · rintro ⟨y, hy, rfl⟩ z exact ⟨_, hy z, map_mul _ _ _⟩ · intro H obtain ⟨y, _, e⟩ := H 1 rw [_root_.map_one, mul_one] at e subst e simp only [← _root_.map_mul, (NoZeroSMulDivisors.algebraMap_injective S L).eq_iff, exists_eq_right] at H exact ⟨_, H, rfl⟩ · rw [AlgHom.map_adjoin, Set.image_singleton]; rfl variable {I : Ideal R} /-- This technical lemma tell us that if `C` is the conductor of `R<x>` and `I` is an ideal of `R` then `p * (I * S) ⊆ I * R<x>` for any `p` in `C ∩ R` -/ theorem prod_mem_ideal_map_of_mem_conductor {p : R} {z : S} (hp : p ∈ Ideal.comap (algebraMap R S) (conductor R x)) (hz' : z ∈ I.map (algebraMap R S)) : algebraMap R S p * z ∈ algebraMap R<x> S '' ↑(I.map (algebraMap R R<x>)) := by rw [Ideal.map, Ideal.span, Finsupp.mem_span_image_iff_total] at hz' obtain ⟨l, H, H'⟩ := hz' rw [Finsupp.total_apply] at H' rw [← H', mul_comm, Finsupp.sum_mul] have lem : ∀ {a : R}, a ∈ I → l a • algebraMap R S a * algebraMap R S p ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) := by intro a ha rw [Algebra.id.smul_eq_mul, mul_assoc, mul_comm, mul_assoc, Set.mem_image] refine Exists.intro (algebraMap R R<x> a * ⟨l a * algebraMap R S p, show l a * algebraMap R S p ∈ R<x> from ?h⟩) ?_ case h => rw [mul_comm] exact mem_conductor_iff.mp (Ideal.mem_comap.mp hp) _ · refine ⟨?_, ?_⟩ · rw [mul_comm] apply Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ ha) · simp only [RingHom.map_mul, mul_comm (algebraMap R S p) (l a)] rfl refine Finset.sum_induction _ (fun u => u ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>)) (fun a b => ?_) ?_ ?_ · rintro ⟨z, hz, rfl⟩ ⟨y, hy, rfl⟩ rw [← RingHom.map_add] exact ⟨z + y, Ideal.add_mem _ (SetLike.mem_coe.mp hz) hy, rfl⟩ · exact ⟨0, SetLike.mem_coe.mpr <| Ideal.zero_mem _, RingHom.map_zero _⟩ · intro y hy exact lem ((Finsupp.mem_supported _ l).mp H hy) #align prod_mem_ideal_map_of_mem_conductor prod_mem_ideal_map_of_mem_conductor /-- A technical result telling us that `(I * S) ∩ R<x> = I * R<x>` for any ideal `I` of `R`. -/ theorem comap_map_eq_map_adjoin_of_coprime_conductor (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : (I.map (algebraMap R S)).comap (algebraMap R<x> S) = I.map (algebraMap R R<x>) := by apply le_antisymm · -- This is adapted from [Neukirch1992]. Let `C = (conductor R x)`. The idea of the proof -- is that since `I` and `C ∩ R` are coprime, we have -- `(I * S) ∩ R<x> ⊆ (I + C) * ((I * S) ∩ R<x>) ⊆ I * R<x> + I * C * S ⊆ I * R<x>`. intro y hy obtain ⟨z, hz⟩ := y obtain ⟨p, hp, q, hq, hpq⟩ := Submodule.mem_sup.mp ((Ideal.eq_top_iff_one _).mp hx) have temp : algebraMap R S p * z + algebraMap R S q * z = z := by simp only [← add_mul, ← RingHom.map_add (algebraMap R S), hpq, map_one, one_mul] suffices z ∈ algebraMap R<x> S '' I.map (algebraMap R R<x>) ↔ (⟨z, hz⟩ : R<x>) ∈ I.map (algebraMap R R<x>) by rw [← this, ← temp] obtain ⟨a, ha⟩ := (Set.mem_image _ _ _).mp (prod_mem_ideal_map_of_mem_conductor hp (show z ∈ I.map (algebraMap R S) by rwa [Ideal.mem_comap] at hy)) use a + algebraMap R R<x> q * ⟨z, hz⟩ refine ⟨Ideal.add_mem (I.map (algebraMap R R<x>)) ha.left ?_, by simp only [ha.right, map_add, AlgHom.map_mul, add_right_inj]; rfl⟩ rw [mul_comm] exact Ideal.mul_mem_left (I.map (algebraMap R R<x>)) _ (Ideal.mem_map_of_mem _ hq) refine ⟨fun h => ?_, fun h => (Set.mem_image _ _ _).mpr (Exists.intro ⟨z, hz⟩ ⟨by simp [h], rfl⟩)⟩ obtain ⟨x₁, hx₁, hx₂⟩ := (Set.mem_image _ _ _).mp h have : x₁ = ⟨z, hz⟩ := by apply h_alg simp [hx₂] rfl rwa [← this] · -- The converse inclusion is trivial have : algebraMap R S = (algebraMap _ S).comp (algebraMap R R<x>) := by ext; rfl rw [this, ← Ideal.map_map] apply Ideal.le_comap_map #align comap_map_eq_map_adjoin_of_coprime_conductor comap_map_eq_map_adjoin_of_coprime_conductor /-- The canonical morphism of rings from `R<x> ⧸ (I*R<x>)` to `S ⧸ (I*S)` is an isomorphism when `I` and `(conductor R x) ∩ R` are coprime. -/ noncomputable def quotAdjoinEquivQuotMap (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) : R<x> ⧸ I.map (algebraMap R R<x>) ≃+* S ⧸ I.map (algebraMap R S) := by let f : R<x> ⧸ I.map (algebraMap R R<x>) →+* S ⧸ I.map (algebraMap R S) := (Ideal.Quotient.lift (I.map (algebraMap R R<x>)) ((Ideal.Quotient.mk (I.map (algebraMap R S))).comp (algebraMap R<x> S)) (fun r hr => by have : algebraMap R S = (algebraMap R<x> S).comp (algebraMap R R<x>) := by ext; rfl rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, this, ← Ideal.map_map] exact Ideal.mem_map_of_mem _ hr)) refine RingEquiv.ofBijective f ⟨?_, ?_⟩ · --the kernel of the map is clearly `(I * S) ∩ R<x>`. To get injectivity, we need to show that --this is contained in `I * R<x>`, which is the content of the previous lemma. refine RingHom.lift_injective_of_ker_le_ideal _ _ fun u hu => ?_ rwa [RingHom.mem_ker, RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem, ← Ideal.mem_comap, comap_map_eq_map_adjoin_of_coprime_conductor hx h_alg] at hu · -- Surjectivity follows from the surjectivity of the canonical map `R<x> → S ⧸ (I * S)`, -- which in turn follows from the fact that `I * S + (conductor R x) = S`. refine Ideal.Quotient.lift_surjective_of_surjective _ _ fun y => ?_ obtain ⟨z, hz⟩ := Ideal.Quotient.mk_surjective y have : z ∈ conductor R x ⊔ I.map (algebraMap R S) := by suffices conductor R x ⊔ I.map (algebraMap R S) = ⊤ by simp only [this, Submodule.mem_top] rw [Ideal.eq_top_iff_one] at hx ⊢ replace hx := Ideal.mem_map_of_mem (algebraMap R S) hx rw [Ideal.map_sup, RingHom.map_one] at hx exact (sup_le_sup (show ((conductor R x).comap (algebraMap R S)).map (algebraMap R S) ≤ conductor R x from Ideal.map_comap_le) (le_refl (I.map (algebraMap R S)))) hx rw [← Ideal.mem_quotient_iff_mem_sup, hz, Ideal.mem_map_iff_of_surjective] at this · obtain ⟨u, hu, hu'⟩ := this use ⟨u, conductor_subset_adjoin hu⟩ simp only [← hu'] rfl · exact Ideal.Quotient.mk_surjective #align quot_adjoin_equiv_quot_map quotAdjoinEquivQuotMap -- Porting note: on-line linter fails with `failed to synthesize` instance -- but #lint does not report any problem @[simp, nolint simpNF] theorem quotAdjoinEquivQuotMap_apply_mk (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (h_alg : Function.Injective (algebraMap R<x> S)) (a : R<x>) : quotAdjoinEquivQuotMap hx h_alg (Ideal.Quotient.mk (I.map (algebraMap R R<x>)) a) = Ideal.Quotient.mk (I.map (algebraMap R S)) ↑a := rfl #align quot_adjoin_equiv_quot_map_apply_mk quotAdjoinEquivQuotMap_apply_mk namespace KummerDedekind open scoped Polynomial Classical variable [IsDomain R] [IsIntegrallyClosed R] variable [IsDedekindDomain S] variable [NoZeroSMulDivisors R S] attribute [local instance] Ideal.Quotient.field /-- The first half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the prime factors of `I*S` are in bijection with those of the minimal polynomial of the generator of `S` over `R`, taken `mod I`. -/ noncomputable def normalizedFactorsMapEquivNormalizedFactorsMinPolyMk (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) : {J : Ideal S | J ∈ normalizedFactors (I.map (algebraMap R S))} ≃ {d : (R ⧸ I)[X] | d ∈ normalizedFactors (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x))} := by -- Porting note: Lean needs to be reminded about this so it does not time out have : IsPrincipalIdealRing (R ⧸ I)[X] := inferInstance let f : S ⧸ map (algebraMap R S) I ≃+* (R ⧸ I)[X] ⧸ span {Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)} := by refine (quotAdjoinEquivQuotMap hx ?_).symm.trans (((Algebra.adjoin.powerBasis' hx').quotientEquivQuotientMinpolyMap I).toRingEquiv.trans (quotEquivOfEq ?_)) · exact NoZeroSMulDivisors.algebraMap_injective (Algebra.adjoin R {x}) S · rw [Algebra.adjoin.powerBasis'_minpoly_gen hx'] refine (normalizedFactorsEquivOfQuotEquiv f ?_ ?_).trans ?_ · rwa [Ne, map_eq_bot_iff_of_injective (NoZeroSMulDivisors.algebraMap_injective R S), ← Ne] · by_contra h exact (show Polynomial.map (Ideal.Quotient.mk I) (minpoly R x) ≠ 0 from Polynomial.map_monic_ne_zero (minpoly.monic hx')) (span_singleton_eq_bot.mp h) · refine (normalizedFactorsEquivSpanNormalizedFactors ?_).symm exact Polynomial.map_monic_ne_zero (minpoly.monic hx') #align kummer_dedekind.normalized_factors_map_equiv_normalized_factors_min_poly_mk KummerDedekind.normalizedFactorsMapEquivNormalizedFactorsMinPolyMk /-- The second half of the **Kummer-Dedekind Theorem** in the monogenic case, stating that the bijection `FactorsEquiv'` defined in the first half preserves multiplicities. -/
Mathlib/NumberTheory/KummerDedekind.lean
274
282
theorem multiplicity_factors_map_eq_multiplicity (hI : IsMaximal I) (hI' : I ≠ ⊥) (hx : (conductor R x).comap (algebraMap R S) ⊔ I = ⊤) (hx' : IsIntegral R x) {J : Ideal S} (hJ : J ∈ normalizedFactors (I.map (algebraMap R S))) : multiplicity J (I.map (algebraMap R S)) = multiplicity (↑(normalizedFactorsMapEquivNormalizedFactorsMinPolyMk hI hI' hx hx' ⟨J, hJ⟩)) (Polynomial.map (Ideal.Quotient.mk I) (minpoly R x)) := by
rw [normalizedFactorsMapEquivNormalizedFactorsMinPolyMk, Equiv.coe_trans, Function.comp_apply, multiplicity_normalizedFactorsEquivSpanNormalizedFactors_symm_eq_multiplicity, normalizedFactorsEquivOfQuotEquiv_multiplicity_eq_multiplicity]
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.InverseFunctionTheorem.FDeriv import Mathlib.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.NormedSpace.Complemented #align_import analysis.calculus.implicit from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Implicit function theorem We prove three versions of the implicit function theorem. First we define a structure `ImplicitFunctionData` that holds arguments for the most general version of the implicit function theorem, see `ImplicitFunctionData.implicitFunction` and `ImplicitFunctionData.implicitFunction_hasStrictFDerivAt`. This version allows a user to choose a specific implicit function but provides only a little convenience over the inverse function theorem. Then we define `HasStrictFDerivAt.implicitFunctionDataOfComplemented`: implicit function defined by `f (g z y) = z`, where `f : E → F` is a function strictly differentiable at `a` such that its derivative `f'` is surjective and has a `complemented` kernel. Finally, if the codomain of `f` is a finite dimensional space, then we can automatically prove that the kernel of `f'` is complemented, hence the only assumptions are `HasStrictFDerivAt` and `f'.range = ⊤`. This version is named `HasStrictFDerivAt.implicitFunction`. ## TODO * Add a version for a function `f : E × F → G` such that $$\frac{\partial f}{\partial y}$$ is invertible. * Add a version for `f : 𝕜 × 𝕜 → 𝕜` proving `HasStrictDerivAt` and `deriv φ = ...`. * Prove that in a real vector space the implicit function has the same smoothness as the original one. * If the original function is differentiable in a neighborhood, then the implicit function is differentiable in a neighborhood as well. Current setup only proves differentiability at one point for the implicit function constructed in this file (as opposed to an unspecified implicit function). One of the ways to overcome this difficulty is to use uniqueness of the implicit function in the general version of the theorem. Another way is to prove that *any* implicit function satisfying some predicate is strictly differentiable. ## Tags implicit function, inverse function -/ noncomputable section open scoped Topology open Filter open ContinuousLinearMap (fst snd smulRight ker_prod) open ContinuousLinearEquiv (ofBijective) open LinearMap (ker range) /-! ### General version Consider two functions `f : E → F` and `g : E → G` and a point `a` such that * both functions are strictly differentiable at `a`; * the derivatives are surjective; * the kernels of the derivatives are complementary subspaces of `E`. Note that the map `x ↦ (f x, g x)` has a bijective derivative, hence it is a partial homeomorphism between `E` and `F × G`. We use this fact to define a function `φ : F → G → E` (see `ImplicitFunctionData.implicitFunction`) such that for `(y, z)` close enough to `(f a, g a)` we have `f (φ y z) = y` and `g (φ y z) = z`. We also prove a formula for $$\frac{\partial\varphi}{\partial z}.$$ Though this statement is almost symmetric with respect to `F`, `G`, we interpret it in the following way. Consider a family of surfaces `{x | f x = y}`, `y ∈ 𝓝 (f a)`. Each of these surfaces is parametrized by `φ y`. There are many ways to choose a (differentiable) function `φ` such that `f (φ y z) = y` but the extra condition `g (φ y z) = z` allows a user to select one of these functions. If we imagine that the level surfaces `f = const` form a local horizontal foliation, then the choice of `g` fixes a transverse foliation `g = const`, and `φ` is the inverse function of the projection of `{x | f x = y}` along this transverse foliation. This version of the theorem is used to prove the other versions and can be used if a user needs to have a complete control over the choice of the implicit function. -/ /-- Data for the general version of the implicit function theorem. It holds two functions `f : E → F` and `g : E → G` (named `leftFun` and `rightFun`) and a point `a` (named `pt`) such that * both functions are strictly differentiable at `a`; * the derivatives are surjective; * the kernels of the derivatives are complementary subspaces of `E`. -/ -- Porting note(#5171): linter not yet ported @[nolint has_nonempty_instance] structure ImplicitFunctionData (𝕜 : Type*) [NontriviallyNormedField 𝕜] (E : Type*) [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] (F : Type*) [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] (G : Type*) [NormedAddCommGroup G] [NormedSpace 𝕜 G] [CompleteSpace G] where leftFun : E → F leftDeriv : E →L[𝕜] F rightFun : E → G rightDeriv : E →L[𝕜] G pt : E left_has_deriv : HasStrictFDerivAt leftFun leftDeriv pt right_has_deriv : HasStrictFDerivAt rightFun rightDeriv pt left_range : range leftDeriv = ⊤ right_range : range rightDeriv = ⊤ isCompl_ker : IsCompl (ker leftDeriv) (ker rightDeriv) #align implicit_function_data ImplicitFunctionData namespace ImplicitFunctionData variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [CompleteSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] [CompleteSpace F] {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] [CompleteSpace G] (φ : ImplicitFunctionData 𝕜 E F G) /-- The function given by `x ↦ (leftFun x, rightFun x)`. -/ def prodFun (x : E) : F × G := (φ.leftFun x, φ.rightFun x) #align implicit_function_data.prod_fun ImplicitFunctionData.prodFun @[simp] theorem prodFun_apply (x : E) : φ.prodFun x = (φ.leftFun x, φ.rightFun x) := rfl #align implicit_function_data.prod_fun_apply ImplicitFunctionData.prodFun_apply protected theorem hasStrictFDerivAt : HasStrictFDerivAt φ.prodFun (φ.leftDeriv.equivProdOfSurjectiveOfIsCompl φ.rightDeriv φ.left_range φ.right_range φ.isCompl_ker : E →L[𝕜] F × G) φ.pt := φ.left_has_deriv.prod φ.right_has_deriv #align implicit_function_data.has_strict_fderiv_at ImplicitFunctionData.hasStrictFDerivAt /-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are complementary subspaces of `E`, then `x ↦ (f x, g x)` defines a partial homeomorphism between `E` and `F × G`. In particular, `{x | f x = f a}` is locally homeomorphic to `G`. -/ def toPartialHomeomorph : PartialHomeomorph E (F × G) := φ.hasStrictFDerivAt.toPartialHomeomorph _ #align implicit_function_data.to_local_homeomorph ImplicitFunctionData.toPartialHomeomorph /-- Implicit function theorem. If `f : E → F` and `g : E → G` are two maps strictly differentiable at `a`, their derivatives `f'`, `g'` are surjective, and the kernels of these derivatives are complementary subspaces of `E`, then `implicitFunction` is the unique (germ of a) map `φ : F → G → E` such that `f (φ y z) = y` and `g (φ y z) = z`. -/ def implicitFunction : F → G → E := Function.curry <| φ.toPartialHomeomorph.symm #align implicit_function_data.implicit_function ImplicitFunctionData.implicitFunction @[simp] theorem toPartialHomeomorph_coe : ⇑φ.toPartialHomeomorph = φ.prodFun := rfl #align implicit_function_data.to_local_homeomorph_coe ImplicitFunctionData.toPartialHomeomorph_coe theorem toPartialHomeomorph_apply (x : E) : φ.toPartialHomeomorph x = (φ.leftFun x, φ.rightFun x) := rfl #align implicit_function_data.to_local_homeomorph_apply ImplicitFunctionData.toPartialHomeomorph_apply theorem pt_mem_toPartialHomeomorph_source : φ.pt ∈ φ.toPartialHomeomorph.source := φ.hasStrictFDerivAt.mem_toPartialHomeomorph_source #align implicit_function_data.pt_mem_to_local_homeomorph_source ImplicitFunctionData.pt_mem_toPartialHomeomorph_source theorem map_pt_mem_toPartialHomeomorph_target : (φ.leftFun φ.pt, φ.rightFun φ.pt) ∈ φ.toPartialHomeomorph.target := φ.toPartialHomeomorph.map_source <| φ.pt_mem_toPartialHomeomorph_source #align implicit_function_data.map_pt_mem_to_local_homeomorph_target ImplicitFunctionData.map_pt_mem_toPartialHomeomorph_target theorem prod_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.prodFun (φ.implicitFunction p.1 p.2) = p := φ.hasStrictFDerivAt.eventually_right_inverse.mono fun ⟨_, _⟩ h => h #align implicit_function_data.prod_map_implicit_function ImplicitFunctionData.prod_map_implicitFunction theorem left_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.leftFun (φ.implicitFunction p.1 p.2) = p.1 := φ.prod_map_implicitFunction.mono fun _ => congr_arg Prod.fst #align implicit_function_data.left_map_implicit_function ImplicitFunctionData.left_map_implicitFunction theorem right_map_implicitFunction : ∀ᶠ p : F × G in 𝓝 (φ.prodFun φ.pt), φ.rightFun (φ.implicitFunction p.1 p.2) = p.2 := φ.prod_map_implicitFunction.mono fun _ => congr_arg Prod.snd #align implicit_function_data.right_map_implicit_function ImplicitFunctionData.right_map_implicitFunction theorem implicitFunction_apply_image : ∀ᶠ x in 𝓝 φ.pt, φ.implicitFunction (φ.leftFun x) (φ.rightFun x) = x := φ.hasStrictFDerivAt.eventually_left_inverse #align implicit_function_data.implicit_function_apply_image ImplicitFunctionData.implicitFunction_apply_image theorem map_nhds_eq : map φ.leftFun (𝓝 φ.pt) = 𝓝 (φ.leftFun φ.pt) := show map (Prod.fst ∘ φ.prodFun) (𝓝 φ.pt) = 𝓝 (φ.prodFun φ.pt).1 by rw [← map_map, φ.hasStrictFDerivAt.map_nhds_eq_of_equiv, map_fst_nhds] #align implicit_function_data.map_nhds_eq ImplicitFunctionData.map_nhds_eq
Mathlib/Analysis/Calculus/Implicit.lean
201
214
theorem implicitFunction_hasStrictFDerivAt (g'inv : G →L[𝕜] E) (hg'inv : φ.rightDeriv.comp g'inv = ContinuousLinearMap.id 𝕜 G) (hg'invf : φ.leftDeriv.comp g'inv = 0) : HasStrictFDerivAt (φ.implicitFunction (φ.leftFun φ.pt)) g'inv (φ.rightFun φ.pt) := by
have := φ.hasStrictFDerivAt.to_localInverse simp only [prodFun] at this convert this.comp (φ.rightFun φ.pt) ((hasStrictFDerivAt_const _ _).prod (hasStrictFDerivAt_id _)) -- Porting note: added parentheses to help `simp` simp only [ContinuousLinearMap.ext_iff, (ContinuousLinearMap.comp_apply)] at hg'inv hg'invf ⊢ -- porting note (#10745): was `simp [ContinuousLinearEquiv.eq_symm_apply]`; -- both `simp` and `rw` fail here, `erw` works intro x erw [ContinuousLinearEquiv.eq_symm_apply] simp [*]
/- 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.Trigonometric.Complex #align_import analysis.special_functions.trigonometric.arctan from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The `arctan` function. Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)` and the whole line. The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or `arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of `arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to `π / 4 = arctan 1`), including John Machin's original one at `four_mul_arctan_inv_5_sub_arctan_inv_239`. -/ noncomputable section namespace Real open Set Filter open scoped Topology Real theorem tan_add {x y : ℝ} (h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨ (∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_tan] using @Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast) #align real.tan_add Real.tan_add theorem tan_add' {x y : ℝ} (h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) : tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := tan_add (Or.inl h) #align real.tan_add' Real.tan_add' theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by have := @Complex.tan_two_mul x norm_cast at * #align real.tan_two_mul Real.tan_two_mul theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 := tan_eq_zero_iff.mpr (by use n) #align real.tan_int_mul_pi_div_two Real.tan_int_mul_pi_div_two theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos] rwa [h_eq] at this exact continuousOn_sin.div continuousOn_cos fun x => id #align real.continuous_on_tan Real.continuousOn_tan @[continuity] theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x := continuousOn_iff_continuous_restrict.1 continuousOn_tan #align real.continuous_tan Real.continuous_tan theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by refine ContinuousOn.mono continuousOn_tan fun x => ?_ simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne] rw [cos_eq_zero_iff] rintro hx_gt hx_lt ⟨r, hxr_eq⟩ rcases le_or_lt 0 r with h | h · rw [lt_iff_not_ge] at hx_lt refine hx_lt ?_ rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)] simp [h] · rw [lt_iff_not_ge] at hx_gt refine hx_gt ?_ rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul, mul_le_mul_right (half_pos pi_pos)] have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff] · set_option tactic.skipAssignedInstances false in norm_num rw [← Int.cast_one, ← Int.cast_neg]; norm_cast · exact zero_lt_two #align real.continuous_on_tan_Ioo Real.continuousOn_tan_Ioo theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ := have := neg_lt_self pi_div_two_pos continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this) (by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two) (by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two) #align real.surj_on_tan Real.surjOn_tan theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial #align real.tan_surjective Real.tan_surjective theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ := univ_subset_iff.1 surjOn_tan #align real.image_tan_Ioo Real.image_tan_Ioo /-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/ def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ := (strictMonoOn_tan.orderIso _ _).trans <| (OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ #align real.tan_order_iso Real.tanOrderIso /-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and `arctan x < π / 2` -/ -- @[pp_nodot] -- Porting note: removed noncomputable def arctan (x : ℝ) : ℝ := tanOrderIso.symm x #align real.arctan Real.arctan @[simp] theorem tan_arctan (x : ℝ) : tan (arctan x) = x := tanOrderIso.apply_symm_apply x #align real.tan_arctan Real.tan_arctan theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) := Subtype.coe_prop _ #align real.arctan_mem_Ioo Real.arctan_mem_Ioo @[simp] theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) := ((EquivLike.surjective _).range_comp _).trans Subtype.range_coe #align real.range_arctan Real.range_arctan theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x := Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩ #align real.arctan_tan Real.arctan_tan theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) := cos_pos_of_mem_Ioo <| arctan_mem_Ioo x #align real.cos_arctan_pos Real.cos_arctan_pos theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan] #align real.cos_sq_arctan Real.cos_sq_arctan theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] #align real.sin_arctan Real.sin_arctan theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan] #align real.cos_arctan Real.cos_arctan theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 := (arctan_mem_Ioo x).2 #align real.arctan_lt_pi_div_two Real.arctan_lt_pi_div_two theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x := (arctan_mem_Ioo x).1 #align real.neg_pi_div_two_lt_arctan Real.neg_pi_div_two_lt_arctan theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) := Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x) #align real.arctan_eq_arcsin Real.arctan_eq_arcsin theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) : arcsin x = arctan (x / √(1 - x ^ 2)) := by rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul, mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2] #align real.arcsin_eq_arctan Real.arcsin_eq_arctan @[simp] theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin] #align real.arctan_zero Real.arctan_zero @[mono] theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono theorem arctan_injective : arctan.Injective := arctan_strictMono.injective @[simp] theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 := .trans (by rw [arctan_zero]) arctan_injective.eq_iff theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) := tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) := tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : arctan y = x := injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h]) #align real.arctan_eq_of_tan_eq Real.arctan_eq_of_tan_eq @[simp] theorem arctan_one : arctan 1 = π / 4 := arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos] #align real.arctan_one Real.arctan_one @[simp] theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div] #align real.arctan_neg Real.arctan_neg theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _) congr 1 rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div, sqrt_sq h] all_goals positivity #align real.arctan_eq_arccos Real.arctan_eq_arccos -- The junk values for `arccos` and `sqrt` make this true even for `1 < x`. theorem arccos_eq_arctan {x : ℝ} (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by rw [arccos, eq_comm] refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩ · rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div] · linarith only [arcsin_le_pi_div_two x, pi_pos] · linarith only [arcsin_pos.2 h] #align real.arccos_eq_arctan Real.arccos_eq_arctan theorem arctan_inv_of_pos {x : ℝ} (h : 0 < x) : arctan x⁻¹ = π / 2 - arctan x := by rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan] · norm_num exact (arctan_lt_pi_div_two x).trans (half_lt_self_iff.mpr pi_pos) · rw [sub_lt_self_iff, ← arctan_zero] exact tanOrderIso.symm.strictMono h
Mathlib/Analysis/SpecialFunctions/Trigonometric/Arctan.lean
225
227
theorem arctan_inv_of_neg {x : ℝ} (h : x < 0) : arctan x⁻¹ = -(π / 2) - arctan x := by
have := arctan_inv_of_pos (neg_pos.mpr h) rwa [inv_neg, arctan_neg, neg_eq_iff_eq_neg, neg_sub', arctan_neg, neg_neg] at this
/- Copyright (c) 2024 Mitchell Lee. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Lee -/ import Mathlib.GroupTheory.Coxeter.Length import Mathlib.Data.ZMod.Parity /-! # Reflections, inversions, and inversion sequences Throughout this file, `B` is a type and `M : CoxeterMatrix B` is a Coxeter matrix. `cs : CoxeterSystem M W` is a Coxeter system; that is, `W` is a group, and `cs` holds the data of a group isomorphism `W ≃* M.group`, where `M.group` refers to the quotient of the free group on `B` by the Coxeter relations given by the matrix `M`. See `Mathlib/GroupTheory/Coxeter/Basic.lean` for more details. We define a *reflection* (`CoxeterSystem.IsReflection`) to be an element of the form $t = u s_i u^{-1}$, where $u \in W$ and $s_i$ is a simple reflection. We say that a reflection $t$ is a *left inversion* (`CoxeterSystem.IsLeftInversion`) of an element $w \in W$ if $\ell(t w) < \ell(w)$, and we say it is a *right inversion* (`CoxeterSystem.IsRightInversion`) of $w$ if $\ell(w t) > \ell(w)$. Here $\ell$ is the length function (see `Mathlib/GroupTheory/Coxeter/Length.lean`). Given a word, we define its *left inversion sequence* (`CoxeterSystem.leftInvSeq`) and its *right inversion sequence* (`CoxeterSystem.rightInvSeq`). We prove that if a word is reduced, then both of its inversion sequences contain no duplicates. In fact, the right (respectively, left) inversion sequence of a reduced word for $w$ consists of all of the right (respectively, left) inversions of $w$ in some order, but we do not prove that in this file. ## Main definitions * `CoxeterSystem.IsReflection` * `CoxeterSystem.IsLeftInversion` * `CoxeterSystem.IsRightInversion` * `CoxeterSystem.leftInvSeq` * `CoxeterSystem.rightInvSeq` ## References * [A. Björner and F. Brenti, *Combinatorics of Coxeter Groups*](bjorner2005) -/ namespace CoxeterSystem open List Matrix Function variable {B : Type*} variable {W : Type*} [Group W] variable {M : CoxeterMatrix B} (cs : CoxeterSystem M W) local prefix:100 "s" => cs.simple local prefix:100 "π" => cs.wordProd local prefix:100 "ℓ" => cs.length /-- `t : W` is a *reflection* of the Coxeter system `cs` if it is of the form $w s_i w^{-1}$, where $w \in W$ and $s_i$ is a simple reflection. -/ def IsReflection (t : W) : Prop := ∃ w i, t = w * s i * w⁻¹ theorem isReflection_simple (i : B) : cs.IsReflection (s i) := by use 1, i; simp namespace IsReflection variable {cs} variable {t : W} (ht : cs.IsReflection t) theorem pow_two : t ^ 2 = 1 := by rcases ht with ⟨w, i, rfl⟩ simp theorem mul_self : t * t = 1 := by rcases ht with ⟨w, i, rfl⟩ simp theorem inv : t⁻¹ = t := by rcases ht with ⟨w, i, rfl⟩ simp [mul_assoc] theorem isReflection_inv : cs.IsReflection t⁻¹ := by rwa [ht.inv] theorem odd_length : Odd (ℓ t) := by suffices cs.lengthParity t = Multiplicative.ofAdd 1 by simpa [lengthParity_eq_ofAdd_length, ZMod.eq_one_iff_odd] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem length_mul_left_ne (w : W) : ℓ (w * t) ≠ ℓ w := by suffices cs.lengthParity (w * t) ≠ cs.lengthParity w by contrapose! this simp only [lengthParity_eq_ofAdd_length, this] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem length_mul_right_ne (w : W) : ℓ (t * w) ≠ ℓ w := by suffices cs.lengthParity (t * w) ≠ cs.lengthParity w by contrapose! this simp only [lengthParity_eq_ofAdd_length, this] rcases ht with ⟨w, i, rfl⟩ simp [lengthParity_simple] theorem conj (w : W) : cs.IsReflection (w * t * w⁻¹) := by obtain ⟨u, i, rfl⟩ := ht use w * u, i group end IsReflection @[simp] theorem isReflection_conj_iff (w t : W) : cs.IsReflection (w * t * w⁻¹) ↔ cs.IsReflection t := by constructor · intro h simpa [← mul_assoc] using h.conj w⁻¹ · exact IsReflection.conj (w := w) /-- The proposition that `t` is a right inversion of `w`; i.e., `t` is a reflection and $\ell (w t) < \ell(w)$. -/ def IsRightInversion (w t : W) : Prop := cs.IsReflection t ∧ ℓ (w * t) < ℓ w /-- The proposition that `t` is a left inversion of `w`; i.e., `t` is a reflection and $\ell (t w) < \ell(w)$. -/ def IsLeftInversion (w t : W) : Prop := cs.IsReflection t ∧ ℓ (t * w) < ℓ w theorem isRightInversion_inv_iff {w t : W} : cs.IsRightInversion w⁻¹ t ↔ cs.IsLeftInversion w t := by apply and_congr_right intro ht rw [← length_inv, mul_inv_rev, inv_inv, ht.inv, cs.length_inv w] theorem isLeftInversion_inv_iff {w t : W} : cs.IsLeftInversion w⁻¹ t ↔ cs.IsRightInversion w t := by convert cs.isRightInversion_inv_iff.symm simp namespace IsReflection variable {cs} variable {t : W} (ht : cs.IsReflection t) theorem isRightInversion_mul_left_iff {w : W} : cs.IsRightInversion (w * t) t ↔ ¬cs.IsRightInversion w t := by unfold IsRightInversion simp only [mul_assoc, ht.inv, ht.mul_self, mul_one, ht, true_and, not_lt] constructor · exact le_of_lt · exact (lt_of_le_of_ne' · (ht.length_mul_left_ne w)) theorem not_isRightInversion_mul_left_iff {w : W} : ¬cs.IsRightInversion (w * t) t ↔ cs.IsRightInversion w t := ht.isRightInversion_mul_left_iff.not_left theorem isLeftInversion_mul_right_iff {w : W} : cs.IsLeftInversion (t * w) t ↔ ¬cs.IsLeftInversion w t := by rw [← isRightInversion_inv_iff, ← isRightInversion_inv_iff, mul_inv_rev, ht.inv, ht.isRightInversion_mul_left_iff] theorem not_isLeftInversion_mul_right_iff {w : W} : ¬cs.IsLeftInversion (t * w) t ↔ cs.IsLeftInversion w t := ht.isLeftInversion_mul_right_iff.not_left end IsReflection @[simp] theorem isRightInversion_simple_iff_isRightDescent (w : W) (i : B) : cs.IsRightInversion w (s i) ↔ cs.IsRightDescent w i := by simp [IsRightInversion, IsRightDescent, cs.isReflection_simple i] @[simp] theorem isLeftInversion_simple_iff_isLeftDescent (w : W) (i : B) : cs.IsLeftInversion w (s i) ↔ cs.IsLeftDescent w i := by simp [IsLeftInversion, IsLeftDescent, cs.isReflection_simple i] /-- The right inversion sequence of `ω`. The right inversion sequence of a word $s_{i_1} \cdots s_{i_\ell}$ is the sequence $$s_{i_\ell}\cdots s_{i_1}\cdots s_{i_\ell}, \ldots, s_{i_{\ell}}s_{i_{\ell - 1}}s_{i_{\ell - 2}}s_{i_{\ell - 1}}s_{i_\ell}, \ldots, s_{i_{\ell}}s_{i_{\ell - 1}}s_{i_\ell}, s_{i_\ell}.$$ -/ def rightInvSeq (ω : List B) : List W := match ω with | [] => [] | i :: ω => (π ω)⁻¹ * (s i) * (π ω) :: rightInvSeq ω /-- The left inversion sequence of `ω`. The left inversion sequence of a word $s_{i_1} \cdots s_{i_\ell}$ is the sequence $$s_{i_1}, s_{i_1}s_{i_2}s_{i_1}, s_{i_1}s_{i_2}s_{i_3}s_{i_2}s_{i_1}, \ldots, s_{i_1}\cdots s_{i_\ell}\cdots s_{i_1}.$$ -/ def leftInvSeq (ω : List B) : List W := match ω with | [] => [] | i :: ω => s i :: List.map (MulAut.conj (s i)) (leftInvSeq ω) local prefix:100 "ris" => cs.rightInvSeq local prefix:100 "lis" => cs.leftInvSeq @[simp] theorem rightInvSeq_nil : ris [] = [] := rfl @[simp] theorem leftInvSeq_nil : lis [] = [] := rfl @[simp] theorem rightInvSeq_singleton (i : B) : ris [i] = [s i] := by simp [rightInvSeq] @[simp] theorem leftInvSeq_singleton (i : B) : lis [i] = [s i] := rfl theorem rightInvSeq_concat (ω : List B) (i : B) : ris (ω.concat i) = (List.map (MulAut.conj (s i)) (ris ω)).concat (s i) := by induction' ω with j ω ih · simp · dsimp [rightInvSeq] rw [ih] simp only [concat_eq_append, wordProd_append, wordProd_cons, wordProd_nil, mul_one, mul_inv_rev, inv_simple, cons_append, cons.injEq, and_true] group private theorem leftInvSeq_eq_reverse_rightInvSeq_reverse (ω : List B) : lis ω = (ris ω.reverse).reverse := by induction' ω with i ω ih · simp · rw [leftInvSeq, reverse_cons, ← concat_eq_append, rightInvSeq_concat, ih] simp [map_reverse] theorem leftInvSeq_concat (ω : List B) (i : B) : lis (ω.concat i) = (lis ω).concat ((π ω) * (s i) * (π ω)⁻¹) := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse, rightInvSeq] theorem rightInvSeq_reverse (ω : List B) : ris (ω.reverse) = (lis ω).reverse := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] theorem leftInvSeq_reverse (ω : List B) : lis (ω.reverse) = (ris ω).reverse := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] @[simp] theorem length_rightInvSeq (ω : List B) : (ris ω).length = ω.length := by induction' ω with i ω ih · simp · simpa [rightInvSeq] @[simp] theorem length_leftInvSeq (ω : List B) : (lis ω).length = ω.length := by simp [leftInvSeq_eq_reverse_rightInvSeq_reverse] theorem getD_rightInvSeq (ω : List B) (j : ℕ) : (ris ω).getD j 1 = (π (ω.drop (j + 1)))⁻¹ * (Option.map (cs.simple) (ω.get? j)).getD 1 * π (ω.drop (j + 1)) := by induction' ω with i ω ih generalizing j · simp · dsimp only [rightInvSeq] rcases j with _ | j' · simp [getD_cons_zero] · simp [getD_cons_succ, ih j'] theorem getD_leftInvSeq (ω : List B) (j : ℕ) : (lis ω).getD j 1 = π (ω.take j) * (Option.map (cs.simple) (ω.get? j)).getD 1 * (π (ω.take j))⁻¹ := by induction' ω with i ω ih generalizing j · simp · dsimp [leftInvSeq] rcases j with _ | j' · simp [getD_cons_zero] · rw [getD_cons_succ] rw [(by simp : 1 = ⇑(MulAut.conj (s i)) 1)] rw [getD_map] rw [ih j'] simp [← mul_assoc, wordProd_cons] theorem getD_rightInvSeq_mul_self (ω : List B) (j : ℕ) : ((ris ω).getD j 1) * ((ris ω).getD j 1) = 1 := by simp [getD_rightInvSeq, mul_assoc] rcases em (j < ω.length) with hj | nhj · rw [get?_eq_get hj] simp [← mul_assoc] · rw [get?_eq_none.mpr (by omega)] simp theorem getD_leftInvSeq_mul_self (ω : List B) (j : ℕ) : ((lis ω).getD j 1) * ((lis ω).getD j 1) = 1 := by simp [getD_leftInvSeq, mul_assoc] rcases em (j < ω.length) with hj | nhj · rw [get?_eq_get hj] simp [← mul_assoc] · rw [get?_eq_none.mpr (by omega)] simp theorem rightInvSeq_drop (ω : List B) (j : ℕ) : ris (ω.drop j) = (ris ω).drop j := by induction' j with j ih₁ generalizing ω · simp · induction' ω with k ω _ · simp · rw [drop_succ_cons, ih₁ ω, rightInvSeq, drop_succ_cons] theorem leftInvSeq_take (ω : List B) (j : ℕ) : lis (ω.take j) = (lis ω).take j := by obtain le | ge := Nat.le_or_ge j ω.length · simp only [leftInvSeq_eq_reverse_rightInvSeq_reverse] rw [List.reverse_take j (by simpa)] nth_rw 1 [← List.reverse_reverse ω] rw [List.reverse_take j (by simpa)] simp [rightInvSeq_drop] · rw [take_length_le ge, take_length_le (by simpa)] theorem isReflection_of_mem_rightInvSeq (ω : List B) {t : W} (ht : t ∈ ris ω) : cs.IsReflection t := by induction' ω with i ω ih · simp at ht · dsimp [rightInvSeq] at ht rcases ht with _ | ⟨_, mem⟩ · use (π ω)⁻¹, i group · exact ih mem theorem isReflection_of_mem_leftInvSeq (ω : List B) {t : W} (ht : t ∈ lis ω) : cs.IsReflection t := by simp only [leftInvSeq_eq_reverse_rightInvSeq_reverse, mem_reverse] at ht exact cs.isReflection_of_mem_rightInvSeq ω.reverse ht theorem wordProd_mul_getD_rightInvSeq (ω : List B) (j : ℕ) : π ω * ((ris ω).getD j 1) = π (ω.eraseIdx j) := by rw [getD_rightInvSeq, eraseIdx_eq_take_drop_succ] nth_rw 1 [← take_append_drop (j + 1) ω] rw [take_succ] obtain lt | le := lt_or_le j ω.length · rw [get?_eq_get lt] simp only [wordProd_append, wordProd_cons, mul_assoc] simp · rw [get?_eq_none.mpr le] simp theorem getD_leftInvSeq_mul_wordProd (ω : List B) (j : ℕ) : ((lis ω).getD j 1) * π ω = π (ω.eraseIdx j) := by rw [getD_leftInvSeq, eraseIdx_eq_take_drop_succ] nth_rw 4 [← take_append_drop (j + 1) ω] rw [take_succ] obtain lt | le := lt_or_le j ω.length · rw [get?_eq_get lt] simp only [wordProd_append, wordProd_cons, mul_assoc] simp · rw [get?_eq_none.mpr le] simp
Mathlib/GroupTheory/Coxeter/Inversion.lean
346
357
theorem isRightInversion_of_mem_rightInvSeq {ω : List B} (hω : cs.IsReduced ω) {t : W} (ht : t ∈ ris ω) : cs.IsRightInversion (π ω) t := by
constructor · exact cs.isReflection_of_mem_rightInvSeq ω ht · obtain ⟨⟨j, hj⟩, rfl⟩ := List.mem_iff_get.mp ht rw [← List.getD_eq_get _ 1 hj, wordProd_mul_getD_rightInvSeq] rw [cs.length_rightInvSeq] at hj calc ℓ (π (ω.eraseIdx j)) _ ≤ (ω.eraseIdx j).length := cs.length_wordProd_le _ _ < ω.length := by rw [← List.length_eraseIdx_add_one hj]; exact lt_add_one _ _ = ℓ (π ω) := hω.symm
/- 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 -/ import Mathlib.Data.Finsupp.Encodable import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span import Mathlib.Data.Set.Countable #align_import linear_algebra.finsupp from "leanprover-community/mathlib"@"9d684a893c52e1d6692a504a118bfccbae04feeb" /-! # Properties of the module `α →₀ M` Given an `R`-module `M`, the `R`-module structure on `α →₀ M` is defined in `Data.Finsupp.Basic`. In this file we define `Finsupp.supported s` to be the set `{f : α →₀ M | f.support ⊆ s}` interpreted as a submodule of `α →₀ M`. We also define `LinearMap` versions of various maps: * `Finsupp.lsingle a : M →ₗ[R] ι →₀ M`: `Finsupp.single a` as a linear map; * `Finsupp.lapply a : (ι →₀ M) →ₗ[R] M`: the map `fun f ↦ f a` as a linear map; * `Finsupp.lsubtypeDomain (s : Set α) : (α →₀ M) →ₗ[R] (s →₀ M)`: restriction to a subtype as a linear map; * `Finsupp.restrictDom`: `Finsupp.filter` as a linear map to `Finsupp.supported s`; * `Finsupp.lsum`: `Finsupp.sum` or `Finsupp.liftAddHom` as a `LinearMap`; * `Finsupp.total α M R (v : ι → M)`: sends `l : ι → R` to the linear combination of `v i` with coefficients `l i`; * `Finsupp.totalOn`: a restricted version of `Finsupp.total` with domain `Finsupp.supported R R s` and codomain `Submodule.span R (v '' s)`; * `Finsupp.supportedEquivFinsupp`: a linear equivalence between the functions `α →₀ M` supported on `s` and the functions `s →₀ M`; * `Finsupp.lmapDomain`: a linear map version of `Finsupp.mapDomain`; * `Finsupp.domLCongr`: a `LinearEquiv` version of `Finsupp.domCongr`; * `Finsupp.congr`: if the sets `s` and `t` are equivalent, then `supported M R s` is equivalent to `supported M R t`; * `Finsupp.lcongr`: a `LinearEquiv`alence between `α →₀ M` and `β →₀ N` constructed using `e : α ≃ β` and `e' : M ≃ₗ[R] N`. ## Tags function with finite support, module, linear algebra -/ noncomputable section open Set LinearMap Submodule namespace Finsupp section SMul variable {α : Type*} {β : Type*} {R : Type*} {M : Type*} {M₂ : Type*} theorem smul_sum [Zero β] [AddCommMonoid M] [DistribSMul R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • v.sum h = v.sum fun a b => c • h a b := Finset.smul_sum #align finsupp.smul_sum Finsupp.smul_sum @[simp] theorem sum_smul_index_linearMap' [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M₂] [Module R M₂] {v : α →₀ M} {c : R} {h : α → M →ₗ[R] M₂} : ((c • v).sum fun a => h a) = c • v.sum fun a => h a := by rw [Finsupp.sum_smul_index', Finsupp.smul_sum] · simp only [map_smul] · intro i exact (h i).map_zero #align finsupp.sum_smul_index_linear_map' Finsupp.sum_smul_index_linearMap' end SMul section LinearEquivFunOnFinite variable (R : Type*) {S : Type*} (M : Type*) (α : Type*) variable [Finite α] [AddCommMonoid M] [Semiring R] [Module R M] /-- Given `Finite α`, `linearEquivFunOnFinite R` is the natural `R`-linear equivalence between `α →₀ β` and `α → β`. -/ @[simps apply] noncomputable def linearEquivFunOnFinite : (α →₀ M) ≃ₗ[R] α → M := { equivFunOnFinite with toFun := (⇑) map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv_fun_on_finite Finsupp.linearEquivFunOnFinite @[simp] theorem linearEquivFunOnFinite_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α) (single x m) = Pi.single x m := equivFunOnFinite_single x m #align finsupp.linear_equiv_fun_on_finite_single Finsupp.linearEquivFunOnFinite_single @[simp] theorem linearEquivFunOnFinite_symm_single [DecidableEq α] (x : α) (m : M) : (linearEquivFunOnFinite R M α).symm (Pi.single x m) = single x m := equivFunOnFinite_symm_single x m #align finsupp.linear_equiv_fun_on_finite_symm_single Finsupp.linearEquivFunOnFinite_symm_single @[simp] theorem linearEquivFunOnFinite_symm_coe (f : α →₀ M) : (linearEquivFunOnFinite R M α).symm f = f := (linearEquivFunOnFinite R M α).symm_apply_apply f #align finsupp.linear_equiv_fun_on_finite_symm_coe Finsupp.linearEquivFunOnFinite_symm_coe end LinearEquivFunOnFinite section LinearEquiv.finsuppUnique variable (R : Type*) {S : Type*} (M : Type*) variable [AddCommMonoid M] [Semiring R] [Module R M] variable (α : Type*) [Unique α] /-- If `α` has a unique term, then the type of finitely supported functions `α →₀ M` is `R`-linearly equivalent to `M`. -/ noncomputable def LinearEquiv.finsuppUnique : (α →₀ M) ≃ₗ[R] M := { Finsupp.equivFunOnFinite.trans (Equiv.funUnique α M) with map_add' := fun _ _ => rfl map_smul' := fun _ _ => rfl } #align finsupp.linear_equiv.finsupp_unique Finsupp.LinearEquiv.finsuppUnique variable {R M} @[simp] theorem LinearEquiv.finsuppUnique_apply (f : α →₀ M) : LinearEquiv.finsuppUnique R M α f = f default := rfl #align finsupp.linear_equiv.finsupp_unique_apply Finsupp.LinearEquiv.finsuppUnique_apply variable {α} @[simp] theorem LinearEquiv.finsuppUnique_symm_apply [Unique α] (m : M) : (LinearEquiv.finsuppUnique R M α).symm m = Finsupp.single default m := by ext; simp [LinearEquiv.finsuppUnique, Equiv.funUnique, single, Pi.single, equivFunOnFinite, Function.update] #align finsupp.linear_equiv.finsupp_unique_symm_apply Finsupp.LinearEquiv.finsuppUnique_symm_apply end LinearEquiv.finsuppUnique variable {α : Type*} {M : Type*} {N : Type*} {P : Type*} {R : Type*} {S : Type*} variable [Semiring R] [Semiring S] [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] variable [AddCommMonoid P] [Module R P] /-- Interpret `Finsupp.single a` as a linear map. -/ def lsingle (a : α) : M →ₗ[R] α →₀ M := { Finsupp.singleAddHom a with map_smul' := fun _ _ => (smul_single _ _ _).symm } #align finsupp.lsingle Finsupp.lsingle /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. -/ theorem lhom_ext ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a b, φ (single a b) = ψ (single a b)) : φ = ψ := LinearMap.toAddMonoidHom_injective <| addHom_ext h #align finsupp.lhom_ext Finsupp.lhom_ext /-- Two `R`-linear maps from `Finsupp X M` which agree on each `single x y` agree everywhere. We formulate this fact using equality of linear maps `φ.comp (lsingle a)` and `ψ.comp (lsingle a)` so that the `ext` tactic can apply a type-specific extensionality lemma to prove equality of these maps. E.g., if `M = R`, then it suffices to verify `φ (single a 1) = ψ (single a 1)`. -/ -- Porting note: The priority should be higher than `LinearMap.ext`. @[ext high] theorem lhom_ext' ⦃φ ψ : (α →₀ M) →ₗ[R] N⦄ (h : ∀ a, φ.comp (lsingle a) = ψ.comp (lsingle a)) : φ = ψ := lhom_ext fun a => LinearMap.congr_fun (h a) #align finsupp.lhom_ext' Finsupp.lhom_ext' /-- Interpret `fun f : α →₀ M ↦ f a` as a linear map. -/ def lapply (a : α) : (α →₀ M) →ₗ[R] M := { Finsupp.applyAddHom a with map_smul' := fun _ _ => rfl } #align finsupp.lapply Finsupp.lapply section CompatibleSMul variable (R S M N ι : Type*) variable [Semiring S] [AddCommMonoid M] [AddCommMonoid N] [Module S M] [Module S N] instance _root_.LinearMap.CompatibleSMul.finsupp_dom [SMulZeroClass R M] [DistribSMul R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul (ι →₀ M) N R S where map_smul f r m := by conv_rhs => rw [← sum_single m, map_finsupp_sum, smul_sum] erw [← sum_single (r • m), sum_mapRange_index single_zero, map_finsupp_sum] congr; ext i m; exact (f.comp <| lsingle i).map_smul_of_tower r m instance _root_.LinearMap.CompatibleSMul.finsupp_cod [SMul R M] [SMulZeroClass R N] [LinearMap.CompatibleSMul M N R S] : LinearMap.CompatibleSMul M (ι →₀ N) R S where map_smul f r m := by ext i; apply ((lapply i).comp f).map_smul_of_tower end CompatibleSMul /-- Forget that a function is finitely supported. This is the linear version of `Finsupp.toFun`. -/ @[simps] def lcoeFun : (α →₀ M) →ₗ[R] α → M where toFun := (⇑) map_add' x y := by ext simp map_smul' x y := by ext simp #align finsupp.lcoe_fun Finsupp.lcoeFun section LSubtypeDomain variable (s : Set α) /-- Interpret `Finsupp.subtypeDomain s` as a linear map. -/ def lsubtypeDomain : (α →₀ M) →ₗ[R] s →₀ M where toFun := subtypeDomain fun x => x ∈ s map_add' _ _ := subtypeDomain_add map_smul' _ _ := ext fun _ => rfl #align finsupp.lsubtype_domain Finsupp.lsubtypeDomain theorem lsubtypeDomain_apply (f : α →₀ M) : (lsubtypeDomain s : (α →₀ M) →ₗ[R] s →₀ M) f = subtypeDomain (fun x => x ∈ s) f := rfl #align finsupp.lsubtype_domain_apply Finsupp.lsubtypeDomain_apply end LSubtypeDomain @[simp] theorem lsingle_apply (a : α) (b : M) : (lsingle a : M →ₗ[R] α →₀ M) b = single a b := rfl #align finsupp.lsingle_apply Finsupp.lsingle_apply @[simp] theorem lapply_apply (a : α) (f : α →₀ M) : (lapply a : (α →₀ M) →ₗ[R] M) f = f a := rfl #align finsupp.lapply_apply Finsupp.lapply_apply @[simp] theorem lapply_comp_lsingle_same (a : α) : lapply a ∘ₗ lsingle a = (.id : M →ₗ[R] M) := by ext; simp @[simp] theorem lapply_comp_lsingle_of_ne (a a' : α) (h : a ≠ a') : lapply a ∘ₗ lsingle a' = (0 : M →ₗ[R] M) := by ext; simp [h.symm] @[simp] theorem ker_lsingle (a : α) : ker (lsingle a : M →ₗ[R] α →₀ M) = ⊥ := ker_eq_bot_of_injective (single_injective a) #align finsupp.ker_lsingle Finsupp.ker_lsingle theorem lsingle_range_le_ker_lapply (s t : Set α) (h : Disjoint s t) : ⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) ≤ ⨅ a ∈ t, ker (lapply a : (α →₀ M) →ₗ[R] M) := by refine iSup_le fun a₁ => iSup_le fun h₁ => range_le_iff_comap.2 ?_ simp only [(ker_comp _ _).symm, eq_top_iff, SetLike.le_def, mem_ker, comap_iInf, mem_iInf] intro b _ a₂ h₂ have : a₁ ≠ a₂ := fun eq => h.le_bot ⟨h₁, eq.symm ▸ h₂⟩ exact single_eq_of_ne this #align finsupp.lsingle_range_le_ker_lapply Finsupp.lsingle_range_le_ker_lapply theorem iInf_ker_lapply_le_bot : ⨅ a, ker (lapply a : (α →₀ M) →ₗ[R] M) ≤ ⊥ := by simp only [SetLike.le_def, mem_iInf, mem_ker, mem_bot, lapply_apply] exact fun a h => Finsupp.ext h #align finsupp.infi_ker_lapply_le_bot Finsupp.iInf_ker_lapply_le_bot theorem iSup_lsingle_range : ⨆ a, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M) = ⊤ := by refine eq_top_iff.2 <| SetLike.le_def.2 fun f _ => ?_ rw [← sum_single f] exact sum_mem fun a _ => Submodule.mem_iSup_of_mem a ⟨_, rfl⟩ #align finsupp.supr_lsingle_range Finsupp.iSup_lsingle_range theorem disjoint_lsingle_lsingle (s t : Set α) (hs : Disjoint s t) : Disjoint (⨆ a ∈ s, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) (⨆ a ∈ t, LinearMap.range (lsingle a : M →ₗ[R] α →₀ M)) := by -- Porting note: 2 placeholders are added to prevent timeout. refine (Disjoint.mono (lsingle_range_le_ker_lapply s sᶜ ?_) (lsingle_range_le_ker_lapply t tᶜ ?_)) ?_ · apply disjoint_compl_right · apply disjoint_compl_right rw [disjoint_iff_inf_le] refine le_trans (le_iInf fun i => ?_) iInf_ker_lapply_le_bot classical by_cases his : i ∈ s · by_cases hit : i ∈ t · exact (hs.le_bot ⟨his, hit⟩).elim exact inf_le_of_right_le (iInf_le_of_le i <| iInf_le _ hit) exact inf_le_of_left_le (iInf_le_of_le i <| iInf_le _ his) #align finsupp.disjoint_lsingle_lsingle Finsupp.disjoint_lsingle_lsingle theorem span_single_image (s : Set M) (a : α) : Submodule.span R (single a '' s) = (Submodule.span R s).map (lsingle a : M →ₗ[R] α →₀ M) := by rw [← span_image]; rfl #align finsupp.span_single_image Finsupp.span_single_image variable (M R) /-- `Finsupp.supported M R s` is the `R`-submodule of all `p : α →₀ M` such that `p.support ⊆ s`. -/ def supported (s : Set α) : Submodule R (α →₀ M) where carrier := { p | ↑p.support ⊆ s } add_mem' {p q} hp hq := by classical refine Subset.trans (Subset.trans (Finset.coe_subset.2 support_add) ?_) (union_subset hp hq) rw [Finset.coe_union] zero_mem' := by simp only [subset_def, Finset.mem_coe, Set.mem_setOf_eq, mem_support_iff, zero_apply] intro h ha exact (ha rfl).elim smul_mem' a p hp := Subset.trans (Finset.coe_subset.2 support_smul) hp #align finsupp.supported Finsupp.supported variable {M} theorem mem_supported {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ↑p.support ⊆ s := Iff.rfl #align finsupp.mem_supported Finsupp.mem_supported theorem mem_supported' {s : Set α} (p : α →₀ M) : p ∈ supported M R s ↔ ∀ x ∉ s, p x = 0 := by haveI := Classical.decPred fun x : α => x ∈ s; simp [mem_supported, Set.subset_def, not_imp_comm] #align finsupp.mem_supported' Finsupp.mem_supported' theorem mem_supported_support (p : α →₀ M) : p ∈ Finsupp.supported M R (p.support : Set α) := by rw [Finsupp.mem_supported] #align finsupp.mem_supported_support Finsupp.mem_supported_support theorem single_mem_supported {s : Set α} {a : α} (b : M) (h : a ∈ s) : single a b ∈ supported M R s := Set.Subset.trans support_single_subset (Finset.singleton_subset_set_iff.2 h) #align finsupp.single_mem_supported Finsupp.single_mem_supported theorem supported_eq_span_single (s : Set α) : supported R R s = span R ((fun i => single i 1) '' s) := by refine (span_eq_of_le _ ?_ (SetLike.le_def.2 fun l hl => ?_)).symm · rintro _ ⟨_, hp, rfl⟩ exact single_mem_supported R 1 hp · rw [← l.sum_single] refine sum_mem fun i il => ?_ -- Porting note: Needed to help this convert quite a bit replacing underscores convert smul_mem (M := α →₀ R) (x := single i 1) (span R ((fun i => single i 1) '' s)) (l i) ?_ · simp [span] · apply subset_span apply Set.mem_image_of_mem _ (hl il) #align finsupp.supported_eq_span_single Finsupp.supported_eq_span_single variable (M) /-- Interpret `Finsupp.filter s` as a linear map from `α →₀ M` to `supported M R s`. -/ def restrictDom (s : Set α) [DecidablePred (· ∈ s)] : (α →₀ M) →ₗ[R] supported M R s := LinearMap.codRestrict _ { toFun := filter (· ∈ s) map_add' := fun _ _ => filter_add map_smul' := fun _ _ => filter_smul } fun l => (mem_supported' _ _).2 fun _ => filter_apply_neg (· ∈ s) l #align finsupp.restrict_dom Finsupp.restrictDom variable {M R} section @[simp] theorem restrictDom_apply (s : Set α) (l : α →₀ M) [DecidablePred (· ∈ s)]: (restrictDom M R s l : α →₀ M) = Finsupp.filter (· ∈ s) l := rfl #align finsupp.restrict_dom_apply Finsupp.restrictDom_apply end theorem restrictDom_comp_subtype (s : Set α) [DecidablePred (· ∈ s)] : (restrictDom M R s).comp (Submodule.subtype _) = LinearMap.id := by ext l a by_cases h : a ∈ s <;> simp [h] exact ((mem_supported' R l.1).1 l.2 a h).symm #align finsupp.restrict_dom_comp_subtype Finsupp.restrictDom_comp_subtype theorem range_restrictDom (s : Set α) [DecidablePred (· ∈ s)] : LinearMap.range (restrictDom M R s) = ⊤ := range_eq_top.2 <| Function.RightInverse.surjective <| LinearMap.congr_fun (restrictDom_comp_subtype s) #align finsupp.range_restrict_dom Finsupp.range_restrictDom theorem supported_mono {s t : Set α} (st : s ⊆ t) : supported M R s ≤ supported M R t := fun _ h => Set.Subset.trans h st #align finsupp.supported_mono Finsupp.supported_mono @[simp] theorem supported_empty : supported M R (∅ : Set α) = ⊥ := eq_bot_iff.2 fun l h => (Submodule.mem_bot R).2 <| by ext; simp_all [mem_supported'] #align finsupp.supported_empty Finsupp.supported_empty @[simp] theorem supported_univ : supported M R (Set.univ : Set α) = ⊤ := eq_top_iff.2 fun _ _ => Set.subset_univ _ #align finsupp.supported_univ Finsupp.supported_univ theorem supported_iUnion {δ : Type*} (s : δ → Set α) : supported M R (⋃ i, s i) = ⨆ i, supported M R (s i) := by refine le_antisymm ?_ (iSup_le fun i => supported_mono <| Set.subset_iUnion _ _) haveI := Classical.decPred fun x => x ∈ ⋃ i, s i suffices LinearMap.range ((Submodule.subtype _).comp (restrictDom M R (⋃ i, s i))) ≤ ⨆ i, supported M R (s i) by rwa [LinearMap.range_comp, range_restrictDom, Submodule.map_top, range_subtype] at this rw [range_le_iff_comap, eq_top_iff] rintro l ⟨⟩ -- Porting note: Was ported as `induction l using Finsupp.induction` refine Finsupp.induction l ?_ ?_ · exact zero_mem _ · refine fun x a l _ _ => add_mem ?_ by_cases h : ∃ i, x ∈ s i <;> simp [h] cases' h with i hi exact le_iSup (fun i => supported M R (s i)) i (single_mem_supported R _ hi) #align finsupp.supported_Union Finsupp.supported_iUnion theorem supported_union (s t : Set α) : supported M R (s ∪ t) = supported M R s ⊔ supported M R t := by erw [Set.union_eq_iUnion, supported_iUnion, iSup_bool_eq]; rfl #align finsupp.supported_union Finsupp.supported_union theorem supported_iInter {ι : Type*} (s : ι → Set α) : supported M R (⋂ i, s i) = ⨅ i, supported M R (s i) := Submodule.ext fun x => by simp [mem_supported, subset_iInter_iff] #align finsupp.supported_Inter Finsupp.supported_iInter theorem supported_inter (s t : Set α) : supported M R (s ∩ t) = supported M R s ⊓ supported M R t := by rw [Set.inter_eq_iInter, supported_iInter, iInf_bool_eq]; rfl #align finsupp.supported_inter Finsupp.supported_inter theorem disjoint_supported_supported {s t : Set α} (h : Disjoint s t) : Disjoint (supported M R s) (supported M R t) := disjoint_iff.2 <| by rw [← supported_inter, disjoint_iff_inter_eq_empty.1 h, supported_empty] #align finsupp.disjoint_supported_supported Finsupp.disjoint_supported_supported
Mathlib/LinearAlgebra/Finsupp.lean
430
436
theorem disjoint_supported_supported_iff [Nontrivial M] {s t : Set α} : Disjoint (supported M R s) (supported M R t) ↔ Disjoint s t := by
refine ⟨fun h => Set.disjoint_left.mpr fun x hx1 hx2 => ?_, disjoint_supported_supported⟩ rcases exists_ne (0 : M) with ⟨y, hy⟩ have := h.le_bot ⟨single_mem_supported R y hx1, single_mem_supported R y hx2⟩ rw [mem_bot, single_eq_zero] at this exact hy this
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Init.Function import Mathlib.Init.Order.Defs #align_import data.bool.basic from "leanprover-community/mathlib"@"c4658a649d216f57e99621708b09dcb3dcccbd23" /-! # Booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Tags bool, boolean, Bool, De Morgan -/ namespace Bool @[deprecated (since := "2024-06-07")] alias decide_True := decide_true_eq_true #align bool.to_bool_true decide_true_eq_true @[deprecated (since := "2024-06-07")] alias decide_False := decide_false_eq_false #align bool.to_bool_false decide_false_eq_false #align bool.to_bool_coe Bool.decide_coe @[deprecated (since := "2024-06-07")] alias coe_decide := decide_eq_true_iff #align bool.coe_to_bool decide_eq_true_iff @[deprecated decide_eq_true_iff (since := "2024-06-07")] alias of_decide_iff := decide_eq_true_iff #align bool.of_to_bool_iff decide_eq_true_iff #align bool.tt_eq_to_bool_iff true_eq_decide_iff #align bool.ff_eq_to_bool_iff false_eq_decide_iff @[deprecated (since := "2024-06-07")] alias decide_not := decide_not #align bool.to_bool_not decide_not #align bool.to_bool_and Bool.decide_and #align bool.to_bool_or Bool.decide_or #align bool.to_bool_eq decide_eq_decide @[deprecated (since := "2024-06-07")] alias not_false' := false_ne_true #align bool.not_ff Bool.false_ne_true @[deprecated (since := "2024-06-07")] alias eq_iff_eq_true_iff := eq_iff_iff #align bool.default_bool Bool.default_bool theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp #align bool.dichotomy Bool.dichotomy theorem forall_bool' {p : Bool → Prop} (b : Bool) : (∀ x, p x) ↔ p b ∧ p !b := ⟨fun h ↦ ⟨h _, h _⟩, fun ⟨h₁, h₂⟩ x ↦ by cases b <;> cases x <;> assumption⟩ @[simp] theorem forall_bool {p : Bool → Prop} : (∀ b, p b) ↔ p false ∧ p true := forall_bool' false #align bool.forall_bool Bool.forall_bool theorem exists_bool' {p : Bool → Prop} (b : Bool) : (∃ x, p x) ↔ p b ∨ p !b := ⟨fun ⟨x, hx⟩ ↦ by cases x <;> cases b <;> first | exact .inl ‹_› | exact .inr ‹_›, fun h ↦ by cases h <;> exact ⟨_, ‹_›⟩⟩ @[simp] theorem exists_bool {p : Bool → Prop} : (∃ b, p b) ↔ p false ∨ p true := exists_bool' false #align bool.exists_bool Bool.exists_bool #align bool.decidable_forall_bool Bool.instDecidableForallOfDecidablePred #align bool.decidable_exists_bool Bool.instDecidableExistsOfDecidablePred #align bool.cond_eq_ite Bool.cond_eq_ite #align bool.cond_to_bool Bool.cond_decide #align bool.cond_bnot Bool.cond_not theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true #align bool.bnot_ne_id Bool.not_ne_id #align bool.coe_bool_iff Bool.coe_iff_coe @[deprecated (since := "2024-06-07")] alias eq_true_of_ne_false := eq_true_of_ne_false #align bool.eq_tt_of_ne_ff eq_true_of_ne_false @[deprecated (since := "2024-06-07")] alias eq_false_of_ne_true := eq_false_of_ne_true #align bool.eq_ff_of_ne_tt eq_true_of_ne_false #align bool.bor_comm Bool.or_comm #align bool.bor_assoc Bool.or_assoc #align bool.bor_left_comm Bool.or_left_comm theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H] #align bool.bor_inl Bool.or_inl theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H] #align bool.bor_inr Bool.or_inr #align bool.band_comm Bool.and_comm #align bool.band_assoc Bool.and_assoc #align bool.band_left_comm Bool.and_left_comm theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide #align bool.band_elim_left Bool.and_elim_left theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide #align bool.band_intro Bool.and_intro theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide #align bool.band_elim_right Bool.and_elim_right #align bool.band_bor_distrib_left Bool.and_or_distrib_left #align bool.band_bor_distrib_right Bool.and_or_distrib_right #align bool.bor_band_distrib_left Bool.or_and_distrib_left #align bool.bor_band_distrib_right Bool.or_and_distrib_right #align bool.bnot_ff Bool.not_false #align bool.bnot_tt Bool.not_true lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide #align bool.eq_bnot_iff Bool.eq_not_iff lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide #align bool.bnot_eq_iff Bool.not_eq_iff #align bool.not_eq_bnot Bool.not_eq_not #align bool.bnot_not_eq Bool.not_not_eq theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b := not_eq_not #align bool.ne_bnot Bool.ne_not @[deprecated (since := "2024-06-07")] alias not_ne := not_not_eq #align bool.bnot_ne Bool.not_not_eq lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide #align bool.bnot_ne_self Bool.not_ne_self lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide #align bool.self_ne_bnot Bool.self_ne_not lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide #align bool.eq_or_eq_bnot Bool.eq_or_eq_not -- Porting note: naming issue again: these two `not` are different. theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp #align bool.bnot_iff_not Bool.not_iff_not theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by cases a <;> decide #align bool.eq_tt_of_bnot_eq_ff Bool.eq_true_of_not_eq_false' theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by cases a <;> decide #align bool.eq_ff_of_bnot_eq_tt Bool.eq_false_of_not_eq_true' #align bool.band_bnot_self Bool.and_not_self #align bool.bnot_band_self Bool.not_and_self #align bool.bor_bnot_self Bool.or_not_self #align bool.bnot_bor_self Bool.not_or_self theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide #align bool.bxor_comm Bool.xor_comm attribute [simp] xor_assoc #align bool.bxor_assoc Bool.xor_assoc #align bool.bxor_left_comm Bool.xor_left_comm #align bool.bxor_bnot_left Bool.not_xor #align bool.bxor_bnot_right Bool.xor_not #align bool.bxor_bnot_bnot Bool.not_xor_not #align bool.bxor_ff_left Bool.false_xor #align bool.bxor_ff_right Bool.xor_false #align bool.band_bxor_distrib_left Bool.and_xor_distrib_left #align bool.band_bxor_distrib_right Bool.and_xor_distrib_right
Mathlib/Data/Bool/Basic.lean
185
185
theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by
decide
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.GroupPower.IterateHom import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Order.Iterate import Mathlib.Order.SemiconjSup import Mathlib.Tactic.Monotonicity import Mathlib.Topology.Order.MonotoneContinuity #align_import dynamics.circle.rotation_number.translation_number from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Translation number of a monotone real map that commutes with `x ↦ x + 1` Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit $$ \tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n} $$ exists and does not depend on `x`. This number is called the *translation number* of `f`. Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and only if `τ(f)=m/n`. Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and consider a real number `a` such that `⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is not formalized yet). This function is strictly monotone, continuous, and satisfies `F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`. It does not depend on the choice of `a`. ## Main definitions * `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`; the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the multiplication is given by composition: `(f * g) x = f (g x)`. * `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`. ## Main statements We prove the following properties of `CircleDeg1Lift.translationNumber`. * `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0` and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal translation numbers. * `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g` are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`. * `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map (equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then the translation number of `f⁻¹` is the negative of the translation number of `f`. * `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then `τ (f * g) = τ f + τ g`. * `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`. * `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these maps are semiconjugate to each other. * `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are equal to each other for all `g : G`, then these two actions are semiconjugate by some `F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]. ## Notation We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`. ## Implementation notes We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence `(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`. This way it is much easier to prove that the limit exists and basic properties of the limit. We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation preserving circle homeomorphisms for two reasons: * non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry cells); * definition and some basic properties still work for this class. ## References * [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes] ## TODO Here are some short-term goals. * Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use `Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?). * Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation. * Introduce `ConditionallyCompleteLattice` structure, use it in the proof of `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`. * Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational translation by a continuous `CircleDeg1Lift`. ## Tags circle homeomorphism, rotation number -/ open scoped Classical open Filter Set Int Topology open Function hiding Commute /-! ### Definition and monoid structure -/ /-- A lift of a monotone degree one map `S¹ → S¹`. -/ structure CircleDeg1Lift extends ℝ →o ℝ : Type where map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1 #align circle_deg1_lift CircleDeg1Lift namespace CircleDeg1Lift instance : FunLike CircleDeg1Lift ℝ ℝ where coe f := f.toFun coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl instance : OrderHomClass CircleDeg1Lift ℝ ℝ where map_rel f _ _ h := f.monotone' h @[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl #align circle_deg1_lift.coe_mk CircleDeg1Lift.coe_mk variable (f g : CircleDeg1Lift) @[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl protected theorem monotone : Monotone f := f.monotone' #align circle_deg1_lift.monotone CircleDeg1Lift.monotone @[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h #align circle_deg1_lift.mono CircleDeg1Lift.mono theorem strictMono_iff_injective : StrictMono f ↔ Injective f := f.monotone.strictMono_iff_injective #align circle_deg1_lift.strict_mono_iff_injective CircleDeg1Lift.strictMono_iff_injective @[simp] theorem map_add_one : ∀ x, f (x + 1) = f x + 1 := f.map_add_one' #align circle_deg1_lift.map_add_one CircleDeg1Lift.map_add_one @[simp] theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1] #align circle_deg1_lift.map_one_add CircleDeg1Lift.map_one_add #noalign circle_deg1_lift.coe_inj -- Use `DFunLike.coe_inj` @[ext] theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align circle_deg1_lift.ext CircleDeg1Lift.ext theorem ext_iff {f g : CircleDeg1Lift} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align circle_deg1_lift.ext_iff CircleDeg1Lift.ext_iff instance : Monoid CircleDeg1Lift where mul f g := { toOrderHom := f.1.comp g.1 map_add_one' := fun x => by simp [map_add_one] } one := ⟨.id, fun _ => rfl⟩ mul_one f := rfl one_mul f := rfl mul_assoc f₁ f₂ f₃ := DFunLike.coe_injective rfl instance : Inhabited CircleDeg1Lift := ⟨1⟩ @[simp] theorem coe_mul : ⇑(f * g) = f ∘ g := rfl #align circle_deg1_lift.coe_mul CircleDeg1Lift.coe_mul theorem mul_apply (x) : (f * g) x = f (g x) := rfl #align circle_deg1_lift.mul_apply CircleDeg1Lift.mul_apply @[simp] theorem coe_one : ⇑(1 : CircleDeg1Lift) = id := rfl #align circle_deg1_lift.coe_one CircleDeg1Lift.coe_one instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ := ⟨fun f => ⇑(f : CircleDeg1Lift)⟩ #align circle_deg1_lift.units_has_coe_to_fun CircleDeg1Lift.unitsHasCoeToFun #noalign circle_deg1_lift.units_coe -- now LHS = RHS @[simp] theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) : (f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id] #align circle_deg1_lift.units_inv_apply_apply CircleDeg1Lift.units_inv_apply_apply @[simp] theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) : f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id] #align circle_deg1_lift.units_apply_inv_apply CircleDeg1Lift.units_apply_inv_apply /-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/ def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where toFun f := { toFun := f invFun := ⇑f⁻¹ left_inv := units_inv_apply_apply f right_inv := units_apply_inv_apply f map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ } map_one' := rfl map_mul' f g := rfl #align circle_deg1_lift.to_order_iso CircleDeg1Lift.toOrderIso @[simp] theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f := rfl #align circle_deg1_lift.coe_to_order_iso CircleDeg1Lift.coe_toOrderIso @[simp] theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_symm CircleDeg1Lift.coe_toOrderIso_symm @[simp] theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) := rfl #align circle_deg1_lift.coe_to_order_iso_inv CircleDeg1Lift.coe_toOrderIso_inv theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f := ⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h => Units.isUnit { val := f inv := { toFun := (Equiv.ofBijective f h).symm monotone' := fun x y hxy => (f.strictMono_iff_injective.2 h.1).le_iff_le.1 (by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy]) map_add_one' := fun x => h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] } val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩ #align circle_deg1_lift.is_unit_iff_bijective CircleDeg1Lift.isUnit_iff_bijective theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n] | 0 => rfl | n + 1 => by ext x simp [coe_pow n, pow_succ] #align circle_deg1_lift.coe_pow CircleDeg1Lift.coe_pow theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} : SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ := ext_iff #align circle_deg1_lift.semiconj_by_iff_semiconj CircleDeg1Lift.semiconjBy_iff_semiconj theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g := ext_iff #align circle_deg1_lift.commute_iff_commute CircleDeg1Lift.commute_iff_commute /-! ### Translate by a constant -/ /-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from `Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is `translation (Multiplicative.ofAdd x)`. -/ def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <| { toFun := fun x => ⟨⟨fun y => Multiplicative.toAdd x + y, fun _ _ h => add_le_add_left h _⟩, fun _ => (add_assoc _ _ _).symm⟩ map_one' := ext <| zero_add map_mul' := fun _ _ => ext <| add_assoc _ _ } #align circle_deg1_lift.translate CircleDeg1Lift.translate @[simp] theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y := rfl #align circle_deg1_lift.translate_apply CircleDeg1Lift.translate_apply @[simp] theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y := rfl #align circle_deg1_lift.translate_inv_apply CircleDeg1Lift.translate_inv_apply @[simp] theorem translate_zpow (x : ℝ) (n : ℤ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow] #align circle_deg1_lift.translate_zpow CircleDeg1Lift.translate_zpow @[simp] theorem translate_pow (x : ℝ) (n : ℕ) : translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := translate_zpow x n #align circle_deg1_lift.translate_pow CircleDeg1Lift.translate_pow @[simp] theorem translate_iterate (x : ℝ) (n : ℕ) : (translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow] #align circle_deg1_lift.translate_iterate CircleDeg1Lift.translate_iterate /-! ### Commutativity with integer translations In this section we prove that `f` commutes with translations by an integer number. First we formulate these statements (for a natural or an integer number, addition on the left or on the right, addition or subtraction) using `Function.Commute`, then reformulate as `simp` lemmas `map_int_add` etc. -/ theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n #align circle_deg1_lift.commute_nat_add CircleDeg1Lift.commute_nat_add theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by simp only [add_comm _ (n : ℝ), f.commute_nat_add n] #align circle_deg1_lift.commute_add_nat CircleDeg1Lift.commute_add_nat theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_nat CircleDeg1Lift.commute_sub_nat theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n) | (n : ℕ) => f.commute_add_nat n | -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1) #align circle_deg1_lift.commute_add_int CircleDeg1Lift.commute_add_int theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n #align circle_deg1_lift.commute_int_add CircleDeg1Lift.commute_int_add theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by simpa only [sub_eq_add_neg] using (f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv #align circle_deg1_lift.commute_sub_int CircleDeg1Lift.commute_sub_int @[simp] theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x := f.commute_int_add m x #align circle_deg1_lift.map_int_add CircleDeg1Lift.map_int_add @[simp] theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m := f.commute_add_int m x #align circle_deg1_lift.map_add_int CircleDeg1Lift.map_add_int @[simp] theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n := f.commute_sub_int n x #align circle_deg1_lift.map_sub_int CircleDeg1Lift.map_sub_int @[simp] theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n := f.map_add_int x n #align circle_deg1_lift.map_add_nat CircleDeg1Lift.map_add_nat @[simp] theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x := f.map_int_add n x #align circle_deg1_lift.map_nat_add CircleDeg1Lift.map_nat_add @[simp] theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n := f.map_sub_int x n #align circle_deg1_lift.map_sub_nat CircleDeg1Lift.map_sub_nat theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add] #align circle_deg1_lift.map_int_of_map_zero CircleDeg1Lift.map_int_of_map_zero @[simp] theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right] #align circle_deg1_lift.map_fract_sub_fract_eq CircleDeg1Lift.map_fract_sub_fract_eq /-! ### Pointwise order on circle maps -/ /-- Monotone circle maps form a lattice with respect to the pointwise order -/ noncomputable instance : Lattice CircleDeg1Lift where sup f g := { toFun := fun x => max (f x) (g x) monotone' := fun x y h => max_le_max (f.mono h) (g.mono h) -- TODO: generalize to `Monotone.max` map_add_one' := fun x => by simp [max_add_add_right] } le f g := ∀ x, f x ≤ g x le_refl f x := le_refl (f x) le_trans f₁ f₂ f₃ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x) le_antisymm f₁ f₂ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x) le_sup_left f g x := le_max_left (f x) (g x) le_sup_right f g x := le_max_right (f x) (g x) sup_le f₁ f₂ f₃ h₁ h₂ x := max_le (h₁ x) (h₂ x) inf f g := { toFun := fun x => min (f x) (g x) monotone' := fun x y h => min_le_min (f.mono h) (g.mono h) map_add_one' := fun x => by simp [min_add_add_right] } inf_le_left f g x := min_le_left (f x) (g x) inf_le_right f g x := min_le_right (f x) (g x) le_inf f₁ f₂ f₃ h₂ h₃ x := le_min (h₂ x) (h₃ x) @[simp] theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) := rfl #align circle_deg1_lift.sup_apply CircleDeg1Lift.sup_apply @[simp] theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) := rfl #align circle_deg1_lift.inf_apply CircleDeg1Lift.inf_apply theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h => f.monotone.iterate_le_of_le h _ #align circle_deg1_lift.iterate_monotone CircleDeg1Lift.iterate_monotone theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] := iterate_monotone n h #align circle_deg1_lift.iterate_mono CircleDeg1Lift.iterate_mono theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by simp only [coe_pow, iterate_mono h n x] #align circle_deg1_lift.pow_mono CircleDeg1Lift.pow_mono theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n #align circle_deg1_lift.pow_monotone CircleDeg1Lift.pow_monotone /-! ### Estimates on `(f * g) 0` We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed floors and ceils. We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0` is less than two. -/ theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ := calc f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _ _ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _ #align circle_deg1_lift.map_le_of_map_zero CircleDeg1Lift.map_le_of_map_zero theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_le_of_map_zero (g 0) #align circle_deg1_lift.map_map_zero_le CircleDeg1Lift.map_map_zero_le theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ := calc ⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g _ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_int _ _ #align circle_deg1_lift.floor_map_map_zero_le CircleDeg1Lift.floor_map_map_zero_le theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ := calc ⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g _ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_int _ _ #align circle_deg1_lift.ceil_map_map_zero_le CircleDeg1Lift.ceil_map_map_zero_le theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 := calc f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g _ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _ _ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm #align circle_deg1_lift.map_map_zero_lt CircleDeg1Lift.map_map_zero_lt theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x := calc f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm _ ≤ f x := f.monotone <| floor_le _ #align circle_deg1_lift.le_map_of_map_zero CircleDeg1Lift.le_map_of_map_zero theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) := f.le_map_of_map_zero (g 0) #align circle_deg1_lift.le_map_map_zero CircleDeg1Lift.le_map_map_zero theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ := calc ⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_int _ _).symm _ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_floor_map_map_zero CircleDeg1Lift.le_floor_map_map_zero theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ := calc ⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_int _ _).symm _ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g #align circle_deg1_lift.le_ceil_map_map_zero CircleDeg1Lift.le_ceil_map_map_zero theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) := calc f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _ _ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _ _ ≤ f (g 0) := f.le_map_map_zero g #align circle_deg1_lift.lt_map_map_zero CircleDeg1Lift.lt_map_map_zero theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg] exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩ #align circle_deg1_lift.dist_map_map_zero_lt CircleDeg1Lift.dist_map_map_zero_lt theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := calc dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _ _ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub, abs_sub_comm (g₂ (f 0))] _ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f) _ = 2 := one_add_one_eq_two #align circle_deg1_lift.dist_map_zero_lt_of_semiconj CircleDeg1Lift.dist_map_zero_lt_of_semiconj theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) : dist (g₁ 0) (g₂ 0) < 2 := dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h #align circle_deg1_lift.dist_map_zero_lt_of_semiconj_by CircleDeg1Lift.dist_map_zero_lt_of_semiconjBy /-! ### Limits at infinities and continuity -/ protected theorem tendsto_atBot : Tendsto f atBot atBot := tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <| (tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <| tendsto_atBot_add_const_right _ _ tendsto_id #align circle_deg1_lift.tendsto_at_bot CircleDeg1Lift.tendsto_atBot protected theorem tendsto_atTop : Tendsto f atTop atTop := tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <| (tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id #align circle_deg1_lift.tendsto_at_top CircleDeg1Lift.tendsto_atTop theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f := ⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩ #align circle_deg1_lift.continuous_iff_surjective CircleDeg1Lift.continuous_iff_surjective /-! ### Estimates on `(f^n) x` If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on `f^[n] x` and `x + n * m`. For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications work for `n = 0`. For `<` and `>` we formulate only `iff` versions. -/ theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) : f^[n] x ≤ x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n #align circle_deg1_lift.iterate_le_of_map_le_add_int CircleDeg1Lift.iterate_le_of_map_le_add_int theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) : x + n * m ≤ f^[n] x := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n #align circle_deg1_lift.le_iterate_of_add_int_le_map CircleDeg1Lift.le_iterate_of_add_int_le_map theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) : f^[n] x = x + n * m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h #align circle_deg1_lift.iterate_eq_of_map_eq_add_int CircleDeg1Lift.iterate_eq_of_map_eq_add_int theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_le_iff CircleDeg1Lift.iterate_pos_le_iff theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x < x + n * m ↔ f x < x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_lt_iff CircleDeg1Lift.iterate_pos_lt_iff theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : f^[n] x = x + n * m ↔ f x = x + m := by simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strictMono_id.add_const (m : ℝ)) hn #align circle_deg1_lift.iterate_pos_eq_iff CircleDeg1Lift.iterate_pos_eq_iff theorem le_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m ≤ f^[n] x ↔ x + m ≤ f x := by simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn) #align circle_deg1_lift.le_iterate_pos_iff CircleDeg1Lift.le_iterate_pos_iff theorem lt_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) : x + n * m < f^[n] x ↔ x + m < f x := by simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn) #align circle_deg1_lift.lt_iterate_pos_iff CircleDeg1Lift.lt_iterate_pos_iff theorem mul_floor_map_zero_le_floor_iterate_zero (n : ℕ) : ↑n * ⌊f 0⌋ ≤ ⌊f^[n] 0⌋ := by rw [le_floor, Int.cast_mul, Int.cast_natCast, ← zero_add ((n : ℝ) * _)] apply le_iterate_of_add_int_le_map simp [floor_le] #align circle_deg1_lift.mul_floor_map_zero_le_floor_iterate_zero CircleDeg1Lift.mul_floor_map_zero_le_floor_iterate_zero /-! ### Definition of translation number -/ noncomputable section /-- An auxiliary sequence used to define the translation number. -/ def transnumAuxSeq (n : ℕ) : ℝ := (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n #align circle_deg1_lift.transnum_aux_seq CircleDeg1Lift.transnumAuxSeq /-- The translation number of a `CircleDeg1Lift`, $τ(f)=\lim_{n→∞}\frac{f^n(x)-x}{n}$. We use an auxiliary sequence `\frac{f^{2^n}(0)}{2^n}` to define `τ(f)` because some proofs are simpler this way. -/ def translationNumber : ℝ := limUnder atTop f.transnumAuxSeq #align circle_deg1_lift.translation_number CircleDeg1Lift.translationNumber end -- TODO: choose two different symbols for `CircleDeg1Lift.translationNumber` and the future -- `circle_mono_homeo.rotation_number`, then make them `localized notation`s local notation "τ" => translationNumber theorem transnumAuxSeq_def : f.transnumAuxSeq = fun n : ℕ => (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n := rfl #align circle_deg1_lift.transnum_aux_seq_def CircleDeg1Lift.transnumAuxSeq_def theorem translationNumber_eq_of_tendsto_aux {τ' : ℝ} (h : Tendsto f.transnumAuxSeq atTop (𝓝 τ')) : τ f = τ' := h.limUnder_eq #align circle_deg1_lift.translation_number_eq_of_tendsto_aux CircleDeg1Lift.translationNumber_eq_of_tendsto_aux theorem translationNumber_eq_of_tendsto₀ {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n] 0 / n) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto_aux <| by simpa [(· ∘ ·), transnumAuxSeq_def, coe_pow] using h.comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) #align circle_deg1_lift.translation_number_eq_of_tendsto₀ CircleDeg1Lift.translationNumber_eq_of_tendsto₀ theorem translationNumber_eq_of_tendsto₀' {τ' : ℝ} (h : Tendsto (fun n : ℕ => f^[n + 1] 0 / (n + 1)) atTop (𝓝 τ')) : τ f = τ' := f.translationNumber_eq_of_tendsto₀ <| (tendsto_add_atTop_iff_nat 1).1 (mod_cast h) #align circle_deg1_lift.translation_number_eq_of_tendsto₀' CircleDeg1Lift.translationNumber_eq_of_tendsto₀' theorem transnumAuxSeq_zero : f.transnumAuxSeq 0 = f 0 := by simp [transnumAuxSeq] #align circle_deg1_lift.transnum_aux_seq_zero CircleDeg1Lift.transnumAuxSeq_zero theorem transnumAuxSeq_dist_lt (n : ℕ) : dist (f.transnumAuxSeq n) (f.transnumAuxSeq (n + 1)) < 1 / 2 / 2 ^ n := by have : 0 < (2 ^ (n + 1) : ℝ) := pow_pos zero_lt_two _ rw [div_div, ← pow_succ', ← abs_of_pos this] replace := abs_pos.2 (ne_of_gt this) convert (div_lt_div_right this).2 ((f ^ 2 ^ n).dist_map_map_zero_lt (f ^ 2 ^ n)) using 1 simp_rw [transnumAuxSeq, Real.dist_eq] rw [← abs_div, sub_div, pow_succ, pow_succ', ← two_mul, mul_div_mul_left _ _ (two_ne_zero' ℝ), pow_mul, sq, mul_apply] #align circle_deg1_lift.transnum_aux_seq_dist_lt CircleDeg1Lift.transnumAuxSeq_dist_lt theorem tendsto_translationNumber_aux : Tendsto f.transnumAuxSeq atTop (𝓝 <| τ f) := (cauchySeq_of_le_geometric_two 1 fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n).tendsto_limUnder #align circle_deg1_lift.tendsto_translation_number_aux CircleDeg1Lift.tendsto_translationNumber_aux theorem dist_map_zero_translationNumber_le : dist (f 0) (τ f) ≤ 1 := f.transnumAuxSeq_zero ▸ dist_le_of_le_geometric_two_of_tendsto₀ 1 (fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n) f.tendsto_translationNumber_aux #align circle_deg1_lift.dist_map_zero_translation_number_le CircleDeg1Lift.dist_map_zero_translationNumber_le theorem tendsto_translationNumber_of_dist_bounded_aux (x : ℕ → ℝ) (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) (x n) ≤ C) : Tendsto (fun n : ℕ => x (2 ^ n) / 2 ^ n) atTop (𝓝 <| τ f) := by apply f.tendsto_translationNumber_aux.congr_dist (squeeze_zero (fun _ => dist_nonneg) _ _) · exact fun n => C / 2 ^ n · intro n have : 0 < (2 ^ n : ℝ) := pow_pos zero_lt_two _ convert (div_le_div_right this).2 (H (2 ^ n)) using 1 rw [transnumAuxSeq, Real.dist_eq, ← sub_div, abs_div, abs_of_pos this, Real.dist_eq] · exact mul_zero C ▸ tendsto_const_nhds.mul <| tendsto_inv_atTop_zero.comp <| tendsto_pow_atTop_atTop_of_one_lt one_lt_two #align circle_deg1_lift.tendsto_translation_number_of_dist_bounded_aux CircleDeg1Lift.tendsto_translationNumber_of_dist_bounded_aux theorem translationNumber_eq_of_dist_bounded {f g : CircleDeg1Lift} (C : ℝ) (H : ∀ n : ℕ, dist ((f ^ n) 0) ((g ^ n) 0) ≤ C) : τ f = τ g := Eq.symm <| g.translationNumber_eq_of_tendsto_aux <| f.tendsto_translationNumber_of_dist_bounded_aux _ C H #align circle_deg1_lift.translation_number_eq_of_dist_bounded CircleDeg1Lift.translationNumber_eq_of_dist_bounded @[simp] theorem translationNumber_one : τ 1 = 0 := translationNumber_eq_of_tendsto₀ _ <| by simp [tendsto_const_nhds] #align circle_deg1_lift.translation_number_one CircleDeg1Lift.translationNumber_one theorem translationNumber_eq_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (H : SemiconjBy f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_dist_bounded 2 fun n => le_of_lt <| dist_map_zero_lt_of_semiconjBy <| H.pow_right n #align circle_deg1_lift.translation_number_eq_of_semiconj_by CircleDeg1Lift.translationNumber_eq_of_semiconjBy theorem translationNumber_eq_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (H : Function.Semiconj f g₁ g₂) : τ g₁ = τ g₂ := translationNumber_eq_of_semiconjBy <| semiconjBy_iff_semiconj.2 H #align circle_deg1_lift.translation_number_eq_of_semiconj CircleDeg1Lift.translationNumber_eq_of_semiconj theorem translationNumber_mul_of_commute {f g : CircleDeg1Lift} (h : Commute f g) : τ (f * g) = τ f + τ g := by refine tendsto_nhds_unique ?_ (f.tendsto_translationNumber_aux.add g.tendsto_translationNumber_aux) simp only [transnumAuxSeq, ← add_div] refine (f * g).tendsto_translationNumber_of_dist_bounded_aux (fun n ↦ (f ^ n) 0 + (g ^ n) 0) 1 fun n ↦ ?_ rw [h.mul_pow, dist_comm] exact le_of_lt ((f ^ n).dist_map_map_zero_lt (g ^ n)) #align circle_deg1_lift.translation_number_mul_of_commute CircleDeg1Lift.translationNumber_mul_of_commute @[simp] theorem translationNumber_units_inv (f : CircleDeg1Liftˣ) : τ ↑f⁻¹ = -τ f := eq_neg_iff_add_eq_zero.2 <| by simp [← translationNumber_mul_of_commute (Commute.refl _).units_inv_left] #align circle_deg1_lift.translation_number_units_inv CircleDeg1Lift.translationNumber_units_inv @[simp] theorem translationNumber_pow : ∀ n : ℕ, τ (f ^ n) = n * τ f | 0 => by simp | n + 1 => by rw [pow_succ, translationNumber_mul_of_commute (Commute.pow_self f n), translationNumber_pow n, Nat.cast_add_one, add_mul, one_mul] #align circle_deg1_lift.translation_number_pow CircleDeg1Lift.translationNumber_pow @[simp] theorem translationNumber_zpow (f : CircleDeg1Liftˣ) : ∀ n : ℤ, τ (f ^ n : Units _) = n * τ f | (n : ℕ) => by simp [translationNumber_pow f n] | -[n+1] => by simp; ring #align circle_deg1_lift.translation_number_zpow CircleDeg1Lift.translationNumber_zpow @[simp] theorem translationNumber_conj_eq (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f * g * ↑f⁻¹) = τ g := (translationNumber_eq_of_semiconjBy (f.mk_semiconjBy g)).symm #align circle_deg1_lift.translation_number_conj_eq CircleDeg1Lift.translationNumber_conj_eq @[simp] theorem translationNumber_conj_eq' (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) : τ (↑f⁻¹ * g * f) = τ g := translationNumber_conj_eq f⁻¹ g #align circle_deg1_lift.translation_number_conj_eq' CircleDeg1Lift.translationNumber_conj_eq' theorem dist_pow_map_zero_mul_translationNumber_le (n : ℕ) : dist ((f ^ n) 0) (n * f.translationNumber) ≤ 1 := f.translationNumber_pow n ▸ (f ^ n).dist_map_zero_translationNumber_le #align circle_deg1_lift.dist_pow_map_zero_mul_translation_number_le CircleDeg1Lift.dist_pow_map_zero_mul_translationNumber_le theorem tendsto_translation_number₀' : Tendsto (fun n : ℕ => (f ^ (n + 1) : CircleDeg1Lift) 0 / ((n : ℝ) + 1)) atTop (𝓝 <| τ f) := by refine tendsto_iff_dist_tendsto_zero.2 <| squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) ((tendsto_const_div_atTop_nhds_zero_nat 1).comp (tendsto_add_atTop_nat 1)) dsimp have : (0 : ℝ) < n + 1 := n.cast_add_one_pos rw [Real.dist_eq, div_sub' _ _ _ (ne_of_gt this), abs_div, ← Real.dist_eq, abs_of_pos this, Nat.cast_add_one, div_le_div_right this, ← Nat.cast_add_one] apply dist_pow_map_zero_mul_translationNumber_le #align circle_deg1_lift.tendsto_translation_number₀' CircleDeg1Lift.tendsto_translation_number₀' theorem tendsto_translation_number₀ : Tendsto (fun n : ℕ => (f ^ n) 0 / n) atTop (𝓝 <| τ f) := (tendsto_add_atTop_iff_nat 1).1 (mod_cast f.tendsto_translation_number₀') #align circle_deg1_lift.tendsto_translation_number₀ CircleDeg1Lift.tendsto_translation_number₀ /-- For any `x : ℝ` the sequence $\frac{f^n(x)-x}{n}$ tends to the translation number of `f`. In particular, this limit does not depend on `x`. -/ theorem tendsto_translationNumber (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ n) x - x) / n) atTop (𝓝 <| τ f) := by rw [← translationNumber_conj_eq' (translate <| Multiplicative.ofAdd x)] refine (tendsto_translation_number₀ _).congr fun n ↦ ?_ simp [sub_eq_neg_add, Units.conj_pow'] #align circle_deg1_lift.tendsto_translation_number CircleDeg1Lift.tendsto_translationNumber theorem tendsto_translation_number' (x : ℝ) : Tendsto (fun n : ℕ => ((f ^ (n + 1) : CircleDeg1Lift) x - x) / (n + 1)) atTop (𝓝 <| τ f) := mod_cast (tendsto_add_atTop_iff_nat 1).2 (f.tendsto_translationNumber x) #align circle_deg1_lift.tendsto_translation_number' CircleDeg1Lift.tendsto_translation_number' theorem translationNumber_mono : Monotone τ := fun f g h => le_of_tendsto_of_tendsto' f.tendsto_translation_number₀ g.tendsto_translation_number₀ fun n => by gcongr; exact pow_mono h _ _ #align circle_deg1_lift.translation_number_mono CircleDeg1Lift.translationNumber_mono theorem translationNumber_translate (x : ℝ) : τ (translate <| Multiplicative.ofAdd x) = x := translationNumber_eq_of_tendsto₀' _ <| by simp only [translate_iterate, translate_apply, add_zero, Nat.cast_succ, mul_div_cancel_left₀ (M₀ := ℝ) _ (Nat.cast_add_one_ne_zero _), tendsto_const_nhds] #align circle_deg1_lift.translation_number_translate CircleDeg1Lift.translationNumber_translate theorem translationNumber_le_of_le_add {z : ℝ} (hz : ∀ x, f x ≤ x + z) : τ f ≤ z := translationNumber_translate z ▸ translationNumber_mono fun x => (hz x).trans_eq (add_comm _ _) #align circle_deg1_lift.translation_number_le_of_le_add CircleDeg1Lift.translationNumber_le_of_le_add theorem le_translationNumber_of_add_le {z : ℝ} (hz : ∀ x, x + z ≤ f x) : z ≤ τ f := translationNumber_translate z ▸ translationNumber_mono fun x => (add_comm _ _).trans_le (hz x) #align circle_deg1_lift.le_translation_number_of_add_le CircleDeg1Lift.le_translationNumber_of_add_le theorem translationNumber_le_of_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) : τ f ≤ m := le_of_tendsto' (f.tendsto_translation_number' x) fun n => (div_le_iff' (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| sub_le_iff_le_add'.2 <| (coe_pow f (n + 1)).symm ▸ @Nat.cast_add_one ℝ _ n ▸ f.iterate_le_of_map_le_add_int h (n + 1) #align circle_deg1_lift.translation_number_le_of_le_add_int CircleDeg1Lift.translationNumber_le_of_le_add_int theorem translationNumber_le_of_le_add_nat {x : ℝ} {m : ℕ} (h : f x ≤ x + m) : τ f ≤ m := @translationNumber_le_of_le_add_int f x m h #align circle_deg1_lift.translation_number_le_of_le_add_nat CircleDeg1Lift.translationNumber_le_of_le_add_nat theorem le_translationNumber_of_add_int_le {x : ℝ} {m : ℤ} (h : x + m ≤ f x) : ↑m ≤ τ f := ge_of_tendsto' (f.tendsto_translation_number' x) fun n => (le_div_iff (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| le_sub_iff_add_le'.2 <| by simp only [coe_pow, mul_comm (m : ℝ), ← Nat.cast_add_one, f.le_iterate_of_add_int_le_map h] #align circle_deg1_lift.le_translation_number_of_add_int_le CircleDeg1Lift.le_translationNumber_of_add_int_le theorem le_translationNumber_of_add_nat_le {x : ℝ} {m : ℕ} (h : x + m ≤ f x) : ↑m ≤ τ f := @le_translationNumber_of_add_int_le f x m h #align circle_deg1_lift.le_translation_number_of_add_nat_le CircleDeg1Lift.le_translationNumber_of_add_nat_le /-- If `f x - x` is an integer number `m` for some point `x`, then `τ f = m`. On the circle this means that a map with a fixed point has rotation number zero. -/ theorem translationNumber_of_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) : τ f = m := le_antisymm (translationNumber_le_of_le_add_int f <| le_of_eq h) (le_translationNumber_of_add_int_le f <| le_of_eq h.symm) #align circle_deg1_lift.translation_number_of_eq_add_int CircleDeg1Lift.translationNumber_of_eq_add_int theorem floor_sub_le_translationNumber (x : ℝ) : ↑⌊f x - x⌋ ≤ τ f := le_translationNumber_of_add_int_le f <| le_sub_iff_add_le'.1 (floor_le <| f x - x) #align circle_deg1_lift.floor_sub_le_translation_number CircleDeg1Lift.floor_sub_le_translationNumber theorem translationNumber_le_ceil_sub (x : ℝ) : τ f ≤ ⌈f x - x⌉ := translationNumber_le_of_le_add_int f <| sub_le_iff_le_add'.1 (le_ceil <| f x - x) #align circle_deg1_lift.translation_number_le_ceil_sub CircleDeg1Lift.translationNumber_le_ceil_sub theorem map_lt_of_translationNumber_lt_int {n : ℤ} (h : τ f < n) (x : ℝ) : f x < x + n := not_le.1 <| mt f.le_translationNumber_of_add_int_le <| not_le.2 h #align circle_deg1_lift.map_lt_of_translation_number_lt_int CircleDeg1Lift.map_lt_of_translationNumber_lt_int theorem map_lt_of_translationNumber_lt_nat {n : ℕ} (h : τ f < n) (x : ℝ) : f x < x + n := @map_lt_of_translationNumber_lt_int f n h x #align circle_deg1_lift.map_lt_of_translation_number_lt_nat CircleDeg1Lift.map_lt_of_translationNumber_lt_nat theorem map_lt_add_floor_translationNumber_add_one (x : ℝ) : f x < x + ⌊τ f⌋ + 1 := by rw [add_assoc] norm_cast refine map_lt_of_translationNumber_lt_int _ ?_ _ push_cast exact lt_floor_add_one _ #align circle_deg1_lift.map_lt_add_floor_translation_number_add_one CircleDeg1Lift.map_lt_add_floor_translationNumber_add_one
Mathlib/Dynamics/Circle/RotationNumber/TranslationNumber.lean
875
878
theorem map_lt_add_translationNumber_add_one (x : ℝ) : f x < x + τ f + 1 := calc f x < x + ⌊τ f⌋ + 1 := f.map_lt_add_floor_translationNumber_add_one x _ ≤ x + τ f + 1 := by
gcongr; apply floor_le
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Yaël Dillies -/ import Mathlib.MeasureTheory.Integral.SetIntegral #align_import measure_theory.integral.average from "leanprover-community/mathlib"@"c14c8fcde993801fca8946b0d80131a1a81d1520" /-! # Integral average of a function In this file we define `MeasureTheory.average μ f` (notation: `⨍ x, f x ∂μ`) to be the average value of `f` with respect to measure `μ`. It is defined as `∫ x, f x ∂((μ univ)⁻¹ • μ)`, so it is equal to zero if `f` is not integrable or if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, we use `⨍ x in s, f x ∂μ` (notation for `⨍ x, f x ∂(μ.restrict s)`). For average w.r.t. the volume, one can omit `∂volume`. Both have a version for the Lebesgue integral rather than Bochner. We prove several version of the first moment method: An integrable function is below/above its average on a set of positive measure. ## Implementation notes The average is defined as an integral over `(μ univ)⁻¹ • μ` so that all theorems about Bochner integrals work for the average without modifications. For theorems that require integrability of a function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`. ## TODO Provide the first moment method for the Lebesgue integral as well. A draft is available on branch `first_moment_lintegral` in mathlib3 repository. ## Tags integral, center mass, average value -/ open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {α E F : Type*} {m0 : MeasurableSpace α} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {μ ν : Measure α} {s t : Set α} /-! ### Average value of a function w.r.t. a measure The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `μ` (notation: `⨍ x, f x ∂μ`, `⨍⁻ x, f x ∂μ`) is defined as the (Bochner, Lebesgue) integral divided by the total measure, so it is equal to zero if `μ` is an infinite measure, and (typically) equal to infinity if `f` is not integrable. If `μ` is a probability measure, then the average of any function is equal to its integral. -/ namespace MeasureTheory section ENNReal variable (μ) {f g : α → ℝ≥0∞} /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`, denoted `⨍⁻ x, f x ∂μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ noncomputable def laverage (f : α → ℝ≥0∞) := ∫⁻ x, f x ∂(μ univ)⁻¹ • μ #align measure_theory.laverage MeasureTheory.laverage /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ`. It is equal to `(μ univ)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `μ` is an infinite measure. If `μ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x ∂μ`, defined as `⨍⁻ x, f x ∂(μ.restrict s)`. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" ∂"μ:70 => laverage μ r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure. It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x ∂(volume.restrict s)`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. a measure `μ` on a set `s`. It is equal to `(μ s)⁻¹ * ∫⁻ x, f x ∂μ`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `∂volume`. -/ notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" ∂"μ:70 => laverage (Measure.restrict μ s) r /-- Average value of an `ℝ≥0∞`-valued function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 (prettyPrint := false) "⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r @[simp] theorem laverage_zero : ⨍⁻ _x, (0 : ℝ≥0∞) ∂μ = 0 := by rw [laverage, lintegral_zero] #align measure_theory.laverage_zero MeasureTheory.laverage_zero @[simp] theorem laverage_zero_measure (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂(0 : Measure α) = 0 := by simp [laverage] #align measure_theory.laverage_zero_measure MeasureTheory.laverage_zero_measure theorem laverage_eq' (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂(μ univ)⁻¹ • μ := rfl #align measure_theory.laverage_eq' MeasureTheory.laverage_eq' theorem laverage_eq (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = (∫⁻ x, f x ∂μ) / μ univ := by rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul] #align measure_theory.laverage_eq MeasureTheory.laverage_eq theorem laverage_eq_lintegral [IsProbabilityMeasure μ] (f : α → ℝ≥0∞) : ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rw [laverage, measure_univ, inv_one, one_smul] #align measure_theory.laverage_eq_lintegral MeasureTheory.laverage_eq_lintegral @[simp] theorem measure_mul_laverage [IsFiniteMeasure μ] (f : α → ℝ≥0∞) : μ univ * ⨍⁻ x, f x ∂μ = ∫⁻ x, f x ∂μ := by rcases eq_or_ne μ 0 with hμ | hμ · rw [hμ, lintegral_zero_measure, laverage_zero_measure, mul_zero] · rw [laverage_eq, ENNReal.mul_div_cancel' (measure_univ_ne_zero.2 hμ) (measure_ne_top _ _)] #align measure_theory.measure_mul_laverage MeasureTheory.measure_mul_laverage theorem setLaverage_eq (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = (∫⁻ x in s, f x ∂μ) / μ s := by rw [laverage_eq, restrict_apply_univ] #align measure_theory.set_laverage_eq MeasureTheory.setLaverage_eq theorem setLaverage_eq' (f : α → ℝ≥0∞) (s : Set α) : ⨍⁻ x in s, f x ∂μ = ∫⁻ x, f x ∂(μ s)⁻¹ • μ.restrict s := by simp only [laverage_eq', restrict_apply_univ] #align measure_theory.set_laverage_eq' MeasureTheory.setLaverage_eq' variable {μ} theorem laverage_congr {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : ⨍⁻ x, f x ∂μ = ⨍⁻ x, g x ∂μ := by simp only [laverage_eq, lintegral_congr_ae h] #align measure_theory.laverage_congr MeasureTheory.laverage_congr theorem setLaverage_congr (h : s =ᵐ[μ] t) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in t, f x ∂μ := by simp only [setLaverage_eq, set_lintegral_congr h, measure_congr h] #align measure_theory.set_laverage_congr MeasureTheory.setLaverage_congr theorem setLaverage_congr_fun (hs : MeasurableSet s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) : ⨍⁻ x in s, f x ∂μ = ⨍⁻ x in s, g x ∂μ := by simp only [laverage_eq, set_lintegral_congr_fun hs h] #align measure_theory.set_laverage_congr_fun MeasureTheory.setLaverage_congr_fun theorem laverage_lt_top (hf : ∫⁻ x, f x ∂μ ≠ ∞) : ⨍⁻ x, f x ∂μ < ∞ := by obtain rfl | hμ := eq_or_ne μ 0 · simp · rw [laverage_eq] exact div_lt_top hf (measure_univ_ne_zero.2 hμ) #align measure_theory.laverage_lt_top MeasureTheory.laverage_lt_top theorem setLaverage_lt_top : ∫⁻ x in s, f x ∂μ ≠ ∞ → ⨍⁻ x in s, f x ∂μ < ∞ := laverage_lt_top #align measure_theory.set_laverage_lt_top MeasureTheory.setLaverage_lt_top theorem laverage_add_measure : ⨍⁻ x, f x ∂(μ + ν) = μ univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂μ + ν univ / (μ univ + ν univ) * ⨍⁻ x, f x ∂ν := by by_cases hμ : IsFiniteMeasure μ; swap · rw [not_isFiniteMeasure_iff] at hμ simp [laverage_eq, hμ] by_cases hν : IsFiniteMeasure ν; swap · rw [not_isFiniteMeasure_iff] at hν simp [laverage_eq, hν] haveI := hμ; haveI := hν simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div, ← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq] #align measure_theory.laverage_add_measure MeasureTheory.laverage_add_measure theorem measure_mul_setLaverage (f : α → ℝ≥0∞) (h : μ s ≠ ∞) : μ s * ⨍⁻ x in s, f x ∂μ = ∫⁻ x in s, f x ∂μ := by have := Fact.mk h.lt_top rw [← measure_mul_laverage, restrict_apply_univ] #align measure_theory.measure_mul_set_laverage MeasureTheory.measure_mul_setLaverage theorem laverage_union (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : ⨍⁻ x in s ∪ t, f x ∂μ = μ s / (μ s + μ t) * ⨍⁻ x in s, f x ∂μ + μ t / (μ s + μ t) * ⨍⁻ x in t, f x ∂μ := by rw [restrict_union₀ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ] #align measure_theory.laverage_union MeasureTheory.laverage_union theorem laverage_union_mem_openSegment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hs₀ : μ s ≠ 0) (ht₀ : μ t ≠ 0) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) : ⨍⁻ x in s ∪ t, f x ∂μ ∈ openSegment ℝ≥0∞ (⨍⁻ x in s, f x ∂μ) (⨍⁻ x in t, f x ∂μ) := by refine ⟨μ s / (μ s + μ t), μ t / (μ s + μ t), ENNReal.div_pos hs₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ENNReal.div_pos ht₀ <| add_ne_top.2 ⟨hsμ, htμ⟩, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)] #align measure_theory.laverage_union_mem_open_segment MeasureTheory.laverage_union_mem_openSegment
Mathlib/MeasureTheory/Integral/Average.lean
205
215
theorem laverage_union_mem_segment (hd : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) (hsμ : μ s ≠ ∞) (htμ : μ t ≠ ∞) : ⨍⁻ x in s ∪ t, f x ∂μ ∈ [⨍⁻ x in s, f x ∂μ -[ℝ≥0∞] ⨍⁻ x in t, f x ∂μ] := by
by_cases hs₀ : μ s = 0 · rw [← ae_eq_empty] at hs₀ rw [restrict_congr_set (hs₀.union EventuallyEq.rfl), empty_union] exact right_mem_segment _ _ _ · refine ⟨μ s / (μ s + μ t), μ t / (μ s + μ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hs₀ h.1) (add_ne_top.2 ⟨hsμ, htμ⟩)]
/- Copyright (c) 2023 Antoine Chambert-Loir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Chambert-Loir -/ import Mathlib.Algebra.Exact import Mathlib.RingTheory.TensorProduct.Basic /-! # Right-exactness properties of tensor product ## Modules * `LinearMap.rTensor_surjective` asserts that when one tensors a surjective map on the right, one still gets a surjective linear map. More generally, `LinearMap.rTensor_range` computes the range of `LinearMap.rTensor` * `LinearMap.lTensor_surjective` asserts that when one tensors a surjective map on the left, one still gets a surjective linear map. More generally, `LinearMap.lTensor_range` computes the range of `LinearMap.lTensor` * `TensorProduct.rTensor_exact` says that when one tensors a short exact sequence on the right, one still gets a short exact sequence (right-exactness of `TensorProduct.rTensor`), and `rTensor.equiv` gives the LinearEquiv that follows from this combined with `LinearMap.rTensor_surjective`. * `TensorProduct.lTensor_exact` says that when one tensors a short exact sequence on the left, one still gets a short exact sequence (right-exactness of `TensorProduct.rTensor`) and `lTensor.equiv` gives the LinearEquiv that follows from this combined with `LinearMap.lTensor_surjective`. * For `N : Submodule R M`, `LinearMap.exact_subtype_mkQ N` says that the inclusion of the submodule and the quotient map form an exact pair, and `lTensor_mkQ` compute `ker (lTensor Q (N.mkQ))` and similarly for `rTensor_mkQ` * `TensorProduct.map_ker` computes the kernel of `TensorProduct.map f g'` in the presence of two short exact sequences. The proofs are those of [bourbaki1989] (chap. 2, §3, n°6) ## Algebras In the case of a tensor product of algebras, these results can be particularized to compute some kernels. * `Algebra.TensorProduct.ker_map` computes the kernel of `Algebra.TensorProduct.map f g` * `Algebra.TensorProduct.lTensor_ker` and `Algebra.TensorProduct.rTensor_ker` compute the kernels of `Algebra.TensorProduct.map f id` and `Algebra.TensorProduct.map id g` ## Note on implementation * All kernels are computed by applying the first isomorphism theorem and establishing some isomorphisms. * The proofs are essentially done twice, once for `lTensor` and then for `rTensor`. It is possible to apply `TensorProduct.flip` to deduce one of them from the other. However, this approach will lead to different isomorphisms, and it is not quicker. * The proofs of `Ideal.map_includeLeft_eq` and `Ideal.map_includeRight_eq` could be easier if `I ⊗[R] B` was naturally an `A ⊗[R] B` module, and the map to `A ⊗[R] B` was known to be linear. This depends on the B-module structure on a tensor product whose use rapidly conflicts with everything… ## TODO * Treat the noncommutative case * Treat the case of modules over semirings (For a possible definition of an exact sequence of commutative semigroups, see [Grillet-1969b], Pierre-Antoine Grillet, *The tensor product of commutative semigroups*, Trans. Amer. Math. Soc. 138 (1969), 281-293, doi:10.1090/S0002-9947-1969-0237688-1 .) -/ section Modules open TensorProduct LinearMap section Semiring variable {R : Type*} [CommSemiring R] {M N P Q: Type*} [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] [Module R M] [Module R N] [Module R P] [Module R Q] {f : M →ₗ[R] N} (g : N →ₗ[R] P) lemma le_comap_range_lTensor (q : Q) : LinearMap.range g ≤ (LinearMap.range (lTensor Q g)).comap (TensorProduct.mk R Q P q) := by rintro x ⟨n, rfl⟩ exact ⟨q ⊗ₜ[R] n, rfl⟩ lemma le_comap_range_rTensor (q : Q) : LinearMap.range g ≤ (LinearMap.range (rTensor Q g)).comap ((TensorProduct.mk R P Q).flip q) := by rintro x ⟨n, rfl⟩ exact ⟨n ⊗ₜ[R] q, rfl⟩ variable (Q) {g} /-- If `g` is surjective, then `lTensor Q g` is surjective -/
Mathlib/LinearAlgebra/TensorProduct/RightExactness.lean
111
122
theorem LinearMap.lTensor_surjective (hg : Function.Surjective g) : Function.Surjective (lTensor Q g) := by
intro z induction z using TensorProduct.induction_on with | zero => exact ⟨0, map_zero _⟩ | tmul q p => obtain ⟨n, rfl⟩ := hg p exact ⟨q ⊗ₜ[R] n, rfl⟩ | add x y hx hy => obtain ⟨x, rfl⟩ := hx obtain ⟨y, rfl⟩ := hy exact ⟨x + y, map_add _ _ _⟩
/- Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Game.Ordinal import Mathlib.SetTheory.Ordinal.NaturalOps #align_import set_theory.game.birthday from "leanprover-community/mathlib"@"a347076985674932c0e91da09b9961ed0a79508c" /-! # Birthdays of games The birthday of a game is an ordinal that represents at which "step" the game was constructed. We define it recursively as the least ordinal larger than the birthdays of its left and right games. We prove the basic properties about these. # Main declarations - `SetTheory.PGame.birthday`: The birthday of a pre-game. # Todo - Define the birthdays of `SetTheory.Game`s and `Surreal`s. - Characterize the birthdays of basic arithmetical operations. -/ universe u open Ordinal namespace SetTheory open scoped NaturalOps PGame namespace PGame /-- The birthday of a pre-game is inductively defined as the least strict upper bound of the birthdays of its left and right games. It may be thought as the "step" in which a certain game is constructed. -/ noncomputable def birthday : PGame.{u} → Ordinal.{u} | ⟨_, _, xL, xR⟩ => max (lsub.{u, u} fun i => birthday (xL i)) (lsub.{u, u} fun i => birthday (xR i)) #align pgame.birthday SetTheory.PGame.birthday theorem birthday_def (x : PGame) : birthday x = max (lsub.{u, u} fun i => birthday (x.moveLeft i)) (lsub.{u, u} fun i => birthday (x.moveRight i)) := by cases x; rw [birthday]; rfl #align pgame.birthday_def SetTheory.PGame.birthday_def theorem birthday_moveLeft_lt {x : PGame} (i : x.LeftMoves) : (x.moveLeft i).birthday < x.birthday := by cases x; rw [birthday]; exact lt_max_of_lt_left (lt_lsub _ i) #align pgame.birthday_move_left_lt SetTheory.PGame.birthday_moveLeft_lt theorem birthday_moveRight_lt {x : PGame} (i : x.RightMoves) : (x.moveRight i).birthday < x.birthday := by cases x; rw [birthday]; exact lt_max_of_lt_right (lt_lsub _ i) #align pgame.birthday_move_right_lt SetTheory.PGame.birthday_moveRight_lt theorem lt_birthday_iff {x : PGame} {o : Ordinal} : o < x.birthday ↔ (∃ i : x.LeftMoves, o ≤ (x.moveLeft i).birthday) ∨ ∃ i : x.RightMoves, o ≤ (x.moveRight i).birthday := by constructor · rw [birthday_def] intro h cases' lt_max_iff.1 h with h' h' · left rwa [lt_lsub_iff] at h' · right rwa [lt_lsub_iff] at h' · rintro (⟨i, hi⟩ | ⟨i, hi⟩) · exact hi.trans_lt (birthday_moveLeft_lt i) · exact hi.trans_lt (birthday_moveRight_lt i) #align pgame.lt_birthday_iff SetTheory.PGame.lt_birthday_iff theorem Relabelling.birthday_congr : ∀ {x y : PGame.{u}}, x ≡r y → birthday x = birthday y | ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, r => by unfold birthday congr 1 all_goals apply lsub_eq_of_range_eq.{u, u, u} ext i; constructor all_goals rintro ⟨j, rfl⟩ · exact ⟨_, (r.moveLeft j).birthday_congr.symm⟩ · exact ⟨_, (r.moveLeftSymm j).birthday_congr⟩ · exact ⟨_, (r.moveRight j).birthday_congr.symm⟩ · exact ⟨_, (r.moveRightSymm j).birthday_congr⟩ termination_by x y => (x, y) #align pgame.relabelling.birthday_congr SetTheory.PGame.Relabelling.birthday_congr @[simp] theorem birthday_eq_zero {x : PGame} : birthday x = 0 ↔ IsEmpty x.LeftMoves ∧ IsEmpty x.RightMoves := by rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff] #align pgame.birthday_eq_zero SetTheory.PGame.birthday_eq_zero @[simp] theorem birthday_zero : birthday 0 = 0 := by simp [inferInstanceAs (IsEmpty PEmpty)] #align pgame.birthday_zero SetTheory.PGame.birthday_zero @[simp]
Mathlib/SetTheory/Game/Birthday.lean
107
107
theorem birthday_one : birthday 1 = 1 := by
rw [birthday_def]; simp