Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2019 Minchao Wu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Minchao Wu, Mario Carneiro -/ import Mathlib.Computability.Halting /-! # Strong reducibility and degrees. This file defines the notions of computable many-one reduction and one-one reduction between sets, and shows that the corresponding degrees form a semilattice. ## Notations This file uses the local notation `⊕'` for `Sum.elim` to denote the disjoint union of two degrees. ## References * [Robert Soare, *Recursively enumerable sets and degrees*][soare1987] ## Tags computability, reducibility, reduction -/ universe u v w open Function /-- `p` is many-one reducible to `q` if there is a computable function translating questions about `p` to questions about `q`. -/ def ManyOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc ManyOneReducible] infixl:1000 " ≤₀ " => ManyOneReducible theorem ManyOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) : (fun a => q (f a)) ≤₀ q := ⟨f, h, fun _ => Iff.rfl⟩ @[refl] theorem manyOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₀ p := ⟨id, Computable.id, by simp⟩ @[trans] theorem ManyOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ q → q ≤₀ r → p ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ theorem reflexive_manyOneReducible {α} [Primcodable α] : Reflexive (@ManyOneReducible α α _ _) := manyOneReducible_refl theorem transitive_manyOneReducible {α} [Primcodable α] : Transitive (@ManyOneReducible α α _ _) := fun _ _ _ => ManyOneReducible.trans /-- `p` is one-one reducible to `q` if there is an injective computable function translating questions about `p` to questions about `q`. -/ def OneOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ Injective f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc OneOneReducible] infixl:1000 " ≤₁ " => OneOneReducible theorem OneOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) (i : Injective f) : (fun a => q (f a)) ≤₁ q := ⟨f, h, i, fun _ => Iff.rfl⟩ @[refl] theorem oneOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₁ p := ⟨id, Computable.id, injective_id, by simp⟩ @[trans] theorem OneOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₁ q → q ≤₁ r → p ≤₁ r | ⟨f, c₁, i₁, h₁⟩, ⟨g, c₂, i₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, i₂.comp i₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩ theorem OneOneReducible.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ q → p ≤₀ q | ⟨f, c, _, h⟩ => ⟨f, c, h⟩ theorem OneOneReducible.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e) : (q ∘ e) ≤₁ q := OneOneReducible.mk _ h e.injective theorem OneOneReducible.of_equiv_symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e.symm) : q ≤₁ (q ∘ e) := by convert OneOneReducible.of_equiv _ h; funext; simp theorem reflexive_oneOneReducible {α} [Primcodable α] : Reflexive (@OneOneReducible α α _ _) := oneOneReducible_refl theorem transitive_oneOneReducible {α} [Primcodable α] : Transitive (@OneOneReducible α α _ _) := fun _ _ _ => OneOneReducible.trans namespace ComputablePred variable {α : Type*} {β : Type*} [Primcodable α] [Primcodable β] open Computable theorem computable_of_manyOneReducible {p : α → Prop} {q : β → Prop} (h₁ : p ≤₀ q) (h₂ : ComputablePred q) : ComputablePred p := by rcases h₁ with ⟨f, c, hf⟩ rw [show p = fun a => q (f a) from Set.ext hf] rcases computable_iff.1 h₂ with ⟨g, hg, rfl⟩ exact ⟨by infer_instance, by simpa using hg.comp c⟩ theorem computable_of_oneOneReducible {p : α → Prop} {q : β → Prop} (h : p ≤₁ q) : ComputablePred q → ComputablePred p := computable_of_manyOneReducible h.to_many_one end ComputablePred /-- `p` and `q` are many-one equivalent if each one is many-one reducible to the other. -/ def ManyOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₀ q ∧ q ≤₀ p /-- `p` and `q` are one-one equivalent if each one is one-one reducible to the other. -/ def OneOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₁ q ∧ q ≤₁ p @[refl] theorem manyOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : ManyOneEquiv p p := ⟨manyOneReducible_refl _, manyOneReducible_refl _⟩ @[symm] theorem ManyOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : ManyOneEquiv p q → ManyOneEquiv q p := And.symm @[trans] theorem ManyOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : ManyOneEquiv p q → ManyOneEquiv q r → ManyOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ theorem equivalence_of_manyOneEquiv {α} [Primcodable α] : Equivalence (@ManyOneEquiv α α _ _) := ⟨manyOneEquiv_refl, fun {_ _} => ManyOneEquiv.symm, fun {_ _ _} => ManyOneEquiv.trans⟩ @[refl] theorem oneOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : OneOneEquiv p p := ⟨oneOneReducible_refl _, oneOneReducible_refl _⟩ @[symm] theorem OneOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → OneOneEquiv q p := And.symm @[trans] theorem OneOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : OneOneEquiv p q → OneOneEquiv q r → OneOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩ theorem equivalence_of_oneOneEquiv {α} [Primcodable α] : Equivalence (@OneOneEquiv α α _ _) := ⟨oneOneEquiv_refl, fun {_ _} => OneOneEquiv.symm, fun {_ _ _} => OneOneEquiv.trans⟩ theorem OneOneEquiv.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : OneOneEquiv p q → ManyOneEquiv p q | ⟨pq, qp⟩ => ⟨pq.to_many_one, qp.to_many_one⟩ /-- a computable bijection -/ nonrec def Equiv.Computable {α β} [Primcodable α] [Primcodable β] (e : α ≃ β) := Computable e ∧ Computable e.symm theorem Equiv.Computable.symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} : e.Computable → e.symm.Computable := And.symm theorem Equiv.Computable.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {e₁ : α ≃ β} {e₂ : β ≃ γ} : e₁.Computable → e₂.Computable → (e₁.trans e₂).Computable | ⟨l₁, r₁⟩, ⟨l₂, r₂⟩ => ⟨l₂.comp l₁, r₁.comp r₂⟩ theorem Computable.eqv (α) [Denumerable α] : (Denumerable.eqv α).Computable := ⟨Computable.encode, Computable.ofNat _⟩ theorem Computable.equiv₂ (α β) [Denumerable α] [Denumerable β] : (Denumerable.equiv₂ α β).Computable := (Computable.eqv _).trans (Computable.eqv _).symm theorem OneOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : OneOneEquiv (p ∘ e) p := ⟨OneOneReducible.of_equiv _ h.1, OneOneReducible.of_equiv_symm _ h.2⟩ theorem ManyOneEquiv.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (h : e.Computable) {p} : ManyOneEquiv (p ∘ e) p := (OneOneEquiv.of_equiv h).to_many_one theorem ManyOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : p ≤₀ r ↔ q ≤₀ r := ⟨h.2.trans, h.1.trans⟩ theorem ManyOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : p ≤₀ q ↔ p ≤₀ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ theorem OneOneEquiv.le_congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : p ≤₁ r ↔ q ≤₁ r := ⟨h.2.trans, h.1.trans⟩ theorem OneOneEquiv.le_congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : p ≤₁ q ↔ p ≤₁ r := ⟨fun h' => h'.trans h.1, fun h' => h'.trans h.2⟩ theorem ManyOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv p q) : ManyOneEquiv p r ↔ ManyOneEquiv q r := and_congr h.le_congr_left h.le_congr_right theorem ManyOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : ManyOneEquiv q r) : ManyOneEquiv p q ↔ ManyOneEquiv p r := and_congr h.le_congr_right h.le_congr_left theorem OneOneEquiv.congr_left {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv p q) : OneOneEquiv p r ↔ OneOneEquiv q r := and_congr h.le_congr_left h.le_congr_right theorem OneOneEquiv.congr_right {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} (h : OneOneEquiv q r) : OneOneEquiv p q ↔ OneOneEquiv p r := and_congr h.le_congr_right h.le_congr_left @[simp] theorem ULower.down_computable {α} [Primcodable α] : (ULower.equiv α).Computable := ⟨Primrec.ulower_down.to_comp, Primrec.ulower_up.to_comp⟩ theorem manyOneEquiv_up {α} [Primcodable α] {p : α → Prop} : ManyOneEquiv (p ∘ ULower.up) p := ManyOneEquiv.of_equiv ULower.down_computable.symm local infixl:1001 " ⊕' " => Sum.elim open Nat.Primrec theorem OneOneReducible.disjoin_left {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ p ⊕' q := ⟨Sum.inl, Computable.sumInl, fun _ _ => Sum.inl.inj_iff.1, fun _ => Iff.rfl⟩ theorem OneOneReducible.disjoin_right {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : q ≤₁ p ⊕' q := ⟨Sum.inr, Computable.sumInr, fun _ _ => Sum.inr.inj_iff.1, fun _ => Iff.rfl⟩ theorem disjoin_manyOneReducible {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ r → q ≤₀ r → (p ⊕' q) ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨Sum.elim f g, Computable.id.sumCasesOn (c₁.comp Computable.snd).to₂ (c₂.comp Computable.snd).to₂, fun x => by cases x <;> [apply h₁; apply h₂]⟩ theorem disjoin_le {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : (p ⊕' q) ≤₀ r ↔ p ≤₀ r ∧ q ≤₀ r := ⟨fun h => ⟨OneOneReducible.disjoin_left.to_many_one.trans h, OneOneReducible.disjoin_right.to_many_one.trans h⟩, fun ⟨h₁, h₂⟩ => disjoin_manyOneReducible h₁ h₂⟩ variable {α : Type u} [Primcodable α] [Inhabited α] {β : Type v} [Primcodable β] [Inhabited β] /-- Computable and injective mapping of predicates to sets of natural numbers. -/ def toNat (p : Set α) : Set ℕ := { n | p ((Encodable.decode (α := α) n).getD default) } @[simp] theorem toNat_manyOneReducible {p : Set α} : toNat p ≤₀ p := ⟨fun n => (Encodable.decode (α := α) n).getD default, Computable.option_getD Computable.decode (Computable.const _), fun _ => Iff.rfl⟩ @[simp] theorem manyOneReducible_toNat {p : Set α} : p ≤₀ toNat p := ⟨Encodable.encode, Computable.encode, by simp [toNat, setOf]⟩ @[simp] theorem manyOneReducible_toNat_toNat {p : Set α} {q : Set β} : toNat p ≤₀ toNat q ↔ p ≤₀ q := ⟨fun h => manyOneReducible_toNat.trans (h.trans toNat_manyOneReducible), fun h => toNat_manyOneReducible.trans (h.trans manyOneReducible_toNat)⟩ @[simp] theorem toNat_manyOneEquiv {p : Set α} : ManyOneEquiv (toNat p) p := by simp [ManyOneEquiv] @[simp] theorem manyOneEquiv_toNat (p : Set α) (q : Set β) : ManyOneEquiv (toNat p) (toNat q) ↔ ManyOneEquiv p q := by simp [ManyOneEquiv] /-- A many-one degree is an equivalence class of sets up to many-one equivalence. -/ def ManyOneDegree : Type := Quotient (⟨ManyOneEquiv, equivalence_of_manyOneEquiv⟩ : Setoid (Set ℕ)) namespace ManyOneDegree /-- The many-one degree of a set on a primcodable type. -/ def of (p : α → Prop) : ManyOneDegree := Quotient.mk'' (toNat p) @[elab_as_elim] protected theorem ind_on {C : ManyOneDegree → Prop} (d : ManyOneDegree) (h : ∀ p : Set ℕ, C (of p)) : C d := Quotient.inductionOn' d h /-- Lifts a function on sets of natural numbers to many-one degrees. -/ protected abbrev liftOn {φ} (d : ManyOneDegree) (f : Set ℕ → φ) (h : ∀ p q, ManyOneEquiv p q → f p = f q) : φ := Quotient.liftOn' d f h @[simp] protected theorem liftOn_eq {φ} (p : Set ℕ) (f : Set ℕ → φ) (h : ∀ p q, ManyOneEquiv p q → f p = f q) : (of p).liftOn f h = f p := rfl /-- Lifts a binary function on sets of natural numbers to many-one degrees. -/ @[reducible, simp] protected def liftOn₂ {φ} (d₁ d₂ : ManyOneDegree) (f : Set ℕ → Set ℕ → φ) (h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) : φ := d₁.liftOn (fun p => d₂.liftOn (f p) fun _ _ hq => h _ _ _ _ (by rfl) hq) (by intro p₁ p₂ hp induction d₂ using ManyOneDegree.ind_on apply h · assumption · rfl) @[simp] protected theorem liftOn₂_eq {φ} (p q : Set ℕ) (f : Set ℕ → Set ℕ → φ) (h : ∀ p₁ p₂ q₁ q₂, ManyOneEquiv p₁ p₂ → ManyOneEquiv q₁ q₂ → f p₁ q₁ = f p₂ q₂) : (of p).liftOn₂ (of q) f h = f p q := rfl @[simp] theorem of_eq_of {p : α → Prop} {q : β → Prop} : of p = of q ↔ ManyOneEquiv p q := by rw [of, of, Quotient.eq''] simp instance instInhabited : Inhabited ManyOneDegree := ⟨of (∅ : Set ℕ)⟩ /-- For many-one degrees `d₁` and `d₂`, `d₁ ≤ d₂` if the sets in `d₁` are many-one reducible to the sets in `d₂`. -/ instance instLE : LE ManyOneDegree := ⟨fun d₁ d₂ =>
ManyOneDegree.liftOn₂ d₁ d₂ (· ≤₀ ·) fun _p₁ _p₂ _q₁ _q₂ hp hq => propext (hp.le_congr_left.trans hq.le_congr_right)⟩
Mathlib/Computability/Reduce.lean
352
353
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gamma.Deriv import Mathlib.Analysis.SpecialFunctions.Gaussian.GaussianIntegral /-! # Convexity properties of the Gamma function In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique* positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and `f 1 = 1`. The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler limit formula, `Real.BohrMollerup.tendsto_logGammaSeq`, stating that for positive real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) ∈ Finset.range (n + 1), log (x + m)` tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one such function; then we show that `Γ` satisfies these conditions. Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the context of this proof, we place them in a separate namespace `Real.BohrMollerup` to avoid clutter. (This includes the logarithmic form of the Euler limit formula, since later we will prove a more general form of the Euler limit formula valid for any real or complex `x`; see `Real.Gamma_seq_tendsto_Gamma` and `Complex.Gamma_seq_tendsto_Gamma` in the file `Mathlib/Analysis/SpecialFunctions/Gamma/Beta.lean`.) As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a later file). TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up to a constant, and it should be possible to deduce the value of this constant using Stirling's formula). -/ noncomputable section open Filter Set MeasureTheory open scoped Nat ENNReal Topology Real namespace Real section Convexity /-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form), proved using the Hölder inequality applied to Euler's integral. -/ theorem Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ} (hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b := by -- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a` -- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows: let f : ℝ → ℝ → ℝ → ℝ := fun c u x => exp (-c * x) * x ^ (c * (u - 1)) have e : HolderConjugate (1 / a) (1 / b) := Real.holderConjugate_one_div ha hb hab have hab' : b = 1 - a := by linarith have hst : 0 < a * s + b * t := by positivity -- some properties of f: have posf : ∀ c u x : ℝ, x ∈ Ioi (0 : ℝ) → 0 ≤ f c u x := fun c u x hx => mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le have posf' : ∀ c u : ℝ, ∀ᵐ x : ℝ ∂volume.restrict (Ioi 0), 0 ≤ f c u x := fun c u => (ae_restrict_iff' measurableSet_Ioi).mpr (ae_of_all _ (posf c u)) have fpow : ∀ {c x : ℝ} (_ : 0 < c) (u : ℝ) (_ : 0 < x), exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c) := by intro c x hc u hx dsimp only [f] rw [mul_rpow (exp_pos _).le ((rpow_nonneg hx.le) _), ← exp_mul, ← rpow_mul hx.le] congr 2 <;> field_simp [hc.ne']; ring -- show `f c u` is in `ℒp` for `p = 1/c`: have f_mem_Lp : ∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u), MemLp (f c u) (ENNReal.ofReal (1 / c)) (volume.restrict (Ioi 0)) := by intro c u hc hu have A : ENNReal.ofReal (1 / c) ≠ 0 := by rwa [Ne, ENNReal.ofReal_eq_zero, not_le, one_div_pos] have B : ENNReal.ofReal (1 / c) ≠ ∞ := ENNReal.ofReal_ne_top rw [← memLp_norm_rpow_iff _ A B, ENNReal.toReal_ofReal (one_div_nonneg.mpr hc.le), ENNReal.div_self A B, memLp_one_iff_integrable] · apply Integrable.congr (GammaIntegral_convergent hu) refine eventuallyEq_of_mem (self_mem_ae_restrict measurableSet_Ioi) fun x hx => ?_ dsimp only rw [fpow hc u hx] congr 1 exact (norm_of_nonneg (posf _ _ x hx)).symm · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_Ioi refine (Continuous.continuousOn ?_).mul (continuousOn_of_forall_continuousAt fun x hx => ?_) · exact continuous_exp.comp (continuous_const.mul continuous_id') · exact continuousAt_rpow_const _ _ (Or.inl (mem_Ioi.mp hx).ne') -- now apply Hölder: rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst] convert MeasureTheory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t) (f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1 · refine setIntegral_congr_fun measurableSet_Ioi fun x hx => ?_ dsimp only have A : exp (-x) = exp (-a * x) * exp (-b * x) := by rw [← exp_add, ← add_mul, ← neg_add, hab, neg_one_mul] have B : x ^ (a * s + b * t - 1) = x ^ (a * (s - 1)) * x ^ (b * (t - 1)) := by rw [← rpow_add hx, hab']; congr 1; ring rw [A, B] ring · rw [one_div_one_div, one_div_one_div] congr 2 <;> exact setIntegral_congr_fun measurableSet_Ioi fun x hx => fpow (by assumption) _ hx theorem convexOn_log_Gamma : ConvexOn ℝ (Ioi 0) (log ∘ Gamma) := by refine convexOn_iff_forall_pos.mpr ⟨convex_Ioi _, fun x hx y hy a b ha hb hab => ?_⟩ have : b = 1 - a := by linarith subst this simp_rw [Function.comp_apply, smul_eq_mul] simp only [mem_Ioi] at hx hy rw [← log_rpow, ← log_rpow, ← log_mul] · gcongr exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab all_goals positivity theorem convexOn_Gamma : ConvexOn ℝ (Ioi 0) Gamma := by refine ((convexOn_exp.subset (subset_univ _) ?_).comp convexOn_log_Gamma (exp_monotone.monotoneOn _)).congr fun x hx => exp_log (Gamma_pos_of_pos hx) rw [convex_iff_isPreconnected] refine isPreconnected_Ioi.image _ fun x hx => ContinuousAt.continuousWithinAt ?_ refine (differentiableAt_Gamma fun m => ?_).continuousAt.log (Gamma_pos_of_pos hx).ne' exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg (mem_Ioi.mp hx) (Nat.cast_nonneg m))).ne' end Convexity section BohrMollerup namespace BohrMollerup /-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to `log (Gamma x)` as `n → ∞`. -/ def logGammaSeq (x : ℝ) (n : ℕ) : ℝ := x * log n + log n ! - ∑ m ∈ Finset.range (n + 1), log (x + m) variable {f : ℝ → ℝ} {x : ℝ} {n : ℕ} theorem f_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) : f n = f 1 + log (n - 1)! := by refine Nat.le_induction (by simp) (fun m hm IH => ?_) n (Nat.one_le_iff_ne_zero.2 hn) have A : 0 < (m : ℝ) := Nat.cast_pos.2 hm simp only [hf_feq A, Nat.cast_add, Nat.cast_one, Nat.add_succ_sub_one, add_zero] rw [IH, add_assoc, ← log_mul (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) A.ne', ← Nat.cast_mul] conv_rhs => rw [← Nat.succ_pred_eq_of_pos hm, Nat.factorial_succ, mul_comm] congr exact (Nat.succ_pred_eq_of_pos hm).symm theorem f_add_nat_eq (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) : f (x + n) = f x + ∑ m ∈ Finset.range n, log (x + m) := by induction n with | zero => simp | succ n hn => have : x + n.succ = x + n + 1 := by push_cast; ring rw [this, hf_feq, hn] · rw [Finset.range_succ, Finset.sum_insert Finset.not_mem_range_self] abel · linarith [(Nat.cast_nonneg n : 0 ≤ (n : ℝ))] /-- Linear upper bound for `f (x + n)` on unit interval -/ theorem f_add_nat_le (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) : f (n + x) ≤ f n + x * log n := by have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) have : f n + x * log n = (1 - x) * f n + x * f (n + 1) := by rw [hf_feq hn']; ring rw [this, (by ring : (n : ℝ) + x = (1 - x) * n + x * (n + 1))] simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ)) (by linarith : 0 ≤ 1 - x) hx.le (by linarith) /-- Linear lower bound for `f (x + n)` on unit interval -/ theorem f_add_nat_ge (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : 2 ≤ n) (hx : 0 < x) : f n + x * log (n - 1) ≤ f (n + x) := by have npos : 0 < (n : ℝ) - 1 := by rw [← Nat.cast_one, sub_pos, Nat.cast_lt]; omega have c := (convexOn_iff_slope_mono_adjacent.mp <| hf_conv).2 npos (by linarith : 0 < (n : ℝ) + x) (by linarith : (n : ℝ) - 1 < (n : ℝ)) (by linarith) rw [add_sub_cancel_left, sub_sub_cancel, div_one] at c have : f (↑n - 1) = f n - log (↑n - 1) := by rw [eq_sub_iff_add_eq, ← hf_feq npos, sub_add_cancel] rwa [this, le_div_iff₀ hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c theorem logGammaSeq_add_one (x : ℝ) (n : ℕ) : logGammaSeq (x + 1) n = logGammaSeq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) := by dsimp only [Nat.factorial_succ, logGammaSeq] conv_rhs => rw [Finset.sum_range_succ', Nat.cast_zero, add_zero] rw [Nat.cast_mul, log_mul]; rotate_left · rw [Nat.cast_ne_zero]; exact Nat.succ_ne_zero n · rw [Nat.cast_ne_zero]; exact Nat.factorial_ne_zero n have : ∑ m ∈ Finset.range (n + 1), log (x + 1 + ↑m) = ∑ k ∈ Finset.range (n + 1), log (x + ↑(k + 1)) := by congr! 2 with m push_cast abel rw [← this, Nat.cast_add_one n] ring theorem le_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) : f x ≤ f 1 + x * log (n + 1) - x * log n + logGammaSeq x n := by rw [logGammaSeq, ← add_sub_assoc, le_sub_iff_add_le, ← f_add_nat_eq (@hf_feq) hx, add_comm x] refine (f_add_nat_le hf_conv (@hf_feq) (Nat.add_one_ne_zero n) hx hx').trans (le_of_eq ?_) rw [f_nat_eq @hf_feq (by omega : n + 1 ≠ 0), Nat.add_sub_cancel, Nat.cast_add_one] ring theorem ge_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hn : n ≠ 0) : f 1 + logGammaSeq x n ≤ f x := by dsimp [logGammaSeq] rw [← add_sub_assoc, sub_le_iff_le_add, ← f_add_nat_eq (@hf_feq) hx, add_comm x _] refine le_trans (le_of_eq ?_) (f_add_nat_ge hf_conv @hf_feq ?_ hx) · rw [f_nat_eq @hf_feq, Nat.add_sub_cancel, Nat.cast_add_one, add_sub_cancel_right] · ring · exact Nat.succ_ne_zero _ · omega theorem tendsto_logGammaSeq_of_le_one (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (hx' : x ≤ 1) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by refine tendsto_of_tendsto_of_tendsto_of_le_of_le' (f := logGammaSeq x) (g := fun n ↦ f x - f 1 - x * (log (n + 1) - log n)) ?_ tendsto_const_nhds ?_ ?_ · have : f x - f 1 = f x - f 1 - x * 0 := by ring nth_rw 2 [this] exact Tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _) · filter_upwards with n rw [sub_le_iff_le_add', sub_le_iff_le_add'] convert le_logGammaSeq hf_conv (@hf_feq) hx hx' n using 1 ring · show ∀ᶠ n : ℕ in atTop, logGammaSeq x n ≤ f x - f 1 filter_upwards [eventually_ne_atTop 0] with n hn using le_sub_iff_add_le'.mpr (ge_logGammaSeq hf_conv hf_feq hx hn) theorem tendsto_logGammaSeq (hf_conv : ConvexOn ℝ (Ioi 0) f) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) := by suffices ∀ m : ℕ, ↑m < x → x ≤ m + 1 → Tendsto (logGammaSeq x) atTop (𝓝 <| f x - f 1) by refine this ⌈x - 1⌉₊ ?_ ?_ · rcases lt_or_le x 1 with ⟨⟩ · rwa [Nat.ceil_eq_zero.mpr (by linarith : x - 1 ≤ 0), Nat.cast_zero] · convert Nat.ceil_lt_add_one (by linarith : 0 ≤ x - 1) abel · rw [← sub_le_iff_le_add]; exact Nat.le_ceil _ intro m induction' m with m hm generalizing x · rw [Nat.cast_zero, zero_add] exact fun _ hx' => tendsto_logGammaSeq_of_le_one hf_conv (@hf_feq) hx hx' · intro hy hy' rw [Nat.cast_succ, ← sub_le_iff_le_add] at hy' rw [Nat.cast_succ, ← lt_sub_iff_add_lt] at hy specialize hm ((Nat.cast_nonneg _).trans_lt hy) hy hy' -- now massage gauss_product n (x - 1) into gauss_product (n - 1) x have : ∀ᶠ n : ℕ in atTop, logGammaSeq (x - 1) n = logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1) := by refine Eventually.mp (eventually_ge_atTop 1) (Eventually.of_forall fun n hn => ?_) have := logGammaSeq_add_one (x - 1) (n - 1) rw [sub_add_cancel, Nat.sub_add_cancel hn] at this rw [this] ring replace hm := ((Tendsto.congr' this hm).add (tendsto_const_nhds : Tendsto (fun _ => log (x - 1)) _ _)).comp (tendsto_add_atTop_nat 1) have : ((fun x_1 : ℕ => (fun n : ℕ => logGammaSeq x (n - 1) + x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1)) x_1 + (fun b : ℕ => log (x - 1)) x_1) ∘ fun a : ℕ => a + 1) = fun n => logGammaSeq x n + x * (log (↑n + 1) - log ↑n) := by ext1 n dsimp only [Function.comp_apply] rw [sub_add_cancel, Nat.add_sub_cancel] rw [this] at hm convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2 · ring · have := hf_feq ((Nat.cast_nonneg m).trans_lt hy) rw [sub_add_cancel] at this rw [this] ring theorem tendsto_log_gamma {x : ℝ} (hx : 0 < x) : Tendsto (logGammaSeq x) atTop (𝓝 <| log (Gamma x)) := by have : log (Gamma x) = (log ∘ Gamma) x - (log ∘ Gamma) 1 := by simp_rw [Function.comp_apply, Gamma_one, log_one, sub_zero] rw [this] refine BohrMollerup.tendsto_logGammaSeq convexOn_log_Gamma (fun {y} hy => ?_) hx rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] end BohrMollerup -- (namespace) /-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued function on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/ theorem eq_Gamma_of_log_convex {f : ℝ → ℝ} (hf_conv : ConvexOn ℝ (Ioi 0) (log ∘ f)) (hf_feq : ∀ {y : ℝ}, 0 < y → f (y + 1) = y * f y) (hf_pos : ∀ {y : ℝ}, 0 < y → 0 < f y) (hf_one : f 1 = 1) : EqOn f Gamma (Ioi (0 : ℝ)) := by suffices EqOn (log ∘ f) (log ∘ Gamma) (Ioi (0 : ℝ)) from fun x hx ↦ log_injOn_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx) intro x hx have e1 := BohrMollerup.tendsto_logGammaSeq hf_conv ?_ hx · rw [Function.comp_apply (f := log) (g := f) (x := 1), hf_one, log_one, sub_zero] at e1 exact tendsto_nhds_unique e1 (BohrMollerup.tendsto_log_gamma hx) · intro y hy rw [Function.comp_apply, Function.comp_apply, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'] ring end BohrMollerup -- (section) section StrictMono theorem Gamma_two : Gamma 2 = 1 := by simp [Nat.factorial_one] theorem Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 := by -- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in -- `Mathlib/Analysis/SpecialFunctions/Gaussian.lean`, but we give a self-contained proof using -- log-convexity to avoid unnecessary imports. have A : (0 : ℝ) < 3 / 2 := by norm_num have := BohrMollerup.f_add_nat_le convexOn_log_Gamma (fun {y} hy => ?_) two_ne_zero one_half_pos (by norm_num : 1 / 2 ≤ (1 : ℝ)) swap · rw [Function.comp_apply, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm, Function.comp_apply] rw [Function.comp_apply, Function.comp_apply, Nat.cast_two, Gamma_two, log_one, zero_add, (by norm_num : (2 : ℝ) + 1 / 2 = 3 / 2 + 1), Gamma_add_one A.ne', log_mul A.ne' (Gamma_pos_of_pos A).ne', ← le_sub_iff_add_le', log_le_iff_le_exp (Gamma_pos_of_pos A)] at this refine this.trans_lt (exp_lt_one_iff.mpr ?_) rw [mul_comm, ← mul_div_assoc, div_sub' two_ne_zero] refine div_neg_of_neg_of_pos ?_ two_pos rw [sub_neg, mul_one, ← Nat.cast_two, ← log_pow, ← exp_lt_exp, Nat.cast_two, exp_log two_pos, exp_log] <;> norm_num theorem Gamma_strictMonoOn_Ici : StrictMonoOn Gamma (Ici 2) := by convert convexOn_Gamma.strict_mono_of_lt (by norm_num : (0 : ℝ) < 3 / 2) (by norm_num : (3 / 2 : ℝ) < 2) (Gamma_two.symm ▸ Gamma_three_div_two_lt_one) symm rw [inter_eq_right] exact fun x hx => two_pos.trans_le <| mem_Ici.mp hx end StrictMono section Doubling /-! ## The Gamma doubling formula As a fun application of the Bohr-Mollerup theorem, we prove the Gamma-function doubling formula (for positive real `s`). The idea is that `2 ^ s * Gamma (s / 2) * Gamma (s / 2 + 1 / 2)` is log-convex and satisfies the Gamma functional equation, so it must actually be a constant multiple of `Gamma`, and we can compute the constant by specialising at `s = 1`. -/ /-- Auxiliary definition for the doubling formula (we'll show this is equal to `Gamma s`) -/ def doublingGamma (s : ℝ) : ℝ := Gamma (s / 2) * Gamma (s / 2 + 1 / 2) * 2 ^ (s - 1) / √π theorem doublingGamma_add_one (s : ℝ) (hs : s ≠ 0) : doublingGamma (s + 1) = s * doublingGamma s := by rw [doublingGamma, doublingGamma, (by abel : s + 1 - 1 = s - 1 + 1), add_div, add_assoc,
add_halves (1 : ℝ), Gamma_add_one (div_ne_zero hs two_ne_zero), rpow_add two_pos, rpow_one] ring theorem doublingGamma_one : doublingGamma 1 = 1 := by simp_rw [doublingGamma, Gamma_one_half_eq, add_halves (1 : ℝ), sub_self, Gamma_one, mul_one, rpow_zero, mul_one, div_self (sqrt_ne_zero'.mpr pi_pos)] theorem log_doublingGamma_eq : EqOn (log ∘ doublingGamma) (fun s => log (Gamma (s / 2)) + log (Gamma (s / 2 + 1 / 2)) + s * log 2 - log (2 * √π)) (Ioi 0) := by intro s hs
Mathlib/Analysis/SpecialFunctions/Gamma/BohrMollerup.lean
373
384
/- 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 import Mathlib.Geometry.Manifold.ContMDiff.Defs /-! # 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 assert_not_exists tangentBundleCore open scoped Topology Manifold open Set Bundle ChartedSpace 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₁ : 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.uniqueDiffOn _ (mem_range_self _) variable {I} theorem uniqueMDiffWithinAt_iff_inter_range {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := Iff.rfl 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] 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_nhdsWithin {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) @[deprecated (since := "2024-10-31")] alias UniqueMDiffWithinAt.mono_of_mem := UniqueMDiffWithinAt.mono_of_mem_nhdsWithin 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 _) theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.mono_of_mem_nhdsWithin (Filter.inter_mem self_mem_nhdsWithin ht) theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.inter' (nhdsWithin_le_nhds ht) theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x := (uniqueMDiffWithinAt_univ I).mono_of_mem_nhdsWithin <| nhdsWithin_le_nhds <| hs.mem_nhds xs 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) theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s := fun _x hx => hs.uniqueMDiffWithinAt hx theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) := isOpen_univ.uniqueMDiffOn 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) 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))⟩ theorem mdifferentiableWithinAt_univ : MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt] theorem mdifferentiableWithinAt_inter (ht : t ∈ 𝓝 x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter ht] theorem mdifferentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter' ht] theorem MDifferentiableAt.mdifferentiableWithinAt (h : MDifferentiableAt I I' f x) : MDifferentiableWithinAt I I' f s x := MDifferentiableWithinAt.mono (subset_univ _) (mdifferentiableWithinAt_univ.2 h) 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 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 theorem mdifferentiableOn_univ : MDifferentiableOn I I' f univ ↔ MDifferentiable I I' f := by simp only [MDifferentiableOn, mdifferentiableWithinAt_univ, mfld_simps]; rfl 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 MDifferentiable.mdifferentiableOn (h : MDifferentiable I I' f) : MDifferentiableOn I I' f s := (mdifferentiableOn_univ.2 h).mono (subset_univ _) 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⟩) theorem MDifferentiable.mdifferentiableAt (hf : MDifferentiable I I' f) : MDifferentiableAt I I' f x := hf x /-! ### Relating differentiability in a manifold and differentiability in the model space through extended charts -/ theorem mdifferentiableWithinAt_iff_target_inter {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] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ theorem mdifferentiableWithinAt_iff : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [MDifferentiableWithinAt, ChartedSpace.liftPropWithinAt_iff']; rfl /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. This form states smoothness of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `mdifferentiableWithinAt_iff`, it is a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ theorem mdifferentiableWithinAt_iff_target_inter' : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source)) (extChartAt I x x) := by simp only [MDifferentiableWithinAt, liftPropWithinAt_iff'] exact and_congr_right fun hc => differentiableWithinAt_congr_nhds <| hc.nhdsWithin_extChartAt_symm_preimage_inter_range /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart in the target. -/ theorem mdifferentiableWithinAt_iff_target : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) s x := by simp_rw [MDifferentiableWithinAt, liftPropWithinAt_iff', ← and_assoc] have cont : ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔ ContinuousWithinAt f s x := and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt simp_rw [cont, DifferentiableWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe, chartAt_self_eq, PartialHomeomorph.refl_apply] rfl theorem mdifferentiableAt_iff_target {x : M} : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) x := by rw [← mdifferentiableWithinAt_univ, ← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target, continuousWithinAt_univ] section IsManifold variable {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'} open IsManifold theorem mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas [IsManifold I 1 M] (he : e ∈ maximalAtlas I 1 M) (hx : x ∈ e.source) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := by have h2x := hx; rw [← e.extend_source (I := I)] at h2x simp_rw [MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_source he hx, StructureGroupoid.liftPropWithinAt_self_source, e.extend_symm_continuousWithinAt_comp_right_iff, differentiableWithinAtProp_self_source, DifferentiableWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x] rfl theorem mdifferentiableWithinAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableWithinAt I I' f s x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx' theorem mdifferentiableAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableAt I I' f x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by simp_rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter] theorem mdifferentiableWithinAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) s x := by simp_rw [MDifferentiableWithinAt] rw [differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_target (chart_mem_maximalAtlas y) hy, and_congr_right] intro hf simp_rw [StructureGroupoid.liftPropWithinAt_self_target] simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf] rw [← extChartAt_source I'] at hy simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf] rfl theorem mdifferentiableAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) x := by rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target_of_mem_source hy, continuousWithinAt_univ, ← mdifferentiableWithinAt_univ] variable [IsManifold I 1 M] [IsManifold I' 1 M'] theorem mdifferentiableWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart he hx he' hy /-- An alternative formulation of `mdifferentiableWithinAt_iff_of_mem_maximalAtlas` if the set if `s` lies in `e.source`. -/ theorem mdifferentiableWithinAt_iff_image {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) (e.extend I x) := by rw [mdifferentiableWithinAt_iff_of_mem_maximalAtlas he he' hx hy, and_congr_right_iff] refine fun _ => differentiableWithinAt_congr_nhds ?_ simp_rw [nhdsWithin_eq_iff_eventuallyEq, e.extend_symm_preimage_inter_range_eventuallyEq hs hx] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness 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 ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hx hy /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. Version requiring differentiability in the target instead of `range I`. -/ 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).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) (extChartAt I x x') := by refine (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans ?_ rw [← extChartAt_source I] at hx rw [← extChartAt_source I'] at hy rw [and_congr_right_iff] set e := extChartAt I x; set e' := extChartAt I' (f x) refine fun hc => differentiableWithinAt_congr_nhds ?_ rw [← e.image_source_inter_eq', ← map_extChartAt_nhdsWithin_eq_image' hx, ← map_extChartAt_nhdsWithin' hx, inter_comm, nhdsWithin_inter_of_mem] exact hc (extChartAt_source_mem_nhds' hy) theorem mdifferentiableAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x' ↔ ContinuousAt f x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans <| by rw [continuousWithinAt_univ, preimage_univ, univ_inter] theorem mdifferentiableOn_iff_of_mem_maximalAtlas (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := by simp_rw [ContinuousOn, DifferentiableOn, Set.forall_mem_image, ← forall_and, MDifferentiableOn] exact forall₂_congr fun x hx => mdifferentiableWithinAt_iff_image he he' hs (hs hx) (h2s hx) /-- Differentiability on a set is equivalent to differentiability in the extended charts. -/ theorem mdifferentiableOn_iff_of_mem_maximalAtlas' (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := (mdifferentiableOn_iff_of_mem_maximalAtlas he he' hs h2s).trans <| and_iff_right_of_imp fun h ↦ (e.continuousOn_writtenInExtend_iff hs h2s).1 h.continuousOn /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source {x : M} {y : M'} (hs : s ⊆ (chartAt H x).source) (h2s : MapsTo f s (chartAt H' y).source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := mdifferentiableOn_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source' {x : M} {y : M'} (hs : s ⊆ (extChartAt I x).source) (h2s : MapsTo f s (extChartAt I' y).source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := by rw [extChartAt_source] at hs h2s exact mdifferentiableOn_iff_of_mem_maximalAtlas' (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart. -/ theorem mdifferentiableOn_iff : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) := by constructor · intro h refine ⟨fun x hx => (h x hx).1, fun x y z hz => ?_⟩ simp only [mfld_simps] at hz let w := (extChartAt I x).symm z have : w ∈ s := by simp only [w, hz, mfld_simps] specialize h w this have w1 : w ∈ (chartAt H x).source := by simp only [w, hz, mfld_simps] have w2 : f w ∈ (chartAt H' y).source := by simp only [w, hz, mfld_simps] convert ((mdifferentiableWithinAt_iff_of_mem_source w1 w2).mp h).2.mono _ · simp only [w, hz, mfld_simps] · mfld_set_tac · rintro ⟨hcont, hdiff⟩ x hx refine differentiableWithinAt_localInvariantProp.liftPropWithinAt_iff.mpr ?_ refine ⟨hcont x hx, ?_⟩ dsimp [DifferentiableWithinAtProp] convert hdiff x (f x) (extChartAt I x x) (by simp only [hx, mfld_simps]) using 1 mfld_set_tac /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart in the target. -/ theorem mdifferentiableOn_iff_target : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (s ∩ f ⁻¹' (extChartAt I' y).source) := by simp only [mdifferentiableOn_iff, ModelWithCorners.source_eq, chartAt_self_eq, PartialHomeomorph.refl_partialEquiv, PartialEquiv.refl_trans, extChartAt, PartialHomeomorph.extend, Set.preimage_univ, Set.inter_univ, and_congr_right_iff] intro h constructor · refine fun h' y => ⟨?_, fun x _ => h' x y⟩ have h'' : ContinuousOn _ univ := (ModelWithCorners.continuous I').continuousOn convert (h''.comp_inter (chartAt H' y).continuousOn_toFun).comp_inter h simp · exact fun h' x y => (h' y).2 x 0 /-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/ theorem mdifferentiable_iff : MDifferentiable I I' f ↔ Continuous f ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (f ⁻¹' (extChartAt I' y).source)) := by simp [← mdifferentiableOn_univ, mdifferentiableOn_iff, continuous_iff_continuousOn_univ] /-- One can reformulate smoothness as continuity and smoothness in any extended chart in the target. -/ theorem mdifferentiable_iff_target : MDifferentiable I I' f ↔ Continuous f ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (f ⁻¹' (extChartAt I' y).source) := by rw [← mdifferentiableOn_univ, mdifferentiableOn_iff_target] simp [continuous_iff_continuousOn_univ] end IsManifold /-! ### Deducing differentiability from smoothness -/ variable {n : WithTop ℕ∞} theorem ContMDiffWithinAt.mdifferentiableWithinAt (hf : ContMDiffWithinAt I I' n f s x)
(hn : 1 ≤ n) : MDifferentiableWithinAt I I' f s x := by suffices h : MDifferentiableWithinAt I I' f (s ∩ f ⁻¹' (extChartAt I' (f x)).source) x by rwa [mdifferentiableWithinAt_inter'] at h apply hf.1.preimage_mem_nhdsWithin exact extChartAt_source_mem_nhds (f x)
Mathlib/Geometry/Manifold/MFDeriv/Basic.lean
465
469
/- Copyright (c) 2018 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Kim Morrison, Floris van Doorn -/ import Mathlib.CategoryTheory.Limits.IsLimit import Mathlib.CategoryTheory.Category.ULift import Mathlib.CategoryTheory.EssentiallySmall import Mathlib.CategoryTheory.Functor.EpiMono import Mathlib.Logic.Equiv.Basic /-! # Existence of limits and colimits In `CategoryTheory.Limits.IsLimit` we defined `IsLimit c`, the data showing that a cone `c` is a limit cone. The two main structures defined in this file are: * `LimitCone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and * `HasLimit F`, asserting the mere existence of some limit cone for `F`. `HasLimit` is a propositional typeclass (it's important that it is a proposition merely asserting the existence of a limit, as otherwise we would have non-defeq problems from incompatible instances). While `HasLimit` only asserts the existence of a limit cone, we happily use the axiom of choice in mathlib, so there are convenience functions all depending on `HasLimit F`: * `limit F : C`, producing some limit object (of course all such are isomorphic) * `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit, * `limit.lift F c : c.pt ⟶ limit F`, the universal morphism from any other `c : Cone F`, etc. Key to using the `HasLimit` interface is that there is an `@[ext]` lemma stating that to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j` for every `j`. This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using automation (e.g. `tidy`). There are abbreviations `HasLimitsOfShape J C` and `HasLimits C` asserting the existence of classes of limits. Later more are introduced, for finite limits, special shapes of limits, etc. Ideally, many results about limits should be stated first in terms of `IsLimit`, and then a result in terms of `HasLimit` derived from this. At this point, however, this is far from uniformly achieved in mathlib --- often statements are only written in terms of `HasLimit`. ## Implementation At present we simply say everything twice, in order to handle both limits and colimits. It would be highly desirable to have some automation support, e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`. ## References * [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D) -/ noncomputable section open CategoryTheory CategoryTheory.Category CategoryTheory.Functor Opposite namespace CategoryTheory.Limits -- morphism levels before object levels. See note [CategoryTheory universes]. universe v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u'' variable {J : Type u₁} [Category.{v₁} J] {K : Type u₂} [Category.{v₂} K] variable {C : Type u} [Category.{v} C] variable {F : J ⥤ C} section Limit /-- `LimitCone F` contains a cone over `F` together with the information that it is a limit. -/ structure LimitCone (F : J ⥤ C) where /-- The cone itself -/ cone : Cone F /-- The proof that is the limit cone -/ isLimit : IsLimit cone /-- `HasLimit F` represents the mere existence of a limit for `F`. -/ class HasLimit (F : J ⥤ C) : Prop where mk' :: /-- There is some limit cone for `F` -/ exists_limit : Nonempty (LimitCone F) theorem HasLimit.mk {F : J ⥤ C} (d : LimitCone F) : HasLimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `LimitCone F` from `HasLimit F`. -/ def getLimitCone (F : J ⥤ C) [HasLimit F] : LimitCone F := Classical.choice <| HasLimit.exists_limit variable (J C) /-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/ class HasLimitsOfShape : Prop where /-- All functors `F : J ⥤ C` from `J` have limits -/ has_limit : ∀ F : J ⥤ C, HasLimit F := by infer_instance /-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`) if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All functors `F : J ⥤ C` from all small `J` have limits -/ has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by infer_instance /-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/ abbrev HasLimits (C : Type u) [Category.{v} C] : Prop := HasLimitsOfSize.{v, v} C theorem HasLimits.has_limits_of_shape {C : Type u} [Category.{v} C] [HasLimits C] (J : Type v) [Category.{v} J] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasLimitOfHasLimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasLimitsOfShape J C] (F : J ⥤ C) : HasLimit F := HasLimitsOfShape.has_limit F -- see Note [lower instance priority] instance (priority := 100) hasLimitsOfShapeOfHasLimits {J : Type u₁} [Category.{v₁} J] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfShape J C := HasLimitsOfSize.has_limits_of_shape J -- Interface to the `HasLimit` class. /-- An arbitrary choice of limit cone for a functor. -/ def limit.cone (F : J ⥤ C) [HasLimit F] : Cone F := (getLimitCone F).cone /-- An arbitrary choice of limit object of a functor. -/ def limit (F : J ⥤ C) [HasLimit F] := (limit.cone F).pt /-- The projection from the limit object to a value of the functor. -/ def limit.π (F : J ⥤ C) [HasLimit F] (j : J) : limit F ⟶ F.obj j := (limit.cone F).π.app j @[reassoc] theorem limit.π_comp_eqToHom (F : J ⥤ C) [HasLimit F] {j j' : J} (hj : j = j') : limit.π F j ≫ eqToHom (by subst hj; rfl) = limit.π F j' := by subst hj simp @[simp] theorem limit.cone_x {F : J ⥤ C} [HasLimit F] : (limit.cone F).pt = limit F := rfl @[simp] theorem limit.cone_π {F : J ⥤ C} [HasLimit F] : (limit.cone F).π.app = limit.π _ := rfl @[reassoc (attr := simp)] theorem limit.w (F : J ⥤ C) [HasLimit F] {j j' : J} (f : j ⟶ j') : limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f /-- Evidence that the arbitrary choice of cone provided by `limit.cone F` is a limit cone. -/ def limit.isLimit (F : J ⥤ C) [HasLimit F] : IsLimit (limit.cone F) := (getLimitCone F).isLimit /-- The morphism from the cone point of any other cone to the limit object. -/ def limit.lift (F : J ⥤ C) [HasLimit F] (c : Cone F) : c.pt ⟶ limit F := (limit.isLimit F).lift c @[simp] theorem limit.isLimit_lift {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.isLimit F).lift c = limit.lift F c := rfl @[reassoc (attr := simp)] theorem limit.lift_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : limit.lift F c ≫ limit.π F j = c.π.app j := IsLimit.fac _ c j /-- Functoriality of limits. Usually this morphism should be accessed through `lim.map`, but may be needed separately when you have specified limits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def limMap {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) : limit F ⟶ limit G := IsLimit.map _ (limit.isLimit G) α @[reassoc (attr := simp)] theorem limMap_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) (j : J) : limMap α ≫ limit.π G j = limit.π F j ≫ α.app j := limit.lift_π _ j /-- The cone morphism from any cone to the arbitrary choice of limit cone. -/ def limit.coneMorphism {F : J ⥤ C} [HasLimit F] (c : Cone F) : c ⟶ limit.cone F := (limit.isLimit F).liftConeMorphism c @[simp] theorem limit.coneMorphism_hom {F : J ⥤ C} [HasLimit F] (c : Cone F) : (limit.coneMorphism c).hom = limit.lift F c := rfl theorem limit.coneMorphism_π {F : J ⥤ C} [HasLimit F] (c : Cone F) (j : J) : (limit.coneMorphism c).hom ≫ limit.π F j = c.π.app j := by simp @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_hom_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso hc (limit.isLimit _)).hom ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_hom_comp _ _ _ @[reassoc (attr := simp)] theorem limit.conePointUniqueUpToIso_inv_comp {F : J ⥤ C} [HasLimit F] {c : Cone F} (hc : IsLimit c) (j : J) : (IsLimit.conePointUniqueUpToIso (limit.isLimit _) hc).inv ≫ limit.π F j = c.π.app j := IsLimit.conePointUniqueUpToIso_inv_comp _ _ _ theorem limit.existsUnique {F : J ⥤ C} [HasLimit F] (t : Cone F) : ∃! l : t.pt ⟶ limit F, ∀ j, l ≫ limit.π F j = t.π.app j := (limit.isLimit F).existsUnique _ /-- Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point. -/ def limit.isoLimitCone {F : J ⥤ C} [HasLimit F] (t : LimitCone F) : limit F ≅ t.cone.pt := IsLimit.conePointUniqueUpToIso (limit.isLimit F) t.isLimit @[reassoc (attr := simp)] theorem limit.isoLimitCone_hom_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).hom ≫ t.cone.π.app j = limit.π F j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] simp @[reassoc (attr := simp)] theorem limit.isoLimitCone_inv_π {F : J ⥤ C} [HasLimit F] (t : LimitCone F) (j : J) : (limit.isoLimitCone t).inv ≫ limit.π F j = t.cone.π.app j := by dsimp [limit.isoLimitCone, IsLimit.conePointUniqueUpToIso] simp @[ext] theorem limit.hom_ext {F : J ⥤ C} [HasLimit F] {X : C} {f f' : X ⟶ limit F} (w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' := (limit.isLimit F).hom_ext w @[reassoc (attr := simp)] theorem limit.lift_map {F G : J ⥤ C} [HasLimit F] [HasLimit G] (c : Cone F) (α : F ⟶ G) : limit.lift F c ≫ limMap α = limit.lift G ((Cones.postcompose α).obj c) := by ext rw [assoc, limMap_π, limit.lift_π_assoc, limit.lift_π] rfl @[simp] theorem limit.lift_cone {F : J ⥤ C} [HasLimit F] : limit.lift F (limit.cone F) = 𝟙 (limit F) := (limit.isLimit _).lift_self /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and cones with cone point `W`. -/ def limit.homIso (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ F.cones.obj (op W) := (limit.isLimit F).homIso W @[simp] theorem limit.homIso_hom (F : J ⥤ C) [HasLimit F] {W : C} (f : ULift (W ⟶ limit F)) : (limit.homIso F W).hom f = (const J).map f.down ≫ (limit.cone F).π := (limit.isLimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from a specified object `W` to the limit object, and an explicit componentwise description of cones with cone point `W`. -/ def limit.homIso' (F : J ⥤ C) [HasLimit F] (W : C) : ULift.{u₁} (W ⟶ limit F : Type v) ≅ { p : ∀ j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } := (limit.isLimit F).homIso' W theorem limit.lift_extend {F : J ⥤ C} [HasLimit F] (c : Cone F) {X : C} (f : X ⟶ c.pt) : limit.lift F (c.extend f) = f ≫ limit.lift F c := by aesop_cat /-- If a functor `F` has a limit, so does any naturally isomorphic functor. -/ theorem hasLimit_of_iso {F G : J ⥤ C} [HasLimit F] (α : F ≅ G) : HasLimit G := HasLimit.mk { cone := (Cones.postcompose α.hom).obj (limit.cone F) isLimit := (IsLimit.postcomposeHomEquiv _ _).symm (limit.isLimit F) } @[deprecated (since := "2025-03-03")] alias hasLimitOfIso := hasLimit_of_iso theorem hasLimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasLimit F ↔ HasLimit G := ⟨fun _ ↦ hasLimit_of_iso α, fun _ ↦ hasLimit_of_iso α.symm⟩ -- See the construction of limits from products and equalizers -- for an example usage. /-- If a functor `G` has the same collection of cones as a functor `F` which has a limit, then `G` also has a limit. -/ theorem HasLimit.ofConesIso {J K : Type u₁} [Category.{v₁} J] [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cones ≅ G.cones) [HasLimit F] : HasLimit G := HasLimit.mk ⟨_, IsLimit.ofNatIso (IsLimit.natIso (limit.isLimit F) ≪≫ h)⟩ /-- The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasLimit.isoOfNatIso {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) : limit F ≅ limit G := IsLimit.conePointsIsoOfNatIso (limit.isLimit F) (limit.isLimit G) w @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_hom_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j := IsLimit.conePointsIsoOfNatIso_hom_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.isoOfNatIso_inv_π {F G : J ⥤ C} [HasLimit F] [HasLimit G] (w : F ≅ G) (j : J) : (HasLimit.isoOfNatIso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j := IsLimit.conePointsIsoOfNatIso_inv_comp _ _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_hom {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone F) (w : F ≅ G) : limit.lift F t ≫ (HasLimit.isoOfNatIso w).hom = limit.lift G ((Cones.postcompose w.hom).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_hom _ _ _ @[reassoc (attr := simp)] theorem HasLimit.lift_isoOfNatIso_inv {F G : J ⥤ C} [HasLimit F] [HasLimit G] (t : Cone G) (w : F ≅ G) : limit.lift G t ≫ (HasLimit.isoOfNatIso w).inv = limit.lift F ((Cones.postcompose w.inv).obj _) := IsLimit.lift_comp_conePointsIsoOfNatIso_inv _ _ _ /-- The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasLimit.isoOfEquivalence {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G := IsLimit.conePointsIsoOfEquivalence (limit.isLimit F) (limit.isLimit G) e w @[simp] theorem HasLimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : (HasLimit.isoOfEquivalence e w).hom ≫ limit.π G k = limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp @[simp] theorem HasLimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasLimit F] {G : K ⥤ C} [HasLimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : (HasLimit.isoOfEquivalence e w).inv ≫ limit.π F j = limit.π G (e.functor.obj j) ≫ w.hom.app j := by simp only [HasLimit.isoOfEquivalence, IsLimit.conePointsIsoOfEquivalence_hom] dsimp simp section Pre variable (F) variable [HasLimit F] (E : K ⥤ J) [HasLimit (E ⋙ F)] /-- The canonical morphism from the limit of `F` to the limit of `E ⋙ F`. -/ def limit.pre : limit F ⟶ limit (E ⋙ F) := limit.lift (E ⋙ F) ((limit.cone F).whisker E) @[reassoc (attr := simp)] theorem limit.pre_π (k : K) : limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_pre (c : Cone F) : limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) := by ext; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem limit.pre_pre [h : HasLimit (D ⋙ E ⋙ F)] : haveI : HasLimit ((D ⋙ E) ⋙ F) := h limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) := by haveI : HasLimit ((D ⋙ E) ⋙ F) := h ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; rfl variable {E F} /-- - If we have particular limit cones available for `E ⋙ F` and for `F`, we obtain a formula for `limit.pre F E`. -/ theorem limit.pre_eq (s : LimitCone (E ⋙ F)) (t : LimitCone F) : limit.pre F E = (limit.isoLimitCone t).hom ≫ s.isLimit.lift (t.cone.whisker E) ≫ (limit.isoLimitCone s).inv := by aesop_cat end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F : J ⥤ C) [HasLimit F] (G : C ⥤ D) [HasLimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`. -/ def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) := limit.lift (F ⋙ G) (G.mapCone (limit.cone F)) @[reassoc (attr := simp)] theorem limit.post_π (j : J) : limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) := by erw [IsLimit.fac] rfl @[simp] theorem limit.lift_post (c : Cone F) : G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.mapCone c) := by ext rw [assoc, limit.post_π, ← G.map_comp, limit.lift_π, limit.lift_π] rfl @[simp] theorem limit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) [h : HasLimit ((F ⋙ G) ⋙ H)] : -- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) haveI : HasLimit (F ⋙ G ⋙ H) := h H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) := by haveI : HasLimit (F ⋙ G ⋙ H) := h ext; erw [assoc, limit.post_π, ← H.map_comp, limit.post_π, limit.post_π]; rfl end Post theorem limit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasLimit F] [HasLimit (E ⋙ F)] [HasLimit (F ⋙ G)] [h : HasLimit ((E ⋙ F) ⋙ G)] :-- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or haveI : HasLimit (E ⋙ F ⋙ G) := h G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E := by haveI : HasLimit (E ⋙ F ⋙ G) := h ext; erw [assoc, limit.post_π, ← G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π] open CategoryTheory.Equivalence instance hasLimitEquivalenceComp (e : K ≌ J) [HasLimit F] : HasLimit (e.functor ⋙ F) := HasLimit.mk { cone := Cone.whisker e.functor (limit.cone F) isLimit := IsLimit.whiskerEquivalence (limit.isLimit F) e } -- not entirely sure why this is needed /-- If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`. -/ theorem hasLimitOfEquivalenceComp (e : K ≌ J) [HasLimit (e.functor ⋙ F)] : HasLimit F := by haveI : HasLimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasLimitEquivalenceComp e.symm apply hasLimit_of_iso (e.invFunIdAssoc F) -- `hasLimitCompEquivalence` and `hasLimitOfCompEquivalence` -- are proved in `CategoryTheory/Adjunction/Limits.lean`. section LimFunctor variable [HasLimitsOfShape J C] section /-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/ @[simps] def lim : (J ⥤ C) ⥤ C where obj F := limit F map α := limMap α map_id F := by apply Limits.limit.hom_ext; intro j simp map_comp α β := by apply Limits.limit.hom_ext; intro j simp [assoc] end variable {G : J ⥤ C} (α : F ⟶ G) theorem limMap_eq : limMap α = lim.map α := rfl theorem limit.map_pre [HasLimitsOfShape K C] (E : K ⥤ J) : lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whiskerLeft E α) := by ext simp theorem limit.map_pre' [HasLimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whiskerRight α F) := by ext1; simp [← category.assoc] theorem limit.id_pre (F : J ⥤ C) : limit.pre F (𝟭 _) = lim.map (Functor.leftUnitor F).inv := by aesop_cat theorem limit.map_post {D : Type u'} [Category.{v'} D] [HasLimitsOfShape J D] (H : C ⥤ D) : /- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/ H.map (limMap α) ≫ limit.post G H = limit.post F H ≫ limMap (whiskerRight α H) := by ext simp only [whiskerRight_app, limMap_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp] /-- The isomorphism between morphisms from `W` to the cone point of the limit cone for `F` and cones over `F` with cone point `W` is natural in `F`. -/ def limYoneda : lim ⋙ yoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => limit.homIso F (unop W) /-- The constant functor and limit functor are adjoint to each other -/ def constLimAdj : (const J : C ⥤ J ⥤ C) ⊣ lim := Adjunction.mk' { homEquiv := fun c g ↦ { toFun := fun f => limit.lift _ ⟨c, f⟩ invFun := fun f => { app := fun _ => f ≫ limit.π _ _ } left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun _ => limit.lift _ ⟨_, 𝟙 _⟩ } counit := { app := fun g => { app := limit.π _ } } } instance : IsRightAdjoint (lim : (J ⥤ C) ⥤ C) := ⟨_, ⟨constLimAdj⟩⟩ end LimFunctor instance limMap_mono' {F G : J ⥤ C} [HasLimitsOfShape J C] (α : F ⟶ G) [Mono α] : Mono (limMap α) := (lim : (J ⥤ C) ⥤ C).map_mono α instance limMap_mono {F G : J ⥤ C} [HasLimit F] [HasLimit G] (α : F ⟶ G) [∀ j, Mono (α.app j)] : Mono (limMap α) := ⟨fun {Z} u v h => limit.hom_ext fun j => (cancel_mono (α.app j)).1 <| by simpa using h =≫ limit.π _ j⟩ section Adjunction variable {L : (J ⥤ C) ⥤ C} (adj : Functor.const _ ⊣ L) /- The fact that the existence of limits of shape `J` is equivalent to the existence of a right adjoint to the constant functor `C ⥤ (J ⥤ C)` is obtained in the file `Mathlib.CategoryTheory.Limits.ConeCategory`: see the lemma `hasLimitsOfShape_iff_isLeftAdjoint_const`. In the definitions below, given an adjunction `adj : Functor.const _ ⊣ (L : (J ⥤ C) ⥤ C)`, we directly construct a limit cone for any `F : J ⥤ C`. -/ /-- The limit cone obtained from a right adjoint of the constant functor. -/ @[simps] noncomputable def coneOfAdj (F : J ⥤ C) : Cone F where pt := L.obj F π := adj.counit.app F /-- The cones defined by `coneOfAdj` are limit cones. -/ @[simps] def isLimitConeOfAdj (F : J ⥤ C) : IsLimit (coneOfAdj adj F) where lift s := adj.homEquiv _ _ s.π fac s j := by have eq := NatTrans.congr_app (adj.counit.naturality s.π) j have eq' := NatTrans.congr_app (adj.left_triangle_components s.pt) j dsimp at eq eq' ⊢ rw [adj.homEquiv_unit, assoc, eq, reassoc_of% eq'] uniq s m hm := (adj.homEquiv _ _).symm.injective (by ext j; simpa using hm j) end Adjunction /-- We can transport limits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasLimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasLimitsOfShape J C] : HasLimitsOfShape J' C := by constructor intro F apply hasLimitOfEquivalenceComp e variable (C) /-- A category that has larger limits also has smaller limits. -/ theorem hasLimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasLimitsOfSize.{v₁, u₁} C] : HasLimitsOfSize.{v₂, u₂} C where has_limits_of_shape J {_} := hasLimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasLimitsOfSizeShrink.{v u} C` tries to obtain `HasLimitsOfSize.{v u} C` from some other `HasLimitsOfSize C`. -/ theorem hasLimitsOfSizeShrink [HasLimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasLimitsOfSize.{v₁, u₁} C := hasLimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestLimitsOfHasLimits [HasLimits C] : HasLimitsOfSize.{0, 0} C := hasLimitsOfSizeShrink.{0, 0} C end Limit section Colimit /-- `ColimitCocone F` contains a cocone over `F` together with the information that it is a colimit. -/ structure ColimitCocone (F : J ⥤ C) where /-- The cocone itself -/ cocone : Cocone F /-- The proof that it is the colimit cocone -/ isColimit : IsColimit cocone /-- `HasColimit F` represents the mere existence of a colimit for `F`. -/ class HasColimit (F : J ⥤ C) : Prop where mk' :: /-- There exists a colimit for `F` -/ exists_colimit : Nonempty (ColimitCocone F) theorem HasColimit.mk {F : J ⥤ C} (d : ColimitCocone F) : HasColimit F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `ColimitCocone F` from `HasColimit F`. -/ def getColimitCocone (F : J ⥤ C) [HasColimit F] : ColimitCocone F := Classical.choice <| HasColimit.exists_colimit variable (J C) /-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/ class HasColimitsOfShape : Prop where /-- All `F : J ⥤ C` have colimits for a fixed `J` -/ has_colimit : ∀ F : J ⥤ C, HasColimit F := by infer_instance /-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`) if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`. -/ @[pp_with_univ] class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where /-- All `F : J ⥤ C` have colimits for all small `J` -/ has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by infer_instance /-- `C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets. -/ abbrev HasColimits (C : Type u) [Category.{v} C] : Prop := HasColimitsOfSize.{v, v} C theorem HasColimits.hasColimitsOfShape {C : Type u} [Category.{v} C] [HasColimits C] (J : Type v) [Category.{v} J] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J variable {J C} -- see Note [lower instance priority] instance (priority := 100) hasColimitOfHasColimitsOfShape {J : Type u₁} [Category.{v₁} J] [HasColimitsOfShape J C] (F : J ⥤ C) : HasColimit F := HasColimitsOfShape.has_colimit F -- see Note [lower instance priority] instance (priority := 100) hasColimitsOfShapeOfHasColimitsOfSize {J : Type u₁} [Category.{v₁} J] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfShape J C := HasColimitsOfSize.has_colimits_of_shape J -- Interface to the `HasColimit` class. /-- An arbitrary choice of colimit cocone of a functor. -/ def colimit.cocone (F : J ⥤ C) [HasColimit F] : Cocone F := (getColimitCocone F).cocone /-- An arbitrary choice of colimit object of a functor. -/ def colimit (F : J ⥤ C) [HasColimit F] := (colimit.cocone F).pt /-- The coprojection from a value of the functor to the colimit object. -/ def colimit.ι (F : J ⥤ C) [HasColimit F] (j : J) : F.obj j ⟶ colimit F := (colimit.cocone F).ι.app j @[reassoc] theorem colimit.eqToHom_comp_ι (F : J ⥤ C) [HasColimit F] {j j' : J} (hj : j = j') : eqToHom (by subst hj; rfl) ≫ colimit.ι F j = colimit.ι F j' := by subst hj simp @[simp] theorem colimit.cocone_ι {F : J ⥤ C} [HasColimit F] (j : J) : (colimit.cocone F).ι.app j = colimit.ι _ j := rfl @[simp] theorem colimit.cocone_x {F : J ⥤ C} [HasColimit F] : (colimit.cocone F).pt = colimit F := rfl @[reassoc (attr := simp)] theorem colimit.w (F : J ⥤ C) [HasColimit F] {j j' : J} (f : j ⟶ j') : F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f /-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/ def colimit.isColimit (F : J ⥤ C) [HasColimit F] : IsColimit (colimit.cocone F) := (getColimitCocone F).isColimit /-- The morphism from the colimit object to the cone point of any other cocone. -/ def colimit.desc (F : J ⥤ C) [HasColimit F] (c : Cocone F) : colimit F ⟶ c.pt := (colimit.isColimit F).desc c @[simp] theorem colimit.isColimit_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.isColimit F).desc c = colimit.desc F c := rfl /-- We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`, and combined with `colimit.ext` we rely on these lemmas for many calculations. However, since `Category.assoc` is a `@[simp]` lemma, often expressions are right associated, and it's hard to apply these lemmas about `colimit.ι`. We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism. (see `Tactic/reassoc_axiom.lean`) -/ @[reassoc (attr := simp)] theorem colimit.ι_desc {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ colimit.desc F c = c.ι.app j := IsColimit.fac _ c j /-- Functoriality of colimits. Usually this morphism should be accessed through `colim.map`, but may be needed separately when you have specified colimits for the source and target functors, but not necessarily for all functors of shape `J`. -/ def colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) : colimit F ⟶ colimit G := IsColimit.map (colimit.isColimit F) _ α @[reassoc (attr := simp)] theorem ι_colimMap {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) (j : J) : colimit.ι F j ≫ colimMap α = α.app j ≫ colimit.ι G j := colimit.ι_desc _ j /-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/ def colimit.coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) : colimit.cocone F ⟶ c := (colimit.isColimit F).descCoconeMorphism c @[simp] theorem colimit.coconeMorphism_hom {F : J ⥤ C} [HasColimit F] (c : Cocone F) : (colimit.coconeMorphism c).hom = colimit.desc F c := rfl theorem colimit.ι_coconeMorphism {F : J ⥤ C} [HasColimit F] (c : Cocone F) (j : J) : colimit.ι F j ≫ (colimit.coconeMorphism c).hom = c.ι.app j := by simp @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_hom {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _) hc).hom = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_hom _ _ _ @[reassoc (attr := simp)] theorem colimit.comp_coconePointUniqueUpToIso_inv {F : J ⥤ C} [HasColimit F] {c : Cocone F} (hc : IsColimit c) (j : J) : colimit.ι F j ≫ (IsColimit.coconePointUniqueUpToIso hc (colimit.isColimit _)).inv = c.ι.app j := IsColimit.comp_coconePointUniqueUpToIso_inv _ _ _ theorem colimit.existsUnique {F : J ⥤ C} [HasColimit F] (t : Cocone F) : ∃! d : colimit F ⟶ t.pt, ∀ j, colimit.ι F j ≫ d = t.ι.app j := (colimit.isColimit F).existsUnique _ /-- Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point. -/ def colimit.isoColimitCocone {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) : colimit F ≅ t.cocone.pt := IsColimit.coconePointUniqueUpToIso (colimit.isColimit F) t.isColimit @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_hom {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : colimit.ι F j ≫ (colimit.isoColimitCocone t).hom = t.cocone.ι.app j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] simp @[reassoc (attr := simp)] theorem colimit.isoColimitCocone_ι_inv {F : J ⥤ C} [HasColimit F] (t : ColimitCocone F) (j : J) : t.cocone.ι.app j ≫ (colimit.isoColimitCocone t).inv = colimit.ι F j := by dsimp [colimit.isoColimitCocone, IsColimit.coconePointUniqueUpToIso] simp @[ext] theorem colimit.hom_ext {F : J ⥤ C} [HasColimit F] {X : C} {f f' : colimit F ⟶ X} (w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' := (colimit.isColimit F).hom_ext w @[simp] theorem colimit.desc_cocone {F : J ⥤ C} [HasColimit F] : colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) := (colimit.isColimit _).desc_self /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and cocones with cone point `W`. -/ def colimit.homIso (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ F.cocones.obj W := (colimit.isColimit F).homIso W @[simp] theorem colimit.homIso_hom (F : J ⥤ C) [HasColimit F] {W : C} (f : ULift (colimit F ⟶ W)) : (colimit.homIso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down := (colimit.isColimit F).homIso_hom f /-- The isomorphism (in `Type`) between morphisms from the colimit object to a specified object `W`, and an explicit componentwise description of cocones with cone point `W`. -/ def colimit.homIso' (F : J ⥤ C) [HasColimit F] (W : C) : ULift.{u₁} (colimit F ⟶ W : Type v) ≅ { p : ∀ j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } := (colimit.isColimit F).homIso' W theorem colimit.desc_extend (F : J ⥤ C) [HasColimit F] (c : Cocone F) {X : C} (f : c.pt ⟶ X) : colimit.desc F (c.extend f) = colimit.desc F c ≫ f := by ext1; rw [← Category.assoc]; simp -- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`. -- This is intentional; it seems to help with elaboration. /-- If `F` has a colimit, so does any naturally isomorphic functor. -/ theorem hasColimit_of_iso {F G : J ⥤ C} [HasColimit F] (α : G ≅ F) : HasColimit G := HasColimit.mk { cocone := (Cocones.precompose α.hom).obj (colimit.cocone F) isColimit := (IsColimit.precomposeHomEquiv _ _).symm (colimit.isColimit F) } @[deprecated (since := "2025-03-03")] alias hasColimitOfIso := hasColimit_of_iso theorem hasColimit_iff_of_iso {F G : J ⥤ C} (α : F ≅ G) : HasColimit F ↔ HasColimit G := ⟨fun _ ↦ hasColimit_of_iso α.symm, fun _ ↦ hasColimit_of_iso α⟩ /-- If a functor `G` has the same collection of cocones as a functor `F` which has a colimit, then `G` also has a colimit. -/ theorem HasColimit.ofCoconesIso {K : Type u₁} [Category.{v₂} K] (F : J ⥤ C) (G : K ⥤ C) (h : F.cocones ≅ G.cocones) [HasColimit F] : HasColimit G := HasColimit.mk ⟨_, IsColimit.ofNatIso (IsColimit.natIso (colimit.isColimit F) ≪≫ h)⟩ /-- The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic, if the functors are naturally isomorphic. -/ def HasColimit.isoOfNatIso {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfNatIso (colimit.isColimit F) (colimit.isColimit G) w @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_hom {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfNatIso w).hom = w.hom.app j ≫ colimit.ι G j := IsColimit.comp_coconePointsIsoOfNatIso_hom _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_ι_inv {F G : J ⥤ C} [HasColimit F] [HasColimit G] (w : F ≅ G) (j : J) : colimit.ι G j ≫ (HasColimit.isoOfNatIso w).inv = w.inv.app j ≫ colimit.ι F j := IsColimit.comp_coconePointsIsoOfNatIso_inv _ _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_hom_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone G) (w : F ≅ G) : (HasColimit.isoOfNatIso w).hom ≫ colimit.desc G t = colimit.desc F ((Cocones.precompose w.hom).obj _) := IsColimit.coconePointsIsoOfNatIso_hom_desc _ _ _ @[reassoc (attr := simp)] theorem HasColimit.isoOfNatIso_inv_desc {F G : J ⥤ C} [HasColimit F] [HasColimit G] (t : Cocone F) (w : F ≅ G) : (HasColimit.isoOfNatIso w).inv ≫ colimit.desc F t = colimit.desc G ((Cocones.precompose w.inv).obj _) := IsColimit.coconePointsIsoOfNatIso_inv_desc _ _ _ /-- The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic, if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism. -/ def HasColimit.isoOfEquivalence {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G := IsColimit.coconePointsIsoOfEquivalence (colimit.isColimit F) (colimit.isColimit G) e w @[simp] theorem HasColimit.isoOfEquivalence_hom_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) : colimit.ι F j ≫ (HasColimit.isoOfEquivalence e w).hom = F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] @[simp] theorem HasColimit.isoOfEquivalence_inv_π {F : J ⥤ C} [HasColimit F] {G : K ⥤ C} [HasColimit G] (e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) : colimit.ι G k ≫ (HasColimit.isoOfEquivalence e w).inv = G.map (e.counitInv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) := by simp [HasColimit.isoOfEquivalence, IsColimit.coconePointsIsoOfEquivalence_inv] section Pre variable (F) variable [HasColimit F] (E : K ⥤ J) [HasColimit (E ⋙ F)] /-- The canonical morphism from the colimit of `E ⋙ F` to the colimit of `F`. -/ def colimit.pre : colimit (E ⋙ F) ⟶ colimit F := colimit.desc (E ⋙ F) ((colimit.cocone F).whisker E) @[reassoc (attr := simp)] theorem colimit.ι_pre (k : K) : colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) := by erw [IsColimit.fac] rfl @[reassoc (attr := simp)] theorem colimit.ι_inv_pre [IsIso (pre F E)] (k : K) : colimit.ι F (E.obj k) ≫ inv (colimit.pre F E) = colimit.ι (E ⋙ F) k := by simp [IsIso.comp_inv_eq] @[reassoc (attr := simp)] theorem colimit.pre_desc (c : Cocone F) : colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) := by ext; rw [← assoc, colimit.ι_pre]; simp variable {L : Type u₃} [Category.{v₃} L] variable (D : L ⥤ K) @[simp] theorem colimit.pre_pre [h : HasColimit (D ⋙ E ⋙ F)] : haveI : HasColimit ((D ⋙ E) ⋙ F) := h colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) := by ext j rw [← assoc, colimit.ι_pre, colimit.ι_pre] haveI : HasColimit ((D ⋙ E) ⋙ F) := h exact (colimit.ι_pre F (D ⋙ E) j).symm variable {E F} /-- - If we have particular colimit cocones available for `E ⋙ F` and for `F`, we obtain a formula for `colimit.pre F E`. -/ theorem colimit.pre_eq (s : ColimitCocone (E ⋙ F)) (t : ColimitCocone F) : colimit.pre F E = (colimit.isoColimitCocone s).hom ≫ s.isColimit.desc (t.cocone.whisker E) ≫ (colimit.isoColimitCocone t).inv := by aesop_cat end Pre section Post variable {D : Type u'} [Category.{v'} D] variable (F) variable [HasColimit F] (G : C ⥤ D) [HasColimit (F ⋙ G)] /-- The canonical morphism from `G` applied to the colimit of `F ⋙ G` to `G` applied to the colimit of `F`. -/ def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) := colimit.desc (F ⋙ G) (G.mapCocone (colimit.cocone F)) @[reassoc (attr := simp)] theorem colimit.ι_post (j : J) : colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) := by erw [IsColimit.fac] rfl @[simp] theorem colimit.post_desc (c : Cocone F) : colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.mapCocone c) := by ext rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_desc, colimit.ι_desc] rfl @[simp] theorem colimit.post_post {E : Type u''} [Category.{v''} E] (H : D ⥤ E) -- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) [h : HasColimit ((F ⋙ G) ⋙ H)] : haveI : HasColimit (F ⋙ G ⋙ H) := h colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) := by ext j rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_post] haveI : HasColimit (F ⋙ G ⋙ H) := h exact (colimit.ι_post F (G ⋙ H) j).symm end Post theorem colimit.pre_post {D : Type u'} [Category.{v'} D] (E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D) [HasColimit F] [HasColimit (E ⋙ F)] [HasColimit (F ⋙ G)] [h : HasColimit ((E ⋙ F) ⋙ G)] : -- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or haveI : HasColimit (E ⋙ F ⋙ G) := h colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) = colimit.pre (F ⋙ G) E ≫ colimit.post F G := by ext j rw [← assoc, colimit.ι_post, ← G.map_comp, colimit.ι_pre, ← assoc] haveI : HasColimit (E ⋙ F ⋙ G) := h erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post] open CategoryTheory.Equivalence instance hasColimit_equivalence_comp (e : K ≌ J) [HasColimit F] : HasColimit (e.functor ⋙ F) := HasColimit.mk { cocone := Cocone.whisker e.functor (colimit.cocone F) isColimit := IsColimit.whiskerEquivalence (colimit.isColimit F) e } /-- If a `E ⋙ F` has a colimit, and `E` is an equivalence, we can construct a colimit of `F`. -/ theorem hasColimit_of_equivalence_comp (e : K ≌ J) [HasColimit (e.functor ⋙ F)] : HasColimit F := by haveI : HasColimit (e.inverse ⋙ e.functor ⋙ F) := Limits.hasColimit_equivalence_comp e.symm apply hasColimit_of_iso (e.invFunIdAssoc F).symm section ColimFunctor variable [HasColimitsOfShape J C] section /-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/ @[simps] def colim : (J ⥤ C) ⥤ C where obj F := colimit F map α := colimMap α end variable {G : J ⥤ C} (α : F ⟶ G) theorem colimMap_eq : colimMap α = colim.map α := rfl @[reassoc] theorem colimit.ι_map (j : J) : colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j := by simp @[reassoc (attr := simp)] theorem colimit.map_desc (c : Cocone G) : colimMap α ≫ colimit.desc G c = colimit.desc F ((Cocones.precompose α).obj c) := by ext j simp [← assoc, colimit.ι_map, assoc, colimit.ι_desc, colimit.ι_desc] theorem colimit.pre_map [HasColimitsOfShape K C] (E : K ⥤ J) : colimit.pre F E ≫ colim.map α = colim.map (whiskerLeft E α) ≫ colimit.pre G E := by ext rw [← assoc, colimit.ι_pre, colimit.ι_map, ← assoc, colimit.ι_map, assoc, colimit.ι_pre] rfl theorem colimit.pre_map' [HasColimitsOfShape K C] (F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) : colimit.pre F E₁ = colim.map (whiskerRight α F) ≫ colimit.pre F E₂ := by ext1 simp [← assoc, assoc] theorem colimit.pre_id (F : J ⥤ C) : colimit.pre F (𝟭 _) = colim.map (Functor.leftUnitor F).hom := by aesop_cat theorem colimit.map_post {D : Type u'} [Category.{v'} D] [HasColimitsOfShape J D] (H : C ⥤ D) :/- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/ colimit.post F H ≫ H.map (colim.map α) = colim.map (whiskerRight α H) ≫ colimit.post G H := by ext rw [← assoc, colimit.ι_post, ← H.map_comp, colimit.ι_map, H.map_comp] rw [← assoc, colimit.ι_map, assoc, colimit.ι_post] rfl /-- The isomorphism between morphisms from the cone point of the colimit cocone for `F` to `W` and cocones over `F` with cone point `W` is natural in `F`. -/ def colimCoyoneda : colim.op ⋙ coyoneda ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} ≅ CategoryTheory.cocones J C := NatIso.ofComponents fun F => NatIso.ofComponents fun W => colimit.homIso (unop F) W /-- The colimit functor and constant functor are adjoint to each other -/ def colimConstAdj : (colim : (J ⥤ C) ⥤ C) ⊣ const J := Adjunction.mk' { homEquiv := fun f c ↦ { toFun := fun g => { app := fun _ => colimit.ι _ _ ≫ g } invFun := fun g => colimit.desc _ ⟨_, g⟩ left_inv := by aesop_cat right_inv := by aesop_cat } unit := { app := fun g => { app := colimit.ι _ } } counit := { app := fun _ => colimit.desc _ ⟨_, 𝟙 _⟩ } } instance : IsLeftAdjoint (colim : (J ⥤ C) ⥤ C) := ⟨_, ⟨colimConstAdj⟩⟩ end ColimFunctor instance colimMap_epi' {F G : J ⥤ C} [HasColimitsOfShape J C] (α : F ⟶ G) [Epi α] : Epi (colimMap α) := (colim : (J ⥤ C) ⥤ C).map_epi α instance colimMap_epi {F G : J ⥤ C} [HasColimit F] [HasColimit G] (α : F ⟶ G) [∀ j, Epi (α.app j)] : Epi (colimMap α) := ⟨fun {Z} u v h => colimit.hom_ext fun j => (cancel_epi (α.app j)).1 <| by simpa using colimit.ι _ j ≫= h⟩ /-- We can transport colimits of shape `J` along an equivalence `J ≌ J'`. -/ theorem hasColimitsOfShape_of_equivalence {J' : Type u₂} [Category.{v₂} J'] (e : J ≌ J') [HasColimitsOfShape J C] : HasColimitsOfShape J' C := by constructor intro F apply hasColimit_of_equivalence_comp e variable (C) /-- A category that has larger colimits also has smaller colimits. -/ theorem hasColimitsOfSizeOfUnivLE [UnivLE.{v₂, v₁}] [UnivLE.{u₂, u₁}] [HasColimitsOfSize.{v₁, u₁} C] : HasColimitsOfSize.{v₂, u₂} C where has_colimits_of_shape J {_} := hasColimitsOfShape_of_equivalence ((ShrinkHoms.equivalence J).trans <| Shrink.equivalence _).symm /-- `hasColimitsOfSizeShrink.{v u} C` tries to obtain `HasColimitsOfSize.{v u} C` from some other `HasColimitsOfSize C`. -/ theorem hasColimitsOfSizeShrink [HasColimitsOfSize.{max v₁ v₂, max u₁ u₂} C] : HasColimitsOfSize.{v₁, u₁} C := hasColimitsOfSizeOfUnivLE.{max v₁ v₂, max u₁ u₂} C instance (priority := 100) hasSmallestColimitsOfHasColimits [HasColimits C] : HasColimitsOfSize.{0, 0} C := hasColimitsOfSizeShrink.{0, 0} C end Colimit
section Opposite
Mathlib/CategoryTheory/Limits/HasLimits.lean
1,100
1,102
/- 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.AlgebraicGeometry.Gluing import Mathlib.CategoryTheory.Limits.Opposites import Mathlib.AlgebraicGeometry.AffineScheme import Mathlib.CategoryTheory.Limits.Shapes.Diagonal import Mathlib.CategoryTheory.ChosenFiniteProducts.Over /-! # Fibred products of schemes In this file we construct the fibred product of schemes via gluing. We roughly follow [har77] Theorem 3.3. In particular, the main construction is to show that for an open cover `{ Uᵢ }` of `X`, if there exist fibred products `Uᵢ ×[Z] Y` for each `i`, then there exists a fibred product `X ×[Z] Y`. Then, for constructing the fibred product for arbitrary schemes `X, Y, Z`, we can use the construction to reduce to the case where `X, Y, Z` are all affine, where fibred products are constructed via tensor products. -/ universe v u noncomputable section open CategoryTheory CategoryTheory.Limits AlgebraicGeometry namespace AlgebraicGeometry.Scheme namespace Pullback variable {C : Type u} [Category.{v} C] variable {X Y Z : Scheme.{u}} (𝒰 : OpenCover.{u} X) (f : X ⟶ Z) (g : Y ⟶ Z) variable [∀ i, HasPullback (𝒰.map i ≫ f) g] /-- The intersection of `Uᵢ ×[Z] Y` and `Uⱼ ×[Z] Y` is given by (Uᵢ ×[Z] Y) ×[X] Uⱼ -/ def v (i j : 𝒰.J) : Scheme := pullback ((pullback.fst (𝒰.map i ≫ f) g) ≫ 𝒰.map i) (𝒰.map j) /-- The canonical transition map `(Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ (Uⱼ ×[Z] Y) ×[X] Uᵢ` given by the fact that pullbacks are associative and symmetric. -/ def t (i j : 𝒰.J) : v 𝒰 f g i j ⟶ v 𝒰 f g j i := by have : HasPullback (pullback.snd _ _ ≫ 𝒰.map i ≫ f) g := hasPullback_assoc_symm (𝒰.map j) (𝒰.map i) (𝒰.map i ≫ f) g have : HasPullback (pullback.snd _ _ ≫ 𝒰.map j ≫ f) g := hasPullback_assoc_symm (𝒰.map i) (𝒰.map j) (𝒰.map j ≫ f) g refine (pullbackSymmetry ..).hom ≫ (pullbackAssoc ..).inv ≫ ?_ refine ?_ ≫ (pullbackAssoc ..).hom ≫ (pullbackSymmetry ..).hom refine pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (𝟙 _) (𝟙 _) ?_ ?_ · rw [pullbackSymmetry_hom_comp_snd_assoc, pullback.condition_assoc, Category.comp_id] · rw [Category.comp_id, Category.id_comp] @[simp, reassoc] theorem t_fst_fst (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_inv_fst_fst, pullbackSymmetry_hom_comp_fst] @[simp, reassoc] theorem t_fst_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackAssoc_hom_snd_snd, pullback.lift_snd, Category.comp_id, pullbackAssoc_inv_snd, pullbackSymmetry_hom_comp_snd_assoc] @[simp, reassoc] theorem t_snd (i j : 𝒰.J) : t 𝒰 f g i j ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t, Category.assoc, pullbackSymmetry_hom_comp_snd, pullbackAssoc_hom_fst, pullback.lift_fst_assoc, pullbackSymmetry_hom_comp_fst, pullbackAssoc_inv_fst_snd, pullbackSymmetry_hom_comp_snd_assoc] theorem t_id (i : 𝒰.J) : t 𝒰 f g i i = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, Category.assoc, t_fst_fst] · simp only [Category.assoc, t_fst_snd] · rw [← cancel_mono (𝒰.map i)]; simp only [pullback.condition, t_snd, Category.assoc] /-- The inclusion map of `V i j = (Uᵢ ×[Z] Y) ×[X] Uⱼ ⟶ Uᵢ ×[Z] Y` -/ abbrev fV (i j : 𝒰.J) : v 𝒰 f g i j ⟶ pullback (𝒰.map i ≫ f) g := pullback.fst _ _ /-- The map `((Xᵢ ×[Z] Y) ×[X] Xⱼ) ×[Xᵢ ×[Z] Y] ((Xᵢ ×[Z] Y) ×[X] Xₖ)` ⟶ `((Xⱼ ×[Z] Y) ×[X] Xₖ) ×[Xⱼ ×[Z] Y] ((Xⱼ ×[Z] Y) ×[X] Xᵢ)` needed for gluing -/ def t' (i j k : 𝒰.J) : pullback (fV 𝒰 f g i j) (fV 𝒰 f g i k) ⟶ pullback (fV 𝒰 f g j k) (fV 𝒰 f g j i) := by refine (pullbackRightPullbackFstIso ..).hom ≫ ?_ refine ?_ ≫ (pullbackSymmetry _ _).hom refine ?_ ≫ (pullbackRightPullbackFstIso ..).inv refine pullback.map _ _ _ _ (t 𝒰 f g i j) (𝟙 _) (𝟙 _) ?_ ?_ · simp_rw [Category.comp_id, t_fst_fst_assoc, ← pullback.condition] · rw [Category.comp_id, Category.id_comp] @[simp, reassoc] theorem t'_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_fst_assoc, pullbackRightPullbackFstIso_inv_snd_snd, pullback.lift_snd, Category.comp_id, pullbackRightPullbackFstIso_hom_snd] @[simp, reassoc] theorem t'_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_fst, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_fst_snd, pullbackRightPullbackFstIso_hom_fst_assoc] @[simp, reassoc] theorem t'_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t', Category.assoc, pullbackSymmetry_hom_comp_snd_assoc, pullbackRightPullbackFstIso_inv_fst_assoc, pullback.lift_fst_assoc, t_snd, pullbackRightPullbackFstIso_hom_fst_assoc] theorem cocycle_fst_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by simp only [t'_fst_fst_fst, t'_fst_snd, t'_snd_snd] theorem cocycle_fst_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t'_fst_fst_snd] theorem cocycle_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [t'_fst_snd, t'_snd_snd, t'_fst_fst_fst] theorem cocycle_snd_fst_fst (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.fst _ _ := by rw [← cancel_mono (𝒰.map i)] simp only [pullback.condition_assoc, t'_snd_fst_fst, t'_fst_snd, t'_snd_snd] theorem cocycle_snd_fst_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.fst _ _ ≫ pullback.snd _ _ := by simp only [pullback.condition_assoc, t'_snd_fst_snd] theorem cocycle_snd_snd (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j ≫ pullback.snd _ _ ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp only [t'_snd_snd, t'_fst_fst_fst, t'_fst_snd] -- `by tidy` should solve it, but it times out. theorem cocycle (i j k : 𝒰.J) : t' 𝒰 f g i j k ≫ t' 𝒰 f g j k i ≫ t' 𝒰 f g k i j = 𝟙 _ := by apply pullback.hom_ext <;> rw [Category.id_comp] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_fst_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_fst_snd 𝒰 f g i j k] · apply pullback.hom_ext · apply pullback.hom_ext · simp_rw [Category.assoc, cocycle_snd_fst_fst 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_fst_snd 𝒰 f g i j k] · simp_rw [Category.assoc, cocycle_snd_snd 𝒰 f g i j k] /-- Given `Uᵢ ×[Z] Y`, this is the glued fibered product `X ×[Z] Y`. -/ @[simps U V f t t', simps -isSimp J] def gluing : Scheme.GlueData.{u} where J := 𝒰.J U i := pullback (𝒰.map i ≫ f) g V := fun ⟨i, j⟩ => v 𝒰 f g i j -- `p⁻¹(Uᵢ ∩ Uⱼ)` where `p : Uᵢ ×[Z] Y ⟶ Uᵢ ⟶ X`. f _ _ := pullback.fst _ _ f_id _ := inferInstance f_open := inferInstance t i j := t 𝒰 f g i j t_id i := t_id 𝒰 f g i t' i j k := t' 𝒰 f g i j k t_fac i j k := by apply pullback.hom_ext on_goal 1 => apply pullback.hom_ext all_goals simp only [t'_snd_fst_fst, t'_snd_fst_snd, t'_snd_snd, t_fst_fst, t_fst_snd, t_snd, Category.assoc] cocycle i j k := cocycle 𝒰 f g i j k @[simp] lemma gluing_ι (j : 𝒰.J) : (gluing 𝒰 f g).ι j = Multicoequalizer.π (gluing 𝒰 f g).diagram j := rfl /-- The first projection from the glued scheme into `X`. -/ def p1 : (gluing 𝒰 f g).glued ⟶ X := by apply Multicoequalizer.desc (gluing 𝒰 f g).diagram _ fun i ↦ pullback.fst _ _ ≫ 𝒰.map i simp [t_fst_fst_assoc, ← pullback.condition] /-- The second projection from the glued scheme into `Y`. -/ def p2 : (gluing 𝒰 f g).glued ⟶ Y := by apply Multicoequalizer.desc _ _ fun i ↦ pullback.snd _ _ simp [t_fst_snd] theorem p_comm : p1 𝒰 f g ≫ f = p2 𝒰 f g ≫ g := by apply Multicoequalizer.hom_ext simp [p1, p2, pullback.condition] variable (s : PullbackCone f g) /-- (Implementation) The canonical map `(s.X ×[X] Uᵢ) ×[s.X] (s.X ×[X] Uⱼ) ⟶ (Uᵢ ×[Z] Y) ×[X] Uⱼ` This is used in `gluedLift`. -/ def gluedLiftPullbackMap (i j : 𝒰.J) : pullback ((𝒰.pullbackCover s.fst).map i) ((𝒰.pullbackCover s.fst).map j) ⟶ (gluing 𝒰 f g).V ⟨i, j⟩ := by refine (pullbackRightPullbackFstIso _ _ _).hom ≫ ?_ refine pullback.map _ _ _ _ ?_ (𝟙 _) (𝟙 _) ?_ ?_ · exact (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition · simpa using pullback.condition · simp only [Category.comp_id, Category.id_comp] @[reassoc] theorem gluedLiftPullbackMap_fst (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.fst _ _ = pullback.fst _ _ ≫ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition := by simp [gluedLiftPullbackMap] @[reassoc] theorem gluedLiftPullbackMap_snd (i j : 𝒰.J) : gluedLiftPullbackMap 𝒰 f g s i j ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by simp [gluedLiftPullbackMap] /-- The lifted map `s.X ⟶ (gluing 𝒰 f g).glued` in order to show that `(gluing 𝒰 f g).glued` is indeed the pullback. Given a pullback cone `s`, we have the maps `s.fst ⁻¹' Uᵢ ⟶ Uᵢ` and `s.fst ⁻¹' Uᵢ ⟶ s.X ⟶ Y` that we may lift to a map `s.fst ⁻¹' Uᵢ ⟶ Uᵢ ×[Z] Y`. to glue these into a map `s.X ⟶ Uᵢ ×[Z] Y`, we need to show that the maps agree on `(s.fst ⁻¹' Uᵢ) ×[s.X] (s.fst ⁻¹' Uⱼ) ⟶ Uᵢ ×[Z] Y`. This is achieved by showing that both of these maps factors through `gluedLiftPullbackMap`. -/ def gluedLift : s.pt ⟶ (gluing 𝒰 f g).glued := by fapply (𝒰.pullbackCover s.fst).glueMorphisms · exact fun i ↦ (pullbackSymmetry _ _).hom ≫ pullback.map _ _ _ _ (𝟙 _) s.snd f (Category.id_comp _).symm s.condition ≫ (gluing 𝒰 f g).ι i intro i j rw [← gluedLiftPullbackMap_fst_assoc, ← gluing_f, ← (gluing 𝒰 f g).glue_condition i j, gluing_t, gluing_f] simp_rw [← Category.assoc] congr 1
apply pullback.hom_ext <;> simp_rw [Category.assoc] · rw [t_fst_fst, gluedLiftPullbackMap_snd] congr 1
Mathlib/AlgebraicGeometry/Pullbacks.lean
281
283
/- Copyright (c) 2020 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa, Alex Meiburg -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Degree.Monomial /-! # Erase the leading term of a univariate polynomial ## Definition * `eraseLead f`: the polynomial `f - leading term of f` `eraseLead` serves as reduction step in an induction, shaving off one monomial from a polynomial. The definition is set up so that it does not mention subtraction in the definition, and thus works for polynomials over semirings as well as rings. -/ noncomputable section open Polynomial open Polynomial Finset namespace Polynomial variable {R : Type*} [Semiring R] {f : R[X]} /-- `eraseLead f` for a polynomial `f` is the polynomial obtained by subtracting from `f` the leading term of `f`. -/ def eraseLead (f : R[X]) : R[X] := Polynomial.erase f.natDegree f section EraseLead theorem eraseLead_support (f : R[X]) : f.eraseLead.support = f.support.erase f.natDegree := by simp only [eraseLead, support_erase] theorem eraseLead_coeff (i : ℕ) : f.eraseLead.coeff i = if i = f.natDegree then 0 else f.coeff i := by simp only [eraseLead, coeff_erase] @[simp] theorem eraseLead_coeff_natDegree : f.eraseLead.coeff f.natDegree = 0 := by simp [eraseLead_coeff] theorem eraseLead_coeff_of_ne (i : ℕ) (hi : i ≠ f.natDegree) : f.eraseLead.coeff i = f.coeff i := by simp [eraseLead_coeff, hi] @[simp] theorem eraseLead_zero : eraseLead (0 : R[X]) = 0 := by simp only [eraseLead, erase_zero] @[simp] theorem eraseLead_add_monomial_natDegree_leadingCoeff (f : R[X]) : f.eraseLead + monomial f.natDegree f.leadingCoeff = f := (add_comm _ _).trans (f.monomial_add_erase _) @[simp] theorem eraseLead_add_C_mul_X_pow (f : R[X]) : f.eraseLead + C f.leadingCoeff * X ^ f.natDegree = f := by rw [C_mul_X_pow_eq_monomial, eraseLead_add_monomial_natDegree_leadingCoeff] @[simp] theorem self_sub_monomial_natDegree_leadingCoeff {R : Type*} [Ring R] (f : R[X]) : f - monomial f.natDegree f.leadingCoeff = f.eraseLead := (eq_sub_iff_add_eq.mpr (eraseLead_add_monomial_natDegree_leadingCoeff f)).symm @[simp] theorem self_sub_C_mul_X_pow {R : Type*} [Ring R] (f : R[X]) : f - C f.leadingCoeff * X ^ f.natDegree = f.eraseLead := by rw [C_mul_X_pow_eq_monomial, self_sub_monomial_natDegree_leadingCoeff] theorem eraseLead_ne_zero (f0 : 2 ≤ #f.support) : eraseLead f ≠ 0 := by rw [Ne, ← card_support_eq_zero, eraseLead_support] exact (zero_lt_one.trans_le <| (tsub_le_tsub_right f0 1).trans Finset.pred_card_le_card_erase).ne.symm theorem lt_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) : a < f.natDegree := by rw [eraseLead_support, mem_erase] at h exact (le_natDegree_of_mem_supp a h.2).lt_of_ne h.1 theorem ne_natDegree_of_mem_eraseLead_support {a : ℕ} (h : a ∈ (eraseLead f).support) : a ≠ f.natDegree := (lt_natDegree_of_mem_eraseLead_support h).ne theorem natDegree_not_mem_eraseLead_support : f.natDegree ∉ (eraseLead f).support := fun h => ne_natDegree_of_mem_eraseLead_support h rfl theorem eraseLead_support_card_lt (h : f ≠ 0) : #(eraseLead f).support < #f.support := by rw [eraseLead_support] exact card_lt_card (erase_ssubset <| natDegree_mem_support_of_nonzero h) theorem card_support_eraseLead_add_one (h : f ≠ 0) : #f.eraseLead.support + 1 = #f.support := by set c := #f.support with hc cases h₁ : c case zero => by_contra exact h (card_support_eq_zero.mp h₁) case succ => rw [eraseLead_support, card_erase_of_mem (natDegree_mem_support_of_nonzero h), ← hc, h₁] rfl @[simp] theorem card_support_eraseLead : #f.eraseLead.support = #f.support - 1 := by by_cases hf : f = 0 · rw [hf, eraseLead_zero, support_zero, card_empty] · rw [← card_support_eraseLead_add_one hf, add_tsub_cancel_right] theorem card_support_eraseLead' {c : ℕ} (fc : #f.support = c + 1) : #f.eraseLead.support = c := by
rw [card_support_eraseLead, fc, add_tsub_cancel_right] theorem card_support_eq_one_of_eraseLead_eq_zero (h₀ : f ≠ 0) (h₁ : f.eraseLead = 0) : #f.support = 1 := (card_support_eq_zero.mpr h₁ ▸ card_support_eraseLead_add_one h₀).symm theorem card_support_le_one_of_eraseLead_eq_zero (h : f.eraseLead = 0) : #f.support ≤ 1 := by by_cases hpz : f = 0 case pos => simp [hpz] case neg => exact le_of_eq (card_support_eq_one_of_eraseLead_eq_zero hpz h)
Mathlib/Algebra/Polynomial/EraseLead.lean
115
124
/- 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.Group.Subgroup.Ker import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Free groups This file defines free groups over a type. Furthermore, it is shown that the free group construction is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`. ## Main definitions * `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type `α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`. * `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`. * `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`. * `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G` given a group `G` and a function `f : α → G`. ## Main statements * `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word reduction (also known as Newman's diamond lemma). * `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type is isomorphic to the integers. * The free group construction is an instance of a monad. ## Implementation details First we introduce the one step reduction relation `FreeGroup.Red.Step`: `w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans` and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient over `FreeGroup.Red.Step`. For the additive version we introduce the same relation under a different name so that we can distinguish the quotient types more easily. ## Tags free group, Newman's diamond lemma, Church-Rosser theorem -/ open Relation open scoped List universe u v w variable {α : Type u} attribute [local simp] List.append_eq_has_append -- Porting note: to_additive.map_namespace is not supported yet -- worked around it by putting a few extra manual mappings (but not too many all in all) -- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup /-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/ inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeAddGroup.Red.Step.not /-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/ @[to_additive FreeAddGroup.Red.Step] inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop | not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂) attribute [simp] FreeGroup.Red.Step.not namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- Reflexive-transitive closure of `Red.Step` -/ @[to_additive FreeAddGroup.Red "Reflexive-transitive closure of `Red.Step`"] def Red : List (α × Bool) → List (α × Bool) → Prop := ReflTransGen Red.Step @[to_additive (attr := refl)] theorem Red.refl : Red L L := ReflTransGen.refl @[to_additive (attr := trans)] theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ := ReflTransGen.trans namespace Red /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/ @[to_additive "Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄`"] theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length | _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl @[to_additive (attr := simp)] theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by cases b <;> exact Step.not @[to_additive (attr := simp)] theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L := @Step.not _ [] _ _ _ @[to_additive (attr := simp)] theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L := @Red.Step.not_rev _ [] _ _ _ @[to_additive] theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃) | _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor @[to_additive] theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) := @Step.append_left _ [x] _ _ H @[to_additive] theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃) | _, _, _, Red.Step.not => by simp @[to_additive] theorem not_step_nil : ¬Step [] L := by generalize h' : [] = L' intro h rcases h with - | ⟨L₁, L₂⟩ simp [List.nil_eq_append_iff] at h' @[to_additive] theorem Step.cons_left_iff {a : α} {b : Bool} : Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by constructor · generalize hL : ((a, b) :: L₁ : List _) = L rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all · rintro (⟨L, h, rfl⟩ | rfl) · exact Step.cons h · exact Step.cons_not @[to_additive] theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L | (a, b) => by simp [Step.cons_left_iff, not_step_nil] @[to_additive] theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by simp +contextual [Step.cons_left_iff, iff_def, or_imp] @[to_additive] theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂ | [] => by simp | p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff] @[to_additive] theorem Step.diamond_aux : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2}, L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ → L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅ | [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp | [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp | [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩ | (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩ | (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H => let ⟨H1, H2⟩ := List.cons.inj H match Step.diamond_aux H2 with | Or.inl H3 => Or.inl <| by simp [H1, H3] | Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩ @[to_additive] theorem Step.diamond : ∀ {L₁ L₂ L₃ L₄ : List (α × Bool)}, Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅ | _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H @[to_additive] theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ := ReflTransGen.single /-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma. -/ @[to_additive "**Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4` respectively. This is also known as Newman's diamond lemma."] theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ := Relation.church_rosser fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩ @[to_additive] theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) := ReflTransGen.lift (List.cons p) fun _ _ => Step.cons @[to_additive] theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ := Iff.intro (by generalize eq₁ : (p :: L₁ : List _) = LL₁ generalize eq₂ : (p :: L₂ : List _) = LL₂ intro h induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with | refl => subst_vars cases eq₂ constructor | head h₁₂ h ih => subst_vars obtain ⟨a, b⟩ := p rw [Step.cons_left_iff] at h₁₂ rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl) · exact (ih rfl rfl).head h₁₂ · exact (cons_cons h).tail Step.cons_not_rev) cons_cons @[to_additive] theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂ | [] => Iff.rfl | p :: L => by simp [append_append_left_iff L, cons_cons_iff] @[to_additive] theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) := (h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂) @[to_additive] theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ := Iff.intro (by generalize eq : L₁ ++ L₂ = L₁₂ intro h induction h generalizing L₁ L₂ with | refl => exact ⟨_, _, eq.symm, by rfl, by rfl⟩ | tail hLL' h ih => obtain @⟨s, e, a, b⟩ := h rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩) · have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩ · have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) := by simp rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩ exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩) fun ⟨_, _, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄ /-- The empty word `[]` only reduces to itself. -/ @[to_additive "The empty word `[]` only reduces to itself."] theorem nil_iff : Red [] L ↔ L = [] := reflTransGen_iff_eq fun _ => Red.not_step_nil /-- A letter only reduces to itself. -/ @[to_additive "A letter only reduces to itself."] theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] := reflTransGen_iff_eq fun _ => not_step_singleton /-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces to `x⁻¹` -/ @[to_additive "If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w` reduces to `-x`."] theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] := Iff.intro (fun h => by have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂ rw [singleton_iff] at h₁ subst L' assumption) fun h => (cons_cons h).tail Step.cons_not @[to_additive] theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) : Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by apply reflTransGen_iff_eq generalize eq : [(x1, not b1), (x2, b2)] = L' intro L h' cases h' simp only [List.cons_eq_append_iff, List.cons.injEq, Prod.mk.injEq, and_false, List.nil_eq_append_iff, exists_const, or_self, or_false, List.cons_ne_nil] at eq rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩ simp at h /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then `w₁` reduces to `x⁻¹yw₂`. -/ @[to_additive "If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁` reduces to `y + w₂`, then `w₁` reduces to `-x + y + w₂`."] theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2)) (H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2 rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩ · simp [nil_iff] at h₁ · cases eq show Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂) apply append_append _ h₂ have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁ have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩ rw [red_iff_irreducible H1] at h₁ rwa [h₁] at h₂ open List -- for <+ notation @[to_additive] theorem Step.sublist (H : Red.Step L₁ L₂) : L₂ <+ L₁ := by cases H; simp /-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/ @[to_additive "If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`."] protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ := @reflTransGen_of_transitive_reflexive _ (fun a b => b <+ a) _ _ _ (fun l => List.Sublist.refl l) (fun _a _b _c hab hbc => List.Sublist.trans hbc hab) (fun _ _ => Red.Step.sublist) @[to_additive] theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length := h.sublist.length_le @[to_additive] theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → sizeOf L₂ < sizeOf L₁ | _, _, @Step.not _ L1 L2 x b => by induction L1 with | nil => dsimp omega | cons hd tl ih => dsimp exact Nat.add_lt_add_left ih _ @[to_additive] theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by induction h with | refl => exact ⟨0, rfl⟩ | tail _h₁₂ h₂₃ ih => rcases ih with ⟨n, eq⟩ exists 1 + n simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc] @[to_additive] theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ := h₂₁.sublist.antisymm h₁₂.sublist end Red @[to_additive FreeAddGroup.equivalence_join_red] theorem equivalence_join_red : Equivalence (Join (@Red α)) := equivalence_join_reflTransGen fun _ b c hab hac => match b, c, Red.Step.diamond hab hac rfl with | b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩ | _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩ @[to_additive FreeAddGroup.join_red_of_step] theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ := join_of_single reflexive_reflTransGen h.to_red @[to_additive FreeAddGroup.eqvGen_step_iff_join_red] theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ := Iff.intro (fun h => have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step equivalence_join_red.eqvGen_iff.1 this) (join_of_equivalence (Relation.EqvGen.is_equivalence _) fun _ _ => reflTransGen_of_equivalence (Relation.EqvGen.is_equivalence _) EqvGen.rel) end FreeGroup /-- If `α` is a type, then `FreeGroup α` is the free group generated by `α`. This is a group equipped with a function `FreeGroup.of : α → FreeGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeGroup.of` and a unique group homomorphism `FreeGroup.lift f : FreeGroup α →* G`. A typical element of `FreeGroup α` is a formal product of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `x⁻¹ * y * y * x * y⁻¹` is a "typical" element of `FreeGroup α`. In particular if `α` is empty then `FreeGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeGroup α` is isomorphic to `Multiplicative ℤ`. If `α` has two or more terms then `FreeGroup α` is not commutative. -/ @[to_additive " If `α` is a type, then `FreeAddGroup α` is the free additive group generated by `α`. This is a group equipped with a function `FreeAddGroup.of : α → FreeAddGroup α` which has the following universal property: if `G` is any group, and `f : α → G` is any function, then this function is the composite of `FreeAddGroup.of` and a unique group homomorphism `FreeAddGroup.lift f : FreeAddGroup α →+ G`. A typical element of `FreeAddGroup α` is a formal sum of elements of `α` and their formal inverses, quotient by reduction. For example if `x` and `y` are terms of type `α` then `-x + y + y + x + -y` is a \"typical\" element of `FreeAddGroup α`. In particular if `α` is empty then `FreeAddGroup α` is isomorphic to the trivial group, and if `α` has one term then `FreeAddGroup α` is isomorphic to `ℤ`. If `α` has two or more terms then `FreeAddGroup α` is not commutative. "] def FreeGroup (α : Type u) : Type u := Quot <| @FreeGroup.Red.Step α namespace FreeGroup variable {L L₁ L₂ L₃ L₄ : List (α × Bool)} /-- The canonical map from `List (α × Bool)` to the free group on `α`. -/ @[to_additive "The canonical map from `List (α × Bool)` to the free additive group on `α`."] def mk (L : List (α × Bool)) : FreeGroup α := Quot.mk Red.Step L @[to_additive (attr := simp)] theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L := rfl @[to_additive (attr := simp)] theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L := rfl @[to_additive (attr := simp)] theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β) (H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L := rfl open scoped Relator in @[to_additive (attr := simp)] theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool)) (H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) := rfl @[to_additive] instance : One (FreeGroup α) := ⟨mk []⟩ @[to_additive] theorem one_eq_mk : (1 : FreeGroup α) = mk [] := rfl @[to_additive] instance : Inhabited (FreeGroup α) := ⟨1⟩ @[to_additive] instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance @[to_additive] instance : Mul (FreeGroup α) := ⟨fun x y => Quot.liftOn x (fun L₁ => Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H => Quot.sound <| Red.Step.append_left H) fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩ @[to_additive (attr := simp)] theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) := rfl /-- Transform a word representing a free group element into a word representing its inverse. -/ @[to_additive "Transform a word representing a free group element into a word representing its negative."] def invRev (w : List (α × Bool)) : List (α × Bool) := (List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse @[to_additive (attr := simp)] theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev] @[to_additive (attr := simp)] theorem invRev_invRev : invRev (invRev L₁) = L₁ := by simp [invRev, List.map_reverse, Function.comp_def] @[to_additive (attr := simp)] theorem invRev_empty : invRev ([] : List (α × Bool)) = [] := rfl @[to_additive (attr := simp)] theorem invRev_append : invRev (L₁ ++ L₂) = invRev L₂ ++ invRev L₁ := by simp [invRev] @[to_additive] theorem invRev_cons {a : (α × Bool)} : invRev (a :: L) = invRev L ++ invRev [a] := by simp [invRev] @[to_additive] theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev @[to_additive] theorem invRev_injective : Function.Injective (@invRev α) := invRev_involutive.injective @[to_additive] theorem invRev_surjective : Function.Surjective (@invRev α) := invRev_involutive.surjective @[to_additive] theorem invRev_bijective : Function.Bijective (@invRev α) := invRev_involutive.bijective @[to_additive] instance : Inv (FreeGroup α) := ⟨Quot.map invRev (by intro a b h cases h simp [invRev])⟩ @[to_additive (attr := simp)] theorem inv_mk : (mk L)⁻¹ = mk (invRev L) := rfl @[to_additive] theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by obtain ⟨a, b, x, y⟩ := h simp [FreeGroup.invRev] @[to_additive] theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) := Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h @[to_additive (attr := simp)] theorem Red.step_invRev_iff : Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive (attr := simp)] theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ := ⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩ @[to_additive] instance : Group (FreeGroup α) where mul := (· * ·) one := 1 inv := Inv.inv mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp one_mul := by rintro ⟨L⟩; rfl mul_one := by rintro ⟨L⟩; simp [one_eq_mk] inv_mul_cancel := by rintro ⟨L⟩ exact List.recOn L rfl fun ⟨x, b⟩ tl ih => Eq.trans (Quot.sound <| by simp [invRev, one_eq_mk]) ih @[to_additive (attr := simp)] theorem pow_mk (n : ℕ) : mk L ^ n = mk (List.flatten <| List.replicate n L) := match n with | 0 => rfl | n + 1 => by rw [pow_succ', pow_mk, mul_mk, List.replicate_succ, List.flatten_cons] /-- `of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element. -/ @[to_additive "`of` is the canonical injection from the type to the free group over that type by sending each element to the equivalence class of the letter that is the element."] def of (x : α) : FreeGroup α := mk [(x, true)] @[to_additive] theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ := calc mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro Quot.eqvGen_exact Quot.eqvGen_sound _ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red /-- The canonical map from the type to the free group is an injection. -/ @[to_additive "The canonical map from the type to the additive free group is an injection."] theorem of_injective : Function.Injective (@of α) := fun _ _ H => by let ⟨L₁, hx, hy⟩ := Red.exact.1 H simp [Red.singleton_iff] at hx hy; aesop section lift variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α} /-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/ @[to_additive "Given `f : α → β` with `β` an additive group, the canonical map `List (α × Bool) → β`"] def Lift.aux : List (α × Bool) → β := fun L => List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹ @[to_additive] theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by obtain @⟨_, _, _, b⟩ := H; cases b <;> simp [Lift.aux] /-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to `β` -/ @[to_additive (attr := simps symm_apply) "If `β` is an additive group, then any function from `α` to `β` extends uniquely to an additive group homomorphism from the free additive group over `α` to `β`"] def lift : (α → β) ≃ (FreeGroup α →* β) where toFun f := MonoidHom.mk' (Quot.lift (Lift.aux f) fun _ _ => Red.Step.lift) <| by rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux] invFun g := g ∘ of left_inv f := List.prod_singleton right_inv g := MonoidHom.ext <| by rintro ⟨L⟩ exact List.recOn L (g.map_one.symm) (by rintro ⟨x, _ | _⟩ t (ih : _ = g (mk t)) · show _ = g ((of x)⁻¹ * mk t) simpa [Lift.aux] using ih · show _ = g (of x * mk t) simpa [Lift.aux] using ih) variable {f} @[to_additive (attr := simp)] theorem lift.mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) := rfl @[to_additive (attr := simp)] theorem lift.of {x} : lift f (of x) = f x := List.prod_singleton @[to_additive] theorem lift.unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} : g x = FreeGroup.lift f x := DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x /-- Two homomorphisms out of a free group are equal if they are equal on generators. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext) "Two homomorphisms out of a free additive group are equal if they are equal on generators. See note [partially-applied ext lemmas]."] theorem ext_hom {G : Type*} [Group G] (f g : FreeGroup α →* G) (h : ∀ a, f (of a) = g (of a)) : f = g := lift.symm.injective <| funext h @[to_additive] theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) := lift.apply_symm_apply (MonoidHom.id _) @[to_additive] theorem lift.of_eq (x : FreeGroup α) : lift FreeGroup.of x = x := DFunLike.congr_fun (lift_of_eq_id α) x @[to_additive] theorem lift.range_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by rintro _ ⟨⟨L⟩, rfl⟩ exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦ Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih) (by simpa using s.mul_mem (H ⟨x, rfl⟩) ih) @[to_additive] theorem lift.range_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by apply le_antisymm (lift.range_le Subgroup.subset_closure) rw [Subgroup.closure_le] rintro _ ⟨a, rfl⟩ exact ⟨FreeGroup.of a, by simp only [lift.of]⟩ /-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the set of generators equals `⊤`. -/ @[to_additive (attr := simp)] theorem closure_range_of (α) : Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by rw [← lift.range_eq_closure, lift_of_eq_id] exact MonoidHom.range_eq_top.2 Function.surjective_id end lift section Map variable {β : Type v} (f : α → β) {x y : FreeGroup α} /-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over `α` to the free group over `β`. -/ @[to_additive "Any function from `α` to `β` extends uniquely to an additive group homomorphism from the additive free group over `α` to the additive free group over `β`."] def map : FreeGroup α →* FreeGroup β := MonoidHom.mk' (Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp) (by rintro ⟨L₁⟩ ⟨L₂⟩; simp) variable {f} @[to_additive (attr := simp)] theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) := rfl @[to_additive (attr := simp)] theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id'] @[to_additive (attr := simp)] theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x := map.id x @[to_additive] theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) : map g (map f x) = map (g ∘ f) x := by rcases x with ⟨L⟩; simp [Function.comp_def] @[to_additive (attr := simp)] theorem map.of {x} : map f (of x) = of (f x) := rfl @[to_additive] theorem map.unique (g : FreeGroup α →* FreeGroup β) (hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) : ∀ {x}, g x = map f x := by rintro ⟨L⟩ exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) => Bool.recOn b (show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) = FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by simp [g.map_mul, g.map_inv, hg, ih]) (show g (FreeGroup.of x * FreeGroup.mk t) = FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih]) @[to_additive] theorem map_eq_lift : map f x = lift (of ∘ f) x := Eq.symm <| map.unique _ fun x => by simp /-- Equivalent types give rise to multiplicatively equivalent free groups. The converse can be found in `Mathlib.GroupTheory.FreeGroup.GeneratorEquiv`, as `Equiv.ofFreeGroupEquiv`. -/ @[to_additive (attr := simps apply) "Equivalent types give rise to additively equivalent additive free groups."] def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where toFun := map e invFun := map e.symm left_inv x := by simp [Function.comp, map.comp] right_inv x := by simp [Function.comp, map.comp] map_mul' := MonoidHom.map_mul _ @[to_additive (attr := simp)] theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ := MulEquiv.ext map.id @[to_additive (attr := simp)] theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm := rfl @[to_additive] theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) : (freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) := MulEquiv.ext <| map.comp _ _ end Map section Prod variable [Group α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/ @[to_additive "If `α` is an additive group, then any function from `α` to `α` extends uniquely to an additive homomorphism from the additive free group over `α` to `α`."] def prod : FreeGroup α →* α := lift id variable {x y} @[to_additive (attr := simp)] theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) := rfl @[to_additive (attr := simp)] theorem prod.of {x : α} : prod (of x) = x := lift.of @[to_additive] theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x := lift.unique g hg end Prod @[to_additive] theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by rw [← lift.unique (prod.comp (map f)) (by simp), MonoidHom.coe_comp, Function.comp_apply] section Sum variable [AddGroup α] (x y : FreeGroup α) /-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the free group over `α` to `α`. This is the additive version of `Prod`. -/ def sum : α := @prod (Multiplicative _) _ x variable {x y} @[simp] theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) := rfl @[simp] theorem sum.of {x : α} : sum (of x) = x := @prod.of _ (_) _ -- note: there are no bundled homs with different notation in the domain and codomain, so we copy -- these manually @[simp] theorem sum.map_mul : sum (x * y) = sum x + sum y := (@prod (Multiplicative _) _).map_mul _ _ @[simp] theorem sum.map_one : sum (1 : FreeGroup α) = 0 := (@prod (Multiplicative _) _).map_one @[simp] theorem sum.map_inv : sum x⁻¹ = -sum x := (prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _ end Sum /-- The bijection between the free group on the empty type, and a type with one element. -/ @[to_additive "The bijection between the additive free group on the empty type, and a type with one element."] def freeGroupEmptyEquivUnit : FreeGroup Empty ≃ Unit where toFun _ := () invFun _ := 1 left_inv := by rintro ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; rfl right_inv := fun ⟨⟩ => rfl /-- The bijection between the free group on a singleton, and the integers. -/ def freeGroupUnitEquivInt : FreeGroup Unit ≃ ℤ where toFun x := sum (by revert x exact ↑(map fun _ => (1 : ℤ))) invFun x := of () ^ x left_inv := by rintro ⟨L⟩ simp only [quot_mk_eq_mk, map.mk, sum_mk, List.map_map] exact List.recOn L (by rfl) (fun ⟨⟨⟩, b⟩ tl ih => by cases b <;> simp [zpow_add] at ih ⊢ <;> rw [ih] <;> rfl) right_inv x := Int.induction_on x (by simp) (fun i ih => by simp only [zpow_natCast, map_pow, map.of] at ih simp [zpow_add, ih]) (fun i ih => by simp only [zpow_neg, zpow_natCast, map_inv, map_pow, map.of, sum.map_inv, neg_inj] at ih simp [zpow_add, ih, sub_eq_add_neg]) section Category variable {β : Type u} @[to_additive] instance : Monad FreeGroup.{u} where pure {_α} := of map {_α _β f} := map f bind {_α _β x f} := lift f x @[to_additive (attr := elab_as_elim, induction_eliminator)] protected theorem induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1) (Cp : ∀ x, C <| pure x) (Ci : ∀ x, C (pure x) → C (pure x)⁻¹) (Cm : ∀ x y, C x → C y → C (x * y)) : C z := Quot.inductionOn z fun L => List.recOn L C1 fun ⟨x, b⟩ _tl ih => Bool.recOn b (Cm _ _ (Ci _ <| Cp x) ih) (Cm _ _ (Cp x) ih) @[to_additive] theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeGroup α) = pure (f x) := map.of @[to_additive (attr := simp)] theorem map_one (f : α → β) : f <$> (1 : FreeGroup α) = 1 := (map f).map_one @[to_additive (attr := simp)] theorem map_mul (f : α → β) (x y : FreeGroup α) : f <$> (x * y) = f <$> x * f <$> y := (map f).map_mul x y @[to_additive (attr := simp)] theorem map_inv (f : α → β) (x : FreeGroup α) : f <$> x⁻¹ = (f <$> x)⁻¹ := (map f).map_inv x @[to_additive] theorem pure_bind (f : α → FreeGroup β) (x) : pure x >>= f = f x := lift.of @[to_additive (attr := simp)] theorem one_bind (f : α → FreeGroup β) : 1 >>= f = 1 := (lift f).map_one @[to_additive (attr := simp)] theorem mul_bind (f : α → FreeGroup β) (x y : FreeGroup α) : x * y >>= f = (x >>= f) * (y >>= f) := (lift f).map_mul _ _ @[to_additive (attr := simp)] theorem inv_bind (f : α → FreeGroup β) (x : FreeGroup α) : x⁻¹ >>= f = (x >>= f)⁻¹ := (lift f).map_inv _ @[to_additive] instance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk' (id_map := fun x => FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih]) fun x y ihx ihy => by rw [map_mul, ihx, ihy]) (pure_bind := fun x f => pure_bind f x) (bind_assoc := fun x => FreeGroup.induction_on x (by intros; iterate 3 rw [one_bind]) (fun x => by intros; iterate 2 rw [pure_bind]) (fun x ih => by intros; (iterate 3 rw [inv_bind]); rw [ih]) (fun x y ihx ihy => by intros; (iterate 3 rw [mul_bind]); rw [ihx, ihy])) (bind_pure_comp := fun f x => FreeGroup.induction_on x (by rw [one_bind, map_one]) (fun x => by rw [pure_bind, map_pure]) (fun x ih => by rw [inv_bind, map_inv, ih]) (fun x y ihx ihy => by rw [mul_bind, map_mul, ihx, ihy])) end Category end FreeGroup
Mathlib/GroupTheory/FreeGroup/Basic.lean
1,193
1,197
/- 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.Ordinal.Family import Mathlib.Tactic.Abel /-! # Natural operations on ordinals The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `Game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. ## Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `Ordinal`. ## Todo - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ universe u v open Function Order Set noncomputable section /-! ### Basic casts between `Ordinal` and `NatOrdinal` -/ /-- A type synonym for ordinals with natural addition and multiplication. -/ def NatOrdinal : Type _ := Ordinal deriving Zero, Inhabited, One, WellFoundedRelation -- The `LinearOrder, `SuccOrder` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance NatOrdinal.instLinearOrder : LinearOrder NatOrdinal := Ordinal.instLinearOrder instance NatOrdinal.instSuccOrder : SuccOrder NatOrdinal := Ordinal.instSuccOrder instance NatOrdinal.instOrderBot : OrderBot NatOrdinal := Ordinal.instOrderBot instance NatOrdinal.instNoMaxOrder : NoMaxOrder NatOrdinal := Ordinal.instNoMaxOrder instance NatOrdinal.instZeroLEOneClass : ZeroLEOneClass NatOrdinal := Ordinal.instZeroLEOneClass instance NatOrdinal.instNeZeroOne : NeZero (1 : NatOrdinal) := Ordinal.instNeZeroOne instance NatOrdinal.uncountable : Uncountable NatOrdinal := Ordinal.uncountable /-- The identity function between `Ordinal` and `NatOrdinal`. -/ @[match_pattern] def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal := OrderIso.refl _ /-- The identity function between `NatOrdinal` and `Ordinal`. -/ @[match_pattern] def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal := OrderIso.refl _ namespace NatOrdinal open Ordinal @[simp] theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal := rfl @[simp] theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : a.toOrdinal.toNatOrdinal = a := rfl theorem lt_wf : @WellFounded NatOrdinal (· < ·) := Ordinal.lt_wf instance : WellFoundedLT NatOrdinal := Ordinal.wellFoundedLT instance : ConditionallyCompleteLinearOrderBot NatOrdinal := WellFoundedLT.conditionallyCompleteLinearOrderBot _ @[simp] theorem bot_eq_zero : (⊥ : NatOrdinal) = 0 := rfl @[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl @[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl @[simp] theorem toOrdinal_eq_zero {a} : toOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toOrdinal_eq_one {a} : toOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toOrdinal_max (a b : NatOrdinal) : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) := rfl @[simp] theorem toOrdinal_min (a b : NatOrdinal) : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) := rfl theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) := rfl @[simp] theorem zero_le (o : NatOrdinal) : 0 ≤ o := Ordinal.zero_le o theorem not_lt_zero (o : NatOrdinal) : ¬ o < 0 := Ordinal.not_lt_zero o @[simp] theorem lt_one_iff_zero {o : NatOrdinal} : o < 1 ↔ o = 0 := Ordinal.lt_one_iff_zero /-- A recursor for `NatOrdinal`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {β : NatOrdinal → Sort*} (h : ∀ a, β (toNatOrdinal a)) : ∀ a, β a := fun a => h (toOrdinal a) /-- `Ordinal.induction` but for `NatOrdinal`. -/ theorem induction {p : NatOrdinal → Prop} : ∀ (i) (_ : ∀ j, (∀ k, k < j → p k) → p j), p i := Ordinal.induction instance small_Iio (a : NatOrdinal.{u}) : Small.{u} (Set.Iio a) := Ordinal.small_Iio a instance small_Iic (a : NatOrdinal.{u}) : Small.{u} (Set.Iic a) := Ordinal.small_Iic a instance small_Ico (a b : NatOrdinal.{u}) : Small.{u} (Set.Ico a b) := Ordinal.small_Ico a b instance small_Icc (a b : NatOrdinal.{u}) : Small.{u} (Set.Icc a b) := Ordinal.small_Icc a b instance small_Ioo (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioo a b) := Ordinal.small_Ioo a b instance small_Ioc (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioc a b) := Ordinal.small_Ioc a b end NatOrdinal namespace Ordinal variable {a b c : Ordinal.{u}} @[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl @[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : a.toNatOrdinal.toOrdinal = a := rfl @[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl @[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl @[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toNatOrdinal_max (a b : Ordinal) : toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_min (a b : Ordinal) : toNatOrdinal (min a b) = min (toNatOrdinal a) (toNatOrdinal b) := rfl /-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this guarantees we only need to open the `NaturalOps` locale once. -/ /-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd (a b : Ordinal.{u}) : Ordinal.{u} := max (⨆ x : Iio a, succ (nadd x.1 b)) (⨆ x : Iio b, succ (nadd a x.1)) termination_by (a, b) decreasing_by all_goals cases x; decreasing_tactic @[inherit_doc] scoped[NaturalOps] infixl:65 " ♯ " => Ordinal.nadd open NaturalOps /-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively defined as the least ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for all `a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and distributive (over natural addition). Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying the Cantor normal forms of `a` and `b` as if they were polynomials in `ω`. Addition of exponents is done via natural addition. -/ noncomputable def nmul (a b : Ordinal.{u}) : Ordinal.{u} := sInf {c | ∀ a' < a, ∀ b' < b, nmul a' b ♯ nmul a b' < c ♯ nmul a' b'} termination_by (a, b) @[inherit_doc] scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul /-! ### Natural addition -/ theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by rw [nadd] simp [Ordinal.lt_iSup_iff] theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by rw [← not_lt, lt_nadd_iff] simp theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c := lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩) theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a := lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩) theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_left h a).le · exact le_rfl theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := by rcases lt_or_eq_of_le h with (h | rfl) · exact (nadd_lt_nadd_right h a).le · exact le_rfl variable (a b) theorem nadd_comm (a b) : a ♯ b = b ♯ a := by rw [nadd, nadd, max_comm] congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_comm _ _) termination_by (a, b) @[deprecated "blsub will soon be deprecated" (since := "2024-11-18")] theorem blsub_nadd_of_mono {f : ∀ c < a ♯ b, Ordinal.{max u v}} (hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{u,v} _ f = max (blsub.{u, v} a fun a' ha' => f (a' ♯ b) <| nadd_lt_nadd_right ha' b) (blsub.{u, v} b fun b' hb' => f (a ♯ b') <| nadd_lt_nadd_left hb' a) := by apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _) · intro i h rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩) · exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha')) · exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb')) all_goals apply blsub_le_of_brange_subset.{u, u, v} rintro c ⟨d, hd, rfl⟩ apply mem_brange_self private theorem iSup_nadd_of_monotone {a b} (f : Ordinal.{u} → Ordinal.{u}) (h : Monotone f) : ⨆ x : Iio (a ♯ b), f x = max (⨆ a' : Iio a, f (a'.1 ♯ b)) (⨆ b' : Iio b, f (a ♯ b'.1)) := by apply (max_le _ _).antisymm' · rw [Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ obtain ⟨x, hx, hi⟩ | ⟨x, hx, hi⟩ := lt_nadd_iff.1 hi · exact le_max_of_le_left ((h hi).trans <| Ordinal.le_iSup (fun x : Iio a ↦ _) ⟨x, hx⟩) · exact le_max_of_le_right ((h hi).trans <| Ordinal.le_iSup (fun x : Iio b ↦ _) ⟨x, hx⟩) all_goals apply csSup_le_csSup' (bddAbove_of_small _) rintro _ ⟨⟨c, hc⟩, rfl⟩ refine mem_range_self (⟨_, ?_⟩ : Iio _) apply_rules [nadd_lt_nadd_left, nadd_lt_nadd_right] theorem nadd_assoc (a b c) : a ♯ b ♯ c = a ♯ (b ♯ c) := by unfold nadd rw [iSup_nadd_of_monotone fun a' ↦ succ (a' ♯ c), iSup_nadd_of_monotone fun b' ↦ succ (a ♯ b'), max_assoc] · congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_assoc _ _ _) · exact succ_mono.comp fun x y h ↦ nadd_le_nadd_left h _ · exact succ_mono.comp fun x y h ↦ nadd_le_nadd_right h _ termination_by (a, b, c) @[simp] theorem nadd_zero (a : Ordinal) : a ♯ 0 = a := by rw [nadd, ciSup_of_empty fun _ : Iio 0 ↦ _, sup_bot_eq] convert iSup_succ a rename_i x cases x exact nadd_zero _ termination_by a @[simp] theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero] @[simp] theorem nadd_one (a : Ordinal) : a ♯ 1 = succ a := by rw [nadd, ciSup_unique (s := fun _ : Iio 1 ↦ _), Iio_one_default_eq, nadd_zero, max_eq_right_iff, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ rwa [nadd_one, succ_le_succ_iff, succ_le_iff] termination_by a @[simp] theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one] theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [← nadd_one (a ♯ b), nadd_assoc, nadd_one] theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [← one_nadd (a ♯ b), ← nadd_assoc, one_nadd] @[simp] theorem nadd_nat (n : ℕ) : a ♯ n = a + n := by induction' n with n hn · simp · rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn] @[simp] theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat] theorem add_le_nadd : a + b ≤ a ♯ b := by induction b using limitRecOn with | zero => simp | succ c h => rwa [add_succ, nadd_succ, succ_le_succ_iff] | isLimit c hc H => rw [(isNormal_add_right a).apply_of_isLimit hc, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ exact (H i hi).trans (nadd_le_nadd_left hi.le a) end Ordinal namespace NatOrdinal open Ordinal NaturalOps instance : Add NatOrdinal := ⟨nadd⟩ instance : SuccAddOrder NatOrdinal := ⟨fun x => (nadd_one x).symm⟩ theorem lt_add_iff {a b c : NatOrdinal} : a < b + c ↔ (∃ b' < b, a ≤ b' + c) ∨ ∃ c' < c, a ≤ b + c' := Ordinal.lt_nadd_iff theorem add_le_iff {a b c : NatOrdinal} : b + c ≤ a ↔ (∀ b' < b, b' + c < a) ∧ ∀ c' < c, b + c' < a := Ordinal.nadd_le_iff instance : AddLeftStrictMono NatOrdinal.{u} := ⟨fun a _ _ h => nadd_lt_nadd_left h a⟩ instance : AddLeftMono NatOrdinal.{u} := ⟨fun a _ _ h => nadd_le_nadd_left h a⟩ instance : AddLeftReflectLE NatOrdinal.{u} := ⟨fun a b c h => by by_contra! h' exact h.not_lt (add_lt_add_left h' a)⟩ instance : AddCommMonoid NatOrdinal := { add := (· + ·) add_assoc := nadd_assoc zero := 0 zero_add := zero_nadd add_zero := nadd_zero add_comm := nadd_comm nsmul := nsmulRec } instance : IsOrderedCancelAddMonoid NatOrdinal := { add_le_add_left := fun _ _ => add_le_add_left le_of_add_le_add_left := fun _ _ _ => le_of_add_le_add_left } instance : AddMonoidWithOne NatOrdinal := AddMonoidWithOne.unary @[simp] theorem toOrdinal_natCast (n : ℕ) : toOrdinal n = n := by induction' n with n hn · rfl · change (toOrdinal n) ♯ 1 = n + 1 rw [hn]; exact nadd_one n instance : CharZero NatOrdinal where cast_injective m n h := by apply_fun toOrdinal at h simpa using h end NatOrdinal open NatOrdinal open NaturalOps namespace Ordinal theorem nadd_eq_add (a b : Ordinal) : a ♯ b = toOrdinal (toNatOrdinal a + toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_natCast (n : ℕ) : toNatOrdinal n = n := by rw [← toOrdinal_natCast n] rfl theorem lt_of_nadd_lt_nadd_left : ∀ {a b c}, a ♯ b < a ♯ c → b < c := @lt_of_add_lt_add_left NatOrdinal _ _ _ theorem lt_of_nadd_lt_nadd_right : ∀ {a b c}, b ♯ a < c ♯ a → b < c := @lt_of_add_lt_add_right NatOrdinal _ _ _ theorem le_of_nadd_le_nadd_left : ∀ {a b c}, a ♯ b ≤ a ♯ c → b ≤ c := @le_of_add_le_add_left NatOrdinal _ _ _ theorem le_of_nadd_le_nadd_right : ∀ {a b c}, b ♯ a ≤ c ♯ a → b ≤ c := @le_of_add_le_add_right NatOrdinal _ _ _ @[simp] theorem nadd_lt_nadd_iff_left : ∀ (a) {b c}, a ♯ b < a ♯ c ↔ b < c := @add_lt_add_iff_left NatOrdinal _ _ _ _ @[simp] theorem nadd_lt_nadd_iff_right : ∀ (a) {b c}, b ♯ a < c ♯ a ↔ b < c := @add_lt_add_iff_right NatOrdinal _ _ _ _ @[simp] theorem nadd_le_nadd_iff_left : ∀ (a) {b c}, a ♯ b ≤ a ♯ c ↔ b ≤ c := @add_le_add_iff_left NatOrdinal _ _ _ _ @[simp] theorem nadd_le_nadd_iff_right : ∀ (a) {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c := @_root_.add_le_add_iff_right NatOrdinal _ _ _ _ theorem nadd_le_nadd : ∀ {a b c d}, a ≤ b → c ≤ d → a ♯ c ≤ b ♯ d := @add_le_add NatOrdinal _ _ _ _ theorem nadd_lt_nadd : ∀ {a b c d}, a < b → c < d → a ♯ c < b ♯ d := @add_lt_add NatOrdinal _ _ _ _ theorem nadd_lt_nadd_of_lt_of_le : ∀ {a b c d}, a < b → c ≤ d → a ♯ c < b ♯ d := @add_lt_add_of_lt_of_le NatOrdinal _ _ _ _ theorem nadd_lt_nadd_of_le_of_lt : ∀ {a b c d}, a ≤ b → c < d → a ♯ c < b ♯ d := @add_lt_add_of_le_of_lt NatOrdinal _ _ _ _ theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c := @_root_.add_left_cancel NatOrdinal _ _ theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c := @_root_.add_right_cancel NatOrdinal _ _ @[simp] theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c := @add_left_cancel_iff NatOrdinal _ _ @[simp] theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c := @add_right_cancel_iff NatOrdinal _ _ theorem le_nadd_self {a b} : a ≤ b ♯ a := by simpa using nadd_le_nadd_right (Ordinal.zero_le b) a theorem le_nadd_left {a b c} (h : a ≤ c) : a ≤ b ♯ c := le_nadd_self.trans (nadd_le_nadd_left h b) theorem le_self_nadd {a b} : a ≤ a ♯ b := by simpa using nadd_le_nadd_left (Ordinal.zero_le b) a theorem le_nadd_right {a b c} (h : a ≤ b) : a ≤ b ♯ c := le_self_nadd.trans (nadd_le_nadd_right h c) theorem nadd_left_comm : ∀ a b c, a ♯ (b ♯ c) = b ♯ (a ♯ c) := @add_left_comm NatOrdinal _ theorem nadd_right_comm : ∀ a b c, a ♯ b ♯ c = a ♯ c ♯ b := @add_right_comm NatOrdinal _ /-! ### Natural multiplication -/ variable {a b c d : Ordinal.{u}} @[deprecated "avoid using the definition of `nmul` directly" (since := "2024-11-19")] theorem nmul_def (a b : Ordinal) : a ⨳ b = sInf {c | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'} := by rw [nmul] /-- The set in the definition of `nmul` is nonempty. -/ private theorem nmul_nonempty (a b : Ordinal.{u}) : {c : Ordinal.{u} | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'}.Nonempty := by obtain ⟨c, hc⟩ : BddAbove ((fun x ↦ x.1 ⨳ b ♯ a ⨳ x.2) '' Set.Iio a ×ˢ Set.Iio b) := bddAbove_of_small _ exact ⟨_, fun x hx y hy ↦ (lt_succ_of_le <| hc <| Set.mem_image_of_mem _ <| Set.mk_mem_prod hx hy).trans_le le_self_nadd⟩ theorem nmul_nadd_lt {a' b' : Ordinal} (ha : a' < a) (hb : b' < b) : a' ⨳ b ♯ a ⨳ b' < a ⨳ b ♯ a' ⨳ b' := by conv_rhs => rw [nmul] exact csInf_mem (nmul_nonempty a b) a' ha b' hb theorem nmul_nadd_le {a' b' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) : a' ⨳ b ♯ a ⨳ b' ≤ a ⨳ b ♯ a' ⨳ b' := by rcases lt_or_eq_of_le ha with (ha | rfl) · rcases lt_or_eq_of_le hb with (hb | rfl) · exact (nmul_nadd_lt ha hb).le · rw [nadd_comm] · exact le_rfl theorem lt_nmul_iff : c < a ⨳ b ↔ ∃ a' < a, ∃ b' < b, c ♯ a' ⨳ b' ≤ a' ⨳ b ♯ a ⨳ b' := by refine ⟨fun h => ?_, ?_⟩ · rw [nmul] at h simpa using not_mem_of_lt_csInf h ⟨0, fun _ _ => bot_le⟩ · rintro ⟨a', ha, b', hb, h⟩ have := h.trans_lt (nmul_nadd_lt ha hb) rwa [nadd_lt_nadd_iff_right] at this theorem nmul_le_iff : a ⨳ b ≤ c ↔ ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b' := by rw [← not_iff_not]; simp [lt_nmul_iff] theorem nmul_comm (a b) : a ⨳ b = b ⨳ a := by rw [nmul, nmul] congr; ext x; constructor <;> intro H c hc d hd · rw [nadd_comm, ← nmul_comm, ← nmul_comm a, ← nmul_comm d] exact H _ hd _ hc · rw [nadd_comm, nmul_comm, nmul_comm c, nmul_comm c] exact H _ hd _ hc termination_by (a, b) @[simp] theorem nmul_zero (a) : a ⨳ 0 = 0 := by rw [← Ordinal.le_zero, nmul_le_iff] exact fun _ _ a ha => (Ordinal.not_lt_zero a ha).elim @[simp] theorem zero_nmul (a) : 0 ⨳ a = 0 := by rw [nmul_comm, nmul_zero] @[simp] theorem nmul_one (a : Ordinal) : a ⨳ 1 = a := by rw [nmul] convert csInf_Ici ext b refine ⟨fun H ↦ le_of_forall_lt (a := a) fun c hc ↦ ?_, fun ha c hc ↦ ?_⟩ -- Porting note: had to add arguments to `nmul_one` in the next two lines -- for the termination checker. · simpa [nmul_one c] using H c hc · simpa [nmul_one c] using hc.trans_le ha termination_by a @[simp] theorem one_nmul (a) : 1 ⨳ a = a := by rw [nmul_comm, nmul_one] theorem nmul_lt_nmul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c ⨳ a < c ⨳ b := lt_nmul_iff.2 ⟨0, h₂, a, h₁, by simp⟩ theorem nmul_lt_nmul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a ⨳ c < b ⨳ c := lt_nmul_iff.2 ⟨a, h₁, 0, h₂, by simp⟩ theorem nmul_le_nmul_left (h : a ≤ b) (c) : c ⨳ a ≤ c ⨳ b := by rcases lt_or_eq_of_le h with (h₁ | rfl) <;> rcases (eq_zero_or_pos c).symm with (h₂ | rfl) · exact (nmul_lt_nmul_of_pos_left h₁ h₂).le all_goals simp theorem nmul_le_nmul_right (h : a ≤ b) (c) : a ⨳ c ≤ b ⨳ c := by rw [nmul_comm, nmul_comm b] exact nmul_le_nmul_left h c theorem nmul_nadd (a b c : Ordinal) : a ⨳ (b ♯ c) = a ⨳ b ♯ a ⨳ c := by refine le_antisymm (nmul_le_iff.2 fun a' ha d hd => ?_) (nadd_le_iff.2 ⟨fun d hd => ?_, fun d hd => ?_⟩) · rw [nmul_nadd] rcases lt_nadd_iff.1 hd with (⟨b', hb, hd⟩ | ⟨c', hc, hd⟩) · have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha hb) (nmul_nadd_le ha.le hd) rw [nmul_nadd, nmul_nadd] at this simp only [nadd_assoc] at this rwa [nadd_left_comm, nadd_left_comm _ (a ⨳ b'), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, ← nadd_assoc, ← nadd_assoc] at this · have := nadd_lt_nadd_of_le_of_lt (nmul_nadd_le ha.le hd) (nmul_nadd_lt ha hc) rw [nmul_nadd, nmul_nadd] at this simp only [nadd_assoc] at this rwa [nadd_left_comm, nadd_comm (a ⨳ c), nadd_left_comm (a' ⨳ d), nadd_left_comm (a ⨳ c'), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a' ⨳ c), nadd_left_comm (a ⨳ d), nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a ⨳ d), nadd_comm (a' ⨳ d), ← nadd_assoc, ← nadd_assoc] at this · rcases lt_nmul_iff.1 hd with ⟨a', ha, b', hb, hd⟩ have := nadd_lt_nadd_of_le_of_lt hd (nmul_nadd_lt ha (nadd_lt_nadd_right hb c)) rw [nmul_nadd, nmul_nadd, nmul_nadd a'] at this simp only [nadd_assoc] at this rwa [nadd_left_comm (a' ⨳ b'), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm, nadd_left_comm _ (a' ⨳ b'), nadd_left_comm (a ⨳ b'), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ c), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm, nadd_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left] at this · rcases lt_nmul_iff.1 hd with ⟨a', ha, c', hc, hd⟩ have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha (nadd_lt_nadd_left hc b)) hd rw [nmul_nadd, nmul_nadd, nmul_nadd a'] at this simp only [nadd_assoc] at this rwa [nadd_left_comm _ (a' ⨳ b), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ c'), nadd_left_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left, nadd_left_comm, nadd_comm (a' ⨳ c'), nadd_left_comm _ (a ⨳ c'), nadd_lt_nadd_iff_left, nadd_comm _ (a' ⨳ c'), nadd_comm _ (a' ⨳ c'), nadd_left_comm, nadd_lt_nadd_iff_left] at this termination_by (a, b, c) theorem nadd_nmul (a b c) : (a ♯ b) ⨳ c = a ⨳ c ♯ b ⨳ c := by rw [nmul_comm, nmul_nadd, nmul_comm, nmul_comm c] theorem nmul_nadd_lt₃ {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) : a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' < a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_lt (nmul_nadd_lt ha hb) hc theorem nmul_nadd_le₃ {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) : a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' ≤ a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_le (nmul_nadd_le ha hb) hc private theorem nmul_nadd_lt₃' {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) : a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') < a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _)] convert nmul_nadd_lt₃ hb hc ha using 1 <;> (simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf) @[deprecated nmul_nadd_le₃ (since := "2024-11-19")] theorem nmul_nadd_le₃' {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) : a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') ≤ a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _)] convert nmul_nadd_le₃ hb hc ha using 1 <;> (simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf) theorem lt_nmul_iff₃ : d < a ⨳ b ⨳ c ↔ ∃ a' < a, ∃ b' < b, ∃ c' < c, d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' ≤ a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' := by refine ⟨fun h ↦ ?_, fun ⟨a', ha, b', hb, c', hc, h⟩ ↦ ?_⟩ · rcases lt_nmul_iff.1 h with ⟨e, he, c', hc, H₁⟩ rcases lt_nmul_iff.1 he with ⟨a', ha, b', hb, H₂⟩ refine ⟨a', ha, b', hb, c', hc, ?_⟩ have := nadd_le_nadd H₁ (nmul_nadd_le H₂ hc.le) simp only [nadd_nmul, nadd_assoc] at this rw [nadd_left_comm, nadd_left_comm d, nadd_left_comm, nadd_le_nadd_iff_left, nadd_left_comm (a ⨳ b' ⨳ c), nadd_left_comm (a' ⨳ b ⨳ c), nadd_left_comm (a ⨳ b ⨳ c'), nadd_le_nadd_iff_left, nadd_left_comm (a ⨳ b ⨳ c'), nadd_left_comm (a ⨳ b ⨳ c')] at this simpa only [nadd_assoc] · have := h.trans_lt (nmul_nadd_lt₃ ha hb hc) repeat rw [nadd_lt_nadd_iff_right] at this assumption theorem nmul_le_iff₃ : a ⨳ b ⨳ c ≤ d ↔ ∀ a' < a, ∀ b' < b, ∀ c' < c, a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' < d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by simpa using lt_nmul_iff₃.not private theorem nmul_le_iff₃' : a ⨳ (b ⨳ c) ≤ d ↔ ∀ a' < a, ∀ b' < b, ∀ c' < c, a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') < d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by simp only [nmul_comm _ (_ ⨳ _), nmul_le_iff₃, nadd_eq_add, toOrdinal_toNatOrdinal] constructor <;> intro h a' ha b' hb c' hc · convert h b' hb c' hc a' ha using 1 <;> abel_nf · convert h c' hc a' ha b' hb using 1 <;> abel_nf @[deprecated lt_nmul_iff₃ (since := "2024-11-19")] theorem lt_nmul_iff₃' : d < a ⨳ (b ⨳ c) ↔ ∃ a' < a, ∃ b' < b, ∃ c' < c, d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') ≤ a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') := by simpa using nmul_le_iff₃'.not theorem nmul_assoc (a b c : Ordinal) : a ⨳ b ⨳ c = a ⨳ (b ⨳ c) := by apply le_antisymm · rw [nmul_le_iff₃] intro a' ha b' hb c' hc repeat rw [nmul_assoc] exact nmul_nadd_lt₃' ha hb hc · rw [nmul_le_iff₃'] intro a' ha b' hb c' hc repeat rw [← nmul_assoc] exact nmul_nadd_lt₃ ha hb hc termination_by (a, b, c) end Ordinal namespace NatOrdinal open Ordinal instance : Mul NatOrdinal := ⟨nmul⟩
theorem lt_mul_iff {a b c : NatOrdinal} : c < a * b ↔ ∃ a' < a, ∃ b' < b, c + a' * b' ≤ a' * b + a * b' := Ordinal.lt_nmul_iff theorem mul_le_iff {a b c : NatOrdinal} :
Mathlib/SetTheory/Ordinal/NaturalOps.lean
671
676
/- Copyright (c) 2023 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.Bivariate import Mathlib.AlgebraicGeometry.EllipticCurve.Weierstrass import Mathlib.AlgebraicGeometry.EllipticCurve.VariableChange /-! # Affine coordinates for Weierstrass curves This file defines the type of points on a Weierstrass curve as an inductive, consisting of the point at infinity and affine points satisfying a Weierstrass equation with a nonsingular condition. This file also defines the negation and addition operations of the group law for this type, and proves that they respect the Weierstrass equation and the nonsingular condition. The fact that they form an abelian group is proven in `Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean`. ## Mathematical background Let `W` be a Weierstrass curve over a field `F` with coefficients `aᵢ`. An *affine point* on `W` is a tuple `(x, y)` of elements in `R` satisfying the *Weierstrass equation* `W(X, Y) = 0` in *affine coordinates*, where `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)`. It is *nonsingular* if its partial derivatives `W_X(x, y)` and `W_Y(x, y)` do not vanish simultaneously. The nonsingular affine points on `W` can be given negation and addition operations defined by a secant-and-tangent process. * Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third nonsingular point of intersection between `W` and the vertical line through `P`. Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - a₁x - a₃)`. * Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the negation of the unique third nonsingular point of intersection between `W` and the line `L` through `P` and `Q`. Explicitly, let `P` be `(x₁, y₁)` and let `Q` be `(x₂, y₂)`. * If `x₁ = x₂` and `y₁ = -y₂ - a₁x₂ - a₃`, then `L` is vertical. * If `x₁ = x₂` and `y₁ ≠ -y₂ - a₁x₂ - a₃`, then `L` is the tangent of `W` at `P = Q`, and has slope `ℓ := (3x₁² + 2a₂x₁ + a₄ - a₁y₁) / (2y₁ + a₁x₁ + a₃)`. * Otherwise `x₁ ≠ x₂`, then `L` is the secant of `W` through `P` and `Q`, and has slope `ℓ := (y₁ - y₂) / (x₁ - x₂)`. In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the equation obtained by substituting the line `Y = ℓ(X - x₁) + y₁` into the Weierstrass equation, and can be written down explicitly as `x := ℓ² + a₁ℓ - a₂ - x₁ - x₂` by inspecting the coefficients of `X²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps `Y` to `-Y - a₁X - a₃`, is precisely `y := -(ℓ(x - x₁) + y₁) - a₁x - a₃`. The type of nonsingular points `W⟮F⟯` in affine coordinates is an inductive, consisting of the unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. Then `W⟮F⟯` can be endowed with a group law, with `𝓞` as the identity nonsingular point, which is uniquely determined by these formulae. ## Main definitions * `WeierstrassCurve.Affine.Equation`: the Weierstrass equation of an affine Weierstrass curve. * `WeierstrassCurve.Affine.Nonsingular`: the nonsingular condition on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point`: a nonsingular rational point on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.neg`: the negation operation on an affine Weierstrass curve. * `WeierstrassCurve.Affine.Point.add`: the addition operation on an affine Weierstrass curve. ## Main statements * `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation. * `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation. * `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition. * `WeierstrassCurve.Affine.nonsingular_of_Δ_ne_zero`: an affine Weierstrass curve is nonsingular at every point if its discriminant is non-zero. * `WeierstrassCurve.Affine.nonsingular`: an affine elliptic curve is nonsingular at every point. ## Notations * `W⟮K⟯`: the group of nonsingular rational points on `W` base changed to `K`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, rational point, affine coordinates -/ open Polynomial open scoped Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "derivative_simp" : tactic => `(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add, derivative_sub, derivative_mul, derivative_sq]) local macro "eval_simp" : tactic => `(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval]) local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, WeierstrassCurve.map]) universe r s u v w /-! ## Weierstrass curves -/ namespace WeierstrassCurve variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} {L : Type w} variable (R) in /-- An abbreviation for a Weierstrass curve in affine coordinates. -/ abbrev Affine : Type r := WeierstrassCurve R /-- The conversion from a Weierstrass curve to affine coordinates. -/ abbrev toAffine (W : WeierstrassCurve R) : Affine R := W namespace Affine variable [CommRing R] [CommRing S] [CommRing A] [CommRing B] [Field F] [Field K] [Field L] {W' : Affine R} {W : Affine F} section Equation /-! ### Weierstrass equations -/ variable (W') in /-- The polynomial `W(X, Y) := Y² + a₁XY + a₃Y - (X³ + a₂X² + a₄X + a₆)` associated to a Weierstrass curve `W` over a ring `R` in affine coordinates. For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the inner variable represents `X` and the outer variable represents `Y`. For clarity, the alternative notations `Y` and `R[X][Y]` are provided in the `Polynomial.Bivariate` scope to represent the outer variable and the bivariate polynomial ring `R[X][X]` respectively. -/ noncomputable def polynomial : R[X][Y] := Y ^ 2 + C (C W'.a₁ * X + C W'.a₃) * Y - C (X ^ 3 + C W'.a₂ * X ^ 2 + C W'.a₄ * X + C W'.a₆) lemma polynomial_eq : W'.polynomial = Cubic.toPoly ⟨0, 1, Cubic.toPoly ⟨0, 0, W'.a₁, W'.a₃⟩, Cubic.toPoly ⟨-1, -W'.a₂, -W'.a₄, -W'.a₆⟩⟩ := by simp only [polynomial, Cubic.toPoly] C_simp ring1 lemma polynomial_ne_zero [Nontrivial R] : W'.polynomial ≠ 0 := by rw [polynomial_eq] exact Cubic.ne_zero_of_b_ne_zero one_ne_zero @[simp] lemma degree_polynomial [Nontrivial R] : W'.polynomial.degree = 2 := by rw [polynomial_eq] exact Cubic.degree_of_b_ne_zero' one_ne_zero @[simp] lemma natDegree_polynomial [Nontrivial R] : W'.polynomial.natDegree = 2 := by rw [polynomial_eq] exact Cubic.natDegree_of_b_ne_zero' one_ne_zero lemma monic_polynomial : W'.polynomial.Monic := by nontriviality R simpa only [polynomial_eq] using Cubic.monic_of_b_eq_one' lemma irreducible_polynomial [IsDomain R] : Irreducible W'.polynomial := by by_contra h rcases (monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff natDegree_polynomial).mp h with ⟨f, g, h0, h1⟩ simp only [polynomial_eq, Cubic.coeff_eq_c, Cubic.coeff_eq_d] at h0 h1 apply_fun degree at h0 h1 rw [Cubic.degree_of_a_ne_zero' <| neg_ne_zero.mpr <| one_ne_zero' R, degree_mul] at h0 apply (h1.symm.le.trans Cubic.degree_of_b_eq_zero').not_lt rcases Nat.WithBot.add_eq_three_iff.mp h0.symm with h | h | h | h iterate 2 rw [degree_add_eq_right_of_degree_lt] <;> simp only [h] <;> decide iterate 2 rw [degree_add_eq_left_of_degree_lt] <;> simp only [h] <;> decide lemma evalEval_polynomial (x y : R) : W'.polynomial.evalEval x y = y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) := by simp only [polynomial] eval_simp rw [add_mul, ← add_assoc] @[simp] lemma evalEval_polynomial_zero : W'.polynomial.evalEval 0 0 = -W'.a₆ := by simp only [evalEval_polynomial, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The proposition that an affine point `(x, y)` lies in a Weierstrass curve `W`. In other words, it satisfies the Weierstrass equation `W(X, Y) = 0`. -/ def Equation (x y : R) : Prop := W'.polynomial.evalEval x y = 0 lemma equation_iff' (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y - (x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆) = 0 := by rw [Equation, evalEval_polynomial] lemma equation_iff (x y : R) : W'.Equation x y ↔ y ^ 2 + W'.a₁ * x * y + W'.a₃ * y = x ^ 3 + W'.a₂ * x ^ 2 + W'.a₄ * x + W'.a₆ := by rw [equation_iff', sub_eq_zero] @[simp] lemma equation_zero : W'.Equation 0 0 ↔ W'.a₆ = 0 := by rw [Equation, evalEval_polynomial_zero, neg_eq_zero] lemma equation_iff_variableChange (x y : R) : W'.Equation x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Equation 0 0 := by rw [equation_iff', ← neg_eq_zero, equation_zero, variableChange_a₆, inv_one, Units.val_one] congr! 1 ring1 end Equation section Nonsingular /-! ### Nonsingular Weierstrass equations -/ variable (W') in /-- The partial derivative `W_X(X, Y)` with respect to `X` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialX : R[X][Y] := C (C W'.a₁) * Y - C (C 3 * X ^ 2 + C (2 * W'.a₂) * X + C W'.a₄) lemma evalEval_polynomialX (x y : R) : W'.polynomialX.evalEval x y = W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) := by simp only [polynomialX] eval_simp @[simp] lemma evalEval_polynomialX_zero : W'.polynomialX.evalEval 0 0 = -W'.a₄ := by simp only [evalEval_polynomialX, zero_add, zero_sub, mul_zero, zero_pow <| Nat.succ_ne_zero _] variable (W') in /-- The partial derivative `W_Y(X, Y)` with respect to `Y` of the polynomial `W(X, Y)` associated to a Weierstrass curve `W` in affine coordinates. -/ -- TODO: define this in terms of `Polynomial.derivative`. noncomputable def polynomialY : R[X][Y] := C (C 2) * Y + C (C W'.a₁ * X + C W'.a₃) lemma evalEval_polynomialY (x y : R) : W'.polynomialY.evalEval x y = 2 * y + W'.a₁ * x + W'.a₃ := by simp only [polynomialY] eval_simp rw [← add_assoc] @[simp] lemma evalEval_polynomialY_zero : W'.polynomialY.evalEval 0 0 = W'.a₃ := by simp only [evalEval_polynomialY, zero_add, mul_zero] variable (W') in /-- The proposition that an affine point `(x, y)` on a Weierstrass curve `W` is nonsingular. In other words, either `W_X(x, y) ≠ 0` or `W_Y(x, y) ≠ 0`. Note that this definition is only mathematically accurate for fields. -/ -- TODO: generalise this definition to be mathematically accurate for a larger class of rings. def Nonsingular (x y : R) : Prop := W'.Equation x y ∧ (W'.polynomialX.evalEval x y ≠ 0 ∨ W'.polynomialY.evalEval x y ≠ 0) lemma nonsingular_iff' (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y - (3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄) ≠ 0 ∨ 2 * y + W'.a₁ * x + W'.a₃ ≠ 0) := by rw [Nonsingular, equation_iff', evalEval_polynomialX, evalEval_polynomialY] lemma nonsingular_iff (x y : R) : W'.Nonsingular x y ↔ W'.Equation x y ∧ (W'.a₁ * y ≠ 3 * x ^ 2 + 2 * W'.a₂ * x + W'.a₄ ∨ y ≠ -y - W'.a₁ * x - W'.a₃) := by rw [nonsingular_iff', sub_ne_zero, ← sub_ne_zero (a := y)] congr! 3 ring1 @[simp] lemma nonsingular_zero : W'.Nonsingular 0 0 ↔ W'.a₆ = 0 ∧ (W'.a₃ ≠ 0 ∨ W'.a₄ ≠ 0) := by rw [Nonsingular, equation_zero, evalEval_polynomialX_zero, neg_ne_zero, evalEval_polynomialY_zero, or_comm] lemma nonsingular_iff_variableChange (x y : R) : W'.Nonsingular x y ↔ (VariableChange.mk 1 x 0 y • W').toAffine.Nonsingular 0 0 := by rw [nonsingular_iff', equation_iff_variableChange, equation_zero, ← neg_ne_zero, or_comm, nonsingular_zero, variableChange_a₃, variableChange_a₄, inv_one, Units.val_one] simp only [variableChange_def] congr! 3 <;> ring1 private lemma equation_zero_iff_nonsingular_zero_of_Δ_ne_zero (hΔ : W'.Δ ≠ 0) : W'.Equation 0 0 ↔ W'.Nonsingular 0 0 := by simp only [equation_zero, nonsingular_zero, iff_self_and]
contrapose! hΔ simp only [b₂, b₄, b₆, b₈, Δ, hΔ] ring1
Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean
283
285
/- 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.LinearAlgebra.AffineSpace.AffineMap import Mathlib.Tactic.FieldSimp /-! # Slope of a function In this file we define the slope of a function `f : k → PE` taking values in an affine space over `k` and prove some basic theorems about `slope`. The `slope` function naturally appears in the Mean Value Theorem, and in the proof of the fact that a function with nonnegative second derivative on an interval is convex on this interval. ## Tags affine space, slope -/ open AffineMap variable {k E PE : Type*} [Field k] [AddCommGroup E] [Module k E] [AddTorsor E PE] /-- `slope f a b = (b - a)⁻¹ • (f b -ᵥ f a)` is the slope of a function `f` on the interval `[a, b]`. Note that `slope f a a = 0`, not the derivative of `f` at `a`. -/ def slope (f : k → PE) (a b : k) : E := (b - a)⁻¹ • (f b -ᵥ f a) theorem slope_fun_def (f : k → PE) : slope f = fun a b => (b - a)⁻¹ • (f b -ᵥ f a) := rfl theorem slope_def_field (f : k → k) (a b : k) : slope f a b = (f b - f a) / (b - a) := (div_eq_inv_mul _ _).symm theorem slope_fun_def_field (f : k → k) (a : k) : slope f a = fun b => (f b - f a) / (b - a) := (div_eq_inv_mul _ _).symm @[simp] theorem slope_same (f : k → PE) (a : k) : (slope f a a : E) = 0 := by rw [slope, sub_self, inv_zero, zero_smul] theorem slope_def_module (f : k → E) (a b : k) : slope f a b = (b - a)⁻¹ • (f b - f a) := rfl @[simp] theorem sub_smul_slope (f : k → PE) (a b : k) : (b - a) • slope f a b = f b -ᵥ f a := by rcases eq_or_ne a b with (rfl | hne) · rw [sub_self, zero_smul, vsub_self] · rw [slope, smul_inv_smul₀ (sub_ne_zero.2 hne.symm)] theorem sub_smul_slope_vadd (f : k → PE) (a b : k) : (b - a) • slope f a b +ᵥ f a = f b := by rw [sub_smul_slope, vsub_vadd] @[simp] theorem slope_vadd_const (f : k → E) (c : PE) : (slope fun x => f x +ᵥ c) = slope f := by ext a b simp only [slope, vadd_vsub_vadd_cancel_right, vsub_eq_sub] @[simp] theorem slope_sub_smul (f : k → E) {a b : k} (h : a ≠ b) : slope (fun x => (x - a) • f x) a b = f b := by simp [slope, inv_smul_smul₀ (sub_ne_zero.2 h.symm)] theorem eq_of_slope_eq_zero {f : k → PE} {a b : k} (h : slope f a b = (0 : E)) : f a = f b := by
rw [← sub_smul_slope_vadd f a b, h, smul_zero, zero_vadd] theorem AffineMap.slope_comp {F PF : Type*} [AddCommGroup F] [Module k F] [AddTorsor F PF]
Mathlib/LinearAlgebra/AffineSpace/Slope.lean
67
69
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.GeomSum import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Nat.Log import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.Nat.Digits import Mathlib.RingTheory.Multiplicity /-! # Natural number multiplicity This file contains lemmas about the multiplicity function (the maximum prime power dividing a number) when applied to naturals, in particular calculating it for factorials and binomial coefficients. ## Multiplicity calculations * `Nat.Prime.multiplicity_factorial`: Legendre's Theorem. The multiplicity of `p` in `n!` is `n / p + ... + n / p ^ b` for any `b` such that `n / p ^ (b + 1) = 0`. See `padicValNat_factorial` for this result stated in the language of `p`-adic valuations and `sub_one_mul_padicValNat_factorial` for a related result. * `Nat.Prime.multiplicity_factorial_mul`: The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. * `Nat.Prime.multiplicity_choose`: Kummer's Theorem. The multiplicity of `p` in `n.choose k` is the number of carries when `k` and `n - k` are added in base `p`. See `padicValNat_choose` for the same result but stated in the language of `p`-adic valuations and `sub_one_mul_padicValNat_choose_eq_sub_sum_digits` for a related result. ## Other declarations * `Nat.multiplicity_eq_card_pow_dvd`: The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i` divides `n`. * `Nat.multiplicity_two_factorial_lt`: The multiplicity of `2` in `n!` is strictly less than `n`. * `Nat.Prime.multiplicity_something`: Specialization of `multiplicity.something` to a prime in the naturals. Avoids having to provide `p ≠ 1` and other trivialities, along with translating between `Prime` and `Nat.Prime`. ## Tags Legendre, p-adic -/ open Finset Nat open Nat namespace Nat /-- The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i` divides `n`. This set is expressed by filtering `Ico 1 b` where `b` is any bound greater than `log m n`. -/ theorem emultiplicity_eq_card_pow_dvd {m n b : ℕ} (hm : m ≠ 1) (hn : 0 < n) (hb : log m n < b) : emultiplicity m n = #{i ∈ Ico 1 b | m ^ i ∣ n} := have fin := Nat.finiteMultiplicity_iff.2 ⟨hm, hn⟩ calc emultiplicity m n = #(Ico 1 <| multiplicity m n + 1) := by simp [fin.emultiplicity_eq_multiplicity] _ = #{i ∈ Ico 1 b | m ^ i ∣ n} := congr_arg _ <| congr_arg card <| Finset.ext fun i => by simp only [mem_Ico, Nat.lt_succ_iff, fin.pow_dvd_iff_le_multiplicity, mem_filter, and_assoc, and_congr_right_iff, iff_and_self] intro hi h rw [← fin.pow_dvd_iff_le_multiplicity] at h rcases m with - | m · rw [zero_pow, zero_dvd_iff] at h exacts [(hn.ne' h).elim, one_le_iff_ne_zero.1 hi] refine LE.le.trans_lt ?_ hb exact le_log_of_pow_le (one_lt_iff_ne_zero_and_ne_one.2 ⟨m.succ_ne_zero, hm⟩) (le_of_dvd hn h) namespace Prime theorem emultiplicity_one {p : ℕ} (hp : p.Prime) : emultiplicity p 1 = 0 := emultiplicity_of_one_right hp.prime.not_unit theorem emultiplicity_mul {p m n : ℕ} (hp : p.Prime) : emultiplicity p (m * n) = emultiplicity p m + emultiplicity p n := _root_.emultiplicity_mul hp.prime theorem emultiplicity_pow {p m n : ℕ} (hp : p.Prime) : emultiplicity p (m ^ n) = n * emultiplicity p m := _root_.emultiplicity_pow hp.prime theorem emultiplicity_self {p : ℕ} (hp : p.Prime) : emultiplicity p p = 1 := (Nat.finiteMultiplicity_iff.2 ⟨hp.ne_one, hp.pos⟩).emultiplicity_self theorem emultiplicity_pow_self {p n : ℕ} (hp : p.Prime) : emultiplicity p (p ^ n) = n := _root_.emultiplicity_pow_self hp.ne_zero hp.prime.not_unit n /-- **Legendre's Theorem** The multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/ theorem emultiplicity_factorial {p : ℕ} (hp : p.Prime) : ∀ {n b : ℕ}, log p n < b → emultiplicity p n ! = (∑ i ∈ Ico 1 b, n / p ^ i : ℕ) | 0, b, _ => by simp [Ico, hp.emultiplicity_one] | n + 1, b, hb => calc emultiplicity p (n + 1)! = emultiplicity p n ! + emultiplicity p (n + 1) := by rw [factorial_succ, hp.emultiplicity_mul, add_comm] _ = (∑ i ∈ Ico 1 b, n / p ^ i : ℕ) + #{i ∈ Ico 1 b | p ^ i ∣ n + 1} := by rw [emultiplicity_factorial hp ((log_mono_right <| le_succ _).trans_lt hb), ← emultiplicity_eq_card_pow_dvd hp.ne_one (succ_pos _) hb] _ = (∑ i ∈ Ico 1 b, (n / p ^ i + if p ^ i ∣ n + 1 then 1 else 0) : ℕ) := by rw [sum_add_distrib, sum_boole] simp _ = (∑ i ∈ Ico 1 b, (n + 1) / p ^ i : ℕ) := congr_arg _ <| Finset.sum_congr rfl fun _ _ => Nat.succ_div.symm /-- For a prime number `p`, taking `(p - 1)` times the multiplicity of `p` in `n!` equals `n` minus the sum of base `p` digits of `n`. -/ theorem sub_one_mul_multiplicity_factorial {n p : ℕ} (hp : p.Prime) : (p - 1) * multiplicity p n ! = n - (p.digits n).sum := by simp only [multiplicity_eq_of_emultiplicity_eq_some <| emultiplicity_factorial hp <| lt_succ_of_lt <| lt.base (log p n), ← Finset.sum_Ico_add' _ 0 _ 1, Ico_zero_eq_range, ← sub_one_mul_sum_log_div_pow_eq_sub_sum_digits] /-- The multiplicity of `p` in `(p * (n + 1))!` is one more than the sum of the multiplicities of `p` in `(p * n)!` and `n + 1`. -/ theorem emultiplicity_factorial_mul_succ {n p : ℕ} (hp : p.Prime) : emultiplicity p (p * (n + 1))! = emultiplicity p (p * n)! + emultiplicity p (n + 1) + 1 := by have hp' := hp.prime have h0 : 2 ≤ p := hp.two_le have h1 : 1 ≤ p * n + 1 := Nat.le_add_left _ _ have h2 : p * n + 1 ≤ p * (n + 1) := by linarith have h3 : p * n + 1 ≤ p * (n + 1) + 1 := by omega have hm : emultiplicity p (p * n)! ≠ ⊤ := by rw [Ne, emultiplicity_eq_top, Classical.not_not, Nat.finiteMultiplicity_iff] exact ⟨hp.ne_one, factorial_pos _⟩ revert hm have h4 : ∀ m ∈ Ico (p * n + 1) (p * (n + 1)), emultiplicity p m = 0 := by intro m hm rw [emultiplicity_eq_zero, not_dvd_iff_between_consec_multiples _ hp.pos] rw [mem_Ico] at hm exact ⟨n, lt_of_succ_le hm.1, hm.2⟩ simp_rw [← prod_Ico_id_eq_factorial, Finset.emultiplicity_prod hp', ← sum_Ico_consecutive _ h1 h3, add_assoc] intro h rw [WithTop.add_left_inj h, sum_Ico_succ_top h2, hp.emultiplicity_mul, hp.emultiplicity_self, sum_congr rfl h4, sum_const_zero, zero_add, add_comm 1] /-- The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. -/ theorem emultiplicity_factorial_mul {n p : ℕ} (hp : p.Prime) : emultiplicity p (p * n)! = emultiplicity p n ! + n := by induction' n with n ih · simp · simp only [hp, emultiplicity_factorial_mul_succ, ih, factorial_succ, emultiplicity_mul, cast_add, cast_one, ← add_assoc] congr 1 rw [add_comm, add_assoc] /-- A prime power divides `n!` iff it is at most the sum of the quotients `n / p ^ i`. This sum is expressed over the set `Ico 1 b` where `b` is any bound greater than `log p n` -/ theorem pow_dvd_factorial_iff {p : ℕ} {n r b : ℕ} (hp : p.Prime) (hbn : log p n < b) : p ^ r ∣ n ! ↔ r ≤ ∑ i ∈ Ico 1 b, n / p ^ i := by rw [← WithTop.coe_le_coe, ENat.some_eq_coe, ← hp.emultiplicity_factorial hbn, pow_dvd_iff_le_emultiplicity] theorem emultiplicity_factorial_le_div_pred {p : ℕ} (hp : p.Prime) (n : ℕ) : emultiplicity p n ! ≤ (n / (p - 1) : ℕ) := by rw [hp.emultiplicity_factorial (lt_succ_self _)] apply WithTop.coe_mono exact Nat.geom_sum_Ico_le hp.two_le _ _ theorem multiplicity_choose_aux {p n b k : ℕ} (hp : p.Prime) (hkn : k ≤ n) : ∑ i ∈ Finset.Ico 1 b, n / p ^ i = ((∑ i ∈ Finset.Ico 1 b, k / p ^ i) + ∑ i ∈ Finset.Ico 1 b, (n - k) / p ^ i) + #{i ∈ Ico 1 b | p ^ i ≤ k % p ^ i + (n - k) % p ^ i} := calc ∑ i ∈ Finset.Ico 1 b, n / p ^ i = ∑ i ∈ Finset.Ico 1 b, (k + (n - k)) / p ^ i := by simp only [add_tsub_cancel_of_le hkn] _ = ∑ i ∈ Finset.Ico 1 b, (k / p ^ i + (n - k) / p ^ i + if p ^ i ≤ k % p ^ i + (n - k) % p ^ i then 1 else 0) := by simp only [Nat.add_div (pow_pos hp.pos _)] _ = _ := by simp [sum_add_distrib, sum_boole] /-- The multiplicity of `p` in `choose (n + k) k` is the number of carries when `k` and `n` are added in base `p`. The set is expressed by filtering `Ico 1 b` where `b` is any bound greater than `log p (n + k)`. -/ theorem emultiplicity_choose' {p n k b : ℕ} (hp : p.Prime) (hnb : log p (n + k) < b) : emultiplicity p (choose (n + k) k) = #{i ∈ Ico 1 b | p ^ i ≤ k % p ^ i + n % p ^ i} := by have h₁ : emultiplicity p (choose (n + k) k) + emultiplicity p (k ! * n !) = #{i ∈ Ico 1 b | p ^ i ≤ k % p ^ i + n % p ^ i} + emultiplicity p (k ! * n !) := by rw [← hp.emultiplicity_mul, ← mul_assoc] have := (add_tsub_cancel_right n k) ▸ choose_mul_factorial_mul_factorial (le_add_left k n) rw [this, hp.emultiplicity_factorial hnb, hp.emultiplicity_mul, hp.emultiplicity_factorial ((log_mono_right (le_add_left k n)).trans_lt hnb), hp.emultiplicity_factorial ((log_mono_right (le_add_left n k)).trans_lt (add_comm n k ▸ hnb)), multiplicity_choose_aux hp (le_add_left k n)] simp [add_comm] refine WithTop.add_right_cancel ?_ h₁ apply finiteMultiplicity_iff_emultiplicity_ne_top.1 exact Nat.finiteMultiplicity_iff.2 ⟨hp.ne_one, mul_pos (factorial_pos k) (factorial_pos n)⟩ /-- The multiplicity of `p` in `choose n k` is the number of carries when `k` and `n - k` are added in base `p`. The set is expressed by filtering `Ico 1 b` where `b` is any bound greater than `log p n`. -/ theorem emultiplicity_choose {p n k b : ℕ} (hp : p.Prime) (hkn : k ≤ n) (hnb : log p n < b) : emultiplicity p (choose n k) = #{i ∈ Ico 1 b | p ^ i ≤ k % p ^ i + (n - k) % p ^ i} := by have := Nat.sub_add_cancel hkn convert @emultiplicity_choose' p (n - k) k b hp _ · rw [this] exact this.symm ▸ hnb /-- A lower bound on the multiplicity of `p` in `choose n k`. -/ theorem emultiplicity_le_emultiplicity_choose_add {p : ℕ} (hp : p.Prime) : ∀ n k : ℕ, emultiplicity p n ≤ emultiplicity p (choose n k) + emultiplicity p k | _, 0 => by simp | 0, _ + 1 => by simp | n + 1, k + 1 => by rw [← hp.emultiplicity_mul] refine emultiplicity_le_emultiplicity_of_dvd_right ?_ rw [← succ_mul_choose_eq] exact dvd_mul_right _ _ variable {p n k : ℕ} theorem emultiplicity_choose_prime_pow_add_emultiplicity (hp : p.Prime) (hkn : k ≤ p ^ n) (hk0 : k ≠ 0) : emultiplicity p (choose (p ^ n) k) + emultiplicity p k = n := le_antisymm (by have hdisj : Disjoint {i ∈ Ico 1 n.succ | p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i} {i ∈ Ico 1 n.succ | p ^ i ∣ k} := by simp +contextual [disjoint_right, *, dvd_iff_mod_eq_zero, Nat.mod_lt _ (pow_pos hp.pos _)] rw [emultiplicity_choose hp hkn (lt_succ_self _), emultiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) hk0.bot_lt (lt_succ_of_le (log_mono_right hkn)), ← Nat.cast_add] apply WithTop.coe_mono rw [log_pow hp.one_lt, ← card_union_of_disjoint hdisj, filter_union_right] have filter_le_Ico := (Ico 1 n.succ).card_filter_le fun x => p ^ x ≤ k % p ^ x + (p ^ n - k) % p ^ x ∨ p ^ x ∣ k rwa [card_Ico 1 n.succ] at filter_le_Ico) (by rw [← hp.emultiplicity_pow_self]; exact emultiplicity_le_emultiplicity_choose_add hp _ _) theorem emultiplicity_choose_prime_pow {p n k : ℕ} (hp : p.Prime) (hkn : k ≤ p ^ n) (hk0 : k ≠ 0) : emultiplicity p (choose (p ^ n) k) = ↑(n - multiplicity p k) := by push_cast rw [← emultiplicity_choose_prime_pow_add_emultiplicity hp hkn hk0, (finiteMultiplicity_iff.2 ⟨hp.ne_one, Nat.pos_of_ne_zero hk0⟩).emultiplicity_eq_multiplicity, (finiteMultiplicity_iff.2 ⟨hp.ne_one, choose_pos hkn⟩).emultiplicity_eq_multiplicity] norm_cast rw [Nat.add_sub_cancel_right] theorem dvd_choose_pow (hp : Prime p) (hk : k ≠ 0) (hkp : k ≠ p ^ n) : p ∣ (p ^ n).choose k := by obtain hkp | hkp := hkp.symm.lt_or_lt · simp [choose_eq_zero_of_lt hkp] refine emultiplicity_ne_zero.1 fun h => hkp.not_le <| Nat.le_of_dvd hk.bot_lt ?_ have H := hp.emultiplicity_choose_prime_pow_add_emultiplicity hkp.le hk rw [h, zero_add, emultiplicity_eq_coe] at H exact H.1 theorem dvd_choose_pow_iff (hp : Prime p) : p ∣ (p ^ n).choose k ↔ k ≠ 0 ∧ k ≠ p ^ n := by refine ⟨fun h => ⟨?_, ?_⟩, fun h => dvd_choose_pow hp h.1 h.2⟩ <;> rintro rfl <;> simp [hp.ne_one] at h end Prime
theorem emultiplicity_two_factorial_lt : ∀ {n : ℕ} (_ : n ≠ 0), emultiplicity 2 n ! < n := by have h2 := prime_two.prime refine binaryRec ?_ ?_ · exact fun h => False.elim <| h rfl · intro b n ih h by_cases hn : n = 0
Mathlib/Data/Nat/Multiplicity.lean
272
278
/- 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.SpecialFunctions.Log.Deriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.FundThmCalculus /-! # Non integrable functions In this file we prove that the derivative of a function that tends to infinity is not interval integrable, see `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter` and `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured`. Then we apply the latter lemma to prove that the function `fun x => x⁻¹` is integrable on `a..b` if and only if `a = b` or `0 ∉ [a, b]`. ## Main results * `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured`: if `f` tends to infinity along `𝓝[≠] c` and `f' = O(g)` along the same filter, then `g` is not interval integrable on any nontrivial integral `a..b`, `c ∈ [a, b]`. * `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_filter`: a version of `not_intervalIntegrable_of_tendsto_norm_atTop_of_deriv_isBigO_punctured` that works for one-sided neighborhoods; * `not_intervalIntegrable_of_sub_inv_isBigO_punctured`: if `1 / (x - c) = O(f)` as `x → c`, `x ≠ c`, then `f` is not interval integrable on any nontrivial interval `a..b`, `c ∈ [a, b]`; * `intervalIntegrable_sub_inv_iff`, `intervalIntegrable_inv_iff`: integrability conditions for `(x - c)⁻¹` and `x⁻¹`. ## Tags integrable function -/ open scoped MeasureTheory Topology Interval NNReal ENNReal open MeasureTheory TopologicalSpace Set Filter Asymptotics intervalIntegral variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] /-- If `f` is eventually differentiable along a nontrivial filter `l : Filter ℝ` that is generated by convex sets, the norm of `f` tends to infinity along `l`, and `f' = O(g)` along `l`, where `f'` is the derivative of `f`, then `g` is not integrable on any set `k` belonging to `l`. Auxiliary version assuming that `E` is complete. -/ theorem not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter_aux [CompleteSpace E] {f : ℝ → E} {g : ℝ → F}
{k : Set ℝ} (l : Filter ℝ) [NeBot l] [TendstoIxxClass Icc l l] (hl : k ∈ l) (hd : ∀ᶠ x in l, DifferentiableAt ℝ f x) (hf : Tendsto (fun x => ‖f x‖) l atTop) (hfg : deriv f =O[l] g) : ¬IntegrableOn g k := by intro hgi obtain ⟨C, hC₀, s, hsl, hsub, hfd, hg⟩ : ∃ (C : ℝ) (_ : 0 ≤ C), ∃ s ∈ l, (∀ x ∈ s, ∀ y ∈ s, [[x, y]] ⊆ k) ∧ (∀ x ∈ s, ∀ y ∈ s, ∀ z ∈ [[x, y]], DifferentiableAt ℝ f z) ∧ ∀ x ∈ s, ∀ y ∈ s, ∀ z ∈ [[x, y]], ‖deriv f z‖ ≤ C * ‖g z‖ := by rcases hfg.exists_nonneg with ⟨C, C₀, hC⟩ have h : ∀ᶠ x : ℝ × ℝ in l ×ˢ l, ∀ y ∈ [[x.1, x.2]], (DifferentiableAt ℝ f y ∧ ‖deriv f y‖ ≤ C * ‖g y‖) ∧ y ∈ k := (tendsto_fst.uIcc tendsto_snd).eventually ((hd.and hC.bound).and hl).smallSets rcases mem_prod_self_iff.1 h with ⟨s, hsl, hs⟩ simp only [prod_subset_iff, mem_setOf_eq] at hs exact ⟨C, C₀, s, hsl, fun x hx y hy z hz => (hs x hx y hy z hz).2, fun x hx y hy z hz => (hs x hx y hy z hz).1.1, fun x hx y hy z hz => (hs x hx y hy z hz).1.2⟩ replace hgi : IntegrableOn (fun x ↦ C * ‖g x‖) k := by exact hgi.norm.smul C obtain ⟨c, hc, d, hd, hlt⟩ : ∃ c ∈ s, ∃ d ∈ s, (‖f c‖ + ∫ y in k, C * ‖g y‖) < ‖f d‖ := by rcases Filter.nonempty_of_mem hsl with ⟨c, hc⟩ have : ∀ᶠ x in l, (‖f c‖ + ∫ y in k, C * ‖g y‖) < ‖f x‖ := hf.eventually (eventually_gt_atTop _) exact ⟨c, hc, (this.and hsl).exists.imp fun d hd => ⟨hd.2, hd.1⟩⟩ specialize hsub c hc d hd; specialize hfd c hc d hd replace hg : ∀ x ∈ Ι c d, ‖deriv f x‖ ≤ C * ‖g x‖ := fun z hz => hg c hc d hd z ⟨hz.1.le, hz.2⟩ have hg_ae : ∀ᵐ x ∂volume.restrict (Ι c d), ‖deriv f x‖ ≤ C * ‖g x‖ := (ae_restrict_mem measurableSet_uIoc).mono hg have hsub' : Ι c d ⊆ k := Subset.trans Ioc_subset_Icc_self hsub have hfi : IntervalIntegrable (deriv f) volume c d := by rw [intervalIntegrable_iff] have : IntegrableOn (fun x ↦ C * ‖g x‖) (Ι c d) := IntegrableOn.mono hgi hsub' le_rfl exact Integrable.mono' this (aestronglyMeasurable_deriv _ _) hg_ae refine hlt.not_le (sub_le_iff_le_add'.1 ?_) calc ‖f d‖ - ‖f c‖ ≤ ‖f d - f c‖ := norm_sub_norm_le _ _ _ = ‖∫ x in c..d, deriv f x‖ := congr_arg _ (integral_deriv_eq_sub hfd hfi).symm _ = ‖∫ x in Ι c d, deriv f x‖ := norm_integral_eq_norm_integral_uIoc _ _ ≤ ∫ x in Ι c d, ‖deriv f x‖ := norm_integral_le_integral_norm _ _ ≤ ∫ x in Ι c d, C * ‖g x‖ := setIntegral_mono_on hfi.norm.def' (hgi.mono_set hsub') measurableSet_uIoc hg _ ≤ ∫ x in k, C * ‖g x‖ := by apply setIntegral_mono_set hgi (ae_of_all _ fun x => mul_nonneg hC₀ (norm_nonneg _)) hsub'.eventuallyLE theorem not_integrableOn_of_tendsto_norm_atTop_of_deriv_isBigO_filter
Mathlib/Analysis/SpecialFunctions/NonIntegrable.lean
52
96
/- 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 -/ import Mathlib.Data.Set.Operations import Mathlib.Order.Basic import Mathlib.Order.BooleanAlgebra import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators import Mathlib.Tactic.Lift /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the module `Mathlib.Data.Set.Defs`. This file provides some basic definitions related to sets and functions not present in the definitions file, as well as extra lemmas for functions defined in the definitions file and `Mathlib.Data.Set.Operations` (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ assert_not_exists RelIso /-! ### Set coercion to a type -/ open Function universe u v namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebra : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ namespace Set variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto theorem setOf_injective : Function.Injective (@setOf α) := injective_id theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl /-- This lemma is intended for use with `rw` where a membership predicate is needed, hence the explicit argument and the equality in the reverse direction from normal. See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/ theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl theorem setOf_set {s : Set α} : setOf s = s := rfl theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by simp [not_subset] lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s := ⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩ protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not /-! ### Non-empty sets -/ theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty := nonempty_subtype alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype -- Redeclare for refined keys -- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))` instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) := inferInstanceAs (Nonempty (univ : Set α)) theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› @[deprecated (since := "2024-11-23")] alias nonempty_of_nonempty_subtype := Nonempty.of_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun @[simp] theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => iff_of_eq (or_false _) @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => iff_of_eq (false_or _) theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ @[simp] theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s := left_lt_sup @[simp] theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t := right_lt_sup /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => iff_of_eq (and_false _) @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => iff_of_eq (false_and _) theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ @[simp] theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s := inf_lt_right @[simp] theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t := inf_lt_left /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff] theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp] @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and] theorem sep_true : { x ∈ s | True } = s := inter_univ s theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl end Sep /-- See also `Set.sdiff_inter_right_comm`. -/ lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc .. /-- See also `Set.inter_diff_assoc`. -/ lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm .. lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm .. theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut /-- A version of `diff_union_diff_cancel` with more general hypotheses. -/ theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u := sdiff_sup_sdiff_cancel' hi hu theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) := inf_sdiff /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm lemma inl_compl_union_inr_compl {α β : Type*} {s : Set α} {t : Set β} : Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by rw [compl_union] aesop theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) : r \ s ⊆ r \ t ↔ t ⊆ s := sdiff_le_sdiff_iff_le hs ht theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ := Eq.trans compl_sdiff himp_eq theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by rw [diff_eq, diff_eq, inter_right_comm] theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by rw [diff_eq, diff_eq, inter_right_comm] @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf /-! ### Powerset -/ theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h @[simp] theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s := Iff.rfl theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t := ext fun _ => subset_inter_iff @[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t := ⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩ theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2 @[simp] theorem powerset_nonempty : (𝒫 s).Nonempty := ⟨∅, fun _ h => empty_subset s h⟩ @[simp] theorem powerset_empty : 𝒫(∅ : Set α) = {∅} := ext fun _ => subset_empty_iff @[simp] theorem powerset_univ : 𝒫(univ : Set α) = univ := eq_univ_of_forall subset_univ /-! ### Sets defined as an if-then-else -/ @[deprecated _root_.mem_dite (since := "2025-01-30")] protected theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) : (x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := _root_.mem_dite theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by simp [mem_dite] @[simp] theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t Set.univ ↔ p → x ∈ t := mem_dite_univ_right p (fun _ => t) x theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by split_ifs <;> simp_all @[simp] theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p Set.univ t ↔ ¬p → x ∈ t := mem_dite_univ_left p (fun _ => t) x theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false, not_not] exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩ @[simp] theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t ∅ ↔ p ∧ x ∈ t := (mem_dite_empty_right p (fun _ => t) x).trans (by simp) theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false] exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩ @[simp] theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t := (mem_dite_empty_left p (fun _ => t) x).trans (by simp) /-! ### If-then-else for sets -/ /-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`. Defined as `s ∩ t ∪ s' \ t`. -/ protected def ite (t s s' : Set α) : Set α := s ∩ t ∪ s' \ t @[simp] theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty] @[simp] theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq] @[simp] theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by rw [← ite_compl, ite_inter_self] @[simp] theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t := ite_inter_compl_self t s s' @[simp] theorem ite_same (t s : Set α) : t.ite s s = s := inter_union_diff _ _ @[simp] theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite] @[simp] theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite] @[simp] theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite] @[simp] theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite] @[simp] theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite] @[simp] theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite] theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') : t.ite s₁ s₁' ⊆ t.ite s₂ s₂' := union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h') theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' := union_subset_union inter_subset_left diff_subset theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' := ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) : t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
Mathlib/Data/Set/Basic.lean
1,372
1,373
/- Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Patrick Lutz -/ import Mathlib.FieldTheory.Galois.Basic /-! # Galois Groups of Polynomials In this file, we introduce the Galois group of a polynomial `p` over a field `F`, defined as the automorphism group of its splitting field. We also provide some results about some extension `E` above `p.SplittingField`. ## Main definitions - `Polynomial.Gal p`: the Galois group of a polynomial p. - `Polynomial.Gal.restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`. - `Polynomial.Gal.galAction p E`: the action of `gal p` on the roots of `p` in `E`. ## Main results - `Polynomial.Gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`. - `Polynomial.Gal.galActionHom_injective`: `gal p` acting on the roots of `p` in `E` is faithful. - `Polynomial.Gal.restrictProd_injective`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`. - `Polynomial.Gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality equal to the dimension of its splitting field over `F`. - `Polynomial.Gal.galActionHom_bijective_of_prime_degree`: An irreducible polynomial of prime degree with two non-real roots has full Galois group. ## Other results - `Polynomial.Gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots equals the number of real roots plus the number of roots not fixed by complex conjugation (i.e. with some imaginary component). -/ assert_not_exists Real noncomputable section open scoped Polynomial open Module namespace Polynomial variable {F : Type*} [Field F] (p q : F[X]) (E : Type*) [Field E] [Algebra F E] /-- The Galois group of a polynomial. -/ def Gal := p.SplittingField ≃ₐ[F] p.SplittingField -- The `Group, Fintype` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Gal instance instGroup : Group (Gal p) := inferInstanceAs (Group (p.SplittingField ≃ₐ[F] p.SplittingField)) instance instFintype : Fintype (Gal p) := inferInstanceAs (Fintype (p.SplittingField ≃ₐ[F] p.SplittingField)) instance : EquivLike p.Gal p.SplittingField p.SplittingField := inferInstanceAs (EquivLike (p.SplittingField ≃ₐ[F] p.SplittingField) _ _) instance : AlgEquivClass p.Gal F p.SplittingField p.SplittingField := inferInstanceAs (AlgEquivClass (p.SplittingField ≃ₐ[F] p.SplittingField) F _ _) instance applyMulSemiringAction : MulSemiringAction p.Gal p.SplittingField := AlgEquiv.applyMulSemiringAction @[ext] theorem ext {σ τ : p.Gal} (h : ∀ x ∈ p.rootSet p.SplittingField, σ x = τ x) : σ = τ := by refine AlgEquiv.ext fun x => (AlgHom.mem_equalizer σ.toAlgHom τ.toAlgHom x).mp ((SetLike.ext_iff.mp ?_ x).mpr Algebra.mem_top) rwa [eq_top_iff, ← SplittingField.adjoin_rootSet, Algebra.adjoin_le_iff] /-- If `p` splits in `F` then the `p.gal` is trivial. -/ def uniqueGalOfSplits (h : p.Splits (RingHom.id F)) : Unique p.Gal where default := 1 uniq f := AlgEquiv.ext fun x => by obtain ⟨y, rfl⟩ := Algebra.mem_bot.mp ((SetLike.ext_iff.mp ((IsSplittingField.splits_iff _ p).mp h) x).mp Algebra.mem_top) rw [AlgEquiv.commutes, AlgEquiv.commutes] instance [h : Fact (p.Splits (RingHom.id F))] : Unique p.Gal := uniqueGalOfSplits _ h.1 instance uniqueGalZero : Unique (0 : F[X]).Gal := uniqueGalOfSplits _ (splits_zero _) instance uniqueGalOne : Unique (1 : F[X]).Gal := uniqueGalOfSplits _ (splits_one _) instance uniqueGalC (x : F) : Unique (C x).Gal := uniqueGalOfSplits _ (splits_C _ _) instance uniqueGalX : Unique (X : F[X]).Gal := uniqueGalOfSplits _ (splits_X _) instance uniqueGalXSubC (x : F) : Unique (X - C x).Gal := uniqueGalOfSplits _ (splits_X_sub_C _) instance uniqueGalXPow (n : ℕ) : Unique (X ^ n : F[X]).Gal := uniqueGalOfSplits _ (splits_X_pow _ _) instance [h : Fact (p.Splits (algebraMap F E))] : Algebra p.SplittingField E := (IsSplittingField.lift p.SplittingField p h.1).toRingHom.toAlgebra instance [h : Fact (p.Splits (algebraMap F E))] : IsScalarTower F p.SplittingField E := IsScalarTower.of_algebraMap_eq fun x => ((IsSplittingField.lift p.SplittingField p h.1).commutes x).symm -- The `Algebra p.SplittingField E` instance above behaves badly when -- `E := p.SplittingField`, since it may result in a unification problem -- `IsSplittingField.lift.toRingHom.toAlgebra =?= Algebra.id`, -- which takes an extremely long time to resolve, causing timeouts. -- Since we don't really care about this definition, marking it as irreducible -- causes that unification to error out early. /-- Restrict from a superfield automorphism into a member of `gal p`. -/ def restrict [Fact (p.Splits (algebraMap F E))] : (E ≃ₐ[F] E) →* p.Gal := AlgEquiv.restrictNormalHom p.SplittingField theorem restrict_surjective [Fact (p.Splits (algebraMap F E))] [Normal F E] : Function.Surjective (restrict p E) := AlgEquiv.restrictNormalHom_surjective E section RootsAction /-- The function taking `rootSet p p.SplittingField` to `rootSet p E`. This is actually a bijection, see `Polynomial.Gal.mapRoots_bijective`. -/ def mapRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField → rootSet p E := Set.MapsTo.restrict (IsScalarTower.toAlgHom F p.SplittingField E) _ _ <| rootSet_mapsTo _ theorem mapRoots_bijective [h : Fact (p.Splits (algebraMap F E))] : Function.Bijective (mapRoots p E) := by constructor · exact fun _ _ h => Subtype.ext (RingHom.injective _ (Subtype.ext_iff.mp h)) · intro y -- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial have key := roots_map (IsScalarTower.toAlgHom F p.SplittingField E : p.SplittingField →+* E) ((splits_id_iff_splits _).mpr (IsSplittingField.splits p.SplittingField p)) rw [map_map, AlgHom.comp_algebraMap] at key have hy := Subtype.mem y simp only [rootSet, Finset.mem_coe, Multiset.mem_toFinset, key, Multiset.mem_map] at hy rcases hy with ⟨x, hx1, hx2⟩ exact ⟨⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr hx1⟩, Subtype.ext hx2⟩ /-- The bijection between `rootSet p p.SplittingField` and `rootSet p E`. -/ def rootsEquivRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField ≃ rootSet p E := Equiv.ofBijective (mapRoots p E) (mapRoots_bijective p E) instance galActionAux : MulAction p.Gal (rootSet p p.SplittingField) where smul ϕ := Set.MapsTo.restrict ϕ _ _ <| rootSet_mapsTo ϕ.toAlgHom one_smul _ := by ext; rfl mul_smul _ _ _ := by ext; rfl instance smul [Fact (p.Splits (algebraMap F E))] : SMul p.Gal (rootSet p E) where smul ϕ x := rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x) theorem smul_def [Fact (p.Splits (algebraMap F E))] (ϕ : p.Gal) (x : rootSet p E) : ϕ • x = rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x) := rfl /-- The action of `gal p` on the roots of `p` in `E`. -/ instance galAction [Fact (p.Splits (algebraMap F E))] : MulAction p.Gal (rootSet p E) where one_smul _ := by simp only [smul_def, Equiv.apply_symm_apply, one_smul] mul_smul _ _ _ := by simp only [smul_def, Equiv.apply_symm_apply, Equiv.symm_apply_apply, mul_smul] lemma galAction_isPretransitive [Fact (p.Splits (algebraMap F E))] (hp : Irreducible p) : MulAction.IsPretransitive p.Gal (p.rootSet E) := by refine ⟨fun x y ↦ ?_⟩ have hx := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm x).2).2 have hy := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm y).2).2 obtain ⟨g, hg⟩ := (Normal.minpoly_eq_iff_mem_orbit p.SplittingField).mp (hy.symm.trans hx) exact ⟨g, (rootsEquivRoots p E).apply_eq_iff_eq_symm_apply.mpr (Subtype.ext hg)⟩ variable {p E} /-- `Polynomial.Gal.restrict p E` is compatible with `Polynomial.Gal.galAction p E`. -/ @[simp] theorem restrict_smul [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) : ↑(restrict p E ϕ • x) = ϕ x := by let ψ := AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F p.SplittingField E) change ↑(ψ (ψ.symm _)) = ϕ x rw [AlgEquiv.apply_symm_apply ψ] change ϕ (rootsEquivRoots p E ((rootsEquivRoots p E).symm x)) = ϕ x rw [Equiv.apply_symm_apply (rootsEquivRoots p E)] variable (p E) /-- `Polynomial.Gal.galAction` as a permutation representation -/ def galActionHom [Fact (p.Splits (algebraMap F E))] : p.Gal →* Equiv.Perm (rootSet p E) := MulAction.toPermHom _ _ theorem galActionHom_restrict [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) : ↑(galActionHom p E (restrict p E ϕ) x) = ϕ x := restrict_smul ϕ x /-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/ theorem galActionHom_injective [Fact (p.Splits (algebraMap F E))] :
Function.Injective (galActionHom p E) := by rw [injective_iff_map_eq_one] intro ϕ hϕ ext (x hx) have key := Equiv.Perm.ext_iff.mp hϕ (rootsEquivRoots p E ⟨x, hx⟩) change rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm (rootsEquivRoots p E ⟨x, hx⟩)) =
Mathlib/FieldTheory/PolynomialGaloisGroup.lean
209
215
/- 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.MeasurableSpace.MeasurablyGenerated import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.Order.Interval.Set.Monotone /-! # 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 Topology Filter ENNReal NNReal Interval MeasureTheory open scoped symmDiff 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⟩⟩ /-- 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] theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by contrapose! hs exact ((measure_mono (subset_diff_union s t)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne 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 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] lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint 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_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ := measure_mono_top subset_union_right (measure_diff_eq_top ht hs) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet 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 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 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] 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] 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 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 /-- 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)) /-- 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] 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] @[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] : ∑ x ∈ s, μ {x} = μ s := by trans ∑ x ∈ s, μ (id ⁻¹' {x}) · simp rw [sum_measure_preimage_singleton] · simp · simp theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self] theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] 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 /-- 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 := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩] _ ≤ μ (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 : NullMeasurableSet 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 theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] 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) 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)⟩ 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 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 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 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⟩⟩ @[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] theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet 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] /-- 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 : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α} (hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by refine le_antisymm (by gcongr; apply hsub) ?_ rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop) · calc μ (⋃ i, t i) ≤ ∞ := le_top _ ≤ μ (s i) := hi ▸ h_le i _ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _ push_neg at htop 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 _ _) · measurability · 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 _ 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μ⟩) @[simp] theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) : μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) := Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦ (measure_toMeasurable _).le 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] @[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 @[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 theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset₀ H h] exact measure_mono (subset_univ _) theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (H : Pairwise (AEDisjoint μ 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 /-- 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, NullMeasurableSet (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)).aedisjoint /-- 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, NullMeasurableSet (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)).aedisjoint /-- 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) /-- 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. -/ 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 /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily measurable) sets is the supremum of the measures. -/ theorem _root_.Directed.measure_iUnion [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by -- WLOG, `ι = ℕ` rcases Countable.exists_injective_nat ι with ⟨e, he⟩ generalize ht : Function.extend e s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot he suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot he, Function.comp_def, Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot he _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i ↦ measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := .disjointed fun n ↦ measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) = μ (⋃ n, Td n) := by rw [iUnion_disjointed, measure_iUnion_toMeasurable] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N /-- Continuity from below: the measure of the union of a monotone family of sets is equal to the supremum of their measures. The theorem assumes that the `atTop` filter on the index set is countably generated, so it works for a family indexed by a countable type, as well as `ℝ`. -/ theorem _root_.Monotone.measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases isEmpty_or_nonempty ι with | inl _ => simp | inr _ => rcases exists_seq_monotone_tendsto_atTop_atTop ι with ⟨x, hxm, hx⟩ rw [← hs.iUnion_comp_tendsto_atTop hx, ← Monotone.iSup_comp_tendsto_atTop _ hx] exacts [(hs.comp hxm).directed_le.measure_iUnion, fun _ _ h ↦ measure_mono (hs h)] theorem _root_.Antitone.measure_iUnion [Preorder ι] [IsDirected ι (· ≥ ·)] [(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := hs.dual_left.measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup_accumulate [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by rw [← iUnion_accumulate] exact monotone_accumulate.measure_iUnion theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.to_subtype rw [biUnion_eq_iUnion, hd.directed_val.measure_iUnion, ← iSup_subtype''] /-- **Continuity from above**: the measure of the intersection of a directed downwards countable family of measurable sets is the infimum of the measures. -/ theorem _root_.Directed.measure_iInter [Countable ι] {s : ι → Set α} (h : ∀ i, NullMeasurableSet (s i) μ) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le (fun i => μ (s i)) k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (.iInter h) (this _ (iInter_subset _ k)), diff_iInter, Directed.measure_iUnion] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => le_measure_diff) rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right /-- **Continuity from above**: the measure of the intersection of a monotone family of measurable sets indexed by a type with countably generated `atBot` filter is equal to the infimum of the measures. -/ theorem _root_.Monotone.measure_iInter [Preorder ι] [IsDirected ι (· ≥ ·)] [(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) (hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by refine le_antisymm (le_iInf fun i ↦ measure_mono <| iInter_subset _ _) ?_ have := hfin.nonempty rcases exists_seq_antitone_tendsto_atTop_atBot ι with ⟨x, hxm, hx⟩ calc ⨅ i, μ (s i) ≤ ⨅ n, μ (s (x n)) := le_iInf_comp (μ ∘ s) x _ = μ (⋂ n, s (x n)) := by refine .symm <| (hs.comp_antitone hxm).directed_ge.measure_iInter (fun n ↦ hsm _) ?_ rcases hfin with ⟨k, hk⟩ rcases (hx.eventually_le_atBot k).exists with ⟨n, hn⟩ exact ⟨n, ne_top_of_le_ne_top hk <| measure_mono <| hs hn⟩ _ ≤ μ (⋂ i, s i) := by refine measure_mono <| iInter_mono' fun i ↦ ?_ rcases (hx.eventually_le_atBot i).exists with ⟨n, hn⟩ exact ⟨n, hs hn⟩ /-- **Continuity from above**: the measure of the intersection of an antitone family of measurable sets indexed by a type with countably generated `atTop` filter is equal to the infimum of the measures. -/ theorem _root_.Antitone.measure_iInter [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) (hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := hs.dual_left.measure_iInter hsm hfin /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by rw [← Antitone.measure_iInter] · rw [iInter_comm] exact congrArg μ <| iInter_congr fun i ↦ (biInf_const nonempty_Ici).symm · exact fun i j h ↦ biInter_mono (Iic_subset_Iic.2 h) fun _ _ ↦ Set.Subset.rfl · exact fun i ↦ .biInter (to_countable _) fun _ _ ↦ h _ · refine hfin.imp fun k hk ↦ ne_top_of_le_ne_top hk <| measure_mono <| iInter₂_subset k ?_ rfl /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [hm.measure_iUnion] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm theorem tendsto_measure_iUnion_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)] {s : ι → Set α} (hm : Antitone s) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋃ n, s n))) := tendsto_measure_iUnion_atTop (ι := ιᵒᵈ) hm.dual_left /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion_accumulate {α ι : Type*} [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {_ : MeasurableSpace α} {μ : Measure α} {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [measure_iUnion_eq_iSup_accumulate] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [hm.measure_iInter hs hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm /-- Continuity from above: the measure of the intersection of an increasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)] {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Monotone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋂ n, s n))) := tendsto_measure_iInter_atTop (ι := ιᵒᵈ) hs hm.dual_left hf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [Countable ι] [Preorder ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ≤ i, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by refine .of_neBot_imp fun hne ↦ ?_ cases atTop_neBot_iff.mp hne rw [measure_iInter_eq_iInf_measure_iInter_le hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- Some version of continuity of a measure in the empty set using the intersection along a set of sets. -/ theorem exists_measure_iInter_lt {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [SemilatticeSup ι] [Countable ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ) {ε : ℝ≥0∞} (hε : 0 < ε) (hfin : ∃ i, μ (f i) ≠ ∞) (hfem : ⋂ n, f n = ∅) : ∃ m, μ (⋂ n ≤ m, f n) < ε := by let F m := μ (⋂ n ≤ m, f n) have hFAnti : Antitone F := fun i j hij => measure_mono (biInter_subset_biInter_left fun k hki => le_trans hki hij) suffices Filter.Tendsto F Filter.atTop (𝓝 0) by rw [@ENNReal.tendsto_atTop_zero_iff_lt_of_antitone _ (nonempty_of_exists hfin) _ _ hFAnti] at this exact this ε hε have hzero : μ (⋂ n, f n) = 0 := by simp only [hfem, measure_empty] rw [← hzero] exact tendsto_measure_iInter_le hm hfin /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, NullMeasurableSet (s r) μ) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by have : (atBot : Filter (Ioi a)).IsCountablyGenerated := by rw [← comap_coe_Ioi_nhdsGT] infer_instance simp_rw [← map_coe_Ioi_atBot, tendsto_map'_iff, ← mem_Ioi, biInter_eq_iInter] apply tendsto_measure_iInter_atBot · rwa [Subtype.forall] · exact fun i j h ↦ hm i j i.2 h · simpa only [Subtype.exists, exists_prop] theorem measure_if {x : β} {t : Set β} {s : Set α} [Decidable (x ∈ t)] : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self end OuterMeasure section variable {m0 : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero {_ : MeasurableSpace α} : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl @[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_zero [ms : MeasurableSpace α] (h : ms ≤ (0 : OuterMeasure α).caratheodory) : (0 : OuterMeasure α).toMeasure h = 0 := by ext s hs simp [hs] @[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_eq_zero {ms : MeasurableSpace α} {μ : OuterMeasure α} (h : ms ≤ μ.caratheodory) : μ.toMeasure h = 0 ↔ μ = 0 where mp hμ := by ext s; exact le_bot_iff.1 <| (le_toMeasure_apply _ _ _).trans_eq congr($hμ s) mpr := by rintro rfl; simp @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 instance instInhabited {_ : MeasurableSpace α} : Inhabited (Measure α) := ⟨0⟩ instance instAdd {_ : MeasurableSpace α} : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul {_ : MeasurableSpace α} : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] {_ : MeasurableSpace α} : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] {_ : MeasurableSpace α} : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] {_ : MeasurableSpace α} : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure instance instAddCommMonoid {_ : MeasurableSpace α} : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add @[simp] theorem coeAddHom_apply {_ : MeasurableSpace α} (μ : Measure α) : coeAddHom μ = ⇑μ := rfl @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure {p : α → Prop} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x := ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, ← smul_one_smul ℝ≥0∞, smul_zero] theorem ae_smul_measure_le [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) : ae (c • μ) ≤ ae μ := fun _ h ↦ ae_smul_measure h c section SMulWithZero variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} {p : α → Prop} lemma ae_smul_measure_iff (hc : c ≠ 0) {μ : Measure α} : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp [ae_iff, hc] @[simp] lemma ae_smul_measure_eq (hc : c ≠ 0) (μ : Measure α) : ae (c • μ) = ae μ := by ext; exact ae_smul_measure_iff hc end SMulWithZero theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder {_ : MeasurableSpace α} : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl _ _ := le_rfl le_trans _ _ _ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm _ _ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] instance instAddLeftMono {_ : MeasurableSpace α} : AddLeftMono (Measure α) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) instance {_ : MeasurableSpace α} : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun _ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf {_ : MeasurableSpace α} : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } instance instCompleteLattice {_ : MeasurableSpace α} : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun _ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } end sInf lemma inf_apply {s : Set α} (hs : MeasurableSet s) : (μ ⊓ ν) s = sInf {m | ∃ t, m = μ (t ∩ s) + ν (tᶜ ∩ s)} := by -- `(μ ⊓ ν) s` is defined as `⊓ (t : ℕ → Set α) (ht : s ⊆ ⋃ n, t n), ∑' n, μ (t n) ⊓ ν (t n)` rw [← sInf_pair, Measure.sInf_apply hs, OuterMeasure.sInf_apply (image_nonempty.2 <| insert_nonempty μ {ν})] refine le_antisymm (le_sInf fun m ⟨t, ht₁⟩ ↦ ?_) (le_iInf₂ fun t' ht' ↦ ?_) · subst ht₁ -- We first show `(μ ⊓ ν) s ≤ μ (t ∩ s) + ν (tᶜ ∩ s)` for any `t : Set α` -- For this, define the sequence `t' : ℕ → Set α` where `t' 0 = t ∩ s`, `t' 1 = tᶜ ∩ s` and -- `∅` otherwise. Then, we have by construction -- `(μ ⊓ ν) s ≤ ∑' n, μ (t' n) ⊓ ν (t' n) ≤ μ (t' 0) + ν (t' 1) = μ (t ∩ s) + ν (tᶜ ∩ s)`. set t' : ℕ → Set α := fun n ↦ if n = 0 then t ∩ s else if n = 1 then tᶜ ∩ s else ∅ with ht' refine (iInf₂_le t' fun x hx ↦ ?_).trans ?_ · by_cases hxt : x ∈ t · refine mem_iUnion.2 ⟨0, ?_⟩ simp [hx, hxt] · refine mem_iUnion.2 ⟨1, ?_⟩ simp [hx, hxt] · simp only [iInf_image, coe_toOuterMeasure, iInf_pair] rw [tsum_eq_add_tsum_ite 0, tsum_eq_add_tsum_ite 1, if_neg zero_ne_one.symm, ENNReal.summable.tsum_eq_zero_iff.2 _, add_zero] · exact add_le_add (inf_le_left.trans <| by simp [ht']) (inf_le_right.trans <| by simp [ht']) · simp only [ite_eq_left_iff] intro n hn₁ hn₀ simp only [ht', if_neg hn₀, if_neg hn₁, measure_empty, iInf_pair, le_refl, inf_of_le_left] · simp only [iInf_image, coe_toOuterMeasure, iInf_pair] -- Conversely, fixing `t' : ℕ → Set α` such that `s ⊆ ⋃ n, t' n`, we construct `t : Set α` -- for which `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n)`. -- Denoting `I := {n | μ (t' n) ≤ ν (t' n)}`, we set `t = ⋃ n ∈ I, t' n`. -- Clearly `μ (t ∩ s) ≤ ∑' n ∈ I, μ (t' n)` and `ν (tᶜ ∩ s) ≤ ∑' n ∉ I, ν (t' n)`, so -- `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n ∈ I, μ (t' n) + ∑' n ∉ I, ν (t' n)` -- where the RHS equals `∑' n, μ (t' n) ⊓ ν (t' n)` by the choice of `I`. set t := ⋃ n ∈ {k : ℕ | μ (t' k) ≤ ν (t' k)}, t' n with ht suffices hadd : μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n) by exact le_trans (sInf_le ⟨t, rfl⟩) hadd have hle₁ : μ (t ∩ s) ≤ ∑' (n : {k | μ (t' k) ≤ ν (t' k)}), μ (t' n) := (measure_mono inter_subset_left).trans <| measure_biUnion_le _ (to_countable _) _ have hcap : tᶜ ∩ s ⊆ ⋃ n ∈ {k | ν (t' k) < μ (t' k)}, t' n := by simp_rw [ht, compl_iUnion] refine fun x ⟨hx₁, hx₂⟩ ↦ mem_iUnion₂.2 ?_ obtain ⟨i, hi⟩ := mem_iUnion.1 <| ht' hx₂ refine ⟨i, ?_, hi⟩ by_contra h simp only [mem_setOf_eq, not_lt] at h exact mem_iInter₂.1 hx₁ i h hi have hle₂ : ν (tᶜ ∩ s) ≤ ∑' (n : {k | ν (t' k) < μ (t' k)}), ν (t' n) := (measure_mono hcap).trans (measure_biUnion_le ν (to_countable {k | ν (t' k) < μ (t' k)}) _) refine (add_le_add hle₁ hle₂).trans ?_ have heq : {k | μ (t' k) ≤ ν (t' k)} ∪ {k | ν (t' k) < μ (t' k)} = univ := by ext k; simp [le_or_lt] conv in ∑' (n : ℕ), μ (t' n) ⊓ ν (t' n) => rw [← tsum_univ, ← heq] rw [ENNReal.summable.tsum_union_disjoint (f := fun n ↦ μ (t' n) ⊓ ν (t' n)) ?_ ENNReal.summable] · refine add_le_add (tsum_congr ?_).le (tsum_congr ?_).le · rw [Subtype.forall] intro n hn; simpa · rw [Subtype.forall] intro n hn rw [mem_setOf_eq] at hn simp [le_of_lt hn] · rw [Set.disjoint_iff] rintro k ⟨hk₁, hk₂⟩ rw [mem_setOf_eq] at hk₁ hk₂ exact False.elim <| hk₂.not_le hk₁ @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) @[simp] theorem toOuterMeasure_top {_ : MeasurableSpace α} : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero lemma nonempty_of_neZero (μ : Measure α) [NeZero μ] : Nonempty α := (isEmpty_or_nonempty α).resolve_left fun h ↦ by simpa [eq_empty_of_isEmpty] using NeZero.ne (μ univ) section Sum variable {f : ι → Measure α} /-- Sum of an indexed family of measures. -/ noncomputable def sum (f : ι → Measure α) : Measure α := (OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <| le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _) (OuterMeasure.le_sum_caratheodory _) theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s := le_toMeasure_apply _ _ _ @[simp] theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : sum f s = ∑' i, f i s := toMeasure_apply _ _ hs theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩ calc sum f s = sum f t := measure_congr ht.symm _ = ∑' i, f i t := sum_apply _ t_meas _ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts /-! For the next theorem, the countability assumption is necessary. For a counterexample, consider an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets not containing `x₀`, and their complements. All points but `x₀` are measurable. Consider the sum of the Dirac masses at points different from `x₀`, and `s = {x₀}`. For any Dirac mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one gets `sum δ_x {x₀} = ∞`. -/ theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩ calc sum f s ≤ sum f t := measure_mono hst _ = ∑' i, f i t := sum_apply _ htm _ = ∑' i, f i s := by simp [ht] theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ := le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i @[simp] theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [sum_apply_of_countable] theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs] @[simp] lemma sum_eq_zero : sum f = 0 ↔ ∀ i, f i = 0 := by simp +contextual [Measure.ext_iff, forall_swap (α := ι)] @[simp] lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by ext s hs simp [Measure.sum_apply _ hs] theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by ext1 s hs simp [sum_apply _ hs, ENNReal.tsum_prod'] theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by ext1 s hs simp_rw [sum_apply _ hs] rw [ENNReal.tsum_comm] theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero' h.compl @[simp] theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by ext1 s hs simp only [sum_apply, finset_sum_apply, hs, tsum_fintype] theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) : (sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ] @[simp] theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) := Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by rw [sum_fintype, Fintype.sum_bool] theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν := sum_bool _ @[simp] theorem sum_of_isEmpty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty] theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) : ((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by ext1 t ht simp only [add_apply, sum_apply _ ht] exact ENNReal.summable.tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν := congr_arg sum (funext h) theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by ext1 s hs simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add, ENNReal.summable.tsum_add ENNReal.summable] @[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) : sum (m ∘ e) = sum m := by ext s hs simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s) @[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) : sum (Function.extend f m 0) = sum m := by ext s hs simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)] end Sum /-! ### The `cofinite` filter -/ /-- The filter of sets `s` such that `sᶜ` has finite measure. -/ def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α := comk (μ · < ∞) (by simp) (fun _ ht _ hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦ (measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩ theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := Iff.rfl theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl] theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ := Iff.rfl instance cofinite.instIsMeasurablyGenerated : IsMeasurablyGenerated μ.cofinite where exists_measurable_subset s hs := by refine ⟨(toMeasurable μ sᶜ)ᶜ, ?_, (measurableSet_toMeasurable _ _).compl, ?_⟩ · rwa [compl_mem_cofinite, measure_toMeasurable] · rw [compl_subset_comm] apply subset_toMeasurable end Measure open Measure open MeasureTheory protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) : NullMeasurable f μ := let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β} (hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ := hf.nullMeasurable hs @[simp] theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero] @[simp] theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 := neBot_iff.trans (not_congr ae_eq_bot) instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ @[simp] theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ := ae_eq_bot.2 rfl section Intervals theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable) (hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) : ⨆ x ∈ s, μ (Iic x) = μ univ := by rw [← measure_biUnion_eq_iSup hsc] · congr simp only [← bex_def] at hst exact iUnion₂_eq_univ_iff.2 hst · exact directedOn_iff_directed.2 (hdir.directed_val.mono_comp _ fun x y => Iic_subset_Iic.2) theorem tendsto_measure_Ico_atTop [Preorder α] [NoMaxOrder α] [(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) : Tendsto (fun x => μ (Ico a x)) atTop (𝓝 (μ (Ici a))) := by rw [← iUnion_Ico_right] exact tendsto_measure_iUnion_atTop (antitone_const.Ico monotone_id) theorem tendsto_measure_Ioc_atBot [Preorder α] [NoMinOrder α] [(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) : Tendsto (fun x => μ (Ioc x a)) atBot (𝓝 (μ (Iic a))) := by rw [← iUnion_Ioc_left] exact tendsto_measure_iUnion_atBot (monotone_id.Ioc antitone_const) theorem tendsto_measure_Iic_atTop [Preorder α] [(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) : Tendsto (fun x => μ (Iic x)) atTop (𝓝 (μ univ)) := by rw [← iUnion_Iic] exact tendsto_measure_iUnion_atTop monotone_Iic theorem tendsto_measure_Ici_atBot [Preorder α] [(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) : Tendsto (fun x => μ (Ici x)) atBot (𝓝 (μ univ)) := tendsto_measure_Iic_atTop (α := αᵒᵈ) μ variable [PartialOrder α] {a b : α} theorem Iio_ae_eq_Iic' (ha : μ {a} = 0) : Iio a =ᵐ[μ] Iic a := by rw [← Iic_diff_right, diff_ae_eq_self, measure_mono_null Set.inter_subset_right ha] theorem Ioi_ae_eq_Ici' (ha : μ {a} = 0) : Ioi a =ᵐ[μ] Ici a := Iio_ae_eq_Iic' (α := αᵒᵈ) ha theorem Ioo_ae_eq_Ioc' (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Ioc a b := (ae_eq_refl _).inter (Iio_ae_eq_Iic' hb) theorem Ioc_ae_eq_Icc' (ha : μ {a} = 0) : Ioc a b =ᵐ[μ] Icc a b := (Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _) theorem Ioo_ae_eq_Ico' (ha : μ {a} = 0) : Ioo a b =ᵐ[μ] Ico a b := (Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _) theorem Ioo_ae_eq_Icc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Icc a b := (Ioi_ae_eq_Ici' ha).inter (Iio_ae_eq_Iic' hb) theorem Ico_ae_eq_Icc' (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Icc a b := (ae_eq_refl _).inter (Iio_ae_eq_Iic' hb) theorem Ico_ae_eq_Ioc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Ioc a b := (Ioo_ae_eq_Ico' ha).symm.trans (Ioo_ae_eq_Ioc' hb) end Intervals end end MeasureTheory end
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
1,837
1,841
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.Polynomial.Inductions import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Ring.Regular import Mathlib.RingTheory.Multiplicity import Mathlib.Data.Nat.Lattice /-! # Division of univariate polynomials The main defs are `divByMonic` and `modByMonic`. The compatibility between these is given by `modByMonic_add_div`. We also define `rootMultiplicity`. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ} section Semiring variable [Semiring R] theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 := ⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf => ⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩ theorem X_pow_dvd_iff {f : R[X]} {n : ℕ} : X ^ n ∣ f ↔ ∀ d < n, f.coeff d = 0 := ⟨fun ⟨g, hgf⟩ d hd => by simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff], fun hd => by induction n with | zero => simp [pow_zero, one_dvd] | succ n hn => obtain ⟨g, hgf⟩ := hn fun d : ℕ => fun H : d < n => hd _ (Nat.lt_succ_of_lt H) have := coeff_X_pow_mul g n 0 rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm use k rwa [pow_succ, mul_assoc, ← hgk]⟩ variable {p q : R[X]} theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot ℕ) < degree p) (hmp : Monic p) (hq : q ≠ 0) : FiniteMultiplicity p q := have zn0 : (0 : R) ≠ 1 := haveI := Nontrivial.of_polynomial_ne hq zero_ne_one ⟨natDegree q, fun ⟨r, hr⟩ => by have hp0 : p ≠ 0 := fun hp0 => by simp [hp0] at hp have hr0 : r ≠ 0 := fun hr0 => by subst hr0; simp [hq] at hr have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp] have hpn0' : leadingCoeff p ^ (natDegree q + 1) ≠ 0 := hpn1.symm ▸ zn0.symm have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r ≠ 0 := by simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne, hr0, not_false_eq_true] have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by rw [← degree_eq_natDegree hp0]; exact hp have := congr_arg natDegree hr rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp) (add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _))) this⟩ @[deprecated (since := "2024-11-30")] alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic end Semiring section Ring variable [Ring R] {p q : R[X]} theorem div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : Monic q) : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p := have hp : leadingCoeff p ≠ 0 := mt leadingCoeff_eq_zero.1 h.2 have hq0 : q ≠ 0 := hq.ne_zero_of_polynomial_ne h.2 have hlt : natDegree q ≤ natDegree p := (Nat.cast_le (α := WithBot ℕ)).1 (by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1) degree_sub_lt (by rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2, degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt]) h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C]) /-- See `divByMonic`. -/ noncomputable def divModByMonicAux : ∀ (_p : R[X]) {q : R[X]}, Monic q → R[X] × R[X] | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q) have _wf := div_wf_lemma h hq let dm := divModByMonicAux (p - q * z) hq ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ termination_by p => p /-- `divByMonic`, denoted as `p /ₘ q`, gives the quotient of `p` by a monic polynomial `q`. -/ def divByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).1 else 0 /-- `modByMonic`, denoted as `p %ₘ q`, gives the remainder of `p` by a monic polynomial `q`. -/ def modByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).2 else p @[inherit_doc] infixl:70 " /ₘ " => divByMonic @[inherit_doc] infixl:70 " %ₘ " => modByMonic theorem degree_modByMonic_lt [Nontrivial R] : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %ₘ q) < degree q | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq have := degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic at this ⊢ unfold divModByMonicAux dsimp rw [dif_pos hq] at this ⊢ rw [if_pos h] exact this else Or.casesOn (not_and_or.1 h) (by unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h] exact lt_of_not_ge) (by intro hp unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, Classical.not_not.1 hp] exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero))) termination_by p => p theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q ≠ 1) : natDegree (p %ₘ q) < q.natDegree := by by_cases hpq : p %ₘ q = 0 · rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero] contrapose! hq exact eq_one_of_monic_natDegree_zero hmq hq · haveI := Nontrivial.of_polynomial_ne hpq exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq) @[simp] theorem zero_modByMonic (p : R[X]) : 0 %ₘ p = 0 := by classical unfold modByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero] · rw [dif_neg hp] @[simp] theorem zero_divByMonic (p : R[X]) : 0 /ₘ p = 0 := by classical unfold divByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero] · rw [dif_neg hp] @[simp] theorem modByMonic_zero (p : R[X]) : p %ₘ 0 = p := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold modByMonic divModByMonicAux; rw [dif_neg h] @[simp] theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold divByMonic divModByMonicAux; rw [dif_neg h] theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p /ₘ q = 0 := dif_neg hq theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p %ₘ q = p := dif_neg hq theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q := ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by nontriviality R exact (degree_modByMonic_lt _ hq).le theorem degree_modByMonic_le_left : degree (p %ₘ q) ≤ degree p := by nontriviality R by_cases hq : q.Monic · cases lt_or_ge (degree p) (degree q) · rw [(modByMonic_eq_self_iff hq).mpr ‹_›] · exact (degree_modByMonic_le p hq).trans ‹_› · rw [modByMonic_eq_of_not_monic p hq] theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) : natDegree (p %ₘ g) ≤ g.natDegree := natDegree_le_natDegree (degree_modByMonic_le p hg) theorem natDegree_modByMonic_le_left : natDegree (p %ₘ q) ≤ natDegree p := natDegree_le_natDegree degree_modByMonic_le_left theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by simp [X_dvd_iff, coeff_C] theorem modByMonic_eq_sub_mul_div : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q) | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma h hq have ih := modByMonic_eq_sub_mul_div (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_pos h] rw [modByMonic, dif_pos hq] at ih refine ih.trans ?_ unfold divByMonic rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub] else by unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] termination_by p => p theorem modByMonic_add_div (p : R[X]) {q : R[X]} (hq : Monic q) : p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (modByMonic_eq_sub_mul_div p hq) theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q := ⟨fun h => by have := modByMonic_add_div p hq rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_add_divByMonic (hq : Monic q) (h : degree q ≤ degree p) : degree q + degree (p /ₘ q) = degree p := by nontriviality R have hdiv0 : p /ₘ q ≠ 0 := by rwa [Ne, divByMonic_eq_zero_iff hq, not_lt] have hlc : leadingCoeff q * leadingCoeff (p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul, Ne, leadingCoeff_eq_zero] have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) := calc degree (p %ₘ q) < degree q := degree_modByMonic_lt _ hq _ ≤ _ := by rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree hdiv0, ← Nat.cast_add, Nat.cast_le] exact Nat.le_add_right _ _ calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) := Eq.symm (degree_mul' hlc) _ = degree (p %ₘ q + q * (p /ₘ q)) := (degree_add_eq_right_of_degree_lt hmod).symm _ = _ := congr_arg _ (modByMonic_add_div _ hq) theorem degree_divByMonic_le (p q : R[X]) : degree (p /ₘ q) ≤ degree p := letI := Classical.decEq R if hp0 : p = 0 then by simp only [hp0, zero_divByMonic, le_refl] else if hq : Monic q then if h : degree q ≤ degree p then by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq h, degree_eq_natDegree hq.ne_zero,
degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 (not_lt.2 h))] exact WithBot.coe_le_coe.2 (Nat.le_add_left _ _) else by unfold divByMonic divModByMonicAux simp [dif_pos hq, h, if_false, degree_zero, bot_le] else (divByMonic_eq_of_not_monic p hq).symm ▸ bot_le theorem degree_divByMonic_lt (p : R[X]) {q : R[X]} (hq : Monic q) (hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p := if hpq : degree p < degree q then by haveI := Nontrivial.of_polynomial_ne hp0 rw [(divByMonic_eq_zero_iff hq).2 hpq, degree_eq_natDegree hp0] exact WithBot.bot_lt_coe _ else by
Mathlib/Algebra/Polynomial/Div.lean
295
308
/- 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.Data.NNReal.Basic import Mathlib.Order.Fin.Tuple import Mathlib.Order.Interval.Set.Monotone import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.MetricSpace.Bounded import Mathlib.Topology.MetricSpace.Pseudo.Real import Mathlib.Topology.Order.MonotoneConvergence /-! # Rectangular boxes in `ℝⁿ` In this file we define rectangular boxes in `ℝⁿ`. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` (usually `ι = Fin n` for some `n`). When we need to interpret a box `[l, u]` as a set, we use the product `{x | ∀ i, l i < x i ∧ x i ≤ u i}` of half-open intervals `(l i, u i]`. We exclude `l i` because this way boxes of a partition are disjoint as sets in `ℝⁿ`. Currently, the only use cases for these constructions are the definitions of Riemann-style integrals (Riemann, Henstock-Kurzweil, McShane). ## Main definitions We use the same structure `BoxIntegral.Box` both for ambient boxes and for elements of a partition. Each box is stored as two points `lower upper : ι → ℝ` and a proof of `∀ i, lower i < upper i`. We define instances `Membership (ι → ℝ) (Box ι)` and `CoeTC (Box ι) (Set <| ι → ℝ)` so that each box is interpreted as the set `{x | ∀ i, x i ∈ Set.Ioc (I.lower i) (I.upper i)}`. This way boxes of a partition are pairwise disjoint and their union is exactly the original box. We require boxes to be nonempty, because this way coercion to sets is injective. The empty box can be represented as `⊥ : WithBot (BoxIntegral.Box ι)`. We define the following operations on boxes: * coercion to `Set (ι → ℝ)` and `Membership (ι → ℝ) (BoxIntegral.Box ι)` as described above; * `PartialOrder` and `SemilatticeSup` instances such that `I ≤ J` is equivalent to `(I : Set (ι → ℝ)) ⊆ J`; * `Lattice` instances on `WithBot (BoxIntegral.Box ι)`; * `BoxIntegral.Box.Icc`: the closed box `Set.Icc I.lower I.upper`; defined as a bundled monotone map from `Box ι` to `Set (ι → ℝ)`; * `BoxIntegral.Box.face I i : Box (Fin n)`: a hyperface of `I : BoxIntegral.Box (Fin (n + 1))`; * `BoxIntegral.Box.distortion`: the maximal ratio of two lengths of edges of a box; defined as the supremum of `nndist I.lower I.upper / nndist (I.lower i) (I.upper i)`. We also provide a convenience constructor `BoxIntegral.Box.mk' (l u : ι → ℝ) : WithBot (Box ι)` that returns the box `⟨l, u, _⟩` if it is nonempty and `⊥` otherwise. ## Tags rectangular box -/ open Set Function Metric Filter noncomputable section open scoped NNReal Topology namespace BoxIntegral variable {ι : Type*} /-! ### Rectangular box: definition and partial order -/ /-- A nontrivial rectangular box in `ι → ℝ` with corners `lower` and `upper`. Represents the product of half-open intervals `(lower i, upper i]`. -/ structure Box (ι : Type*) where /-- coordinates of the lower and upper corners of the box -/ (lower upper : ι → ℝ) /-- Each lower coordinate is less than its upper coordinate: i.e., the box is non-empty -/ lower_lt_upper : ∀ i, lower i < upper i attribute [simp] Box.lower_lt_upper namespace Box variable (I J : Box ι) {x y : ι → ℝ} instance : Inhabited (Box ι) := ⟨⟨0, 1, fun _ ↦ zero_lt_one⟩⟩ theorem lower_le_upper : I.lower ≤ I.upper := fun i ↦ (I.lower_lt_upper i).le theorem lower_ne_upper (i) : I.lower i ≠ I.upper i := (I.lower_lt_upper i).ne instance : Membership (ι → ℝ) (Box ι) := ⟨fun I x ↦ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i)⟩ /-- The set of points in this box: this is the product of half-open intervals `(lower i, upper i]`, where `lower` and `upper` are this box' corners. -/ @[coe] def toSet (I : Box ι) : Set (ι → ℝ) := { x | x ∈ I } instance : CoeTC (Box ι) (Set <| ι → ℝ) := ⟨toSet⟩ @[simp] theorem mem_mk {l u x : ι → ℝ} {H} : x ∈ mk l u H ↔ ∀ i, x i ∈ Ioc (l i) (u i) := Iff.rfl @[simp, norm_cast] theorem mem_coe : x ∈ (I : Set (ι → ℝ)) ↔ x ∈ I := Iff.rfl theorem mem_def : x ∈ I ↔ ∀ i, x i ∈ Ioc (I.lower i) (I.upper i) := Iff.rfl theorem mem_univ_Ioc {I : Box ι} : (x ∈ pi univ fun i ↦ Ioc (I.lower i) (I.upper i)) ↔ x ∈ I := mem_univ_pi theorem coe_eq_pi : (I : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (I.lower i) (I.upper i) := Set.ext fun _ ↦ mem_univ_Ioc.symm @[simp] theorem upper_mem : I.upper ∈ I := fun i ↦ right_mem_Ioc.2 <| I.lower_lt_upper i theorem exists_mem : ∃ x, x ∈ I := ⟨_, I.upper_mem⟩ theorem nonempty_coe : Set.Nonempty (I : Set (ι → ℝ)) := I.exists_mem @[simp] theorem coe_ne_empty : (I : Set (ι → ℝ)) ≠ ∅ := I.nonempty_coe.ne_empty @[simp] theorem empty_ne_coe : ∅ ≠ (I : Set (ι → ℝ)) := I.coe_ne_empty.symm instance : LE (Box ι) := ⟨fun I J ↦ ∀ ⦃x⦄, x ∈ I → x ∈ J⟩ theorem le_def : I ≤ J ↔ ∀ x ∈ I, x ∈ J := Iff.rfl theorem le_TFAE : List.TFAE [I ≤ J, (I : Set (ι → ℝ)) ⊆ J, Icc I.lower I.upper ⊆ Icc J.lower J.upper, J.lower ≤ I.lower ∧ I.upper ≤ J.upper] := by tfae_have 1 ↔ 2 := Iff.rfl tfae_have 2 → 3 | h => by simpa [coe_eq_pi, closure_pi_set, lower_ne_upper] using closure_mono h tfae_have 3 ↔ 4 := Icc_subset_Icc_iff I.lower_le_upper tfae_have 4 → 2 | h, x, hx, i => Ioc_subset_Ioc (h.1 i) (h.2 i) (hx i) tfae_finish variable {I J} @[simp, norm_cast] theorem coe_subset_coe : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := Iff.rfl theorem le_iff_bounds : I ≤ J ↔ J.lower ≤ I.lower ∧ I.upper ≤ J.upper := (le_TFAE I J).out 0 3 theorem injective_coe : Injective ((↑) : Box ι → Set (ι → ℝ)) := by rintro ⟨l₁, u₁, h₁⟩ ⟨l₂, u₂, h₂⟩ h simp only [Subset.antisymm_iff, coe_subset_coe, le_iff_bounds] at h congr exacts [le_antisymm h.2.1 h.1.1, le_antisymm h.1.2 h.2.2] @[simp, norm_cast] theorem coe_inj : (I : Set (ι → ℝ)) = J ↔ I = J := injective_coe.eq_iff @[ext] theorem ext (H : ∀ x, x ∈ I ↔ x ∈ J) : I = J := injective_coe <| Set.ext H theorem ne_of_disjoint_coe (h : Disjoint (I : Set (ι → ℝ)) J) : I ≠ J := mt coe_inj.2 <| h.ne I.coe_ne_empty instance : PartialOrder (Box ι) := { PartialOrder.lift ((↑) : Box ι → Set (ι → ℝ)) injective_coe with le := (· ≤ ·) } /-- Closed box corresponding to `I : BoxIntegral.Box ι`. -/ protected def Icc : Box ι ↪o Set (ι → ℝ) := OrderEmbedding.ofMapLEIff (fun I : Box ι ↦ Icc I.lower I.upper) fun I J ↦ (le_TFAE I J).out 2 0 theorem Icc_def : Box.Icc I = Icc I.lower I.upper := rfl @[simp] theorem upper_mem_Icc (I : Box ι) : I.upper ∈ Box.Icc I := right_mem_Icc.2 I.lower_le_upper @[simp] theorem lower_mem_Icc (I : Box ι) : I.lower ∈ Box.Icc I := left_mem_Icc.2 I.lower_le_upper protected theorem isCompact_Icc (I : Box ι) : IsCompact (Box.Icc I) := isCompact_Icc theorem Icc_eq_pi : Box.Icc I = pi univ fun i ↦ Icc (I.lower i) (I.upper i) := (pi_univ_Icc _ _).symm theorem le_iff_Icc : I ≤ J ↔ Box.Icc I ⊆ Box.Icc J := (le_TFAE I J).out 0 2 theorem antitone_lower : Antitone fun I : Box ι ↦ I.lower := fun _ _ H ↦ (le_iff_bounds.1 H).1 theorem monotone_upper : Monotone fun I : Box ι ↦ I.upper := fun _ _ H ↦ (le_iff_bounds.1 H).2 theorem coe_subset_Icc : ↑I ⊆ Box.Icc I := fun _ hx ↦ ⟨fun i ↦ (hx i).1.le, fun i ↦ (hx i).2⟩ theorem isBounded_Icc [Finite ι] (I : Box ι) : Bornology.IsBounded (Box.Icc I) := by cases nonempty_fintype ι exact Metric.isBounded_Icc _ _ theorem isBounded [Finite ι] (I : Box ι) : Bornology.IsBounded I.toSet := Bornology.IsBounded.subset I.isBounded_Icc coe_subset_Icc /-! ### Supremum of two boxes -/ /-- `I ⊔ J` is the least box that includes both `I` and `J`. Since `↑I ∪ ↑J` is usually not a box, `↑(I ⊔ J)` is larger than `↑I ∪ ↑J`. -/ instance : SemilatticeSup (Box ι) := { sup := fun I J ↦ ⟨I.lower ⊓ J.lower, I.upper ⊔ J.upper, fun i ↦ (min_le_left _ _).trans_lt <| (I.lower_lt_upper i).trans_le (le_max_left _ _)⟩ le_sup_left := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_left, le_sup_left⟩ le_sup_right := fun _ _ ↦ le_iff_bounds.2 ⟨inf_le_right, le_sup_right⟩ sup_le := fun _ _ _ h₁ h₂ ↦ le_iff_bounds.2 ⟨le_inf (antitone_lower h₁) (antitone_lower h₂), sup_le (monotone_upper h₁) (monotone_upper h₂)⟩ } /-! ### `WithBot (Box ι)` In this section we define coercion from `WithBot (Box ι)` to `Set (ι → ℝ)` by sending `⊥` to `∅`. -/ /-- The set underlying this box: `⊥` is mapped to `∅`. -/ @[coe] def withBotToSet (o : WithBot (Box ι)) : Set (ι → ℝ) := o.elim ∅ (↑) instance withBotCoe : CoeTC (WithBot (Box ι)) (Set (ι → ℝ)) := ⟨withBotToSet⟩ @[simp, norm_cast] theorem coe_bot : ((⊥ : WithBot (Box ι)) : Set (ι → ℝ)) = ∅ := rfl @[simp, norm_cast] theorem coe_coe : ((I : WithBot (Box ι)) : Set (ι → ℝ)) = I := rfl theorem isSome_iff : ∀ {I : WithBot (Box ι)}, I.isSome ↔ (I : Set (ι → ℝ)).Nonempty | ⊥ => by unfold Option.isSome simp | (I : Box ι) => by unfold Option.isSome simp [I.nonempty_coe] theorem biUnion_coe_eq_coe (I : WithBot (Box ι)) : ⋃ (J : Box ι) (_ : ↑J = I), (J : Set (ι → ℝ)) = I := by induction I <;> simp [WithBot.coe_eq_coe] @[simp, norm_cast] theorem withBotCoe_subset_iff {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) ⊆ J ↔ I ≤ J := by induction I; · simp induction J; · simp [subset_empty_iff] simp [le_def] @[simp, norm_cast] theorem withBotCoe_inj {I J : WithBot (Box ι)} : (I : Set (ι → ℝ)) = J ↔ I = J := by simp only [Subset.antisymm_iff, ← le_antisymm_iff, withBotCoe_subset_iff] open scoped Classical in /-- Make a `WithBot (Box ι)` from a pair of corners `l u : ι → ℝ`. If `l i < u i` for all `i`, then the result is `⟨l, u, _⟩ : Box ι`, otherwise it is `⊥`. In any case, the result interpreted as a set in `ι → ℝ` is the set `{x : ι → ℝ | ∀ i, x i ∈ Ioc (l i) (u i)}`. -/ def mk' (l u : ι → ℝ) : WithBot (Box ι) := if h : ∀ i, l i < u i then ↑(⟨l, u, h⟩ : Box ι) else ⊥ @[simp] theorem mk'_eq_bot {l u : ι → ℝ} : mk' l u = ⊥ ↔ ∃ i, u i ≤ l i := by rw [mk'] split_ifs with h <;> simpa using h @[simp] theorem mk'_eq_coe {l u : ι → ℝ} : mk' l u = I ↔ l = I.lower ∧ u = I.upper := by obtain ⟨lI, uI, hI⟩ := I; rw [mk']; split_ifs with h · simp [WithBot.coe_eq_coe] · suffices l = lI → u ≠ uI by simpa rintro rfl rfl exact h hI @[simp] theorem coe_mk' (l u : ι → ℝ) : (mk' l u : Set (ι → ℝ)) = pi univ fun i ↦ Ioc (l i) (u i) := by rw [mk']; split_ifs with h · exact coe_eq_pi _ · rcases not_forall.mp h with ⟨i, hi⟩ rw [coe_bot, univ_pi_eq_empty] exact Ioc_eq_empty hi instance WithBot.inf : Min (WithBot (Box ι)) := ⟨fun I ↦ WithBot.recBotCoe (fun _ ↦ ⊥) (fun I J ↦ WithBot.recBotCoe ⊥ (fun J ↦ mk' (I.lower ⊔ J.lower) (I.upper ⊓ J.upper)) J) I⟩ @[simp] theorem coe_inf (I J : WithBot (Box ι)) : (↑(I ⊓ J) : Set (ι → ℝ)) = (I : Set _) ∩ J := by induction I · change ∅ = _ simp induction J · change ∅ = _ simp change ((mk' _ _ : WithBot (Box ι)) : Set (ι → ℝ)) = _ simp only [coe_eq_pi, ← pi_inter_distrib, Ioc_inter_Ioc, Pi.sup_apply, Pi.inf_apply, coe_mk', coe_coe] instance : Lattice (WithBot (Box ι)) := { inf := min inf_le_left := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_left inf_le_right := fun I J ↦ by rw [← withBotCoe_subset_iff, coe_inf] exact inter_subset_right le_inf := fun I J₁ J₂ h₁ h₂ ↦ by simp only [← withBotCoe_subset_iff, coe_inf] at * exact subset_inter h₁ h₂ } @[simp, norm_cast] theorem disjoint_withBotCoe {I J : WithBot (Box ι)} : Disjoint (I : Set (ι → ℝ)) J ↔ Disjoint I J := by simp only [disjoint_iff_inf_le, ← withBotCoe_subset_iff, coe_inf] rfl theorem disjoint_coe : Disjoint (I : WithBot (Box ι)) J ↔ Disjoint (I : Set (ι → ℝ)) J := disjoint_withBotCoe.symm
theorem not_disjoint_coe_iff_nonempty_inter : ¬Disjoint (I : WithBot (Box ι)) J ↔ (I ∩ J : Set (ι → ℝ)).Nonempty := by rw [disjoint_coe, Set.not_disjoint_iff_nonempty_inter] /-!
Mathlib/Analysis/BoxIntegral/Box/Basic.lean
340
345
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Ring.Associated import Mathlib.Algebra.Star.Unitary import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Tactic.Ring import Mathlib.Algebra.EuclideanDomain.Int /-! # ℤ[√d] The ring of integers adjoined with a square root of `d : ℤ`. After defining the norm, we show that it is a linearly ordered commutative ring, as well as an integral domain. We provide the universal property, that ring homomorphisms `ℤ√d →+* R` correspond to choices of square roots of `d` in `R`. -/ /-- The ring of integers adjoined with a square root of `d`. These have the form `a + b √d` where `a b : ℤ`. The components are called `re` and `im` by analogy to the negative `d` case. -/ @[ext] structure Zsqrtd (d : ℤ) where /-- Component of the integer not multiplied by `√d` -/ re : ℤ /-- Component of the integer multiplied by `√d` -/ im : ℤ deriving DecidableEq @[inherit_doc] prefix:100 "ℤ√" => Zsqrtd namespace Zsqrtd section variable {d : ℤ} /-- Convert an integer to a `ℤ√d` -/ def ofInt (n : ℤ) : ℤ√d := ⟨n, 0⟩ theorem ofInt_re (n : ℤ) : (ofInt n : ℤ√d).re = n := rfl theorem ofInt_im (n : ℤ) : (ofInt n : ℤ√d).im = 0 := rfl /-- The zero of the ring -/ instance : Zero (ℤ√d) := ⟨ofInt 0⟩ @[simp] theorem zero_re : (0 : ℤ√d).re = 0 := rfl @[simp] theorem zero_im : (0 : ℤ√d).im = 0 := rfl instance : Inhabited (ℤ√d) := ⟨0⟩ /-- The one of the ring -/ instance : One (ℤ√d) := ⟨ofInt 1⟩ @[simp] theorem one_re : (1 : ℤ√d).re = 1 := rfl @[simp] theorem one_im : (1 : ℤ√d).im = 0 := rfl /-- The representative of `√d` in the ring -/ def sqrtd : ℤ√d := ⟨0, 1⟩ @[simp] theorem sqrtd_re : (sqrtd : ℤ√d).re = 0 := rfl @[simp] theorem sqrtd_im : (sqrtd : ℤ√d).im = 1 := rfl /-- Addition of elements of `ℤ√d` -/ instance : Add (ℤ√d) := ⟨fun z w => ⟨z.1 + w.1, z.2 + w.2⟩⟩ @[simp] theorem add_def (x y x' y' : ℤ) : (⟨x, y⟩ + ⟨x', y'⟩ : ℤ√d) = ⟨x + x', y + y'⟩ := rfl @[simp] theorem add_re (z w : ℤ√d) : (z + w).re = z.re + w.re := rfl @[simp] theorem add_im (z w : ℤ√d) : (z + w).im = z.im + w.im := rfl /-- Negation in `ℤ√d` -/ instance : Neg (ℤ√d) := ⟨fun z => ⟨-z.1, -z.2⟩⟩ @[simp] theorem neg_re (z : ℤ√d) : (-z).re = -z.re := rfl @[simp] theorem neg_im (z : ℤ√d) : (-z).im = -z.im := rfl /-- Multiplication in `ℤ√d` -/ instance : Mul (ℤ√d) := ⟨fun z w => ⟨z.1 * w.1 + d * z.2 * w.2, z.1 * w.2 + z.2 * w.1⟩⟩ @[simp] theorem mul_re (z w : ℤ√d) : (z * w).re = z.re * w.re + d * z.im * w.im := rfl @[simp] theorem mul_im (z w : ℤ√d) : (z * w).im = z.re * w.im + z.im * w.re := rfl instance addCommGroup : AddCommGroup (ℤ√d) := by refine { add := (· + ·) zero := (0 : ℤ√d) sub := fun a b => a + -b neg := Neg.neg nsmul := @nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ zsmul := @zsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩ ⟨Neg.neg⟩ (@nsmulRec (ℤ√d) ⟨0⟩ ⟨(· + ·)⟩) add_assoc := ?_ zero_add := ?_ add_zero := ?_ neg_add_cancel := ?_ add_comm := ?_ } <;> intros <;> ext <;> simp [add_comm, add_left_comm] @[simp] theorem sub_re (z w : ℤ√d) : (z - w).re = z.re - w.re := rfl @[simp] theorem sub_im (z w : ℤ√d) : (z - w).im = z.im - w.im := rfl instance addGroupWithOne : AddGroupWithOne (ℤ√d) := { Zsqrtd.addCommGroup with natCast := fun n => ofInt n intCast := ofInt one := 1 } instance commRing : CommRing (ℤ√d) := by refine { Zsqrtd.addGroupWithOne with mul := (· * ·) npow := @npowRec (ℤ√d) ⟨1⟩ ⟨(· * ·)⟩, add_comm := ?_ left_distrib := ?_ right_distrib := ?_ zero_mul := ?_ mul_zero := ?_ mul_assoc := ?_ one_mul := ?_ mul_one := ?_ mul_comm := ?_ } <;> intros <;> ext <;> simp <;> ring instance : AddMonoid (ℤ√d) := by infer_instance instance : Monoid (ℤ√d) := by infer_instance instance : CommMonoid (ℤ√d) := by infer_instance instance : CommSemigroup (ℤ√d) := by infer_instance instance : Semigroup (ℤ√d) := by infer_instance instance : AddCommSemigroup (ℤ√d) := by infer_instance instance : AddSemigroup (ℤ√d) := by infer_instance instance : CommSemiring (ℤ√d) := by infer_instance instance : Semiring (ℤ√d) := by infer_instance instance : Ring (ℤ√d) := by infer_instance instance : Distrib (ℤ√d) := by infer_instance /-- Conjugation in `ℤ√d`. The conjugate of `a + b √d` is `a - b √d`. -/ instance : Star (ℤ√d) where star z := ⟨z.1, -z.2⟩ @[simp] theorem star_mk (x y : ℤ) : star (⟨x, y⟩ : ℤ√d) = ⟨x, -y⟩ := rfl @[simp] theorem star_re (z : ℤ√d) : (star z).re = z.re := rfl @[simp] theorem star_im (z : ℤ√d) : (star z).im = -z.im := rfl instance : StarRing (ℤ√d) where star_involutive _ := Zsqrtd.ext rfl (neg_neg _) star_mul a b := by ext <;> simp <;> ring star_add _ _ := Zsqrtd.ext rfl (neg_add _ _) -- Porting note: proof was `by decide` instance nontrivial : Nontrivial (ℤ√d) := ⟨⟨0, 1, Zsqrtd.ext_iff.not.mpr (by simp)⟩⟩ @[simp] theorem natCast_re (n : ℕ) : (n : ℤ√d).re = n := rfl @[simp] theorem ofNat_re (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).re = n := rfl @[simp] theorem natCast_im (n : ℕ) : (n : ℤ√d).im = 0 := rfl @[simp] theorem ofNat_im (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℤ√d).im = 0 := rfl theorem natCast_val (n : ℕ) : (n : ℤ√d) = ⟨n, 0⟩ := rfl @[simp] theorem intCast_re (n : ℤ) : (n : ℤ√d).re = n := by cases n <;> rfl @[simp] theorem intCast_im (n : ℤ) : (n : ℤ√d).im = 0 := by cases n <;> rfl theorem intCast_val (n : ℤ) : (n : ℤ√d) = ⟨n, 0⟩ := by ext <;> simp instance : CharZero (ℤ√d) where cast_injective m n := by simp [Zsqrtd.ext_iff] @[simp] theorem ofInt_eq_intCast (n : ℤ) : (ofInt n : ℤ√d) = n := by ext <;> simp [ofInt_re, ofInt_im] @[simp] theorem nsmul_val (n : ℕ) (x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp @[simp] theorem smul_val (n x y : ℤ) : (n : ℤ√d) * ⟨x, y⟩ = ⟨n * x, n * y⟩ := by ext <;> simp theorem smul_re (a : ℤ) (b : ℤ√d) : (↑a * b).re = a * b.re := by simp theorem smul_im (a : ℤ) (b : ℤ√d) : (↑a * b).im = a * b.im := by simp @[simp] theorem muld_val (x y : ℤ) : sqrtd (d := d) * ⟨x, y⟩ = ⟨d * y, x⟩ := by ext <;> simp @[simp] theorem dmuld : sqrtd (d := d) * sqrtd (d := d) = d := by ext <;> simp @[simp] theorem smuld_val (n x y : ℤ) : sqrtd * (n : ℤ√d) * ⟨x, y⟩ = ⟨d * n * y, n * x⟩ := by ext <;> simp theorem decompose {x y : ℤ} : (⟨x, y⟩ : ℤ√d) = x + sqrtd (d := d) * y := by ext <;> simp theorem mul_star {x y : ℤ} : (⟨x, y⟩ * star ⟨x, y⟩ : ℤ√d) = x * x - d * y * y := by ext <;> simp [sub_eq_add_neg, mul_comm] theorem intCast_dvd (z : ℤ) (a : ℤ√d) : ↑z ∣ a ↔ z ∣ a.re ∧ z ∣ a.im := by constructor · rintro ⟨x, rfl⟩ simp only [add_zero, intCast_re, zero_mul, mul_im, dvd_mul_right, and_self_iff, mul_re, mul_zero, intCast_im] · rintro ⟨⟨r, hr⟩, ⟨i, hi⟩⟩ use ⟨r, i⟩ rw [smul_val, Zsqrtd.ext_iff] exact ⟨hr, hi⟩ @[simp, norm_cast] theorem intCast_dvd_intCast (a b : ℤ) : (a : ℤ√d) ∣ b ↔ a ∣ b := by rw [intCast_dvd] constructor · rintro ⟨hre, -⟩ rwa [intCast_re] at hre · rw [intCast_re, intCast_im] exact fun hc => ⟨hc, dvd_zero a⟩ protected theorem eq_of_smul_eq_smul_left {a : ℤ} {b c : ℤ√d} (ha : a ≠ 0) (h : ↑a * b = a * c) : b = c := by rw [Zsqrtd.ext_iff] at h ⊢ apply And.imp _ _ h <;> simpa only [smul_re, smul_im] using mul_left_cancel₀ ha section Gcd theorem gcd_eq_zero_iff (a : ℤ√d) : Int.gcd a.re a.im = 0 ↔ a = 0 := by simp only [Int.gcd_eq_zero_iff, Zsqrtd.ext_iff, eq_self_iff_true, zero_im, zero_re] theorem gcd_pos_iff (a : ℤ√d) : 0 < Int.gcd a.re a.im ↔ a ≠ 0 := pos_iff_ne_zero.trans <| not_congr a.gcd_eq_zero_iff theorem isCoprime_of_dvd_isCoprime {a b : ℤ√d} (hcoprime : IsCoprime a.re a.im) (hdvd : b ∣ a) : IsCoprime b.re b.im := by apply isCoprime_of_dvd · rintro ⟨hre, him⟩ obtain rfl : b = 0 := Zsqrtd.ext hre him rw [zero_dvd_iff] at hdvd simp [hdvd, zero_im, zero_re, not_isCoprime_zero_zero] at hcoprime · rintro z hz - hzdvdu hzdvdv apply hz obtain ⟨ha, hb⟩ : z ∣ a.re ∧ z ∣ a.im := by rw [← intCast_dvd] apply dvd_trans _ hdvd rw [intCast_dvd] exact ⟨hzdvdu, hzdvdv⟩ exact hcoprime.isUnit_of_dvd' ha hb @[deprecated (since := "2025-01-23")] alias coprime_of_dvd_coprime := isCoprime_of_dvd_isCoprime theorem exists_coprime_of_gcd_pos {a : ℤ√d} (hgcd : 0 < Int.gcd a.re a.im) : ∃ b : ℤ√d, a = ((Int.gcd a.re a.im : ℤ) : ℤ√d) * b ∧ IsCoprime b.re b.im := by obtain ⟨re, im, H1, Hre, Him⟩ := Int.exists_gcd_one hgcd rw [mul_comm] at Hre Him refine ⟨⟨re, im⟩, ?_, ?_⟩ · rw [smul_val, ← Hre, ← Him] · rw [Int.isCoprime_iff_gcd_eq_one, H1] end Gcd /-- Read `SqLe a c b d` as `a √c ≤ b √d` -/ def SqLe (a c b d : ℕ) : Prop := c * a * a ≤ d * b * b
theorem sqLe_of_le {c d x y z w : ℕ} (xz : z ≤ x) (yw : y ≤ w) (xy : SqLe x c y d) : SqLe z c w d := le_trans (mul_le_mul (Nat.mul_le_mul_left _ xz) xz (Nat.zero_le _) (Nat.zero_le _)) <| le_trans xy (mul_le_mul (Nat.mul_le_mul_left _ yw) yw (Nat.zero_le _) (Nat.zero_le _)) theorem sqLe_add_mixed {c d x y z w : ℕ} (xy : SqLe x c y d) (zw : SqLe z c w d) : c * (x * z) ≤ d * (y * w) := Nat.mul_self_le_mul_self_iff.1 <| by
Mathlib/NumberTheory/Zsqrtd/Basic.lean
350
356
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yakov Pechersky -/ import Mathlib.Data.List.Nodup import Mathlib.Data.List.Infix import Mathlib.Data.Quot /-! # List rotation This file proves basic results about `List.rotate`, the list rotation. ## Main declarations * `List.IsRotated l₁ l₂`: States that `l₁` is a rotated version of `l₂`. * `List.cyclicPermutations l`: The list of all cyclic permutants of `l`, up to the length of `l`. ## Tags rotated, rotation, permutation, cycle -/ universe u variable {α : Type u} open Nat Function namespace List theorem rotate_mod (l : List α) (n : ℕ) : l.rotate (n % l.length) = l.rotate n := by simp [rotate] @[simp] theorem rotate_nil (n : ℕ) : ([] : List α).rotate n = [] := by simp [rotate] @[simp] theorem rotate_zero (l : List α) : l.rotate 0 = l := by simp [rotate] theorem rotate'_nil (n : ℕ) : ([] : List α).rotate' n = [] := by simp @[simp] theorem rotate'_zero (l : List α) : l.rotate' 0 = l := by cases l <;> rfl theorem rotate'_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate' n.succ = (l ++ [a]).rotate' n := by simp [rotate'] @[simp] theorem length_rotate' : ∀ (l : List α) (n : ℕ), (l.rotate' n).length = l.length | [], _ => by simp | _ :: _, 0 => rfl | a :: l, n + 1 => by rw [List.rotate', length_rotate' (l ++ [a]) n]; simp theorem rotate'_eq_drop_append_take : ∀ {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = l.drop n ++ l.take n | [], n, h => by simp [drop_append_of_le_length h] | l, 0, h => by simp [take_append_of_le_length h] | a :: l, n + 1, h => by have hnl : n ≤ l.length := le_of_succ_le_succ h have hnl' : n ≤ (l ++ [a]).length := by rw [length_append, length_cons, List.length]; exact le_of_succ_le h rw [rotate'_cons_succ, rotate'_eq_drop_append_take hnl', drop, take, drop_append_of_le_length hnl, take_append_of_le_length hnl]; simp theorem rotate'_rotate' : ∀ (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m) | a :: l, 0, m => by simp | [], n, m => by simp | a :: l, n + 1, m => by rw [rotate'_cons_succ, rotate'_rotate' _ n, Nat.add_right_comm, ← rotate'_cons_succ, Nat.succ_eq_add_one] @[simp] theorem rotate'_length (l : List α) : rotate' l l.length = l := by rw [rotate'_eq_drop_append_take le_rfl]; simp @[simp] theorem rotate'_length_mul (l : List α) : ∀ n : ℕ, l.rotate' (l.length * n) = l | 0 => by simp | n + 1 => calc l.rotate' (l.length * (n + 1)) = (l.rotate' (l.length * n)).rotate' (l.rotate' (l.length * n)).length := by simp [-rotate'_length, Nat.mul_succ, rotate'_rotate'] _ = l := by rw [rotate'_length, rotate'_length_mul l n] theorem rotate'_mod (l : List α) (n : ℕ) : l.rotate' (n % l.length) = l.rotate' n := calc l.rotate' (n % l.length) = (l.rotate' (n % l.length)).rotate' ((l.rotate' (n % l.length)).length * (n / l.length)) := by rw [rotate'_length_mul] _ = l.rotate' n := by rw [rotate'_rotate', length_rotate', Nat.mod_add_div] theorem rotate_eq_rotate' (l : List α) (n : ℕ) : l.rotate n = l.rotate' n := if h : l.length = 0 then by simp_all [length_eq_zero_iff] else by rw [← rotate'_mod, rotate'_eq_drop_append_take (le_of_lt (Nat.mod_lt _ (Nat.pos_of_ne_zero h)))] simp [rotate] @[simp] theorem rotate_cons_succ (l : List α) (a : α) (n : ℕ) : (a :: l : List α).rotate (n + 1) = (l ++ [a]).rotate n := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate'_cons_succ] @[simp] theorem mem_rotate : ∀ {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l | [], _, n => by simp | a :: l, _, 0 => by simp | a :: l, _, n + 1 => by simp [rotate_cons_succ, mem_rotate, or_comm] @[simp] theorem length_rotate (l : List α) (n : ℕ) : (l.rotate n).length = l.length := by rw [rotate_eq_rotate', length_rotate'] @[simp] theorem rotate_replicate (a : α) (n : ℕ) (k : ℕ) : (replicate n a).rotate k = replicate n a := eq_replicate_iff.2 ⟨by rw [length_rotate, length_replicate], fun b hb => eq_of_mem_replicate <| mem_rotate.1 hb⟩ theorem rotate_eq_drop_append_take {l : List α} {n : ℕ} : n ≤ l.length → l.rotate n = l.drop n ++ l.take n := by rw [rotate_eq_rotate']; exact rotate'_eq_drop_append_take theorem rotate_eq_drop_append_take_mod {l : List α} {n : ℕ} : l.rotate n = l.drop (n % l.length) ++ l.take (n % l.length) := by rcases l.length.zero_le.eq_or_lt with hl | hl · simp [eq_nil_of_length_eq_zero hl.symm] rw [← rotate_eq_drop_append_take (n.mod_lt hl).le, rotate_mod] @[simp] theorem rotate_append_length_eq (l l' : List α) : (l ++ l').rotate l.length = l' ++ l := by rw [rotate_eq_rotate'] induction l generalizing l' · simp · simp_all [rotate'] theorem rotate_rotate (l : List α) (n m : ℕ) : (l.rotate n).rotate m = l.rotate (n + m) := by rw [rotate_eq_rotate', rotate_eq_rotate', rotate_eq_rotate', rotate'_rotate'] @[simp] theorem rotate_length (l : List α) : rotate l l.length = l := by rw [rotate_eq_rotate', rotate'_length] @[simp] theorem rotate_length_mul (l : List α) (n : ℕ) : l.rotate (l.length * n) = l := by rw [rotate_eq_rotate', rotate'_length_mul] theorem rotate_perm (l : List α) (n : ℕ) : l.rotate n ~ l := by rw [rotate_eq_rotate'] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate'_cons_succ] exact (hn _).trans (perm_append_singleton _ _) @[simp] theorem nodup_rotate {l : List α} {n : ℕ} : Nodup (l.rotate n) ↔ Nodup l := (rotate_perm l n).nodup_iff @[simp] theorem rotate_eq_nil_iff {l : List α} {n : ℕ} : l.rotate n = [] ↔ l = [] := by induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [rotate_cons_succ, hn] theorem nil_eq_rotate_iff {l : List α} {n : ℕ} : [] = l.rotate n ↔ [] = l := by rw [eq_comm, rotate_eq_nil_iff, eq_comm] @[simp] theorem rotate_singleton (x : α) (n : ℕ) : [x].rotate n = [x] := rotate_replicate x 1 n theorem zipWith_rotate_distrib {β γ : Type*} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ) (h : l.length = l'.length) : (zipWith f l l').rotate n = zipWith f (l.rotate n) (l'.rotate n) := by rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod, h, zipWith_append, ← drop_zipWith, ← take_zipWith, List.length_zipWith, h, min_self] rw [length_drop, length_drop, h] theorem zipWith_rotate_one {β : Type*} (f : α → α → β) (x y : α) (l : List α) : zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: zipWith f (y :: l) (l ++ [x]) := by simp theorem getElem?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n)[m]? = l[(m + n) % l.length]? := by rw [rotate_eq_drop_append_take_mod] rcases lt_or_le m (l.drop (n % l.length)).length with hm | hm · rw [getElem?_append_left hm, getElem?_drop, ← add_mod_mod] rw [length_drop, Nat.lt_sub_iff_add_lt] at hm rw [mod_eq_of_lt hm, Nat.add_comm] · have hlt : n % length l < length l := mod_lt _ (m.zero_le.trans_lt hml) rw [getElem?_append_right hm, getElem?_take_of_lt, length_drop] · congr 1 rw [length_drop] at hm have hm' := Nat.sub_le_iff_le_add'.1 hm have : n % length l + m - length l < length l := by rw [Nat.sub_lt_iff_lt_add hm'] exact Nat.add_lt_add hlt hml conv_rhs => rw [Nat.add_comm m, ← mod_add_mod, mod_eq_sub_mod hm', mod_eq_of_lt this] omega · rwa [Nat.sub_lt_iff_lt_add' hm, length_drop, Nat.sub_add_cancel hlt.le] theorem getElem_rotate (l : List α) (n : ℕ) (k : Nat) (h : k < (l.rotate n).length) : (l.rotate n)[k] = l[(k + n) % l.length]'(mod_lt _ (length_rotate l n ▸ k.zero_le.trans_lt h)) := by rw [← Option.some_inj, ← getElem?_eq_getElem, ← getElem?_eq_getElem, getElem?_rotate] exact h.trans_eq (length_rotate _ _) set_option linter.deprecated false in @[deprecated getElem?_rotate (since := "2025-02-14")] theorem get?_rotate {l : List α} {n m : ℕ} (hml : m < l.length) : (l.rotate n).get? m = l.get? ((m + n) % l.length) := by simp only [get?_eq_getElem?, length_rotate, hml, getElem?_eq_getElem, getElem_rotate] rw [← getElem?_eq_getElem] theorem get_rotate (l : List α) (n : ℕ) (k : Fin (l.rotate n).length) : (l.rotate n).get k = l.get ⟨(k + n) % l.length, mod_lt _ (length_rotate l n ▸ k.pos)⟩ := by simp [getElem_rotate] theorem head?_rotate {l : List α} {n : ℕ} (h : n < l.length) : head? (l.rotate n) = l[n]? := by rw [head?_eq_getElem?, getElem?_rotate (n.zero_le.trans_lt h), Nat.zero_add, Nat.mod_eq_of_lt h] theorem get_rotate_one (l : List α) (k : Fin (l.rotate 1).length) : (l.rotate 1).get k = l.get ⟨(k + 1) % l.length, mod_lt _ (length_rotate l 1 ▸ k.pos)⟩ := get_rotate l 1 k /-- A version of `List.getElem_rotate` that represents `l[k]` in terms of `(List.rotate l n)[⋯]`, not vice versa. Can be used instead of rewriting `List.getElem_rotate` from right to left. -/ theorem getElem_eq_getElem_rotate (l : List α) (n : ℕ) (k : Nat) (hk : k < l.length) : l[k] = ((l.rotate n)[(l.length - n % l.length + k) % l.length]' ((Nat.mod_lt _ (k.zero_le.trans_lt hk)).trans_eq (length_rotate _ _).symm)) := by rw [getElem_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [hk, (mod_lt _ (k.zero_le.trans_lt hk)).le] /-- A version of `List.get_rotate` that represents `List.get l` in terms of `List.get (List.rotate l n)`, not vice versa. Can be used instead of rewriting `List.get_rotate` from right to left. -/ theorem get_eq_get_rotate (l : List α) (n : ℕ) (k : Fin l.length) : l.get k = (l.rotate n).get ⟨(l.length - n % l.length + k) % l.length, (Nat.mod_lt _ (k.1.zero_le.trans_lt k.2)).trans_eq (length_rotate _ _).symm⟩ := by rw [get_rotate] refine congr_arg l.get (Fin.eq_of_val_eq ?_) simp only [mod_add_mod] rw [← add_mod_mod, Nat.add_right_comm, Nat.sub_add_cancel, add_mod_left, mod_eq_of_lt] exacts [k.2, (mod_lt _ (k.1.zero_le.trans_lt k.2)).le] theorem rotate_eq_self_iff_eq_replicate [hα : Nonempty α] : ∀ {l : List α}, (∀ n, l.rotate n = l) ↔ ∃ a, l = replicate l.length a | [] => by simp | a :: l => ⟨fun h => ⟨a, ext_getElem length_replicate.symm fun n h₁ h₂ => by rw [getElem_replicate, ← Option.some_inj, ← getElem?_eq_getElem, ← head?_rotate h₁, h, head?_cons]⟩, fun ⟨b, hb⟩ n => by rw [hb, rotate_replicate]⟩ theorem rotate_one_eq_self_iff_eq_replicate [Nonempty α] {l : List α} : l.rotate 1 = l ↔ ∃ a : α, l = List.replicate l.length a := ⟨fun h => rotate_eq_self_iff_eq_replicate.mp fun n => Nat.rec l.rotate_zero (fun n hn => by rwa [Nat.succ_eq_add_one, ← l.rotate_rotate, hn]) n, fun h => rotate_eq_self_iff_eq_replicate.mpr h 1⟩ theorem rotate_injective (n : ℕ) : Function.Injective fun l : List α => l.rotate n := by rintro l l' (h : l.rotate n = l'.rotate n) have hle : l.length = l'.length := (l.length_rotate n).symm.trans (h.symm ▸ l'.length_rotate n) rw [rotate_eq_drop_append_take_mod, rotate_eq_drop_append_take_mod] at h obtain ⟨hd, ht⟩ := append_inj h (by simp_all) rw [← take_append_drop _ l, ht, hd, take_append_drop] @[simp] theorem rotate_eq_rotate {l l' : List α} {n : ℕ} : l.rotate n = l'.rotate n ↔ l = l' := (rotate_injective n).eq_iff theorem rotate_eq_iff {l l' : List α} {n : ℕ} : l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length) := by rw [← @rotate_eq_rotate _ l _ n, rotate_rotate, ← rotate_mod l', add_mod] rcases l'.length.zero_le.eq_or_lt with hl | hl · rw [eq_nil_of_length_eq_zero hl.symm, rotate_nil] · rcases (Nat.zero_le (n % l'.length)).eq_or_lt with hn | hn · simp [← hn] · rw [mod_eq_of_lt (Nat.sub_lt hl hn), Nat.sub_add_cancel, mod_self, rotate_zero] exact (Nat.mod_lt _ hl).le @[simp] theorem rotate_eq_singleton_iff {l : List α} {n : ℕ} {x : α} : l.rotate n = [x] ↔ l = [x] := by rw [rotate_eq_iff, rotate_singleton] @[simp] theorem singleton_eq_rotate_iff {l : List α} {n : ℕ} {x : α} : [x] = l.rotate n ↔ [x] = l := by rw [eq_comm, rotate_eq_singleton_iff, eq_comm] theorem reverse_rotate (l : List α) (n : ℕ) : (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length) := by rw [← length_reverse, ← rotate_eq_iff] induction' n with n hn generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · rw [rotate_cons_succ, ← rotate_rotate, hn] simp theorem rotate_reverse (l : List α) (n : ℕ) : l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse := by rw [← reverse_reverse l] simp_rw [reverse_rotate, reverse_reverse, rotate_eq_iff, rotate_rotate, length_rotate, length_reverse] rw [← length_reverse] let k := n % l.reverse.length rcases hk' : k with - | k' · simp_all! [k, length_reverse, ← rotate_rotate] · rcases l with - | ⟨x, l⟩ · simp · rw [Nat.mod_eq_of_lt, Nat.sub_add_cancel, rotate_length] · exact Nat.sub_le _ _ · exact Nat.sub_lt (by simp) (by simp_all! [k]) theorem map_rotate {β : Type*} (f : α → β) (l : List α) (n : ℕ) : map f (l.rotate n) = (map f l).rotate n := by induction' n with n hn IH generalizing l · simp · rcases l with - | ⟨hd, tl⟩ · simp · simp [hn] theorem Nodup.rotate_congr {l : List α} (hl : l.Nodup) (hn : l ≠ []) (i j : ℕ) (h : l.rotate i = l.rotate j) : i % l.length = j % l.length := by rw [← rotate_mod l i, ← rotate_mod l j] at h simpa only [head?_rotate, mod_lt, length_pos_of_ne_nil hn, getElem?_eq_getElem, Option.some_inj, hl.getElem_inj_iff, Fin.ext_iff] using congr_arg head? h theorem Nodup.rotate_congr_iff {l : List α} (hl : l.Nodup) {i j : ℕ} : l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = [] := by rcases eq_or_ne l [] with rfl | hn · simp · simp only [hn, or_false] refine ⟨hl.rotate_congr hn _ _, fun h ↦ ?_⟩ rw [← rotate_mod, h, rotate_mod] theorem Nodup.rotate_eq_self_iff {l : List α} (hl : l.Nodup) {n : ℕ} : l.rotate n = l ↔ n % l.length = 0 ∨ l = [] := by rw [← zero_mod, ← hl.rotate_congr_iff, rotate_zero] section IsRotated variable (l l' : List α) /-- `IsRotated l₁ l₂` or `l₁ ~r l₂` asserts that `l₁` and `l₂` are cyclic permutations of each other. This is defined by claiming that `∃ n, l.rotate n = l'`. -/ def IsRotated : Prop := ∃ n, l.rotate n = l' @[inherit_doc List.IsRotated] -- This matches the precedence of the infix `~` for `List.Perm`, and of other relation infixes infixr:50 " ~r " => IsRotated variable {l l'} @[refl] theorem IsRotated.refl (l : List α) : l ~r l := ⟨0, by simp⟩ @[symm] theorem IsRotated.symm (h : l ~r l') : l' ~r l := by obtain ⟨n, rfl⟩ := h rcases l with - | ⟨hd, tl⟩ · exists 0 · use (hd :: tl).length * n - n rw [rotate_rotate, Nat.add_sub_cancel', rotate_length_mul] exact Nat.le_mul_of_pos_left _ (by simp) theorem isRotated_comm : l ~r l' ↔ l' ~r l := ⟨IsRotated.symm, IsRotated.symm⟩ @[simp] protected theorem IsRotated.forall (l : List α) (n : ℕ) : l.rotate n ~r l := IsRotated.symm ⟨n, rfl⟩ @[trans] theorem IsRotated.trans : ∀ {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l'' | _, _, _, ⟨n, rfl⟩, ⟨m, rfl⟩ => ⟨n + m, by rw [rotate_rotate]⟩ theorem IsRotated.eqv : Equivalence (@IsRotated α) := Equivalence.mk IsRotated.refl IsRotated.symm IsRotated.trans /-- The relation `List.IsRotated l l'` forms a `Setoid` of cycles. -/ def IsRotated.setoid (α : Type*) : Setoid (List α) where r := IsRotated iseqv := IsRotated.eqv theorem IsRotated.perm (h : l ~r l') : l ~ l' := Exists.elim h fun _ hl => hl ▸ (rotate_perm _ _).symm theorem IsRotated.nodup_iff (h : l ~r l') : Nodup l ↔ Nodup l' := h.perm.nodup_iff theorem IsRotated.mem_iff (h : l ~r l') {a : α} : a ∈ l ↔ a ∈ l' := h.perm.mem_iff @[simp] theorem isRotated_nil_iff : l ~r [] ↔ l = [] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_nil_iff' : [] ~r l ↔ [] = l := by rw [isRotated_comm, isRotated_nil_iff, eq_comm] @[simp] theorem isRotated_singleton_iff {x : α} : l ~r [x] ↔ l = [x] := ⟨fun ⟨n, hn⟩ => by simpa using hn, fun h => h ▸ by rfl⟩ @[simp] theorem isRotated_singleton_iff' {x : α} : [x] ~r l ↔ [x] = l := by rw [isRotated_comm, isRotated_singleton_iff, eq_comm] theorem isRotated_concat (hd : α) (tl : List α) : (tl ++ [hd]) ~r (hd :: tl) := IsRotated.symm ⟨1, by simp⟩ theorem isRotated_append : (l ++ l') ~r (l' ++ l) := ⟨l.length, by simp⟩ theorem IsRotated.reverse (h : l ~r l') : l.reverse ~r l'.reverse := by obtain ⟨n, rfl⟩ := h exact ⟨_, (reverse_rotate _ _).symm⟩ theorem isRotated_reverse_comm_iff : l.reverse ~r l' ↔ l ~r l'.reverse := by constructor <;> · intro h simpa using h.reverse @[simp] theorem isRotated_reverse_iff : l.reverse ~r l'.reverse ↔ l ~r l' := by simp [isRotated_reverse_comm_iff] theorem isRotated_iff_mod : l ~r l' ↔ ∃ n ≤ l.length, l.rotate n = l' := by refine ⟨fun h => ?_, fun ⟨n, _, h⟩ => ⟨n, h⟩⟩ obtain ⟨n, rfl⟩ := h rcases l with - | ⟨hd, tl⟩ · simp · refine ⟨n % (hd :: tl).length, ?_, rotate_mod _ _⟩ refine (Nat.mod_lt _ ?_).le simp theorem isRotated_iff_mem_map_range : l ~r l' ↔ l' ∈ (List.range (l.length + 1)).map l.rotate := by simp_rw [mem_map, mem_range, isRotated_iff_mod] exact ⟨fun ⟨n, hn, h⟩ => ⟨n, Nat.lt_succ_of_le hn, h⟩, fun ⟨n, hn, h⟩ => ⟨n, Nat.le_of_lt_succ hn, h⟩⟩ theorem IsRotated.map {β : Type*} {l₁ l₂ : List α} (h : l₁ ~r l₂) (f : α → β) : map f l₁ ~r map f l₂ := by obtain ⟨n, rfl⟩ := h rw [map_rotate] use n theorem IsRotated.cons_getLast_dropLast (L : List α) (hL : L ≠ []) : L.getLast hL :: L.dropLast ~r L := by induction L using List.reverseRecOn with | nil => simp at hL | append_singleton a L _ => simp only [getLast_append, dropLast_concat] apply IsRotated.symm apply isRotated_concat theorem IsRotated.dropLast_tail {α} {L : List α} (hL : L ≠ []) (hL' : L.head hL = L.getLast hL) : L.dropLast ~r L.tail := match L with | [] => by simp | [_] => by simp | a :: b :: L => by simp only [head_cons, ne_eq, reduceCtorEq, not_false_eq_true, getLast_cons] at hL' simp [hL', IsRotated.cons_getLast_dropLast] /-- List of all cyclic permutations of `l`. The `cyclicPermutations` of a nonempty list `l` will always contain `List.length l` elements. This implies that under certain conditions, there are duplicates in `List.cyclicPermutations l`. The `n`th entry is equal to `l.rotate n`, proven in `List.get_cyclicPermutations`. The proof that every cyclic permutant of `l` is in the list is `List.mem_cyclicPermutations_iff`. cyclicPermutations [1, 2, 3, 2, 4] = [[1, 2, 3, 2, 4], [2, 3, 2, 4, 1], [3, 2, 4, 1, 2], [2, 4, 1, 2, 3], [4, 1, 2, 3, 2]] -/ def cyclicPermutations : List α → List (List α) | [] => [[]] | l@(_ :: _) => dropLast (zipWith (· ++ ·) (tails l) (inits l)) @[simp] theorem cyclicPermutations_nil : cyclicPermutations ([] : List α) = [[]] := rfl theorem cyclicPermutations_cons (x : α) (l : List α) : cyclicPermutations (x :: l) = dropLast (zipWith (· ++ ·) (tails (x :: l)) (inits (x :: l))) := rfl theorem cyclicPermutations_of_ne_nil (l : List α) (h : l ≠ []) : cyclicPermutations l = dropLast (zipWith (· ++ ·) (tails l) (inits l)) := by obtain ⟨hd, tl, rfl⟩ := exists_cons_of_ne_nil h exact cyclicPermutations_cons _ _ theorem length_cyclicPermutations_cons (x : α) (l : List α) : length (cyclicPermutations (x :: l)) = length l + 1 := by simp [cyclicPermutations_cons] @[simp]
theorem length_cyclicPermutations_of_ne_nil (l : List α) (h : l ≠ []) : length (cyclicPermutations l) = length l := by simp [cyclicPermutations_of_ne_nil _ h]
Mathlib/Data/List/Rotate.lean
511
513
/- Copyright (c) 2023 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Computability.AkraBazzi.GrowsPolynomially import Mathlib.Analysis.Calculus.Deriv.Inv import Mathlib.Analysis.SpecialFunctions.Pow.Deriv /-! # Divide-and-conquer recurrences and the Akra-Bazzi theorem A divide-and-conquer recurrence is a function `T : ℕ → ℝ` that satisfies a recurrence relation of the form `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` for large enough `n`, where `r_i(n)` is some function where `‖r_i(n) - b_i n‖ ∈ o(n / (log n)^2)` for every `i`, the `a_i`'s are some positive coefficients, and the `b_i`'s are reals `∈ (0,1)`. (Note that this can be improved to `O(n / (log n)^(1+ε))`, this is left as future work.) These recurrences arise mainly in the analysis of divide-and-conquer algorithms such as mergesort or Strassen's algorithm for matrix multiplication. This class of algorithms works by dividing an instance of the problem of size `n`, into `k` smaller instances, where the `i`'th instance is of size roughly `b_i n`, and calling itself recursively on those smaller instances. `T(n)` then represents the running time of the algorithm, and `g(n)` represents the running time required to actually divide up the instance and process the answers that come out of the recursive calls. Since virtually all such algorithms produce instances that are only approximately of size `b_i n` (they have to round up or down at the very least), we allow the instance sizes to be given by some function `r_i(n)` that approximates `b_i n`. The Akra-Bazzi theorem gives the asymptotic order of such a recurrence: it states that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))`, where `p` is the unique real number such that `∑ a_i b_i^p = 1`. ## Main definitions and results * `AkraBazziRecurrence T g a b r`: the predicate stating that `T : ℕ → ℝ` satisfies an Akra-Bazzi recurrence with parameters `g`, `a`, `b` and `r` as above. * `GrowsPolynomially`: The growth condition that `g` must satisfy for the theorem to apply. It roughly states that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for u between b*n and n for any constant `b ∈ (0,1)`. * `sumTransform`: The transformation which turns a function `g` into `n^p * ∑ u ∈ Finset.Ico n₀ n, g u / u^(p+1)`. * `asympBound`: The asymptotic bound satisfied by an Akra-Bazzi recurrence, namely `n^p (1 + ∑ g(u) / u^(p+1))` * `isTheta_asympBound`: The main result stating that `T(n) ∈ Θ(n^p (1 + ∑_{u=0}^{n-1} g(n) / u^{p+1}))` ## Implementation Note that the original version of the theorem has an integral rather than a sum in the above expression, and first considers the `T : ℝ → ℝ` case before moving on to `ℕ → ℝ`. We prove the above version with a sum, as it is simpler and more relevant for algorithms. ## TODO * Specialize this theorem to the very common case where the recurrence is of the form `T(n) = ℓT(r_i(n)) + g(n)` where `g(n) ∈ Θ(n^t)` for some `t`. (This is often called the "master theorem" in the literature.) * Add the original version of the theorem with an integral instead of a sum. ## References * Mohamad Akra and Louay Bazzi, On the solution of linear recurrence equations * Tom Leighton, Notes on better master theorems for divide-and-conquer recurrences * Manuel Eberl, Asymptotic reasoning in a proof assistant -/ open Finset Real Filter Asymptotics open scoped Topology /-! #### Definition of Akra-Bazzi recurrences This section defines the predicate `AkraBazziRecurrence T g a b r` which states that `T` satisfies the recurrence `T(n) = ∑_{i=0}^{k-1} a_i T(r_i(n)) + g(n)` with appropriate conditions on the various parameters. -/ /-- An Akra-Bazzi recurrence is a function that satisfies the recurrence `T n = (∑ i, a i * T (r i n)) + g n`. -/ structure AkraBazziRecurrence {α : Type*} [Fintype α] [Nonempty α] (T : ℕ → ℝ) (g : ℝ → ℝ) (a : α → ℝ) (b : α → ℝ) (r : α → ℕ → ℕ) where /-- Point below which the recurrence is in the base case -/ n₀ : ℕ /-- `n₀` is always `> 0` -/ n₀_gt_zero : 0 < n₀ /-- The `a`'s are nonzero -/ a_pos : ∀ i, 0 < a i /-- The `b`'s are nonzero -/ b_pos : ∀ i, 0 < b i /-- The b's are less than 1 -/ b_lt_one : ∀ i, b i < 1 /-- `g` is nonnegative -/ g_nonneg : ∀ x ≥ 0, 0 ≤ g x /-- `g` grows polynomially -/ g_grows_poly : AkraBazziRecurrence.GrowsPolynomially g /-- The actual recurrence -/ h_rec (n : ℕ) (hn₀ : n₀ ≤ n) : T n = (∑ i, a i * T (r i n)) + g n /-- Base case: `T(n) > 0` whenever `n < n₀` -/ T_gt_zero' (n : ℕ) (hn : n < n₀) : 0 < T n /-- The `r`'s always reduce `n` -/ r_lt_n : ∀ i n, n₀ ≤ n → r i n < n /-- The `r`'s approximate the `b`'s -/ dist_r_b : ∀ i, (fun n => (r i n : ℝ) - b i * n) =o[atTop] fun n => n / (log n) ^ 2 namespace AkraBazziRecurrence section min_max variable {α : Type*} [Finite α] [Nonempty α] /-- Smallest `b i` -/ noncomputable def min_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_min b /-- Largest `b i` -/ noncomputable def max_bi (b : α → ℝ) : α := Classical.choose <| Finite.exists_max b @[aesop safe apply] lemma min_bi_le {b : α → ℝ} (i : α) : b (min_bi b) ≤ b i := Classical.choose_spec (Finite.exists_min b) i @[aesop safe apply] lemma max_bi_le {b : α → ℝ} (i : α) : b i ≤ b (max_bi b) := Classical.choose_spec (Finite.exists_max b) i end min_max lemma isLittleO_self_div_log_id : (fun (n : ℕ) => n / log n ^ 2) =o[atTop] (fun (n : ℕ) => (n : ℝ)) := by calc (fun (n : ℕ) => (n : ℝ) / log n ^ 2) = fun (n : ℕ) => (n : ℝ) * ((log n) ^ 2)⁻¹ := by simp_rw [div_eq_mul_inv] _ =o[atTop] fun (n : ℕ) => (n : ℝ) * 1⁻¹ := by refine IsBigO.mul_isLittleO (isBigO_refl _ _) ?_ refine IsLittleO.inv_rev ?main ?zero case zero => simp case main => calc _ = (fun (_ : ℕ) => ((1 : ℝ) ^ 2)) := by simp _ =o[atTop] (fun (n : ℕ) => (log n)^2) := IsLittleO.pow (IsLittleO.natCast_atTop <| isLittleO_const_log_atTop) (by norm_num) _ = (fun (n : ℕ) => (n : ℝ)) := by ext; simp variable {α : Type*} [Fintype α] {T : ℕ → ℝ} {g : ℝ → ℝ} {a b : α → ℝ} {r : α → ℕ → ℕ} variable [Nonempty α] (R : AkraBazziRecurrence T g a b r) section include R lemma dist_r_b' : ∀ᶠ n in atTop, ∀ i, ‖(r i n : ℝ) - b i * n‖ ≤ n / log n ^ 2 := by rw [Filter.eventually_all] intro i simpa using IsLittleO.eventuallyLE (R.dist_r_b i) lemma eventually_b_le_r : ∀ᶠ (n : ℕ) in atTop, ∀ i, (b i : ℝ) * n - (n / log n ^ 2) ≤ r i n := by filter_upwards [R.dist_r_b'] with n hn intro i have h₁ : 0 ≤ b i := le_of_lt <| R.b_pos _ rw [sub_le_iff_le_add, add_comm, ← sub_le_iff_le_add] calc (b i : ℝ) * n - r i n = ‖b i * n‖ - ‖(r i n : ℝ)‖ := by simp only [norm_mul, RCLike.norm_natCast, sub_left_inj, Nat.cast_eq_zero, Real.norm_of_nonneg h₁] _ ≤ ‖(b i * n : ℝ) - r i n‖ := norm_sub_norm_le _ _ _ = ‖(r i n : ℝ) - b i * n‖ := norm_sub_rev _ _ _ ≤ n / log n ^ 2 := hn i lemma eventually_r_le_b : ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n ≤ (b i : ℝ) * n + (n / log n ^ 2) := by filter_upwards [R.dist_r_b'] with n hn intro i calc r i n = b i * n + (r i n - b i * n) := by ring _ ≤ b i * n + ‖r i n - b i * n‖ := by gcongr; exact Real.le_norm_self _ _ ≤ b i * n + n / log n ^ 2 := by gcongr; exact hn i lemma eventually_r_lt_n : ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n < n := by filter_upwards [eventually_ge_atTop R.n₀] with n hn exact fun i => R.r_lt_n i n hn lemma eventually_bi_mul_le_r : ∀ᶠ (n : ℕ) in atTop, ∀ i, (b (min_bi b) / 2) * n ≤ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo (by positivity : 0 < b (min_bi b) / 2) filter_upwards [hlo', R.eventually_b_le_r] with n hn hn' intro i simp only [Real.norm_of_nonneg (by positivity : 0 ≤ (n : ℝ))] at hn calc b (min_bi b) / 2 * n = b (min_bi b) * n - b (min_bi b) / 2 * n := by ring _ ≤ b (min_bi b) * n - ‖n / log n ^ 2‖ := by gcongr _ ≤ b i * n - ‖n / log n ^ 2‖ := by gcongr; aesop _ = b i * n - n / log n ^ 2 := by congr exact Real.norm_of_nonneg <| by positivity _ ≤ r i n := hn' i lemma bi_min_div_two_lt_one : b (min_bi b) / 2 < 1 := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) calc b (min_bi b) / 2 < b (min_bi b) := by aesop (add safe apply div_two_lt_of_pos) _ < 1 := R.b_lt_one _ lemma bi_min_div_two_pos : 0 < b (min_bi b) / 2 := div_pos (R.b_pos _) (by norm_num) lemma exists_eventually_const_mul_le_r : ∃ c ∈ Set.Ioo (0 : ℝ) 1, ∀ᶠ (n : ℕ) in atTop, ∀ i, c * n ≤ r i n := by have gt_zero : 0 < b (min_bi b) := R.b_pos (min_bi b) exact ⟨b (min_bi b) / 2, ⟨⟨by positivity, R.bi_min_div_two_lt_one⟩, R.eventually_bi_mul_le_r⟩⟩ lemma eventually_r_ge (C : ℝ) : ∀ᶠ (n : ℕ) in atTop, ∀ i, C ≤ r i n := by obtain ⟨c, hc_mem, hc⟩ := R.exists_eventually_const_mul_le_r filter_upwards [eventually_ge_atTop ⌈C / c⌉₊, hc] with n hn₁ hn₂ have h₁ := hc_mem.1 intro i calc C = c * (C / c) := by rw [← mul_div_assoc] exact (mul_div_cancel_left₀ _ (by positivity)).symm _ ≤ c * ⌈C / c⌉₊ := by gcongr; simp [Nat.le_ceil] _ ≤ c * n := by gcongr _ ≤ r i n := hn₂ i lemma tendsto_atTop_r (i : α) : Tendsto (r i) atTop atTop := by rw [tendsto_atTop] intro b have := R.eventually_r_ge b rw [Filter.eventually_all] at this exact_mod_cast this i lemma tendsto_atTop_r_real (i : α) : Tendsto (fun n => (r i n : ℝ)) atTop atTop := Tendsto.comp tendsto_natCast_atTop_atTop (R.tendsto_atTop_r i) lemma exists_eventually_r_le_const_mul : ∃ c ∈ Set.Ioo (0 : ℝ) 1, ∀ᶠ (n : ℕ) in atTop, ∀ i, r i n ≤ c * n := by let c := b (max_bi b) + (1 - b (max_bi b)) / 2 have h_max_bi_pos : 0 < b (max_bi b) := R.b_pos _ have h_max_bi_lt_one : 0 < 1 - b (max_bi b) := by have : b (max_bi b) < 1 := R.b_lt_one _ linarith have hc_pos : 0 < c := by positivity have h₁ : 0 < (1 - b (max_bi b)) / 2 := by positivity have hc_lt_one : c < 1 := calc b (max_bi b) + (1 - b (max_bi b)) / 2 = b (max_bi b) * (1 / 2) + 1 / 2 := by ring _ < 1 * (1 / 2) + 1 / 2 := by gcongr exact R.b_lt_one _ _ = 1 := by norm_num refine ⟨c, ⟨hc_pos, hc_lt_one⟩, ?_⟩ have hlo := isLittleO_self_div_log_id rw [Asymptotics.isLittleO_iff] at hlo have hlo' := hlo h₁ filter_upwards [hlo', R.eventually_r_le_b] with n hn hn' intro i rw [Real.norm_of_nonneg (by positivity)] at hn simp only [Real.norm_of_nonneg (by positivity : 0 ≤ (n : ℝ))] at hn calc r i n ≤ b i * n + n / log n ^ 2 := by exact hn' i _ ≤ b i * n + (1 - b (max_bi b)) / 2 * n := by gcongr _ = (b i + (1 - b (max_bi b)) / 2) * n := by ring _ ≤ (b (max_bi b) + (1 - b (max_bi b)) / 2) * n := by gcongr; exact max_bi_le _ lemma eventually_r_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < r i n := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r i).eventually_gt_atTop 0 lemma eventually_log_b_mul_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < log (b i * n) := by rw [Filter.eventually_all] intro i have h : Tendsto (fun (n : ℕ) => log (b i * n)) atTop atTop := Tendsto.comp tendsto_log_atTop <| Tendsto.const_mul_atTop (b_pos R i) tendsto_natCast_atTop_atTop exact h.eventually_gt_atTop 0 @[aesop safe apply] lemma T_pos (n : ℕ) : 0 < T n := by induction n using Nat.strongRecOn with | ind n h_ind => cases lt_or_le n R.n₀ with | inl hn => exact R.T_gt_zero' n hn -- n < R.n₀ | inr hn => -- R.n₀ ≤ n rw [R.h_rec n hn] have := R.g_nonneg refine add_pos_of_pos_of_nonneg (Finset.sum_pos ?sum_elems univ_nonempty) (by aesop) exact fun i _ => mul_pos (R.a_pos i) <| h_ind _ (R.r_lt_n i _ hn) @[aesop safe apply] lemma T_nonneg (n : ℕ) : 0 ≤ T n := le_of_lt <| R.T_pos n end /-! #### Smoothing function We define `ε` as the "smoothing function" `fun n => 1 / log n`, which will be used in the form of a factor of `1 ± ε n` needed to make the induction step go through. This is its own definition to make it easier to switch to a different smoothing function. For example, choosing `1 / log n ^ δ` for a suitable choice of `δ` leads to a slightly tighter theorem at the price of a more complicated proof. This part of the file then proves several properties of this function that will be needed later in the proof. -/ /-- The "smoothing function" is defined as `1 / log n`. This is defined as an `ℝ → ℝ` function as opposed to `ℕ → ℝ` since this is more convenient for the proof, where we need to e.g. take derivatives. -/ noncomputable def smoothingFn (n : ℝ) : ℝ := 1 / log n local notation "ε" => smoothingFn lemma one_add_smoothingFn_le_two {x : ℝ} (hx : exp 1 ≤ x) : 1 + ε x ≤ 2 := by simp only [smoothingFn, ← one_add_one_eq_two] gcongr have : 1 < x := by calc 1 = exp 0 := by simp _ < exp 1 := by simp _ ≤ x := hx rw [div_le_one (log_pos this)] calc 1 = log (exp 1) := by simp _ ≤ log x := log_le_log (exp_pos _) hx lemma isLittleO_smoothingFn_one : ε =o[atTop] (fun _ => (1 : ℝ)) := by unfold smoothingFn refine isLittleO_of_tendsto (fun _ h => False.elim <| one_ne_zero h) ?_ simp only [one_div, div_one] exact Tendsto.inv_tendsto_atTop Real.tendsto_log_atTop lemma isEquivalent_one_add_smoothingFn_one : (fun x => 1 + ε x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.add_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma isEquivalent_one_sub_smoothingFn_one : (fun x => 1 - ε x) ~[atTop] (fun _ => (1 : ℝ)) := IsEquivalent.sub_isLittleO IsEquivalent.refl isLittleO_smoothingFn_one lemma growsPolynomially_one_sub_smoothingFn : GrowsPolynomially fun x => 1 - ε x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_sub_smoothingFn_one lemma growsPolynomially_one_add_smoothingFn : GrowsPolynomially fun x => 1 + ε x := GrowsPolynomially.of_isEquivalent_const isEquivalent_one_add_smoothingFn_one lemma eventually_one_sub_smoothingFn_gt_const_real (c : ℝ) (hc : c < 1) : ∀ᶠ (x : ℝ) in atTop, c < 1 - ε x := by have h₁ : Tendsto (fun x => 1 - ε x) atTop (𝓝 1) := by rw [← isEquivalent_const_iff_tendsto one_ne_zero] exact isEquivalent_one_sub_smoothingFn_one rw [tendsto_order] at h₁ exact h₁.1 c hc lemma eventually_one_sub_smoothingFn_gt_const (c : ℝ) (hc : c < 1) : ∀ᶠ (n : ℕ) in atTop, c < 1 - ε n := Eventually.natCast_atTop (p := fun n => c < 1 - ε n) <| eventually_one_sub_smoothingFn_gt_const_real c hc lemma eventually_one_sub_smoothingFn_pos_real : ∀ᶠ (x : ℝ) in atTop, 0 < 1 - ε x := eventually_one_sub_smoothingFn_gt_const_real 0 zero_lt_one lemma eventually_one_sub_smoothingFn_pos : ∀ᶠ (n : ℕ) in atTop, 0 < 1 - ε n := (eventually_one_sub_smoothingFn_pos_real).natCast_atTop lemma eventually_one_sub_smoothingFn_nonneg : ∀ᶠ (n : ℕ) in atTop, 0 ≤ 1 - ε n := by filter_upwards [eventually_one_sub_smoothingFn_pos] with n hn; exact le_of_lt hn include R in lemma eventually_one_sub_smoothingFn_r_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < 1 - ε (r i n) := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r_real i).eventually eventually_one_sub_smoothingFn_pos_real @[aesop safe apply] lemma differentiableAt_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ ε x := by have : log x ≠ 0 := Real.log_ne_zero_of_pos_of_ne_one (by positivity) (ne_of_gt hx) show DifferentiableAt ℝ (fun z => 1 / log z) x simp_rw [one_div] exact DifferentiableAt.inv (differentiableAt_log (by positivity)) this @[aesop safe apply] lemma differentiableAt_one_sub_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ (fun z => 1 - ε z) x := DifferentiableAt.sub (differentiableAt_const _) <| differentiableAt_smoothingFn hx lemma differentiableOn_one_sub_smoothingFn : DifferentiableOn ℝ (fun z => 1 - ε z) (Set.Ioi 1) := fun _ hx => (differentiableAt_one_sub_smoothingFn hx).differentiableWithinAt @[aesop safe apply] lemma differentiableAt_one_add_smoothingFn {x : ℝ} (hx : 1 < x) : DifferentiableAt ℝ (fun z => 1 + ε z) x := DifferentiableAt.add (differentiableAt_const _) <| differentiableAt_smoothingFn hx lemma differentiableOn_one_add_smoothingFn : DifferentiableOn ℝ (fun z => 1 + ε z) (Set.Ioi 1) := fun _ hx => (differentiableAt_one_add_smoothingFn hx).differentiableWithinAt lemma deriv_smoothingFn {x : ℝ} (hx : 1 < x) : deriv ε x = -x⁻¹ / (log x ^ 2) := by have : log x ≠ 0 := Real.log_ne_zero_of_pos_of_ne_one (by positivity) (ne_of_gt hx) show deriv (fun z => 1 / log z) x = -x⁻¹ / (log x ^ 2) rw [deriv_div] <;> aesop lemma isLittleO_deriv_smoothingFn : deriv ε =o[atTop] fun x => x⁻¹ := calc deriv ε =ᶠ[atTop] fun x => -x⁻¹ / (log x ^ 2) := by filter_upwards [eventually_gt_atTop 1] with x hx rw [deriv_smoothingFn hx] _ = fun x => (-x * log x ^ 2)⁻¹ := by simp_rw [neg_div, div_eq_mul_inv, ← mul_inv, neg_inv, neg_mul] _ =o[atTop] fun x => (x * 1)⁻¹ := by refine IsLittleO.inv_rev ?_ ?_ · refine IsBigO.mul_isLittleO (by rw [isBigO_neg_right]; aesop (add safe isBigO_refl)) ?_ rw [isLittleO_one_left_iff] exact Tendsto.comp tendsto_norm_atTop_atTop <| Tendsto.comp (tendsto_pow_atTop (by norm_num)) tendsto_log_atTop · exact Filter.Eventually.of_forall (fun x hx => by rw [mul_one] at hx; simp [hx]) _ = fun x => x⁻¹ := by simp lemma eventually_deriv_one_sub_smoothingFn : deriv (fun x => 1 - ε x) =ᶠ[atTop] fun x => x⁻¹ / (log x ^ 2) := calc deriv (fun x => 1 - ε x) =ᶠ[atTop] -(deriv ε) := by filter_upwards [eventually_gt_atTop 1] with x hx; rw [deriv_sub] <;> aesop _ =ᶠ[atTop] fun x => x⁻¹ / (log x ^ 2) := by filter_upwards [eventually_gt_atTop 1] with x hx simp [deriv_smoothingFn hx, neg_div] lemma eventually_deriv_one_add_smoothingFn : deriv (fun x => 1 + ε x) =ᶠ[atTop] fun x => -x⁻¹ / (log x ^ 2) := calc deriv (fun x => 1 + ε x) =ᶠ[atTop] deriv ε := by filter_upwards [eventually_gt_atTop 1] with x hx; rw [deriv_add] <;> aesop _ =ᶠ[atTop] fun x => -x⁻¹ / (log x ^ 2) := by filter_upwards [eventually_gt_atTop 1] with x hx simp [deriv_smoothingFn hx] lemma isLittleO_deriv_one_sub_smoothingFn : deriv (fun x => 1 - ε x) =o[atTop] fun (x : ℝ) => x⁻¹ := calc deriv (fun x => 1 - ε x) =ᶠ[atTop] fun z => -(deriv ε z) := by filter_upwards [eventually_gt_atTop 1] with x hx; rw [deriv_sub] <;> aesop _ =o[atTop] fun x => x⁻¹ := by rw [isLittleO_neg_left]; exact isLittleO_deriv_smoothingFn lemma isLittleO_deriv_one_add_smoothingFn : deriv (fun x => 1 + ε x) =o[atTop] fun (x : ℝ) => x⁻¹ := calc deriv (fun x => 1 + ε x) =ᶠ[atTop] fun z => deriv ε z := by filter_upwards [eventually_gt_atTop 1] with x hx; rw [deriv_add] <;> aesop _ =o[atTop] fun x => x⁻¹ := isLittleO_deriv_smoothingFn lemma eventually_one_add_smoothingFn_pos : ∀ᶠ (n : ℕ) in atTop, 0 < 1 + ε n := by have h₁ := isLittleO_smoothingFn_one rw [isLittleO_iff] at h₁ refine Eventually.natCast_atTop (p := fun n => 0 < 1 + ε n) ?_ filter_upwards [h₁ (by norm_num : (0 : ℝ) < 1/2), eventually_gt_atTop 1] with x _ hx' have : 0 < log x := Real.log_pos hx' show 0 < 1 + 1 / log x positivity include R in lemma eventually_one_add_smoothingFn_r_pos : ∀ᶠ (n : ℕ) in atTop, ∀ i, 0 < 1 + ε (r i n) := by rw [Filter.eventually_all] exact fun i => (R.tendsto_atTop_r i).eventually (f := r i) eventually_one_add_smoothingFn_pos lemma eventually_one_add_smoothingFn_nonneg : ∀ᶠ (n : ℕ) in atTop, 0 ≤ 1 + ε n := by filter_upwards [eventually_one_add_smoothingFn_pos] with n hn; exact le_of_lt hn lemma strictAntiOn_smoothingFn : StrictAntiOn ε (Set.Ioi 1) := by show StrictAntiOn (fun x => 1 / log x) (Set.Ioi 1) simp_rw [one_div] refine StrictAntiOn.comp_strictMonoOn inv_strictAntiOn ?log fun _ hx => log_pos hx refine StrictMonoOn.mono strictMonoOn_log (fun x hx => ?_) exact Set.Ioi_subset_Ioi zero_le_one hx
lemma strictMonoOn_one_sub_smoothingFn : StrictMonoOn (fun (x : ℝ) => (1 : ℝ) - ε x) (Set.Ioi 1) := by simp_rw [sub_eq_add_neg] exact StrictMonoOn.const_add (StrictAntiOn.neg <| strictAntiOn_smoothingFn) 1 lemma strictAntiOn_one_add_smoothingFn : StrictAntiOn (fun (x : ℝ) => (1 : ℝ) + ε x) (Set.Ioi 1) := StrictAntiOn.const_add strictAntiOn_smoothingFn 1 section include R lemma isEquivalent_smoothingFn_sub_self (i : α) : (fun (n : ℕ) => ε (b i * n) - ε n) ~[atTop] fun n => -log (b i) / (log n)^2 := by calc (fun (n : ℕ) => 1 / log (b i * n) - 1 / log n) =ᶠ[atTop] fun (n : ℕ) => (log n - log (b i * n)) / (log (b i * n) * log n) := by filter_upwards [eventually_gt_atTop 1, R.eventually_log_b_mul_pos] with n hn hn' have h_log_pos : 0 < log n := Real.log_pos <| by aesop simp only [one_div] rw [inv_sub_inv (by have := hn' i; positivity) (by aesop)] _ =ᶠ[atTop] (fun (n : ℕ) ↦ (log n - log (b i) - log n) / ((log (b i) + log n) * log n)) := by filter_upwards [eventually_ne_atTop 0] with n hn have : 0 < b i := R.b_pos i
Mathlib/Computability/AkraBazzi/AkraBazzi.lean
457
478
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl theorem pow_card (a : K) : a ^ q = a := by by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul] theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by induction n with | zero => simp | succ n ih => simp [pow_succ, pow_mul, ih, pow_card] end variable (K) [Field K] [Fintype K] /-- The cardinality `q` is a power of the characteristic of `K`. -/ @[stacks 09HY "first part"] theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩ letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with } obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K rw [ZMod.card] at h refine ⟨⟨n, ?_⟩, hp.1, h⟩ apply Or.resolve_left (Nat.eq_zero_or_pos n) rintro rfl rw [pow_zero] at h have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h) exact absurd this zero_ne_one -- this statement doesn't use `q` because we want `K` to be an explicit parameter theorem card' : ∃ (p : ℕ), CharP K p ∧ ∃ (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) := let ⟨p, hc⟩ := CharP.exists K ⟨p, hc, @FiniteField.card K _ _ p hc⟩ lemma isPrimePow_card : IsPrimePow (Fintype.card K) := by obtain ⟨p, _, n, hp, hn⟩ := card' K exact ⟨p, n, Nat.prime_iff.mp hp, n.prop, hn.symm⟩ theorem cast_card_eq_zero : (q : K) = 0 := by simp theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by classical obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ) rw [← Nat.card_eq_fintype_card, ← Nat.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx, orderOf_dvd_iff_pow_eq_one] constructor · intro h; apply h · intro h y simp_rw [← mem_powers_iff_mem_zpowers] at hx rcases hx y with ⟨j, rfl⟩ rw [← pow_mul, mul_comm, pow_mul, h, one_pow] /-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q` is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/ theorem sum_pow_units [DecidableEq K] (i : ℕ) : (∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by let φ : Kˣ →* K := { toFun := fun x => x ^ i map_one' := by simp map_mul' := by intros; simp [mul_pow] } have : Decidable (φ = 1) := by classical infer_instance calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ _ = if q - 1 ∣ i then -1 else 0 := by suffices q - 1 ∣ i ↔ φ = 1 by simp only [this] split_ifs; swap · exact Nat.cast_zero · rw [Fintype.card_units, Nat.cast_sub, cast_card_eq_zero, Nat.cast_one, zero_sub] show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩ rw [← forall_pow_eq_one_iff, DFunLike.ext_iff] apply forall_congr'; intro x; simp [φ, Units.ext_iff] /-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q` is equal to `0` if `i < q - 1`. -/ theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by by_cases hi : i = 0 · simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero] classical have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩ have : univ.map φ = univ \ {0} := by ext x simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and, mem_sdiff, mem_singleton, φ] using isUnit_iff_ne_zero calc ∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero] _ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ] _ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq section frobenius variable (R) [CommRing R] [Algebra K R] /-- If `R` is an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is given by raising every element of `R` to its `#K`-th power. -/ @[simps!] def frobeniusAlgHom : R →ₐ[K] R where __ := powMonoidHom q map_zero' := zero_pow Fintype.card_pos.ne' map_add' _ _ := by obtain ⟨p, _, _, hp, card_eq⟩ := card' K nontriviality R have : CharP R p := charP_of_injective_algebraMap' K R p have : ExpChar R p := .prime hp simp only [OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, powMonoidHom_apply, card_eq] exact add_pow_expChar_pow .. commutes' _ := by simp [← RingHom.map_pow, pow_card] theorem coe_frobeniusAlgHom : ⇑(frobeniusAlgHom K R) = (· ^ q) := rfl /-- If `R` is a perfect ring and an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquiv (p : ℕ) [ExpChar R p] [PerfectRing R p] : R ≃ₐ[K] R := .ofBijective (frobeniusAlgHom K R) <| by obtain ⟨p', _, n, hp, card_eq⟩ := card' K rw [coe_frobeniusAlgHom, card_eq] have : ExpChar K p' := ExpChar.prime hp nontriviality R have := ExpChar.eq ‹_› (expChar_of_injective_algebraMap (algebraMap K R).injective p') subst this apply bijective_iterateFrobenius variable (L : Type*) [Field L] [Algebra K L] /-- If `L/K` is an algebraic extension of a finite field, the Frobenius `K`-algebra endomorphism of `L` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : L ≃ₐ[K] L := (Algebra.IsAlgebraic.algEquivEquivAlgHom K L).symm (frobeniusAlgHom K L) theorem coe_frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : ⇑(frobeniusAlgEquivOfAlgebraic K L) = (· ^ q) := rfl variable [Finite L] open Polynomial in theorem orderOf_frobeniusAlgHom : orderOf (frobeniusAlgHom K L) = Module.finrank K L := (orderOf_eq_iff Module.finrank_pos).mpr <| by have := Fintype.ofFinite L refine ⟨DFunLike.ext _ _ fun x ↦ ?_, fun m lt pos eq ↦ ?_⟩ · simp_rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← Module.card_eq_pow_finrank, pow_card] have := card_le_degree_of_subset_roots (R := L) (p := X ^ q ^ m - X) (Z := univ) fun x _ ↦ by simp_rw [mem_roots', IsRoot, eval_sub, eval_pow, eval_X] have := DFunLike.congr_fun eq x rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← sub_eq_zero] at this refine ⟨fun h ↦ ?_, this⟩ simpa [if_neg (Nat.one_lt_pow pos.ne' Fintype.one_lt_card).ne] using congr_arg (coeff · 1) h refine this.not_lt (((natDegree_sub_le ..).trans_eq ?_).trans_lt <| (Nat.pow_lt_pow_right Fintype.one_lt_card lt).trans_eq Module.card_eq_pow_finrank.symm) simp [Nat.one_le_pow _ _ Fintype.card_pos] theorem orderOf_frobeniusAlgEquivOfAlgebraic : orderOf (frobeniusAlgEquivOfAlgebraic K L) = Module.finrank K L := by simpa [orderOf_eq_iff Module.finrank_pos, DFunLike.ext_iff] using orderOf_frobeniusAlgHom K L theorem bijective_frobeniusAlgHom_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgHom K L ^ n.1 := let e := (finCongr <| orderOf_frobeniusAlgHom K L).symm.trans <| finEquivPowers (orderOf_pos_iff.mp <| orderOf_frobeniusAlgHom K L ▸ Module.finrank_pos) (Subtype.val_injective.comp e.injective).bijective_of_nat_card_le ((card_algHom_le_finrank K L L).trans_eq <| by simp) theorem bijective_frobeniusAlgEquivOfAlgebraic_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgEquivOfAlgebraic K L ^ n.1 := ((Algebra.IsAlgebraic.algEquivEquivAlgHom K L).bijective.of_comp_iff' _).mp <| by simpa only [Function.comp_def, map_pow] using bijective_frobeniusAlgHom_pow K L instance (K L) [Finite L] [Field K] [Field L] [Algebra K L] : IsCyclic (L ≃ₐ[K] L) where exists_zpow_surjective := have := Finite.of_injective _ (algebraMap K L).injective have := Fintype.ofFinite K ⟨frobeniusAlgEquivOfAlgebraic K L, fun f ↦ have ⟨n, hn⟩ := (bijective_frobeniusAlgEquivOfAlgebraic_pow K L).2 f; ⟨n, hn⟩⟩ end frobenius open Polynomial section variable [Fintype K] (K' : Type*) [Field K'] {p n : ℕ} theorem X_pow_card_sub_X_natDegree_eq (hp : 1 < p) : (X ^ p - X : K'[X]).natDegree = p := by have h1 : (X : K'[X]).degree < (X ^ p : K'[X]).degree := by rw [degree_X_pow, degree_X] exact mod_cast hp rw [natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt h1), natDegree_X_pow] theorem X_pow_card_pow_sub_X_natDegree_eq (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]).natDegree = p ^ n := X_pow_card_sub_X_natDegree_eq K' <| Nat.one_lt_pow hn hp theorem X_pow_card_sub_X_ne_zero (hp : 1 < p) : (X ^ p - X : K'[X]) ≠ 0 := ne_zero_of_natDegree_gt <| calc 1 < _ := hp _ = _ := (X_pow_card_sub_X_natDegree_eq K' hp).symm theorem X_pow_card_pow_sub_X_ne_zero (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K' <| Nat.one_lt_pow hn hp end theorem roots_X_pow_card_sub_X : roots (X ^ q - X : K[X]) = Finset.univ.val := by classical have aux : (X ^ q - X : K[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K Fintype.one_lt_card have : (roots (X ^ q - X : K[X])).toFinset = Finset.univ := by rw [eq_univ_iff_forall] intro x rw [Multiset.mem_toFinset, mem_roots aux, IsRoot.def, eval_sub, eval_pow, eval_X, sub_eq_zero, pow_card] rw [← this, Multiset.toFinset_val, eq_comm, Multiset.dedup_eq_self] apply nodup_roots rw [separable_def] convert isCoprime_one_right.neg_right (R := K[X]) using 1 rw [derivative_sub, derivative_X, derivative_X_pow, Nat.cast_card_eq_zero K, C_0, zero_mul, zero_sub] variable {K} theorem frobenius_pow {p : ℕ} [Fact p.Prime] [CharP K p] {n : ℕ} (hcard : q = p ^ n) : frobenius K p ^ n = 1 := by ext x; conv_rhs => rw [RingHom.one_def, RingHom.id_apply, ← pow_card x, hcard] clear hcard induction n with | zero => simp | succ n hn => rw [pow_succ', pow_succ, pow_mul, RingHom.mul_def, RingHom.comp_apply, frobenius_def, hn] open Polynomial theorem expand_card (f : K[X]) : expand K q f = f ^ q := by obtain ⟨p, hp⟩ := CharP.exists K letI := hp rcases FiniteField.card K p with ⟨⟨n, npos⟩, ⟨hp, hn⟩⟩ haveI : Fact p.Prime := ⟨hp⟩ dsimp at hn rw [hn, ← map_expand_pow_char, frobenius_pow hn, RingHom.one_def, map_id] end FiniteField namespace ZMod open FiniteField Polynomial theorem sq_add_sq (p : ℕ) [hp : Fact p.Prime] (x : ZMod p) : ∃ a b : ZMod p, a ^ 2 + b ^ 2 = x := by rcases hp.1.eq_two_or_odd with hp2 | hp_odd · subst p change Fin 2 at x fin_cases x · use 0; simp · use 0, 1; simp let f : (ZMod p)[X] := X ^ 2 let g : (ZMod p)[X] := X ^ 2 - C x obtain ⟨a, b, hab⟩ : ∃ a b, f.eval a + g.eval b = 0 := @exists_root_sum_quadratic _ _ _ _ f g (degree_X_pow 2) (degree_X_pow_sub_C (by decide) _) (by rw [ZMod.card, hp_odd]) refine ⟨a, b, ?_⟩ rw [← sub_eq_zero] simpa only [f, g, eval_C, eval_X, eval_pow, eval_sub, ← add_sub_assoc] using hab end ZMod /-- If `p` is a prime natural number and `x` is an integer number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [ZMOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_zmodEq (p : ℕ) [Fact p.Prime] (x : ℤ) : ∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ (a : ℤ) ^ 2 + (b : ℤ) ^ 2 ≡ x [ZMOD p] := by rcases ZMod.sq_add_sq p x with ⟨a, b, hx⟩ refine ⟨a.valMinAbs.natAbs, b.valMinAbs.natAbs, ZMod.natAbs_valMinAbs_le _, ZMod.natAbs_valMinAbs_le _, ?_⟩ rw [← a.coe_valMinAbs, ← b.coe_valMinAbs] at hx push_cast rw [sq_abs, sq_abs, ← ZMod.intCast_eq_intCast_iff] exact mod_cast hx /-- If `p` is a prime natural number and `x` is a natural number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [MOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_modEq (p : ℕ) [Fact p.Prime] (x : ℕ) : ∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ a ^ 2 + b ^ 2 ≡ x [MOD p] := by simpa only [← Int.natCast_modEq_iff] using Nat.sq_add_sq_zmodEq p x namespace CharP theorem sq_add_sq (R : Type*) [Ring R] [IsDomain R] (p : ℕ) [NeZero p] [CharP R p] (x : ℤ) : ∃ a b : ℕ, ((a : R) ^ 2 + (b : R) ^ 2) = x := by haveI := char_is_prime_of_pos R p obtain ⟨a, b, hab⟩ := ZMod.sq_add_sq p x refine ⟨a.val, b.val, ?_⟩ simpa using congr_arg (ZMod.castHom dvd_rfl R) hab end CharP open scoped Nat open ZMod /-- The **Fermat-Euler totient theorem**. `Nat.ModEq.pow_totient` is an alternative statement of the same theorem. -/ @[simp] theorem ZMod.pow_totient {n : ℕ} (x : (ZMod n)ˣ) : x ^ φ n = 1 := by cases n · rw [Nat.totient_zero, pow_zero] · rw [← card_units_eq_totient, pow_card_eq_one] /-- The **Fermat-Euler totient theorem**. `ZMod.pow_totient` is an alternative statement of the same theorem. -/ theorem Nat.ModEq.pow_totient {x n : ℕ} (h : Nat.Coprime x n) : x ^ φ n ≡ 1 [MOD n] := by rw [← ZMod.eq_iff_modEq_nat] let x' : Units (ZMod n) := ZMod.unitOfCoprime _ h have := ZMod.pow_totient x' apply_fun ((fun (x : Units (ZMod n)) => (x : ZMod n)) : Units (ZMod n) → ZMod n) at this simpa only [Nat.succ_eq_add_one, Nat.cast_pow, Units.val_one, Nat.cast_one, coe_unitOfCoprime, Units.val_pow_eq_pow_val] /-- For each `n ≥ 0`, the unit group of `ZMod n` is finite. -/ instance instFiniteZModUnits : (n : ℕ) → Finite (ZMod n)ˣ | 0 => Finite.of_fintype ℤˣ | _ + 1 => inferInstance open FiniteField namespace ZMod variable {p : ℕ} [Fact p.Prime] instance : Subsingleton (Subfield (ZMod p)) := subsingleton_of_bot_eq_top <| top_unique (a := ⊥) fun n _ ↦ have := zsmul_mem (one_mem (⊥ : Subfield (ZMod p))) n.val by rwa [natCast_zsmul, Nat.smul_one_eq_cast, ZMod.natCast_zmod_val] at this theorem fieldRange_castHom_eq_bot (p : ℕ) [Fact p.Prime] [DivisionRing K] [CharP K p] : (ZMod.castHom (m := p) dvd_rfl K).fieldRange = (⊥ : Subfield K) := by rw [RingHom.fieldRange_eq_map, ← Subfield.map_bot (K := ZMod p), Subsingleton.elim ⊥] /-- A variation on Fermat's little theorem. See `ZMod.pow_card_sub_one_eq_one` -/ @[simp] theorem pow_card (x : ZMod p) : x ^ p = x := by have h := FiniteField.pow_card x; rwa [ZMod.card p] at h @[simp] theorem pow_card_pow {n : ℕ} (x : ZMod p) : x ^ p ^ n = x := by induction n with | zero => simp | succ n ih => simp [pow_succ, pow_mul, ih, pow_card] @[simp] theorem frobenius_zmod (p : ℕ) [Fact p.Prime] : frobenius (ZMod p) p = RingHom.id _ := by ext a rw [frobenius_def, ZMod.pow_card, RingHom.id_apply] -- This was a `simp` lemma, but now the LHS simplifies to `φ p`. theorem card_units (p : ℕ) [Fact p.Prime] : Fintype.card (ZMod p)ˣ = p - 1 := by rw [Fintype.card_units, card] /-- **Fermat's Little Theorem**: for every unit `a` of `ZMod p`, we have `a ^ (p - 1) = 1`. -/ theorem units_pow_card_sub_one_eq_one (p : ℕ) [Fact p.Prime] (a : (ZMod p)ˣ) : a ^ (p - 1) = 1 := by rw [← card_units p, pow_card_eq_one]
/-- **Fermat's Little Theorem**: for all nonzero `a : ZMod p`, we have `a ^ (p - 1) = 1`. -/ theorem pow_card_sub_one_eq_one {a : ZMod p} (ha : a ≠ 0) : a ^ (p - 1) = 1 := by have h := FiniteField.pow_card_sub_one_eq_one a ha rwa [ZMod.card p] at h
Mathlib/FieldTheory/Finite/Basic.lean
586
590
/- Copyright (c) 2019 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.Setoid.Basic import Mathlib.Dynamics.FixedPoints.Topology import Mathlib.Topology.MetricSpace.Lipschitz /-! # Contracting maps A Lipschitz continuous self-map with Lipschitz constant `K < 1` is called a *contracting map*. In this file we prove the Banach fixed point theorem, some explicit estimates on the rate of convergence, and some properties of the map sending a contracting map to its fixed point. ## Main definitions * `ContractingWith K f` : a Lipschitz continuous self-map with `K < 1`; * `efixedPoint` : given a contracting map `f` on a complete emetric space and a point `x` such that `edist x (f x) ≠ ∞`, `efixedPoint f hf x hx` is the unique fixed point of `f` in `EMetric.ball x ∞`; * `fixedPoint` : the unique fixed point of a contracting map on a complete nonempty metric space. ## Tags contracting map, fixed point, Banach fixed point theorem -/ open NNReal Topology ENNReal Filter Function variable {α : Type*} /-- A map is said to be `ContractingWith K`, if `K < 1` and `f` is `LipschitzWith K`. -/ def ContractingWith [EMetricSpace α] (K : ℝ≥0) (f : α → α) := K < 1 ∧ LipschitzWith K f namespace ContractingWith variable [EMetricSpace α] {K : ℝ≥0} {f : α → α} open EMetric Set theorem toLipschitzWith (hf : ContractingWith K f) : LipschitzWith K f := hf.2 theorem one_sub_K_pos' (hf : ContractingWith K f) : (0 : ℝ≥0∞) < 1 - K := by simp [hf.1] theorem one_sub_K_ne_zero (hf : ContractingWith K f) : (1 : ℝ≥0∞) - K ≠ 0 := ne_of_gt hf.one_sub_K_pos' theorem one_sub_K_ne_top : (1 : ℝ≥0∞) - K ≠ ∞ := by norm_cast exact ENNReal.coe_ne_top theorem edist_inequality (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) : edist x y ≤ (edist x (f x) + edist y (f y)) / (1 - K) := suffices edist x y ≤ edist x (f x) + edist y (f y) + K * edist x y by rwa [ENNReal.le_div_iff_mul_le (Or.inl hf.one_sub_K_ne_zero) (Or.inl one_sub_K_ne_top), mul_comm, ENNReal.sub_mul fun _ _ ↦ h, one_mul, tsub_le_iff_right] calc edist x y ≤ edist x (f x) + edist (f x) (f y) + edist (f y) y := edist_triangle4 _ _ _ _ _ = edist x (f x) + edist y (f y) + edist (f x) (f y) := by rw [edist_comm y, add_right_comm] _ ≤ edist x (f x) + edist y (f y) + K * edist x y := add_le_add le_rfl (hf.2 _ _) theorem edist_le_of_fixedPoint (hf : ContractingWith K f) {x y} (h : edist x y ≠ ∞) (hy : IsFixedPt f y) : edist x y ≤ edist x (f x) / (1 - K) := by simpa only [hy.eq, edist_self, add_zero] using hf.edist_inequality h theorem eq_or_edist_eq_top_of_fixedPoints (hf : ContractingWith K f) {x y} (hx : IsFixedPt f x) (hy : IsFixedPt f y) : x = y ∨ edist x y = ∞ := by refine or_iff_not_imp_right.2 fun h ↦ edist_le_zero.1 ?_ simpa only [hx.eq, edist_self, add_zero, ENNReal.zero_div] using hf.edist_le_of_fixedPoint h hy /-- If a map `f` is `ContractingWith K`, and `s` is a forward-invariant set, then restriction of `f` to `s` is `ContractingWith K` as well. -/ theorem restrict (hf : ContractingWith K f) {s : Set α} (hs : MapsTo f s s) : ContractingWith K (hs.restrict f s s) := ⟨hf.1, fun x y ↦ hf.2 x y⟩ section variable [CompleteSpace α] /-- Banach fixed-point theorem, contraction mapping theorem, `EMetricSpace` version. A contracting map on a complete metric space has a fixed point. We include more conclusions in this theorem to avoid proving them again later. The main API for this theorem are the functions `efixedPoint` and `fixedPoint`, and lemmas about these functions. -/ theorem exists_fixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : ∃ y, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧ ∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := have : CauchySeq fun n ↦ f^[n] x := cauchySeq_of_edist_le_geometric K (edist x (f x)) (ENNReal.coe_lt_one_iff.2 hf.1) hx (hf.toLipschitzWith.edist_iterate_succ_le_geometric x) let ⟨y, hy⟩ := cauchySeq_tendsto_of_complete this ⟨y, isFixedPt_of_tendsto_iterate hy hf.2.continuous.continuousAt, hy, edist_le_of_edist_le_geometric_of_tendsto K (edist x (f x)) (hf.toLipschitzWith.edist_iterate_succ_le_geometric x) hy⟩ variable (f) in -- avoid `efixedPoint _` in pretty printer /-- Let `x` be a point of a complete emetric space. Suppose that `f` is a contracting map, and `edist x (f x) ≠ ∞`. Then `efixedPoint` is the unique fixed point of `f` in `EMetric.ball x ∞`. -/ noncomputable def efixedPoint (hf : ContractingWith K f) (x : α) (hx : edist x (f x) ≠ ∞) : α := Classical.choose <| hf.exists_fixedPoint x hx theorem efixedPoint_isFixedPt (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : IsFixedPt f (efixedPoint f hf x hx) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).1 theorem tendsto_iterate_efixedPoint (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint f hf x hx) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).2.1 theorem apriori_edist_iterate_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) (n : ℕ) : edist (f^[n] x) (efixedPoint f hf x hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := (Classical.choose_spec <| hf.exists_fixedPoint x hx).2.2 n theorem edist_efixedPoint_le (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint f hf x hx) ≤ edist x (f x) / (1 - K) := by convert hf.apriori_edist_iterate_efixedPoint_le hx 0 simp only [pow_zero, mul_one] theorem edist_efixedPoint_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint f hf x hx) < ∞ := (hf.edist_efixedPoint_le hx).trans_lt (ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top theorem efixedPoint_eq_of_edist_lt_top (hf : ContractingWith K f) {x : α} (hx : edist x (f x) ≠ ∞) {y : α} (hy : edist y (f y) ≠ ∞) (h : edist x y ≠ ∞) : efixedPoint f hf x hx = efixedPoint f hf y hy := by refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h') <;> try apply efixedPoint_isFixedPt change edistLtTopSetoid _ _ trans x · apply Setoid.symm' exact hf.edist_efixedPoint_lt_top hx trans y exacts [lt_top_iff_ne_top.2 h, hf.edist_efixedPoint_lt_top hy] end /-- Banach fixed-point theorem for maps contracting on a complete subset. -/ theorem exists_fixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : ∃ y ∈ s, IsFixedPt f y ∧ Tendsto (fun n ↦ f^[n] x) atTop (𝓝 y) ∧ ∀ n : ℕ, edist (f^[n] x) y ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := by haveI := hsc.completeSpace_coe rcases hf.exists_fixedPoint ⟨x, hxs⟩ hx with ⟨y, hfy, h_tendsto, hle⟩ refine ⟨y, y.2, Subtype.ext_iff_val.1 hfy, ?_, fun n ↦ ?_⟩ · convert (continuous_subtype_val.tendsto _).comp h_tendsto simp only [(· ∘ ·), MapsTo.iterate_restrict, MapsTo.val_restrict_apply] · convert hle n rw [MapsTo.iterate_restrict] rfl variable (f) in -- avoid `efixedPoint _` in pretty printer /-- Let `s` be a complete forward-invariant set of a self-map `f`. If `f` contracts on `s` and `x ∈ s` satisfies `edist x (f x) ≠ ∞`, then `efixedPoint'` is the unique fixed point of the restriction of `f` to `s ∩ EMetric.ball x ∞`. -/ noncomputable def efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) (x : α) (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : α := Classical.choose <| hf.exists_fixedPoint' hsc hsf hxs hx theorem efixedPoint_mem' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : efixedPoint' f hsc hsf hf x hxs hx ∈ s := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).1 theorem efixedPoint_isFixedPt' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : IsFixedPt f (efixedPoint' f hsc hsf hf x hxs hx) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.1 theorem tendsto_iterate_efixedPoint' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : Tendsto (fun n ↦ f^[n] x) atTop (𝓝 <| efixedPoint' f hsc hsf hf x hxs hx) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.1 theorem apriori_edist_iterate_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) (n : ℕ) : edist (f^[n] x) (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) * (K : ℝ≥0∞) ^ n / (1 - K) := (Classical.choose_spec <| hf.exists_fixedPoint' hsc hsf hxs hx).2.2.2 n theorem edist_efixedPoint_le' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint' f hsc hsf hf x hxs hx) ≤ edist x (f x) / (1 - K) := by convert hf.apriori_edist_iterate_efixedPoint_le' hsc hsf hxs hx 0 rw [pow_zero, mul_one] theorem edist_efixedPoint_lt_top' {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hf : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) : edist x (efixedPoint' f hsc hsf hf x hxs hx) < ∞ := (hf.edist_efixedPoint_le' hsc hsf hxs hx).trans_lt (ENNReal.mul_ne_top hx <| ENNReal.inv_ne_top.2 hf.one_sub_K_ne_zero).lt_top /-- If a globally contracting map `f` has two complete forward-invariant sets `s`, `t`, and `x ∈ s` is at a finite distance from `y ∈ t`, then the `efixedPoint'` constructed by `x` is the same as the `efixedPoint'` constructed by `y`. This lemma takes additional arguments stating that `f` contracts on `s` and `t` because this way it can be used to prove the desired equality with non-trivial proofs of these facts. -/ theorem efixedPoint_eq_of_edist_lt_top' (hf : ContractingWith K f) {s : Set α} (hsc : IsComplete s) (hsf : MapsTo f s s) (hfs : ContractingWith K <| hsf.restrict f s s) {x : α} (hxs : x ∈ s) (hx : edist x (f x) ≠ ∞) {t : Set α} (htc : IsComplete t) (htf : MapsTo f t t) (hft : ContractingWith K <| htf.restrict f t t) {y : α} (hyt : y ∈ t) (hy : edist y (f y) ≠ ∞) (hxy : edist x y ≠ ∞) : efixedPoint' f hsc hsf hfs x hxs hx = efixedPoint' f htc htf hft y hyt hy := by refine (hf.eq_or_edist_eq_top_of_fixedPoints ?_ ?_).elim id fun h' ↦ False.elim (ne_of_lt ?_ h') <;> try apply efixedPoint_isFixedPt' change edistLtTopSetoid _ _ trans x · apply Setoid.symm' apply edist_efixedPoint_lt_top' trans y · exact lt_top_iff_ne_top.2 hxy · apply edist_efixedPoint_lt_top' end ContractingWith namespace ContractingWith variable [MetricSpace α] {K : ℝ≥0} {f : α → α} theorem one_sub_K_pos (hf : ContractingWith K f) : (0 : ℝ) < 1 - K := sub_pos.2 hf.1 section variable (hf : ContractingWith K f) include hf theorem dist_le_mul (x y : α) : dist (f x) (f y) ≤ K * dist x y := hf.toLipschitzWith.dist_le_mul x y theorem dist_inequality (x y) : dist x y ≤ (dist x (f x) + dist y (f y)) / (1 - K) :=
suffices dist x y ≤ dist x (f x) + dist y (f y) + K * dist x y by rwa [le_div_iff₀ hf.one_sub_K_pos, mul_comm, _root_.sub_mul, one_mul, sub_le_iff_le_add] calc dist x y ≤ dist x (f x) + dist y (f y) + dist (f x) (f y) := dist_triangle4_right _ _ _ _ _ ≤ dist x (f x) + dist y (f y) + K * dist x y := add_le_add_left (hf.dist_le_mul _ _) _ theorem dist_le_of_fixedPoint (x) {y} (hy : IsFixedPt f y) : dist x y ≤ dist x (f x) / (1 - K) := by simpa only [hy.eq, dist_self, add_zero] using hf.dist_inequality x y theorem fixedPoint_unique' {x y} (hx : IsFixedPt f x) (hy : IsFixedPt f y) : x = y := (hf.eq_or_edist_eq_top_of_fixedPoints hx hy).resolve_right (edist_ne_top _ _) /-- Let `f` be a contracting map with constant `K`; let `g` be another map uniformly `C`-close to `f`. If `x` and `y` are their fixed points, then `dist x y ≤ C / (1 - K)`. -/ theorem dist_fixedPoint_fixedPoint_of_dist_le' (g : α → α) {x y} (hx : IsFixedPt f x)
Mathlib/Topology/MetricSpace/Contracting.lean
243
257
/- Copyright (c) 2024 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Probability.Kernel.Disintegration.Density import Mathlib.Probability.Kernel.WithDensity /-! # Radon-Nikodym derivative and Lebesgue decomposition for kernels Let `α` and `γ` be two measurable space, where either `α` is countable or `γ` is countably generated. Let `κ, η : Kernel α γ` be finite kernels. Then there exists a function `Kernel.rnDeriv κ η : α → γ → ℝ≥0∞` jointly measurable on `α × γ` and a kernel `Kernel.singularPart κ η : Kernel α γ` such that * `κ = Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η`, * for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a`, * for all `a : α`, `Kernel.singularPart κ η a = 0 ↔ κ a ≪ η a`, * for all `a : α`, `Kernel.withDensity η (Kernel.rnDeriv κ η) a = 0 ↔ κ a ⟂ₘ η a`. Furthermore, the sets `{a | κ a ≪ η a}` and `{a | κ a ⟂ₘ η a}` are measurable. When `γ` is countably generated, the construction of the derivative starts from `Kernel.density`: for two finite kernels `κ' : Kernel α (γ × β)` and `η' : Kernel α γ` with `fst κ' ≤ η'`, the function `density κ' η' : α → γ → Set β → ℝ` is jointly measurable in the first two arguments and satisfies that for all `a : α` and all measurable sets `s : Set β` and `A : Set γ`, `∫ x in A, density κ' η' a x s ∂(η' a) = (κ' a (A ×ˢ s)).toReal`. We use that definition for `β = Unit` and `κ' = map κ (fun a ↦ (a, ()))`. We can't choose `η' = η` in general because we might not have `κ ≤ η`, but if we could, we would get a measurable function `f` with the property `κ = withDensity η f`, which is the decomposition we want for `κ ≤ η`. To circumvent that difficulty, we take `η' = κ + η` and thus define `rnDerivAux κ η`. Finally, `rnDeriv κ η a x` is given by `ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x)`. Up to some conversions between `ℝ` and `ℝ≥0`, the singular part is `withDensity (κ + η) (rnDerivAux κ (κ + η) - (1 - rnDerivAux κ (κ + η)) * rnDeriv κ η)`. The countably generated measurable space assumption is not needed to have a decomposition for measures, but the additional difficulty with kernels is to obtain joint measurability of the derivative. This is why we can't simply define `rnDeriv κ η` by `a ↦ (κ a).rnDeriv (ν a)` everywhere unless `α` is countable (although `rnDeriv κ η` has that value almost everywhere). See the construction of `Kernel.density` for details on how the countably generated hypothesis is used. ## Main definitions * `ProbabilityTheory.Kernel.rnDeriv`: a function `α → γ → ℝ≥0∞` jointly measurable on `α × γ` * `ProbabilityTheory.Kernel.singularPart`: a `Kernel α γ` ## Main statements * `ProbabilityTheory.Kernel.mutuallySingular_singularPart`: for all `a : α`, `Kernel.singularPart κ η a ⟂ₘ η a` * `ProbabilityTheory.Kernel.rnDeriv_add_singularPart`: `Kernel.withDensity η (Kernel.rnDeriv κ η) + Kernel.singularPart κ η = κ` * `ProbabilityTheory.Kernel.measurableSet_absolutelyContinuous` : the set `{a | κ a ≪ η a}` is Measurable * `ProbabilityTheory.Kernel.measurableSet_mutuallySingular` : the set `{a | κ a ⟂ₘ η a}` is Measurable Uniqueness results: if `κ = η.withDensity f + ξ` for measurable `f` and `ξ` is such that `ξ a ⟂ₘ η a` for some `a : α` then * `ProbabilityTheory.Kernel.eq_rnDeriv`: `f a =ᵐ[η a] Kernel.rnDeriv κ η a` * `ProbabilityTheory.Kernel.eq_singularPart`: `ξ a = Kernel.singularPart κ η a` ## References Theorem 1.28 in [O. Kallenberg, Random Measures, Theory and Applications][kallenberg2017]. -/ open MeasureTheory Set Filter ENNReal open scoped NNReal MeasureTheory Topology ProbabilityTheory namespace ProbabilityTheory.Kernel variable {α γ : Type*} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} {κ η : Kernel α γ} [hαγ : MeasurableSpace.CountableOrCountablyGenerated α γ] open Classical in /-- Auxiliary function used to define `ProbabilityTheory.Kernel.rnDeriv` and `ProbabilityTheory.Kernel.singularPart`. This has the properties we want for a Radon-Nikodym derivative only if `κ ≪ ν`. The definition of `rnDeriv κ η` will be built from `rnDerivAux κ (κ + η)`. -/ noncomputable def rnDerivAux (κ η : Kernel α γ) (a : α) (x : γ) : ℝ := if hα : Countable α then ((κ a).rnDeriv (η a) x).toReal else haveI := hαγ.countableOrCountablyGenerated.resolve_left hα density (map κ (fun a ↦ (a, ()))) η a x univ lemma rnDerivAux_nonneg (hκη : κ ≤ η) {a : α} {x : γ} : 0 ≤ rnDerivAux κ η a x := by rw [rnDerivAux] split_ifs with hα · exact ENNReal.toReal_nonneg · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_nonneg ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ lemma rnDerivAux_le_one [IsFiniteKernel η] (hκη : κ ≤ η) {a : α} : rnDerivAux κ η a ≤ᵐ[η a] 1 := by filter_upwards [Measure.rnDeriv_le_one_of_le (hκη a)] with x hx_le_one simp_rw [rnDerivAux] split_ifs with hα · refine ENNReal.toReal_le_of_le_ofReal zero_le_one ?_ simp only [Pi.one_apply, ENNReal.ofReal_one] exact hx_le_one · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact density_le_one ((fst_map_id_prod _ measurable_const).trans_le hκη) _ _ _ @[fun_prop] lemma measurable_rnDerivAux (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ Kernel.rnDerivAux κ η p.1 p.2) := by simp_rw [rnDerivAux] split_ifs with hα · refine Measurable.ennreal_toReal ?_ change Measurable ((fun q : γ × α ↦ (κ q.2).rnDeriv (η q.2) q.1) ∘ Prod.swap) refine (measurable_from_prod_countable' (fun a ↦ ?_) ?_).comp measurable_swap · exact Measure.measurable_rnDeriv (κ a) (η a) · intro a a' c ha'_mem_a have h_eq : ∀ κ : Kernel α γ, κ a' = κ a := fun κ ↦ by ext s hs exact mem_of_mem_measurableAtom ha'_mem_a (Kernel.measurable_coe κ hs (measurableSet_singleton (κ a s))) rfl rw [h_eq κ, h_eq η] · have := hαγ.countableOrCountablyGenerated.resolve_left hα exact measurable_density _ η MeasurableSet.univ @[fun_prop] lemma measurable_rnDerivAux_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ rnDerivAux κ η a x) := by fun_prop lemma setLIntegral_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) {s : Set γ} (hs : MeasurableSet s) : ∫⁻ x in s, ENNReal.ofReal (rnDerivAux κ (κ + η) a x) ∂(κ + η) a = κ a s := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le simp_rw [rnDerivAux] split_ifs with hα · have h_ac : κ a ≪ (κ + η) a := Measure.absolutelyContinuous_of_le (h_le a) rw [← Measure.setLIntegral_rnDeriv h_ac] refine setLIntegral_congr_fun hs ?_ filter_upwards [Measure.rnDeriv_lt_top (κ a) ((κ + η) a)] with x hx_lt _ rw [ENNReal.ofReal_toReal hx_lt.ne] · have := hαγ.countableOrCountablyGenerated.resolve_left hα rw [setLIntegral_density ((fst_map_id_prod _ measurable_const).trans_le h_le) _ MeasurableSet.univ hs, map_apply' _ (by fun_prop) _ (hs.prod MeasurableSet.univ)] congr with x simp lemma withDensity_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ := by ext a s hs rw [Kernel.withDensity_apply'] swap; · fun_prop simp_rw [ofNNReal_toNNReal] exact setLIntegral_rnDerivAux κ η a hs lemma withDensity_one_sub_rnDerivAux (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] : withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) = η := by have h_le : κ ≤ κ + η := le_add_of_nonneg_right bot_le suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x)) = κ + η by ext a s have h : (withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) + withDensity (κ + η) (fun a x ↦ Real.toNNReal (rnDerivAux κ (κ + η) a x))) a s = κ a s + η a s := by rw [this] simp simp only [coe_add, Pi.add_apply, Measure.coe_add] at h rwa [withDensity_rnDerivAux, add_comm, ENNReal.add_right_inj (measure_ne_top _ _)] at h simp_rw [ofNNReal_toNNReal, ENNReal.ofReal_sub _ (rnDerivAux_nonneg h_le), ENNReal.ofReal_one] rw [withDensity_sub_add_cancel] · rw [withDensity_one'] · exact measurable_const · fun_prop · intro a filter_upwards [rnDerivAux_le_one h_le] with x hx simp only [ENNReal.ofReal_le_one] exact hx /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. -/ def mutuallySingularSet (κ η : Kernel α γ) : Set (α × γ) := {p | 1 ≤ rnDerivAux κ (κ + η) p.1 p.2} /-- A set of points in `α × γ` related to the absolute continuity / mutual singularity of `κ` and `η`. That is, * `withDensity η (rnDeriv κ η) a (mutuallySingularSetSlice κ η a) = 0`, * `singularPart κ η a (mutuallySingularSetSlice κ η a)ᶜ = 0`. -/ def mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : Set γ := {x | 1 ≤ rnDerivAux κ (κ + η) a x} lemma mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∈ mutuallySingularSetSlice κ η a ↔ 1 ≤ rnDerivAux κ (κ + η) a x := by rw [mutuallySingularSetSlice, mem_setOf] lemma not_mem_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) (x : γ) : x ∉ mutuallySingularSetSlice κ η a ↔ rnDerivAux κ (κ + η) a x < 1 := by simp [mutuallySingularSetSlice] lemma measurableSet_mutuallySingularSet (κ η : Kernel α γ) : MeasurableSet (mutuallySingularSet κ η) := measurable_rnDerivAux κ (κ + η) measurableSet_Ici lemma measurableSet_mutuallySingularSetSlice (κ η : Kernel α γ) (a : α) : MeasurableSet (mutuallySingularSetSlice κ η a) := measurable_prodMk_left (measurableSet_mutuallySingularSet κ η) lemma measure_mutuallySingularSetSlice (κ η : Kernel α γ) [IsFiniteKernel κ] [IsFiniteKernel η] (a : α) : η a (mutuallySingularSetSlice κ η a) = 0 := by suffices withDensity (κ + η) (fun a x ↦ Real.toNNReal (1 - rnDerivAux κ (κ + η) a x)) a {x | 1 ≤ rnDerivAux κ (κ + η) a x} = 0 by rwa [withDensity_one_sub_rnDerivAux κ η] at this simp_rw [ofNNReal_toNNReal] rw [Kernel.withDensity_apply', lintegral_eq_zero_iff, EventuallyEq, ae_restrict_iff] rotate_left · exact (measurableSet_singleton 0).preimage (by fun_prop) · fun_prop · fun_prop refine ae_of_all _ (fun x hx ↦ ?_) simp only [mem_setOf_eq] at hx simp [hx] /-- Radon-Nikodym derivative of the kernel `κ` with respect to the kernel `η`. -/ noncomputable irreducible_def rnDeriv (κ η : Kernel α γ) (a : α) (x : γ) : ℝ≥0∞ := ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x) lemma rnDeriv_def' (κ η : Kernel α γ) : rnDeriv κ η = fun a x ↦ ENNReal.ofReal (rnDerivAux κ (κ + η) a x) / ENNReal.ofReal (1 - rnDerivAux κ (κ + η) a x) := by ext; rw [rnDeriv_def] @[fun_prop] lemma measurable_rnDeriv (κ η : Kernel α γ) : Measurable (fun p : α × γ ↦ rnDeriv κ η p.1 p.2) := by simp_rw [rnDeriv_def] exact (measurable_rnDerivAux κ _).ennreal_ofReal.div (measurable_const.sub (measurable_rnDerivAux κ _)).ennreal_ofReal @[fun_prop] lemma measurable_rnDeriv_right (κ η : Kernel α γ) (a : α) : Measurable (fun x : γ ↦ rnDeriv κ η a x) := by fun_prop lemma rnDeriv_eq_top_iff (κ η : Kernel α γ) (a : α) (x : γ) :
rnDeriv κ η a x = ∞ ↔ (a, x) ∈ mutuallySingularSet κ η := by simp only [rnDeriv, ENNReal.div_eq_top, ne_eq, ENNReal.ofReal_eq_zero, not_le, tsub_le_iff_right, zero_add, ENNReal.ofReal_ne_top, not_false_eq_true, and_true, or_false, mutuallySingularSet, mem_setOf_eq, and_iff_right_iff_imp] exact fun h ↦ zero_lt_one.trans_le h
Mathlib/Probability/Kernel/RadonNikodym.lean
246
250
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll, Anatole Dedecker -/ import Mathlib.Analysis.LocallyConvex.Bounded import Mathlib.Analysis.Seminorm import Mathlib.Data.Real.Sqrt import Mathlib.Topology.Algebra.Equicontinuity import Mathlib.Topology.MetricSpace.Equicontinuity import Mathlib.Topology.Algebra.FilterBasis import Mathlib.Topology.Algebra.Module.LocallyConvex /-! # Topology induced by a family of seminorms ## Main definitions * `SeminormFamily.basisSets`: The set of open seminorm balls for a family of seminorms. * `SeminormFamily.moduleFilterBasis`: A module filter basis formed by the open balls. * `Seminorm.IsBounded`: A linear map `f : E →ₗ[𝕜] F` is bounded iff every seminorm in `F` can be bounded by a finite number of seminorms in `E`. ## Main statements * `WithSeminorms.toLocallyConvexSpace`: A space equipped with a family of seminorms is locally convex. * `WithSeminorms.firstCountable`: A space is first countable if it's topology is induced by a countable family of seminorms. ## Continuity of semilinear maps If `E` and `F` are topological vector space with the topology induced by a family of seminorms, then we have a direct method to prove that a linear map is continuous: * `Seminorm.continuous_from_bounded`: A bounded linear map `f : E →ₗ[𝕜] F` is continuous. If the topology of a space `E` is induced by a family of seminorms, then we can characterize von Neumann boundedness in terms of that seminorm family. Together with `LinearMap.continuous_of_locally_bounded` this gives general criterion for continuity. * `WithSeminorms.isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.isVonNBounded_iff_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_finset_seminorm_bounded` * `WithSeminorms.image_isVonNBounded_iff_seminorm_bounded` ## Tags seminorm, locally convex -/ open NormedField Set Seminorm TopologicalSpace Filter List open NNReal Pointwise Topology Uniformity variable {𝕜 𝕜₂ 𝕝 𝕝₂ E F G ι ι' : Type*} section FilterBasis variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable (𝕜 E ι) /-- An abbreviation for indexed families of seminorms. This is mainly to allow for dot-notation. -/ abbrev SeminormFamily := ι → Seminorm 𝕜 E variable {𝕜 E ι} namespace SeminormFamily /-- The sets of a filter basis for the neighborhood filter of 0. -/ def basisSets (p : SeminormFamily 𝕜 E ι) : Set (Set E) := ⋃ (s : Finset ι) (r) (_ : 0 < r), singleton (ball (s.sup p) (0 : E) r) variable (p : SeminormFamily 𝕜 E ι) theorem basisSets_iff {U : Set E} : U ∈ p.basisSets ↔ ∃ (i : Finset ι) (r : ℝ), 0 < r ∧ U = ball (i.sup p) 0 r := by simp only [basisSets, mem_iUnion, exists_prop, mem_singleton_iff] theorem basisSets_mem (i : Finset ι) {r : ℝ} (hr : 0 < r) : (i.sup p).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨i, _, hr, rfl⟩ theorem basisSets_singleton_mem (i : ι) {r : ℝ} (hr : 0 < r) : (p i).ball 0 r ∈ p.basisSets := (basisSets_iff _).mpr ⟨{i}, _, hr, by rw [Finset.sup_singleton]⟩ theorem basisSets_nonempty [Nonempty ι] : p.basisSets.Nonempty := by let i := Classical.arbitrary ι refine nonempty_def.mpr ⟨(p i).ball 0 1, ?_⟩ exact p.basisSets_singleton_mem i zero_lt_one theorem basisSets_intersect (U V : Set E) (hU : U ∈ p.basisSets) (hV : V ∈ p.basisSets) : ∃ z ∈ p.basisSets, z ⊆ U ∩ V := by classical rcases p.basisSets_iff.mp hU with ⟨s, r₁, hr₁, hU⟩ rcases p.basisSets_iff.mp hV with ⟨t, r₂, hr₂, hV⟩ use ((s ∪ t).sup p).ball 0 (min r₁ r₂) refine ⟨p.basisSets_mem (s ∪ t) (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ?_⟩ rw [hU, hV, ball_finset_sup_eq_iInter _ _ _ (lt_min_iff.mpr ⟨hr₁, hr₂⟩), ball_finset_sup_eq_iInter _ _ _ hr₁, ball_finset_sup_eq_iInter _ _ _ hr₂] exact Set.subset_inter (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_left hi, ball_mono <| min_le_left _ _⟩) (Set.iInter₂_mono' fun i hi => ⟨i, Finset.subset_union_right hi, ball_mono <| min_le_right _ _⟩) theorem basisSets_zero (U) (hU : U ∈ p.basisSets) : (0 : E) ∈ U := by rcases p.basisSets_iff.mp hU with ⟨ι', r, hr, hU⟩ rw [hU, mem_ball_zero, map_zero] exact hr theorem basisSets_add (U) (hU : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V + V ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ use (s.sup p).ball 0 (r / 2) refine ⟨p.basisSets_mem s (div_pos hr zero_lt_two), ?_⟩ refine Set.Subset.trans (ball_add_ball_subset (s.sup p) (r / 2) (r / 2) 0 0) ?_ rw [hU, add_zero, add_halves] theorem basisSets_neg (U) (hU' : U ∈ p.basisSets) : ∃ V ∈ p.basisSets, V ⊆ (fun x : E => -x) ⁻¹' U := by rcases p.basisSets_iff.mp hU' with ⟨s, r, _, hU⟩ rw [hU, neg_preimage, neg_ball (s.sup p), neg_zero] exact ⟨U, hU', Eq.subset hU⟩ /-- The `addGroupFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def addGroupFilterBasis [Nonempty ι] : AddGroupFilterBasis E := addGroupFilterBasisOfComm p.basisSets p.basisSets_nonempty p.basisSets_intersect p.basisSets_zero p.basisSets_add p.basisSets_neg theorem basisSets_smul_right (v : E) (U : Set E) (hU : U ∈ p.basisSets) : ∀ᶠ x : 𝕜 in 𝓝 0, x • v ∈ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU, Filter.eventually_iff] simp_rw [(s.sup p).mem_ball_zero, map_smul_eq_mul] by_cases h : 0 < (s.sup p) v · simp_rw [(lt_div_iff₀ h).symm] rw [← _root_.ball_zero_eq] exact Metric.ball_mem_nhds 0 (div_pos hr h) simp_rw [le_antisymm (not_lt.mp h) (apply_nonneg _ v), mul_zero, hr] exact IsOpen.mem_nhds isOpen_univ (mem_univ 0) variable [Nonempty ι] theorem basisSets_smul (U) (hU : U ∈ p.basisSets) : ∃ V ∈ 𝓝 (0 : 𝕜), ∃ W ∈ p.addGroupFilterBasis.sets, V • W ⊆ U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ refine ⟨Metric.ball 0 √r, Metric.ball_mem_nhds 0 (Real.sqrt_pos.mpr hr), ?_⟩ refine ⟨(s.sup p).ball 0 √r, p.basisSets_mem s (Real.sqrt_pos.mpr hr), ?_⟩ refine Set.Subset.trans (ball_smul_ball (s.sup p) √r √r) ?_ rw [hU, Real.mul_self_sqrt (le_of_lt hr)] theorem basisSets_smul_left (x : 𝕜) (U : Set E) (hU : U ∈ p.basisSets) : ∃ V ∈ p.addGroupFilterBasis.sets, V ⊆ (fun y : E => x • y) ⁻¹' U := by rcases p.basisSets_iff.mp hU with ⟨s, r, hr, hU⟩ rw [hU] by_cases h : x ≠ 0 · rw [(s.sup p).smul_ball_preimage 0 r x h, smul_zero] use (s.sup p).ball 0 (r / ‖x‖) exact ⟨p.basisSets_mem s (div_pos hr (norm_pos_iff.mpr h)), Subset.rfl⟩ refine ⟨(s.sup p).ball 0 r, p.basisSets_mem s hr, ?_⟩ simp only [not_ne_iff.mp h, Set.subset_def, mem_ball_zero, hr, mem_univ, map_zero, imp_true_iff, preimage_const_of_mem, zero_smul] /-- The `moduleFilterBasis` induced by the filter basis `Seminorm.basisSets`. -/ protected def moduleFilterBasis : ModuleFilterBasis 𝕜 E where toAddGroupFilterBasis := p.addGroupFilterBasis smul' := p.basisSets_smul _ smul_left' := p.basisSets_smul_left smul_right' := p.basisSets_smul_right theorem filter_eq_iInf (p : SeminormFamily 𝕜 E ι) : p.moduleFilterBasis.toFilterBasis.filter = ⨅ i, (𝓝 0).comap (p i) := by refine le_antisymm (le_iInf fun i => ?_) ?_ · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.le_basis_iff (Metric.nhds_basis_ball.comap _)] intro ε hε refine ⟨(p i).ball 0 ε, ?_, ?_⟩ · rw [← (Finset.sup_singleton : _ = p i)] exact p.basisSets_mem {i} hε · rw [id, (p i).ball_zero_eq_preimage_ball] · rw [p.moduleFilterBasis.toFilterBasis.hasBasis.ge_iff] rintro U (hU : U ∈ p.basisSets) rcases p.basisSets_iff.mp hU with ⟨s, r, hr, rfl⟩ rw [id, Seminorm.ball_finset_sup_eq_iInter _ _ _ hr, s.iInter_mem_sets] exact fun i _ => Filter.mem_iInf_of_mem i ⟨Metric.ball 0 r, Metric.ball_mem_nhds 0 hr, Eq.subset (p i).ball_zero_eq_preimage_ball.symm⟩ /-- If a family of seminorms is continuous, then their basis sets are neighborhoods of zero. -/ lemma basisSets_mem_nhds {𝕜 E ι : Type*} [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] (p : SeminormFamily 𝕜 E ι) (hp : ∀ i, Continuous (p i)) (U : Set E) (hU : U ∈ p.basisSets) : U ∈ 𝓝 (0 : E) := by obtain ⟨s, r, hr, rfl⟩ := p.basisSets_iff.mp hU clear hU refine Seminorm.ball_mem_nhds ?_ hr classical induction s using Finset.induction_on case empty => simpa using continuous_zero case insert a s _ hs => simp only [Finset.sup_insert, coe_sup] exact Continuous.max (hp a) hs end SeminormFamily end FilterBasis section Bounded namespace Seminorm variable [NormedField 𝕜] [AddCommGroup E] [Module 𝕜 E] variable [NormedField 𝕜₂] [AddCommGroup F] [Module 𝕜₂ F] variable {σ₁₂ : 𝕜 →+* 𝕜₂} [RingHomIsometric σ₁₂] -- Todo: This should be phrased entirely in terms of the von Neumann bornology. /-- The proposition that a linear map is bounded between spaces with families of seminorms. -/ def IsBounded (p : ι → Seminorm 𝕜 E) (q : ι' → Seminorm 𝕜₂ F) (f : E →ₛₗ[σ₁₂] F) : Prop := ∀ i, ∃ s : Finset ι, ∃ C : ℝ≥0, (q i).comp f ≤ C • s.sup p theorem isBounded_const (ι' : Type*) [Nonempty ι'] {p : ι → Seminorm 𝕜 E} {q : Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded p (fun _ : ι' => q) f ↔ ∃ (s : Finset ι) (C : ℝ≥0), q.comp f ≤ C • s.sup p := by simp only [IsBounded, forall_const] theorem const_isBounded (ι : Type*) [Nonempty ι] {p : Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} (f : E →ₛₗ[σ₁₂] F) : IsBounded (fun _ : ι => p) q f ↔ ∀ i, ∃ C : ℝ≥0, (q i).comp f ≤ C • p := by constructor <;> intro h i · rcases h i with ⟨s, C, h⟩ exact ⟨C, le_trans h (smul_le_smul (Finset.sup_le fun _ _ => le_rfl) le_rfl)⟩ use {Classical.arbitrary ι} simp only [h, Finset.sup_singleton] theorem isBounded_sup {p : ι → Seminorm 𝕜 E} {q : ι' → Seminorm 𝕜₂ F} {f : E →ₛₗ[σ₁₂] F} (hf : IsBounded p q f) (s' : Finset ι') : ∃ (C : ℝ≥0) (s : Finset ι), (s'.sup q).comp f ≤ C • s.sup p := by classical obtain rfl | _ := s'.eq_empty_or_nonempty · exact ⟨1, ∅, by simp [Seminorm.bot_eq_zero]⟩ choose fₛ fC hf using hf
use s'.card • s'.sup fC, Finset.biUnion s' fₛ have hs : ∀ i : ι', i ∈ s' → (q i).comp f ≤ s'.sup fC • (Finset.biUnion s' fₛ).sup p := by intro i hi refine (hf i).trans (smul_le_smul ?_ (Finset.le_sup hi)) exact Finset.sup_mono (Finset.subset_biUnion_of_mem fₛ hi) refine (comp_mono f (finset_sup_le_sum q s')).trans ?_ simp_rw [← pullback_apply, map_sum, pullback_apply] refine (Finset.sum_le_sum hs).trans ?_ rw [Finset.sum_const, smul_assoc] end Seminorm end Bounded section Topology
Mathlib/Analysis/LocallyConvex/WithSeminorms.lean
243
258
/- Copyright (c) 2021 Hunter Monroe. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hunter Monroe, Kyle Miller, Alena Gusakov -/ import Mathlib.Combinatorics.SimpleGraph.DeleteEdges import Mathlib.Data.Fintype.Powerset /-! # Subgraphs of a simple graph A subgraph of a simple graph consists of subsets of the graph's vertices and edges such that the endpoints of each edge are present in the vertex subset. The edge subset is formalized as a sub-relation of the adjacency relation of the simple graph. ## Main definitions * `Subgraph G` is the type of subgraphs of a `G : SimpleGraph V`. * `Subgraph.neighborSet`, `Subgraph.incidenceSet`, and `Subgraph.degree` are like their `SimpleGraph` counterparts, but they refer to vertices from `G` to avoid subtype coercions. * `Subgraph.coe` is the coercion from a `G' : Subgraph G` to a `SimpleGraph G'.verts`. (In Lean 3 this could not be a `Coe` instance since the destination type depends on `G'`.) * `Subgraph.IsSpanning` for whether a subgraph is a spanning subgraph and `Subgraph.IsInduced` for whether a subgraph is an induced subgraph. * Instances for `Lattice (Subgraph G)` and `BoundedOrder (Subgraph G)`. * `SimpleGraph.toSubgraph`: If a `SimpleGraph` is a subgraph of another, then you can turn it into a member of the larger graph's `SimpleGraph.Subgraph` type. * Graph homomorphisms from a subgraph to a graph (`Subgraph.map_top`) and between subgraphs (`Subgraph.map`). ## Implementation notes * Recall that subgraphs are not determined by their vertex sets, so `SetLike` does not apply to this kind of subobject. ## TODO * Images of graph homomorphisms as subgraphs. -/ universe u v namespace SimpleGraph /-- A subgraph of a `SimpleGraph` is a subset of vertices along with a restriction of the adjacency relation that is symmetric and is supported by the vertex subset. They also form a bounded lattice. Thinking of `V → V → Prop` as `Set (V × V)`, a set of darts (i.e., half-edges), then `Subgraph.adj_sub` is that the darts of a subgraph are a subset of the darts of `G`. -/ @[ext] structure Subgraph {V : Type u} (G : SimpleGraph V) where /-- Vertices of the subgraph -/ verts : Set V /-- Edges of the subgraph -/ Adj : V → V → Prop adj_sub : ∀ {v w : V}, Adj v w → G.Adj v w edge_vert : ∀ {v w : V}, Adj v w → v ∈ verts symm : Symmetric Adj := by aesop_graph -- Porting note: Originally `by obviously` initialize_simps_projections SimpleGraph.Subgraph (Adj → adj) variable {ι : Sort*} {V : Type u} {W : Type v} /-- The one-vertex subgraph. -/ @[simps] protected def singletonSubgraph (G : SimpleGraph V) (v : V) : G.Subgraph where verts := {v} Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm _ _ := False.elim /-- The one-edge subgraph. -/ @[simps] def subgraphOfAdj (G : SimpleGraph V) {v w : V} (hvw : G.Adj v w) : G.Subgraph where verts := {v, w} Adj a b := s(v, w) = s(a, b) adj_sub h := by rw [← G.mem_edgeSet, ← h] exact hvw edge_vert {a b} h := by apply_fun fun e ↦ a ∈ e at h simp only [Sym2.mem_iff, true_or, eq_iff_iff, iff_true] at h exact h namespace Subgraph variable {G : SimpleGraph V} {G₁ G₂ : G.Subgraph} {a b : V} protected theorem loopless (G' : Subgraph G) : Irreflexive G'.Adj := fun v h ↦ G.loopless v (G'.adj_sub h) theorem adj_comm (G' : Subgraph G) (v w : V) : G'.Adj v w ↔ G'.Adj w v := ⟨fun x ↦ G'.symm x, fun x ↦ G'.symm x⟩ @[symm] theorem adj_symm (G' : Subgraph G) {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.symm {G' : Subgraph G} {u v : V} (h : G'.Adj u v) : G'.Adj v u := G'.symm h protected theorem Adj.adj_sub {H : G.Subgraph} {u v : V} (h : H.Adj u v) : G.Adj u v := H.adj_sub h protected theorem Adj.fst_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ∈ H.verts := H.edge_vert h protected theorem Adj.snd_mem {H : G.Subgraph} {u v : V} (h : H.Adj u v) : v ∈ H.verts := h.symm.fst_mem protected theorem Adj.ne {H : G.Subgraph} {u v : V} (h : H.Adj u v) : u ≠ v := h.adj_sub.ne theorem adj_congr_of_sym2 {H : G.Subgraph} {u v w x : V} (h2 : s(u, v) = s(w, x)) : H.Adj u v ↔ H.Adj w x := by simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, Prod.swap_prod_mk] at h2 rcases h2 with hl | hr · rw [hl.1, hl.2] · rw [hr.1, hr.2, Subgraph.adj_comm] /-- Coercion from `G' : Subgraph G` to a `SimpleGraph G'.verts`. -/ @[simps] protected def coe (G' : Subgraph G) : SimpleGraph G'.verts where Adj v w := G'.Adj v w symm _ _ h := G'.symm h loopless v h := loopless G v (G'.adj_sub h) @[simp] theorem coe_adj_sub (G' : Subgraph G) (u v : G'.verts) (h : G'.coe.Adj u v) : G.Adj u v := G'.adj_sub h -- Given `h : H.Adj u v`, then `h.coe : H.coe.Adj ⟨u, _⟩ ⟨v, _⟩`. protected theorem Adj.coe {H : G.Subgraph} {u v : V} (h : H.Adj u v) : H.coe.Adj ⟨u, H.edge_vert h⟩ ⟨v, H.edge_vert h.symm⟩ := h instance (G : SimpleGraph V) (H : Subgraph G) [DecidableRel H.Adj] : DecidableRel H.coe.Adj := fun a b ↦ ‹DecidableRel H.Adj› _ _ /-- A subgraph is called a *spanning subgraph* if it contains all the vertices of `G`. -/ def IsSpanning (G' : Subgraph G) : Prop := ∀ v : V, v ∈ G'.verts theorem isSpanning_iff {G' : Subgraph G} : G'.IsSpanning ↔ G'.verts = Set.univ := Set.eq_univ_iff_forall.symm protected alias ⟨IsSpanning.verts_eq_univ, _⟩ := isSpanning_iff /-- Coercion from `Subgraph G` to `SimpleGraph V`. If `G'` is a spanning subgraph, then `G'.spanningCoe` yields an isomorphic graph. In general, this adds in all vertices from `V` as isolated vertices. -/ @[simps] protected def spanningCoe (G' : Subgraph G) : SimpleGraph V where Adj := G'.Adj symm := G'.symm loopless v hv := G.loopless v (G'.adj_sub hv) @[simp] theorem Adj.of_spanningCoe {G' : Subgraph G} {u v : G'.verts} (h : G'.spanningCoe.Adj u v) : G.Adj u v := G'.adj_sub h lemma spanningCoe_le (G' : G.Subgraph) : G'.spanningCoe ≤ G := fun _ _ ↦ G'.3 theorem spanningCoe_inj : G₁.spanningCoe = G₂.spanningCoe ↔ G₁.Adj = G₂.Adj := by simp [Subgraph.spanningCoe] lemma mem_of_adj_spanningCoe {v w : V} {s : Set V} (G : SimpleGraph s) (hadj : G.spanningCoe.Adj v w) : v ∈ s := by aesop @[simp] lemma spanningCoe_subgraphOfAdj {v w : V} (hadj : G.Adj v w) : (G.subgraphOfAdj hadj).spanningCoe = fromEdgeSet {s(v, w)} := by ext v w aesop /-- `spanningCoe` is equivalent to `coe` for a subgraph that `IsSpanning`. -/ @[simps] def spanningCoeEquivCoeOfSpanning (G' : Subgraph G) (h : G'.IsSpanning) : G'.spanningCoe ≃g G'.coe where toFun v := ⟨v, h v⟩ invFun v := v left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- A subgraph is called an *induced subgraph* if vertices of `G'` are adjacent if they are adjacent in `G`. -/ def IsInduced (G' : Subgraph G) : Prop := ∀ ⦃v⦄, v ∈ G'.verts → ∀ ⦃w⦄, w ∈ G'.verts → G.Adj v w → G'.Adj v w @[simp] protected lemma IsInduced.adj {G' : G.Subgraph} (hG' : G'.IsInduced) {a b : G'.verts} : G'.Adj a b ↔ G.Adj a b := ⟨coe_adj_sub _ _ _, hG' a.2 b.2⟩ /-- `H.support` is the set of vertices that form edges in the subgraph `H`. -/ def support (H : Subgraph G) : Set V := Rel.dom H.Adj theorem mem_support (H : Subgraph G) {v : V} : v ∈ H.support ↔ ∃ w, H.Adj v w := Iff.rfl theorem support_subset_verts (H : Subgraph G) : H.support ⊆ H.verts := fun _ ⟨_, h⟩ ↦ H.edge_vert h /-- `G'.neighborSet v` is the set of vertices adjacent to `v` in `G'`. -/ def neighborSet (G' : Subgraph G) (v : V) : Set V := {w | G'.Adj v w} theorem neighborSet_subset (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G.neighborSet v := fun _ ↦ G'.adj_sub theorem neighborSet_subset_verts (G' : Subgraph G) (v : V) : G'.neighborSet v ⊆ G'.verts := fun _ h ↦ G'.edge_vert (adj_symm G' h) @[simp] theorem mem_neighborSet (G' : Subgraph G) (v w : V) : w ∈ G'.neighborSet v ↔ G'.Adj v w := Iff.rfl /-- A subgraph as a graph has equivalent neighbor sets. -/ def coeNeighborSetEquiv {G' : Subgraph G} (v : G'.verts) : G'.coe.neighborSet v ≃ G'.neighborSet v where toFun w := ⟨w, w.2⟩ invFun w := ⟨⟨w, G'.edge_vert (G'.adj_symm w.2)⟩, w.2⟩ left_inv _ := rfl right_inv _ := rfl /-- The edge set of `G'` consists of a subset of edges of `G`. -/ def edgeSet (G' : Subgraph G) : Set (Sym2 V) := Sym2.fromRel G'.symm theorem edgeSet_subset (G' : Subgraph G) : G'.edgeSet ⊆ G.edgeSet := Sym2.ind (fun _ _ ↦ G'.adj_sub) @[simp] protected lemma mem_edgeSet {G' : Subgraph G} {v w : V} : s(v, w) ∈ G'.edgeSet ↔ G'.Adj v w := .rfl @[simp] lemma edgeSet_coe {G' : G.Subgraph} : G'.coe.edgeSet = Sym2.map (↑) ⁻¹' G'.edgeSet := by ext e; induction e using Sym2.ind; simp lemma image_coe_edgeSet_coe (G' : G.Subgraph) : Sym2.map (↑) '' G'.coe.edgeSet = G'.edgeSet := by rw [edgeSet_coe, Set.image_preimage_eq_iff] rintro e he induction e using Sym2.ind with | h a b => rw [Subgraph.mem_edgeSet] at he exact ⟨s(⟨a, edge_vert _ he⟩, ⟨b, edge_vert _ he.symm⟩), Sym2.map_pair_eq ..⟩ theorem mem_verts_of_mem_edge {G' : Subgraph G} {e : Sym2 V} {v : V} (he : e ∈ G'.edgeSet) (hv : v ∈ e) : v ∈ G'.verts := by induction e rcases Sym2.mem_iff.mp hv with (rfl | rfl) · exact G'.edge_vert he · exact G'.edge_vert (G'.symm he) /-- The `incidenceSet` is the set of edges incident to a given vertex. -/ def incidenceSet (G' : Subgraph G) (v : V) : Set (Sym2 V) := {e ∈ G'.edgeSet | v ∈ e} theorem incidenceSet_subset_incidenceSet (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G.incidenceSet v := fun _ h ↦ ⟨G'.edgeSet_subset h.1, h.2⟩ theorem incidenceSet_subset (G' : Subgraph G) (v : V) : G'.incidenceSet v ⊆ G'.edgeSet := fun _ h ↦ h.1 /-- Give a vertex as an element of the subgraph's vertex type. -/ abbrev vert (G' : Subgraph G) (v : V) (h : v ∈ G'.verts) : G'.verts := ⟨v, h⟩ /-- Create an equal copy of a subgraph (see `copy_eq`) with possibly different definitional equalities. See Note [range copy pattern]. -/ def copy (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : Subgraph G where verts := V'' Adj := adj' adj_sub := hadj.symm ▸ G'.adj_sub edge_vert := hV.symm ▸ hadj.symm ▸ G'.edge_vert symm := hadj.symm ▸ G'.symm theorem copy_eq (G' : Subgraph G) (V'' : Set V) (hV : V'' = G'.verts) (adj' : V → V → Prop) (hadj : adj' = G'.Adj) : G'.copy V'' hV adj' hadj = G' := Subgraph.ext hV hadj /-- The union of two subgraphs. -/ instance : Max G.Subgraph where max G₁ G₂ := { verts := G₁.verts ∪ G₂.verts Adj := G₁.Adj ⊔ G₂.Adj adj_sub := fun hab => Or.elim hab (fun h => G₁.adj_sub h) fun h => G₂.adj_sub h edge_vert := Or.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => Or.imp G₁.adj_symm G₂.adj_symm } /-- The intersection of two subgraphs. -/ instance : Min G.Subgraph where min G₁ G₂ := { verts := G₁.verts ∩ G₂.verts Adj := G₁.Adj ⊓ G₂.Adj adj_sub := fun hab => G₁.adj_sub hab.1 edge_vert := And.imp (fun h => G₁.edge_vert h) fun h => G₂.edge_vert h symm := fun _ _ => And.imp G₁.adj_symm G₂.adj_symm } /-- The `top` subgraph is `G` as a subgraph of itself. -/ instance : Top G.Subgraph where top := { verts := Set.univ Adj := G.Adj adj_sub := id edge_vert := @fun v _ _ => Set.mem_univ v symm := G.symm } /-- The `bot` subgraph is the subgraph with no vertices or edges. -/ instance : Bot G.Subgraph where bot := { verts := ∅ Adj := ⊥ adj_sub := False.elim edge_vert := False.elim symm := fun _ _ => id } instance : SupSet G.Subgraph where sSup s := { verts := ⋃ G' ∈ s, verts G' Adj := fun a b => ∃ G' ∈ s, Adj G' a b adj_sub := by rintro a b ⟨G', -, hab⟩ exact G'.adj_sub hab edge_vert := by rintro a b ⟨G', hG', hab⟩ exact Set.mem_iUnion₂_of_mem hG' (G'.edge_vert hab) symm := fun a b h => by simpa [adj_comm] using h } instance : InfSet G.Subgraph where sInf s := { verts := ⋂ G' ∈ s, verts G' Adj := fun a b => (∀ ⦃G'⦄, G' ∈ s → Adj G' a b) ∧ G.Adj a b adj_sub := And.right edge_vert := fun hab => Set.mem_iInter₂_of_mem fun G' hG' => G'.edge_vert <| hab.1 hG' symm := fun _ _ => And.imp (forall₂_imp fun _ _ => Adj.symm) G.adj_symm } @[simp] theorem sup_adj : (G₁ ⊔ G₂).Adj a b ↔ G₁.Adj a b ∨ G₂.Adj a b := Iff.rfl @[simp] theorem inf_adj : (G₁ ⊓ G₂).Adj a b ↔ G₁.Adj a b ∧ G₂.Adj a b := Iff.rfl @[simp] theorem top_adj : (⊤ : Subgraph G).Adj a b ↔ G.Adj a b := Iff.rfl @[simp] theorem not_bot_adj : ¬ (⊥ : Subgraph G).Adj a b := not_false @[simp] theorem verts_sup (G₁ G₂ : G.Subgraph) : (G₁ ⊔ G₂).verts = G₁.verts ∪ G₂.verts := rfl @[simp] theorem verts_inf (G₁ G₂ : G.Subgraph) : (G₁ ⊓ G₂).verts = G₁.verts ∩ G₂.verts := rfl @[simp] theorem verts_top : (⊤ : G.Subgraph).verts = Set.univ := rfl @[simp] theorem verts_bot : (⊥ : G.Subgraph).verts = ∅ := rfl @[simp] theorem sSup_adj {s : Set G.Subgraph} : (sSup s).Adj a b ↔ ∃ G ∈ s, Adj G a b := Iff.rfl @[simp] theorem sInf_adj {s : Set G.Subgraph} : (sInf s).Adj a b ↔ (∀ G' ∈ s, Adj G' a b) ∧ G.Adj a b := Iff.rfl @[simp] theorem iSup_adj {f : ι → G.Subgraph} : (⨆ i, f i).Adj a b ↔ ∃ i, (f i).Adj a b := by simp [iSup] @[simp] theorem iInf_adj {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ (∀ i, (f i).Adj a b) ∧ G.Adj a b := by simp [iInf] theorem sInf_adj_of_nonempty {s : Set G.Subgraph} (hs : s.Nonempty) : (sInf s).Adj a b ↔ ∀ G' ∈ s, Adj G' a b := sInf_adj.trans <| and_iff_left_of_imp <| by obtain ⟨G', hG'⟩ := hs exact fun h => G'.adj_sub (h _ hG') theorem iInf_adj_of_nonempty [Nonempty ι] {f : ι → G.Subgraph} : (⨅ i, f i).Adj a b ↔ ∀ i, (f i).Adj a b := by rw [iInf, sInf_adj_of_nonempty (Set.range_nonempty _)] simp @[simp] theorem verts_sSup (s : Set G.Subgraph) : (sSup s).verts = ⋃ G' ∈ s, verts G' := rfl @[simp] theorem verts_sInf (s : Set G.Subgraph) : (sInf s).verts = ⋂ G' ∈ s, verts G' := rfl @[simp] theorem verts_iSup {f : ι → G.Subgraph} : (⨆ i, f i).verts = ⋃ i, (f i).verts := by simp [iSup] @[simp] theorem verts_iInf {f : ι → G.Subgraph} : (⨅ i, f i).verts = ⋂ i, (f i).verts := by simp [iInf] @[simp] lemma coe_bot : (⊥ : G.Subgraph).coe = ⊥ := rfl @[simp] lemma IsInduced.top : (⊤ : G.Subgraph).IsInduced := fun _ _ _ _ ↦ id /-- The graph isomorphism between the top element of `G.subgraph` and `G`. -/ def topIso : (⊤ : G.Subgraph).coe ≃g G where toFun := (↑) invFun a := ⟨a, Set.mem_univ _⟩ left_inv _ := Subtype.eta .. right_inv _ := rfl map_rel_iff' := .rfl theorem verts_spanningCoe_injective : (fun G' : Subgraph G => (G'.verts, G'.spanningCoe)).Injective := by intro G₁ G₂ h rw [Prod.ext_iff] at h exact Subgraph.ext h.1 (spanningCoe_inj.1 h.2) /-- For subgraphs `G₁`, `G₂`, `G₁ ≤ G₂` iff `G₁.verts ⊆ G₂.verts` and `∀ a b, G₁.adj a b → G₂.adj a b`. -/ instance distribLattice : DistribLattice G.Subgraph := { show DistribLattice G.Subgraph from verts_spanningCoe_injective.distribLattice _ (fun _ _ => rfl) fun _ _ => rfl with le := fun x y => x.verts ⊆ y.verts ∧ ∀ ⦃v w : V⦄, x.Adj v w → y.Adj v w } instance : BoundedOrder (Subgraph G) where top := ⊤ bot := ⊥ le_top x := ⟨Set.subset_univ _, fun _ _ => x.adj_sub⟩ bot_le _ := ⟨Set.empty_subset _, fun _ _ => False.elim⟩ /-- Note that subgraphs do not form a Boolean algebra, because of `verts`. -/ def completelyDistribLatticeMinimalAxioms : CompletelyDistribLattice.MinimalAxioms G.Subgraph := { Subgraph.distribLattice with le := (· ≤ ·) sup := (· ⊔ ·) inf := (· ⊓ ·) top := ⊤ bot := ⊥ le_top := fun G' => ⟨Set.subset_univ _, fun _ _ => G'.adj_sub⟩ bot_le := fun _ => ⟨Set.empty_subset _, fun _ _ => False.elim⟩ sSup := sSup -- Porting note: needed `apply` here to modify elaboration; previously the term itself was fine. le_sSup := fun s G' hG' => ⟨by apply Set.subset_iUnion₂ G' hG', fun _ _ hab => ⟨G', hG', hab⟩⟩ sSup_le := fun s G' hG' => ⟨Set.iUnion₂_subset fun _ hH => (hG' _ hH).1, by rintro a b ⟨H, hH, hab⟩ exact (hG' _ hH).2 hab⟩ sInf := sInf sInf_le := fun _ G' hG' => ⟨Set.iInter₂_subset G' hG', fun _ _ hab => hab.1 hG'⟩ le_sInf := fun _ G' hG' => ⟨Set.subset_iInter₂ fun _ hH => (hG' _ hH).1, fun _ _ hab => ⟨fun _ hH => (hG' _ hH).2 hab, G'.adj_sub hab⟩⟩ iInf_iSup_eq := fun f => Subgraph.ext (by simpa using iInf_iSup_eq) (by ext; simp [Classical.skolem]) } instance : CompletelyDistribLattice G.Subgraph := .ofMinimalAxioms completelyDistribLatticeMinimalAxioms @[gcongr] lemma verts_mono {H H' : G.Subgraph} (h : H ≤ H') : H.verts ⊆ H'.verts := h.1 lemma verts_monotone : Monotone (verts : G.Subgraph → Set V) := fun _ _ h ↦ h.1 @[simps] instance subgraphInhabited : Inhabited (Subgraph G) := ⟨⊥⟩ @[simp] theorem neighborSet_sup {H H' : G.Subgraph} (v : V) : (H ⊔ H').neighborSet v = H.neighborSet v ∪ H'.neighborSet v := rfl @[simp] theorem neighborSet_inf {H H' : G.Subgraph} (v : V) : (H ⊓ H').neighborSet v = H.neighborSet v ∩ H'.neighborSet v := rfl @[simp] theorem neighborSet_top (v : V) : (⊤ : G.Subgraph).neighborSet v = G.neighborSet v := rfl @[simp] theorem neighborSet_bot (v : V) : (⊥ : G.Subgraph).neighborSet v = ∅ := rfl @[simp] theorem neighborSet_sSup (s : Set G.Subgraph) (v : V) : (sSup s).neighborSet v = ⋃ G' ∈ s, neighborSet G' v := by ext simp @[simp] theorem neighborSet_sInf (s : Set G.Subgraph) (v : V) : (sInf s).neighborSet v = (⋂ G' ∈ s, neighborSet G' v) ∩ G.neighborSet v := by ext simp @[simp] theorem neighborSet_iSup (f : ι → G.Subgraph) (v : V) : (⨆ i, f i).neighborSet v = ⋃ i, (f i).neighborSet v := by simp [iSup] @[simp] theorem neighborSet_iInf (f : ι → G.Subgraph) (v : V) : (⨅ i, f i).neighborSet v = (⋂ i, (f i).neighborSet v) ∩ G.neighborSet v := by simp [iInf] @[simp] theorem edgeSet_top : (⊤ : Subgraph G).edgeSet = G.edgeSet := rfl @[simp] theorem edgeSet_bot : (⊥ : Subgraph G).edgeSet = ∅ := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_inf {H₁ H₂ : Subgraph G} : (H₁ ⊓ H₂).edgeSet = H₁.edgeSet ∩ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_sup {H₁ H₂ : Subgraph G} : (H₁ ⊔ H₂).edgeSet = H₁.edgeSet ∪ H₂.edgeSet := Set.ext <| Sym2.ind (by simp) @[simp] theorem edgeSet_sSup (s : Set G.Subgraph) : (sSup s).edgeSet = ⋃ G' ∈ s, edgeSet G' := by ext e induction e simp @[simp] theorem edgeSet_sInf (s : Set G.Subgraph) : (sInf s).edgeSet = (⋂ G' ∈ s, edgeSet G') ∩ G.edgeSet := by ext e induction e simp @[simp] theorem edgeSet_iSup (f : ι → G.Subgraph) : (⨆ i, f i).edgeSet = ⋃ i, (f i).edgeSet := by simp [iSup] @[simp] theorem edgeSet_iInf (f : ι → G.Subgraph) : (⨅ i, f i).edgeSet = (⋂ i, (f i).edgeSet) ∩ G.edgeSet := by simp [iInf] @[simp] theorem spanningCoe_top : (⊤ : Subgraph G).spanningCoe = G := rfl @[simp] theorem spanningCoe_bot : (⊥ : Subgraph G).spanningCoe = ⊥ := rfl /-- Turn a subgraph of a `SimpleGraph` into a member of its subgraph type. -/ @[simps] def _root_.SimpleGraph.toSubgraph (H : SimpleGraph V) (h : H ≤ G) : G.Subgraph where verts := Set.univ Adj := H.Adj adj_sub e := h e edge_vert _ := Set.mem_univ _ symm := H.symm theorem support_mono {H H' : Subgraph G} (h : H ≤ H') : H.support ⊆ H'.support := Rel.dom_mono h.2 theorem _root_.SimpleGraph.toSubgraph.isSpanning (H : SimpleGraph V) (h : H ≤ G) : (toSubgraph H h).IsSpanning := Set.mem_univ theorem spanningCoe_le_of_le {H H' : Subgraph G} (h : H ≤ H') : H.spanningCoe ≤ H'.spanningCoe := h.2 @[simp] lemma sup_spanningCoe (H H' : Subgraph G) : (H ⊔ H').spanningCoe = H.spanningCoe ⊔ H'.spanningCoe := rfl /-- The top of the `Subgraph G` lattice is equivalent to the graph itself. -/ def topEquiv : (⊤ : Subgraph G).coe ≃g G where toFun v := ↑v invFun v := ⟨v, trivial⟩ left_inv _ := rfl right_inv _ := rfl map_rel_iff' := Iff.rfl /-- The bottom of the `Subgraph G` lattice is equivalent to the empty graph on the empty vertex type. -/ def botEquiv : (⊥ : Subgraph G).coe ≃g (⊥ : SimpleGraph Empty) where toFun v := v.property.elim invFun v := v.elim left_inv := fun ⟨_, h⟩ ↦ h.elim right_inv v := v.elim map_rel_iff' := Iff.rfl theorem edgeSet_mono {H₁ H₂ : Subgraph G} (h : H₁ ≤ H₂) : H₁.edgeSet ≤ H₂.edgeSet := Sym2.ind h.2 theorem _root_.Disjoint.edgeSet {H₁ H₂ : Subgraph G} (h : Disjoint H₁ H₂) : Disjoint H₁.edgeSet H₂.edgeSet := disjoint_iff_inf_le.mpr <| by simpa using edgeSet_mono h.le_bot section map variable {G' : SimpleGraph W} {f : G →g G'} /-- Graph homomorphisms induce a covariant function on subgraphs. -/ @[simps] protected def map (f : G →g G') (H : G.Subgraph) : G'.Subgraph where verts := f '' H.verts Adj := Relation.Map H.Adj f f adj_sub := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact f.map_rel (H.adj_sub h) edge_vert := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact Set.mem_image_of_mem _ (H.edge_vert h) symm := by rintro _ _ ⟨u, v, h, rfl, rfl⟩ exact ⟨v, u, H.symm h, rfl, rfl⟩ @[simp] lemma map_id (H : G.Subgraph) : H.map Hom.id = H := by ext <;> simp lemma map_comp {U : Type*} {G'' : SimpleGraph U} (H : G.Subgraph) (f : G →g G') (g : G' →g G'') : H.map (g.comp f) = (H.map f).map g := by ext <;> simp [Subgraph.map] @[gcongr] lemma map_mono {H₁ H₂ : G.Subgraph} (hH : H₁ ≤ H₂) : H₁.map f ≤ H₂.map f := by constructor · intro simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro v hv rfl exact ⟨_, hH.1 hv, rfl⟩ · rintro _ _ ⟨u, v, ha, rfl, rfl⟩ exact ⟨_, _, hH.2 ha, rfl, rfl⟩ lemma map_monotone : Monotone (Subgraph.map f) := fun _ _ ↦ map_mono theorem map_sup (f : G →g G') (H₁ H₂ : G.Subgraph) : (H₁ ⊔ H₂).map f = H₁.map f ⊔ H₂.map f := by ext <;> simp [Set.image_union, map_adj, sup_adj, Relation.Map, or_and_right, exists_or] @[simp] lemma map_iso_top {H : SimpleGraph W} (e : G ≃g H) : Subgraph.map e.toHom ⊤ = ⊤ := by ext <;> simp [Relation.Map, e.apply_eq_iff_eq_symm_apply, ← e.map_rel_iff] @[simp] lemma edgeSet_map (f : G →g G') (H : G.Subgraph) : (H.map f).edgeSet = Sym2.map f '' H.edgeSet := Sym2.fromRel_relationMap .. end map /-- Graph homomorphisms induce a contravariant function on subgraphs. -/ @[simps] protected def comap {G' : SimpleGraph W} (f : G →g G') (H : G'.Subgraph) : G.Subgraph where verts := f ⁻¹' H.verts Adj u v := G.Adj u v ∧ H.Adj (f u) (f v) adj_sub h := h.1 edge_vert h := Set.mem_preimage.1 (H.edge_vert h.2) symm _ _ h := ⟨G.symm h.1, H.symm h.2⟩ theorem comap_monotone {G' : SimpleGraph W} (f : G →g G') : Monotone (Subgraph.comap f) := by intro H H' h constructor · intro simp only [comap_verts, Set.mem_preimage] apply h.1 · intro v w simp +contextual only [comap_adj, and_imp, true_and] intro apply h.2 @[simp] lemma comap_equiv_top {H : SimpleGraph W} (f : G →g H) : Subgraph.comap f ⊤ = ⊤ := by ext <;> simp +contextual [f.map_adj] theorem map_le_iff_le_comap {G' : SimpleGraph W} (f : G →g G') (H : G.Subgraph) (H' : G'.Subgraph) : H.map f ≤ H' ↔ H ≤ H'.comap f := by refine ⟨fun h ↦ ⟨fun v hv ↦ ?_, fun v w hvw ↦ ?_⟩, fun h ↦ ⟨fun v ↦ ?_, fun v w ↦ ?_⟩⟩ · simp only [comap_verts, Set.mem_preimage] exact h.1 ⟨v, hv, rfl⟩ · simp only [H.adj_sub hvw, comap_adj, true_and] exact h.2 ⟨v, w, hvw, rfl, rfl⟩ · simp only [map_verts, Set.mem_image, forall_exists_index, and_imp] rintro w hw rfl exact h.1 hw · simp only [Relation.Map, map_adj, forall_exists_index, and_imp] rintro u u' hu rfl rfl exact (h.2 hu).2 instance [DecidableEq V] [Fintype V] [DecidableRel G.Adj] : Fintype G.Subgraph := by refine .ofBijective (α := {H : Finset V × (V → V → Bool) // (∀ a b, H.2 a b → G.Adj a b) ∧ (∀ a b, H.2 a b → a ∈ H.1) ∧ ∀ a b, H.2 a b = H.2 b a}) (fun H ↦ ⟨H.1.1, fun a b ↦ H.1.2 a b, @H.2.1, @H.2.2.1, by simp [Symmetric, H.2.2.2]⟩) ⟨?_, fun H ↦ ?_⟩ · rintro ⟨⟨_, _⟩, -⟩ ⟨⟨_, _⟩, -⟩ simp [funext_iff] · classical exact ⟨⟨(H.verts.toFinset, fun a b ↦ H.Adj a b), fun a b ↦ by simpa using H.adj_sub, fun a b ↦ by simpa using H.edge_vert, by simp [H.adj_comm]⟩, by simp⟩ instance [Finite V] : Finite G.Subgraph := by classical cases nonempty_fintype V; infer_instance /-- Given two subgraphs, one a subgraph of the other, there is an induced injective homomorphism of the subgraphs as graphs. -/ @[simps] def inclusion {x y : Subgraph G} (h : x ≤ y) : x.coe →g y.coe where toFun v := ⟨↑v, And.left h v.property⟩ map_rel' hvw := h.2 hvw theorem inclusion.injective {x y : Subgraph G} (h : x ≤ y) : Function.Injective (inclusion h) := by intro v w h rw [inclusion, DFunLike.coe, Subtype.mk_eq_mk] at h exact Subtype.ext h /-- There is an induced injective homomorphism of a subgraph of `G` into `G`. -/ @[simps] protected def hom (x : Subgraph G) : x.coe →g G where toFun v := v map_rel' := x.adj_sub @[simp] lemma coe_hom (x : Subgraph G) : (x.hom : x.verts → V) = (fun (v : x.verts) => (v : V)) := rfl theorem hom_injective {x : Subgraph G} : Function.Injective x.hom := fun _ _ ↦ Subtype.ext @[deprecated (since := "2025-03-15")] alias hom.injective := hom_injective @[simp] lemma map_hom_top (G' : G.Subgraph) : Subgraph.map G'.hom ⊤ = G' := by aesop (add unfold safe Relation.Map, unsafe G'.edge_vert, unsafe Adj.symm) /-- There is an induced injective homomorphism of a subgraph of `G` as a spanning subgraph into `G`. -/ @[simps] def spanningHom (x : Subgraph G) : x.spanningCoe →g G where toFun := id map_rel' := x.adj_sub theorem spanningHom_injective {x : Subgraph G} : Function.Injective x.spanningHom := fun _ _ ↦ id @[deprecated (since := "2025-03-15")] alias spanningHom.injective := spanningHom_injective theorem neighborSet_subset_of_subgraph {x y : Subgraph G} (h : x ≤ y) (v : V) : x.neighborSet v ⊆ y.neighborSet v := fun _ h' ↦ h.2 h' instance neighborSet.decidablePred (G' : Subgraph G) [h : DecidableRel G'.Adj] (v : V) : DecidablePred (· ∈ G'.neighborSet v) := h v /-- If a graph is locally finite at a vertex, then so is a subgraph of that graph. -/ instance finiteAt {G' : Subgraph G} (v : G'.verts) [DecidableRel G'.Adj] [Fintype (G.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G.neighborSet v) (G'.neighborSet_subset v) /-- If a subgraph is locally finite at a vertex, then so are subgraphs of that subgraph. This is not an instance because `G''` cannot be inferred. -/ def finiteAtOfSubgraph {G' G'' : Subgraph G} [DecidableRel G'.Adj] (h : G' ≤ G'') (v : G'.verts) [Fintype (G''.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset (G''.neighborSet v) (neighborSet_subset_of_subgraph h v) instance (G' : Subgraph G) [Fintype G'.verts] (v : V) [DecidablePred (· ∈ G'.neighborSet v)] : Fintype (G'.neighborSet v) := Set.fintypeSubset G'.verts (neighborSet_subset_verts G' v) instance coeFiniteAt {G' : Subgraph G} (v : G'.verts) [Fintype (G'.neighborSet v)] : Fintype (G'.coe.neighborSet v) := Fintype.ofEquiv _ (coeNeighborSetEquiv v).symm theorem IsSpanning.card_verts [Fintype V] {G' : Subgraph G} [Fintype G'.verts] (h : G'.IsSpanning) : G'.verts.toFinset.card = Fintype.card V := by simp only [isSpanning_iff.1 h, Set.toFinset_univ] congr /-- The degree of a vertex in a subgraph. It's zero for vertices outside the subgraph. -/ def degree (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] : ℕ := Fintype.card (G'.neighborSet v) theorem finset_card_neighborSet_eq_degree {G' : Subgraph G} {v : V} [Fintype (G'.neighborSet v)] : (G'.neighborSet v).toFinset.card = G'.degree v := by rw [degree, Set.toFinset_card] theorem degree_le (G' : Subgraph G) (v : V) [Fintype (G'.neighborSet v)] [Fintype (G.neighborSet v)] : G'.degree v ≤ G.degree v := by rw [← card_neighborSet_eq_degree] exact Set.card_le_card (G'.neighborSet_subset v) theorem degree_le' (G' G'' : Subgraph G) (h : G' ≤ G'') (v : V) [Fintype (G'.neighborSet v)] [Fintype (G''.neighborSet v)] : G'.degree v ≤ G''.degree v := Set.card_le_card (neighborSet_subset_of_subgraph h v) @[simp]
theorem coe_degree (G' : Subgraph G) (v : G'.verts) [Fintype (G'.coe.neighborSet v)] [Fintype (G'.neighborSet v)] : G'.coe.degree v = G'.degree v := by rw [← card_neighborSet_eq_degree]
Mathlib/Combinatorics/SimpleGraph/Subgraph.lean
795
797
/- Copyright (c) 2024 Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Junyan Xu -/ import Mathlib.RingTheory.AdjoinRoot /-! # Bivariate polynomials This file introduces the notation `R[X][Y]` for the polynomial ring `R[X][X]` in two variables, and the notation `Y` for the second variable, in the `Polynomial.Bivariate` scope. It also defines `Polynomial.evalEval` for the evaluation of a bivariate polynomial at a point on the affine plane, which is a ring homomorphism (`Polynomial.evalEvalRingHom`), as well as the abbreviation `CC` to view a constant in the base ring `R` as a bivariate polynomial. -/ /-- The notation `Y` for `X` in the `Polynomial` scope. -/ scoped[Polynomial.Bivariate] notation3:max "Y" => Polynomial.X (R := Polynomial _) /-- The notation `R[X][Y]` for `R[X][X]` in the `Polynomial` scope. -/ scoped[Polynomial.Bivariate] notation3:max R "[X][Y]" => Polynomial (Polynomial R) open scoped Polynomial.Bivariate namespace Polynomial noncomputable section variable {R S : Type*} section Semiring variable [Semiring R] /-- `evalEval x y p` is the evaluation `p(x,y)` of a two-variable polynomial `p : R[X][Y]`. -/ abbrev evalEval (x y : R) (p : R[X][Y]) : R := eval x (eval (C y) p) /-- A constant viewed as a polynomial in two variables. -/ abbrev CC (r : R) : R[X][Y] := C (C r) lemma evalEval_C (x y : R) (p : R[X]) : (C p).evalEval x y = p.eval x := by rw [evalEval, eval_C] @[simp] lemma evalEval_CC (x y : R) (p : R) : (CC p).evalEval x y = p := by rw [evalEval_C, eval_C] @[simp] lemma evalEval_zero (x y : R) : (0 : R[X][Y]).evalEval x y = 0 := by simp only [evalEval, eval_zero] @[simp] lemma evalEval_one (x y : R) : (1 : R[X][Y]).evalEval x y = 1 := by simp only [evalEval, eval_one] @[simp] lemma evalEval_natCast (x y : R) (n : ℕ) : (n : R[X][Y]).evalEval x y = n := by simp only [evalEval, eval_natCast] @[simp] lemma evalEval_X (x y : R) : X.evalEval x y = y := by rw [evalEval, eval_X, eval_C] @[simp] lemma evalEval_add (x y : R) (p q : R[X][Y]) : (p + q).evalEval x y = p.evalEval x y + q.evalEval x y := by simp only [evalEval, eval_add] lemma evalEval_sum (x y : R) (p : R[X]) (f : ℕ → R → R[X][Y]) : (p.sum f).evalEval x y = p.sum fun n a => (f n a).evalEval x y := by simp only [evalEval, eval, eval₂_sum] lemma evalEval_finset_sum {ι : Type*} (s : Finset ι) (x y : R) (f : ι → R[X][Y]) : (∑ i ∈ s, f i).evalEval x y = ∑ i ∈ s, (f i).evalEval x y := by simp only [evalEval, eval_finset_sum] @[simp] lemma evalEval_smul [DistribSMul S R] [IsScalarTower S R R] (x y : R) (s : S) (p : R[X][Y]) : (s • p).evalEval x y = s • p.evalEval x y := by simp only [evalEval, eval_smul] lemma evalEval_surjective (x y : R) : Function.Surjective <| evalEval x y := fun y => ⟨CC y, evalEval_CC ..⟩
end Semiring
Mathlib/Algebra/Polynomial/Bivariate.lean
86
88
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Real /-! # Properties of addition, multiplication and subtraction on extended non-negative real numbers In this file we prove elementary properties of algebraic operations on `ℝ≥0∞`, including addition, multiplication, natural powers and truncated subtraction, as well as how these interact with the order structure on `ℝ≥0∞`. Notably excluded from this list are inversion and division, the definitions and properties of which can be found in `Mathlib.Data.ENNReal.Inv`. Note: the definitions of the operations included in this file can be found in `Mathlib.Data.ENNReal.Basic`. -/ assert_not_exists Finset open Set NNReal ENNReal namespace ENNReal variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} section Mul @[mono, gcongr] theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := WithTop.mul_lt_mul ac bd protected lemma pow_right_strictMono {n : ℕ} (hn : n ≠ 0) : StrictMono fun a : ℝ≥0∞ ↦ a ^ n := WithTop.pow_right_strictMono hn @[gcongr] protected lemma pow_lt_pow_left (hab : a < b) {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n := WithTop.pow_lt_pow_left hab hn -- TODO: generalize to `WithTop` theorem mul_left_strictMono (h0 : a ≠ 0) (hinf : a ≠ ∞) : StrictMono (a * ·) := by lift a to ℝ≥0 using hinf rw [coe_ne_zero] at h0 intro x y h contrapose! h simpa only [← mul_assoc, ← coe_mul, inv_mul_cancel₀ h0, coe_one, one_mul] using mul_le_mul_left' h (↑a⁻¹) @[gcongr] protected theorem mul_lt_mul_left' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) : a * b < a * c := ENNReal.mul_left_strictMono h0 hinf bc @[gcongr] protected theorem mul_lt_mul_right' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) : b * a < c * a := mul_comm b a ▸ mul_comm c a ▸ ENNReal.mul_left_strictMono h0 hinf bc -- TODO: generalize to `WithTop` protected theorem mul_right_inj (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b = a * c ↔ b = c := (mul_left_strictMono h0 hinf).injective.eq_iff @[deprecated (since := "2025-01-20")] alias mul_eq_mul_left := ENNReal.mul_right_inj -- TODO: generalize to `WithTop` protected theorem mul_left_inj (h0 : c ≠ 0) (hinf : c ≠ ∞) : a * c = b * c ↔ a = b := mul_comm c a ▸ mul_comm c b ▸ ENNReal.mul_right_inj h0 hinf @[deprecated (since := "2025-01-20")] alias mul_eq_mul_right := ENNReal.mul_left_inj -- TODO: generalize to `WithTop` theorem mul_le_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b ≤ a * c ↔ b ≤ c := (mul_left_strictMono h0 hinf).le_iff_le -- TODO: generalize to `WithTop` theorem mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) := mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left -- TODO: generalize to `WithTop` theorem mul_lt_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b < a * c ↔ b < c := (mul_left_strictMono h0 hinf).lt_iff_lt -- TODO: generalize to `WithTop` theorem mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) := mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left protected lemma mul_eq_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * b = a ↔ b = 1 := by simpa using ENNReal.mul_right_inj ha₀ ha (c := 1) protected lemma mul_eq_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b = b ↔ a = 1 := by simpa using ENNReal.mul_left_inj hb₀ hb (b := 1) end Mul section OperationsAndOrder protected theorem pow_pos : 0 < a → ∀ n : ℕ, 0 < a ^ n := CanonicallyOrderedAdd.pow_pos protected theorem pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a ^ n ≠ 0 := by simpa only [pos_iff_ne_zero] using ENNReal.pow_pos theorem not_lt_zero : ¬a < 0 := by simp protected theorem le_of_add_le_add_left : a ≠ ∞ → a + b ≤ a + c → b ≤ c := WithTop.le_of_add_le_add_left protected theorem le_of_add_le_add_right : a ≠ ∞ → b + a ≤ c + a → b ≤ c := WithTop.le_of_add_le_add_right @[gcongr] protected theorem add_lt_add_left : a ≠ ∞ → b < c → a + b < a + c := WithTop.add_lt_add_left @[gcongr] protected theorem add_lt_add_right : a ≠ ∞ → b < c → b + a < c + a := WithTop.add_lt_add_right protected theorem add_le_add_iff_left : a ≠ ∞ → (a + b ≤ a + c ↔ b ≤ c) := WithTop.add_le_add_iff_left protected theorem add_le_add_iff_right : a ≠ ∞ → (b + a ≤ c + a ↔ b ≤ c) := WithTop.add_le_add_iff_right protected theorem add_lt_add_iff_left : a ≠ ∞ → (a + b < a + c ↔ b < c) := WithTop.add_lt_add_iff_left protected theorem add_lt_add_iff_right : a ≠ ∞ → (b + a < c + a ↔ b < c) := WithTop.add_lt_add_iff_right protected theorem add_lt_add_of_le_of_lt : a ≠ ∞ → a ≤ b → c < d → a + c < b + d := WithTop.add_lt_add_of_le_of_lt protected theorem add_lt_add_of_lt_of_le : c ≠ ∞ → a < b → c ≤ d → a + c < b + d := WithTop.add_lt_add_of_lt_of_le instance addLeftReflectLT : AddLeftReflectLT ℝ≥0∞ := WithTop.addLeftReflectLT theorem lt_add_right (ha : a ≠ ∞) (hb : b ≠ 0) : a < a + b := by rwa [← pos_iff_ne_zero, ← ENNReal.add_lt_add_iff_left ha, add_zero] at hb end OperationsAndOrder section OperationsAndInfty variable {α : Type*} {n : ℕ} @[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top @[simp] theorem add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := WithTop.add_lt_top theorem toNNReal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ ≠ ∞) (h₂ : r₂ ≠ ∞) : (r₁ + r₂).toNNReal = r₁.toNNReal + r₂.toNNReal := by lift r₁ to ℝ≥0 using h₁ lift r₂ to ℝ≥0 using h₂ rfl /-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) : a.toReal ≤ b.toReal + c.toReal := by refine le_trans (toReal_mono' hle ?_) toReal_add_le simpa only [add_eq_top, or_imp] using And.intro hb hc /-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then `ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer triangle-like inequalities from `ENNReal`s to `Real`s. -/ theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) : a.toReal ≤ b.toReal + c.toReal := toReal_le_add' hle (flip absurd hb) (flip absurd hc) theorem not_lt_top {x : ℝ≥0∞} : ¬x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, Classical.not_not] theorem add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top @[aesop (rule_sets := [finiteness]) safe apply] protected lemma Finiteness.add_ne_top {a b : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≠ ∞) : a + b ≠ ∞ := ENNReal.add_ne_top.2 ⟨ha, hb⟩ theorem mul_top' : a * ∞ = if a = 0 then 0 else ∞ := by convert WithTop.mul_top' a @[simp] theorem mul_top (h : a ≠ 0) : a * ∞ = ∞ := WithTop.mul_top h theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_mul' a @[simp] theorem top_mul (h : a ≠ 0) : ∞ * a = ∞ := WithTop.top_mul h theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 := WithTop.mul_eq_top_iff theorem mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ := WithTop.mul_lt_top -- This is unsafe because we could have `a = ∞` and `b = 0` or vice-versa @[aesop (rule_sets := [finiteness]) unsafe 75% apply] theorem mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := WithTop.mul_ne_top theorem lt_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a < ∞ := lt_top_iff_ne_top.2 fun ha => h <| mul_eq_top.2 (Or.inr ⟨ha, hb⟩) theorem lt_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b < ∞ := lt_top_of_mul_ne_top_left (by rwa [mul_comm]) ha theorem mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ a < ∞ ∧ b < ∞ ∨ a = 0 ∨ b = 0 := by constructor · intro h rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right] intro hb ha exact ⟨lt_top_of_mul_ne_top_left h.ne hb, lt_top_of_mul_ne_top_right h.ne ha⟩ · rintro (⟨ha, hb⟩ | rfl | rfl) <;> [exact mul_lt_top ha hb; simp; simp] theorem mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ := by rw [ENNReal.mul_lt_top_iff, and_self, or_self, or_iff_left_iff_imp] rintro rfl exact zero_lt_top theorem mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b := CanonicallyOrderedAdd.mul_pos theorem mul_pos (ha : a ≠ 0) (hb : b ≠ 0) : 0 < a * b := mul_pos_iff.2 ⟨pos_iff_ne_zero.2 ha, pos_iff_ne_zero.2 hb⟩ @[simp] lemma top_pow {n : ℕ} (hn : n ≠ 0) : (∞ : ℝ≥0∞) ^ n = ∞ := WithTop.top_pow hn @[simp] lemma pow_eq_top_iff : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := WithTop.pow_eq_top_iff lemma pow_ne_top_iff : a ^ n ≠ ∞ ↔ a ≠ ∞ ∨ n = 0 := WithTop.pow_ne_top_iff @[simp] lemma pow_lt_top_iff : a ^ n < ∞ ↔ a < ∞ ∨ n = 0 := WithTop.pow_lt_top_iff lemma eq_top_of_pow (n : ℕ) (ha : a ^ n = ∞) : a = ∞ := WithTop.eq_top_of_pow n ha @[deprecated (since := "2025-04-24")] alias pow_eq_top := eq_top_of_pow lemma pow_ne_top (ha : a ≠ ∞) : a ^ n ≠ ∞ := WithTop.pow_ne_top ha lemma pow_lt_top (ha : a < ∞) : a ^ n < ∞ := WithTop.pow_lt_top ha end OperationsAndInfty -- TODO: generalize to `WithTop` @[gcongr] protected theorem add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := by lift a to ℝ≥0 using ac.ne_top lift b to ℝ≥0 using bd.ne_top cases c; · simp cases d; · simp simp only [← coe_add, some_eq_coe, coe_lt_coe] at * exact add_lt_add ac bd section Cancel -- TODO: generalize to `WithTop` /-- An element `a` is `AddLECancellable` if `a + b ≤ a + c` implies `b ≤ c` for all `b` and `c`. This is true in `ℝ≥0∞` for all elements except `∞`. -/ @[simp] theorem addLECancellable_iff_ne {a : ℝ≥0∞} : AddLECancellable a ↔ a ≠ ∞ := by constructor · rintro h rfl refine zero_lt_one.not_le (h ?_) simp · rintro h b c hbc apply ENNReal.le_of_add_le_add_left h hbc /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_ne {a : ℝ≥0∞} (h : a ≠ ∞) : AddLECancellable a := addLECancellable_iff_ne.mpr h /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_lt {a : ℝ≥0∞} (h : a < ∞) : AddLECancellable a := cancel_of_ne h.ne /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_of_lt' {a b : ℝ≥0∞} (h : a < b) : AddLECancellable a := cancel_of_ne h.ne_top /-- This lemma has an abbreviated name because it is used frequently. -/ theorem cancel_coe {a : ℝ≥0} : AddLECancellable (a : ℝ≥0∞) := cancel_of_ne coe_ne_top theorem add_right_inj (h : a ≠ ∞) : a + b = a + c ↔ b = c := (cancel_of_ne h).inj theorem add_left_inj (h : a ≠ ∞) : b + a = c + a ↔ b = c := (cancel_of_ne h).inj_left end Cancel section Sub theorem sub_eq_sInf {a b : ℝ≥0∞} : a - b = sInf { d | a ≤ d + b } := le_antisymm (le_sInf fun _ h => tsub_le_iff_right.mpr h) <| sInf_le <| mem_setOf.2 le_tsub_add /-- This is a special case of `WithTop.coe_sub` in the `ENNReal` namespace -/ @[simp, norm_cast] theorem coe_sub : (↑(r - p) : ℝ≥0∞) = ↑r - ↑p := WithTop.coe_sub /-- This is a special case of `WithTop.top_sub_coe` in the `ENNReal` namespace -/ @[simp] theorem top_sub_coe : ∞ - ↑r = ∞ := WithTop.top_sub_coe @[simp] lemma top_sub (ha : a ≠ ∞) : ∞ - a = ∞ := by lift a to ℝ≥0 using ha; exact top_sub_coe /-- This is a special case of `WithTop.sub_top` in the `ENNReal` namespace -/ theorem sub_top : a - ∞ = 0 := WithTop.sub_top @[simp] theorem sub_eq_top_iff : a - b = ∞ ↔ a = ∞ ∧ b ≠ ∞ := WithTop.sub_eq_top_iff lemma sub_ne_top_iff : a - b ≠ ∞ ↔ a ≠ ∞ ∨ b = ∞ := WithTop.sub_ne_top_iff -- This is unsafe because we could have `a = b = ∞` @[aesop (rule_sets := [finiteness]) unsafe 75% apply] theorem sub_ne_top (ha : a ≠ ∞) : a - b ≠ ∞ := mt sub_eq_top_iff.mp <| mt And.left ha @[simp, norm_cast] theorem natCast_sub (m n : ℕ) : ↑(m - n) = (m - n : ℝ≥0∞) := by rw [← coe_natCast, Nat.cast_tsub, coe_sub, coe_natCast, coe_natCast] /-- See `ENNReal.sub_eq_of_eq_add'` for a version assuming that `a = c + b` itself is finite rather than `b`. -/ protected theorem sub_eq_of_eq_add (hb : b ≠ ∞) : a = c + b → a - b = c := (cancel_of_ne hb).tsub_eq_of_eq_add /-- Weaker version of `ENNReal.sub_eq_of_eq_add` assuming that `a = c + b` itself is finite rather han `b`. -/ protected lemma sub_eq_of_eq_add' (ha : a ≠ ∞) : a = c + b → a - b = c := (cancel_of_ne ha).tsub_eq_of_eq_add' /-- See `ENNReal.eq_sub_of_add_eq'` for a version assuming that `b = a + c` itself is finite rather than `c`. -/ protected theorem eq_sub_of_add_eq (hc : c ≠ ∞) : a + c = b → a = b - c := (cancel_of_ne hc).eq_tsub_of_add_eq /-- Weaker version of `ENNReal.eq_sub_of_add_eq` assuming that `b = a + c` itself is finite rather than `c`. -/ protected lemma eq_sub_of_add_eq' (hb : b ≠ ∞) : a + c = b → a = b - c := (cancel_of_ne hb).eq_tsub_of_add_eq' /-- See `ENNReal.sub_eq_of_eq_add_rev'` for a version assuming that `a = b + c` itself is finite rather than `b`. -/ protected theorem sub_eq_of_eq_add_rev (hb : b ≠ ∞) : a = b + c → a - b = c := (cancel_of_ne hb).tsub_eq_of_eq_add_rev /-- Weaker version of `ENNReal.sub_eq_of_eq_add_rev` assuming that `a = b + c` itself is finite rather than `b`. -/ protected lemma sub_eq_of_eq_add_rev' (ha : a ≠ ∞) : a = b + c → a - b = c := (cancel_of_ne ha).tsub_eq_of_eq_add_rev' @[simp] protected theorem add_sub_cancel_left (ha : a ≠ ∞) : a + b - a = b := (cancel_of_ne ha).add_tsub_cancel_left @[simp] protected theorem add_sub_cancel_right (hb : b ≠ ∞) : a + b - b = a := (cancel_of_ne hb).add_tsub_cancel_right protected theorem sub_add_eq_add_sub (hab : b ≤ a) (b_ne_top : b ≠ ∞) : a - b + c = a + c - b := by by_cases c_top : c = ∞ · simpa [c_top] using ENNReal.eq_sub_of_add_eq b_ne_top rfl refine ENNReal.eq_sub_of_add_eq b_ne_top ?_ simp only [add_assoc, add_comm c b] simpa only [← add_assoc] using (add_left_inj c_top).mpr <| tsub_add_cancel_of_le hab protected theorem lt_add_of_sub_lt_left (h : a ≠ ∞ ∨ b ≠ ∞) : a - b < c → a < b + c := by obtain rfl | hb := eq_or_ne b ∞ · rw [top_add, lt_top_iff_ne_top] exact fun _ => h.resolve_right (Classical.not_not.2 rfl) · exact (cancel_of_ne hb).lt_add_of_tsub_lt_left protected theorem lt_add_of_sub_lt_right (h : a ≠ ∞ ∨ c ≠ ∞) : a - c < b → a < b + c := add_comm c b ▸ ENNReal.lt_add_of_sub_lt_left h theorem le_sub_of_add_le_left (ha : a ≠ ∞) : a + b ≤ c → b ≤ c - a := (cancel_of_ne ha).le_tsub_of_add_le_left theorem le_sub_of_add_le_right (hb : b ≠ ∞) : a + b ≤ c → a ≤ c - b := (cancel_of_ne hb).le_tsub_of_add_le_right protected theorem sub_lt_of_lt_add (hac : c ≤ a) (h : a < b + c) : a - c < b := ((cancel_of_lt' <| hac.trans_lt h).tsub_lt_iff_right hac).mpr h protected theorem sub_lt_iff_lt_right (hb : b ≠ ∞) (hab : b ≤ a) : a - b < c ↔ a < c + b := (cancel_of_ne hb).tsub_lt_iff_right hab protected theorem sub_lt_self (ha : a ≠ ∞) (ha₀ : a ≠ 0) (hb : b ≠ 0) : a - b < a := (cancel_of_ne ha).tsub_lt_self (pos_iff_ne_zero.2 ha₀) (pos_iff_ne_zero.2 hb) protected theorem sub_lt_self_iff (ha : a ≠ ∞) : a - b < a ↔ 0 < a ∧ 0 < b := (cancel_of_ne ha).tsub_lt_self_iff theorem sub_lt_of_sub_lt (h₂ : c ≤ a) (h₃ : a ≠ ∞ ∨ b ≠ ∞) (h₁ : a - b < c) : a - c < b := ENNReal.sub_lt_of_lt_add h₂ (add_comm c b ▸ ENNReal.lt_add_of_sub_lt_right h₃ h₁) theorem sub_sub_cancel (h : a ≠ ∞) (h2 : b ≤ a) : a - (a - b) = b := (cancel_of_ne <| sub_ne_top h).tsub_tsub_cancel_of_le h2 theorem sub_right_inj {a b c : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≤ a) (hc : c ≤ a) : a - b = a - c ↔ b = c := (cancel_of_ne ha).tsub_right_inj (cancel_of_ne <| ne_top_of_le_ne_top ha hb) (cancel_of_ne <| ne_top_of_le_ne_top ha hc) hb hc protected theorem sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := by rcases le_or_lt a b with hab | hab; · simp [hab, mul_right_mono hab, tsub_eq_zero_of_le] rcases eq_or_lt_of_le (zero_le b) with (rfl | hb); · simp exact (cancel_of_ne <| mul_ne_top hab.ne_top (h hb hab)).tsub_mul protected theorem mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by simp only [mul_comm a] exact ENNReal.sub_mul h theorem sub_le_sub_iff_left (h : c ≤ a) (h' : a ≠ ∞) : (a - b ≤ a - c) ↔ c ≤ b := (cancel_of_ne h').tsub_le_tsub_iff_left (cancel_of_ne (ne_top_of_le_ne_top h' h)) h theorem le_toReal_sub {a b : ℝ≥0∞} (hb : b ≠ ∞) : a.toReal - b.toReal ≤ (a - b).toReal := by lift b to ℝ≥0 using hb induction a · simp · simp only [← coe_sub, NNReal.sub_def, Real.coe_toNNReal', coe_toReal] exact le_max_left _ _ @[simp] lemma toNNReal_sub (hb : b ≠ ∞) : (a - b).toNNReal = a.toNNReal - b.toNNReal := by lift b to ℝ≥0 using hb; induction a <;> simp [← coe_sub] @[simp] lemma toReal_sub_of_le (hba : b ≤ a) (ha : a ≠ ∞) : (a - b).toReal = a.toReal - b.toReal := by simp [ENNReal.toReal, ne_top_of_le_ne_top ha hba, toNNReal_mono ha hba] theorem ofReal_sub (p : ℝ) {q : ℝ} (hq : 0 ≤ q) : ENNReal.ofReal (p - q) = ENNReal.ofReal p - ENNReal.ofReal q := by obtain h | h := le_total p q · rw [ofReal_of_nonpos (sub_nonpos_of_le h), tsub_eq_zero_of_le (ofReal_le_ofReal h)] refine ENNReal.eq_sub_of_add_eq ofReal_ne_top ?_ rw [← ofReal_add (sub_nonneg_of_le h) hq, sub_add_cancel] end Sub section Interval variable {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞} protected theorem Ico_eq_Iio : Ico 0 y = Iio y := Ico_bot theorem mem_Iio_self_add : x ≠ ∞ → ε ≠ 0 → x ∈ Iio (x + ε) := fun xt ε0 => lt_add_right xt ε0 theorem mem_Ioo_self_sub_add : x ≠ ∞ → x ≠ 0 → ε₁ ≠ 0 → ε₂ ≠ 0 → x ∈ Ioo (x - ε₁) (x + ε₂) := fun xt x0 ε0 ε0' => ⟨ENNReal.sub_lt_self xt x0 ε0, lt_add_right xt ε0'⟩ @[simp] theorem image_coe_Iic (x : ℝ≥0) : (↑) '' Iic x = Iic (x : ℝ≥0∞) := WithTop.image_coe_Iic @[simp] theorem image_coe_Ici (x : ℝ≥0) : (↑) '' Ici x = Ico ↑x ∞ := WithTop.image_coe_Ici @[simp] theorem image_coe_Iio (x : ℝ≥0) : (↑) '' Iio x = Iio (x : ℝ≥0∞) := WithTop.image_coe_Iio @[simp] theorem image_coe_Ioi (x : ℝ≥0) : (↑) '' Ioi x = Ioo ↑x ∞ := WithTop.image_coe_Ioi @[simp] theorem image_coe_Icc (x y : ℝ≥0) : (↑) '' Icc x y = Icc (x : ℝ≥0∞) y := WithTop.image_coe_Icc @[simp] theorem image_coe_Ico (x y : ℝ≥0) : (↑) '' Ico x y = Ico (x : ℝ≥0∞) y := WithTop.image_coe_Ico @[simp] theorem image_coe_Ioc (x y : ℝ≥0) : (↑) '' Ioc x y = Ioc (x : ℝ≥0∞) y := WithTop.image_coe_Ioc @[simp] theorem image_coe_Ioo (x y : ℝ≥0) : (↑) '' Ioo x y = Ioo (x : ℝ≥0∞) y := WithTop.image_coe_Ioo @[simp] theorem image_coe_uIcc (x y : ℝ≥0) : (↑) '' uIcc x y = uIcc (x : ℝ≥0∞) y := by simp [uIcc] @[simp] theorem image_coe_uIoc (x y : ℝ≥0) : (↑) '' uIoc x y = uIoc (x : ℝ≥0∞) y := by simp [uIoc] @[simp] theorem image_coe_uIoo (x y : ℝ≥0) : (↑) '' uIoo x y = uIoo (x : ℝ≥0∞) y := by simp [uIoo] end Interval end ENNReal
Mathlib/Data/ENNReal/Operations.lean
520
523
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Bhavik Mehta -/ import Mathlib.Analysis.Calculus.Deriv.Support import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.MeasureTheory.Function.Jacobian import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts import Mathlib.MeasureTheory.Measure.Haar.NormedSpace import Mathlib.MeasureTheory.Measure.Haar.Unique /-! # Links between an integral and its "improper" version In its current state, mathlib only knows how to talk about definite ("proper") integrals, in the sense that it treats integrals over `[x, +∞)` the same as it treats integrals over `[y, z]`. For example, the integral over `[1, +∞)` is **not** defined to be the limit of the integral over `[1, x]` as `x` tends to `+∞`, which is known as an **improper integral**. Indeed, the "proper" definition is stronger than the "improper" one. The usual counterexample is `x ↦ sin(x)/x`, which has an improper integral over `[1, +∞)` but no definite integral. Although definite integrals have better properties, they are hardly usable when it comes to computing integrals on unbounded sets, which is much easier using limits. Thus, in this file, we prove various ways of studying the proper integral by studying the improper one. ## Definitions The main definition of this file is `MeasureTheory.AECover`. It is a rather technical definition whose sole purpose is generalizing and factoring proofs. Given an index type `ι`, a countably generated filter `l` over `ι`, and an `ι`-indexed family `φ` of subsets of a measurable space `α` equipped with a measure `μ`, one should think of a hypothesis `hφ : MeasureTheory.AECover μ l φ` as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ i, f x ∂μ` as `i` tends to `l`. When using this definition with a measure restricted to a set `s`, which happens fairly often, one should not try too hard to use a `MeasureTheory.AECover` of subsets of `s`, as it often makes proofs more complicated than necessary. See for example the proof of `MeasureTheory.integrableOn_Iic_of_intervalIntegral_norm_tendsto` where we use `(fun x ↦ oi x)` as a `MeasureTheory.AECover` w.r.t. `μ.restrict (Iic b)`, instead of using `(fun x ↦ Ioc x b)`. ## Main statements - `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is a measurable `ENNReal`-valued function, then `∫⁻ x in φ n, f x ∂μ` tends to `∫⁻ x, f x ∂μ` as `n` tends to `l` - `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, if `f` is measurable and integrable on each `φ n`, and if `∫ x in φ n, ‖f x‖ ∂μ` tends to some `I : ℝ` as n tends to `l`, then `f` is integrable - `MeasureTheory.AECover.integral_tendsto_of_countably_generated` : if `φ` is a `MeasureTheory.AECover μ l`, where `l` is a countably generated filter, and if `f` is measurable and integrable (globally), then `∫ x in φ n, f x ∂μ` tends to `∫ x, f x ∂μ` as `n` tends to `+∞`. We then specialize these lemmas to various use cases involving intervals, which are frequent in analysis. In particular, - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_tendsto` is a version of FTC-2 on the interval `(a, +∞)`, giving the formula `∫ x in (a, +∞), g' x = l - g a` if `g'` is integrable and `g` tends to `l` at `+∞`. - `MeasureTheory.integral_Ioi_of_hasDerivAt_of_nonneg` gives the same result assuming that `g'` is nonnegative instead of integrable. Its automatic integrability in this context is proved in `MeasureTheory.integrableOn_Ioi_deriv_of_nonneg`. - `MeasureTheory.integral_comp_smul_deriv_Ioi` is a version of the change of variables formula on semi-infinite intervals. - `MeasureTheory.tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi` shows that a function whose derivative is integrable on `(a, +∞)` has a limit at `+∞`. - `MeasureTheory.tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi` shows that an integrable function whose derivative is integrable on `(a, +∞)` tends to `0` at `+∞`. Versions of these results are also given on the intervals `(-∞, a]` and `(-∞, +∞)`, as well as the corresponding versions of integration by parts. -/ open MeasureTheory Filter Set TopologicalSpace Topology open scoped ENNReal NNReal namespace MeasureTheory section AECover variable {α ι : Type*} [MeasurableSpace α] (μ : Measure α) (l : Filter ι) /-- A sequence `φ` of subsets of `α` is a `MeasureTheory.AECover` w.r.t. a measure `μ` and a filter `l` if almost every point (w.r.t. `μ`) of `α` eventually belongs to `φ n` (w.r.t. `l`), and if each `φ n` is measurable. This definition is a technical way to avoid duplicating a lot of proofs. It should be thought of as a sufficient condition for being able to interpret `∫ x, f x ∂μ` (if it exists) as the limit of `∫ x in φ n, f x ∂μ` as `n` tends to `l`. See for example `MeasureTheory.AECover.lintegral_tendsto_of_countably_generated`, `MeasureTheory.AECover.integrable_of_integral_norm_tendsto` and `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ structure AECover (φ : ι → Set α) : Prop where ae_eventually_mem : ∀ᵐ x ∂μ, ∀ᶠ i in l, x ∈ φ i protected measurableSet : ∀ i, MeasurableSet <| φ i variable {μ} {l} namespace AECover /-! ## Operations on `AECover`s -/ /-- Elementwise intersection of two `AECover`s is an `AECover`. -/ theorem inter {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hψ : AECover μ l ψ) : AECover μ l (fun i ↦ φ i ∩ ψ i) where ae_eventually_mem := hψ.1.mp <| hφ.1.mono fun _ ↦ Eventually.and measurableSet _ := (hφ.2 _).inter (hψ.2 _) theorem superset {φ ψ : ι → Set α} (hφ : AECover μ l φ) (hsub : ∀ i, φ i ⊆ ψ i) (hmeas : ∀ i, MeasurableSet (ψ i)) : AECover μ l ψ := ⟨hφ.1.mono fun _x hx ↦ hx.mono fun i hi ↦ hsub i hi, hmeas⟩ theorem mono_ac {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≪ μ) : AECover ν l φ := ⟨hle hφ.1, hφ.2⟩ theorem mono {ν : Measure α} {φ : ι → Set α} (hφ : AECover μ l φ) (hle : ν ≤ μ) : AECover ν l φ := hφ.mono_ac hle.absolutelyContinuous end AECover section MetricSpace variable [PseudoMetricSpace α] [OpensMeasurableSpace α] theorem aecover_ball {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.ball x (r i)) where measurableSet _ := Metric.isOpen_ball.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ioi_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha theorem aecover_closedBall {x : α} {r : ι → ℝ} (hr : Tendsto r l atTop) : AECover μ l (fun i ↦ Metric.closedBall x (r i)) where measurableSet _ := Metric.isClosed_closedBall.measurableSet ae_eventually_mem := by filter_upwards with y filter_upwards [hr (Ici_mem_atTop (dist x y))] with a ha using by simpa [dist_comm] using ha end MetricSpace section Preorderα variable [Preorder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} theorem aecover_Ici (ha : Tendsto a l atBot) : AECover μ l fun i => Ici (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_le_atBot measurableSet _ := measurableSet_Ici theorem aecover_Iic (hb : Tendsto b l atTop) : AECover μ l fun i => Iic <| b i := aecover_Ici (α := αᵒᵈ) hb theorem aecover_Icc (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : AECover μ l fun i => Icc (a i) (b i) := (aecover_Ici ha).inter (aecover_Iic hb) end Preorderα section LinearOrderα variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) include ha in theorem aecover_Ioi [NoMinOrder α] : AECover μ l fun i => Ioi (a i) where ae_eventually_mem := ae_of_all μ ha.eventually_lt_atBot measurableSet _ := measurableSet_Ioi include hb in theorem aecover_Iio [NoMaxOrder α] : AECover μ l fun i => Iio (b i) := aecover_Ioi (α := αᵒᵈ) hb include ha hb theorem aecover_Ioo [NoMinOrder α] [NoMaxOrder α] : AECover μ l fun i => Ioo (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iio hb) theorem aecover_Ioc [NoMinOrder α] : AECover μ l fun i => Ioc (a i) (b i) := (aecover_Ioi ha).inter (aecover_Iic hb) theorem aecover_Ico [NoMaxOrder α] : AECover μ l fun i => Ico (a i) (b i) := (aecover_Ici ha).inter (aecover_Iio hb) end LinearOrderα section FiniteIntervals variable [LinearOrder α] [TopologicalSpace α] [OrderClosedTopology α] [OpensMeasurableSpace α] {a b : ι → α} {A B : α} (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) include ha in theorem aecover_Ioi_of_Ioi : AECover (μ.restrict (Ioi A)) l fun i ↦ Ioi (a i) where ae_eventually_mem := (ae_restrict_mem measurableSet_Ioi).mono fun _x hx ↦ ha.eventually <| eventually_lt_nhds hx measurableSet _ := measurableSet_Ioi include hb in theorem aecover_Iio_of_Iio : AECover (μ.restrict (Iio B)) l fun i ↦ Iio (b i) := aecover_Ioi_of_Ioi (α := αᵒᵈ) hb include ha in theorem aecover_Ioi_of_Ici : AECover (μ.restrict (Ioi A)) l fun i ↦ Ici (a i) := (aecover_Ioi_of_Ioi ha).superset (fun _ ↦ Ioi_subset_Ici_self) fun _ ↦ measurableSet_Ici include hb in theorem aecover_Iio_of_Iic : AECover (μ.restrict (Iio B)) l fun i ↦ Iic (b i) := aecover_Ioi_of_Ici (α := αᵒᵈ) hb include ha hb in theorem aecover_Ioo_of_Ioo : AECover (μ.restrict <| Ioo A B) l fun i => Ioo (a i) (b i) := ((aecover_Ioi_of_Ioi ha).mono <| Measure.restrict_mono Ioo_subset_Ioi_self le_rfl).inter ((aecover_Iio_of_Iio hb).mono <| Measure.restrict_mono Ioo_subset_Iio_self le_rfl) include ha hb in theorem aecover_Ioo_of_Icc : AECover (μ.restrict <| Ioo A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Icc_self) fun _ ↦ measurableSet_Icc include ha hb in theorem aecover_Ioo_of_Ico : AECover (μ.restrict <| Ioo A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ico_self) fun _ ↦ measurableSet_Ico include ha hb in theorem aecover_Ioo_of_Ioc : AECover (μ.restrict <| Ioo A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).superset (fun _ ↦ Ioo_subset_Ioc_self) fun _ ↦ measurableSet_Ioc variable [NoAtoms μ] theorem aecover_Ioc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ioc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ioc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ioc).ge theorem aecover_Ico_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Ico_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Ico A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Ico).ge theorem aecover_Icc_of_Icc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Icc (a i) (b i) := (aecover_Ioo_of_Icc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ico (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ico (a i) (b i) := (aecover_Ioo_of_Ico ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ioc (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioc (a i) (b i) := (aecover_Ioo_of_Ioc ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge theorem aecover_Icc_of_Ioo (ha : Tendsto a l (𝓝 A)) (hb : Tendsto b l (𝓝 B)) : AECover (μ.restrict <| Icc A B) l fun i => Ioo (a i) (b i) := (aecover_Ioo_of_Ioo ha hb).mono (Measure.restrict_congr_set Ioo_ae_eq_Icc).ge end FiniteIntervals protected theorem AECover.restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} : AECover (μ.restrict s) l φ := hφ.mono Measure.restrict_le_self theorem aecover_restrict_of_ae_imp {s : Set α} {φ : ι → Set α} (hs : MeasurableSet s) (ae_eventually_mem : ∀ᵐ x ∂μ, x ∈ s → ∀ᶠ n in l, x ∈ φ n) (measurable : ∀ n, MeasurableSet <| φ n) : AECover (μ.restrict s) l φ where ae_eventually_mem := by rwa [ae_restrict_iff' hs] measurableSet := measurable theorem AECover.inter_restrict {φ : ι → Set α} (hφ : AECover μ l φ) {s : Set α} (hs : MeasurableSet s) : AECover (μ.restrict s) l fun i => φ i ∩ s := aecover_restrict_of_ae_imp hs (hφ.ae_eventually_mem.mono fun _x hx hxs => hx.mono fun _i hi => ⟨hi, hxs⟩) fun i => (hφ.measurableSet i).inter hs theorem AECover.ae_tendsto_indicator {β : Type*} [Zero β] [TopologicalSpace β] (f : α → β) {φ : ι → Set α} (hφ : AECover μ l φ) : ∀ᵐ x ∂μ, Tendsto (fun i => (φ i).indicator f x) l (𝓝 <| f x) := hφ.ae_eventually_mem.mono fun _x hx => tendsto_const_nhds.congr' <| hx.mono fun _n hn => (indicator_of_mem hn _).symm theorem AECover.aemeasurable {β : Type*} [MeasurableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEMeasurable f (μ.restrict <| φ i)) : AEMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aemeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists theorem AECover.aestronglyMeasurable {β : Type*} [TopologicalSpace β] [PseudoMetrizableSpace β] [l.IsCountablyGenerated] [l.NeBot] {f : α → β} {φ : ι → Set α} (hφ : AECover μ l φ) (hfm : ∀ i, AEStronglyMeasurable f (μ.restrict <| φ i)) : AEStronglyMeasurable f μ := by obtain ⟨u, hu⟩ := l.exists_seq_tendsto have := aestronglyMeasurable_iUnion_iff.mpr fun n : ℕ => hfm (u n) rwa [Measure.restrict_eq_self_of_ae_mem] at this filter_upwards [hφ.ae_eventually_mem] with x hx using mem_iUnion.mpr (hu.eventually hx).exists end AECover theorem AECover.comp_tendsto {α ι ι' : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} {l' : Filter ι'} {φ : ι → Set α} (hφ : AECover μ l φ) {u : ι' → ι} (hu : Tendsto u l' l) : AECover μ l' (φ ∘ u) where ae_eventually_mem := hφ.ae_eventually_mem.mono fun _x hx => hu.eventually hx measurableSet i := hφ.measurableSet (u i) section AECoverUnionInterCountable variable {α ι : Type*} [Countable ι] [MeasurableSpace α] {μ : Measure α} theorem AECover.biUnion_Iic_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋃ (k) (_h : k ∈ Iic n), φ k := hφ.superset (fun _ ↦ subset_biUnion_of_mem right_mem_Iic) fun _ ↦ .biUnion (to_countable _) fun _ _ ↦ (hφ.2 _) theorem AECover.biInter_Ici_aecover [Preorder ι] {φ : ι → Set α} (hφ : AECover μ atTop φ) : AECover μ atTop fun n : ι => ⋂ (k) (_h : k ∈ Ici n), φ k where ae_eventually_mem := hφ.ae_eventually_mem.mono fun x h ↦ by simpa only [mem_iInter, mem_Ici, eventually_forall_ge_atTop] measurableSet _ := .biInter (to_countable _) fun n _ => hφ.measurableSet n end AECoverUnionInterCountable section Lintegral variable {α ι : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} private theorem lintegral_tendsto_of_monotone_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) (hmono : Monotone φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := let F n := (φ n).indicator f have key₁ : ∀ n, AEMeasurable (F n) μ := fun n => hfm.indicator (hφ.measurableSet n) have key₂ : ∀ᵐ x : α ∂μ, Monotone fun n => F n x := ae_of_all _ fun x _i _j hij => indicator_le_indicator_of_subset (hmono hij) (fun x => zero_le <| f x) x have key₃ : ∀ᵐ x : α ∂μ, Tendsto (fun n => F n x) atTop (𝓝 (f x)) := hφ.ae_tendsto_indicator f (lintegral_tendsto_of_tendsto_of_monotone key₁ key₂ key₃).congr fun n => lintegral_indicator (hφ.measurableSet n) _ theorem AECover.lintegral_tendsto_of_nat {φ : ℕ → Set α} (hφ : AECover μ atTop φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (∫⁻ x in φ ·, f x ∂μ) atTop (𝓝 <| ∫⁻ x, f x ∂μ) := by have lim₁ := lintegral_tendsto_of_monotone_of_nat hφ.biInter_Ici_aecover (fun i j hij => biInter_subset_biInter_left (Ici_subset_Ici.mpr hij)) hfm have lim₂ := lintegral_tendsto_of_monotone_of_nat hφ.biUnion_Iic_aecover (fun i j hij => biUnion_subset_biUnion_left (Iic_subset_Iic.mpr hij)) hfm refine tendsto_of_tendsto_of_tendsto_of_le_of_le lim₁ lim₂ (fun n ↦ ?_) fun n ↦ ?_ exacts [lintegral_mono_set (biInter_subset_of_mem left_mem_Ici), lintegral_mono_set (subset_biUnion_of_mem right_mem_Iic)] theorem AECover.lintegral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 <| ∫⁻ x, f x ∂μ) := tendsto_of_seq_tendsto fun _u hu => (hφ.comp_tendsto hu).lintegral_tendsto_of_nat hfm theorem AECover.lintegral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (I : ℝ≥0∞) (hfm : AEMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, f x ∂μ) l (𝓝 I)) : ∫⁻ x, f x ∂μ = I := tendsto_nhds_unique (hφ.lintegral_tendsto_of_countably_generated hfm) htendsto theorem AECover.iSup_lintegral_eq_of_countably_generated [Nonempty ι] [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ≥0∞} (hfm : AEMeasurable f μ) : ⨆ i : ι, ∫⁻ x in φ i, f x ∂μ = ∫⁻ x, f x ∂μ := by have := hφ.lintegral_tendsto_of_countably_generated hfm refine ciSup_eq_of_forall_le_of_forall_lt_exists_gt (fun i => lintegral_mono' Measure.restrict_le_self le_rfl) fun w hw => ?_ exact (this.eventually_const_lt hw).exists end Lintegral section Integrable variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] theorem AECover.integrable_of_lintegral_enorm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ ENNReal.ofReal I) : Integrable f μ := by refine ⟨hfm, (le_of_tendsto ?_ hbounded).trans_lt ENNReal.ofReal_lt_top⟩ exact hφ.lintegral_tendsto_of_countably_generated hfm.enorm @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_bounded := AECover.integrable_of_lintegral_enorm_bounded theorem AECover.integrable_of_lintegral_enorm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 <| .ofReal I)) : Integrable f μ := by refine hφ.integrable_of_lintegral_enorm_bounded (max 1 (I + 1)) hfm ?_ refine htendsto.eventually (ge_mem_nhds ?_) refine (ENNReal.ofReal_lt_ofReal_iff (lt_max_of_lt_left zero_lt_one)).2 ?_ exact lt_max_of_lt_right (lt_add_one I) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_tendsto := AECover.integrable_of_lintegral_enorm_tendsto theorem AECover.integrable_of_lintegral_enorm_bounded' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (hbounded : ∀ᶠ i in l, ∫⁻ x in φ i, ‖f x‖ₑ ∂μ ≤ I) : Integrable f μ := hφ.integrable_of_lintegral_enorm_bounded I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using hbounded) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_bounded' := AECover.integrable_of_lintegral_enorm_bounded' theorem AECover.integrable_of_lintegral_enorm_tendsto' [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ≥0) (hfm : AEStronglyMeasurable f μ) (htendsto : Tendsto (fun i => ∫⁻ x in φ i, ‖f x‖ₑ ∂μ) l (𝓝 I)) : Integrable f μ := hφ.integrable_of_lintegral_enorm_tendsto I hfm (by simpa only [ENNReal.ofReal_coe_nnreal] using htendsto) @[deprecated (since := "2025-01-22")] alias AECover.integrable_of_lintegral_nnnorm_tendsto' := AECover.integrable_of_lintegral_enorm_tendsto' theorem AECover.integrable_of_integral_norm_bounded [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hbounded : ∀ᶠ i in l, (∫ x in φ i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hfm : AEStronglyMeasurable f μ := hφ.aestronglyMeasurable fun i => (hfi i).aestronglyMeasurable refine hφ.integrable_of_lintegral_enorm_bounded I hfm ?_ conv at hbounded in integral _ _ => rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun x => @norm_nonneg E _ (f x)) hfm.norm.restrict] conv at hbounded in ENNReal.ofReal _ => rw [← coe_nnnorm, ENNReal.ofReal_coe_nnreal] refine hbounded.mono fun i hi => ?_ rw [← ENNReal.ofReal_toReal <| ne_top_of_lt <| hasFiniteIntegral_iff_enorm.mp (hfi i).2] apply ENNReal.ofReal_le_ofReal hi theorem AECover.integrable_of_integral_norm_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (htendsto : Tendsto (fun i => ∫ x in φ i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_norm_bounded I' hfi hI' theorem AECover.integrable_of_integral_bounded_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (hbounded : ∀ᶠ i in l, (∫ x in φ i, f x ∂μ) ≤ I) : Integrable f μ := hφ.integrable_of_integral_norm_bounded I hfi <| hbounded.mono fun _i hi => (integral_congr_ae <| ae_restrict_of_ae <| hnng.mono fun _ => Real.norm_of_nonneg).le.trans hi theorem AECover.integrable_of_integral_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hfi : ∀ i, IntegrableOn f (φ i) μ) (hnng : ∀ᵐ x ∂μ, 0 ≤ f x) (htendsto : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := htendsto.isBoundedUnder_le hφ.integrable_of_integral_bounded_of_nonneg_ae I' hfi hnng hI' end Integrable section Integral variable {α ι E : Type*} [MeasurableSpace α] {μ : Measure α} {l : Filter ι} [NormedAddCommGroup E] [NormedSpace ℝ E] theorem AECover.integral_tendsto_of_countably_generated [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (hfi : Integrable f μ) : Tendsto (fun i => ∫ x in φ i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := suffices h : Tendsto (fun i => ∫ x : α, (φ i).indicator f x ∂μ) l (𝓝 (∫ x : α, f x ∂μ)) from by convert h using 2; rw [integral_indicator (hφ.measurableSet _)] tendsto_integral_filter_of_dominated_convergence (fun x => ‖f x‖) (Eventually.of_forall fun i => hfi.aestronglyMeasurable.indicator <| hφ.measurableSet i) (Eventually.of_forall fun _ => ae_of_all _ fun _ => norm_indicator_le_norm_self _ _) hfi.norm (hφ.ae_tendsto_indicator f) /-- Slight reformulation of `MeasureTheory.AECover.integral_tendsto_of_countably_generated`. -/ theorem AECover.integral_eq_of_tendsto [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → E} (I : E) (hfi : Integrable f μ) (h : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := tendsto_nhds_unique (hφ.integral_tendsto_of_countably_generated hfi) h theorem AECover.integral_eq_of_tendsto_of_nonneg_ae [l.NeBot] [l.IsCountablyGenerated] {φ : ι → Set α} (hφ : AECover μ l φ) {f : α → ℝ} (I : ℝ) (hnng : 0 ≤ᵐ[μ] f) (hfi : ∀ n, IntegrableOn f (φ n) μ) (htendsto : Tendsto (fun n => ∫ x in φ n, f x ∂μ) l (𝓝 I)) : ∫ x, f x ∂μ = I := have hfi' : Integrable f μ := hφ.integrable_of_integral_tendsto_of_nonneg_ae I hfi hnng htendsto hφ.integral_eq_of_tendsto I hfi' htendsto end Integral section IntegrableOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [Filter.NeBot l] [IsCountablyGenerated l] [NormedAddCommGroup E] {a b : ι → ℝ} {f : ℝ → E} theorem integrable_of_intervalIntegral_norm_bounded (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a i..b i, ‖f x‖ ∂μ) ≤ I) : Integrable f μ := by have hφ : AECover μ l _ := aecover_Ioc ha hb refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi ht rwa [← intervalIntegral.integral_of_le (hai.trans hbi)] /-- If `f` is integrable on intervals `Ioc (a i) (b i)`, where `a i` tends to -∞ and `b i` tends to ∞, and `∫ x in a i .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, ∞) -/ theorem integrable_of_intervalIntegral_norm_tendsto (I : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) (b i)) μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a i..b i, ‖f x‖ ∂μ) l (𝓝 I)) : Integrable f μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrable_of_intervalIntegral_norm_bounded I' hfi ha hb hI' theorem integrableOn_Iic_of_intervalIntegral_norm_bounded (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : ∀ᶠ i in l, (∫ x in a i..b, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Iic b) μ := by have hφ : AECover (μ.restrict <| Iic b) l _ := aecover_Ioi ha have hfi : ∀ i, IntegrableOn f (Ioi (a i)) (μ.restrict <| Iic b) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i)] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [ha.eventually (eventually_le_atBot b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] exact id /-- If `f` is integrable on intervals `Ioc (a i) b`, where `a i` tends to -∞, and `∫ x in a i .. b, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (-∞, b) -/ theorem integrableOn_Iic_of_intervalIntegral_norm_tendsto (I b : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc (a i) b) μ) (ha : Tendsto a l atBot) (h : Tendsto (fun i => ∫ x in a i..b, ‖f x‖ ∂μ) l (𝓝 I)) : IntegrableOn f (Iic b) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Iic_of_intervalIntegral_norm_bounded I' b hfi ha hI' theorem integrableOn_Ioi_of_intervalIntegral_norm_bounded (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : ∀ᶠ i in l, (∫ x in a..b i, ‖f x‖ ∂μ) ≤ I) : IntegrableOn f (Ioi a) μ := by have hφ : AECover (μ.restrict <| Ioi a) l _ := aecover_Iic hb have hfi : ∀ i, IntegrableOn f (Iic (b i)) (μ.restrict <| Ioi a) := by intro i rw [IntegrableOn, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact hfi i refine hφ.integrable_of_integral_norm_bounded I hfi (h.mp ?_) filter_upwards [hb.eventually (eventually_ge_atTop a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] exact id /-- If `f` is integrable on intervals `Ioc a (b i)`, where `b i` tends to ∞, and `∫ x in a .. b i, ‖f x‖ ∂μ` converges to `I : ℝ` along a filter `l`, then `f` is integrable on the interval (a, ∞) -/ theorem integrableOn_Ioi_of_intervalIntegral_norm_tendsto (I a : ℝ) (hfi : ∀ i, IntegrableOn f (Ioc a (b i)) μ) (hb : Tendsto b l atTop) (h : Tendsto (fun i => ∫ x in a..b i, ‖f x‖ ∂μ) l (𝓝 <| I)) : IntegrableOn f (Ioi a) μ := let ⟨I', hI'⟩ := h.isBoundedUnder_le integrableOn_Ioi_of_intervalIntegral_norm_bounded I' a hfi hb hI' theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded {I a₀ b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) (b i)) (ha : Tendsto a l <| 𝓝 a₀) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b₀) := by refine (aecover_Ioc_of_Ioc ha hb).integrable_of_integral_norm_bounded I (fun i => (hfi i).restrict) (h.mono fun i hi ↦ ?_) rw [Measure.restrict_restrict measurableSet_Ioc] refine le_trans (setIntegral_mono_set (hfi i).norm ?_ ?_) hi <;> apply ae_of_all · simp only [Pi.zero_apply, norm_nonneg, forall_const] · intro c hc; exact hc.1 theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_left {I a₀ b : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc (a i) b) (ha : Tendsto a l <| 𝓝 a₀) (h : ∀ᶠ i in l, (∫ x in Ioc (a i) b, ‖f x‖) ≤ I) : IntegrableOn f (Ioc a₀ b) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi ha tendsto_const_nhds h theorem integrableOn_Ioc_of_intervalIntegral_norm_bounded_right {I a b₀ : ℝ} (hfi : ∀ i, IntegrableOn f <| Ioc a (b i)) (hb : Tendsto b l <| 𝓝 b₀) (h : ∀ᶠ i in l, (∫ x in Ioc a (b i), ‖f x‖) ≤ I) : IntegrableOn f (Ioc a b₀) := integrableOn_Ioc_of_intervalIntegral_norm_bounded hfi tendsto_const_nhds hb h end IntegrableOfIntervalIntegral section IntegralOfIntervalIntegral variable {ι E : Type*} {μ : Measure ℝ} {l : Filter ι} [IsCountablyGenerated l] [NormedAddCommGroup E] [NormedSpace ℝ E] {a b : ι → ℝ} {f : ℝ → E} theorem intervalIntegral_tendsto_integral (hfi : Integrable f μ) (ha : Tendsto a l atBot) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a i..b i, f x ∂μ) l (𝓝 <| ∫ x, f x ∂μ) := by let φ i := Ioc (a i) (b i) have hφ : AECover μ l φ := aecover_Ioc ha hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot 0), hb.eventually (eventually_ge_atTop 0)] with i hai hbi exact (intervalIntegral.integral_of_le (hai.trans hbi)).symm theorem intervalIntegral_tendsto_integral_Iic (b : ℝ) (hfi : IntegrableOn f (Iic b) μ) (ha : Tendsto a l atBot) : Tendsto (fun i => ∫ x in a i..b, f x ∂μ) l (𝓝 <| ∫ x in Iic b, f x ∂μ) := by let φ i := Ioi (a i) have hφ : AECover (μ.restrict <| Iic b) l φ := aecover_Ioi ha refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [ha.eventually (eventually_le_atBot <| b)] with i hai rw [intervalIntegral.integral_of_le hai, Measure.restrict_restrict (hφ.measurableSet i)] rfl theorem intervalIntegral_tendsto_integral_Ioi (a : ℝ) (hfi : IntegrableOn f (Ioi a) μ) (hb : Tendsto b l atTop) : Tendsto (fun i => ∫ x in a..b i, f x ∂μ) l (𝓝 <| ∫ x in Ioi a, f x ∂μ) := by let φ i := Iic (b i) have hφ : AECover (μ.restrict <| Ioi a) l φ := aecover_Iic hb refine (hφ.integral_tendsto_of_countably_generated hfi).congr' ?_ filter_upwards [hb.eventually (eventually_ge_atTop <| a)] with i hbi rw [intervalIntegral.integral_of_le hbi, Measure.restrict_restrict (hφ.measurableSet i), inter_comm] rfl end IntegralOfIntervalIntegral open Real open scoped Interval section IoiFTC variable {E : Type*} {f f' : ℝ → E} {g g' : ℝ → ℝ} {a l : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `+∞`, then the function has a limit at `+∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi [CompleteSpace E] (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) : Tendsto f atTop (𝓝 (limUnder atTop f)) := by suffices ∃ a, Tendsto f atTop (𝓝 a) from tendsto_nhds_limUnder this suffices CauchySeq f from cauchySeq_tendsto_of_complete this apply Metric.cauchySeq_iff'.2 (fun ε εpos ↦ ?_) have A : ∀ᶠ (n : ℕ) in atTop, ∫ (x : ℝ) in Ici ↑n, ‖f' x‖ < ε := by have L : Tendsto (fun (n : ℕ) ↦ ∫ x in Ici (n : ℝ), ‖f' x‖) atTop (𝓝 (∫ x in ⋂ (n : ℕ), Ici (n : ℝ), ‖f' x‖)) := by apply tendsto_setIntegral_of_antitone (fun n ↦ measurableSet_Ici) · intro m n hmn exact Ici_subset_Ici.2 (Nat.cast_le.mpr hmn) · rcases exists_nat_gt a with ⟨n, hn⟩ exact ⟨n, IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 hn)⟩ have B : ⋂ (n : ℕ), Ici (n : ℝ) = ∅ := by apply eq_empty_of_forall_not_mem (fun x ↦ ?_) simpa only [mem_iInter, mem_Ici, not_forall, not_le] using exists_nat_gt x simp only [B, Measure.restrict_empty, integral_zero_measure] at L exact (tendsto_order.1 L).2 _ εpos have B : ∀ᶠ (n : ℕ) in atTop, a < n := by rcases exists_nat_gt a with ⟨n, hn⟩ filter_upwards [Ioi_mem_atTop n] with m (hm : n < m) using hn.trans (Nat.cast_lt.mpr hm) rcases (A.and B).exists with ⟨N, hN, h'N⟩ refine ⟨N, fun x hx ↦ ?_⟩ calc dist (f x) (f ↑N) = ‖f x - f N‖ := dist_eq_norm _ _ _ = ‖∫ t in Ioc ↑N x, f' t‖ := by rw [← intervalIntegral.integral_of_le hx, intervalIntegral.integral_eq_sub_of_hasDerivAt] · intro y hy simp only [hx, uIcc_of_le, mem_Icc] at hy exact hderiv _ (h'N.trans_le hy.1) · rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono_set (Ioc_subset_Ioi_self.trans (Ioi_subset_Ioi h'N.le)) _ ≤ ∫ t in Ioc ↑N x, ‖f' t‖ := norm_integral_le_integral_norm fun a ↦ f' a _ ≤ ∫ t in Ici ↑N, ‖f' t‖ := by apply setIntegral_mono_set · apply IntegrableOn.mono_set f'int.norm (Ici_subset_Ioi.2 h'N) · filter_upwards with x using norm_nonneg _ · have : Ioc (↑N) x ⊆ Ici ↑N := Ioc_subset_Ioi_self.trans Ioi_subset_Ici_self exact this.eventuallyLE _ < ε := hN open UniformSpace in /-- If a function and its derivative are integrable on `(a, +∞)`, then the function tends to zero at `+∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (fint : IntegrableOn f (Ioi a)) : Tendsto f atTop (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Ioi a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx) have Fint : IntegrableOn (F ∘ f) (Ioi a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Ioi a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atTop (𝓝 (limUnder atTop (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi Fderiv F'int have B : limUnder atTop (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atTop := by exact ⟨Ioi a, Ioi_mem_atTop _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atTop_sets.1 hs with ⟨b, hb⟩ rw [← top_le_iff, ← volume_Ici (a := b)] exact measure_mono hb rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A exact (Completion.isUniformEmbedding_coe E).isEmbedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_Ioi_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by have hcont : ContinuousOn f (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Ioi a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact f'int.mono (fun y hy => hy.1) le_rfl /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(a, +∞)`. When a function has a limit at infinity `m`, and its derivative is integrable, then the integral of the derivative on `(a, +∞)` is `m - f a`. Version assuming differentiability on `[a, +∞)`. Note that such a function always has a limit at infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_Ioi_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Ici a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Ioi a)) (hf : Tendsto f atTop (𝓝 m)) : ∫ x in Ioi a, f' x = m - f a := by refine integral_Ioi_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le) f'int hf exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt /-- A special case of `integral_Ioi_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with compact support. -/ theorem _root_.HasCompactSupport.integral_Ioi_deriv_eq (hf : ContDiff ℝ 1 f) (h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Ioi b, deriv f x = - f b := by have := fun x (_ : x ∈ Ioi b) ↦ hf.differentiable le_rfl x |>.hasDerivAt rw [integral_Ioi_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, zero_sub] · refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f exact h2f.filter_mono _root_.atTop_le_cocompact |>.tendsto /-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integrableOn_Ioi_deriv_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by have hcont : ContinuousOn g (Ici a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine integrableOn_Ioi_of_intervalIntegral_norm_tendsto (l - g a) a (fun x => ?_) tendsto_id ?_ · exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self) (fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1 apply Tendsto.congr' _ (hg.sub_const _) filter_upwards [Ioi_mem_atTop a] with x hx have h'x : a ≤ id x := le_of_lt hx calc g x - g a = ∫ y in a..id x, g' y := by symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le h'x (hcont.mono Icc_subset_Ici_self) fun y hy => hderiv y hy.1 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le h'x] exact intervalIntegral.integrableOn_deriv_of_nonneg (hcont.mono Icc_subset_Ici_self) (fun y hy => hderiv y hy.1) fun y hy => g'pos y hy.1 _ = ∫ y in a..id x, ‖g' y‖ := by simp_rw [intervalIntegral.integral_of_le h'x] refine setIntegral_congr_fun measurableSet_Ioc fun y hy => ?_ dsimp rw [abs_of_nonneg] exact g'pos _ hy.1 /-- When a function has a limit at infinity, and its derivative is nonnegative, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `[a, +∞)`. -/ theorem integrableOn_Ioi_deriv_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by refine integrableOn_Ioi_deriv_of_nonneg ?_ (fun x hx => hderiv x hx.out.le) g'pos hg exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt /-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonneg (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv (integrableOn_Ioi_deriv_of_nonneg hcont hderiv g'pos hg) hg /-- When a function has a limit at infinity `l`, and its derivative is nonnegative, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonneg' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'pos : ∀ x ∈ Ioi a, 0 ≤ g' x) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonneg' hderiv g'pos hg) hg /-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integrableOn_Ioi_deriv_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by apply integrable_neg_iff.1 exact integrableOn_Ioi_deriv_of_nonneg hcont.neg (fun x hx => (hderiv x hx).neg) (fun x hx => neg_nonneg_of_nonpos (g'neg x hx)) hg.neg /-- When a function has a limit at infinity, and its derivative is nonpositive, then the derivative is automatically integrable on `(a, +∞)`. Version assuming differentiability on `[a, +∞)`. -/ theorem integrableOn_Ioi_deriv_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : IntegrableOn g' (Ioi a) := by refine integrableOn_Ioi_deriv_of_nonpos ?_ (fun x hx ↦ hderiv x hx.out.le) g'neg hg exact (hderiv a left_mem_Ici).continuousAt.continuousWithinAt /-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg`). Version assuming differentiability on `(a, +∞)` and continuity at `a⁺`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonpos (hcont : ContinuousWithinAt g (Ici a) a) (hderiv : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto hcont hderiv (integrableOn_Ioi_deriv_of_nonpos hcont hderiv g'neg hg) hg /-- When a function has a limit at infinity `l`, and its derivative is nonpositive, then the integral of the derivative on `(a, +∞)` is `l - g a` (and the derivative is integrable, see `integrable_on_Ioi_deriv_of_nonneg'`). Version assuming differentiability on `[a, +∞)`. -/ theorem integral_Ioi_of_hasDerivAt_of_nonpos' (hderiv : ∀ x ∈ Ici a, HasDerivAt g (g' x) x) (g'neg : ∀ x ∈ Ioi a, g' x ≤ 0) (hg : Tendsto g atTop (𝓝 l)) : ∫ x in Ioi a, g' x = l - g a := integral_Ioi_of_hasDerivAt_of_tendsto' hderiv (integrableOn_Ioi_deriv_of_nonpos' hderiv g'neg hg) hg end IoiFTC section IicFTC variable {E : Type*} {f f' : ℝ → E} {a : ℝ} {m : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- If the derivative of a function defined on the real line is integrable close to `-∞`, then the function has a limit at `-∞`. -/ theorem tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic [CompleteSpace E] (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) : Tendsto f atBot (𝓝 (limUnder atBot f)) := by suffices ∃ a, Tendsto f atBot (𝓝 a) from tendsto_nhds_limUnder this let g := f ∘ (fun x ↦ -x) have hdg : ∀ x ∈ Ioi (-a), HasDerivAt g (-f' (-x)) x := by intro x hx have : -x ∈ Iic a := by simp only [mem_Iic, mem_Ioi, neg_le] at *; exact hx.le simpa using HasDerivAt.scomp x (hderiv (-x) this) (hasDerivAt_neg' x) have L : Tendsto g atTop (𝓝 (limUnder atTop g)) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi hdg exact ((MeasurePreserving.integrableOn_comp_preimage (Measure.measurePreserving_neg _) (Homeomorph.neg ℝ).measurableEmbedding).2 f'int.neg).mono_set (by simp) refine ⟨limUnder atTop g, ?_⟩ have : Tendsto (fun x ↦ g (-x)) atBot (𝓝 (limUnder atTop g)) := L.comp tendsto_neg_atBot_atTop simpa [g] using this open UniformSpace in /-- If a function and its derivative are integrable on `(-∞, a]`, then the function tends to zero at `-∞`. -/ theorem tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (fint : IntegrableOn f (Iic a)) : Tendsto f atBot (𝓝 0) := by let F : E →L[ℝ] Completion E := Completion.toComplL have Fderiv : ∀ x ∈ Iic a, HasDerivAt (F ∘ f) (F (f' x)) x := fun x hx ↦ F.hasFDerivAt.comp_hasDerivAt _ (hderiv x hx) have Fint : IntegrableOn (F ∘ f) (Iic a) := by apply F.integrable_comp fint have F'int : IntegrableOn (F ∘ f') (Iic a) := by apply F.integrable_comp f'int have A : Tendsto (F ∘ f) atBot (𝓝 (limUnder atBot (F ∘ f))) := by apply tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic Fderiv F'int have B : limUnder atBot (F ∘ f) = F 0 := by have : IntegrableAtFilter (F ∘ f) atBot := by exact ⟨Iic a, Iic_mem_atBot _, Fint⟩ apply IntegrableAtFilter.eq_zero_of_tendsto this ?_ A intro s hs rcases mem_atBot_sets.1 hs with ⟨b, hb⟩ apply le_antisymm (le_top) rw [← volume_Iic (a := b)] exact measure_mono hb rwa [B, ← IsEmbedding.tendsto_nhds_iff] at A exact (Completion.isUniformEmbedding_coe E).isEmbedding variable [CompleteSpace E] /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`. When a function has a limit `m` at `-∞`, and its derivative is integrable, then the integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability on `(-∞, a)` and continuity at `a⁻`. Note that such a function always has a limit at minus infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/ theorem integral_Iic_of_hasDerivAt_of_tendsto (hcont : ContinuousWithinAt f (Iic a) a) (hderiv : ∀ x ∈ Iio a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by have hcont : ContinuousOn f (Iic a) := by intro x hx rcases hx.out.eq_or_lt with rfl|hx · exact hcont · exact (hderiv x hx).continuousAt.continuousWithinAt refine tendsto_nhds_unique (intervalIntegral_tendsto_integral_Iic a f'int tendsto_id) ?_ apply Tendsto.congr' _ (hf.const_sub _) filter_upwards [Iic_mem_atBot a] with x hx symm apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hx (hcont.mono Icc_subset_Iic_self) fun y hy => hderiv y hy.2 rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hx] exact f'int.mono (fun y hy => hy.2) le_rfl /-- **Fundamental theorem of calculus-2**, on semi-infinite intervals `(-∞, a)`. When a function has a limit `m` at `-∞`, and its derivative is integrable, then the integral of the derivative on `(-∞, a)` is `f a - m`. Version assuming differentiability on `(-∞, a]`. Note that such a function always has a limit at minus infinity, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic`. -/ theorem integral_Iic_of_hasDerivAt_of_tendsto' (hderiv : ∀ x ∈ Iic a, HasDerivAt f (f' x) x) (f'int : IntegrableOn f' (Iic a)) (hf : Tendsto f atBot (𝓝 m)) : ∫ x in Iic a, f' x = f a - m := by refine integral_Iic_of_hasDerivAt_of_tendsto ?_ (fun x hx => hderiv x hx.out.le) f'int hf exact (hderiv a right_mem_Iic).continuousAt.continuousWithinAt /-- A special case of `integral_Iic_of_hasDerivAt_of_tendsto` where we assume that `f` is C^1 with compact support. -/ theorem _root_.HasCompactSupport.integral_Iic_deriv_eq (hf : ContDiff ℝ 1 f) (h2f : HasCompactSupport f) (b : ℝ) : ∫ x in Iic b, deriv f x = f b := by have := fun x (_ : x ∈ Iio b) ↦ hf.differentiable le_rfl x |>.hasDerivAt rw [integral_Iic_of_hasDerivAt_of_tendsto hf.continuous.continuousWithinAt this, sub_zero] · refine hf.continuous_deriv le_rfl |>.integrable_of_hasCompactSupport h2f.deriv |>.integrableOn rw [hasCompactSupport_iff_eventuallyEq, Filter.coclosedCompact_eq_cocompact] at h2f exact h2f.filter_mono _root_.atBot_le_cocompact |>.tendsto open UniformSpace in lemma _root_.HasCompactSupport.enorm_le_lintegral_Ici_deriv {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] {f : ℝ → F} (hf : ContDiff ℝ 1 f) (h'f : HasCompactSupport f) (x : ℝ) : ‖f x‖ₑ ≤ ∫⁻ y in Iic x, ‖deriv f y‖ₑ := by let I : F →L[ℝ] Completion F := Completion.toComplL let f' : ℝ → Completion F := I ∘ f have hf' : ContDiff ℝ 1 f' := hf.continuousLinearMap_comp I have h'f' : HasCompactSupport f' := h'f.comp_left rfl have : ‖f' x‖ₑ ≤ ∫⁻ y in Iic x, ‖deriv f' y‖ₑ := by rw [← HasCompactSupport.integral_Iic_deriv_eq hf' h'f' x] exact enorm_integral_le_lintegral_enorm _ convert this with y · simp [f', I, Completion.enorm_coe] · rw [fderiv_comp_deriv _ I.differentiableAt (hf.differentiable le_rfl _)] simp only [ContinuousLinearMap.fderiv] simp [I] @[deprecated (since := "2025-01-22")] alias _root_.HasCompactSupport.ennnorm_le_lintegral_Ici_deriv := HasCompactSupport.enorm_le_lintegral_Ici_deriv end IicFTC section UnivFTC variable {E : Type*} {f f' : ℝ → E} {m n : E} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- **Fundamental theorem of calculus-2**, on the whole real line When a function has a limit `m` at `-∞` and `n` at `+∞`, and its derivative is integrable, then the integral of the derivative is `n - m`. Note that such a function always has a limit at `-∞` and `+∞`, see `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Iic` and `tendsto_limUnder_of_hasDerivAt_of_integrableOn_Ioi`. -/ theorem integral_of_hasDerivAt_of_tendsto [CompleteSpace E] (hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f') (hbot : Tendsto f atBot (𝓝 m)) (htop : Tendsto f atTop (𝓝 n)) : ∫ x, f' x = n - m := by rw [← setIntegral_univ, ← Set.Iic_union_Ioi (a := 0), setIntegral_union (Iic_disjoint_Ioi le_rfl) measurableSet_Ioi hf'.integrableOn hf'.integrableOn, integral_Iic_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn hbot, integral_Ioi_of_hasDerivAt_of_tendsto' (fun x _ ↦ hderiv x) hf'.integrableOn htop] abel /-- If a function and its derivative are integrable on the real line, then the integral of the derivative is zero. -/ theorem integral_eq_zero_of_hasDerivAt_of_integrable (hderiv : ∀ x, HasDerivAt f (f' x) x) (hf' : Integrable f') (hf : Integrable f) : ∫ x, f' x = 0 := by by_cases hE : CompleteSpace E; swap · simp [integral, hE] have A : Tendsto f atBot (𝓝 0) := tendsto_zero_of_hasDerivAt_of_integrableOn_Iic (a := 0) (fun x _hx ↦ hderiv x) hf'.integrableOn hf.integrableOn have B : Tendsto f atTop (𝓝 0) := tendsto_zero_of_hasDerivAt_of_integrableOn_Ioi (a := 0) (fun x _hx ↦ hderiv x) hf'.integrableOn hf.integrableOn simpa using integral_of_hasDerivAt_of_tendsto hderiv hf' A B end UnivFTC section IoiChangeVariables open Real open scoped Interval variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-- Change-of-variables formula for `Ioi` integrals of vector-valued functions, proved by taking limits from the result for finite intervals. -/ theorem integral_comp_smul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → E} {a : ℝ} (hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop) (hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x) (hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a) (hg2 : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a)) : (∫ x in Ioi a, f' x • (g ∘ f) x) = ∫ u in Ioi (f a), g u := by have eq : ∀ b : ℝ, a < b → (∫ x in a..b, f' x • (g ∘ f) x) = ∫ u in f a..f b, g u := fun b hb ↦ by have i1 : Ioo (min a b) (max a b) ⊆ Ioi a := by rw [min_eq_left hb.le] exact Ioo_subset_Ioi_self have i2 : [[a, b]] ⊆ Ici a := by rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self refine intervalIntegral.integral_comp_smul_deriv''' (hf.mono i2) (fun x hx => hff' x <| mem_of_mem_of_subset hx i1) (hg_cont.mono <| image_subset _ ?_) (hg1.mono_set <| image_subset _ ?_) (hg2.mono_set i2) · rw [min_eq_left hb.le]; exact Ioo_subset_Ioi_self · rw [uIcc_of_le hb.le]; exact Icc_subset_Ici_self rw [integrableOn_Ici_iff_integrableOn_Ioi] at hg2 have t2 := intervalIntegral_tendsto_integral_Ioi _ hg2 tendsto_id have : Ioi (f a) ⊆ f '' Ici a := Ioi_subset_Ici_self.trans <| IsPreconnected.intermediate_value_Ici isPreconnected_Ici left_mem_Ici (le_principal_iff.mpr <| Ici_mem_atTop _) hf hft have t1 := (intervalIntegral_tendsto_integral_Ioi _ (hg1.mono_set this) tendsto_id).comp hft exact tendsto_nhds_unique (Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop a) eq) t2) t1 /-- Change-of-variables formula for `Ioi` integrals of scalar-valued functions -/ theorem integral_comp_mul_deriv_Ioi {f f' : ℝ → ℝ} {g : ℝ → ℝ} {a : ℝ} (hf : ContinuousOn f <| Ici a) (hft : Tendsto f atTop atTop) (hff' : ∀ x ∈ Ioi a, HasDerivWithinAt f (f' x) (Ioi x) x) (hg_cont : ContinuousOn g <| f '' Ioi a) (hg1 : IntegrableOn g <| f '' Ici a) (hg2 : IntegrableOn (fun x => (g ∘ f) x * f' x) (Ici a)) : (∫ x in Ioi a, (g ∘ f) x * f' x) = ∫ u in Ioi (f a), g u := by have hg2' : IntegrableOn (fun x => f' x • (g ∘ f) x) (Ici a) := by simpa [mul_comm] using hg2 simpa [mul_comm] using integral_comp_smul_deriv_Ioi hf hft hff' hg_cont hg1 hg2' /-- Substitution `y = x ^ p` in integrals over `Ioi 0` -/ theorem integral_comp_rpow_Ioi (g : ℝ → E) {p : ℝ} (hp : p ≠ 0) : (∫ x in Ioi 0, (|p| * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by let S := Ioi (0 : ℝ) have a1 : ∀ x : ℝ, x ∈ S → HasDerivWithinAt (fun t : ℝ => t ^ p) (p * x ^ (p - 1)) S x := fun x hx => (hasDerivAt_rpow_const (Or.inl (mem_Ioi.mp hx).ne')).hasDerivWithinAt have a2 : InjOn (fun x : ℝ => x ^ p) S := by rcases lt_or_gt_of_ne hp with (h | h) · apply StrictAntiOn.injOn intro x hx y hy hxy rw [← inv_lt_inv₀ (rpow_pos_of_pos hx p) (rpow_pos_of_pos hy p), ← rpow_neg (le_of_lt hx), ← rpow_neg (le_of_lt hy)] exact rpow_lt_rpow (le_of_lt hx) hxy (neg_pos.mpr h) exact StrictMonoOn.injOn fun x hx y _ hxy => rpow_lt_rpow (mem_Ioi.mp hx).le hxy h have a3 : (fun t : ℝ => t ^ p) '' S = S := by ext1 x; rw [mem_image]; constructor · rintro ⟨y, hy, rfl⟩; exact rpow_pos_of_pos hy p · intro hx; refine ⟨x ^ (1 / p), rpow_pos_of_pos hx _, ?_⟩ rw [← rpow_mul (le_of_lt hx), one_div_mul_cancel hp, rpow_one] have := integral_image_eq_integral_abs_deriv_smul measurableSet_Ioi a1 a2 g rw [a3] at this; rw [this] refine setIntegral_congr_fun measurableSet_Ioi ?_ intro x hx; dsimp only
rw [abs_mul, abs_of_nonneg (rpow_nonneg (le_of_lt hx) _)] theorem integral_comp_rpow_Ioi_of_pos {g : ℝ → E} {p : ℝ} (hp : 0 < p) : (∫ x in Ioi 0, (p * x ^ (p - 1)) • g (x ^ p)) = ∫ y in Ioi 0, g y := by convert integral_comp_rpow_Ioi g hp.ne' rw [abs_of_nonneg hp.le] theorem integral_comp_mul_left_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) : (∫ x in Ioi a, g (b * x)) = b⁻¹ • ∫ x in Ioi (b * a), g x := by have : ∀ c : ℝ, MeasurableSet (Ioi c) := fun c => measurableSet_Ioi rw [← integral_indicator (this a), ← integral_indicator (this (b * a)), ← abs_of_pos (inv_pos.mpr hb), ← Measure.integral_comp_mul_left] congr ext1 x rw [← indicator_comp_right, preimage_const_mul_Ioi _ hb, mul_div_cancel_left₀ _ hb.ne'] rfl theorem integral_comp_mul_right_Ioi (g : ℝ → E) (a : ℝ) {b : ℝ} (hb : 0 < b) : (∫ x in Ioi a, g (x * b)) = b⁻¹ • ∫ x in Ioi (a * b), g x := by simpa only [mul_comm] using integral_comp_mul_left_Ioi g a hb end IoiChangeVariables section IoiIntegrability
Mathlib/MeasureTheory/Integral/IntegralEqImproper.lean
1,093
1,117
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded import Mathlib.Order.Hom.CompleteLattice /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ limsup u f := limsInf_le_limsSup h h' theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _ @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (Eventually.of_forall fun _ => le_rfl) /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u)) theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u)) /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp] theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1) /-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any `a : α` is a fixed point. -/ theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) : f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop := (CompleteLatticeHom.dual f).apply_limsup_iterate _ variable {f g : Filter β} {p q : β → Prop} {u v : β → α} theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q := sInf_le_sInf fun a ha => ha.mono <| by tauto theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p :=
sSup_le_sSup fun a ha => ha.mono <| by tauto theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p :=
Mathlib/Order/LiminfLimsup.lean
507
509
/- 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, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.Data.Finite.Sum import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Fin import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Basis.SMul import Mathlib.LinearAlgebra.Matrix.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.RingTheory.Ideal.Span /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ι`, `κ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ι → M₁` and `v₂ : κ → M₂`, the `R`-linear equivalence from `M₁ →ₗ[R] M₂` to `Matrix κ ι R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m → R) →ₗ[R] (n → R)` to `Matrix m n R` (with the standard basis on `m → R` and `n → R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n → R) →ₗ[Rᵐᵒᵖ] (m → R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] (n → R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᵐᵒᵖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m → R) →ₗ[R] n → R where toFun x := x ᵥ* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m → R) : M.vecMulLinear x = x ᵥ* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ → _) = M.vecMul := rfl variable [Fintype m] theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M.row) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R M.row := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply, row_def] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ · rw [← h0] ext i simp [vecMul, dotProduct] · rw [← h0] ext j simp [vecMul, dotProduct] lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by rw [← Matrix.vecMul_injective_iff] exact Matrix.vecMul_injective_of_isUnit ha section variable [DecidableEq m] /-- Linear maps `(m → R) →ₗ[R] (n → R)` are linearly equivalent over `Rᵐᵒᵖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m → R) →ₗ[R] n → R) ≃ₗ[Rᵐᵒᵖ] Matrix m n R where toFun f i j := f (single R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent over `Rᵐᵒᵖ` to a linear map `(m → R) →ₗ[R] (n → R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᵐᵒᵖ] (m → R) →ₗ[R] n → R := LinearEquiv.symm LinearMap.toMatrixRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m → R) : (Matrix.toLinearMapRight') M v = v ᵥ* M := rfl @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [Module.End.one_apply] /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n → A` and `m → A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n → R) ≃ₗ[R] m → R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } end end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᵐᵒᵖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n → R) →ₗ[R] m → R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ → _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n → R) : M.mulVecLin v = M *ᵥ v := rfl @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mᵀ.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mᵀ.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m → k) (e₂ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ e₂).mulVecLin = funLeft R R f₁ ∘ₗ M.mulVecLin ∘ₗ funLeft _ _ e₂.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (e₂ : l ≃ n) (M : Matrix k l R) : (reindex e₁ e₂ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) ∘ₗ M.mulVecLin ∘ₗ ↑(LinearEquiv.funCongrLeft R R e₂) := Matrix.mulVecLin_submatrix _ _ _ variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm] @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = ⊥ ↔ ∀ v, M *ᵥ v = 0 → v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range M.col) := by rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose] theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R M.col := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose] lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.col := by rw [← Matrix.mulVec_injective_iff] exact Matrix.mulVec_injective_of_isUnit ha end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n → R) →ₗ[R] (m → R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n → R) →ₗ[R] m → R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (Pi.single j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply]
left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i
Mathlib/LinearAlgebra/Matrix/ToLin.lean
288
290
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Alex Keizer -/ import Mathlib.Algebra.Group.Nat.Even import Mathlib.Algebra.NeZero import Mathlib.Algebra.Ring.Nat import Mathlib.Data.List.GetD import Mathlib.Data.Nat.Bits import Mathlib.Order.Basic import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.Common /-! # Bitwise operations on natural numbers In the first half of this file, we provide theorems for reasoning about natural numbers from their bitwise properties. In the second half of this file, we show properties of the bitwise operations `lor`, `land` and `xor`, which are defined in core. ## Main results * `eq_of_testBit_eq`: two natural numbers are equal if they have equal bits at every position. * `exists_most_significant_bit`: if `n ≠ 0`, then there is some position `i` that contains the most significant `1`-bit of `n`. * `lt_of_testBit`: if `n` and `m` are numbers and `i` is a position such that the `i`-th bit of of `n` is zero, the `i`-th bit of `m` is one, and all more significant bits are equal, then `n < m`. ## Future work There is another way to express bitwise properties of natural number: `digits 2`. The two ways should be connected. ## Keywords bitwise, and, or, xor -/ open Function namespace Nat section variable {f : Bool → Bool → Bool} @[simp] lemma bitwise_zero_left (m : Nat) : bitwise f 0 m = if f false true then m else 0 := by simp [bitwise] @[simp] lemma bitwise_zero_right (n : Nat) : bitwise f n 0 = if f true false then n else 0 := by unfold bitwise simp only [ite_self, decide_false, Nat.zero_div, ite_true, ite_eq_right_iff] rintro ⟨⟩ split_ifs <;> rfl lemma bitwise_zero : bitwise f 0 0 = 0 := by simp only [bitwise_zero_right, ite_self] lemma bitwise_of_ne_zero {n m : Nat} (hn : n ≠ 0) (hm : m ≠ 0) : bitwise f n m = bit (f (bodd n) (bodd m)) (bitwise f (n / 2) (m / 2)) := by conv_lhs => unfold bitwise have mod_two_iff_bod x : (x % 2 = 1 : Bool) = bodd x := by simp only [mod_two_of_bodd, cond]; cases bodd x <;> rfl simp only [hn, hm, mod_two_iff_bod, ite_false, bit, two_mul, Bool.cond_eq_ite] theorem binaryRec_of_ne_zero {C : Nat → Sort*} (z : C 0) (f : ∀ b n, C n → C (bit b n)) {n} (h : n ≠ 0) : binaryRec z f n = bit_decomp n ▸ f (bodd n) (div2 n) (binaryRec z f (div2 n)) := by cases n using bitCasesOn with | h b n => rw [binaryRec_eq _ _ (by right; simpa [bit_eq_zero_iff] using h)] generalize_proofs h; revert h rw [bodd_bit, div2_bit] simp @[simp] lemma bitwise_bit {f : Bool → Bool → Bool} (h : f false false = false := by rfl) (a m b n) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise simp only [bit, ite_apply, Bool.cond_eq_ite] have h4 x : (x + x + 1) / 2 = x := by rw [← two_mul, add_comm]; simp [add_mul_div_left] cases a <;> cases b <;> simp [h4] <;> split_ifs <;> simp_all +decide [two_mul] lemma bit_mod_two_eq_zero_iff (a x) : bit a x % 2 = 0 ↔ !a := by simp lemma bit_mod_two_eq_one_iff (a x) : bit a x % 2 = 1 ↔ a := by simp @[simp] theorem lor_bit : ∀ a m b n, bit a m ||| bit b n = bit (a || b) (m ||| n) := bitwise_bit @[simp] theorem land_bit : ∀ a m b n, bit a m &&& bit b n = bit (a && b) (m &&& n) := bitwise_bit @[simp] theorem ldiff_bit : ∀ a m b n, ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) := bitwise_bit @[simp] theorem xor_bit : ∀ a m b n, bit a m ^^^ bit b n = bit (bne a b) (m ^^^ n) := bitwise_bit attribute [simp] Nat.testBit_bitwise theorem testBit_lor : ∀ m n k, testBit (m ||| n) k = (testBit m k || testBit n k) := testBit_bitwise rfl theorem testBit_land : ∀ m n k, testBit (m &&& n) k = (testBit m k && testBit n k) := testBit_bitwise rfl @[simp] theorem testBit_ldiff : ∀ m n k, testBit (ldiff m n) k = (testBit m k && not (testBit n k)) := testBit_bitwise rfl attribute [simp] testBit_xor end @[simp] theorem bit_false : bit false = (2 * ·) := rfl @[simp] theorem bit_true : bit true = (2 * · + 1) := rfl theorem bit_ne_zero_iff {n : ℕ} {b : Bool} : n.bit b ≠ 0 ↔ n = 0 → b = true := by simp /-- An alternative for `bitwise_bit` which replaces the `f false false = false` assumption with assumptions that neither `bit a m` nor `bit b n` are `0` (albeit, phrased as the implications `m = 0 → a = true` and `n = 0 → b = true`) -/ lemma bitwise_bit' {f : Bool → Bool → Bool} (a : Bool) (m : Nat) (b : Bool) (n : Nat) (ham : m = 0 → a = true) (hbn : n = 0 → b = true) : bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by conv_lhs => unfold bitwise rw [← bit_ne_zero_iff] at ham hbn simp only [ham, hbn, bit_mod_two_eq_one_iff, Bool.decide_coe, ← div2_val, div2_bit, ne_eq, ite_false] conv_rhs => simp only [bit, two_mul, Bool.cond_eq_ite] lemma bitwise_eq_binaryRec (f : Bool → Bool → Bool) : bitwise f = binaryRec (fun n => cond (f false true) n 0) fun a m Ia => binaryRec (cond (f true false) (bit a m) 0) fun b n _ => bit (f a b) (Ia n) := by funext x y induction x using binaryRec' generalizing y with | z => simp only [bitwise_zero_left, binaryRec_zero, Bool.cond_eq_ite] | f xb x hxb ih => rw [← bit_ne_zero_iff] at hxb simp_rw [binaryRec_of_ne_zero _ _ hxb, bodd_bit, div2_bit, eq_rec_constant] induction y using binaryRec' with | z => simp only [bitwise_zero_right, binaryRec_zero, Bool.cond_eq_ite] | f yb y hyb => rw [← bit_ne_zero_iff] at hyb simp_rw [binaryRec_of_ne_zero _ _ hyb, bitwise_of_ne_zero hxb hyb, bodd_bit, ← div2_val, div2_bit, eq_rec_constant, ih] theorem zero_of_testBit_eq_false {n : ℕ} (h : ∀ i, testBit n i = false) : n = 0 := by induction n using Nat.binaryRec with | z => rfl | f b n hn => ?_ have : b = false := by simpa using h 0 rw [this, bit_false, hn fun i => by rw [← h (i + 1), testBit_bit_succ]] theorem testBit_eq_false_of_lt {n i} (h : n < 2 ^ i) : n.testBit i = false := by simp [testBit, shiftRight_eq_div_pow, Nat.div_eq_of_lt h] /-- The ith bit is the ith element of `n.bits`. -/ theorem testBit_eq_inth (n i : ℕ) : n.testBit i = n.bits.getI i := by induction i generalizing n with | zero => simp only [testBit, zero_eq, shiftRight_zero, one_and_eq_mod_two, mod_two_of_bodd, bodd_eq_bits_head, List.getI_zero_eq_headI] cases List.headI (bits n) <;> rfl | succ i ih => conv_lhs => rw [← bit_decomp n] rw [testBit_bit_succ, ih n.div2, div2_bits_eq_tail] cases n.bits <;> simp theorem exists_most_significant_bit {n : ℕ} (h : n ≠ 0) : ∃ i, testBit n i = true ∧ ∀ j, i < j → testBit n j = false := by induction n using Nat.binaryRec with | z => exact False.elim (h rfl) | f b n hn => ?_ by_cases h' : n = 0 · subst h' rw [show b = true by revert h cases b <;> simp] refine ⟨0, ⟨by rw [testBit_bit_zero], fun j hj => ?_⟩⟩ obtain ⟨j', rfl⟩ := exists_eq_succ_of_ne_zero (ne_of_gt hj) rw [testBit_bit_succ, zero_testBit] · obtain ⟨k, ⟨hk, hk'⟩⟩ := hn h' refine ⟨k + 1, ⟨by rw [testBit_bit_succ, hk], fun j hj => ?_⟩⟩ obtain ⟨j', rfl⟩ := exists_eq_succ_of_ne_zero (show j ≠ 0 by intro x; subst x; simp at hj) exact (testBit_bit_succ _ _ _).trans (hk' _ (lt_of_succ_lt_succ hj)) theorem lt_of_testBit {n m : ℕ} (i : ℕ) (hn : testBit n i = false) (hm : testBit m i = true) (hnm : ∀ j, i < j → testBit n j = testBit m j) : n < m := by induction n using Nat.binaryRec generalizing i m with | z => rw [Nat.pos_iff_ne_zero] rintro rfl simp at hm | f b n hn' => induction m using Nat.binaryRec generalizing i with | z => exact False.elim (Bool.false_ne_true ((zero_testBit i).symm.trans hm)) | f b' m hm' => by_cases hi : i = 0 · subst hi simp only [testBit_bit_zero] at hn hm have : n = m := eq_of_testBit_eq fun i => by convert hnm (i + 1) (Nat.zero_lt_succ _) using 1 <;> rw [testBit_bit_succ] rw [hn, hm, this, bit_false, bit_true] exact Nat.lt_succ_self _ · obtain ⟨i', rfl⟩ := exists_eq_succ_of_ne_zero hi simp only [testBit_bit_succ] at hn hm have := hn' _ hn hm fun j hj => by convert hnm j.succ (succ_lt_succ hj) using 1 <;> rw [testBit_bit_succ] have this' : 2 * n < 2 * m := Nat.mul_lt_mul_of_le_of_lt (le_refl _) this Nat.two_pos cases b <;> cases b' <;> simp only [bit_false, bit_true] · exact this' · exact Nat.lt_add_right 1 this' · calc 2 * n + 1 < 2 * n + 2 := lt.base _ _ ≤ 2 * m := mul_le_mul_left 2 this · exact Nat.succ_lt_succ this' theorem bitwise_swap {f : Bool → Bool → Bool} : bitwise (Function.swap f) = Function.swap (bitwise f) := by funext m n simp only [Function.swap] induction m using Nat.strongRecOn generalizing n with | ind m ih => ?_ rcases m with - | m <;> rcases n with - | n <;> try rw [bitwise_zero_left, bitwise_zero_right] · specialize ih ((m+1) / 2) (div_lt_self' ..) simp [bitwise_of_ne_zero, ih] /-- If `f` is a commutative operation on bools such that `f false false = false`, then `bitwise f` is also commutative. -/ theorem bitwise_comm {f : Bool → Bool → Bool} (hf : ∀ b b', f b b' = f b' b) (n m : ℕ) : bitwise f n m = bitwise f m n := suffices bitwise f = swap (bitwise f) by conv_lhs => rw [this] calc bitwise f = bitwise (swap f) := congr_arg _ <| funext fun _ => funext <| hf _ _ = swap (bitwise f) := bitwise_swap theorem lor_comm (n m : ℕ) : n ||| m = m ||| n := bitwise_comm Bool.or_comm n m theorem land_comm (n m : ℕ) : n &&& m = m &&& n := bitwise_comm Bool.and_comm n m lemma and_two_pow (n i : ℕ) : n &&& 2 ^ i = (n.testBit i).toNat * 2 ^ i := by refine eq_of_testBit_eq fun j => ?_ obtain rfl | hij := Decidable.eq_or_ne i j <;> cases h : n.testBit i · simp [h] · simp [h] · simp [h, testBit_two_pow_of_ne hij] · simp [h, testBit_two_pow_of_ne hij] lemma two_pow_and (n i : ℕ) : 2 ^ i &&& n = 2 ^ i * (n.testBit i).toNat := by rw [mul_comm, land_comm, and_two_pow] /-- Proving associativity of bitwise operations in general essentially boils down to a huge case distinction, so it is shorter to use this tactic instead of proving it in the general case. -/ macro "bitwise_assoc_tac" : tactic => set_option hygiene false in `(tactic| ( induction n using Nat.binaryRec generalizing m k with | z => simp | f b n hn => ?_ induction m using Nat.binaryRec with | z => simp | f b' m hm => ?_ induction k using Nat.binaryRec <;> simp [hn, Bool.or_assoc, Bool.and_assoc, Bool.bne_eq_xor])) theorem land_assoc (n m k : ℕ) : (n &&& m) &&& k = n &&& (m &&& k) := by bitwise_assoc_tac theorem lor_assoc (n m k : ℕ) : (n ||| m) ||| k = n ||| (m ||| k) := by bitwise_assoc_tac -- These lemmas match `mul_inv_cancel_right` and `mul_inv_cancel_left`. theorem xor_cancel_right (n m : ℕ) : (m ^^^ n) ^^^ n = m := by rw [Nat.xor_assoc, Nat.xor_self, xor_zero] theorem xor_cancel_left (n m : ℕ) : n ^^^ (n ^^^ m) = m := by rw [← Nat.xor_assoc, Nat.xor_self, zero_xor] theorem xor_right_injective {n : ℕ} : Function.Injective (HXor.hXor n : ℕ → ℕ) := fun m m' h => by rw [← xor_cancel_left n m, ← xor_cancel_left n m', h] theorem xor_left_injective {n : ℕ} : Function.Injective fun m => m ^^^ n := fun m m' (h : m ^^^ n = m' ^^^ n) => by rw [← xor_cancel_right n m, ← xor_cancel_right n m', h] @[simp] theorem xor_right_inj {n m m' : ℕ} : n ^^^ m = n ^^^ m' ↔ m = m' := xor_right_injective.eq_iff @[simp] theorem xor_left_inj {n m m' : ℕ} : m ^^^ n = m' ^^^ n ↔ m = m' := xor_left_injective.eq_iff @[simp] theorem xor_eq_zero {n m : ℕ} : n ^^^ m = 0 ↔ n = m := by rw [← Nat.xor_self n, xor_right_inj, eq_comm] theorem xor_ne_zero {n m : ℕ} : n ^^^ m ≠ 0 ↔ n ≠ m := xor_eq_zero.not theorem xor_trichotomy {a b c : ℕ} (h : a ^^^ b ^^^ c ≠ 0) : b ^^^ c < a ∨ c ^^^ a < b ∨ a ^^^ b < c := by set v := a ^^^ b ^^^ c with hv -- The xor of any two of `a`, `b`, `c` is the xor of `v` and the third. have hab : a ^^^ b = c ^^^ v := by rw [Nat.xor_comm c, xor_cancel_right] have hbc : b ^^^ c = a ^^^ v := by rw [← Nat.xor_assoc, xor_cancel_left] have hca : c ^^^ a = b ^^^ v := by rw [hv, Nat.xor_assoc, Nat.xor_comm a, ← Nat.xor_assoc, xor_cancel_left] -- If `i` is the position of the most significant bit of `v`, then at least one of `a`, `b`, `c` -- has a one bit at position `i`. obtain ⟨i, ⟨hi, hi'⟩⟩ := exists_most_significant_bit h have : testBit a i ∨ testBit b i ∨ testBit c i := by contrapose! hi simp_rw [Bool.eq_false_eq_not_eq_true] at hi ⊢ rw [testBit_xor, testBit_xor, hi.1, hi.2.1, hi.2.2] rfl -- If, say, `a` has a one bit at position `i`, then `a xor v` has a zero bit at position `i`, but -- the same bits as `a` in positions greater than `j`, so `a xor v < a`. obtain h | h | h := this on_goal 1 => left; rw [hbc] on_goal 2 => right; left; rw [hca] on_goal 3 => right; right; rw [hab] all_goals refine lt_of_testBit i ?_ h fun j hj => ?_ · rw [testBit_xor, h, hi] rfl · simp only [testBit_xor, hi' _ hj, Bool.bne_false] theorem lt_xor_cases {a b c : ℕ} (h : a < b ^^^ c) : a ^^^ c < b ∨ a ^^^ b < c := by obtain ha | hb | hc := xor_trichotomy <| Nat.xor_assoc _ _ _ ▸ xor_ne_zero.2 h.ne exacts [(h.asymm ha).elim, Or.inl <| Nat.xor_comm _ _ ▸ hb, Or.inr hc] @[simp] theorem xor_mod_two_eq {m n : ℕ} : (m ^^^ n) % 2 = (m + n) % 2 := by by_cases h : (m + n) % 2 = 0 · simp only [h, mod_two_eq_zero_iff_testBit_zero, testBit_zero, xor_mod_two_eq_one, decide_not, Bool.decide_iff_dist, Bool.not_eq_false', beq_iff_eq, decide_eq_decide] omega · simp only [mod_two_ne_zero] at h simp only [h, xor_mod_two_eq_one] omega @[simp] theorem even_xor {m n : ℕ} : Even (m ^^^ n) ↔ (Even m ↔ Even n) := by simp only [even_iff, xor_mod_two_eq] omega @[simp] theorem bit_lt_two_pow_succ_iff {b x n} : bit b x < 2 ^ (n + 1) ↔ x < 2 ^ n := by cases b <;> simp <;> omega @[deprecated bitwise_lt_two_pow (since := "2024-12-28")] alias bitwise_lt := bitwise_lt_two_pow lemma shiftLeft_lt {x n m : ℕ} (h : x < 2 ^ n) : x <<< m < 2 ^ (n + m) := by simp only [Nat.pow_add, shiftLeft_eq, Nat.mul_lt_mul_right (Nat.two_pow_pos _), h] /-- Note that the LHS is the expression used within `Std.BitVec.append`, hence the name. -/ lemma append_lt {x y n m} (hx : x < 2 ^ n) (hy : y < 2 ^ m) : y <<< n ||| x < 2 ^ (n + m) := by apply bitwise_lt_two_pow · rw [add_comm]; apply shiftLeft_lt hy · apply lt_of_lt_of_le hx <| Nat.pow_le_pow_right (le_succ _) (le_add_right _ _) end Nat
Mathlib/Data/Nat/Bitwise.lean
469
482
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudryashov, Yaël Dillies -/ import Mathlib.Algebra.Order.Invertible import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.LinearAlgebra.AffineSpace.Midpoint import Mathlib.LinearAlgebra.LinearIndependent.Lemmas import Mathlib.LinearAlgebra.Ray import Mathlib.Tactic.GCongr /-! # Segments in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `segment 𝕜 x y`: Closed segment joining `x` and `y`. * `openSegment 𝕜 x y`: Open segment joining `x` and `y`. ## Notations We provide the following notation: * `[x -[𝕜] y] = segment 𝕜 x y` in locale `Convex` ## TODO Generalize all this file to affine spaces. Should we rename `segment` and `openSegment` to `convex.Icc` and `convex.Ioo`? Should we also define `clopenSegment`/`convex.Ico`/`convex.Ioc`? -/ variable {𝕜 E F G ι : Type*} {M : ι → Type*} open Function Set open Pointwise Convex section OrderedSemiring variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] section SMul variable (𝕜) [SMul 𝕜 E] {s : Set E} {x y : E} /-- Segments in a vector space. -/ def segment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a • x + b • y = z } /-- Open segment in a vector space. Note that `openSegment 𝕜 x x = {x}` instead of being `∅` when the base semiring has some element between `0` and `1`. Denoted as `[x -[𝕜] y]` within the `Convex` namespace. -/ def openSegment (x y : E) : Set E := { z : E | ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a • x + b • y = z } @[inherit_doc] scoped[Convex] notation (priority := high) "[" x " -[" 𝕜 "] " y "]" => segment 𝕜 x y theorem segment_eq_image₂ (x y : E) : [x -[𝕜] y] = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1 } := by simp only [segment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem openSegment_eq_image₂ (x y : E) : openSegment 𝕜 x y = (fun p : 𝕜 × 𝕜 => p.1 • x + p.2 • y) '' { p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1 } := by simp only [openSegment, image, Prod.exists, mem_setOf_eq, exists_prop, and_assoc] theorem segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_symm (x y : E) : openSegment 𝕜 x y = openSegment 𝕜 y x := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, fun ⟨a, b, ha, hb, hab, H⟩ => ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ theorem openSegment_subset_segment (x y : E) : openSegment 𝕜 x y ⊆ [x -[𝕜] y] := fun _ ⟨a, b, ha, hb, hab, hz⟩ => ⟨a, b, ha.le, hb.le, hab, hz⟩ theorem segment_subset_iff : [x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ theorem openSegment_subset_iff : openSegment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := ⟨fun H a b ha hb hab => H ⟨a, b, ha, hb, hab, rfl⟩, fun H _ ⟨a, b, ha, hb, hab, hz⟩ => hz ▸ H a b ha hb hab⟩ end SMul open Convex section MulActionWithZero variable (𝕜) variable [ZeroLEOneClass 𝕜] [MulActionWithZero 𝕜 E] theorem left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] := ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩ theorem right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] := segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x end MulActionWithZero section Module variable (𝕜) variable [ZeroLEOneClass 𝕜] [Module 𝕜 E] {s : Set E} {x y z : E} @[simp] theorem segment_same (x : E) : [x -[𝕜] x] = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h => mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩ theorem insert_endpoints_openSegment (x y : E) : insert x (insert y (openSegment 𝕜 x y)) = [x -[𝕜] y] := by simp only [subset_antisymm_iff, insert_subset_iff, left_mem_segment, right_mem_segment, openSegment_subset_segment, true_and] rintro z ⟨a, b, ha, hb, hab, rfl⟩ refine hb.eq_or_gt.imp ?_ fun hb' => ha.eq_or_gt.imp ?_ fun ha' => ?_ · rintro rfl rw [← add_zero a, hab, one_smul, zero_smul, add_zero] · rintro rfl rw [← zero_add b, hab, one_smul, zero_smul, zero_add] · exact ⟨a, b, ha', hb', hab, rfl⟩ variable {𝕜} theorem mem_openSegment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) : z ∈ openSegment 𝕜 x y := by rw [← insert_endpoints_openSegment] at hz exact (hz.resolve_left hx.symm).resolve_left hy.symm theorem openSegment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) : openSegment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s := by simp only [← insert_endpoints_openSegment, insert_subset_iff, *, true_and] end Module end OrderedSemiring open Convex section OrderedRing variable (𝕜) [Ring 𝕜] [PartialOrder 𝕜] [AddRightMono 𝕜] [AddCommGroup E] [AddCommGroup F] [AddCommGroup G] [Module 𝕜 E] [Module 𝕜 F] section DenselyOrdered variable [ZeroLEOneClass 𝕜] [Nontrivial 𝕜] [DenselyOrdered 𝕜] @[simp] theorem openSegment_same (x : E) : openSegment 𝕜 x x = {x} := Set.ext fun z => ⟨fun ⟨a, b, _, _, hab, hz⟩ => by simpa only [← add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz, fun h : z = x => by obtain ⟨a, ha₀, ha₁⟩ := DenselyOrdered.dense (0 : 𝕜) 1 zero_lt_one refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel _ _, ?_⟩ rw [← add_smul, add_sub_cancel, one_smul, h]⟩ end DenselyOrdered theorem segment_eq_image (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem openSegment_eq_image (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 := Set.ext fun _ => ⟨fun ⟨a, b, ha, hb, hab, hz⟩ => ⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel_right]⟩, fun ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩ => ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ theorem segment_eq_image' (x y : E) : [x -[𝕜] y] = (fun θ : 𝕜 => x + θ • (y - x)) '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem openSegment_eq_image' (x y : E) : openSegment 𝕜 x y = (fun θ : 𝕜 => x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 simp only [smul_sub, sub_smul, one_smul] abel theorem segment_eq_image_lineMap (x y : E) : [x -[𝕜] y] = AffineMap.lineMap x y '' Icc (0 : 𝕜) 1 := by convert segment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ theorem openSegment_eq_image_lineMap (x y : E) : openSegment 𝕜 x y = AffineMap.lineMap x y '' Ioo (0 : 𝕜) 1 := by convert openSegment_eq_image 𝕜 x y using 2 exact AffineMap.lineMap_apply_module _ _ _ @[simp] theorem image_segment (f : E →ᵃ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] := Set.ext fun x => by simp_rw [segment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem image_openSegment (f : E →ᵃ[𝕜] F) (a b : E) : f '' openSegment 𝕜 a b = openSegment 𝕜 (f a) (f b) := Set.ext fun x => by simp_rw [openSegment_eq_image_lineMap, mem_image, exists_exists_and_eq_and, AffineMap.apply_lineMap] @[simp] theorem vadd_segment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ [b -[𝕜] c] = [a +ᵥ b -[𝕜] a +ᵥ c] := image_segment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem vadd_openSegment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) : a +ᵥ openSegment 𝕜 b c = openSegment 𝕜 (a +ᵥ b) (a +ᵥ c) := image_openSegment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c @[simp] theorem mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] := by simp_rw [← vadd_eq_add, ← vadd_segment, vadd_mem_vadd_set_iff] @[simp] theorem mem_openSegment_translate (a : E) {x b c : E} : a + x ∈ openSegment 𝕜 (a + b) (a + c) ↔ x ∈ openSegment 𝕜 b c := by simp_rw [← vadd_eq_add, ← vadd_openSegment, vadd_mem_vadd_set_iff]
theorem segment_translate_preimage (a b c : E) : (fun x => a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] := Set.ext fun _ => mem_segment_translate 𝕜 a
Mathlib/Analysis/Convex/Segment.lean
240
244
/- Copyright (c) 2014 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.Basic import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d e : α} {m n : ℤ} /-! ### Relating two divisions. -/ @[deprecated div_le_div_iff_of_pos_right (since := "2024-11-12")] theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := div_le_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_right (since := "2024-11-12")] theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := div_lt_div_iff_of_pos_right hc @[deprecated div_lt_div_iff_of_pos_left (since := "2024-11-13")] theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := div_lt_div_iff_of_pos_left ha hb hc @[deprecated div_le_div_iff_of_pos_left (since := "2024-11-12")] theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := div_le_div_iff_of_pos_left ha hb hc @[deprecated div_lt_div_iff₀ (since := "2024-11-12")] theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := div_lt_div_iff₀ b0 d0 @[deprecated div_le_div_iff₀ (since := "2024-11-12")] theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := div_le_div_iff₀ b0 d0 @[deprecated div_le_div₀ (since := "2024-11-12")] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := div_le_div₀ hc hac hd hbd @[deprecated div_lt_div₀ (since := "2024-11-12")] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := div_lt_div₀ hac hbd c0 d0 @[deprecated div_lt_div₀' (since := "2024-11-12")] theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := div_lt_div₀' hac hbd c0 d0 /-! ### Relating one division and involving `1` -/ @[bound] theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb @[bound] theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb @[bound] theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by rw [le_div_iff₀ hb, one_mul] theorem div_le_one (hb : 0 < b) : a / b ≤ 1 ↔ a ≤ b := by rw [div_le_iff₀ hb, one_mul] theorem one_lt_div (hb : 0 < b) : 1 < a / b ↔ b < a := by rw [lt_div_iff₀ hb, one_mul] theorem div_lt_one (hb : 0 < b) : a / b < 1 ↔ a < b := by rw [div_lt_iff₀ hb, one_mul] theorem one_div_le (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_comm₀ ha hb theorem one_div_lt (ha : 0 < a) (hb : 0 < b) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_comm₀ ha hb theorem le_one_div (ha : 0 < a) (hb : 0 < b) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_comm₀ ha hb theorem lt_one_div (ha : 0 < a) (hb : 0 < b) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_comm₀ ha hb @[bound] lemma Bound.one_lt_div_of_pos_of_lt (b0 : 0 < b) : b < a → 1 < a / b := (one_lt_div b0).mpr @[bound] lemma Bound.div_lt_one_of_pos_of_lt (b0 : 0 < b) : a < b → a / b < 1 := (div_lt_one b0).mpr /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_le (ha : 0 < a) (h : a ≤ b) : 1 / b ≤ 1 / a := by simpa using inv_anti₀ ha h theorem one_div_lt_one_div_of_lt (ha : 0 < a) (h : a < b) : 1 / b < 1 / a := by rwa [lt_div_iff₀' ha, ← div_eq_mul_one_div, div_lt_one (ha.trans h)] theorem le_of_one_div_le_one_div (ha : 0 < a) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_lt ha) h theorem lt_of_one_div_lt_one_div (ha : 0 < a) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_le ha) h /-- For the single implications with fewer assumptions, see `one_div_le_one_div_of_le` and `le_of_one_div_le_one_div` -/ theorem one_div_le_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a ≤ 1 / b ↔ b ≤ a := div_le_div_iff_of_pos_left zero_lt_one ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div (ha : 0 < a) (hb : 0 < b) : 1 / a < 1 / b ↔ b < a := div_lt_div_iff_of_pos_left zero_lt_one ha hb theorem one_lt_one_div (h1 : 0 < a) (h2 : a < 1) : 1 < 1 / a := by rwa [lt_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] theorem one_le_one_div (h1 : 0 < a) (h2 : a ≤ 1) : 1 ≤ 1 / a := by rwa [le_one_div (@zero_lt_one α _ _ _ _ _) h1, one_div_one] /-! ### Results about halving. The equalities also hold in semifields of characteristic `0`. -/ theorem half_pos (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two theorem one_half_pos : (0 : α) < 1 / 2 := half_pos zero_lt_one @[simp] theorem half_le_self_iff : a / 2 ≤ a ↔ 0 ≤ a := by rw [div_le_iff₀ (zero_lt_two' α), mul_two, le_add_iff_nonneg_left] @[simp] theorem half_lt_self_iff : a / 2 < a ↔ 0 < a := by rw [div_lt_iff₀ (zero_lt_two' α), mul_two, lt_add_iff_pos_left] alias ⟨_, half_le_self⟩ := half_le_self_iff alias ⟨_, half_lt_self⟩ := half_lt_self_iff alias div_two_lt_of_pos := half_lt_self theorem one_half_lt_one : (1 / 2 : α) < 1 := half_lt_self zero_lt_one theorem two_inv_lt_one : (2⁻¹ : α) < 1 := (one_div _).symm.trans_lt one_half_lt_one theorem left_lt_add_div_two : a < (a + b) / 2 ↔ a < b := by simp [lt_div_iff₀, mul_two] theorem add_div_two_lt_right : (a + b) / 2 < b ↔ a < b := by simp [div_lt_iff₀, mul_two] theorem add_thirds (a : α) : a / 3 + a / 3 + a / 3 = a := by rw [div_add_div_same, div_add_div_same, ← two_mul, ← add_one_mul 2 a, two_add_one_eq_three, mul_div_cancel_left₀ a three_ne_zero] /-! ### Miscellaneous lemmas -/ @[simp] lemma div_pos_iff_of_pos_left (ha : 0 < a) : 0 < a / b ↔ 0 < b := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_left ha, inv_pos] @[simp] lemma div_pos_iff_of_pos_right (hb : 0 < b) : 0 < a / b ↔ 0 < a := by simp only [div_eq_mul_inv, mul_pos_iff_of_pos_right (inv_pos.2 hb)] theorem mul_le_mul_of_mul_div_le (h : a * (b / c) ≤ d) (hc : 0 < c) : b * a ≤ d * c := by rw [← mul_div_assoc] at h rwa [mul_comm b, ← div_le_iff₀ hc] theorem div_mul_le_div_mul_of_div_le_div (h : a / b ≤ c / d) (he : 0 ≤ e) : a / (b * e) ≤ c / (d * e) := by rw [div_mul_eq_div_mul_one_div, div_mul_eq_div_mul_one_div] exact mul_le_mul_of_nonneg_right h (one_div_nonneg.2 he) theorem exists_pos_mul_lt {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b * c < a := by have : 0 < a / max (b + 1) 1 := div_pos h (lt_max_iff.2 (Or.inr zero_lt_one)) refine ⟨a / max (b + 1) 1, this, ?_⟩ rw [← lt_div_iff₀ this, div_div_cancel₀ h.ne'] exact lt_max_iff.2 (Or.inl <| lt_add_one _) theorem exists_pos_lt_mul {a : α} (h : 0 < a) (b : α) : ∃ c : α, 0 < c ∧ b < c * a := let ⟨c, hc₀, hc⟩ := exists_pos_mul_lt h b; ⟨c⁻¹, inv_pos.2 hc₀, by rwa [← div_eq_inv_mul, lt_div_iff₀ hc₀]⟩ lemma monotone_div_right_of_nonneg (ha : 0 ≤ a) : Monotone (· / a) := fun _b _c hbc ↦ div_le_div_of_nonneg_right hbc ha lemma strictMono_div_right_of_pos (ha : 0 < a) : StrictMono (· / a) := fun _b _c hbc ↦ div_lt_div_of_pos_right hbc ha theorem Monotone.div_const {β : Type*} [Preorder β] {f : β → α} (hf : Monotone f) {c : α} (hc : 0 ≤ c) : Monotone fun x => f x / c := (monotone_div_right_of_nonneg hc).comp hf theorem StrictMono.div_const {β : Type*} [Preorder β] {f : β → α} (hf : StrictMono f) {c : α} (hc : 0 < c) : StrictMono fun x => f x / c := by simpa only [div_eq_mul_inv] using hf.mul_const (inv_pos.2 hc) -- see Note [lower instance priority] instance (priority := 100) LinearOrderedSemiField.toDenselyOrdered : DenselyOrdered α where dense a₁ a₂ h := ⟨(a₁ + a₂) / 2, calc a₁ = (a₁ + a₁) / 2 := (add_self_div_two a₁).symm _ < (a₁ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_left h _) zero_lt_two , calc (a₁ + a₂) / 2 < (a₂ + a₂) / 2 := div_lt_div_of_pos_right (add_lt_add_right h _) zero_lt_two _ = a₂ := add_self_div_two a₂ ⟩ theorem min_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : min (a / c) (b / c) = min a b / c := (monotone_div_right_of_nonneg hc).map_min.symm theorem max_div_div_right {c : α} (hc : 0 ≤ c) (a b : α) : max (a / c) (b / c) = max a b / c := (monotone_div_right_of_nonneg hc).map_max.symm theorem one_div_strictAntiOn : StrictAntiOn (fun x : α => 1 / x) (Set.Ioi 0) := fun _ x1 _ y1 xy => (one_div_lt_one_div (Set.mem_Ioi.mp y1) (Set.mem_Ioi.mp x1)).mpr xy theorem one_div_pow_le_one_div_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : 1 / a ^ n ≤ 1 / a ^ m := by refine (one_div_le_one_div ?_ ?_).mpr (pow_right_mono₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans_le a1) _ theorem one_div_pow_lt_one_div_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : 1 / a ^ n < 1 / a ^ m := by refine (one_div_lt_one_div ?_ ?_).2 (pow_lt_pow_right₀ a1 mn) <;> exact pow_pos (zero_lt_one.trans a1) _ theorem one_div_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_le_one_div_pow_of_le a1 theorem one_div_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => 1 / a ^ n := fun _ _ => one_div_pow_lt_one_div_pow_of_lt a1 theorem inv_strictAntiOn : StrictAntiOn (fun x : α => x⁻¹) (Set.Ioi 0) := fun _ hx _ hy xy => (inv_lt_inv₀ hy hx).2 xy theorem inv_pow_le_inv_pow_of_le (a1 : 1 ≤ a) {m n : ℕ} (mn : m ≤ n) : (a ^ n)⁻¹ ≤ (a ^ m)⁻¹ := by convert one_div_pow_le_one_div_pow_of_le a1 mn using 1 <;> simp theorem inv_pow_lt_inv_pow_of_lt (a1 : 1 < a) {m n : ℕ} (mn : m < n) : (a ^ n)⁻¹ < (a ^ m)⁻¹ := by convert one_div_pow_lt_one_div_pow_of_lt a1 mn using 1 <;> simp theorem inv_pow_anti (a1 : 1 ≤ a) : Antitone fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_le_inv_pow_of_le a1 theorem inv_pow_strictAnti (a1 : 1 < a) : StrictAnti fun n : ℕ => (a ^ n)⁻¹ := fun _ _ => inv_pow_lt_inv_pow_of_lt a1 theorem le_iff_forall_one_lt_le_mul₀ {α : Type*} [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} (hb : 0 ≤ b) : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := by refine ⟨fun h _ hε ↦ h.trans <| le_mul_of_one_le_right hb hε.le, fun h ↦ ?_⟩ obtain rfl|hb := hb.eq_or_lt · simp_rw [zero_mul] at h exact h 2 one_lt_two refine le_of_forall_gt_imp_ge_of_dense fun x hbx => ?_ convert h (x / b) ((one_lt_div hb).mpr hbx) rw [mul_div_cancel₀ _ hb.ne'] /-! ### Results about `IsGLB` -/ theorem IsGLB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isGLB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isGLB_singleton theorem IsGLB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsGLB s b) : IsGLB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha end LinearOrderedSemifield section variable [Field α] [LinearOrder α] [IsStrictOrderedRing α] {a b c d : α} {n : ℤ} /-! ### Lemmas about pos, nonneg, nonpos, neg -/ theorem div_pos_iff : 0 < a / b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by simp only [division_def, mul_pos_iff, inv_pos, inv_lt_zero] theorem div_neg_iff : a / b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b := by simp [division_def, mul_neg_iff] theorem div_nonneg_iff : 0 ≤ a / b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by simp [division_def, mul_nonneg_iff] theorem div_nonpos_iff : a / b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by simp [division_def, mul_nonpos_iff] theorem div_nonneg_of_nonpos (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a / b := div_nonneg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_pos_of_neg_of_neg (ha : a < 0) (hb : b < 0) : 0 < a / b := div_pos_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a / b < 0 := div_neg_iff.2 <| Or.inr ⟨ha, hb⟩ theorem div_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a / b < 0 := div_neg_iff.2 <| Or.inl ⟨ha, hb⟩ /-! ### Relating one division with another term -/ theorem div_le_iff_of_neg (hc : c < 0) : b / c ≤ a ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc) ▸ mul_le_mul_of_nonpos_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc) _ ≥ b * (1 / c) := mul_le_mul_of_nonpos_right h (one_div_neg.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ theorem div_le_iff_of_neg' (hc : c < 0) : b / c ≤ a ↔ c * a ≤ b := by rw [mul_comm, div_le_iff_of_neg hc] theorem le_div_iff_of_neg (hc : c < 0) : a ≤ b / c ↔ b ≤ a * c := by rw [← neg_neg c, mul_neg, div_neg, le_neg, div_le_iff₀ (neg_pos.2 hc), neg_mul] theorem le_div_iff_of_neg' (hc : c < 0) : a ≤ b / c ↔ b ≤ c * a := by rw [mul_comm, le_div_iff_of_neg hc] theorem div_lt_iff_of_neg (hc : c < 0) : b / c < a ↔ a * c < b := lt_iff_lt_of_le_iff_le <| le_div_iff_of_neg hc theorem div_lt_iff_of_neg' (hc : c < 0) : b / c < a ↔ c * a < b := by rw [mul_comm, div_lt_iff_of_neg hc] theorem lt_div_iff_of_neg (hc : c < 0) : a < b / c ↔ b < a * c := lt_iff_lt_of_le_iff_le <| div_le_iff_of_neg hc theorem lt_div_iff_of_neg' (hc : c < 0) : a < b / c ↔ b < c * a := by rw [mul_comm, lt_div_iff_of_neg hc] theorem div_le_one_of_ge (h : b ≤ a) (hb : b ≤ 0) : a / b ≤ 1 := by simpa only [neg_div_neg_eq] using div_le_one_of_le₀ (neg_le_neg h) (neg_nonneg_of_nonpos hb) /-! ### Bi-implications of inequalities using inversions -/ theorem inv_le_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff_of_neg ha, ← div_eq_inv_mul, div_le_iff_of_neg hb, one_mul] theorem inv_le_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv_of_neg hb (inv_lt_zero.2 ha), inv_inv] theorem le_inv_of_neg (ha : a < 0) (hb : b < 0) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv_of_neg (inv_lt_zero.2 hb) ha, inv_inv] theorem inv_lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv_of_neg hb ha) theorem inv_lt_of_neg (ha : a < 0) (hb : b < 0) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv_of_neg hb ha) theorem lt_inv_of_neg (ha : a < 0) (hb : b < 0) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le_of_neg hb ha) /-! ### Monotonicity results involving inversion -/ theorem sub_inv_antitoneOn_Ioi : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Ioi c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv₀ (sub_pos.mpr hb) (sub_pos.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Iio : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Iio c) := antitoneOn_iff_forall_lt.mpr fun _ ha _ hb hab ↦ inv_le_inv_of_neg (sub_neg.mpr hb) (sub_neg.mpr ha) |>.mpr <| sub_le_sub (le_of_lt hab) le_rfl theorem sub_inv_antitoneOn_Icc_right (ha : c < a) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Ioi.mono <| (Set.Icc_subset_Ioi_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem sub_inv_antitoneOn_Icc_left (ha : b < c) : AntitoneOn (fun x ↦ (x-c)⁻¹) (Set.Icc a b) := by by_cases hab : a ≤ b · exact sub_inv_antitoneOn_Iio.mono <| (Set.Icc_subset_Iio_iff hab).mpr ha · simp [hab, Set.Subsingleton.antitoneOn] theorem inv_antitoneOn_Ioi : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Ioi 0) := by convert sub_inv_antitoneOn_Ioi (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Iio : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Iio 0) := by convert sub_inv_antitoneOn_Iio (α := α) exact (sub_zero _).symm theorem inv_antitoneOn_Icc_right (ha : 0 < a) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_right ha exact (sub_zero _).symm theorem inv_antitoneOn_Icc_left (hb : b < 0) : AntitoneOn (fun x : α ↦ x⁻¹) (Set.Icc a b) := by convert sub_inv_antitoneOn_Icc_left hb exact (sub_zero _).symm /-! ### Relating two divisions -/ theorem div_le_div_of_nonpos_of_le (hc : c ≤ 0) (h : b ≤ a) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonpos_right h (one_div_nonpos.2 hc) theorem div_lt_div_of_neg_of_lt (hc : c < 0) (h : b < a) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_neg_right h (one_div_neg.2 hc) theorem div_le_div_right_of_neg (hc : c < 0) : a / c ≤ b / c ↔ b ≤ a := ⟨le_imp_le_of_lt_imp_lt <| div_lt_div_of_neg_of_lt hc, div_le_div_of_nonpos_of_le <| hc.le⟩ theorem div_lt_div_right_of_neg (hc : c < 0) : a / c < b / c ↔ b < a := lt_iff_lt_of_le_iff_le <| div_le_div_right_of_neg hc /-! ### Relating one division and involving `1` -/ theorem one_le_div_of_neg (hb : b < 0) : 1 ≤ a / b ↔ a ≤ b := by rw [le_div_iff_of_neg hb, one_mul] theorem div_le_one_of_neg (hb : b < 0) : a / b ≤ 1 ↔ b ≤ a := by rw [div_le_iff_of_neg hb, one_mul] theorem one_lt_div_of_neg (hb : b < 0) : 1 < a / b ↔ a < b := by rw [lt_div_iff_of_neg hb, one_mul] theorem div_lt_one_of_neg (hb : b < 0) : a / b < 1 ↔ b < a := by rw [div_lt_iff_of_neg hb, one_mul] theorem one_div_le_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ b ↔ 1 / b ≤ a := by simpa using inv_le_of_neg ha hb theorem one_div_lt_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < b ↔ 1 / b < a := by simpa using inv_lt_of_neg ha hb theorem le_one_div_of_neg (ha : a < 0) (hb : b < 0) : a ≤ 1 / b ↔ b ≤ 1 / a := by simpa using le_inv_of_neg ha hb theorem lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : a < 1 / b ↔ b < 1 / a := by simpa using lt_inv_of_neg ha hb theorem one_lt_div_iff : 1 < a / b ↔ 0 < b ∧ b < a ∨ b < 0 ∧ a < b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_lt_div_of_neg] · simp [lt_irrefl, zero_le_one] · simp [hb, hb.not_lt, one_lt_div] theorem one_le_div_iff : 1 ≤ a / b ↔ 0 < b ∧ b ≤ a ∨ b < 0 ∧ a ≤ b := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, one_le_div_of_neg] · simp [lt_irrefl, zero_lt_one.not_le, zero_lt_one] · simp [hb, hb.not_lt, one_le_div] theorem div_lt_one_iff : a / b < 1 ↔ 0 < b ∧ a < b ∨ b = 0 ∨ b < 0 ∧ b < a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_lt_one_of_neg] · simp [zero_lt_one] · simp [hb, hb.not_lt, div_lt_one, hb.ne.symm] theorem div_le_one_iff : a / b ≤ 1 ↔ 0 < b ∧ a ≤ b ∨ b = 0 ∨ b < 0 ∧ b ≤ a := by rcases lt_trichotomy b 0 with (hb | rfl | hb) · simp [hb, hb.not_lt, hb.ne, div_le_one_of_neg] · simp [zero_le_one] · simp [hb, hb.not_lt, div_le_one, hb.ne.symm] /-! ### Relating two divisions, involving `1` -/ theorem one_div_le_one_div_of_neg_of_le (hb : b < 0) (h : a ≤ b) : 1 / b ≤ 1 / a := by rwa [div_le_iff_of_neg' hb, ← div_eq_mul_one_div, div_le_one_of_neg (h.trans_lt hb)] theorem one_div_lt_one_div_of_neg_of_lt (hb : b < 0) (h : a < b) : 1 / b < 1 / a := by rwa [div_lt_iff_of_neg' hb, ← div_eq_mul_one_div, div_lt_one_of_neg (h.trans hb)] theorem le_of_neg_of_one_div_le_one_div (hb : b < 0) (h : 1 / a ≤ 1 / b) : b ≤ a := le_imp_le_of_lt_imp_lt (one_div_lt_one_div_of_neg_of_lt hb) h theorem lt_of_neg_of_one_div_lt_one_div (hb : b < 0) (h : 1 / a < 1 / b) : b < a := lt_imp_lt_of_le_imp_le (one_div_le_one_div_of_neg_of_le hb) h /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_neg_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_le_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a ≤ 1 / b ↔ b ≤ a := by simpa [one_div] using inv_le_inv_of_neg ha hb /-- For the single implications with fewer assumptions, see `one_div_lt_one_div_of_lt` and `lt_of_one_div_lt_one_div` -/ theorem one_div_lt_one_div_of_neg (ha : a < 0) (hb : b < 0) : 1 / a < 1 / b ↔ b < a := lt_iff_lt_of_le_iff_le (one_div_le_one_div_of_neg hb ha) theorem one_div_lt_neg_one (h1 : a < 0) (h2 : -1 < a) : 1 / a < -1 := suffices 1 / a < 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_lt_one_div_of_neg_of_lt h1 h2 theorem one_div_le_neg_one (h1 : a < 0) (h2 : -1 ≤ a) : 1 / a ≤ -1 := suffices 1 / a ≤ 1 / -1 by rwa [one_div_neg_one_eq_neg_one] at this one_div_le_one_div_of_neg_of_le h1 h2 /-! ### Results about halving -/ theorem sub_self_div_two (a : α) : a - a / 2 = a / 2 := by suffices a / 2 + a / 2 - a / 2 = a / 2 by rwa [add_halves] at this rw [add_sub_cancel_right] theorem div_two_sub_self (a : α) : a / 2 - a = -(a / 2) := by suffices a / 2 - (a / 2 + a / 2) = -(a / 2) by rwa [add_halves] at this rw [sub_add_eq_sub_sub, sub_self, zero_sub] theorem add_sub_div_two_lt (h : a < b) : a + (b - a) / 2 < b := by rwa [← div_sub_div_same, sub_eq_add_neg, add_comm (b / 2), ← add_assoc, ← sub_eq_add_neg, ← lt_sub_iff_add_lt, sub_self_div_two, sub_self_div_two, div_lt_div_iff_of_pos_right (zero_lt_two' α)] /-- An inequality involving `2`. -/ theorem sub_one_div_inv_le_two (a2 : 2 ≤ a) : (1 - 1 / a)⁻¹ ≤ 2 := by -- Take inverses on both sides to obtain `2⁻¹ ≤ 1 - 1 / a` refine (inv_anti₀ (inv_pos.2 <| zero_lt_two' α) ?_).trans_eq (inv_inv (2 : α)) -- move `1 / a` to the left and `2⁻¹` to the right. rw [le_sub_iff_add_le, add_comm, ← le_sub_iff_add_le] -- take inverses on both sides and use the assumption `2 ≤ a`. convert (one_div a).le.trans (inv_anti₀ zero_lt_two a2) using 1 -- show `1 - 1 / 2 = 1 / 2`. rw [sub_eq_iff_eq_add, ← two_mul, mul_inv_cancel₀ two_ne_zero] /-! ### Results about `IsLUB` -/ -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_left {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => a * b) '' s) (a * b) := by rcases lt_or_eq_of_le ha with (ha | rfl) · exact (OrderIso.mulLeft₀ _ ha).isLUB_image'.2 hs · simp_rw [zero_mul] rw [hs.nonempty.image_const] exact isLUB_singleton -- TODO: Generalize to `LinearOrderedSemifield` theorem IsLUB.mul_right {s : Set α} (ha : 0 ≤ a) (hs : IsLUB s b) : IsLUB ((fun b => b * a) '' s) (b * a) := by simpa [mul_comm] using hs.mul_left ha /-! ### Miscellaneous lemmas -/ theorem mul_sub_mul_div_mul_neg_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) < 0 ↔ a / c < b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_lt_zero] theorem mul_sub_mul_div_mul_nonpos_iff (hc : c ≠ 0) (hd : d ≠ 0) : (a * d - b * c) / (c * d) ≤ 0 ↔ a / c ≤ b / d := by rw [mul_comm b c, ← div_sub_div _ _ hc hd, sub_nonpos] alias ⟨div_lt_div_of_mul_sub_mul_div_neg, mul_sub_mul_div_mul_neg⟩ := mul_sub_mul_div_mul_neg_iff alias ⟨div_le_div_of_mul_sub_mul_div_nonpos, mul_sub_mul_div_mul_nonpos⟩ := mul_sub_mul_div_mul_nonpos_iff theorem exists_add_lt_and_pos_of_lt (h : b < a) : ∃ c, b + c < a ∧ 0 < c := ⟨(a - b) / 2, add_sub_div_two_lt h, div_pos (sub_pos_of_lt h) zero_lt_two⟩ theorem le_of_forall_sub_le (h : ∀ ε > 0, b - ε ≤ a) : b ≤ a := by contrapose! h simpa only [@and_comm ((0 : α) < _), lt_sub_iff_add_lt, gt_iff_lt] using exists_add_lt_and_pos_of_lt h private lemma exists_lt_mul_left_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) : ∃ a' ∈ Set.Ico 0 a, c < a' * b := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha obtain ⟨a', ha', a_a'⟩ := exists_between ((div_lt_iff₀ hb).2 h) exact ⟨a', ⟨(div_nonneg hc hb.le).trans ha'.le, a_a'⟩, (div_lt_iff₀ hb).1 ha'⟩ private lemma exists_lt_mul_right_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c < a * b) : ∃ b' ∈ Set.Ico 0 b, c < a * b' := by have hb : 0 < b := pos_of_mul_pos_right (hc.trans_lt h) ha simp_rw [mul_comm a] at h ⊢ exact exists_lt_mul_left_of_nonneg hb.le hc h private lemma exists_mul_left_lt₀ {a b c : α} (hc : a * b < c) : ∃ a' > a, a' * b < c := by rcases le_or_lt b 0 with hb | hb · obtain ⟨a', ha'⟩ := exists_gt a exact ⟨a', ha', hc.trans_le' (antitone_mul_right hb ha'.le)⟩ · obtain ⟨a', ha', hc'⟩ := exists_between ((lt_div_iff₀ hb).2 hc) exact ⟨a', ha', (lt_div_iff₀ hb).1 hc'⟩ private lemma exists_mul_right_lt₀ {a b c : α} (hc : a * b < c) : ∃ b' > b, a * b' < c := by simp_rw [mul_comm a] at hc ⊢; exact exists_mul_left_lt₀ hc lemma le_mul_of_forall_lt₀ {a b c : α} (h : ∀ a' > a, ∀ b' > b, c ≤ a' * b') : c ≤ a * b := by refine le_of_forall_gt_imp_ge_of_dense fun d hd ↦ ?_ obtain ⟨a', ha', hd⟩ := exists_mul_left_lt₀ hd obtain ⟨b', hb', hd⟩ := exists_mul_right_lt₀ hd exact (h a' ha' b' hb').trans hd.le lemma mul_le_of_forall_lt_of_nonneg {a b c : α} (ha : 0 ≤ a) (hc : 0 ≤ c) (h : ∀ a' ≥ 0, a' < a → ∀ b' ≥ 0, b' < b → a' * b' ≤ c) : a * b ≤ c := by refine le_of_forall_lt_imp_le_of_dense fun d d_ab ↦ ?_ rcases lt_or_le d 0 with hd | hd · exact hd.le.trans hc obtain ⟨a', ha', d_ab⟩ := exists_lt_mul_left_of_nonneg ha hd d_ab obtain ⟨b', hb', d_ab⟩ := exists_lt_mul_right_of_nonneg ha'.1 hd d_ab exact d_ab.le.trans (h a' ha'.1 ha'.2 b' hb'.1 hb'.2) theorem mul_self_inj_of_nonneg (a0 : 0 ≤ a) (b0 : 0 ≤ b) : a * a = b * b ↔ a = b := mul_self_eq_mul_self_iff.trans <| or_iff_left_of_imp fun h => by subst a have : b = 0 := le_antisymm (neg_nonneg.1 a0) b0 rw [this, neg_zero] theorem min_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : min (a / c) (b / c) = max a b / c := Eq.symm <| Antitone.map_max fun _ _ => div_le_div_of_nonpos_of_le hc theorem max_div_div_right_of_nonpos (hc : c ≤ 0) (a b : α) : max (a / c) (b / c) = min a b / c := Eq.symm <| Antitone.map_min fun _ _ => div_le_div_of_nonpos_of_le hc theorem abs_inv (a : α) : |a⁻¹| = |a|⁻¹ := map_inv₀ (absHom : α →*₀ α) a theorem abs_div (a b : α) : |a / b| = |a| / |b| := map_div₀ (absHom : α →*₀ α) a b theorem abs_one_div (a : α) : |1 / a| = 1 / |a| := by rw [abs_div, abs_one] theorem uniform_continuous_npow_on_bounded (B : α) {ε : α} (hε : 0 < ε) (n : ℕ) : ∃ δ > 0, ∀ q r : α, |r| ≤ B → |q - r| ≤ δ → |q ^ n - r ^ n| < ε := by wlog B_pos : 0 < B generalizing B · have ⟨δ, δ_pos, cont⟩ := this 1 zero_lt_one exact ⟨δ, δ_pos, fun q r hr ↦ cont q r (hr.trans ((le_of_not_lt B_pos).trans zero_le_one))⟩ have pos : 0 < 1 + ↑n * (B + 1) ^ (n - 1) := zero_lt_one.trans_le <| le_add_of_nonneg_right <| mul_nonneg n.cast_nonneg <| (pow_pos (B_pos.trans <| lt_add_of_pos_right _ zero_lt_one) _).le refine ⟨min 1 (ε / (1 + n * (B + 1) ^ (n - 1))), lt_min zero_lt_one (div_pos hε pos), fun q r hr hqr ↦ (abs_pow_sub_pow_le ..).trans_lt ?_⟩ rw [le_inf_iff, le_div_iff₀ pos, mul_one_add, ← mul_assoc] at hqr obtain h | h := (abs_nonneg (q - r)).eq_or_lt · simpa only [← h, zero_mul] using hε refine (lt_of_le_of_lt ?_ <| lt_add_of_pos_left _ h).trans_le hqr.2 refine mul_le_mul_of_nonneg_left (pow_le_pow_left₀ ((abs_nonneg _).trans le_sup_left) ?_ _) (mul_nonneg (abs_nonneg _) n.cast_nonneg) refine max_le ?_ (hr.trans <| le_add_of_nonneg_right zero_le_one) exact add_sub_cancel r q ▸ (abs_add_le ..).trans (add_le_add hr hqr.1) end namespace Mathlib.Meta.Positivity open Lean Meta Qq Function section LinearOrderedSemifield variable {α : Type*} [Semifield α] [LinearOrder α] [IsStrictOrderedRing α] {a b : α} private lemma div_nonneg_of_pos_of_nonneg (ha : 0 < a) (hb : 0 ≤ b) : 0 ≤ a / b := div_nonneg ha.le hb private lemma div_nonneg_of_nonneg_of_pos (ha : 0 ≤ a) (hb : 0 < b) : 0 ≤ a / b := div_nonneg ha hb.le omit [IsStrictOrderedRing α] in private lemma div_ne_zero_of_pos_of_ne_zero (ha : 0 < a) (hb : b ≠ 0) : a / b ≠ 0 := div_ne_zero ha.ne' hb omit [IsStrictOrderedRing α] in private lemma div_ne_zero_of_ne_zero_of_pos (ha : a ≠ 0) (hb : 0 < b) : a / b ≠ 0 := div_ne_zero ha hb.ne' private lemma zpow_zero_pos (a : α) : 0 < a ^ (0 : ℤ) := zero_lt_one.trans_eq (zpow_zero a).symm end LinearOrderedSemifield /-- The `positivity` extension which identifies expressions of the form `a / b`, such that `positivity` successfully recognises both `a` and `b`. -/ @[positivity _ / _] def evalDiv : PositivityExt where eval {u α} zα pα e := do let .app (.app (f : Q($α → $α → $α)) (a : Q($α))) (b : Q($α)) ← withReducible (whnf e) | throwError "not /" let _e_eq : $e =Q $f $a $b := ⟨⟩ let _a ← synthInstanceQ q(Semifield $α) let _a ← synthInstanceQ q(LinearOrder $α) let _a ← synthInstanceQ q(IsStrictOrderedRing $α) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(HDiv.hDiv) let ra ← core zα pα a; let rb ← core zα pα b match ra, rb with | .positive pa, .positive pb => pure (.positive q(div_pos $pa $pb)) | .positive pa, .nonnegative pb => pure (.nonnegative q(div_nonneg_of_pos_of_nonneg $pa $pb)) | .nonnegative pa, .positive pb => pure (.nonnegative q(div_nonneg_of_nonneg_of_pos $pa $pb)) | .nonnegative pa, .nonnegative pb => pure (.nonnegative q(div_nonneg $pa $pb)) | .positive pa, .nonzero pb => pure (.nonzero q(div_ne_zero_of_pos_of_ne_zero $pa $pb)) | .nonzero pa, .positive pb => pure (.nonzero q(div_ne_zero_of_ne_zero_of_pos $pa $pb)) | .nonzero pa, .nonzero pb => pure (.nonzero q(div_ne_zero $pa $pb)) | _, _ => pure .none /-- The `positivity` extension which identifies expressions of the form `a⁻¹`, such that `positivity` successfully recognises `a`. -/ @[positivity _⁻¹] def evalInv : PositivityExt where eval {u α} zα pα e := do let .app (f : Q($α → $α)) (a : Q($α)) ← withReducible (whnf e) | throwError "not ⁻¹" let _e_eq : $e =Q $f $a := ⟨⟩ let _a ← synthInstanceQ q(Semifield $α) let _a ← synthInstanceQ q(LinearOrder $α) let _a ← synthInstanceQ q(IsStrictOrderedRing $α) assumeInstancesCommute let ⟨_f_eq⟩ ← withDefault <| withNewMCtxDepth <| assertDefEqQ q($f) q(Inv.inv) let ra ← core zα pα a match ra with | .positive pa => pure (.positive q(inv_pos_of_pos $pa)) | .nonnegative pa => pure (.nonnegative q(inv_nonneg_of_nonneg $pa)) | .nonzero pa => pure (.nonzero q(inv_ne_zero $pa)) | .none => pure .none /-- The `positivity` extension which identifies expressions of the form `a ^ (0:ℤ)`. -/ @[positivity _ ^ (0 : ℤ), Pow.pow _ (0 : ℤ)] def evalPowZeroInt : PositivityExt where eval {u α} _zα _pα e := do let .app (.app _ (a : Q($α))) _ ← withReducible (whnf e) | throwError "not ^" let _a ← synthInstanceQ q(Semifield $α) let _a ← synthInstanceQ q(LinearOrder $α) let _a ← synthInstanceQ q(IsStrictOrderedRing $α) assumeInstancesCommute let ⟨_a⟩ ← Qq.assertDefEqQ q($e) q($a ^ (0 : ℤ)) pure (.positive q(zpow_zero_pos $a)) end Mathlib.Meta.Positivity
Mathlib/Algebra/Order/Field/Basic.lean
974
977
/- Copyright (c) 2023 Moritz Firsching. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Firsching, Ashvni Narayanan, Michael Stoll -/ import Mathlib.Algebra.BigOperators.Associated import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.Coprime.Lemmas /-! # Lemmas about units in `ZMod`. -/ assert_not_exists TwoSidedIdeal namespace ZMod variable {n m : ℕ} /-- `unitsMap` is a group homomorphism that maps units of `ZMod m` to units of `ZMod n` when `n` divides `m`. -/ def unitsMap (hm : n ∣ m) : (ZMod m)ˣ →* (ZMod n)ˣ := Units.map (castHom hm (ZMod n)) lemma unitsMap_def (hm : n ∣ m) : unitsMap hm = Units.map (castHom hm (ZMod n)) := rfl lemma unitsMap_comp {d : ℕ} (hm : n ∣ m) (hd : m ∣ d) : (unitsMap hm).comp (unitsMap hd) = unitsMap (dvd_trans hm hd) := by simp only [unitsMap_def] rw [← Units.map_comp] exact congr_arg Units.map <| congr_arg RingHom.toMonoidHom <| castHom_comp hm hd @[simp] lemma unitsMap_self (n : ℕ) : unitsMap (dvd_refl n) = MonoidHom.id _ := by simp [unitsMap, castHom_self] /-- `unitsMap_val` shows that coercing from `(ZMod m)ˣ` to `ZMod n` gives the same result when going via `(ZMod n)ˣ` and `ZMod m`. -/ lemma unitsMap_val (h : n ∣ m) (a : (ZMod m)ˣ) : ↑(unitsMap h a) = ((a : ZMod m).cast : ZMod n) := rfl lemma isUnit_cast_of_dvd (hm : n ∣ m) (a : Units (ZMod m)) : IsUnit (cast (a : ZMod m) : ZMod n) := Units.isUnit (unitsMap hm a) @[deprecated (since := "2024-12-16")] alias IsUnit_cast_of_dvd := isUnit_cast_of_dvd theorem unitsMap_surjective [hm : NeZero m] (h : n ∣ m) : Function.Surjective (unitsMap h) := by suffices ∀ x : ℕ, x.Coprime n → ∃ k : ℕ, (x + k * n).Coprime m by intro x have ⟨k, hk⟩ := this x.val.val (val_coe_unit_coprime x) refine ⟨unitOfCoprime _ hk, Units.ext ?_⟩ have : NeZero n := ⟨fun hn ↦ hm.out (eq_zero_of_zero_dvd (hn ▸ h))⟩ simp [unitsMap_def, - castHom_apply] intro x hx let ps : Finset ℕ := {p ∈ m.primeFactors | ¬p ∣ x} use ps.prod id apply Nat.coprime_of_dvd intro p pp hp hpn by_cases hpx : p ∣ x · have h := Nat.dvd_sub hp hpx rw [add_comm, Nat.add_sub_cancel] at h rcases pp.dvd_mul.mp h with h | h · have ⟨q, hq, hq'⟩ := (pp.prime.dvd_finset_prod_iff id).mp h rw [Finset.mem_filter, Nat.mem_primeFactors, ← (Nat.prime_dvd_prime_iff_eq pp hq.1.1).mp hq'] at hq exact hq.2 hpx · exact Nat.Prime.not_coprime_iff_dvd.mpr ⟨p, pp, hpx, h⟩ hx · have pps : p ∈ ps := Finset.mem_filter.mpr ⟨Nat.mem_primeFactors.mpr ⟨pp, hpn, hm.out⟩, hpx⟩ have h := Nat.dvd_sub hp ((Finset.dvd_prod_of_mem id pps).mul_right n) rw [Nat.add_sub_cancel] at h contradiction -- This needs `Nat.primeFactors`, so cannot go into `Mathlib.Data.ZMod.Basic`.
open Nat in lemma not_isUnit_of_mem_primeFactors {n p : ℕ} (h : p ∈ n.primeFactors) : ¬ IsUnit (p : ZMod n) := by rw [isUnit_iff_coprime] exact (Prime.dvd_iff_not_coprime <| prime_of_mem_primeFactors h).mp <| dvd_of_mem_primeFactors h /-- Any element of `ZMod N` has the form `u * d` where `u` is a unit and `d` is a divisor of `N`. -/ lemma eq_unit_mul_divisor {N : ℕ} (a : ZMod N) : ∃ d : ℕ, d ∣ N ∧ ∃ (u : ZMod N), IsUnit u ∧ a = u * d := by rcases eq_or_ne N 0 with rfl | hN -- Silly special case : N = 0. Of no mathematical interest, but true, so let's prove it. · change ℤ at a rcases eq_or_ne a 0 with rfl | ha · refine ⟨0, dvd_zero _, 1, isUnit_one, by rw [Nat.cast_zero, mul_zero]⟩ refine ⟨a.natAbs, dvd_zero _, Int.sign a, ?_, (Int.sign_mul_natAbs a).symm⟩ rcases lt_or_gt_of_ne ha with h | h · simp only [Int.sign_eq_neg_one_of_neg h, IsUnit.neg_iff, isUnit_one] · simp only [Int.sign_eq_one_of_pos h, isUnit_one] -- now the interesting case have : NeZero N := ⟨hN⟩ -- Define `d` as the GCD of a lift of `a` and `N`. let d := a.val.gcd N have hd : d ≠ 0 := Nat.gcd_ne_zero_right hN obtain ⟨a₀, (ha₀ : _ = d * _)⟩ := a.val.gcd_dvd_left N obtain ⟨N₀, (hN₀ : _ = d * _)⟩ := a.val.gcd_dvd_right N refine ⟨d, ⟨N₀, hN₀⟩, ?_⟩ -- Show `a` is a unit mod `N / d`. have hu₀ : IsUnit (a₀ : ZMod N₀) := by refine (isUnit_iff_coprime _ _).mpr (Nat.isCoprime_iff_coprime.mp ?_) obtain ⟨p, q, hpq⟩ : ∃ (p q : ℤ), d = a.val * p + N * q := ⟨_, _, Nat.gcd_eq_gcd_ab _ _⟩ rw [ha₀, hN₀, Nat.cast_mul, Nat.cast_mul, mul_assoc, mul_assoc, ← mul_add, eq_comm, mul_comm _ p, mul_comm _ q] at hpq exact ⟨p, q, Int.eq_one_of_mul_eq_self_right (Nat.cast_ne_zero.mpr hd) hpq⟩ -- Lift it arbitrarily to a unit mod `N`. obtain ⟨u, hu⟩ := (ZMod.unitsMap_surjective (⟨d, mul_comm d N₀ ▸ hN₀⟩ : N₀ ∣ N)) hu₀.unit
Mathlib/Data/ZMod/Units.lean
72
106
/- Copyright (c) 2022 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Subalgebra.Lattice import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Star.Module import Mathlib.Algebra.Star.NonUnitalSubalgebra /-! # Star subalgebras A *-subalgebra is a subalgebra of a *-algebra which is closed under *. The centralizer of a *-closed set is a *-subalgebra. -/ universe u v /-- A *-subalgebra is a subalgebra of a *-algebra which is closed under *. -/ structure StarSubalgebra (R : Type u) (A : Type v) [CommSemiring R] [StarRing R] [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] : Type v extends Subalgebra R A where /-- The `carrier` is closed under the `star` operation. -/ star_mem' {a} : a ∈ carrier → star a ∈ carrier namespace StarSubalgebra /-- Forgetting that a *-subalgebra is closed under *. -/ add_decl_doc StarSubalgebra.toSubalgebra variable {F R A B C : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [StarRing A] [Algebra R A] [StarModule R A] variable [Semiring B] [StarRing B] [Algebra R B] [StarModule R B] variable [Semiring C] [StarRing C] [Algebra R C] [StarModule R C] instance setLike : SetLike (StarSubalgebra R A) A where coe S := S.carrier coe_injective' p q h := by obtain ⟨⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩, _⟩ := p; cases q; congr /-- The actual `StarSubalgebra` obtained from an element of a type satisfying `SubsemiringClass`, `SMulMemClass` and `StarMemClass`. -/ @[simps] def ofClass {S R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [StarRing R] [StarRing A] [StarModule R A] [SetLike S A] [SubsemiringClass S A] [SMulMemClass S R A] [StarMemClass S A] (s : S) : StarSubalgebra R A where carrier := s add_mem' := add_mem zero_mem' := zero_mem _ mul_mem' := mul_mem one_mem' := one_mem _ algebraMap_mem' := algebraMap_mem s star_mem' := star_mem instance (priority := 100) : CanLift (Set A) (StarSubalgebra R A) (↑) (fun s ↦ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ (∀ (r : R), algebraMap R A r ∈ s) ∧ ∀ {x}, x ∈ s → star x ∈ s) where prf s h := ⟨ { carrier := s zero_mem' := by simpa using h.2.2.1 0 add_mem' := h.1 one_mem' := by simpa using h.2.2.1 1 mul_mem' := h.2.1 algebraMap_mem' := h.2.2.1 star_mem' := h.2.2.2 }, rfl ⟩ instance starMemClass : StarMemClass (StarSubalgebra R A) A where star_mem {s} := s.star_mem' instance subsemiringClass : SubsemiringClass (StarSubalgebra R A) A where add_mem {s} := s.add_mem' mul_mem {s} := s.mul_mem' one_mem {s} := s.one_mem' zero_mem {s} := s.zero_mem' instance smulMemClass : SMulMemClass (StarSubalgebra R A) R A where smul_mem {s} r a (ha : a ∈ s.toSubalgebra) := (SMulMemClass.smul_mem r ha : r • a ∈ s.toSubalgebra) instance subringClass {R A} [CommRing R] [StarRing R] [Ring A] [StarRing A] [Algebra R A] [StarModule R A] : SubringClass (StarSubalgebra R A) A where neg_mem {s a} ha := show -a ∈ s.toSubalgebra from neg_mem ha -- this uses the `Star` instance `s` inherits from `StarMemClass (StarSubalgebra R A) A` instance starRing (s : StarSubalgebra R A) : StarRing s := { StarMemClass.instStar s with star_involutive := fun r => Subtype.ext (star_star (r : A)) star_mul := fun r₁ r₂ => Subtype.ext (star_mul (r₁ : A) (r₂ : A)) star_add := fun r₁ r₂ => Subtype.ext (star_add (r₁ : A) (r₂ : A)) } instance algebra (s : StarSubalgebra R A) : Algebra R s := s.toSubalgebra.algebra' instance starModule (s : StarSubalgebra R A) : StarModule R s where star_smul r a := Subtype.ext (star_smul r (a : A)) /-- Turn a `StarSubalgebra` into a `NonUnitalStarSubalgebra` by forgetting that it contains `1`. -/ def toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : NonUnitalStarSubalgebra R A where __ := S smul_mem' r _x hx := S.smul_mem hx r lemma one_mem_toNonUnitalStarSubalgebra (S : StarSubalgebra R A) : 1 ∈ S.toNonUnitalStarSubalgebra := S.one_mem' theorem mem_carrier {s : StarSubalgebra R A} {x : A} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl @[ext] theorem ext {S T : StarSubalgebra R A} (h : ∀ x : A, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h @[simp] lemma coe_mk (S : Subalgebra R A) (h) : ((⟨S, h⟩ : StarSubalgebra R A) : Set A) = S := rfl @[simp] theorem mem_toSubalgebra {S : StarSubalgebra R A} {x} : x ∈ S.toSubalgebra ↔ x ∈ S := Iff.rfl @[simp] theorem coe_toSubalgebra (S : StarSubalgebra R A) : (S.toSubalgebra : Set A) = S := rfl theorem toSubalgebra_injective : Function.Injective (toSubalgebra : StarSubalgebra R A → Subalgebra R A) := fun S T h => ext fun x => by rw [← mem_toSubalgebra, ← mem_toSubalgebra, h] theorem toSubalgebra_inj {S U : StarSubalgebra R A} : S.toSubalgebra = U.toSubalgebra ↔ S = U := toSubalgebra_injective.eq_iff theorem toSubalgebra_le_iff {S₁ S₂ : StarSubalgebra R A} : S₁.toSubalgebra ≤ S₂.toSubalgebra ↔ S₁ ≤ S₂ := Iff.rfl /-- Copy of a star subalgebra with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : StarSubalgebra R A where toSubalgebra := Subalgebra.copy S.toSubalgebra s hs star_mem' {a} ha := hs ▸ S.star_mem' (by simpa [hs] using ha) @[simp] theorem coe_copy (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : (S.copy s hs : Set A) = s := rfl theorem copy_eq (S : StarSubalgebra R A) (s : Set A) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs variable (S : StarSubalgebra R A) protected theorem algebraMap_mem (r : R) : algebraMap R A r ∈ S := S.algebraMap_mem' r theorem rangeS_le : (algebraMap R A).rangeS ≤ S.toSubalgebra.toSubsemiring := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_subset : Set.range (algebraMap R A) ⊆ S := fun _x ⟨r, hr⟩ => hr ▸ S.algebraMap_mem r theorem range_le : Set.range (algebraMap R A) ≤ S := S.range_subset protected theorem smul_mem {x : A} (hx : x ∈ S) (r : R) : r • x ∈ S := (Algebra.smul_def r x).symm ▸ mul_mem (S.algebraMap_mem r) hx /-- Embedding of a subalgebra into the algebra. -/ def subtype : S →⋆ₐ[R] A where toFun := ((↑) : S → A) map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl @[simp] theorem coe_subtype : (S.subtype : S → A) = Subtype.val := rfl theorem subtype_apply (x : S) : S.subtype x = (x : A) := rfl @[simp] theorem toSubalgebra_subtype : S.toSubalgebra.val = S.subtype.toAlgHom := rfl /-- The inclusion map between `StarSubalgebra`s given by `Subtype.map id` as a `StarAlgHom`. -/ @[simps] def inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₁ →⋆ₐ[R] S₂ where toFun := Subtype.map id h map_one' := rfl map_mul' _ _ := rfl map_zero' := rfl map_add' _ _ := rfl commutes' _ := rfl map_star' _ := rfl theorem inclusion_injective {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : Function.Injective <| inclusion h := Set.inclusion_injective h @[simp] theorem subtype_comp_inclusion {S₁ S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂) : S₂.subtype.comp (inclusion h) = S₁.subtype := rfl section Map /-- Transport a star subalgebra via a star algebra homomorphism. -/ def map (f : A →⋆ₐ[R] B) (S : StarSubalgebra R A) : StarSubalgebra R B := { S.toSubalgebra.map f.toAlgHom with star_mem' := by rintro _ ⟨a, ha, rfl⟩ exact map_star f a ▸ Set.mem_image_of_mem _ (S.star_mem' ha) } theorem map_mono {S₁ S₂ : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.map f ≤ S₂.map f := Set.image_subset f theorem map_injective {f : A →⋆ₐ[R] B} (hf : Function.Injective f) : Function.Injective (map f) := fun _S₁ _S₂ ih => ext <| Set.ext_iff.1 <| Set.image_injective.2 hf <| Set.ext <| SetLike.ext_iff.mp ih @[simp] theorem map_id (S : StarSubalgebra R A) : S.map (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.image_id _ theorem map_map (S : StarSubalgebra R A) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.map f).map g = S.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ @[simp] theorem mem_map {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {y : B} : y ∈ map f S ↔ ∃ x ∈ S, f x = y := Subsemiring.mem_map theorem map_toSubalgebra {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} : (S.map f).toSubalgebra = S.toSubalgebra.map f.toAlgHom := SetLike.coe_injective rfl @[simp] theorem coe_map (S : StarSubalgebra R A) (f : A →⋆ₐ[R] B) : (S.map f : Set B) = f '' S := rfl /-- Preimage of a star subalgebra under a star algebra homomorphism. -/ def comap (f : A →⋆ₐ[R] B) (S : StarSubalgebra R B) : StarSubalgebra R A := { S.toSubalgebra.comap f.toAlgHom with star_mem' := @fun a ha => show f (star a) ∈ S from (map_star f a).symm ▸ star_mem ha } theorem map_le_iff_le_comap {S : StarSubalgebra R A} {f : A →⋆ₐ[R] B} {U : StarSubalgebra R B} : map f S ≤ U ↔ S ≤ comap f U := Set.image_subset_iff theorem gc_map_comap (f : A →⋆ₐ[R] B) : GaloisConnection (map f) (comap f) := fun _S _U => map_le_iff_le_comap theorem comap_mono {S₁ S₂ : StarSubalgebra R B} {f : A →⋆ₐ[R] B} : S₁ ≤ S₂ → S₁.comap f ≤ S₂.comap f := Set.preimage_mono theorem comap_injective {f : A →⋆ₐ[R] B} (hf : Function.Surjective f) : Function.Injective (comap f) := fun _S₁ _S₂ h => ext fun b => let ⟨x, hx⟩ := hf b let this := SetLike.ext_iff.1 h x hx ▸ this @[simp] theorem comap_id (S : StarSubalgebra R A) : S.comap (StarAlgHom.id R A) = S := SetLike.coe_injective <| Set.preimage_id theorem comap_comap (S : StarSubalgebra R C) (g : B →⋆ₐ[R] C) (f : A →⋆ₐ[R] B) : (S.comap g).comap f = S.comap (g.comp f) := SetLike.coe_injective <| by exact Set.preimage_preimage @[simp] theorem mem_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) (x : A) : x ∈ S.comap f ↔ f x ∈ S := Iff.rfl @[simp, norm_cast] theorem coe_comap (S : StarSubalgebra R B) (f : A →⋆ₐ[R] B) : (S.comap f : Set A) = f ⁻¹' (S : Set B) := rfl end Map section Centralizer variable (R) /-- The centralizer, or commutant, of the star-closure of a set as a star subalgebra. -/ def centralizer (s : Set A) : StarSubalgebra R A where toSubalgebra := Subalgebra.centralizer R (s ∪ star s) star_mem' := Set.star_mem_centralizer @[simp, norm_cast] theorem coe_centralizer (s : Set A) : (centralizer R s : Set A) = (s ∪ star s).centralizer := rfl open Set in nonrec theorem mem_centralizer_iff {s : Set A} {z : A} : z ∈ centralizer R s ↔ ∀ g ∈ s, g * z = z * g ∧ star g * z = z * star g := by simp [← SetLike.mem_coe, centralizer_union, ← image_star, mem_centralizer_iff, forall_and] theorem centralizer_le (s t : Set A) (h : s ⊆ t) : centralizer R t ≤ centralizer R s := Set.centralizer_subset (Set.union_subset_union h <| Set.preimage_mono h) theorem centralizer_toSubalgebra (s : Set A) : (centralizer R s).toSubalgebra = Subalgebra.centralizer R (s ∪ star s):= rfl theorem coe_centralizer_centralizer (s : Set A) : (centralizer R (centralizer R s : Set A)) = (s ∪ star s).centralizer.centralizer := by rw [coe_centralizer, StarMemClass.star_coe_eq, Set.union_self, coe_centralizer] end Centralizer end StarSubalgebra /-! ### The star closure of a subalgebra -/ namespace Subalgebra open Pointwise variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] /-- The pointwise `star` of a subalgebra is a subalgebra. -/ instance involutiveStar : InvolutiveStar (Subalgebra R A) where star S := { carrier := star S.carrier mul_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_mul x y).symm ▸ mul_mem hy hx one_mem' := Set.mem_star.mp ((star_one A).symm ▸ one_mem S : star (1 : A) ∈ S) add_mem' := fun {x y} hx hy => by simp only [Set.mem_star, Subalgebra.mem_carrier] at * exact (star_add x y).symm ▸ add_mem hx hy zero_mem' := Set.mem_star.mp ((star_zero A).symm ▸ zero_mem S : star (0 : A) ∈ S) algebraMap_mem' := fun r => by simpa only [Set.mem_star, Subalgebra.mem_carrier, ← algebraMap_star_comm] using S.algebraMap_mem (star r) } star_involutive S := Subalgebra.ext fun x => ⟨fun hx => star_star x ▸ hx, fun hx => ((star_star x).symm ▸ hx : star (star x) ∈ S)⟩ @[simp] theorem mem_star_iff (S : Subalgebra R A) (x : A) : x ∈ star S ↔ star x ∈ S := Iff.rfl theorem star_mem_star_iff (S : Subalgebra R A) (x : A) : star x ∈ star S ↔ x ∈ S := by simp @[simp] theorem coe_star (S : Subalgebra R A) : ((star S : Subalgebra R A) : Set A) = star (S : Set A) := rfl theorem star_mono : Monotone (star : Subalgebra R A → Subalgebra R A) := fun _ _ h _ hx => h hx variable (R) in /-- The star operation on `Subalgebra` commutes with `Algebra.adjoin`. -/ theorem star_adjoin_comm (s : Set A) : star (Algebra.adjoin R s) = Algebra.adjoin R (star s) := have this : ∀ t : Set A, Algebra.adjoin R (star t) ≤ star (Algebra.adjoin R t) := fun _ => Algebra.adjoin_le fun _ hx => Algebra.subset_adjoin hx le_antisymm (by simpa only [star_star] using Subalgebra.star_mono (this (star s))) (this s) /-- The `StarSubalgebra` obtained from `S : Subalgebra R A` by taking the smallest subalgebra containing both `S` and `star S`. -/ @[simps!] def starClosure (S : Subalgebra R A) : StarSubalgebra R A where toSubalgebra := S ⊔ star S star_mem' := fun {a} ha => by simp only [Subalgebra.mem_carrier, ← (@Algebra.gi R A _ _ _).l_sup_u _ _] at * rw [← mem_star_iff _ a, star_adjoin_comm, sup_comm] simpa using ha theorem starClosure_toSubalgebra (S : Subalgebra R A) : S.starClosure.toSubalgebra = S ⊔ star S := rfl theorem starClosure_le {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} (h : S₁ ≤ S₂.toSubalgebra) : S₁.starClosure ≤ S₂ := StarSubalgebra.toSubalgebra_le_iff.1 <| sup_le h fun x hx => (star_star x ▸ star_mem (show star x ∈ S₂ from h <| (S₁.mem_star_iff _).1 hx) : x ∈ S₂) theorem starClosure_le_iff {S₁ : Subalgebra R A} {S₂ : StarSubalgebra R A} : S₁.starClosure ≤ S₂ ↔ S₁ ≤ S₂.toSubalgebra := ⟨fun h => le_sup_left.trans h, starClosure_le⟩ end Subalgebra /-! ### The star subalgebra generated by a set -/ namespace StarAlgebra open StarSubalgebra variable {F R A B : Type*} [CommSemiring R] [StarRing R] variable [Semiring A] [Algebra R A] [StarRing A] [StarModule R A] variable [Semiring B] [Algebra R B] [StarRing B] [StarModule R B] variable (R) /-- The minimal star subalgebra that contains `s`. -/ @[simps!] def adjoin (s : Set A) : StarSubalgebra R A := { Algebra.adjoin R (s ∪ star s) with star_mem' := fun hx => by rwa [Subalgebra.mem_carrier, ← Subalgebra.mem_star_iff, Subalgebra.star_adjoin_comm, Set.union_star, star_star, Set.union_comm] } theorem adjoin_eq_starClosure_adjoin (s : Set A) : adjoin R s = (Algebra.adjoin R s).starClosure := toSubalgebra_injective <| show Algebra.adjoin R (s ∪ star s) = Algebra.adjoin R s ⊔ star (Algebra.adjoin R s) from (Subalgebra.star_adjoin_comm R s).symm ▸ Algebra.adjoin_union s (star s) theorem adjoin_toSubalgebra (s : Set A) : (adjoin R s).toSubalgebra = Algebra.adjoin R (s ∪ star s) := rfl @[aesop safe 20 apply (rule_sets := [SetLike])] theorem subset_adjoin (s : Set A) : s ⊆ adjoin R s := Set.subset_union_left.trans Algebra.subset_adjoin theorem star_subset_adjoin (s : Set A) : star s ⊆ adjoin R s := Set.subset_union_right.trans Algebra.subset_adjoin theorem self_mem_adjoin_singleton (x : A) : x ∈ adjoin R ({x} : Set A) := Algebra.subset_adjoin <| Set.mem_union_left _ (Set.mem_singleton x) theorem star_self_mem_adjoin_singleton (x : A) : star x ∈ adjoin R ({x} : Set A) := star_mem <| self_mem_adjoin_singleton R x variable {R} protected theorem gc : GaloisConnection (adjoin R : Set A → StarSubalgebra R A) (↑) := by intro s S rw [← toSubalgebra_le_iff, adjoin_toSubalgebra, Algebra.adjoin_le_iff, coe_toSubalgebra] exact ⟨fun h => Set.subset_union_left.trans h, fun h => Set.union_subset h fun x hx => star_star x ▸ star_mem (show star x ∈ S from h hx)⟩ /-- Galois insertion between `adjoin` and `coe`. -/ protected def gi : GaloisInsertion (adjoin R : Set A → StarSubalgebra R A) (↑) where choice s hs := (adjoin R s).copy s <| le_antisymm (StarAlgebra.gc.le_u_l s) hs gc := StarAlgebra.gc le_l_u S := (StarAlgebra.gc (S : Set A) (adjoin R S)).1 <| le_rfl choice_eq _ _ := StarSubalgebra.copy_eq _ _ _ theorem adjoin_le {S : StarSubalgebra R A} {s : Set A} (hs : s ⊆ S) : adjoin R s ≤ S := StarAlgebra.gc.l_le hs theorem adjoin_le_iff {S : StarSubalgebra R A} {s : Set A} : adjoin R s ≤ S ↔ s ⊆ S := StarAlgebra.gc _ _ lemma adjoin_eq (S : StarSubalgebra R A) : adjoin R (S : Set A) = S := le_antisymm (adjoin_le le_rfl) (subset_adjoin R (S : Set A)) open Submodule in lemma adjoin_eq_span (s : Set A) : Subalgebra.toSubmodule (adjoin R s).toSubalgebra = span R (Submonoid.closure (s ∪ star s)) := by rw [adjoin_toSubalgebra, Algebra.adjoin_eq_span] open Submodule in lemma adjoin_nonUnitalStarSubalgebra_eq_span (s : NonUnitalStarSubalgebra R A) : (adjoin R (s : Set A)).toSubalgebra.toSubmodule = span R {1} ⊔ s.toSubmodule := by rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalStarAlgebra.adjoin_eq_span, NonUnitalStarAlgebra.adjoin_eq] theorem _root_.Subalgebra.starClosure_eq_adjoin (S : Subalgebra R A) : S.starClosure = adjoin R (S : Set A) := le_antisymm (Subalgebra.starClosure_le_iff.2 <| subset_adjoin R (S : Set A)) (adjoin_le (le_sup_left : S ≤ S ⊔ star S)) /-- If some predicate holds for all `x ∈ (s : Set A)` and this predicate is closed under the `algebraMap`, addition, multiplication and star operations, then it holds for `a ∈ adjoin R s`. -/ @[elab_as_elim] theorem adjoin_induction {s : Set A} {p : (x : A) → x ∈ adjoin R s → Prop} (mem : ∀ (x) (h : x ∈ s), p x (subset_adjoin R s h)) (algebraMap : ∀ r, p (_root_.algebraMap R _ r) (_root_.algebraMap_mem _ r)) (add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem hx hy)) (mul : ∀ x y hx hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (star : ∀ x hx, p x hx → p (star x) (star_mem hx)) {a : A} (ha : a ∈ adjoin R s) : p a ha := by refine Algebra.adjoin_induction (fun x hx ↦ ?_) algebraMap add mul ha simp only [Set.mem_union, Set.mem_star] at hx obtain (hx | hx) := hx · exact mem x hx · simpa using star _ (Algebra.subset_adjoin (by simpa using Or.inl hx)) (mem _ hx) @[elab_as_elim] theorem adjoin_induction₂ {s : Set A} {p : (x y : A) → x ∈ adjoin R s → y ∈ adjoin R s → Prop} (mem_mem : ∀ (x) (y) (hx : x ∈ s) (hy : y ∈ s), p x y (subset_adjoin R s hx) (subset_adjoin R s hy)) (algebraMap_both : ∀ r₁ r₂, p (algebraMap R A r₁) (algebraMap R A r₂) (_root_.algebraMap_mem _ r₁) (_root_.algebraMap_mem _ r₂)) (algebraMap_left : ∀ (r) (x) (hx : x ∈ s), p (algebraMap R A r) x (_root_.algebraMap_mem _ r) (subset_adjoin R s hx)) (algebraMap_right : ∀ (r) (x) (hx : x ∈ s), p x (algebraMap R A r) (subset_adjoin R s hx) (_root_.algebraMap_mem _ r)) (add_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x + y) z (add_mem hx hy) hz) (add_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y + z) hx (add_mem hy hz)) (mul_left : ∀ x y z hx hy hz, p x z hx hz → p y z hy hz → p (x * y) z (mul_mem hx hy) hz) (mul_right : ∀ x y z hx hy hz, p x y hx hy → p x z hx hz → p x (y * z) hx (mul_mem hy hz)) (star_left : ∀ x y hx hy, p x y hx hy → p (star x) y (star_mem hx) hy) (star_right : ∀ x y hx hy, p x y hx hy → p x (star y) hx (star_mem hy)) {a b : A} (ha : a ∈ adjoin R s) (hb : b ∈ adjoin R s) : p a b ha hb := by induction hb using adjoin_induction with | mem z hz => induction ha using adjoin_induction with | mem _ h => exact mem_mem _ _ h hz | algebraMap _ => exact algebraMap_left _ _ hz | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | algebraMap r => induction ha using adjoin_induction with | mem _ h => exact algebraMap_right _ _ h | algebraMap _ => exact algebraMap_both _ _ | mul _ _ _ _ h₁ h₂ => exact mul_left _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_left _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_left _ _ _ _ h | mul _ _ _ _ h₁ h₂ => exact mul_right _ _ _ _ _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add_right _ _ _ _ _ _ h₁ h₂ | star _ _ h => exact star_right _ _ _ _ h /-- The difference with `StarSubalgebra.adjoin_induction` is that this acts on the subtype. -/ @[elab_as_elim] theorem adjoin_induction_subtype {s : Set A} {p : adjoin R s → Prop} (a : adjoin R s) (mem : ∀ (x) (h : x ∈ s), p ⟨x, subset_adjoin R s h⟩) (algebraMap : ∀ r, p (algebraMap R _ r)) (add : ∀ x y, p x → p y → p (x + y)) (mul : ∀ x y, p x → p y → p (x * y)) (star : ∀ x, p x → p (star x)) : p a := Subtype.recOn a fun b hb => by induction hb using adjoin_induction with | mem _ h => exact mem _ h | algebraMap _ => exact algebraMap _ | mul _ _ _ _ h₁ h₂ => exact mul _ _ h₁ h₂ | add _ _ _ _ h₁ h₂ => exact add _ _ h₁ h₂ | star _ _ h => exact star _ h variable (R) lemma adjoin_le_centralizer_centralizer (s : Set A) : adjoin R s ≤ centralizer R (centralizer R s) := by rw [← toSubalgebra_le_iff, centralizer_toSubalgebra, adjoin_toSubalgebra]
convert Algebra.adjoin_le_centralizer_centralizer R (s ∪ star s) rw [StarMemClass.star_coe_eq] simp /-- If all elements of `s : Set A` commute pairwise and also commute pairwise with elements of `star s`, then `StarSubalgebra.adjoin R s` is commutative. See note [reducible non-instances]. -/ abbrev adjoinCommSemiringOfComm {s : Set A} (hcomm : ∀ a ∈ s, ∀ b ∈ s, a * b = b * a) (hcomm_star : ∀ a ∈ s, ∀ b ∈ s, a * star b = star b * a) : CommSemiring (adjoin R s) := { (adjoin R s).toSemiring with mul_comm := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ by have hcomm : ∀ a ∈ s ∪ star s, ∀ b ∈ s ∪ star s, a * b = b * a := fun a ha b hb ↦
Mathlib/Algebra/Star/Subalgebra.lean
548
560
/- 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.AlgebraicGeometry.Morphisms.Constructors import Mathlib.RingTheory.LocalProperties.Basic import Mathlib.RingTheory.RingHom.Locally /-! # Properties of morphisms from properties of ring homs. We provide the basic framework for talking about properties of morphisms that come from properties of ring homs. For `P` a property of ring homs, we have two ways of defining a property of scheme morphisms: Let `f : X ⟶ Y`, - `targetAffineLocally (affineAnd P)`: the preimage of an affine open `U = Spec A` is affine (`= Spec B`) and `A ⟶ B` satisfies `P`. (in `Mathlib/AlgebraicGeometry/Morphisms/AffineAnd.lean`) - `affineLocally P`: For each pair of affine open `U = Spec A ⊆ X` and `V = Spec B ⊆ f ⁻¹' U`, the ring hom `A ⟶ B` satisfies `P`. For these notions to be well defined, we require `P` be a sufficient local property. For the former, `P` should be local on the source (`RingHom.RespectsIso P`, `RingHom.LocalizationPreserves P`, `RingHom.OfLocalizationSpan`), and `targetAffineLocally (affine_and P)` will be local on the target. For the latter `P` should be local on the target (`RingHom.PropertyIsLocal P`), and `affineLocally P` will be local on both the source and the target. We also provide the following interface: ## `HasRingHomProperty` `HasRingHomProperty P Q` is a type class asserting that `P` is local at the target and the source, and for `f : Spec B ⟶ Spec A`, it is equivalent to the ring hom property `Q` on `Γ(f)`. For `HasRingHomProperty P Q` and `f : X ⟶ Y`, we provide these API lemmas: - `AlgebraicGeometry.HasRingHomProperty.iff_appLE`: `P f` if and only if `Q (f.appLE U V _)` for all affine `U : Opens Y` and `V : Opens X`. - `AlgebraicGeometry.HasRingHomProperty.iff_of_source_openCover`: If `Y` is affine, `P f ↔ ∀ i, Q ((𝒰.map i ≫ f).appTop)` for an affine open cover `𝒰` of `X`. - `AlgebraicGeometry.HasRingHomProperty.iff_of_isAffine`: If `X` and `Y` are affine, then `P f ↔ Q (f.appTop)`. - `AlgebraicGeometry.HasRingHomProperty.Spec_iff`: `P (Spec.map φ) ↔ Q φ` - `AlgebraicGeometry.HasRingHomProperty.iff_of_iSup_eq_top`: If `Y` is affine, `P f ↔ ∀ i, Q (f.appLE ⊤ (U i) _)` for a family `U` of affine opens of `X`. - `AlgebraicGeometry.HasRingHomProperty.of_isOpenImmersion`: If `f` is an open immersion then `P f`. - `AlgebraicGeometry.HasRingHomProperty.isStableUnderBaseChange`: If `Q` is stable under base change, then so is `P`. We also provide the instances `P.IsMultiplicative`, `P.IsStableUnderComposition`, `IsLocalAtTarget P`, `IsLocalAtSource P`. -/ -- Explicit universe annotations were used in this file to improve performance https://github.com/leanprover-community/mathlib4/issues/12737 universe u open CategoryTheory Opposite TopologicalSpace CategoryTheory.Limits AlgebraicGeometry namespace RingHom variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop) theorem IsStableUnderBaseChange.pullback_fst_appTop (hP : IsStableUnderBaseChange P) (hP' : RespectsIso P) {X Y S : Scheme} [IsAffine X] [IsAffine Y] [IsAffine S] (f : X ⟶ S) (g : Y ⟶ S) (H : P g.appTop.hom) : P (pullback.fst f g).appTop.hom := by -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11224): change `rw` to `erw` erw [← PreservesPullback.iso_inv_fst AffineScheme.forgetToScheme (AffineScheme.ofHom f) (AffineScheme.ofHom g)] rw [Scheme.comp_appTop, CommRingCat.hom_comp, hP'.cancel_right_isIso, AffineScheme.forgetToScheme_map] have := congr_arg Quiver.Hom.unop (PreservesPullback.iso_hom_fst AffineScheme.Γ.rightOp (AffineScheme.ofHom f) (AffineScheme.ofHom g)) simp only [AffineScheme.Γ, Functor.rightOp_obj, Functor.comp_obj, Functor.op_obj, unop_comp, AffineScheme.forgetToScheme_obj, Scheme.Γ_obj, Functor.rightOp_map, Functor.comp_map, Functor.op_map, Quiver.Hom.unop_op, AffineScheme.forgetToScheme_map, Scheme.Γ_map] at this rw [← this, CommRingCat.hom_comp, hP'.cancel_right_isIso, ← pushoutIsoUnopPullback_inl_hom, CommRingCat.hom_comp, hP'.cancel_right_isIso] exact hP.pushout_inl _ hP' _ _ H @[deprecated (since := "2024-11-23")] alias IsStableUnderBaseChange.pullback_fst_app_top := IsStableUnderBaseChange.pullback_fst_appTop end RingHom namespace AlgebraicGeometry section affineLocally variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop) /-- For `P` a property of ring homomorphisms, `sourceAffineLocally P` holds for `f : X ⟶ Y` whenever `P` holds for the restriction of `f` on every affine open subset of `X`. -/ def sourceAffineLocally : AffineTargetMorphismProperty := fun X _ f _ => ∀ U : X.affineOpens, P (f.appLE ⊤ U le_top).hom /-- For `P` a property of ring homomorphisms, `affineLocally P` holds for `f : X ⟶ Y` if for each affine open `U = Spec A ⊆ Y` and `V = Spec B ⊆ f ⁻¹' U`, the ring hom `A ⟶ B` satisfies `P`. Also see `affineLocally_iff_affineOpens_le`. -/ abbrev affineLocally : MorphismProperty Scheme.{u} := targetAffineLocally (sourceAffineLocally P) theorem sourceAffineLocally_respectsIso (h₁ : RingHom.RespectsIso P) : (sourceAffineLocally P).toProperty.RespectsIso := by apply AffineTargetMorphismProperty.respectsIso_mk · introv H U have : IsIso (e.hom.appLE (e.hom ''ᵁ U) U.1 (e.hom.preimage_image_eq _).ge) := inferInstanceAs (IsIso (e.hom.app _ ≫ X.presheaf.map (eqToHom (e.hom.preimage_image_eq _).symm).op)) rw [← Scheme.appLE_comp_appLE _ _ ⊤ (e.hom ''ᵁ U) U.1 le_top (e.hom.preimage_image_eq _).ge, CommRingCat.hom_comp, h₁.cancel_right_isIso] exact H ⟨_, U.prop.image_of_isOpenImmersion e.hom⟩ · introv H U rw [Scheme.comp_appLE, CommRingCat.hom_comp, h₁.cancel_left_isIso] exact H U theorem affineLocally_respectsIso (h : RingHom.RespectsIso P) : (affineLocally P).RespectsIso := letI := sourceAffineLocally_respectsIso P h inferInstance open Scheme in theorem sourceAffineLocally_morphismRestrict {X Y : Scheme.{u}} (f : X ⟶ Y) (U : Y.Opens) (hU : IsAffineOpen U) : @sourceAffineLocally P _ _ (f ∣_ U) hU ↔ ∀ (V : X.affineOpens) (e : V.1 ≤ f ⁻¹ᵁ U), P (f.appLE U V e).hom := by dsimp only [sourceAffineLocally] simp only [morphismRestrict_appLE] rw [(affineOpensRestrict (f ⁻¹ᵁ U)).forall_congr_left, Subtype.forall] refine forall₂_congr fun V h ↦ ?_ have := (affineOpensRestrict (f ⁻¹ᵁ U)).apply_symm_apply ⟨V, h⟩ exact f.appLE_congr _ (Opens.ι_image_top _) congr($(this).1.1) (fun f => P f.hom) theorem affineLocally_iff_affineOpens_le {X Y : Scheme.{u}} (f : X ⟶ Y) : affineLocally.{u} P f ↔ ∀ (U : Y.affineOpens) (V : X.affineOpens) (e : V.1 ≤ f ⁻¹ᵁ U.1), P (f.appLE U V e).hom := forall_congr' fun U ↦ sourceAffineLocally_morphismRestrict P f U U.2 theorem sourceAffineLocally_isLocal (h₁ : RingHom.RespectsIso P) (h₂ : RingHom.LocalizationAwayPreserves P) (h₃ : RingHom.OfLocalizationSpan P) : (sourceAffineLocally P).IsLocal := by constructor · exact sourceAffineLocally_respectsIso P h₁ · intro X Y _ f r H rw [sourceAffineLocally_morphismRestrict] intro U hU have : X.basicOpen (f.appLE ⊤ U (by simp) r) = U := by simp only [Scheme.Hom.appLE, Opens.map_top, CommRingCat.comp_apply, RingHom.coe_comp, Function.comp_apply] rw [Scheme.basicOpen_res] simpa using hU rw [← f.appLE_congr _ rfl this (fun f => P f.hom), IsAffineOpen.appLE_eq_away_map f (isAffineOpen_top Y) U.2 _ r] simp only [CommRingCat.hom_ofHom] apply (config := { allowSynthFailures := true }) h₂ exact H U · introv hs hs' U apply h₃ _ _ hs intro r simp_rw [sourceAffineLocally_morphismRestrict] at hs' have := hs' r ⟨X.basicOpen (f.appLE ⊤ U le_top r.1), U.2.basicOpen (f.appLE ⊤ U le_top r.1)⟩ (by simp [Scheme.Hom.appLE]) rwa [IsAffineOpen.appLE_eq_away_map f (isAffineOpen_top Y) U.2, CommRingCat.hom_ofHom, ← h₁.isLocalization_away_iff] at this variable {P} lemma affineLocally_le {Q : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop} (hPQ : ∀ {R S : Type u} [CommRing R] [CommRing S] {f : R →+* S}, P f → Q f) : affineLocally P ≤ affineLocally Q := fun _ _ _ hf U V ↦ hPQ (hf U V) open RingHom variable {X Y : Scheme.{u}} {f : X ⟶ Y} /-- If `P` holds for `f` over affine opens `U₂` of `Y` and `V₂` of `X` and `U₁` (resp. `V₁`) are open affine neighborhoods of `x` (resp. `f.base x`), then `P` also holds for `f` over some basic open of `U₁` (resp. `V₁`). -/ lemma exists_basicOpen_le_appLE_of_appLE_of_isAffine (hPa : StableUnderCompositionWithLocalizationAwayTarget P) (hPl : LocalizationAwayPreserves P) (x : X) (U₁ : Y.affineOpens) (U₂ : Y.affineOpens) (V₁ : X.affineOpens) (V₂ : X.affineOpens) (hx₁ : x ∈ V₁.1) (hx₂ : x ∈ V₂.1) (e₂ : V₂.1 ≤ f ⁻¹ᵁ U₂.1) (h₂ : P (f.appLE U₂ V₂ e₂).hom) (hfx₁ : f.base x ∈ U₁.1) : ∃ (r : Γ(Y, U₁)) (s : Γ(X, V₁)) (_ : x ∈ X.basicOpen s) (e : X.basicOpen s ≤ f ⁻¹ᵁ Y.basicOpen r), P (f.appLE (Y.basicOpen r) (X.basicOpen s) e).hom := by obtain ⟨r, r', hBrr', hBfx⟩ := exists_basicOpen_le_affine_inter U₁.2 U₂.2 (f.base x) ⟨hfx₁, e₂ hx₂⟩ have ha : IsAffineOpen (X.basicOpen (f.appLE U₂ V₂ e₂ r')) := V₂.2.basicOpen _ have hxa : x ∈ X.basicOpen (f.appLE U₂ V₂ e₂ r') := by simpa [Scheme.Hom.appLE, ← Scheme.preimage_basicOpen] using And.intro hx₂ (hBrr' ▸ hBfx) obtain ⟨s, s', hBss', hBx⟩ := exists_basicOpen_le_affine_inter V₁.2 ha x ⟨hx₁, hxa⟩ haveI := V₂.2.isLocalization_basicOpen (f.appLE U₂ V₂ e₂ r') haveI := U₂.2.isLocalization_basicOpen r' haveI := ha.isLocalization_basicOpen s' have ers : X.basicOpen s ≤ f ⁻¹ᵁ Y.basicOpen r := by rw [hBss', hBrr'] apply le_trans (X.basicOpen_le _) simp [Scheme.Hom.appLE] have heq : f.appLE (Y.basicOpen r') (X.basicOpen s') (hBrr' ▸ hBss' ▸ ers) = f.appLE (Y.basicOpen r') (X.basicOpen (f.appLE U₂ V₂ e₂ r')) (by simp [Scheme.Hom.appLE]) ≫ CommRingCat.ofHom (algebraMap _ _) := by simp only [Scheme.Hom.appLE, homOfLE_leOfHom, CommRingCat.comp_apply, Category.assoc] congr apply X.presheaf.map_comp refine ⟨r, s, hBx, ers, ?_⟩ · rw [f.appLE_congr _ hBrr' hBss' (fun f => P f.hom), heq] apply hPa _ s' _ rw [U₂.2.appLE_eq_away_map f V₂.2] exact hPl _ _ _ _ h₂ /-- If `P` holds for `f` over affine opens `U₂` of `Y` and `V₂` of `X` and `U₁` (resp. `V₁`) are open neighborhoods of `x` (resp. `f.base x`), then `P` also holds for `f` over some affine open `U'` of `Y` (resp. `V'` of `X`) that is contained in `U₁` (resp. `V₁`). -/ lemma exists_affineOpens_le_appLE_of_appLE
(hPa : StableUnderCompositionWithLocalizationAwayTarget P) (hPl : LocalizationAwayPreserves P) (x : X) (U₁ : Y.Opens) (U₂ : Y.affineOpens) (V₁ : X.Opens) (V₂ : X.affineOpens) (hx₁ : x ∈ V₁) (hx₂ : x ∈ V₂.1) (e₂ : V₂.1 ≤ f ⁻¹ᵁ U₂.1) (h₂ : P (f.appLE U₂ V₂ e₂).hom) (hfx₁ : f.base x ∈ U₁.1) : ∃ (U' : Y.affineOpens) (V' : X.affineOpens) (_ : U'.1 ≤ U₁) (_ : V'.1 ≤ V₁) (_ : x ∈ V'.1) (e : V'.1 ≤ f⁻¹ᵁ U'.1), P (f.appLE U' V' e).hom := by obtain ⟨r, hBr, hBfx⟩ := U₂.2.exists_basicOpen_le ⟨f.base x, hfx₁⟩ (e₂ hx₂) obtain ⟨s, hBs, hBx⟩ := V₂.2.exists_basicOpen_le ⟨x, hx₁⟩ hx₂ obtain ⟨r', s', hBx', e', hf'⟩ := exists_basicOpen_le_appLE_of_appLE_of_isAffine hPa hPl x ⟨Y.basicOpen r, U₂.2.basicOpen _⟩ U₂ ⟨X.basicOpen s, V₂.2.basicOpen _⟩ V₂ hBx hx₂ e₂ h₂ hBfx exact ⟨⟨Y.basicOpen r', (U₂.2.basicOpen _).basicOpen _⟩, ⟨X.basicOpen s', (V₂.2.basicOpen _).basicOpen _⟩, le_trans (Y.basicOpen_le _) hBr, le_trans (X.basicOpen_le _) hBs, hBx', e', hf'⟩ end affineLocally /-- `HasRingHomProperty P Q` is a type class asserting that `P` is local at the target and the source, and for `f : Spec B ⟶ Spec A`, it is equivalent to the ring hom property `Q`. To make the proofs easier, we state it instead as 1. `Q` is local (See `RingHom.PropertyIsLocal`)
Mathlib/AlgebraicGeometry/Morphisms/RingHomProperties.lean
224
244
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Degree import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Polynomial.Basic import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred import Mathlib.Order.SuccPred.WithBot /-! # Degree of univariate polynomials ## Main definitions * `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥` * `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0` * `Polynomial.leadingCoeff`: the leading coefficient of a polynomial * `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0 * `Polynomial.nextCoeff`: the next coefficient after the leading coefficient ## Main results * `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials -/ noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbotD 0 /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe] theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbotDBot.gc.le_u_l _ theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbotD_le_iff (fun _ ↦ bot_le) theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbotDBot.gc.monotone_l hpq @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot] · rw [natDegree, degree_C ha, WithBot.unbotD_zero] @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] @[simp] theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] : natDegree (ofNat(n) : R[X]) = 0 := natDegree_natCast _ theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by rw [degree_eq_natDegree h] exact WithBot.succ_coe p.natDegree end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X end NonzeroSemiring section Ring variable [Ring R] @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa variable {p q : R[X]} {ι : Type*} theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h] theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction n with | zero => simp | succ i hi => rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le (add_le_add_right hi _) theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›)
theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero]
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
492
494
/- Copyright (c) 2024 Theodore Hwa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Violeta Hernández Palacios, Junyan Xu, Theodore Hwa -/ import Mathlib.Logic.Hydra import Mathlib.SetTheory.Surreal.Basic /-! ### Surreal multiplication In this file, we show that multiplication of surreal numbers is well-defined, and thus the surreal numbers form a linear ordered commutative ring. An inductive argument proves the following three main theorems: * P1: being numeric is closed under multiplication, * P2: multiplying a numeric pregame by equivalent numeric pregames results in equivalent pregames, * P3: the product of two positive numeric pregames is positive (`mul_pos`). This is Theorem 8 in [Conway2001], or Theorem 3.8 in [SchleicherStoll]. P1 allows us to define multiplication as an operation on numeric pregames, P2 says that this is well-defined as an operation on the quotient by `PGame.Equiv`, namely the surreal numbers, and P3 is an axiom that needs to be satisfied for the surreals to be a `OrderedRing`. We follow the proof in [SchleicherStoll], except that we use the well-foundedness of the hydra relation `CutExpand` on `Multiset PGame` instead of the argument based on a depth function in the paper. In the argument, P3 is stated with four variables `x₁`, `x₂`, `y₁`, `y₂` satisfying `x₁ < x₂` and `y₁ < y₂`, and says that `x₁ * y₂ + x₂ * x₁ < x₁ * y₁ + x₂ * y₂`, which is equivalent to `0 < x₂ - x₁ → 0 < y₂ - y₁ → 0 < (x₂ - x₁) * (y₂ - y₁)`, i.e. `@mul_pos PGame _ (x₂ - x₁) (y₂ - y₁)`. It has to be stated in this form and not in terms of `mul_pos` because we need to show P1, P2 and (a specialized form of) P3 simultaneously, and for example `P1 x y` will be deduced from P3 with variables taking values simpler than `x` or `y` (among other induction hypotheses), but if you subtract two pregames simpler than `x` or `y`, the result may no longer be simpler. The specialized version of P3 is called P4, which takes only three arguments `x₁`, `x₂`, `y` and requires that `y₂ = y` or `-y` and that `y₁` is a left option of `y₂`. After P1, P2 and P4 are shown, a further inductive argument (this time using the `GameAdd` relation) proves P3 in full. Implementation strategy of the inductive argument: we * extract specialized versions (`IH1`, `IH2`, `IH3`, `IH4` and `IH24`) of the induction hypothesis that are easier to apply (taking `IsOption` arguments directly), and * show they are invariant under certain symmetries (permutation and negation of arguments) and that the induction hypothesis indeed implies the specialized versions. * utilize the symmetries to minimize calculation. The whole proof features a clear separation into lemmas of different roles: * verification of symmetry properties of P and IH (`P3_comm`, `ih1_neg_left`, etc.), * calculations that connect P1, P2, P3, and inequalities between the product of two surreals and its options (`mulOption_lt_iff_P1`, etc.), * specializations of the induction hypothesis (`numeric_option_mul`, `ih1`, `ih1_swap`, `ih₁₂`, `ih4`, etc.), * application of specialized induction hypothesis (`P1_of_ih`, `mul_right_le_of_equiv`, `P3_of_lt`, etc.). ## References * [Conway, *On numbers and games*][Conway2001] * [Schleicher, Stoll, *An introduction to Conway's games and numbers*][SchleicherStoll] -/ universe u open SetTheory Game PGame WellFounded namespace Surreal.Multiplication /-- The nontrivial part of P1 in [SchleicherStoll] says that the left options of `x * y` are less than the right options, and this is the general form of these statements. -/ def P1 (x₁ x₂ x₃ y₁ y₂ y₃ : PGame) := ⟦x₁ * y₁⟧ + ⟦x₂ * y₂⟧ - ⟦x₁ * y₂⟧ < ⟦x₃ * y₁⟧ + ⟦x₂ * y₃⟧ - (⟦x₃ * y₃⟧ : Game) /-- The proposition P2, without numericity assumptions. -/ def P2 (x₁ x₂ y : PGame) := x₁ ≈ x₂ → ⟦x₁ * y⟧ = (⟦x₂ * y⟧ : Game) /-- The proposition P3, without the `x₁ < x₂` and `y₁ < y₂` assumptions. -/ def P3 (x₁ x₂ y₁ y₂ : PGame) := ⟦x₁ * y₂⟧ + ⟦x₂ * y₁⟧ < ⟦x₁ * y₁⟧ + (⟦x₂ * y₂⟧ : Game) /-- The proposition P4, without numericity assumptions. In the references, the second part of the conjunction is stated as `∀ j, P3 x₁ x₂ y (y.moveRight j)`, which is equivalent to our statement by `P3_comm` and `P3_neg`. We choose to state everything in terms of left options for uniform treatment. -/ def P4 (x₁ x₂ y : PGame) := x₁ < x₂ → (∀ i, P3 x₁ x₂ (y.moveLeft i) y) ∧ ∀ j, P3 x₁ x₂ ((-y).moveLeft j) (-y) /-- The conjunction of P2 and P4. -/ def P24 (x₁ x₂ y : PGame) : Prop := P2 x₁ x₂ y ∧ P4 x₁ x₂ y variable {x x₁ x₂ x₃ x' y y₁ y₂ y₃ y' : PGame.{u}} /-! #### Symmetry properties of P1, P2, P3, and P4 -/
lemma P3_comm : P3 x₁ x₂ y₁ y₂ ↔ P3 y₁ y₂ x₁ x₂ := by rw [P3, P3, add_comm] congr! 2 <;> rw [quot_mul_comm]
Mathlib/SetTheory/Surreal/Multiplication.lean
96
98
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin -/ import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.RingTheory.DiscreteValuationRing.Basic /-! # p-adic integers This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`. We show that `ℤ_[p]` * is complete, * is nonarchimedean, * is a normed ring, * is a local ring, and * is a discrete valuation ring. The relation between `ℤ_[p]` and `ZMod p` is established in another file. ## Important definitions * `PadicInt` : the type of `p`-adic integers ## Notation We introduce the notation `ℤ_[p]` for the `p`-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open Padic Metric IsLocalRing noncomputable section variable (p : ℕ) [hp : Fact p.Prime] /-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/ def PadicInt : Type := {x : ℚ_[p] // ‖x‖ ≤ 1} /-- The ring of `p`-adic integers. -/ notation "ℤ_[" p "]" => PadicInt p namespace PadicInt variable {p} {x y : ℤ_[p]} /-! ### Ring structure and coercion to `ℚ_[p]` -/ instance : Coe ℤ_[p] ℚ_[p] := ⟨Subtype.val⟩ theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := Subtype.ext variable (p) /-- The `p`-adic integers as a subring of `ℚ_[p]`. -/ def subring : Subring ℚ_[p] where carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 } zero_mem' := by norm_num one_mem' := by norm_num add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩ mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one₀ hx (norm_nonneg _) hy neg_mem' hx := (norm_neg _).trans_le hx @[simp] theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl variable {p} instance instCommRing : CommRing ℤ_[p] := inferInstanceAs <| CommRing (subring p) instance : Inhabited ℤ_[p] := ⟨0⟩ @[simp] theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl @[simp, norm_cast] theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl @[simp, norm_cast] theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl @[simp, norm_cast] theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl @[simp, norm_cast] theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl @[simp, norm_cast] theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl @[simp] lemma coe_eq_zero : (x : ℚ_[p]) = 0 ↔ x = 0 := by rw [← coe_zero, Subtype.coe_inj] lemma coe_ne_zero : (x : ℚ_[p]) ≠ 0 ↔ x ≠ 0 := coe_eq_zero.not @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl /-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/ def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype @[simp, norm_cast] theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := by simp /-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer. Otherwise, the inverse is defined to be `0`. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0 instance : CharZero ℤ_[p] where cast_injective m n h := Nat.cast_injective (R := ℚ_[p]) (by rw [Subtype.ext_iff] at h; norm_cast at h) @[norm_cast] theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by simp /-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic integer. -/ def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] := ⟨⟦⟨_, h⟩⟧, show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by rw [PadicSeq.norm] split_ifs with hne <;> norm_cast apply padicNorm.of_int⟩ /-! ### Instances We now show that `ℤ_[p]` is a * complete metric space * normed ring * integral domain -/ variable (p) instance : MetricSpace ℤ_[p] := Subtype.metricSpace instance : IsUltrametricDist ℤ_[p] := IsUltrametricDist.subtype _ instance completeSpace : CompleteSpace ℤ_[p] := have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const this.completeSpace_coe instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩ variable {p} in theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl instance : NormedCommRing ℤ_[p] where __ := instCommRing dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ ↦ rfl norm_mul_le := by simp [norm_def] instance : NormOneClass ℤ_[p] := ⟨norm_def.trans norm_one⟩ instance : NormMulClass ℤ_[p] := ⟨fun x y ↦ by simp [norm_def]⟩ instance : IsDomain ℤ_[p] := NoZeroDivisors.to_isDomain _ variable {p} /-! ### Norm -/ theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2 theorem nonarchimedean (q r : ℤ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := padicNormE.nonarchimedean _ _ theorem norm_add_eq_max_of_ne {q r : ℤ_[p]} : ‖q‖ ≠ ‖r‖ → ‖q + r‖ = max ‖q‖ ‖r‖ := padicNormE.add_eq_max_of_ne theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_right) h theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_left) h @[simp] theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by simp [norm_def] theorem norm_intCast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by simp [norm_def] @[simp] theorem norm_eq_padic_norm {q : ℚ_[p]} (hq : ‖q‖ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ‖q‖ := rfl @[simp] theorem norm_p : ‖(p : ℤ_[p])‖ = (p : ℝ)⁻¹ := padicNormE.norm_p theorem norm_p_pow (n : ℕ) : ‖(p : ℤ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by simp private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ := ⟨fun n => f n, fun _ hε => by simpa [norm, norm_def] using f.cauchy hε⟩ variable (p) instance complete : CauSeq.IsComplete ℤ_[p] norm := ⟨fun f => have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 := padicNormE_lim_le zero_lt_one fun _ => norm_le_one _ ⟨⟨_, hqn⟩, fun ε => by simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε⟩⟩ theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹ use k rw [← inv_lt_inv₀ hε (zpow_pos _ _)] · rw [zpow_neg, inv_inv, zpow_natCast] apply lt_of_lt_of_le hk norm_cast apply le_of_lt convert Nat.lt_pow_self _ using 1 exact hp.1.one_lt · exact mod_cast hp.1.pos theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε) use k rw [show (p : ℝ) = (p : ℚ) by simp] at hk exact mod_cast hk variable {p} theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by rwa [norm_intCast_eq_padic_norm] padicNormE.norm_int_lt_one_iff_dvd k theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} : ‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by simpa [norm_intCast_eq_padic_norm] padicNormE.norm_int_le_pow_iff_dvd _ _ /-! ### Valuation on `ℤ_[p]` -/ lemma valuation_coe_nonneg : 0 ≤ (x : ℚ_[p]).valuation := by obtain rfl | hx := eq_or_ne x 0 · simp have := x.2 rwa [Padic.norm_eq_zpow_neg_valuation <| coe_ne_zero.2 hx, zpow_le_one_iff_right₀, neg_nonpos] at this exact mod_cast hp.out.one_lt /-- `PadicInt.valuation` lifts the `p`-adic valuation on `ℚ` to `ℤ_[p]`. -/ def valuation (x : ℤ_[p]) : ℕ := (x : ℚ_[p]).valuation.toNat @[simp, norm_cast] lemma valuation_coe (x : ℤ_[p]) : (x : ℚ_[p]).valuation = x.valuation := by simp [valuation, valuation_coe_nonneg] @[simp] lemma valuation_zero : valuation (0 : ℤ_[p]) = 0 := by simp [valuation] @[simp] lemma valuation_one : valuation (1 : ℤ_[p]) = 0 := by simp [valuation] @[simp] lemma valuation_p : valuation (p : ℤ_[p]) = 1 := by simp [valuation] lemma le_valuation_add (hxy : x + y ≠ 0) : min x.valuation y.valuation ≤ (x + y).valuation := by zify; simpa [← valuation_coe] using Padic.le_valuation_add <| coe_ne_zero.2 hxy @[simp] lemma valuation_mul (hx : x ≠ 0) (hy : y ≠ 0) : (x * y).valuation = x.valuation + y.valuation := by zify; simp [← valuation_coe, Padic.valuation_mul (coe_ne_zero.2 hx) (coe_ne_zero.2 hy)] @[simp] lemma valuation_pow (x : ℤ_[p]) (n : ℕ) : (x ^ n).valuation = n * x.valuation := by zify; simp [← valuation_coe] lemma norm_eq_zpow_neg_valuation {x : ℤ_[p]} (hx : x ≠ 0) : ‖x‖ = p ^ (-x.valuation : ℤ) := by simp [norm_def, Padic.norm_eq_zpow_neg_valuation <| coe_ne_zero.2 hx] @[deprecated (since := "2024-12-10")] alias norm_eq_pow_val := norm_eq_zpow_neg_valuation
-- TODO: Do we really need this lemma? @[simp]
Mathlib/NumberTheory/Padics/PadicIntegers.lean
296
298
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Kim Morrison -/ import Mathlib.Algebra.Group.Ext import Mathlib.CategoryTheory.Simple import Mathlib.CategoryTheory.Linear.Basic import Mathlib.CategoryTheory.Endomorphism import Mathlib.FieldTheory.IsAlgClosed.Spectrum /-! # Schur's lemma We first prove the part of Schur's Lemma that holds in any preadditive category with kernels, that any nonzero morphism between simple objects is an isomorphism. Second, we prove Schur's lemma for `𝕜`-linear categories with finite dimensional hom spaces, over an algebraically closed field `𝕜`: the hom space `X ⟶ Y` between simple objects `X` and `Y` is at most one dimensional, and is 1-dimensional iff `X` and `Y` are isomorphic. -/ namespace CategoryTheory open CategoryTheory.Limits variable {C : Type*} [Category C] variable [Preadditive C] -- See also `epi_of_nonzero_to_simple`, which does not require `Preadditive C`. theorem mono_of_nonzero_from_simple [HasKernels C] {X Y : C} [Simple X] {f : X ⟶ Y} (w : f ≠ 0) : Mono f := Preadditive.mono_of_kernel_zero (kernel_zero_of_nonzero_from_simple w) /-- The part of **Schur's lemma** that holds in any preadditive category with kernels: that a nonzero morphism between simple objects is an isomorphism. -/ theorem isIso_of_hom_simple [HasKernels C] {X Y : C} [Simple X] [Simple Y] {f : X ⟶ Y} (w : f ≠ 0) : IsIso f := haveI := mono_of_nonzero_from_simple w isIso_of_mono_of_nonzero w /-- As a corollary of Schur's lemma for preadditive categories, any morphism between simple objects is (exclusively) either an isomorphism or zero. -/ theorem isIso_iff_nonzero [HasKernels C] {X Y : C} [Simple X] [Simple Y] (f : X ⟶ Y) : IsIso f ↔ f ≠ 0 := ⟨fun I => by intro h apply id_nonzero X simp only [← IsIso.hom_inv_id f, h, zero_comp], fun w => isIso_of_hom_simple w⟩ open scoped Classical in /-- In any preadditive category with kernels, the endomorphisms of a simple object form a division ring. -/ noncomputable instance [HasKernels C] {X : C} [Simple X] : DivisionRing (End X) where inv f := if h : f = 0 then 0 else haveI := isIso_of_hom_simple h; inv f exists_pair_ne := ⟨𝟙 X, 0, id_nonzero _⟩ inv_zero := dif_pos rfl mul_inv_cancel f hf := by dsimp rw [dif_neg hf] haveI := isIso_of_hom_simple hf exact IsIso.inv_hom_id f nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl open Module section variable (𝕜 : Type*) [DivisionRing 𝕜] /-- Part of **Schur's lemma** for `𝕜`-linear categories: the hom space between two non-isomorphic simple objects is 0-dimensional. -/ theorem finrank_hom_simple_simple_eq_zero_of_not_iso [HasKernels C] [Linear 𝕜 C] {X Y : C} [Simple X] [Simple Y] (h : (X ≅ Y) → False) : finrank 𝕜 (X ⟶ Y) = 0 := haveI := subsingleton_of_forall_eq (0 : X ⟶ Y) fun f => by have p := not_congr (isIso_iff_nonzero f) simp only [Classical.not_not, Ne] at p exact p.mp fun _ => h (asIso f) finrank_zero_of_subsingleton end variable (𝕜 : Type*) [Field 𝕜] variable [IsAlgClosed 𝕜] [Linear 𝕜 C] -- Porting note: the defeq issue in lean3 described below is no longer a problem in Lean4. -- In the proof below we have some difficulty using `I : FiniteDimensional 𝕜 (X ⟶ X)` -- where we need a `FiniteDimensional 𝕜 (End X)`. -- These are definitionally equal, but without eta reduction Lean can't see this. -- To get around this, we use `convert I`, -- then check the various instances agree field-by-field, -- We prove this with the explicit `isIso_iff_nonzero` assumption, -- rather than just `[Simple X]`, as this form is useful for -- Müger's formulation of semisimplicity. /-- An auxiliary lemma for Schur's lemma. If `X ⟶ X` is finite dimensional, and every nonzero endomorphism is invertible, then `X ⟶ X` is 1-dimensional. -/ theorem finrank_endomorphism_eq_one {X : C} (isIso_iff_nonzero : ∀ f : X ⟶ X, IsIso f ↔ f ≠ 0) [I : FiniteDimensional 𝕜 (X ⟶ X)] : finrank 𝕜 (X ⟶ X) = 1 := by have id_nonzero := (isIso_iff_nonzero (𝟙 X)).mp (by infer_instance) refine finrank_eq_one (𝟙 X) id_nonzero ?_ intro f have : Nontrivial (End X) := nontrivial_of_ne _ _ id_nonzero have : FiniteDimensional 𝕜 (End X) := I obtain ⟨c, nu⟩ := spectrum.nonempty_of_isAlgClosed_of_finiteDimensional 𝕜 (End.of f) use c rw [spectrum.mem_iff, IsUnit.sub_iff, isUnit_iff_isIso, isIso_iff_nonzero, Ne, Classical.not_not, sub_eq_zero, Algebra.algebraMap_eq_smul_one] at nu exact nu.symm variable [HasKernels C] /-- **Schur's lemma** for endomorphisms in `𝕜`-linear categories. -/ theorem finrank_endomorphism_simple_eq_one (X : C) [Simple X] [FiniteDimensional 𝕜 (X ⟶ X)] : finrank 𝕜 (X ⟶ X) = 1 := finrank_endomorphism_eq_one 𝕜 isIso_iff_nonzero theorem endomorphism_simple_eq_smul_id {X : C} [Simple X] [FiniteDimensional 𝕜 (X ⟶ X)] (f : X ⟶ X) : ∃ c : 𝕜, c • 𝟙 X = f := (finrank_eq_one_iff_of_nonzero' (𝟙 X) (id_nonzero X)).mp (finrank_endomorphism_simple_eq_one 𝕜 X) f /-- Endomorphisms of a simple object form a field if they are finite dimensional. This can't be an instance as `𝕜` would be undetermined. -/ noncomputable def fieldEndOfFiniteDimensional (X : C) [Simple X] [I : FiniteDimensional 𝕜 (X ⟶ X)] : Field (End X) := by classical exact { (inferInstance : DivisionRing (End X)) with mul_comm := fun f g => by obtain ⟨c, rfl⟩ := endomorphism_simple_eq_smul_id 𝕜 f obtain ⟨d, rfl⟩ := endomorphism_simple_eq_smul_id 𝕜 g simp [← mul_smul, mul_comm c d] } -- There is a symmetric argument that uses `[FiniteDimensional 𝕜 (Y ⟶ Y)]` instead, -- but we don't bother proving that here. /-- **Schur's lemma** for `𝕜`-linear categories: if hom spaces are finite dimensional, then the hom space between simples is at most 1-dimensional. See `finrank_hom_simple_simple_eq_one_iff` and `finrank_hom_simple_simple_eq_zero_iff` below for the refinements when we know whether or not the simples are isomorphic. -/ theorem finrank_hom_simple_simple_le_one (X Y : C) [FiniteDimensional 𝕜 (X ⟶ X)] [Simple X] [Simple Y] : finrank 𝕜 (X ⟶ Y) ≤ 1 := by obtain (h|h) := subsingleton_or_nontrivial (X ⟶ Y) · rw [finrank_zero_of_subsingleton] exact zero_le_one · obtain ⟨f, nz⟩ := (nontrivial_iff_exists_ne 0).mp h haveI fi := (isIso_iff_nonzero f).mpr nz refine finrank_le_one f ?_
intro g obtain ⟨c, w⟩ := endomorphism_simple_eq_smul_id 𝕜 (g ≫ inv f) exact ⟨c, by simpa using w =≫ f⟩ theorem finrank_hom_simple_simple_eq_one_iff (X Y : C) [FiniteDimensional 𝕜 (X ⟶ X)] [FiniteDimensional 𝕜 (X ⟶ Y)] [Simple X] [Simple Y] : finrank 𝕜 (X ⟶ Y) = 1 ↔ Nonempty (X ≅ Y) := by fconstructor · intro h rw [finrank_eq_one_iff'] at h obtain ⟨f, nz, -⟩ := h
Mathlib/CategoryTheory/Preadditive/Schur.lean
164
174
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop import Mathlib.Algebra.Ring.Action.Rat import Mathlib.Data.Finset.Sort import Mathlib.Tactic.FastInstance /-! # Theory of univariate polynomials This file defines `Polynomial R`, the type of univariate polynomials over the semiring `R`, builds a semiring structure on it, and gives basic definitions that are expanded in other files in this directory. ## Main definitions * `monomial n a` is the polynomial `a X^n`. Note that `monomial n` is defined as an `R`-linear map. * `C a` is the constant polynomial `a`. Note that `C` is defined as a ring homomorphism. * `X` is the polynomial `X`, i.e., `monomial 1 1`. * `p.sum f` is `∑ n ∈ p.support, f n (p.coeff n)`, i.e., one sums the values of functions applied to coefficients of the polynomial `p`. * `p.erase n` is the polynomial `p` in which one removes the `c X^n` term. There are often two natural variants of lemmas involving sums, depending on whether one acts on the polynomials, or on the function. The naming convention is that one adds `index` when acting on the polynomials. For instance, * `sum_add_index` states that `(p + q).sum f = p.sum f + q.sum f`; * `sum_add` states that `p.sum (fun n x ↦ f n x + g n x) = p.sum f + p.sum g`. * Notation to refer to `Polynomial R`, as `R[X]` or `R[t]`. ## Implementation Polynomials are defined using `R[ℕ]`, where `R` is a semiring. The variable `X` commutes with every polynomial `p`: lemma `X_mul` proves the identity `X * p = p * X`. The relationship to `R[ℕ]` is through a structure to make polynomials irreducible from the point of view of the kernel. Most operations are irreducible since Lean can not compute anyway with `AddMonoidAlgebra`. There are two exceptions that we make semireducible: * The zero polynomial, so that its coefficients are definitionally equal to `0`. * The scalar action, to permit typeclass search to unfold it to resolve potential instance diamonds. The raw implementation of the equivalence between `R[X]` and `R[ℕ]` is done through `ofFinsupp` and `toFinsupp` (or, equivalently, `rcases p` when `p` is a polynomial gives an element `q` of `R[ℕ]`, and conversely `⟨q⟩` gives back `p`). The equivalence is also registered as a ring equiv in `Polynomial.toFinsuppIso`. These should in general not be used once the basic API for polynomials is constructed. -/ noncomputable section /-- `Polynomial R` is the type of univariate polynomials over `R`, denoted as `R[X]` within the `Polynomial` namespace. Polynomials should be seen as (semi-)rings with the additional constructor `X`. The embedding from `R` is called `C`. -/ structure Polynomial (R : Type*) [Semiring R] where ofFinsupp :: toFinsupp : AddMonoidAlgebra R ℕ @[inherit_doc] scoped[Polynomial] notation:9000 R "[X]" => Polynomial R open AddMonoidAlgebra Finset open Finsupp hiding single open Function hiding Commute namespace Polynomial universe u variable {R : Type u} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} theorem forall_iff_forall_finsupp (P : R[X] → Prop) : (∀ p, P p) ↔ ∀ q : R[ℕ], P ⟨q⟩ := ⟨fun h q => h ⟨q⟩, fun h ⟨p⟩ => h p⟩ theorem exists_iff_exists_finsupp (P : R[X] → Prop) : (∃ p, P p) ↔ ∃ q : R[ℕ], P ⟨q⟩ := ⟨fun ⟨⟨p⟩, hp⟩ => ⟨p, hp⟩, fun ⟨q, hq⟩ => ⟨⟨q⟩, hq⟩⟩ @[simp] theorem eta (f : R[X]) : Polynomial.ofFinsupp f.toFinsupp = f := by cases f; rfl /-! ### Conversions to and from `AddMonoidAlgebra` Since `R[X]` is not defeq to `R[ℕ]`, but instead is a structure wrapping it, we have to copy across all the arithmetic operators manually, along with the lemmas about how they unfold around `Polynomial.ofFinsupp` and `Polynomial.toFinsupp`. -/ section AddMonoidAlgebra private irreducible_def add : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a + b⟩ private irreducible_def neg {R : Type u} [Ring R] : R[X] → R[X] | ⟨a⟩ => ⟨-a⟩ private irreducible_def mul : R[X] → R[X] → R[X] | ⟨a⟩, ⟨b⟩ => ⟨a * b⟩ instance zero : Zero R[X] := ⟨⟨0⟩⟩ instance one : One R[X] := ⟨⟨1⟩⟩ instance add' : Add R[X] := ⟨add⟩ instance neg' {R : Type u} [Ring R] : Neg R[X] := ⟨neg⟩ instance sub {R : Type u} [Ring R] : Sub R[X] := ⟨fun a b => a + -b⟩ instance mul' : Mul R[X] := ⟨mul⟩ -- If the private definitions are accidentally exposed, simplify them away. @[simp] theorem add_eq_add : add p q = p + q := rfl @[simp] theorem mul_eq_mul : mul p q = p * q := rfl instance instNSMul : SMul ℕ R[X] where smul r p := ⟨r • p.toFinsupp⟩ instance smulZeroClass {S : Type*} [SMulZeroClass S R] : SMulZeroClass S R[X] where smul r p := ⟨r • p.toFinsupp⟩ smul_zero a := congr_arg ofFinsupp (smul_zero a) instance {S : Type*} [Zero S] [SMulZeroClass S R] [NoZeroSMulDivisors S R] : NoZeroSMulDivisors S R[X] where eq_zero_or_eq_zero_of_smul_eq_zero eq := (eq_zero_or_eq_zero_of_smul_eq_zero <| congr_arg toFinsupp eq).imp id (congr_arg ofFinsupp) -- to avoid a bug in the `ring` tactic instance (priority := 1) pow : Pow R[X] ℕ where pow p n := npowRec n p @[simp] theorem ofFinsupp_zero : (⟨0⟩ : R[X]) = 0 := rfl @[simp] theorem ofFinsupp_one : (⟨1⟩ : R[X]) = 1 := rfl @[simp] theorem ofFinsupp_add {a b} : (⟨a + b⟩ : R[X]) = ⟨a⟩ + ⟨b⟩ := show _ = add _ _ by rw [add_def] @[simp] theorem ofFinsupp_neg {R : Type u} [Ring R] {a} : (⟨-a⟩ : R[X]) = -⟨a⟩ := show _ = neg _ by rw [neg_def] @[simp] theorem ofFinsupp_sub {R : Type u} [Ring R] {a b} : (⟨a - b⟩ : R[X]) = ⟨a⟩ - ⟨b⟩ := by rw [sub_eq_add_neg, ofFinsupp_add, ofFinsupp_neg] rfl @[simp] theorem ofFinsupp_mul (a b) : (⟨a * b⟩ : R[X]) = ⟨a⟩ * ⟨b⟩ := show _ = mul _ _ by rw [mul_def] @[simp] theorem ofFinsupp_nsmul (a : ℕ) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl @[simp] theorem ofFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b) : (⟨a • b⟩ : R[X]) = (a • ⟨b⟩ : R[X]) := rfl @[simp] theorem ofFinsupp_pow (a) (n : ℕ) : (⟨a ^ n⟩ : R[X]) = ⟨a⟩ ^ n := by change _ = npowRec n _ induction n with | zero => simp [npowRec] | succ n n_ih => simp [npowRec, n_ih, pow_succ] @[simp] theorem toFinsupp_zero : (0 : R[X]).toFinsupp = 0 := rfl @[simp] theorem toFinsupp_one : (1 : R[X]).toFinsupp = 1 := rfl @[simp] theorem toFinsupp_add (a b : R[X]) : (a + b).toFinsupp = a.toFinsupp + b.toFinsupp := by cases a cases b rw [← ofFinsupp_add] @[simp] theorem toFinsupp_neg {R : Type u} [Ring R] (a : R[X]) : (-a).toFinsupp = -a.toFinsupp := by cases a rw [← ofFinsupp_neg] @[simp] theorem toFinsupp_sub {R : Type u} [Ring R] (a b : R[X]) : (a - b).toFinsupp = a.toFinsupp - b.toFinsupp := by rw [sub_eq_add_neg, ← toFinsupp_neg, ← toFinsupp_add] rfl @[simp] theorem toFinsupp_mul (a b : R[X]) : (a * b).toFinsupp = a.toFinsupp * b.toFinsupp := by cases a cases b rw [← ofFinsupp_mul] @[simp] theorem toFinsupp_nsmul (a : ℕ) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl @[simp] theorem toFinsupp_smul {S : Type*} [SMulZeroClass S R] (a : S) (b : R[X]) : (a • b).toFinsupp = a • b.toFinsupp := rfl @[simp] theorem toFinsupp_pow (a : R[X]) (n : ℕ) : (a ^ n).toFinsupp = a.toFinsupp ^ n := by cases a rw [← ofFinsupp_pow] theorem _root_.IsSMulRegular.polynomial {S : Type*} [SMulZeroClass S R] {a : S} (ha : IsSMulRegular R a) : IsSMulRegular R[X] a | ⟨_x⟩, ⟨_y⟩, h => congr_arg _ <| ha.finsupp (Polynomial.ofFinsupp.inj h) theorem toFinsupp_injective : Function.Injective (toFinsupp : R[X] → AddMonoidAlgebra _ _) := fun ⟨_x⟩ ⟨_y⟩ => congr_arg _ @[simp] theorem toFinsupp_inj {a b : R[X]} : a.toFinsupp = b.toFinsupp ↔ a = b := toFinsupp_injective.eq_iff @[simp] theorem toFinsupp_eq_zero {a : R[X]} : a.toFinsupp = 0 ↔ a = 0 := by rw [← toFinsupp_zero, toFinsupp_inj] @[simp] theorem toFinsupp_eq_one {a : R[X]} : a.toFinsupp = 1 ↔ a = 1 := by rw [← toFinsupp_one, toFinsupp_inj] /-- A more convenient spelling of `Polynomial.ofFinsupp.injEq` in terms of `Iff`. -/ theorem ofFinsupp_inj {a b} : (⟨a⟩ : R[X]) = ⟨b⟩ ↔ a = b := iff_of_eq (ofFinsupp.injEq _ _) @[simp] theorem ofFinsupp_eq_zero {a} : (⟨a⟩ : R[X]) = 0 ↔ a = 0 := by rw [← ofFinsupp_zero, ofFinsupp_inj] @[simp] theorem ofFinsupp_eq_one {a} : (⟨a⟩ : R[X]) = 1 ↔ a = 1 := by rw [← ofFinsupp_one, ofFinsupp_inj] instance inhabited : Inhabited R[X] := ⟨0⟩ instance instNatCast : NatCast R[X] where natCast n := ofFinsupp n @[simp] theorem ofFinsupp_natCast (n : ℕ) : (⟨n⟩ : R[X]) = n := rfl @[simp] theorem toFinsupp_natCast (n : ℕ) : (n : R[X]).toFinsupp = n := rfl @[simp] theorem ofFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (⟨ofNat(n)⟩ : R[X]) = ofNat(n) := rfl @[simp] theorem toFinsupp_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : R[X]).toFinsupp = ofNat(n) := rfl instance semiring : Semiring R[X] := fast_instance% Function.Injective.semiring toFinsupp toFinsupp_injective toFinsupp_zero toFinsupp_one toFinsupp_add toFinsupp_mul (fun _ _ => toFinsupp_nsmul _ _) toFinsupp_pow fun _ => rfl instance distribSMul {S} [DistribSMul S R] : DistribSMul S R[X] := fast_instance% Function.Injective.distribSMul ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul instance distribMulAction {S} [Monoid S] [DistribMulAction S R] : DistribMulAction S R[X] := fast_instance% Function.Injective.distribMulAction ⟨⟨toFinsupp, toFinsupp_zero (R := R)⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul instance faithfulSMul {S} [SMulZeroClass S R] [FaithfulSMul S R] : FaithfulSMul S R[X] where eq_of_smul_eq_smul {_s₁ _s₂} h := eq_of_smul_eq_smul fun a : ℕ →₀ R => congr_arg toFinsupp (h ⟨a⟩) instance module {S} [Semiring S] [Module S R] : Module S R[X] := fast_instance% Function.Injective.module _ ⟨⟨toFinsupp, toFinsupp_zero⟩, toFinsupp_add⟩ toFinsupp_injective toFinsupp_smul instance smulCommClass {S₁ S₂} [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [SMulCommClass S₁ S₂ R] : SMulCommClass S₁ S₂ R[X] := ⟨by rintro m n ⟨f⟩ simp_rw [← ofFinsupp_smul, smul_comm m n f]⟩ instance isScalarTower {S₁ S₂} [SMul S₁ S₂] [SMulZeroClass S₁ R] [SMulZeroClass S₂ R] [IsScalarTower S₁ S₂ R] : IsScalarTower S₁ S₂ R[X] := ⟨by rintro _ _ ⟨⟩ simp_rw [← ofFinsupp_smul, smul_assoc]⟩ instance isScalarTower_right {α K : Type*} [Semiring K] [DistribSMul α K] [IsScalarTower α K K] : IsScalarTower α K[X] K[X] := ⟨by rintro _ ⟨⟩ ⟨⟩ simp_rw [smul_eq_mul, ← ofFinsupp_smul, ← ofFinsupp_mul, ← ofFinsupp_smul, smul_mul_assoc]⟩ instance isCentralScalar {S} [SMulZeroClass S R] [SMulZeroClass Sᵐᵒᵖ R] [IsCentralScalar S R] : IsCentralScalar S R[X] := ⟨by rintro _ ⟨⟩ simp_rw [← ofFinsupp_smul, op_smul_eq_smul]⟩ instance unique [Subsingleton R] : Unique R[X] := { Polynomial.inhabited with uniq := by rintro ⟨x⟩ apply congr_arg ofFinsupp simp [eq_iff_true_of_subsingleton] } variable (R) /-- Ring isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps apply symm_apply] def toFinsuppIso : R[X] ≃+* R[ℕ] where toFun := toFinsupp invFun := ofFinsupp left_inv := fun ⟨_p⟩ => rfl right_inv _p := rfl map_mul' := toFinsupp_mul map_add' := toFinsupp_add instance [DecidableEq R] : DecidableEq R[X] := @Equiv.decidableEq R[X] _ (toFinsuppIso R).toEquiv (Finsupp.instDecidableEq) /-- Linear isomorphism between `R[X]` and `R[ℕ]`. This is just an implementation detail, but it can be useful to transfer results from `Finsupp` to polynomials. -/ @[simps!] def toFinsuppIsoLinear : R[X] ≃ₗ[R] R[ℕ] where __ := toFinsuppIso R map_smul' _ _ := rfl end AddMonoidAlgebra theorem ofFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[ℕ]) : (⟨∑ i ∈ s, f i⟩ : R[X]) = ∑ i ∈ s, ⟨f i⟩ := map_sum (toFinsuppIso R).symm f s theorem toFinsupp_sum {ι : Type*} (s : Finset ι) (f : ι → R[X]) : (∑ i ∈ s, f i : R[X]).toFinsupp = ∑ i ∈ s, (f i).toFinsupp := map_sum (toFinsuppIso R) f s /-- The set of all `n` such that `X^n` has a non-zero coefficient. -/ def support : R[X] → Finset ℕ | ⟨p⟩ => p.support @[simp] theorem support_ofFinsupp (p) : support (⟨p⟩ : R[X]) = p.support := by rw [support] theorem support_toFinsupp (p : R[X]) : p.toFinsupp.support = p.support := by rw [support] @[simp] theorem support_zero : (0 : R[X]).support = ∅ := rfl @[simp] theorem support_eq_empty : p.support = ∅ ↔ p = 0 := by rcases p with ⟨⟩ simp [support] @[simp] lemma support_nonempty : p.support.Nonempty ↔ p ≠ 0 := Finset.nonempty_iff_ne_empty.trans support_eq_empty.not theorem card_support_eq_zero : #p.support = 0 ↔ p = 0 := by simp /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (n : ℕ) : R →ₗ[R] R[X] where toFun t := ⟨Finsupp.single n t⟩ -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp`. map_add' x y := by simp; rw [ofFinsupp_add] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [← ofFinsupp_smul]`. map_smul' r x := by simp; rw [← ofFinsupp_smul, smul_single'] @[simp] theorem toFinsupp_monomial (n : ℕ) (r : R) : (monomial n r).toFinsupp = Finsupp.single n r := by simp [monomial] @[simp] theorem ofFinsupp_single (n : ℕ) (r : R) : (⟨Finsupp.single n r⟩ : R[X]) = monomial n r := by simp [monomial] @[simp] theorem monomial_zero_right (n : ℕ) : monomial n (0 : R) = 0 := (monomial n).map_zero -- This is not a `simp` lemma as `monomial_zero_left` is more general. theorem monomial_zero_one : monomial 0 (1 : R) = 1 := rfl -- TODO: can't we just delete this one? theorem monomial_add (n : ℕ) (r s : R) : monomial n (r + s) = monomial n r + monomial n s := (monomial n).map_add _ _ theorem monomial_mul_monomial (n m : ℕ) (r s : R) : monomial n r * monomial m s = monomial (n + m) (r * s) := toFinsupp_injective <| by simp only [toFinsupp_monomial, toFinsupp_mul, AddMonoidAlgebra.single_mul_single] @[simp] theorem monomial_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r ^ k = monomial (n * k) (r ^ k) := by induction k with | zero => simp [pow_zero, monomial_zero_one] | succ k ih => simp [pow_succ, ih, monomial_mul_monomial, mul_add, add_comm] theorem smul_monomial {S} [SMulZeroClass S R] (a : S) (n : ℕ) (b : R) : a • monomial n b = monomial n (a • b) := toFinsupp_injective <| AddMonoidAlgebra.smul_single _ _ _ theorem monomial_injective (n : ℕ) : Function.Injective (monomial n : R → R[X]) := (toFinsuppIso R).symm.injective.comp (single_injective n) @[simp] theorem monomial_eq_zero_iff (t : R) (n : ℕ) : monomial n t = 0 ↔ t = 0 := LinearMap.map_eq_zero_iff _ (Polynomial.monomial_injective n) theorem monomial_eq_monomial_iff {m n : ℕ} {a b : R} : monomial m a = monomial n b ↔ m = n ∧ a = b ∨ a = 0 ∧ b = 0 := by rw [← toFinsupp_inj, toFinsupp_monomial, toFinsupp_monomial, Finsupp.single_eq_single_iff] theorem support_add : (p + q).support ⊆ p.support ∪ q.support := by simpa [support] using Finsupp.support_add /-- `C a` is the constant polynomial `a`. `C` is provided as a ring homomorphism. -/ def C : R →+* R[X] := { monomial 0 with map_one' := by simp [monomial_zero_one] map_mul' := by simp [monomial_mul_monomial] map_zero' := by simp } @[simp] theorem monomial_zero_left (a : R) : monomial 0 a = C a := rfl @[simp] theorem toFinsupp_C (a : R) : (C a).toFinsupp = single 0 a := rfl theorem C_0 : C (0 : R) = 0 := by simp theorem C_1 : C (1 : R) = 1 := rfl theorem C_mul : C (a * b) = C a * C b := C.map_mul a b theorem C_add : C (a + b) = C a + C b := C.map_add a b @[simp] theorem smul_C {S} [SMulZeroClass S R] (s : S) (r : R) : s • C r = C (s • r) := smul_monomial _ _ r theorem C_pow : C (a ^ n) = C a ^ n := C.map_pow a n theorem C_eq_natCast (n : ℕ) : C (n : R) = (n : R[X]) := map_natCast C n @[simp] theorem C_mul_monomial : C a * monomial n b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, zero_add] @[simp] theorem monomial_mul_C : monomial n a * C b = monomial n (a * b) := by simp only [← monomial_zero_left, monomial_mul_monomial, add_zero] /-- `X` is the polynomial variable (aka indeterminate). -/ def X : R[X] := monomial 1 1 theorem monomial_one_one_eq_X : monomial 1 (1 : R) = X := rfl theorem monomial_one_right_eq_X_pow (n : ℕ) : monomial n (1 : R) = X ^ n := by induction n with | zero => simp [monomial_zero_one] | succ n ih => rw [pow_succ, ← ih, ← monomial_one_one_eq_X, monomial_mul_monomial, mul_one] @[simp] theorem toFinsupp_X : X.toFinsupp = Finsupp.single 1 (1 : R) := rfl theorem X_ne_C [Nontrivial R] (a : R) : X ≠ C a := by intro he simpa using monomial_eq_monomial_iff.1 he /-- `X` commutes with everything, even when the coefficients are noncommutative. -/ theorem X_mul : X * p = p * X := by rcases p with ⟨⟩ simp only [X, ← ofFinsupp_single, ← ofFinsupp_mul, LinearMap.coe_mk, ofFinsupp.injEq] ext simp [AddMonoidAlgebra.mul_apply, AddMonoidAlgebra.sum_single_index, add_comm] theorem X_pow_mul {n : ℕ} : X ^ n * p = p * X ^ n := by induction n with | zero => simp | succ n ih => conv_lhs => rw [pow_succ] rw [mul_assoc, X_mul, ← mul_assoc, ih, mul_assoc, ← pow_succ] /-- Prefer putting constants to the left of `X`. This lemma is the loop-avoiding `simp` version of `Polynomial.X_mul`. -/ @[simp] theorem X_mul_C (r : R) : X * C r = C r * X := X_mul /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul`. -/ @[simp] theorem X_pow_mul_C (r : R) (n : ℕ) : X ^ n * C r = C r * X ^ n := X_pow_mul theorem X_pow_mul_assoc {n : ℕ} : p * X ^ n * q = p * q * X ^ n := by rw [mul_assoc, X_pow_mul, ← mul_assoc] /-- Prefer putting constants to the left of `X ^ n`. This lemma is the loop-avoiding `simp` version of `X_pow_mul_assoc`. -/ @[simp] theorem X_pow_mul_assoc_C {n : ℕ} (r : R) : p * X ^ n * C r = p * C r * X ^ n := X_pow_mul_assoc theorem commute_X (p : R[X]) : Commute X p := X_mul theorem commute_X_pow (p : R[X]) (n : ℕ) : Commute (X ^ n) p := X_pow_mul @[simp] theorem monomial_mul_X (n : ℕ) (r : R) : monomial n r * X = monomial (n + 1) r := by rw [X, monomial_mul_monomial, mul_one] @[simp] theorem monomial_mul_X_pow (n : ℕ) (r : R) (k : ℕ) : monomial n r * X ^ k = monomial (n + k) r := by induction k with | zero => simp | succ k ih => simp [ih, pow_succ, ← mul_assoc, add_assoc] @[simp] theorem X_mul_monomial (n : ℕ) (r : R) : X * monomial n r = monomial (n + 1) r := by rw [X_mul, monomial_mul_X] @[simp] theorem X_pow_mul_monomial (k n : ℕ) (r : R) : X ^ k * monomial n r = monomial (n + k) r := by rw [X_pow_mul, monomial_mul_X_pow] /-- `coeff p n` (often denoted `p.coeff n`) is the coefficient of `X^n` in `p`. -/ def coeff : R[X] → ℕ → R | ⟨p⟩ => p @[simp] theorem coeff_ofFinsupp (p) : coeff (⟨p⟩ : R[X]) = p := by rw [coeff] theorem coeff_injective : Injective (coeff : R[X] → ℕ → R) := by rintro ⟨p⟩ ⟨q⟩ simp only [coeff, DFunLike.coe_fn_eq, imp_self, ofFinsupp.injEq] @[simp] theorem coeff_inj : p.coeff = q.coeff ↔ p = q := coeff_injective.eq_iff theorem toFinsupp_apply (f : R[X]) (i) : f.toFinsupp i = f.coeff i := by cases f; rfl theorem coeff_monomial : coeff (monomial n a) m = if n = m then a else 0 := by simp [coeff, Finsupp.single_apply] @[simp] theorem coeff_monomial_same (n : ℕ) (c : R) : (monomial n c).coeff n = c := Finsupp.single_eq_same theorem coeff_monomial_of_ne {m n : ℕ} (c : R) (h : n ≠ m) : (monomial n c).coeff m = 0 := Finsupp.single_eq_of_ne h @[simp] theorem coeff_zero (n : ℕ) : coeff (0 : R[X]) n = 0 := rfl theorem coeff_one {n : ℕ} : coeff (1 : R[X]) n = if n = 0 then 1 else 0 := by simp_rw [eq_comm (a := n) (b := 0)] exact coeff_monomial @[simp] theorem coeff_one_zero : coeff (1 : R[X]) 0 = 1 := by simp [coeff_one] @[simp] theorem coeff_X_one : coeff (X : R[X]) 1 = 1 := coeff_monomial @[simp] theorem coeff_X_zero : coeff (X : R[X]) 0 = 0 := coeff_monomial @[simp] theorem coeff_monomial_succ : coeff (monomial (n + 1) a) 0 = 0 := by simp [coeff_monomial] theorem coeff_X : coeff (X : R[X]) n = if 1 = n then 1 else 0 := coeff_monomial theorem coeff_X_of_ne_one {n : ℕ} (hn : n ≠ 1) : coeff (X : R[X]) n = 0 := by rw [coeff_X, if_neg hn.symm] @[simp] theorem mem_support_iff : n ∈ p.support ↔ p.coeff n ≠ 0 := by rcases p with ⟨⟩ simp theorem not_mem_support_iff : n ∉ p.support ↔ p.coeff n = 0 := by simp theorem coeff_C : coeff (C a) n = ite (n = 0) a 0 := by convert coeff_monomial (a := a) (m := n) (n := 0) using 2 simp [eq_comm] @[simp] theorem coeff_C_zero : coeff (C a) 0 = a := coeff_monomial theorem coeff_C_ne_zero (h : n ≠ 0) : (C a).coeff n = 0 := by rw [coeff_C, if_neg h] @[simp] lemma coeff_C_succ {r : R} {n : ℕ} : coeff (C r) (n + 1) = 0 := by simp [coeff_C] @[simp] theorem coeff_natCast_ite : (Nat.cast m : R[X]).coeff n = ite (n = 0) m 0 := by simp only [← C_eq_natCast, coeff_C, Nat.cast_ite, Nat.cast_zero] @[simp] theorem coeff_ofNat_zero (a : ℕ) [a.AtLeastTwo] : coeff (ofNat(a) : R[X]) 0 = ofNat(a) := coeff_monomial @[simp] theorem coeff_ofNat_succ (a n : ℕ) [h : a.AtLeastTwo] : coeff (ofNat(a) : R[X]) (n + 1) = 0 := by rw [← Nat.cast_ofNat] simp [-Nat.cast_ofNat] theorem C_mul_X_pow_eq_monomial : ∀ {n : ℕ}, C a * X ^ n = monomial n a | 0 => mul_one _
| n + 1 => by rw [pow_succ, ← mul_assoc, C_mul_X_pow_eq_monomial, X, monomial_mul_monomial, mul_one] @[simp high]
Mathlib/Algebra/Polynomial/Basic.lean
670
673
/- 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 /-! # Split a box along one or more hyperplanes ## Main definitions A hyperplane `{x : ι → ℝ | x i = a}` splits a rectangular box `I : BoxIntegral.Box ι` into two smaller boxes. If `a ∉ Ioo (I.lower i, I.upper i)`, then one of these boxes is empty, so it is not a box in the sense of `BoxIntegral.Box`. We introduce the following definitions. * `BoxIntegral.Box.splitLower I i a` and `BoxIntegral.Box.splitUpper I i a` are these boxes (as `WithBot (BoxIntegral.Box ι)`); * `BoxIntegral.Prepartition.split I i a` is the partition of `I` made of these two boxes (or of one box `I` if one of these boxes is empty); * `BoxIntegral.Prepartition.splitMany I s`, where `s : Finset (ι × ℝ)` is a finite set of hyperplanes `{x : ι → ℝ | x i = a}` encoded as pairs `(i, a)`, is the partition of `I` made by cutting it along all the hyperplanes in `s`. ## Main results The main result `BoxIntegral.Prepartition.exists_iUnion_eq_diff` says that any prepartition `π` of `I` admits a prepartition `π'` of `I` that covers exactly `I \ π.iUnion`. One of these prepartitions is available as `BoxIntegral.Prepartition.compl`. ## Tags rectangular box, partition, hyperplane -/ noncomputable section open Function Set Filter namespace BoxIntegral variable {ι M : Type*} {n : ℕ} namespace Box variable {I : Box ι} {i : ι} {x : ℝ} {y : ι → ℝ} open scoped Classical in /-- Given a box `I` and `x ∈ (I.lower i, I.upper i)`, the hyperplane `{y : ι → ℝ | y i = x}` splits `I` into two boxes. `BoxIntegral.Box.splitLower I i x` is the box `I ∩ {y | y i ≤ x}` (if it is nonempty). As usual, we represent a box that may be empty as `WithBot (BoxIntegral.Box ι)`. -/ def splitLower (I : Box ι) (i : ι) (x : ℝ) : WithBot (Box ι) := mk' I.lower (update I.upper i (min x (I.upper i))) @[simp] theorem coe_splitLower : (splitLower I i x : Set (ι → ℝ)) = ↑I ∩ { y | y i ≤ x } := by rw [splitLower, coe_mk'] ext y simp only [mem_univ_pi, mem_Ioc, mem_inter_iff, mem_coe, mem_setOf_eq, forall_and, ← Pi.le_def, le_update_iff, le_min_iff, and_assoc, and_forall_ne (p := fun j => y j ≤ upper I j) i, mem_def] rw [and_comm (a := y i ≤ x)] theorem splitLower_le : I.splitLower i x ≤ I := withBotCoe_subset_iff.1 <| by simp @[simp] theorem splitLower_eq_bot {i x} : I.splitLower i x = ⊥ ↔ x ≤ I.lower i := by classical rw [splitLower, mk'_eq_bot, exists_update_iff I.upper fun j y => y ≤ I.lower j] simp [(I.lower_lt_upper _).not_le] @[simp] theorem splitLower_eq_self : I.splitLower i x = I ↔ I.upper i ≤ x := by simp [splitLower, update_eq_iff] theorem splitLower_def [DecidableEq ι] {i x} (h : x ∈ Ioo (I.lower i) (I.upper i)) (h' : ∀ j, I.lower j < update I.upper i x j := (forall_update_iff I.upper fun j y => I.lower j < y).2 ⟨h.1, fun _ _ => I.lower_lt_upper _⟩) : I.splitLower i x = (⟨I.lower, update I.upper i x, h'⟩ : Box ι) := by
simp +unfoldPartialApp only [splitLower, mk'_eq_coe, min_eq_left h.2.le, update, and_self]
Mathlib/Analysis/BoxIntegral/Partition/Split.lean
84
85
/- Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Affine import Mathlib.LinearAlgebra.FreeModule.Norm import Mathlib.RingTheory.ClassGroup import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Group law on Weierstrass curves This file proves that the nonsingular rational points on a Weierstrass curve form an abelian group under the geometric group law defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`. ## Mathematical background Let `W` be a Weierstrass curve over a field `F` given by a Weierstrass equation `W(X, Y) = 0` in affine coordinates. As in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`, the set of nonsingular rational points `W⟮F⟯` of `W` consist of the unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. With this description, there is an addition-preserving injection between `W⟮F⟯` and the ideal class group of the *affine coordinate ring* `F[W] := F[X, Y] / ⟨W(X, Y)⟩` of `W`. This is given by mapping `𝓞` to the trivial ideal class and a nonsingular affine point `(x, y)` to the ideal class of the invertible ideal `⟨X - x, Y - y⟩`. Proving that this is well-defined and preserves addition reduces to equalities of integral ideals checked in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul` and in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_mul_XYIdeal` via explicit ideal computations. Now `F[W]` is a free rank two `F[X]`-algebra with basis `{1, Y}`, so every element of `F[W]` is of the form `p + qY` for some `p, q` in `F[X]`, and there is an algebra norm `N : F[W] → F[X]`. Injectivity can then be shown by computing the degree of such a norm `N(p + qY)` in two different ways, which is done in `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis` and in the auxiliary lemmas in the proof of `WeierstrassCurve.Affine.Point.instAddCommGroup`. ## Main definitions * `WeierstrassCurve.Affine.CoordinateRing`: the coordinate ring `F[W]` of a Weierstrass curve `W`. * `WeierstrassCurve.Affine.CoordinateRing.basis`: the power basis of `F[W]` over `F[X]`. ## Main statements * `WeierstrassCurve.Affine.CoordinateRing.instIsDomainCoordinateRing`: the affine coordinate ring of a Weierstrass curve is an integral domain. * `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis`: the degree of the norm of an element in the affine coordinate ring in terms of its power basis. * `WeierstrassCurve.Affine.Point.instAddCommGroup`: the type of nonsingular points `W⟮F⟯` in affine coordinates forms an abelian group under addition. ## References https://drops.dagstuhl.de/storage/00lipics/lipics-vol268-itp2023/LIPIcs.ITP.2023.6/LIPIcs.ITP.2023.6.pdf ## Tags elliptic curve, group law, class group -/ open Ideal Polynomial open scoped nonZeroDivisors Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "eval_simp" : tactic => `(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow]) universe u v namespace WeierstrassCurve.Affine /-! ## Weierstrass curves in affine coordinates -/ variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] (W : Affine R) (f : R →+* S) -- Porting note: in Lean 3, this is a `def` under a `derive comm_ring` tag. -- This generates a reducible instance of `comm_ring` for `coordinate_ring`. In certain -- circumstances this might be extremely slow, because all instances in its definition are unified -- exponentially many times. In this case, one solution is to manually add the local attribute -- `local attribute [irreducible] coordinate_ring.comm_ring` to block this type-level unification. -- In Lean 4, this is no longer an issue and is now an `abbrev`. See Zulip thread: -- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/.E2.9C.94.20class_group.2Emk /-- The affine coordinate ring `R[W] := R[X, Y] / ⟨W(X, Y)⟩` of a Weierstrass curve `W`. -/ abbrev CoordinateRing : Type u := AdjoinRoot W.polynomial /-- The function field `R(W) := Frac(R[W])` of a Weierstrass curve `W`. -/ abbrev FunctionField : Type u := FractionRing W.CoordinateRing namespace CoordinateRing section Algebra /-! ### The coordinate ring as an `R[X]`-algebra -/ noncomputable instance : Algebra R W.CoordinateRing := Quotient.algebra R noncomputable instance : Algebra R[X] W.CoordinateRing := Quotient.algebra R[X] instance : IsScalarTower R R[X] W.CoordinateRing := Quotient.isScalarTower R R[X] _ instance [Subsingleton R] : Subsingleton W.CoordinateRing := Module.subsingleton R[X] _ /-- The natural ring homomorphism mapping `R[X][Y]` to `R[W]`. -/ noncomputable abbrev mk : R[X][Y] →+* W.CoordinateRing := AdjoinRoot.mk W.polynomial /-- The power basis `{1, Y}` for `R[W]` over `R[X]`. -/ protected noncomputable def basis : Basis (Fin 2) R[X] W.CoordinateRing := by classical exact (subsingleton_or_nontrivial R).by_cases (fun _ => default) fun _ => (AdjoinRoot.powerBasis' W.monic_polynomial).basis.reindex <| finCongr W.natDegree_polynomial lemma basis_apply (n : Fin 2) : CoordinateRing.basis W n = (AdjoinRoot.powerBasis' W.monic_polynomial).gen ^ (n : ℕ) := by classical nontriviality R rw [CoordinateRing.basis, Or.by_cases, dif_neg <| not_subsingleton R, Basis.reindex_apply, PowerBasis.basis_eq_pow] rfl @[simp] lemma basis_zero : CoordinateRing.basis W 0 = 1 := by simpa only [basis_apply] using pow_zero _ @[simp] lemma basis_one : CoordinateRing.basis W 1 = mk W Y := by simpa only [basis_apply] using pow_one _ lemma coe_basis : (CoordinateRing.basis W : Fin 2 → W.CoordinateRing) = ![1, mk W Y] := by ext n fin_cases n exacts [basis_zero W, basis_one W] variable {W} in lemma smul (x : R[X]) (y : W.CoordinateRing) : x • y = mk W (C x) * y := (algebraMap_smul W.CoordinateRing x y).symm variable {W} in lemma smul_basis_eq_zero {p q : R[X]} (hpq : p • (1 : W.CoordinateRing) + q • mk W Y = 0) : p = 0 ∧ q = 0 := by have h := Fintype.linearIndependent_iff.mp (CoordinateRing.basis W).linearIndependent ![p, q] rw [Fin.sum_univ_succ, basis_zero, Fin.sum_univ_one, Fin.succ_zero_eq_one, basis_one] at h exact ⟨h hpq 0, h hpq 1⟩ variable {W} in lemma exists_smul_basis_eq (x : W.CoordinateRing) : ∃ p q : R[X], p • (1 : W.CoordinateRing) + q • mk W Y = x := by have h := (CoordinateRing.basis W).sum_equivFun x rw [Fin.sum_univ_succ, Fin.sum_univ_one, basis_zero, Fin.succ_zero_eq_one, basis_one] at h exact ⟨_, _, h⟩ lemma smul_basis_mul_C (y : R[X]) (p q : R[X]) : (p • (1 : W.CoordinateRing) + q • mk W Y) * mk W (C y) = (p * y) • (1 : W.CoordinateRing) + (q * y) • mk W Y := by simp only [smul, map_mul] ring1 lemma smul_basis_mul_Y (p q : R[X]) : (p • (1 : W.CoordinateRing) + q • mk W Y) * mk W Y = (q * (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆)) • (1 : W.CoordinateRing) + (p - q * (C W.a₁ * X + C W.a₃)) • mk W Y := by have Y_sq : mk W Y ^ 2 = mk W (C (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆) - C (C W.a₁ * X + C W.a₃) * Y) := by exact AdjoinRoot.mk_eq_mk.mpr ⟨1, by rw [polynomial]; ring1⟩ simp only [smul, add_mul, mul_assoc, ← sq, Y_sq, C_sub, map_sub, C_mul, map_mul] ring1 /-- The ring homomorphism `R[W] →+* S[W.map f]` induced by a ring homomorphism `f : R →+* S`. -/ noncomputable def map : W.CoordinateRing →+* (W.map f).toAffine.CoordinateRing := AdjoinRoot.lift ((AdjoinRoot.of _).comp <| mapRingHom f) ((AdjoinRoot.root (WeierstrassCurve.map W f).toAffine.polynomial)) <| by rw [← eval₂_map, ← map_polynomial, AdjoinRoot.eval₂_root] lemma map_mk (x : R[X][Y]) : map W f (mk W x) = mk (W.map f) (x.map <| mapRingHom f) := by rw [map, AdjoinRoot.lift_mk, ← eval₂_map] exact AdjoinRoot.aeval_eq <| x.map <| mapRingHom f variable {W} in protected lemma map_smul (x : R[X]) (y : W.CoordinateRing) : map W f (x • y) = x.map f • map W f y := by rw [smul, map_mul, map_mk, map_C, smul] rfl variable {f} in lemma map_injective (hf : Function.Injective f) : Function.Injective <| map W f := (injective_iff_map_eq_zero _).mpr fun y hy => by obtain ⟨p, q, rfl⟩ := exists_smul_basis_eq y simp_rw [map_add, CoordinateRing.map_smul, map_one, map_mk, map_X] at hy obtain ⟨hp, hq⟩ := smul_basis_eq_zero hy rw [Polynomial.map_eq_zero_iff hf] at hp hq simp_rw [hp, hq, zero_smul, add_zero] instance [IsDomain R] : IsDomain W.CoordinateRing := have : IsDomain (W.map <| algebraMap R <| FractionRing R).toAffine.CoordinateRing := AdjoinRoot.isDomain_of_prime irreducible_polynomial.prime (map_injective W <| IsFractionRing.injective R <| FractionRing R).isDomain end Algebra section Ring /-! ### Ideals in the coordinate ring over a ring -/ /-- The class of the element `X - x` in `R[W]` for some `x` in `R`. -/ noncomputable def XClass (x : R) : W.CoordinateRing := mk W <| C <| X - C x lemma XClass_ne_zero [Nontrivial R] (x : R) : XClass W x ≠ 0 := AdjoinRoot.mk_ne_zero_of_natDegree_lt W.monic_polynomial (C_ne_zero.mpr <| X_sub_C_ne_zero x) <| by rw [natDegree_polynomial, natDegree_C]; norm_num1 /-- The class of the element `Y - y(X)` in `R[W]` for some `y(X)` in `R[X]`. -/ noncomputable def YClass (y : R[X]) : W.CoordinateRing := mk W <| Y - C y lemma YClass_ne_zero [Nontrivial R] (y : R[X]) : YClass W y ≠ 0 := AdjoinRoot.mk_ne_zero_of_natDegree_lt W.monic_polynomial (X_sub_C_ne_zero y) <| by rw [natDegree_polynomial, natDegree_X_sub_C]; norm_num1 lemma C_addPolynomial (x y L : R) : mk W (C <| W.addPolynomial x y L) = mk W ((Y - C (linePolynomial x y L)) * (W.negPolynomial - C (linePolynomial x y L))) := AdjoinRoot.mk_eq_mk.mpr ⟨1, by rw [W.C_addPolynomial, add_sub_cancel_left, mul_one]⟩ /-- The ideal `⟨X - x⟩` of `R[W]` for some `x` in `R`. -/ noncomputable def XIdeal (x : R) : Ideal W.CoordinateRing := span {XClass W x} /-- The ideal `⟨Y - y(X)⟩` of `R[W]` for some `y(X)` in `R[X]`. -/ noncomputable def YIdeal (y : R[X]) : Ideal W.CoordinateRing := span {YClass W y} /-- The ideal `⟨X - x, Y - y(X)⟩` of `R[W]` for some `x` in `R` and `y(X)` in `R[X]`. -/ noncomputable def XYIdeal (x : R) (y : R[X]) : Ideal W.CoordinateRing := span {XClass W x, YClass W y} lemma XYIdeal_eq₁ (x y L : R) : XYIdeal W x (C y) = XYIdeal W x (linePolynomial x y L) := by simp only [XYIdeal, XClass, YClass, linePolynomial] rw [← span_pair_add_mul_right <| mk W <| C <| C <| -L, ← map_mul, ← map_add] apply congr_arg (_ ∘ _ ∘ _ ∘ _) C_simp ring1 lemma XYIdeal_add_eq (x₁ x₂ y₁ L : R) : XYIdeal W (W.addX x₁ x₂ L) (C <| W.addY x₁ x₂ y₁ L) = span {mk W <| W.negPolynomial - C (linePolynomial x₁ y₁ L)} ⊔ XIdeal W (W.addX x₁ x₂ L) := by simp only [XYIdeal, XIdeal, XClass, YClass, addY, negAddY, negY, negPolynomial, linePolynomial] rw [sub_sub <| -(Y : R[X][Y]), neg_sub_left (Y : R[X][Y]), map_neg, span_singleton_neg, sup_comm, ← span_insert, ← span_pair_add_mul_right <| mk W <| C <| C <| W.a₁ + L, ← map_mul, ← map_add] apply congr_arg (_ ∘ _ ∘ _ ∘ _) C_simp ring1 /-- The `R`-algebra isomorphism from `R[W] / ⟨X - x, Y - y(X)⟩` to `R` obtained by evaluation at some `y(X)` in `R[X]` and at some `x` in `R` provided that `W(x, y(x)) = 0`. -/ noncomputable def quotientXYIdealEquiv {x : R} {y : R[X]} (h : (W.polynomial.eval y).eval x = 0) : (W.CoordinateRing ⧸ XYIdeal W x y) ≃ₐ[R] R := ((quotientEquivAlgOfEq R <| by simp only [XYIdeal, XClass, YClass, ← Set.image_pair, ← map_span]; rfl).trans <| DoubleQuot.quotQuotEquivQuotOfLEₐ R <| (span_singleton_le_iff_mem _).mpr <| mem_span_C_X_sub_C_X_sub_C_iff_eval_eval_eq_zero.mpr h).trans quotientSpanCXSubCXSubCAlgEquiv end Ring section Field /-! ### Ideals in the coordinate ring over a field -/ variable {F : Type u} [Field F] {W : Affine F} lemma C_addPolynomial_slope {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : mk W (C <| W.addPolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) = -(XClass W x₁ * XClass W x₂ * XClass W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂)) := congr_arg (mk W) <| W.C_addPolynomial_slope h₁ h₂ hxy lemma XYIdeal_eq₂ {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : XYIdeal W x₂ (C y₂) = XYIdeal W x₂ (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) := by have hy₂ : y₂ = (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂).eval x₂ := by by_cases hx : x₁ = x₂ · have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩ rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩ field_simp [linePolynomial, sub_ne_zero_of_ne hy] · field_simp [linePolynomial, slope_of_X_ne hx, sub_ne_zero_of_ne hx] ring1 nth_rw 1 [hy₂] simp only [XYIdeal, XClass, YClass, linePolynomial] rw [← span_pair_add_mul_right <| mk W <| C <| C <| -W.slope x₁ x₂ y₁ y₂, ← map_mul, ← map_add] apply congr_arg (_ ∘ _ ∘ _ ∘ _) eval_simp C_simp ring1 lemma XYIdeal_neg_mul {x y : F} (h : W.Nonsingular x y) : XYIdeal W x (C <| W.negY x y) * XYIdeal W x (C y) = XIdeal W x := by have Y_rw : (Y - C (C y)) * (Y - C (C <| W.negY x y)) - C (X - C x) * (C (X ^ 2 + C (x + W.a₂) * X + C (x ^ 2 + W.a₂ * x + W.a₄)) - C (C W.a₁) * Y) = W.polynomial * 1 := by linear_combination (norm := (rw [negY, polynomial]; C_simp; ring1)) congr_arg C (congr_arg C ((equation_iff ..).mp h.left).symm) simp_rw [XYIdeal, XClass, YClass, span_pair_mul_span_pair, mul_comm, ← map_mul, AdjoinRoot.mk_eq_mk.mpr ⟨1, Y_rw⟩, map_mul, span_insert, ← span_singleton_mul_span_singleton, ← Ideal.mul_sup, ← span_insert] convert mul_top (_ : Ideal W.CoordinateRing) using 2 simp_rw [← Set.image_singleton (f := mk W), ← Set.image_insert_eq, ← map_span] convert map_top (R := F[X][Y]) (mk W) using 1 apply congr_arg simp_rw [eq_top_iff_one, mem_span_insert', mem_span_singleton'] rcases ((nonsingular_iff' ..).mp h).right with hx | hy · let W_X := W.a₁ * y - (3 * x ^ 2 + 2 * W.a₂ * x + W.a₄) refine ⟨C <| C W_X⁻¹ * -(X + C (2 * x + W.a₂)), C <| C <| W_X⁻¹ * W.a₁, 0, C <| C <| W_X⁻¹ * -1, ?_⟩ rw [← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hx] simp only [W_X, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hx] C_simp ring1 · let W_Y := 2 * y + W.a₁ * x + W.a₃ refine ⟨0, C <| C W_Y⁻¹, C <| C <| W_Y⁻¹ * -1, 0, ?_⟩ rw [negY, ← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hy] simp only [W_Y, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hy] C_simp ring1 private lemma XYIdeal'_mul_inv {x y : F} (h : W.Nonsingular x y) : XYIdeal W x (C y) * (XYIdeal W x (C <| W.negY x y) * (XIdeal W x : FractionalIdeal W.CoordinateRing⁰ W.FunctionField)⁻¹) = 1 := by rw [← mul_assoc, ← FractionalIdeal.coeIdeal_mul, mul_comm <| XYIdeal W .., XYIdeal_neg_mul h, XIdeal, FractionalIdeal.coe_ideal_span_singleton_mul_inv W.FunctionField <| XClass_ne_zero W x] lemma XYIdeal_mul_XYIdeal {x₁ x₂ y₁ y₂ : F} (h₁ : W.Equation x₁ y₁) (h₂ : W.Equation x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : XIdeal W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) * (XYIdeal W x₁ (C y₁) * XYIdeal W x₂ (C y₂)) = YIdeal W (linePolynomial x₁ y₁ <| W.slope x₁ x₂ y₁ y₂) * XYIdeal W (W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂) (C <| W.addY x₁ x₂ y₁ <| W.slope x₁ x₂ y₁ y₂) := by have sup_rw : ∀ a b c d : Ideal W.CoordinateRing, a ⊔ (b ⊔ (c ⊔ d)) = a ⊔ d ⊔ b ⊔ c := fun _ _ c _ => by rw [← sup_assoc, sup_comm c, sup_sup_sup_comm, ← sup_assoc] rw [XYIdeal_add_eq, XIdeal, mul_comm, XYIdeal_eq₁ W x₁ y₁ <| W.slope x₁ x₂ y₁ y₂, XYIdeal, XYIdeal_eq₂ h₁ h₂ hxy, XYIdeal, span_pair_mul_span_pair] simp_rw [span_insert, sup_rw, Ideal.sup_mul, span_singleton_mul_span_singleton] rw [← neg_eq_iff_eq_neg.mpr <| C_addPolynomial_slope h₁ h₂ hxy, span_singleton_neg, C_addPolynomial, map_mul, YClass] simp_rw [mul_comm <| XClass W x₁, mul_assoc, ← span_singleton_mul_span_singleton, ← Ideal.mul_sup] rw [span_singleton_mul_span_singleton, ← span_insert, ← span_pair_add_mul_right <| -(XClass W <| W.addX x₁ x₂ <| W.slope x₁ x₂ y₁ y₂), mul_neg, ← sub_eq_add_neg, ← sub_mul, ← map_sub <| mk W, sub_sub_sub_cancel_right, span_insert, ← span_singleton_mul_span_singleton, ← sup_rw, ← Ideal.sup_mul, ← Ideal.sup_mul] apply congr_arg (_ ∘ _) convert top_mul (_ : Ideal W.CoordinateRing) simp_rw [XClass, ← Set.image_singleton (f := mk W), ← map_span, ← Ideal.map_sup, eq_top_iff_one, mem_map_iff_of_surjective _ AdjoinRoot.mk_surjective, ← span_insert, mem_span_insert', mem_span_singleton'] by_cases hx : x₁ = x₂ · have hy : y₁ ≠ W.negY x₂ y₂ := fun h => hxy ⟨hx, h⟩ rcases hx, Y_eq_of_Y_ne h₁ h₂ hx hy with ⟨rfl, rfl⟩ let y := (y₁ - W.negY x₁ y₁) ^ 2 replace hxy := pow_ne_zero 2 <| sub_ne_zero_of_ne hy refine ⟨1 + C (C <| y⁻¹ * 4) * W.polynomial, ⟨C <| C y⁻¹ * (C 4 * X ^ 2 + C (4 * x₁ + W.b₂) * X + C (4 * x₁ ^ 2 + W.b₂ * x₁ + 2 * W.b₄)), 0, C (C y⁻¹) * (Y - W.negPolynomial), ?_⟩, by rw [map_add, map_one, map_mul <| mk W, AdjoinRoot.mk_self, mul_zero, add_zero]⟩ rw [polynomial, negPolynomial, ← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hxy] simp only [y, mul_add, ← mul_assoc, ← C_mul, mul_inv_cancel₀ hxy] linear_combination (norm := (rw [b₂, b₄, negY]; C_simp; ring1)) -4 * congr_arg C (congr_arg C <| (equation_iff ..).mp h₁) · replace hx := sub_ne_zero_of_ne hx refine ⟨_, ⟨⟨C <| C (x₁ - x₂)⁻¹, C <| C <| (x₁ - x₂)⁻¹ * -1, 0, ?_⟩, map_one _⟩⟩ rw [← mul_right_inj' <| C_ne_zero.mpr <| C_ne_zero.mpr hx] simp only [← mul_assoc, mul_add, ← C_mul, mul_inv_cancel₀ hx] C_simp ring1 /-- The non-zero fractional ideal `⟨X - x, Y - y⟩` of `F(W)` for some `x` and `y` in `F`. -/ noncomputable def XYIdeal' {x y : F} (h : W.Nonsingular x y) : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ := Units.mkOfMulEqOne _ _ <| XYIdeal'_mul_inv h lemma XYIdeal'_eq {x y : F} (h : W.Nonsingular x y) : (XYIdeal' h : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) = XYIdeal W x (C y) := rfl lemma mk_XYIdeal'_neg_mul {x y : F} (h : W.Nonsingular x y) : ClassGroup.mk (XYIdeal' <| (nonsingular_neg ..).mpr h) * ClassGroup.mk (XYIdeal' h) = 1 := by rw [← map_mul] exact (ClassGroup.mk_eq_one_of_coe_ideal <| (FractionalIdeal.coeIdeal_mul ..).symm.trans <| FractionalIdeal.coeIdeal_inj.mpr <| XYIdeal_neg_mul h).mpr ⟨_, XClass_ne_zero W _, rfl⟩ @[deprecated (since := "2025-03-01")] alias mk_XYIdeal'_mul_mk_XYIdeal'_of_Yeq := mk_XYIdeal'_neg_mul lemma mk_XYIdeal'_mul_mk_XYIdeal' {x₁ x₂ y₁ y₂ : F} (h₁ : W.Nonsingular x₁ y₁) (h₂ : W.Nonsingular x₂ y₂) (hxy : ¬(x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : ClassGroup.mk (XYIdeal' h₁) * ClassGroup.mk (XYIdeal' h₂) = ClassGroup.mk (XYIdeal' <| nonsingular_add h₁ h₂ hxy) := by rw [← map_mul] exact (ClassGroup.mk_eq_mk_of_coe_ideal (FractionalIdeal.coeIdeal_mul ..).symm <| XYIdeal'_eq _).mpr ⟨_, _, XClass_ne_zero W _, YClass_ne_zero W _, XYIdeal_mul_XYIdeal h₁.left h₂.left hxy⟩ end Field section Norm /-! ### Norms on the coordinate ring -/ lemma norm_smul_basis (p q : R[X]) : Algebra.norm R[X] (p • (1 : W.CoordinateRing) + q • mk W Y) = p ^ 2 - p * q * (C W.a₁ * X + C W.a₃) - q ^ 2 * (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆) := by simp_rw [Algebra.norm_eq_matrix_det <| CoordinateRing.basis W, Matrix.det_fin_two, Algebra.leftMulMatrix_eq_repr_mul, basis_zero, mul_one, basis_one, smul_basis_mul_Y, map_add, Finsupp.add_apply, map_smul, Finsupp.smul_apply, ← basis_zero, ← basis_one, Basis.repr_self_apply, if_pos, one_ne_zero, if_false, smul_eq_mul] ring1 lemma coe_norm_smul_basis (p q : R[X]) : Algebra.norm R[X] (p • (1 : W.CoordinateRing) + q • mk W Y) = mk W ((C p + C q * X) * (C p + C q * (-(Y : R[X][Y]) - C (C W.a₁ * X + C W.a₃)))) := AdjoinRoot.mk_eq_mk.mpr ⟨C q ^ 2, by simp only [norm_smul_basis, polynomial]; C_simp; ring1⟩ lemma degree_norm_smul_basis [IsDomain R] (p q : R[X]) : (Algebra.norm R[X] <| p • (1 : W.CoordinateRing) + q • mk W Y).degree = max (2 • p.degree) (2 • q.degree + 3) := by have hdp : (p ^ 2).degree = 2 • p.degree := degree_pow p 2 have hdpq : (p * q * (C W.a₁ * X + C W.a₃)).degree ≤ p.degree + q.degree + 1 := by simpa only [degree_mul] using add_le_add_left degree_linear_le (p.degree + q.degree) have hdq : (q ^ 2 * (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆)).degree = 2 • q.degree + 3 := by rw [degree_mul, degree_pow, ← one_mul <| X ^ 3, ← C_1, degree_cubic <| one_ne_zero' R] rw [norm_smul_basis] by_cases hp : p = 0 · simpa only [hp, hdq, neg_zero, zero_sub, zero_mul, zero_pow two_ne_zero, degree_neg] using (max_bot_left _).symm · by_cases hq : q = 0 · simpa only [hq, hdp, sub_zero, zero_mul, mul_zero, zero_pow two_ne_zero] using (max_bot_right _).symm · rw [← not_congr degree_eq_bot] at hp hq -- Porting note: BUG `cases` tactic does not modify assumptions in `hp'` and `hq'` rcases hp' : p.degree with _ | dp -- `hp' : ` should be redundant · exact (hp hp').elim -- `hp'` should be `rfl` · rw [hp'] at hdp hdpq -- line should be redundant rcases hq' : q.degree with _ | dq -- `hq' : ` should be redundant · exact (hq hq').elim -- `hq'` should be `rfl` · rw [hq'] at hdpq hdq -- line should be redundant rcases le_or_lt dp (dq + 1) with hpq | hpq · convert (degree_sub_eq_right_of_degree_lt <| (degree_sub_le _ _).trans_lt <| max_lt_iff.mpr ⟨hdp.trans_lt _, hdpq.trans_lt _⟩).trans (max_eq_right_of_lt _).symm <;> rw [hdq] <;> exact WithBot.coe_lt_coe.mpr <| by dsimp; linarith only [hpq] · rw [sub_sub] convert (degree_sub_eq_left_of_degree_lt <| (degree_add_le _ _).trans_lt <| max_lt_iff.mpr ⟨hdpq.trans_lt _, hdq.trans_lt _⟩).trans (max_eq_left_of_lt _).symm <;> rw [hdp] <;> exact WithBot.coe_lt_coe.mpr <| by dsimp; linarith only [hpq] variable {W} in lemma degree_norm_ne_one [IsDomain R] (x : W.CoordinateRing) : (Algebra.norm R[X] x).degree ≠ 1 := by rcases exists_smul_basis_eq x with ⟨p, q, rfl⟩ rw [degree_norm_smul_basis] rcases p.degree with (_ | _ | _ | _) <;> cases q.degree any_goals rintro (_ | _) -- Porting note: replaced `dec_trivial` with `by exact (cmp_eq_lt_iff ..).mp rfl` exact (lt_max_of_lt_right <| by exact (cmp_eq_lt_iff ..).mp rfl).ne' variable {W} in lemma natDegree_norm_ne_one [IsDomain R] (x : W.CoordinateRing) : (Algebra.norm R[X] x).natDegree ≠ 1 := degree_norm_ne_one x ∘ (degree_eq_iff_natDegree_eq_of_pos zero_lt_one).mpr end Norm end CoordinateRing namespace Point /-! ### The axioms for nonsingular rational points on a Weierstrass curve -/ variable {F : Type u} [Field F] {W : Affine F} /-- The group homomorphism mapping a nonsingular affine point `(x, y)` of a Weierstrass curve `W` to the class of the non-zero fractional ideal `⟨X - x, Y - y⟩` in the ideal class group of `F[W]`. -/ @[simps] noncomputable def toClass : W.Point →+ Additive (ClassGroup W.CoordinateRing) where toFun P := match P with | 0 => 0 | some h => Additive.ofMul <| ClassGroup.mk <| CoordinateRing.XYIdeal' h map_zero' := rfl map_add' := by rintro (_ | @⟨x₁, y₁, h₁⟩) (_ | @⟨x₂, y₂, h₂⟩) any_goals simp only [← zero_def, zero_add, add_zero] by_cases hxy : x₁ = x₂ ∧ y₁ = W.negY x₂ y₂ · simp only [hxy.left, hxy.right, add_of_Y_eq rfl rfl] exact (CoordinateRing.mk_XYIdeal'_neg_mul h₂).symm · simp only [add_some hxy] exact (CoordinateRing.mk_XYIdeal'_mul_mk_XYIdeal' h₁ h₂ hxy).symm @[deprecated (since := "2025-02-01")] alias toClassFun := toClass lemma toClass_zero : toClass (0 : W.Point) = 0 := rfl lemma toClass_some {x y : F} (h : W.Nonsingular x y) : toClass (some h) = ClassGroup.mk (CoordinateRing.XYIdeal' h) := rfl private lemma add_eq_zero (P Q : W.Point) : P + Q = 0 ↔ P = -Q := by rcases P, Q with ⟨_ | @⟨x₁, y₁, _⟩, _ | @⟨x₂, y₂, _⟩⟩ any_goals rfl · rw [← zero_def, zero_add, ← neg_eq_iff_eq_neg, neg_zero, eq_comm] · rw [neg_some, some.injEq] constructor · contrapose exact fun hxy => by simpa only [add_some hxy] using some_ne_zero _ · exact fun ⟨hx, hy⟩ => add_of_Y_eq hx hy lemma toClass_eq_zero (P : W.Point) : toClass P = 0 ↔ P = 0 := by constructor · intro hP rcases P with (_ | ⟨h, _⟩) · rfl · rcases (ClassGroup.mk_eq_one_of_coe_ideal <| by rfl).mp hP with ⟨p, h0, hp⟩ apply (p.natDegree_norm_ne_one _).elim rw [← finrank_quotient_span_eq_natDegree_norm (CoordinateRing.basis W) h0, ← (quotientEquivAlgOfEq F hp).toLinearEquiv.finrank_eq, (CoordinateRing.quotientXYIdealEquiv W h).toLinearEquiv.finrank_eq, Module.finrank_self] · exact congr_arg toClass lemma toClass_injective : Function.Injective <| @toClass _ _ W := by rintro (_ | h) _ hP all_goals rw [← neg_inj, ← add_eq_zero, ← toClass_eq_zero, map_add, ← hP] · exact zero_add 0 · exact CoordinateRing.mk_XYIdeal'_neg_mul h noncomputable instance : AddCommGroup W.Point where nsmul := nsmulRec zsmul := zsmulRec zero_add := zero_add add_zero := add_zero neg_add_cancel _ := by rw [add_eq_zero] add_comm _ _ := toClass_injective <| by simp only [map_add, add_comm] add_assoc _ _ _ := toClass_injective <| by simp only [map_add, add_assoc] /-! ## Elliptic curves in affine coordinates -/ variable {R : Type*} [Nontrivial R] [CommRing R] (E : WeierstrassCurve R) [E.IsElliptic] /-- An affine point on an elliptic curve `E` over a commutative ring `R`. -/ def mk {x y : R} (h : E.toAffine.Equation x y) : E.toAffine.Point := .some <| (equation_iff_nonsingular ..).mp h end Point end WeierstrassCurve.Affine
Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean
595
602
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kim Morrison -/ import Mathlib.Algebra.Homology.ComplexShape import Mathlib.CategoryTheory.Subobject.Limits import Mathlib.CategoryTheory.GradedObject import Mathlib.Algebra.Homology.ShortComplex.Basic /-! # Homological complexes. A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. We provide `ChainComplex V α` for `α`-indexed chain complexes in which `d i j ≠ 0` only if `j + 1 = i`, and similarly `CochainComplex V α`, with `i = j + 1`. There is a category structure, where morphisms are chain maps. For `C : HomologicalComplex V c`, we define `C.xNext i`, which is either `C.X j` for some arbitrarily chosen `j` such that `c.r i j`, or `C.X i` if there is no such `j`. Similarly we have `C.xPrev j`. Defined in terms of these we have `C.dFrom i : C.X i ⟶ C.xNext i` and `C.dTo j : C.xPrev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed. -/ universe v u open CategoryTheory CategoryTheory.Category CategoryTheory.Limits variable {ι : Type*} variable (V : Type u) [Category.{v} V] [HasZeroMorphisms V] /-- A `HomologicalComplex V c` with a "shape" controlled by `c : ComplexShape ι` has chain groups `X i` (objects in `V`) indexed by `i : ι`, and a differential `d i j` whenever `c.Rel i j`. We in fact ask for differentials `d i j` for all `i j : ι`, but have a field `shape` requiring that these are zero when not allowed by `c`. This avoids a lot of dependent type theory hell! The composite of any two differentials `d i j ≫ d j k` must be zero. -/ structure HomologicalComplex (c : ComplexShape ι) where X : ι → V d : ∀ i j, X i ⟶ X j shape : ∀ i j, ¬c.Rel i j → d i j = 0 := by aesop_cat d_comp_d' : ∀ i j k, c.Rel i j → c.Rel j k → d i j ≫ d j k = 0 := by aesop_cat namespace HomologicalComplex attribute [simp] shape variable {V} {c : ComplexShape ι} @[reassoc (attr := simp)] theorem d_comp_d (C : HomologicalComplex V c) (i j k : ι) : C.d i j ≫ C.d j k = 0 := by by_cases hij : c.Rel i j · by_cases hjk : c.Rel j k · exact C.d_comp_d' i j k hij hjk · rw [C.shape j k hjk, comp_zero] · rw [C.shape i j hij, zero_comp] theorem ext {C₁ C₂ : HomologicalComplex V c} (h_X : C₁.X = C₂.X) (h_d : ∀ i j : ι, c.Rel i j → C₁.d i j ≫ eqToHom (congr_fun h_X j) = eqToHom (congr_fun h_X i) ≫ C₂.d i j) : C₁ = C₂ := by obtain ⟨X₁, d₁, s₁, h₁⟩ := C₁ obtain ⟨X₂, d₂, s₂, h₂⟩ := C₂ dsimp at h_X subst h_X simp only [mk.injEq, heq_eq_eq, true_and] ext i j by_cases hij : c.Rel i j · simpa only [comp_id, id_comp, eqToHom_refl] using h_d i j hij · rw [s₁ i j hij, s₂ i j hij] /-- The obvious isomorphism `K.X p ≅ K.X q` when `p = q`. -/ def XIsoOfEq (K : HomologicalComplex V c) {p q : ι} (h : p = q) : K.X p ≅ K.X q := eqToIso (by rw [h]) @[simp] lemma XIsoOfEq_rfl (K : HomologicalComplex V c) (p : ι) : K.XIsoOfEq (rfl : p = p) = Iso.refl _ := rfl @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₁₂.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₁₂ : p₁ = p₂) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₁₂).hom ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₁₂.trans h₃₂.symm)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₂₃ : p₂ = p₃) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₂₃).hom = (K.XIsoOfEq (h₂₁.symm.trans h₂₃)).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₁ p₂ p₃ : ι} (h₂₁ : p₂ = p₁) (h₃₂ : p₃ = p₂) : (K.XIsoOfEq h₂₁).inv ≫ (K.XIsoOfEq h₃₂).inv = (K.XIsoOfEq (h₃₂.trans h₂₁).symm).hom := by dsimp [XIsoOfEq] simp only [eqToHom_trans] @[reassoc (attr := simp)] lemma XIsoOfEq_hom_comp_d (K : HomologicalComplex V c) {p₁ p₂ : ι} (h : p₁ = p₂) (p₃ : ι) : (K.XIsoOfEq h).hom ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma XIsoOfEq_inv_comp_d (K : HomologicalComplex V c) {p₂ p₁ : ι} (h : p₂ = p₁) (p₃ : ι) : (K.XIsoOfEq h).inv ≫ K.d p₂ p₃ = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_hom (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₂ = p₃) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).hom = K.d p₁ p₃ := by subst h; simp @[reassoc (attr := simp)] lemma d_comp_XIsoOfEq_inv (K : HomologicalComplex V c) {p₂ p₃ : ι} (h : p₃ = p₂) (p₁ : ι) : K.d p₁ p₂ ≫ (K.XIsoOfEq h).inv = K.d p₁ p₃ := by subst h; simp end HomologicalComplex /-- An `α`-indexed chain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `j + 1 = i`. -/ abbrev ChainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.down α) /-- An `α`-indexed cochain complex is a `HomologicalComplex` in which `d i j ≠ 0` only if `i + 1 = j`. -/ abbrev CochainComplex (α : Type*) [AddRightCancelSemigroup α] [One α] : Type _ := HomologicalComplex V (ComplexShape.up α) namespace ChainComplex @[simp] theorem prev (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.down α).prev i = i + 1 := (ComplexShape.down α).prev_eq' rfl @[simp] theorem next (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.down α).next i = i - 1 := (ComplexShape.down α).next_eq' <| sub_add_cancel _ _ @[simp] theorem next_nat_zero : (ComplexShape.down ℕ).next 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem next_nat_succ (i : ℕ) : (ComplexShape.down ℕ).next (i + 1) = i := (ComplexShape.down ℕ).next_eq' rfl end ChainComplex namespace CochainComplex @[simp] theorem prev (α : Type*) [AddGroup α] [One α] (i : α) : (ComplexShape.up α).prev i = i - 1 := (ComplexShape.up α).prev_eq' <| sub_add_cancel _ _ @[simp] theorem next (α : Type*) [AddRightCancelSemigroup α] [One α] (i : α) : (ComplexShape.up α).next i = i + 1 := (ComplexShape.up α).next_eq' rfl @[simp] theorem prev_nat_zero : (ComplexShape.up ℕ).prev 0 = 0 := by classical refine dif_neg ?_ push_neg intro apply Nat.noConfusion @[simp] theorem prev_nat_succ (i : ℕ) : (ComplexShape.up ℕ).prev (i + 1) = i := (ComplexShape.up ℕ).prev_eq' rfl end CochainComplex namespace HomologicalComplex variable {V} variable {c : ComplexShape ι} (C : HomologicalComplex V c) /-- A morphism of homological complexes consists of maps between the chain groups, commuting with the differentials. -/ @[ext] structure Hom (A B : HomologicalComplex V c) where f : ∀ i, A.X i ⟶ B.X i comm' : ∀ i j, c.Rel i j → f i ≫ B.d i j = A.d i j ≫ f j := by aesop_cat @[reassoc (attr := simp)] theorem Hom.comm {A B : HomologicalComplex V c} (f : A.Hom B) (i j : ι) : f.f i ≫ B.d i j = A.d i j ≫ f.f j := by by_cases hij : c.Rel i j · exact f.comm' i j hij · rw [A.shape i j hij, B.shape i j hij, comp_zero, zero_comp] instance (A B : HomologicalComplex V c) : Inhabited (Hom A B) := ⟨{ f := fun _ => 0 }⟩ /-- Identity chain map. -/ def id (A : HomologicalComplex V c) : Hom A A where f _ := 𝟙 _ /-- Composition of chain maps. -/ def comp (A B C : HomologicalComplex V c) (φ : Hom A B) (ψ : Hom B C) : Hom A C where f i := φ.f i ≫ ψ.f i section attribute [local simp] id comp instance : Category (HomologicalComplex V c) where Hom := Hom id := id comp := comp _ _ _ end @[ext] lemma hom_ext {C D : HomologicalComplex V c} (f g : C ⟶ D) (h : ∀ i, f.f i = g.f i) : f = g := by apply Hom.ext funext apply h @[simp] theorem id_f (C : HomologicalComplex V c) (i : ι) : Hom.f (𝟙 C) i = 𝟙 (C.X i) := rfl @[simp, reassoc] theorem comp_f {C₁ C₂ C₃ : HomologicalComplex V c} (f : C₁ ⟶ C₂) (g : C₂ ⟶ C₃) (i : ι) : (f ≫ g).f i = f.f i ≫ g.f i := rfl @[simp] theorem eqToHom_f {C₁ C₂ : HomologicalComplex V c} (h : C₁ = C₂) (n : ι) : HomologicalComplex.Hom.f (eqToHom h) n = eqToHom (congr_fun (congr_arg HomologicalComplex.X h) n) := by subst h rfl -- We'll use this later to show that `HomologicalComplex V c` is preadditive when `V` is. theorem hom_f_injective {C₁ C₂ : HomologicalComplex V c} : Function.Injective fun f : Hom C₁ C₂ => f.f := by aesop_cat instance (X Y : HomologicalComplex V c) : Zero (X ⟶ Y) := ⟨{ f := fun _ => 0}⟩ @[simp] theorem zero_f (C D : HomologicalComplex V c) (i : ι) : (0 : C ⟶ D).f i = 0 := rfl instance : HasZeroMorphisms (HomologicalComplex V c) where open ZeroObject /-- The zero complex -/ noncomputable def zero [HasZeroObject V] : HomologicalComplex V c where X _ := 0 d _ _ := 0 theorem isZero_zero [HasZeroObject V] : IsZero (zero : HomologicalComplex V c) := by refine ⟨fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩, fun X => ⟨⟨⟨0⟩, fun f => ?_⟩⟩⟩ all_goals ext dsimp only [zero] subsingleton instance [HasZeroObject V] : HasZeroObject (HomologicalComplex V c) := ⟨⟨zero, isZero_zero⟩⟩ noncomputable instance [HasZeroObject V] : Inhabited (HomologicalComplex V c) := ⟨zero⟩ theorem congr_hom {C D : HomologicalComplex V c} {f g : C ⟶ D} (w : f = g) (i : ι) : f.f i = g.f i := congr_fun (congr_arg Hom.f w) i lemma mono_of_mono_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Mono (φ.f i)) : Mono φ where right_cancellation g h eq := by ext i rw [← cancel_mono (φ.f i)] exact congr_hom eq i lemma epi_of_epi_f {K L : HomologicalComplex V c} (φ : K ⟶ L) (hφ : ∀ i, Epi (φ.f i)) : Epi φ where left_cancellation g h eq := by ext i rw [← cancel_epi (φ.f i)] exact congr_hom eq i section variable (V c) /-- The functor picking out the `i`-th object of a complex. -/ @[simps] def eval (i : ι) : HomologicalComplex V c ⥤ V where obj C := C.X i map f := f.f i instance (i : ι) : (eval V c i).PreservesZeroMorphisms where /-- The functor forgetting the differential in a complex, obtaining a graded object. -/ @[simps] def forget : HomologicalComplex V c ⥤ GradedObject ι V where obj C := C.X map f := f.f instance : (forget V c).Faithful where map_injective h := by ext i exact congr_fun h i /-- Forgetting the differentials than picking out the `i`-th object is the same as just picking out the `i`-th object. -/ @[simps!] def forgetEval (i : ι) : forget V c ⋙ GradedObject.eval i ≅ eval V c i := NatIso.ofComponents fun _ => Iso.refl _ end noncomputable section @[reassoc] lemma XIsoOfEq_hom_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n ≫ (L.XIsoOfEq h).hom = (K.XIsoOfEq h).hom ≫ φ.f n' := by subst h; simp @[reassoc] lemma XIsoOfEq_inv_naturality {K L : HomologicalComplex V c} (φ : K ⟶ L) {n n' : ι} (h : n = n') : φ.f n' ≫ (L.XIsoOfEq h).inv = (K.XIsoOfEq h).inv ≫ φ.f n := by subst h; simp -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i j'` are both allowed, then we must have `j = j'`, and so the differentials only differ by an `eqToHom`. -/ theorem d_comp_eqToHom {i j j' : ι} (rij : c.Rel i j) (rij' : c.Rel i j') : C.d i j' ≫ eqToHom (congr_arg C.X (c.next_eq rij' rij)) = C.d i j := by obtain rfl := c.next_eq rij rij' simp only [eqToHom_refl, comp_id] -- Porting note: removed @[simp] as the linter complained /-- If `C.d i j` and `C.d i' j` are both allowed, then we must have `i = i'`, and so the differentials only differ by an `eqToHom`. -/ theorem eqToHom_comp_d {i i' j : ι} (rij : c.Rel i j) (rij' : c.Rel i' j) : eqToHom (congr_arg C.X (c.prev_eq rij rij')) ≫ C.d i' j = C.d i j := by obtain rfl := c.prev_eq rij rij' simp only [eqToHom_refl, id_comp] theorem kernel_eq_kernel [HasKernels V] {i j j' : ι} (r : c.Rel i j) (r' : c.Rel i j') : kernelSubobject (C.d i j) = kernelSubobject (C.d i j') := by rw [← d_comp_eqToHom C r r'] apply kernelSubobject_comp_mono theorem image_eq_image [HasImages V] [HasEqualizers V] {i i' j : ι} (r : c.Rel i j) (r' : c.Rel i' j) : imageSubobject (C.d i j) = imageSubobject (C.d i' j) := by rw [← eqToHom_comp_d C r r'] apply imageSubobject_iso_comp section /-- Either `C.X i`, if there is some `i` with `c.Rel i j`, or `C.X j`. -/ abbrev xPrev (j : ι) : V := C.X (c.prev j) /-- If `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X i`. -/ def xPrevIso {i j : ι} (r : c.Rel i j) : C.xPrev j ≅ C.X i := eqToIso <| by rw [← c.prev_eq' r] /-- If there is no `i` so `c.Rel i j`, then `C.xPrev j` is isomorphic to `C.X j`. -/ def xPrevIsoSelf {j : ι} (h : ¬c.Rel (c.prev j) j) : C.xPrev j ≅ C.X j := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.prev] rw [dif_neg] push_neg; intro i hi have : c.prev j = i := c.prev_eq' hi rw [this] at h; contradiction) /-- Either `C.X j`, if there is some `j` with `c.rel i j`, or `C.X i`. -/ abbrev xNext (i : ι) : V := C.X (c.next i) /-- If `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X j`. -/ def xNextIso {i j : ι} (r : c.Rel i j) : C.xNext i ≅ C.X j := eqToIso <| by rw [← c.next_eq' r] /-- If there is no `j` so `c.Rel i j`, then `C.xNext i` is isomorphic to `C.X i`. -/ def xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.xNext i ≅ C.X i := eqToIso <| congr_arg C.X (by dsimp [ComplexShape.next] rw [dif_neg]; rintro ⟨j, hj⟩ have : c.next i = j := c.next_eq' hj rw [this] at h; contradiction) /-- The differential mapping into `C.X j`, or zero if there isn't one. -/ abbrev dTo (j : ι) : C.xPrev j ⟶ C.X j := C.d (c.prev j) j /-- The differential mapping out of `C.X i`, or zero if there isn't one. -/ abbrev dFrom (i : ι) : C.X i ⟶ C.xNext i := C.d i (c.next i) theorem dTo_eq {i j : ι} (r : c.Rel i j) : C.dTo j = (C.xPrevIso r).hom ≫ C.d i j := by obtain rfl := c.prev_eq' r exact (Category.id_comp _).symm @[simp] theorem dTo_eq_zero {j : ι} (h : ¬c.Rel (c.prev j) j) : C.dTo j = 0 := C.shape _ _ h theorem dFrom_eq {i j : ι} (r : c.Rel i j) : C.dFrom i = C.d i j ≫ (C.xNextIso r).inv := by obtain rfl := c.next_eq' r exact (Category.comp_id _).symm @[simp] theorem dFrom_eq_zero {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i = 0 := C.shape _ _ h @[reassoc (attr := simp)] theorem xPrevIso_comp_dTo {i j : ι} (r : c.Rel i j) : (C.xPrevIso r).inv ≫ C.dTo j = C.d i j := by simp [C.dTo_eq r] @[reassoc (attr := simp)] theorem xPrevIsoSelf_comp_dTo {j : ι} (h : ¬c.Rel (c.prev j) j) : (C.xPrevIsoSelf h).inv ≫ C.dTo j = 0 := by simp [h] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIso {i j : ι} (r : c.Rel i j) : C.dFrom i ≫ (C.xNextIso r).hom = C.d i j := by simp [C.dFrom_eq r] @[reassoc (attr := simp)] theorem dFrom_comp_xNextIsoSelf {i : ι} (h : ¬c.Rel i (c.next i)) : C.dFrom i ≫ (C.xNextIsoSelf h).hom = 0 := by simp [h] -- This is not a simp lemma; the LHS already simplifies. theorem dTo_comp_dFrom (j : ι) : C.dTo j ≫ C.dFrom j = 0 := C.d_comp_d _ _ _ theorem kernel_from_eq_kernel [HasKernels V] {i j : ι} (r : c.Rel i j) : kernelSubobject (C.dFrom i) = kernelSubobject (C.d i j) := by rw [C.dFrom_eq r] apply kernelSubobject_comp_mono theorem image_to_eq_image [HasImages V] [HasEqualizers V] {i j : ι} (r : c.Rel i j) : imageSubobject (C.dTo j) = imageSubobject (C.d i j) := by rw [C.dTo_eq r] apply imageSubobject_iso_comp end namespace Hom variable {C₁ C₂ C₃ : HomologicalComplex V c} /-- The `i`-th component of an isomorphism of chain complexes. -/ @[simps!] def isoApp (f : C₁ ≅ C₂) (i : ι) : C₁.X i ≅ C₂.X i := (eval V c i).mapIso f /-- Construct an isomorphism of chain complexes from isomorphism of the objects which commute with the differentials. -/ @[simps] def isoOfComponents (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom := by aesop_cat) : C₁ ≅ C₂ where hom := { f := fun i => (f i).hom comm' := hf } inv := { f := fun i => (f i).inv comm' := fun i j hij => calc (f i).inv ≫ C₁.d i j = (f i).inv ≫ (C₁.d i j ≫ (f j).hom) ≫ (f j).inv := by simp _ = (f i).inv ≫ ((f i).hom ≫ C₂.d i j) ≫ (f j).inv := by rw [hf i j hij] _ = C₂.d i j ≫ (f j).inv := by simp } hom_inv_id := by ext i exact (f i).hom_inv_id inv_hom_id := by ext i exact (f i).inv_hom_id @[simp] theorem isoOfComponents_app (f : ∀ i, C₁.X i ≅ C₂.X i) (hf : ∀ i j, c.Rel i j → (f i).hom ≫ C₂.d i j = C₁.d i j ≫ (f j).hom) (i : ι) : isoApp (isoOfComponents f hf) i = f i := by ext simp theorem isIso_of_components (f : C₁ ⟶ C₂) [∀ n : ι, IsIso (f.f n)] : IsIso f := (HomologicalComplex.Hom.isoOfComponents fun n => asIso (f.f n)).isIso_hom /-! Lemmas relating chain maps and `dTo`/`dFrom`. -/ /-- `f.prev j` is `f.f i` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev prev (f : Hom C₁ C₂) (j : ι) : C₁.xPrev j ⟶ C₂.xPrev j := f.f _ theorem prev_eq (f : Hom C₁ C₂) {i j : ι} (w : c.Rel i j) : f.prev j = (C₁.xPrevIso w).hom ≫ f.f i ≫ (C₂.xPrevIso w).inv := by obtain rfl := c.prev_eq' w simp only [xPrevIso, eqToIso_refl, Iso.refl_hom, Iso.refl_inv, comp_id, id_comp]
/-- `f.next i` is `f.f j` if there is some `r i j`, and `f.f j` otherwise. -/ abbrev next (f : Hom C₁ C₂) (i : ι) : C₁.xNext i ⟶ C₂.xNext i := f.f _
Mathlib/Algebra/Homology/HomologicalComplex.lean
542
545
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash -/ import Mathlib.Data.Finset.Card import Mathlib.Data.Finset.Union /-! # Finsets in product types This file defines finset constructions on the product type `α × β`. Beware not to confuse with the `Finset.prod` operation which computes the multiplicative product. ## Main declarations * `Finset.product`: Turns `s : Finset α`, `t : Finset β` into their product in `Finset (α × β)`. * `Finset.diag`: For `s : Finset α`, `s.diag` is the `Finset (α × α)` of pairs `(a, a)` with `a ∈ s`. * `Finset.offDiag`: For `s : Finset α`, `s.offDiag` is the `Finset (α × α)` of pairs `(a, b)` with `a, b ∈ s` and `a ≠ b`. -/ assert_not_exists MonoidWithZero open Multiset variable {α β γ : Type*} namespace Finset /-! ### prod -/ section Prod variable {s s' : Finset α} {t t' : Finset β} {a : α} {b : β} /-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def product (s : Finset α) (t : Finset β) : Finset (α × β) := ⟨_, s.nodup.product t.nodup⟩ instance instSProd : SProd (Finset α) (Finset β) (Finset (α × β)) where sprod := Finset.product @[simp] theorem product_eq_sprod : Finset.product s t = s ×ˢ t := rfl @[simp] theorem product_val : (s ×ˢ t).1 = s.1 ×ˢ t.1 := rfl @[simp] theorem mem_product {p : α × β} : p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t := Multiset.mem_product theorem mk_mem_product (ha : a ∈ s) (hb : b ∈ t) : (a, b) ∈ s ×ˢ t := mem_product.2 ⟨ha, hb⟩ @[simp, norm_cast] theorem coe_product (s : Finset α) (t : Finset β) : (↑(s ×ˢ t) : Set (α × β)) = (s : Set α) ×ˢ t := Set.ext fun _ => Finset.mem_product theorem subset_product_image_fst [DecidableEq α] : (s ×ˢ t).image Prod.fst ⊆ s := fun i => by simp +contextual [mem_image] theorem subset_product_image_snd [DecidableEq β] : (s ×ˢ t).image Prod.snd ⊆ t := fun i => by simp +contextual [mem_image] theorem product_image_fst [DecidableEq α] (ht : t.Nonempty) : (s ×ˢ t).image Prod.fst = s := by ext i simp [mem_image, ht.exists_mem] theorem product_image_snd [DecidableEq β] (ht : s.Nonempty) : (s ×ˢ t).image Prod.snd = t := by ext i simp [mem_image, ht.exists_mem] theorem subset_product [DecidableEq α] [DecidableEq β] {s : Finset (α × β)} :
s ⊆ s.image Prod.fst ×ˢ s.image Prod.snd := fun _ hp => mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩
Mathlib/Data/Finset/Prod.lean
81
83
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Data.Rat.Cast.Defs /-! # Casts of rational numbers into characteristic zero fields (or division rings). -/ open Function variable {F ι α β : Type*} namespace Rat variable [DivisionRing α] [CharZero α] {p q : ℚ} @[stacks 09FR "Characteristic zero case."] lemma cast_injective : Injective ((↑) : ℚ → α) | ⟨n₁, d₁, d₁0, c₁⟩, ⟨n₂, d₂, d₂0, c₂⟩, h => by have d₁a : (d₁ : α) ≠ 0 := Nat.cast_ne_zero.2 d₁0 have d₂a : (d₂ : α) ≠ 0 := Nat.cast_ne_zero.2 d₂0 rw [mk'_eq_divInt, mk'_eq_divInt] at h ⊢ rw [cast_divInt_of_ne_zero, cast_divInt_of_ne_zero] at h <;> simp [d₁0, d₂0] at h ⊢ rwa [eq_div_iff_mul_eq d₂a, division_def, mul_assoc, (d₁.cast_commute (d₂ : α)).inv_left₀.eq, ← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq d₁a, eq_comm, ← Int.cast_natCast d₁, ← Int.cast_mul, ← Int.cast_natCast d₂, ← Int.cast_mul, Int.cast_inj, ← mkRat_eq_iff d₁0 d₂0] at h @[simp, norm_cast] lemma cast_inj : (p : α) = q ↔ p = q := cast_injective.eq_iff @[simp, norm_cast] lemma cast_eq_zero : (p : α) = 0 ↔ p = 0 := cast_injective.eq_iff' cast_zero lemma cast_ne_zero : (p : α) ≠ 0 ↔ p ≠ 0 := cast_eq_zero.ne @[simp, norm_cast] lemma cast_add (p q : ℚ) : ↑(p + q) = (p + q : α) := cast_add_of_ne_zero (Nat.cast_ne_zero.2 p.pos.ne') (Nat.cast_ne_zero.2 q.pos.ne') @[simp, norm_cast] lemma cast_sub (p q : ℚ) : ↑(p - q) = (p - q : α) := cast_sub_of_ne_zero (Nat.cast_ne_zero.2 p.pos.ne') (Nat.cast_ne_zero.2 q.pos.ne') @[simp, norm_cast] lemma cast_mul (p q : ℚ) : ↑(p * q) = (p * q : α) := cast_mul_of_ne_zero (Nat.cast_ne_zero.2 p.pos.ne') (Nat.cast_ne_zero.2 q.pos.ne') variable (α) in /-- Coercion `ℚ → α` as a `RingHom`. -/ def castHom : ℚ →+* α where toFun := (↑) map_one' := cast_one map_mul' := cast_mul map_zero' := cast_zero map_add' := cast_add @[simp] lemma coe_castHom : ⇑(castHom α) = ((↑) : ℚ → α) := rfl @[simp, norm_cast] lemma cast_inv (p : ℚ) : ↑(p⁻¹) = (p⁻¹ : α) := map_inv₀ (castHom α) _ @[simp, norm_cast] lemma cast_div (p q : ℚ) : ↑(p / q) = (p / q : α) := map_div₀ (castHom α) .. @[simp, norm_cast] lemma cast_zpow (p : ℚ) (n : ℤ) : ↑(p ^ n) = (p ^ n : α) := map_zpow₀ (castHom α) .. @[norm_cast] theorem cast_mk (a b : ℤ) : (a /. b : α) = a / b := by simp only [divInt_eq_div, cast_div, cast_intCast] end Rat namespace NNRat variable [DivisionSemiring α] [CharZero α] {p q : ℚ≥0} lemma cast_injective : Injective ((↑) : ℚ≥0 → α) := by rintro p q hpq rw [NNRat.cast_def, NNRat.cast_def, Commute.div_eq_div_iff] at hpq on_goal 1 => rw [← p.num_div_den, ← q.num_div_den, div_eq_div_iff] · norm_cast at hpq ⊢ any_goals norm_cast
any_goals apply den_ne_zero exact Nat.cast_commute ..
Mathlib/Data/Rat/Cast/CharZero.lean
78
79
/- 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.Data.Finite.Defs import Mathlib.Data.Finset.BooleanAlgebra import Mathlib.Data.Finset.Image import Mathlib.Data.Fintype.Defs import Mathlib.Data.Fintype.OfMap import Mathlib.Data.Fintype.Sets import Mathlib.Data.List.FinRange /-! # Instances for finite types This file is a collection of basic `Fintype` instances for types such as `Fin`, `Prod` and pi types. -/ assert_not_exists Monoid open Function open Nat universe u v variable {α β γ : Type*} open Finset instance Fin.fintype (n : ℕ) : Fintype (Fin n) := ⟨⟨List.finRange n, List.nodup_finRange n⟩, List.mem_finRange⟩ theorem Fin.univ_def (n : ℕ) : (univ : Finset (Fin n)) = ⟨List.finRange n, List.nodup_finRange n⟩ := rfl theorem Finset.val_univ_fin (n : ℕ) : (Finset.univ : Finset (Fin n)).val = List.finRange n := rfl /-- See also `nonempty_encodable`, `nonempty_denumerable`. -/ theorem nonempty_fintype (α : Type*) [Finite α] : Nonempty (Fintype α) := by rcases Finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩ exact ⟨.ofEquiv _ e.symm⟩ @[simp] theorem List.toFinset_finRange (n : ℕ) : (List.finRange n).toFinset = Finset.univ := by ext; simp @[simp] theorem Fin.univ_val_map {n : ℕ} (f : Fin n → α) : Finset.univ.val.map f = List.ofFn f := by simp [List.ofFn_eq_map, univ_def] theorem Fin.univ_image_def {n : ℕ} [DecidableEq α] (f : Fin n → α) : Finset.univ.image f = (List.ofFn f).toFinset := by simp [Finset.image] theorem Fin.univ_map_def {n : ℕ} (f : Fin n ↪ α) : Finset.univ.map f = ⟨List.ofFn f, List.nodup_ofFn.mpr f.injective⟩ := by simp [Finset.map] @[simp] theorem Fin.image_succAbove_univ {n : ℕ} (i : Fin (n + 1)) : univ.image i.succAbove = {i}ᶜ := by ext m simp @[simp] theorem Fin.image_succ_univ (n : ℕ) : (univ : Finset (Fin n)).image Fin.succ = {0}ᶜ := by rw [← Fin.succAbove_zero, Fin.image_succAbove_univ] @[simp] theorem Fin.image_castSucc (n : ℕ) : (univ : Finset (Fin n)).image Fin.castSucc = {Fin.last n}ᶜ := by rw [← Fin.succAbove_last, Fin.image_succAbove_univ] /- The following three lemmas use `Finset.cons` instead of `insert` and `Finset.map` instead of `Finset.image` to reduce proof obligations downstream. -/ /-- Embed `Fin n` into `Fin (n + 1)` by prepending zero to the `univ` -/ theorem Fin.univ_succ (n : ℕ) : (univ : Finset (Fin (n + 1))) = Finset.cons 0 (univ.map ⟨Fin.succ, Fin.succ_injective _⟩) (by simp [map_eq_image]) := by simp [map_eq_image] /-- Embed `Fin n` into `Fin (n + 1)` by appending a new `Fin.last n` to the `univ` -/ theorem Fin.univ_castSuccEmb (n : ℕ) : (univ : Finset (Fin (n + 1))) = Finset.cons (Fin.last n) (univ.map Fin.castSuccEmb) (by simp [map_eq_image]) := by simp [map_eq_image] /-- Embed `Fin n` into `Fin (n + 1)` by inserting around a specified pivot `p : Fin (n + 1)` into the `univ` -/ theorem Fin.univ_succAbove (n : ℕ) (p : Fin (n + 1)) : (univ : Finset (Fin (n + 1))) = Finset.cons p (univ.map <| Fin.succAboveEmb p) (by simp) := by simp [map_eq_image] @[simp] theorem Fin.univ_image_get [DecidableEq α] (l : List α) : Finset.univ.image l.get = l.toFinset := by simp [univ_image_def] @[simp] theorem Fin.univ_image_getElem' [DecidableEq β] (l : List α) (f : α → β) : Finset.univ.image (fun i : Fin l.length => f <| l[(i : Nat)]) = (l.map f).toFinset := by simp only [univ_image_def, List.ofFn_getElem_eq_map] theorem Fin.univ_image_get' [DecidableEq β] (l : List α) (f : α → β) : Finset.univ.image (f <| l.get ·) = (l.map f).toFinset := by simp @[instance] def Unique.fintype {α : Type*} [Unique α] : Fintype α := Fintype.ofSubsingleton default /-- Short-circuit instance to decrease search for `Unique.fintype`, since that relies on a subsingleton elimination for `Unique`. -/ instance Fintype.subtypeEq (y : α) : Fintype { x // x = y } := Fintype.subtype {y} (by simp) /-- Short-circuit instance to decrease search for `Unique.fintype`, since that relies on a subsingleton elimination for `Unique`. -/ instance Fintype.subtypeEq' (y : α) : Fintype { x // y = x } := Fintype.subtype {y} (by simp [eq_comm]) theorem Fintype.univ_empty : @univ Empty _ = ∅ := rfl theorem Fintype.univ_pempty : @univ PEmpty _ = ∅ := rfl instance Unit.fintype : Fintype Unit := Fintype.ofSubsingleton () theorem Fintype.univ_unit : @univ Unit _ = {()} := rfl instance PUnit.fintype : Fintype PUnit := Fintype.ofSubsingleton PUnit.unit theorem Fintype.univ_punit : @univ PUnit _ = {PUnit.unit} := rfl @[simp] theorem Fintype.univ_bool : @univ Bool _ = {true, false} := rfl /-- Given that `α × β` is a fintype, `α` is also a fintype. -/ def Fintype.prodLeft {α β} [DecidableEq α] [Fintype (α × β)] [Nonempty β] : Fintype α := ⟨(@univ (α × β) _).image Prod.fst, fun a => by simp⟩ /-- Given that `α × β` is a fintype, `β` is also a fintype. -/ def Fintype.prodRight {α β} [DecidableEq β] [Fintype (α × β)] [Nonempty α] : Fintype β := ⟨(@univ (α × β) _).image Prod.snd, fun b => by simp⟩
instance ULift.fintype (α : Type*) [Fintype α] : Fintype (ULift α) := Fintype.ofEquiv _ Equiv.ulift.symm
Mathlib/Data/Fintype/Basic.lean
150
151
/- 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.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y ≠ 0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (π y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : ℕ) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≤ x) (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) := by rw [rpow_def, Complex.cpow_def, if_neg] · have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * π) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring · rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * π) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 · subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ · rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_rpow h · exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≤ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≤ |x| ^ y := by rcases le_or_lt 0 x with hx | hx · rw [abs_rpow_of_nonneg hx] · rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≤ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 · by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] · rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hx₀ : 0 < x) (hx₁ : x ≠ 1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hx₀, mul_inv_cancel₀] exact log_ne_zero.2 ⟨hx₀.ne', hx₁, (hx₀.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x ≠ 1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≤ exp 1 := by calc _ ≤ |x ^ (log x)⁻¹| := le_abs_self _ _ ≤ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt · simp [hx] · rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ‖x ^ y‖ = ‖x‖ ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≤ x) (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) · rw [zero_rpow h, zero_eq_mul] have : y ≠ 0 ∨ z ≠ 0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm ▸ hz.symm ▸ zero_add 0 exact this.imp zero_rpow zero_rpow · exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≤ x) (hw : w ≠ 0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 ≤ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) · rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) · by_cases h : y + z = 0 · simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp · simp [rpow_add', ← H, h] · simp [rpow_add pos] theorem rpow_sum_of_pos {ι : Type*} {a : ℝ} (ha : 0 < a) (f : ι → ℝ) (s : Finset ι) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ →+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ι : Type*} {a : ℝ} (ha : 0 ≤ a) {s : Finset ι} {f : ι → ℝ} (h : ∀ x ∈ s, 0 ≤ f x) : (a ^ ∑ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs · rw [sum_empty, Finset.prod_empty, rpow_zero] · rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] theorem rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊢ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {α : Type*} [TopologicalSpace α] {f : α → ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r ≠ 0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℂ) : (x : ℂ) ^ y = (-x : ℂ) ^ y * exp (π * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) · rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : ℂ) ≠ 0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : ℂ) (y : ℝ) : x ^ (y : ℂ) = ↑(‖x‖ ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx · simp [ofReal_cpow le_rfl] · rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).re = ‖x‖ ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : ℂ) (y : ℝ) : (x ^ (y : ℂ)).im = ‖x‖ ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : ℂ} (hz : z ≠ 0) (w : ℂ) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : ℂ} (h : z = 0 → w.re = 0 → w = 0) : ‖z ^ w‖ = ‖z‖ ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw · simp [hw, h rfl hw] · rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : ℂ) : ‖z ^ w‖ ≤ ‖z‖ ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 → w.re = 0 → w = 0 · exact (norm_cpow_of_imp h).le · push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : ℂ) (y : ℝ) : ‖x ^ (y : ℂ)‖ = ‖x‖ ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : ℂ) (n : ℕ) : ‖x ^ (n⁻¹ : ℂ)‖ = ‖x‖ ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : ℂ) : ‖(x : ℂ) ^ y‖ = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≤ x) {y : ℂ} (hy : re y ≠ 0) : ‖(x : ℂ) ^ y‖ = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : ℂ) : (fun t : ℝ ↦ ‖(t : ℂ) ^ c‖) =ᶠ[atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : ℕ) {s : ℂ} (hs : s.re ≠ 0) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : ‖(n : ℂ) ^ s‖ = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : ℕ} (hn : 0 < n) (s : ℂ) : 0 < ‖(n : ℂ) ^ s‖ := (norm_natCast_cpow_of_pos hn _).symm ▸ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (z : ℂ) : (x : ℂ) ^ (↑y * z) = (↑(x ^ y) : ℂ) ^ z := by rw [cpow_mul, ofReal_cpow hx] · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos · rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : ℕ} theorem rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℤ) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] lemma rpow_add_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x ≠ 0) (y : ℝ) (n : ℕ) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_natCast' (hx : 0 ≤ x) (h : y + n ≠ 0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_intCast' (hx : 0 ≤ x) {n : ℤ} (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_natCast' (hx : 0 ≤ x) (h : y - n ≠ 0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x ≠ 0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (hx : 0 ≤ x) (h : y + 1 ≠ 0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≤ x) (h : 1 + y ≠ 0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≤ x) (h : y - 1 ≠ 0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≤ x) (h : 1 - y ≠ 0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] theorem mul_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all · rw [log_mul ‹_› ‹_›, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' ‹_›)] all_goals positivity theorem inv_rpow (hx : 0 ≤ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] theorem div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancel₀ hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≤ x) (hy : y ≠ 0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancel₀ hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancel₀ hn0, rpow_one] theorem rpow_inv_natCast_pow (hx : 0 ≤ x) (hn : n ≠ 0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancel₀ hn0, rpow_one] lemma rpow_natCast_mul (hx : 0 ≤ x) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≤ x) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≤ x) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≤ x) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr, bound] theorem rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx · rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ · rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr, bound] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x ^ z ≤ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); · rfl rcases eq_or_lt_of_le h₂ with (rfl | h₂'); · simp exact le_of_lt (rpow_lt_rpow h h₁' h₂') theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≤ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_inv₀, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≤ y) (hz : z ≤ 0) : y ^ z ≤ x ^ z := by have := hx.trans_le hxy rw [← inv_le_inv₀, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ theorem rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≤ y ^ z ↔ y ≤ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ≤ y ^ z⁻¹ ↔ x ^ z ≤ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ ≤ y ↔ x ≤ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≤ y ^ z⁻¹ ↔ y ≤ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≤ y ↔ y ^ z ≤ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_inv₀ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≤ x) (hz : z ≤ 0) : x ^ z ≤ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≤ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≤ x ^ z ↔ y ≤ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) : x ^ y ≤ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≤ x ^ z ↔ z ≤ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le] theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x ^ z ≤ 1 := by rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by convert rpow_lt_rpow_of_exponent_lt hx hz exact (rpow_zero x).symm theorem rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x ^ z ≤ 1 := by convert rpow_le_rpow_of_exponent_le hx hz exact (rpow_zero x).symm theorem one_lt_rpow {x z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := by rw [← one_rpow z] exact rpow_lt_rpow zero_le_one hx hz theorem one_le_rpow {x z : ℝ} (hx : 1 ≤ x) (hz : 0 ≤ z) : 1 ≤ x ^ z := by rw [← one_rpow z] exact rpow_le_rpow zero_le_one hx hz theorem one_lt_rpow_of_pos_of_lt_one_of_neg (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := by convert rpow_lt_rpow_of_exponent_gt hx1 hx2 hz exact (rpow_zero x).symm theorem one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) : 1 ≤ x ^ z := by convert rpow_le_rpow_of_exponent_ge hx1 hx2 hz exact (rpow_zero x).symm theorem rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 1 ↔ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx.le, log_neg_iff hx] theorem rpow_lt_one_iff (hx : 0 ≤ x) : x ^ y < 1 ↔ x = 0 ∧ y ≠ 0 ∨ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y := by rcases hx.eq_or_lt with (rfl | hx) · rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, lt_irrefl, zero_lt_one] · simp [rpow_lt_one_iff_of_pos hx, hx.ne.symm] theorem rpow_lt_one_iff' {x y : ℝ} (hx : 0 ≤ x) (hy : 0 < y) : x ^ y < 1 ↔ x < 1 := by rw [← Real.rpow_lt_rpow_iff hx zero_le_one hy, Real.one_rpow] theorem one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ x < 1 ∧ y < 0 := by rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx.le, log_neg_iff hx] theorem one_lt_rpow_iff (hx : 0 ≤ x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ 0 < x ∧ x < 1 ∧ y < 0 := by rcases hx.eq_or_lt with (rfl | hx) · rcases _root_.em (y = 0) with (rfl | hy) <;> simp [*, lt_irrefl, (zero_lt_one' ℝ).not_lt] · simp [one_lt_rpow_iff_of_pos hx, hx] /-- This is a more general but less convenient version of `rpow_le_rpow_of_exponent_ge`. This version allows `x = 0`, so it explicitly forbids `x = y = 0`, `z ≠ 0`. -/ theorem rpow_le_rpow_of_exponent_ge_of_imp (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hyz : z ≤ y) (h : x = 0 → y = 0 → z = 0) : x ^ y ≤ x ^ z := by rcases eq_or_lt_of_le hx0 with (rfl | hx0') · rcases eq_or_ne y 0 with rfl | hy0 · rw [h rfl rfl] · rw [zero_rpow hy0] apply zero_rpow_nonneg · exact rpow_le_rpow_of_exponent_ge hx0' hx1 hyz /-- This version of `rpow_le_rpow_of_exponent_ge` allows `x = 0` but requires `0 ≤ z`. See also `rpow_le_rpow_of_exponent_ge_of_imp` for the most general version. -/ theorem rpow_le_rpow_of_exponent_ge' (hx0 : 0 ≤ x) (hx1 : x ≤ 1) (hz : 0 ≤ z) (hyz : z ≤ y) : x ^ y ≤ x ^ z := rpow_le_rpow_of_exponent_ge_of_imp hx0 hx1 hyz fun _ hy ↦ le_antisymm (hyz.trans_eq hy) hz lemma rpow_max {x y p : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) (hp : 0 ≤ p) : (max x y) ^ p = max (x ^ p) (y ^ p) := by rcases le_total x y with hxy | hxy · rw [max_eq_right hxy, max_eq_right (rpow_le_rpow hx hxy hp)] · rw [max_eq_left hxy, max_eq_left (rpow_le_rpow hy hxy hp)] theorem self_le_rpow_of_le_one (h₁ : 0 ≤ x) (h₂ : x ≤ 1) (h₃ : y ≤ 1) : x ≤ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ h₂ h₃ fun _ ↦ (absurd · one_ne_zero) theorem self_le_rpow_of_one_le (h₁ : 1 ≤ x) (h₂ : 1 ≤ y) : x ≤ x ^ y := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ h₂ theorem rpow_le_self_of_le_one (h₁ : 0 ≤ x) (h₂ : x ≤ 1) (h₃ : 1 ≤ y) : x ^ y ≤ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_ge_of_imp h₁ h₂ h₃ fun _ ↦ (absurd · (one_pos.trans_le h₃).ne') theorem rpow_le_self_of_one_le (h₁ : 1 ≤ x) (h₂ : y ≤ 1) : x ^ y ≤ x := by simpa only [rpow_one] using rpow_le_rpow_of_exponent_le h₁ h₂ theorem self_lt_rpow_of_lt_one (h₁ : 0 < x) (h₂ : x < 1) (h₃ : y < 1) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ h₂ h₃ theorem self_lt_rpow_of_one_lt (h₁ : 1 < x) (h₂ : 1 < y) : x < x ^ y := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ h₂ theorem rpow_lt_self_of_lt_one (h₁ : 0 < x) (h₂ : x < 1) (h₃ : 1 < y) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_gt h₁ h₂ h₃ theorem rpow_lt_self_of_one_lt (h₁ : 1 < x) (h₂ : y < 1) : x ^ y < x := by simpa only [rpow_one] using rpow_lt_rpow_of_exponent_lt h₁ h₂ theorem rpow_left_injOn {x : ℝ} (hx : x ≠ 0) : InjOn (fun y : ℝ => y ^ x) { y : ℝ | 0 ≤ y } := by rintro y hy z hz (hyz : y ^ x = z ^ x) rw [← rpow_one y, ← rpow_one z, ← mul_inv_cancel₀ hx, rpow_mul hy, rpow_mul hz, hyz] lemma rpow_left_inj (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injOn hz).eq_iff hx hy lemma rpow_inv_eq (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x ^ z⁻¹ = y ↔ x = y ^ z := by
rw [← rpow_left_inj _ hy hz, rpow_inv_rpow hx hz]; positivity lemma eq_rpow_inv (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : z ≠ 0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_left_inj hx _ hz, rpow_inv_rpow hy hz]; positivity theorem le_rpow_iff_log_le (hx : 0 < x) (hy : 0 < y) : x ≤ y ^ z ↔ log x ≤ z * log y := by rw [← log_le_log_iff hx (rpow_pos_of_pos hy z), log_rpow hy]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
764
770
/- Copyright (c) 2023 Jz Pan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jz Pan -/ import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.Normal.Closure import Mathlib.RingTheory.AlgebraicIndependent.Adjoin import Mathlib.RingTheory.AlgebraicIndependent.TranscendenceBasis import Mathlib.RingTheory.Polynomial.SeparableDegree import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Separable degree This file contains basics about the separable degree of a field extension. ## Main definitions - `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E` (the algebraic closure of `F` is usually used in the literature, but our definition has the advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F` and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks. - `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an extension `E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. **Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E` for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is the separable closure of `F` in `E`, which is not defined in this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite, then these two definitions coincide. If `E / F` is algebraic with infinite separable degree, we have `#(Field.Emb F E) = 2 ^ Field.sepDegree F E` instead. (See `Field.Emb.cardinal_eq_two_pow_sepDegree` in another file.) For example, if $F = \mathbb{Q}$ and $E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with $\operatorname{Gal}(E/F)$, which is isomorphic to $\mathbb{Z}_p^\times$, which is uncountable, whereas $ [E:F] $ is countable. - `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. ## Main results - `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`: a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. In particular, they have the same cardinality (so their `Field.finSepDegree` are equal). - `Field.embEquivOfAdjoinSplits`, `Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. In particular, they have the same cardinality. - `Field.embEquivOfIsAlgClosed`, `Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. In particular, they have the same cardinality. - `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`: if `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$ (see also `Module.finrank_mul_finrank`). - `Field.infinite_emb_of_transcendental`: `Field.Emb` is infinite for transcendental extensions. - `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than its degree. - `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. - `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. - `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to the number of distinct roots of it over any algebraically closed field. - `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree. - `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable contraction, then its separable degree is equal to its separable contraction degree. - `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible polynomial divides its degree. - `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of `F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`. - `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a separable element. - `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides the degree of `E / F`. - `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. - `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree is equal to its degree if and only if it is a separable extension. - `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element. - `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also separable. ## Tags separable degree, degree, polynomial -/ open Module Polynomial IntermediateField Field noncomputable section universe u v w variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E] variable (K : Type w) [Field K] [Algebra F K] namespace Field /-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`. -/ abbrev Emb := E →ₐ[F] AlgebraicClosure E /-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F` is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`, as a natural number. It is defined to be zero if there are infinitely many of them. Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/ def finSepDegree : ℕ := Nat.card (Emb F E) instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩ instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) := ⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩ /-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic as `F`-algebras. -/ def embEquivOfEquiv (i : E ≃ₐ[F] K) : Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra have : Algebra.IsAlgebraic E K := by constructor intro x have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x) rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h apply AlgEquiv.restrictScalars (R := F) (S := E) exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E) /-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree` over `F`. -/ theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) : finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i) @[simp] theorem finSepDegree_self : finSepDegree F F = 1 := by have : Cardinal.mk (Emb F F) = 1 := le_antisymm (Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton) (Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _) rw [finSepDegree, Nat.card, this, Cardinal.one_toNat] end Field namespace IntermediateField @[simp] theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self] section Tower variable {F} variable [Algebra E K] [IsScalarTower F E K] @[simp] theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E := finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F) @[simp] theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K := finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F) end Tower end IntermediateField namespace Field /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of `IntermediateField.nonempty_algHom_of_adjoin_splits`. -/ def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : Emb F E ≃ (E →ₐ[F] K) := have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) := (hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1) have halg := (topEquiv (F := F) (E := E)).isAlgebraic Classical.choice <| Function.Embedding.antisymm (halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F E (S := S) hK (hS ▸ mem_top)) _) (halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _) /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/ theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤) (hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK) /-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed. -/ def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : Emb F E ≃ (E →ₐ[F] K) := embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩ /-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number, when `E / F` is algebraic and `K / F` is algebraically closed. -/ @[stacks 09HJ "We use `finSepDegree` to state a more general result."] theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] : finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K) /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/ def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : Emb F E × Emb E K ≃ Emb F K := let e : ∀ f : E →ₐ[F] AlgebraicClosure K, @AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦ (@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm (algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans (Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <| fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <| (IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)).restrictScalars F).symm /-- If the field extension `E / F` is transcendental, then `Field.Emb F E` is infinite. -/ instance infinite_emb_of_transcendental [H : Algebra.Transcendental F E] : Infinite (Emb F E) := by obtain ⟨ι, x, hx⟩ := exists_isTranscendenceBasis' F E have := hx.isAlgebraic_field rw [← (embProdEmbOfIsAlgebraic F (adjoin F (Set.range x)) E).infinite_iff] refine @Prod.infinite_of_left _ _ ?_ _ rw [← (embEquivOfEquiv _ _ _ hx.1.aevalEquivField).infinite_iff] obtain ⟨i⟩ := hx.nonempty_iff_transcendental.2 H let K := FractionRing (MvPolynomial ι F) let i1 := IsScalarTower.toAlgHom F (MvPolynomial ι F) (AlgebraicClosure K) have hi1 : Function.Injective i1 := by rw [IsScalarTower.coe_toAlgHom', IsScalarTower.algebraMap_eq _ K] exact (algebraMap K (AlgebraicClosure K)).injective.comp (IsFractionRing.injective _ _) let f (n : ℕ) : Emb F K := IsFractionRing.liftAlgHom (g := i1.comp <| MvPolynomial.aeval fun i : ι ↦ MvPolynomial.X i ^ (n + 1)) <| hi1.comp <| by simpa [algebraicIndependent_iff_injective_aeval] using MvPolynomial.algebraicIndependent_polynomial_aeval_X _ fun i : ι ↦ (Polynomial.transcendental_X F).pow n.succ_pos refine Infinite.of_injective f fun m n h ↦ ?_ replace h : (MvPolynomial.X i) ^ (m + 1) = (MvPolynomial.X i) ^ (n + 1) := hi1 <| by simpa [f, -map_pow] using congr($h (algebraMap _ K (MvPolynomial.X (R := F) i))) simpa using congr(MvPolynomial.totalDegree $h) /-- If the field extension `E / F` is transcendental, then `Field.finSepDegree F E = 0`, which actually means that `Field.Emb F E` is infinite (see `Field.infinite_emb_of_transcendental`). -/ theorem finSepDegree_eq_zero_of_transcendental [Algebra.Transcendental F E] : finSepDegree F E = 0 := Nat.card_eq_zero_of_infinite /-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their separable degrees satisfy the tower law $[E:F]_s [K:E]_s = [K:F]_s$. See also `Module.finrank_mul_finrank`. -/ @[stacks 09HK "Part 1, `finSepDegree` variant"] theorem finSepDegree_mul_finSepDegree_of_isAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] : finSepDegree F E * finSepDegree E K = finSepDegree F K := by simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K) end Field namespace Polynomial variable {F E} variable (f : F[X]) open Classical in /-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number, defined to be the number of distinct roots of it over its splitting field. This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable degree of `0` is `0`, not negative infinity. -/ def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card /-- The separable degree of a polynomial is smaller than its degree. -/ theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by have := f.map (algebraMap F f.SplittingField) |>.card_roots' rw [← aroots_def, natDegree_map] at this classical exact (f.aroots f.SplittingField).toFinset_card_le.trans this @[simp] theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton] @[simp] theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton] /-- A constant polynomial has zero separable degree. -/ theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by linarith only [natSepDegree_le_natDegree f, h] @[simp] theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _) @[simp] theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by rw [← C_0, natSepDegree_C] @[simp] theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by rw [← C_1, natSepDegree_C] /-- A non-constant polynomial has non-zero separable degree. -/ theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty] use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h) classical rw [Multiset.mem_toFinset, mem_aroots] exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩ /-- A polynomial has zero separable degree if and only if it is constant. -/ theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 := ⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩ /-- A polynomial has non-zero separable degree if and only if it is non-constant. -/ theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 := Iff.not <| natSepDegree_eq_zero_iff f /-- The separable degree of a non-zero polynomial is equal to its degree if and only if it is separable. -/ theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) : f.natSepDegree = f.natDegree ↔ f.Separable := by classical simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f), rootSet_def, Finset.coe_sort_coe, Fintype.card_coe] rfl /-- If a polynomial is separable, then its separable degree is equal to its degree. -/ theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) : f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h variable {f} in /-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of dot notation. -/ theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h /-- If a polynomial splits over `E`, then its separable degree is equal to the number of distinct roots of it over `E`. -/ theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) :
Mathlib/FieldTheory/SeparableDegree.lean
362
366
/- Copyright (c) 2020 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou -/ import Mathlib.Data.Set.Order import Mathlib.Order.Bounds.Basic import Mathlib.Order.Interval.Set.Image import Mathlib.Order.Interval.Set.LinearOrder import Mathlib.Tactic.Common /-! # Intervals without endpoints ordering In any lattice `α`, we define `uIcc a b` to be `Icc (a ⊓ b) (a ⊔ b)`, which in a linear order is the set of elements lying between `a` and `b`. `Icc a b` requires the assumption `a ≤ b` to be meaningful, which is sometimes inconvenient. The interval as defined in this file is always the set of things lying between `a` and `b`, regardless of the relative order of `a` and `b`. For real numbers, `uIcc a b` is the same as `segment ℝ a b`. In a product or pi type, `uIcc a b` is the smallest box containing `a` and `b`. For example, `uIcc (1, -1) (-1, 1) = Icc (-1, -1) (1, 1)` is the square of vertices `(1, -1)`, `(-1, -1)`, `(-1, 1)`, `(1, 1)`. In `Finset α` (seen as a hypercube of dimension `Fintype.card α`), `uIcc a b` is the smallest subcube containing both `a` and `b`. ## Notation We use the localized notation `[[a, b]]` for `uIcc a b`. One can open the locale `Interval` to make the notation available. -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Lattice variable [Lattice α] [Lattice β] {a a₁ a₂ b b₁ b₂ x : α} /-- `uIcc a b` is the set of elements lying between `a` and `b`, with `a` and `b` included. Note that we define it more generally in a lattice as `Set.Icc (a ⊓ b) (a ⊔ b)`. In a product type, `uIcc` corresponds to the bounding box of the two elements. -/ def uIcc (a b : α) : Set α := Icc (a ⊓ b) (a ⊔ b) /-- `[[a, b]]` denotes the set of elements lying between `a` and `b`, inclusive. -/ scoped[Interval] notation "[[" a ", " b "]]" => Set.uIcc a b open Interval @[simp] lemma uIcc_toDual (a b : α) : [[toDual a, toDual b]] = ofDual ⁻¹' [[a, b]] := -- Note: needed to hint `(α := α)` after https://github.com/leanprover-community/mathlib4/pull/8386 (elaboration order?) Icc_toDual (α := α) @[deprecated (since := "2025-03-20")] alias dual_uIcc := uIcc_toDual @[simp] theorem uIcc_ofDual (a b : αᵒᵈ) : [[ofDual a, ofDual b]] = toDual ⁻¹' [[a, b]] := Icc_ofDual @[simp] lemma uIcc_of_le (h : a ≤ b) : [[a, b]] = Icc a b := by rw [uIcc, inf_eq_left.2 h, sup_eq_right.2 h] @[simp] lemma uIcc_of_ge (h : b ≤ a) : [[a, b]] = Icc b a := by rw [uIcc, inf_eq_right.2 h, sup_eq_left.2 h]
Mathlib/Order/Interval/Set/UnorderedInterval.lean
78
78
/- 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.Data.Finset.Basic import Mathlib.Data.Finset.Image import Mathlib.Data.Multiset.Fold /-! # The fold operation for a commutative associative operation over a finset. -/ assert_not_exists Monoid namespace Finset open Multiset variable {α β γ : Type*} /-! ### fold -/ section Fold variable (op : β → β → β) [hc : Std.Commutative op] [ha : Std.Associative op] local notation a " * " b => op a b /-- `fold op b f s` folds the commutative associative operation `op` over the `f`-image of `s`, i.e. `fold (+) b f {1,2,3} = f 1 + f 2 + f 3 + b`. -/ def fold (b : β) (f : α → β) (s : Finset α) : β := (s.1.map f).fold op b variable {op} {f : α → β} {b : β} {s : Finset α} {a : α} @[simp] theorem fold_empty : (∅ : Finset α).fold op b f = b := rfl @[simp] theorem fold_cons (h : a ∉ s) : (cons a s h).fold op b f = f a * s.fold op b f := by dsimp only [fold] rw [cons_val, Multiset.map_cons, fold_cons_left] @[simp] theorem fold_insert [DecidableEq α] (h : a ∉ s) : (insert a s).fold op b f = f a * s.fold op b f := by unfold fold rw [insert_val, ndinsert_of_not_mem h, Multiset.map_cons, fold_cons_left] @[simp] theorem fold_singleton : ({a} : Finset α).fold op b f = f a * b := rfl @[simp] theorem fold_map {g : γ ↪ α} {s : Finset γ} : (s.map g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, map, Multiset.map_map] @[simp] theorem fold_image [DecidableEq α] {g : γ → α} {s : Finset γ} (H : ∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) : (s.image g).fold op b f = s.fold op b (f ∘ g) := by simp only [fold, image_val_of_injOn H, Multiset.map_map] @[congr] theorem fold_congr {g : α → β} (H : ∀ x ∈ s, f x = g x) : s.fold op b f = s.fold op b g := by rw [fold, fold, map_congr rfl H] theorem fold_op_distrib {f g : α → β} {b₁ b₂ : β} : (s.fold op (b₁ * b₂) fun x => f x * g x) = s.fold op b₁ f * s.fold op b₂ g := by simp only [fold, fold_distrib] theorem fold_const [hd : Decidable (s = ∅)] (c : β) (h : op c (op b c) = op b c) : Finset.fold op b (fun _ => c) s = if s = ∅ then b else op b c := by classical induction' s using Finset.induction_on with x s hx IH generalizing hd · simp
· simp only [Finset.fold_insert hx, IH, if_false, Finset.insert_ne_empty] split_ifs
Mathlib/Data/Finset/Fold.lean
79
80
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Data.Set.Image import Mathlib.Order.Interval.Set.Basic import Mathlib.Order.WithBot /-! # Intervals in `WithTop α` and `WithBot α` In this file we prove various lemmas about `Set.image`s and `Set.preimage`s of intervals under `some : α → WithTop α` and `some : α → WithBot α`. -/ open Set variable {α : Type*} /-! ### `WithTop` -/ namespace WithTop @[simp] theorem preimage_coe_top : (some : α → WithTop α) ⁻¹' {⊤} = (∅ : Set α) := eq_empty_of_subset_empty fun _ => coe_ne_top variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithTop α) = Iio ⊤ := by ext x rw [mem_Iio, WithTop.lt_top_iff_ne_top, mem_range, ne_top_iff_exists] @[simp] theorem preimage_coe_Ioi : (some : α → WithTop α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithTop α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithTop α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithTop α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithTop α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithTop α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithTop α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithTop α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Iio_top : (some : α → WithTop α) ⁻¹' Iio ⊤ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ico_top : (some : α → WithTop α) ⁻¹' Ico a ⊤ = Ici a := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioo_top : (some : α → WithTop α) ⁻¹' Ioo a ⊤ = Ioi a := by simp [← Ioi_inter_Iio] theorem image_coe_Ioi : (some : α → WithTop α) '' Ioi a = Ioo (a : WithTop α) ⊤ := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, Ioi_inter_Iio] theorem image_coe_Ici : (some : α → WithTop α) '' Ici a = Ico (a : WithTop α) ⊤ := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, Ici_inter_Iio] theorem image_coe_Iio : (some : α → WithTop α) '' Iio a = Iio (a : WithTop α) := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iio_subset_Iio le_top)] theorem image_coe_Iic : (some : α → WithTop α) '' Iic a = Iic (a : WithTop α) := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Iic_subset_Iio.2 <| coe_lt_top a)] theorem image_coe_Icc : (some : α → WithTop α) '' Icc a b = Icc (a : WithTop α) b := by rw [← preimage_coe_Icc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Icc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ico : (some : α → WithTop α) '' Ico a b = Ico (a : WithTop α) b := by rw [← preimage_coe_Ico, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ico_subset_Iio_self <| Iio_subset_Iio le_top)] theorem image_coe_Ioc : (some : α → WithTop α) '' Ioc a b = Ioc (a : WithTop α) b := by rw [← preimage_coe_Ioc, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioc_subset_Iic_self <| Iic_subset_Iio.2 <| coe_lt_top b)] theorem image_coe_Ioo : (some : α → WithTop α) '' Ioo a b = Ioo (a : WithTop α) b := by rw [← preimage_coe_Ioo, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Subset.trans Ioo_subset_Iio_self <| Iio_subset_Iio le_top)] end WithTop /-! ### `WithBot` -/ namespace WithBot @[simp] theorem preimage_coe_bot : (some : α → WithBot α) ⁻¹' {⊥} = (∅ : Set α) := @WithTop.preimage_coe_top αᵒᵈ variable [Preorder α] {a b : α} theorem range_coe : range (some : α → WithBot α) = Ioi ⊥ := @WithTop.range_coe αᵒᵈ _ @[simp] theorem preimage_coe_Ioi : (some : α → WithBot α) ⁻¹' Ioi a = Ioi a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Ici : (some : α → WithBot α) ⁻¹' Ici a = Ici a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Iio : (some : α → WithBot α) ⁻¹' Iio a = Iio a := ext fun _ => coe_lt_coe @[simp] theorem preimage_coe_Iic : (some : α → WithBot α) ⁻¹' Iic a = Iic a := ext fun _ => coe_le_coe @[simp] theorem preimage_coe_Icc : (some : α → WithBot α) ⁻¹' Icc a b = Icc a b := by simp [← Ici_inter_Iic] @[simp] theorem preimage_coe_Ico : (some : α → WithBot α) ⁻¹' Ico a b = Ico a b := by simp [← Ici_inter_Iio] @[simp] theorem preimage_coe_Ioc : (some : α → WithBot α) ⁻¹' Ioc a b = Ioc a b := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo : (some : α → WithBot α) ⁻¹' Ioo a b = Ioo a b := by simp [← Ioi_inter_Iio] @[simp] theorem preimage_coe_Ioi_bot : (some : α → WithBot α) ⁻¹' Ioi ⊥ = univ := by rw [← range_coe, preimage_range] @[simp] theorem preimage_coe_Ioc_bot : (some : α → WithBot α) ⁻¹' Ioc ⊥ a = Iic a := by simp [← Ioi_inter_Iic] @[simp] theorem preimage_coe_Ioo_bot : (some : α → WithBot α) ⁻¹' Ioo ⊥ a = Iio a := by simp [← Ioi_inter_Iio] theorem image_coe_Iio : (some : α → WithBot α) '' Iio a = Ioo (⊥ : WithBot α) a := by rw [← preimage_coe_Iio, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iio] theorem image_coe_Iic : (some : α → WithBot α) '' Iic a = Ioc (⊥ : WithBot α) a := by rw [← preimage_coe_Iic, image_preimage_eq_inter_range, range_coe, inter_comm, Ioi_inter_Iic] theorem image_coe_Ioi : (some : α → WithBot α) '' Ioi a = Ioi (a : WithBot α) := by rw [← preimage_coe_Ioi, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ioi_subset_Ioi bot_le)] theorem image_coe_Ici : (some : α → WithBot α) '' Ici a = Ici (a : WithBot α) := by rw [← preimage_coe_Ici, image_preimage_eq_inter_range, range_coe, inter_eq_self_of_subset_left (Ici_subset_Ioi.2 <| bot_lt_coe a)]
Mathlib/Order/Interval/Set/WithBotTop.lean
175
175
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.GeomSum import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.Ideal.Span /-! # Basic results in number theory This file should contain basic results in number theory. So far, it only contains the essential lemma in the construction of the ring of Witt vectors. ## Main statement `dvd_sub_pow_of_dvd_sub` proves that for elements `a` and `b` in a commutative ring `R` and for all natural numbers `p` and `k` if `p` divides `a-b` in `R`, then `p ^ (k + 1)` divides `a ^ (p ^ k) - b ^ (p ^ k)`. -/ section open Ideal Ideal.Quotient theorem dvd_sub_pow_of_dvd_sub {R : Type*} [CommRing R] {p : ℕ} {a b : R} (h : (p : R) ∣ a - b)
(k : ℕ) : (p ^ (k + 1) : R) ∣ a ^ p ^ k - b ^ p ^ k := by induction k with | zero => rwa [pow_one, pow_zero, pow_one, pow_one] | succ k ih => rw [pow_succ p k, pow_mul, pow_mul, ← geom_sum₂_mul, pow_succ'] refine mul_dvd_mul ?_ ih let f : R →+* R ⧸ span {(p : R)} := mk (span {(p : R)}) have hf : ∀ r : R, (p : R) ∣ r ↔ f r = 0 := fun r ↦ by rw [eq_zero_iff_mem, mem_span_singleton] rw [hf, map_sub, sub_eq_zero] at h rw [hf, RingHom.map_geom_sum₂, map_pow, map_pow, h, geom_sum₂_self, mul_eq_zero_of_left] rw [← map_natCast f, eq_zero_iff_mem, mem_span_singleton]
Mathlib/NumberTheory/Basic.lean
29
39
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Eric Wieser -/ import Mathlib.Data.Matrix.ConjTranspose /-! # Row and column matrices This file provides results about row and column matrices. ## Main definitions * `Matrix.replicateRow ι r : Matrix ι n α`: the matrix where every row is the vector `r : n → α` * `Matrix.replicateCol ι c : Matrix m ι α`: the matrix where every column is the vector `c : m → α` * `Matrix.updateRow M i r`: update the `i`th row of `M` to `r` * `Matrix.updateCol M j c`: update the `j`th column of `M` to `c` -/ variable {l m n o : Type*} universe u v w variable {R : Type*} {α : Type v} {β : Type w} namespace Matrix /-- `Matrix.replicateCol ι u` is the matrix with all columns equal to the vector `u`. To get a column matrix with exactly one column, `Matrix.replicateCol (Fin 1) u` is the canonical choice. -/ def replicateCol (ι : Type*) (w : m → α) : Matrix m ι α := of fun x _ => w x -- TODO: set as an equation lemma for `replicateCol`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateCol_apply {ι : Type*} (w : m → α) (i) (j : ι) : replicateCol ι w i j = w i := rfl /-- `Matrix.replicateRow ι u` is the matrix with all rows equal to the vector `u`. To get a row matrix with exactly one row, `Matrix.replicateRow (Fin 1) u` is the canonical choice. -/ def replicateRow (ι : Type*) (v : n → α) : Matrix ι n α := of fun _ y => v y variable {ι : Type*} -- TODO: set as an equation lemma for `replicateRow`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem replicateRow_apply (v : n → α) (i : ι) (j) : replicateRow ι v i j = v j := rfl theorem replicateCol_injective [Nonempty ι] : Function.Injective (replicateCol ι : (m → α) → Matrix m ι α) := by inhabit ι exact fun _x _y h => funext fun i => congr_fun₂ h i default @[deprecated (since := "2025-03-20")] alias col_injective := replicateCol_injective @[simp] theorem replicateCol_inj [Nonempty ι] {v w : m → α} : replicateCol ι v = replicateCol ι w ↔ v = w := replicateCol_injective.eq_iff @[deprecated (since := "2025-03-20")] alias col_inj := replicateCol_inj @[simp] theorem replicateCol_zero [Zero α] : replicateCol ι (0 : m → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias col_zero := replicateCol_zero @[simp] theorem replicateCol_eq_zero [Zero α] [Nonempty ι] (v : m → α) : replicateCol ι v = 0 ↔ v = 0 := replicateCol_inj @[deprecated (since := "2025-03-20")] alias col_eq_zero := replicateCol_eq_zero @[simp] theorem replicateCol_add [Add α] (v w : m → α) : replicateCol ι (v + w) = replicateCol ι v + replicateCol ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias col_add := replicateCol_add @[simp] theorem replicateCol_smul [SMul R α] (x : R) (v : m → α) : replicateCol ι (x • v) = x • replicateCol ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias col_smul := replicateCol_smul theorem replicateRow_injective [Nonempty ι] : Function.Injective (replicateRow ι : (n → α) → Matrix ι n α) := by inhabit ι exact fun _x _y h => funext fun j => congr_fun₂ h default j @[deprecated (since := "2025-03-20")] alias row_injective := replicateRow_injective @[simp] theorem replicateRow_inj [Nonempty ι] {v w : n → α} : replicateRow ι v = replicateRow ι w ↔ v = w := replicateRow_injective.eq_iff @[simp] theorem replicateRow_zero [Zero α] : replicateRow ι (0 : n → α) = 0 := rfl @[deprecated (since := "2025-03-20")] alias row_zero := replicateRow_zero @[simp] theorem replicateRow_eq_zero [Zero α] [Nonempty ι] (v : n → α) : replicateRow ι v = 0 ↔ v = 0 := replicateRow_inj @[deprecated (since := "2025-03-20")] alias row_eq_zero := replicateRow_eq_zero @[simp] theorem replicateRow_add [Add α] (v w : m → α) : replicateRow ι (v + w) = replicateRow ι v + replicateRow ι w := by ext rfl @[deprecated (since := "2025-03-20")] alias row_add := replicateRow_add @[simp] theorem replicateRow_smul [SMul R α] (x : R) (v : m → α) : replicateRow ι (x • v) = x • replicateRow ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias row_smul := replicateRow_smul @[simp] theorem transpose_replicateCol (v : m → α) : (replicateCol ι v)ᵀ = replicateRow ι v := by ext rfl @[simp] theorem transpose_replicateRow (v : m → α) : (replicateRow ι v)ᵀ = replicateCol ι v := by ext rfl @[simp] theorem conjTranspose_replicateCol [Star α] (v : m → α) : (replicateCol ι v)ᴴ = replicateRow ι (star v) := by ext rfl @[deprecated (since := "2025-03-20")] alias conjTranspose_col := conjTranspose_replicateCol @[simp] theorem conjTranspose_replicateRow [Star α] (v : m → α) : (replicateRow ι v)ᴴ = replicateCol ι (star v) := by ext rfl @[deprecated (since := "2025-03-20")] alias conjTranspose_row := conjTranspose_replicateRow theorem replicateRow_vecMul [Fintype m] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : m → α) : replicateRow ι (v ᵥ* M) = replicateRow ι v * M := by ext rfl @[deprecated (since := "2025-03-20")] alias row_vecMul := replicateRow_vecMul theorem replicateCol_vecMul [Fintype m] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : m → α) : replicateCol ι (v ᵥ* M) = (replicateRow ι v * M)ᵀ := by ext rfl @[deprecated (since := "2025-03-20")] alias col_vecMul := replicateCol_vecMul theorem replicateCol_mulVec [Fintype n] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : n → α) : replicateCol ι (M *ᵥ v) = M * replicateCol ι v := by ext rfl @[deprecated (since := "2025-03-20")] alias col_mulVec := replicateCol_mulVec theorem replicateRow_mulVec [Fintype n] [NonUnitalNonAssocSemiring α] (M : Matrix m n α) (v : n → α) : replicateRow ι (M *ᵥ v) = (M * replicateCol ι v)ᵀ := by ext rfl @[deprecated (since := "2025-03-20")] alias row_mulVec := replicateRow_mulVec theorem replicateRow_mulVec_eq_const [Fintype m] [NonUnitalNonAssocSemiring α] (v w : m → α) : replicateRow ι v *ᵥ w = Function.const _ (v ⬝ᵥ w) := rfl @[deprecated (since := "2025-03-20")] alias row_mulVec_eq_const := replicateRow_mulVec_eq_const theorem mulVec_replicateCol_eq_const [Fintype m] [NonUnitalNonAssocSemiring α] (v w : m → α) : v ᵥ* replicateCol ι w = Function.const _ (v ⬝ᵥ w) := rfl @[deprecated (since := "2025-03-20")] alias mulVec_col_eq_const := mulVec_replicateCol_eq_const theorem replicateRow_mul_replicateCol [Fintype m] [Mul α] [AddCommMonoid α] (v w : m → α) : replicateRow ι v * replicateCol ι w = of fun _ _ => v ⬝ᵥ w := rfl @[deprecated (since := "2025-03-20")] alias row_mul_col := replicateRow_mul_replicateCol @[simp] theorem replicateRow_mul_replicateCol_apply [Fintype m] [Mul α] [AddCommMonoid α] (v w : m → α) (i j) : (replicateRow ι v * replicateCol ι w) i j = v ⬝ᵥ w := rfl @[deprecated (since := "2025-03-20")] alias row_mul_col_apply := replicateRow_mul_replicateCol_apply @[simp] theorem diag_replicateCol_mul_replicateRow [Mul α] [AddCommMonoid α] [Unique ι] (a b : n → α) : diag (replicateCol ι a * replicateRow ι b) = a * b := by ext simp [Matrix.mul_apply, replicateCol, replicateRow] @[deprecated (since := "2025-03-20")] alias diag_col_mul_row := diag_replicateCol_mul_replicateRow variable (ι) theorem vecMulVec_eq [Mul α] [AddCommMonoid α] [Unique ι] (w : m → α) (v : n → α) : vecMulVec w v = replicateCol ι w * replicateRow ι v := by ext simp [vecMulVec, mul_apply] /-! ### Updating rows and columns -/ /-- Update, i.e. replace the `i`th row of matrix `A` with the values in `b`. -/ def updateRow [DecidableEq m] (M : Matrix m n α) (i : m) (b : n → α) : Matrix m n α := of <| Function.update M i b /-- Update, i.e. replace the `j`th column of matrix `A` with the values in `b`. -/ def updateCol [DecidableEq n] (M : Matrix m n α) (j : n) (b : m → α) : Matrix m n α := of fun i => Function.update (M i) j (b i) @[deprecated (since := "2024-12-11")] alias updateColumn := updateCol variable {M : Matrix m n α} {i : m} {j : n} {b : n → α} {c : m → α} @[simp]
theorem updateRow_self [DecidableEq m] : updateRow M i b i = b := Function.update_self (β := fun _ => (n → α)) i b M @[simp] theorem updateCol_self [DecidableEq n] : updateCol M j c i j = c i :=
Mathlib/Data/Matrix/RowCol.lean
241
245
/- Copyright (c) 2021 Benjamin Davidson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog import Mathlib.Analysis.SpecialFunctions.NonIntegrable import Mathlib.Analysis.SpecialFunctions.Pow.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv import Mathlib.MeasureTheory.Integral.IntervalIntegral.IntegrationByParts /-! # Integration of specific interval integrals This file contains proofs of the integrals of various specific functions. This includes: * Integrals of simple functions, such as `id`, `pow`, `inv`, `exp`, `log` * Integrals of some trigonometric functions, such as `sin`, `cos`, `1 / (1 + x^2)` * The integral of `cos x ^ 2 - sin x ^ 2` * Reduction formulae for the integrals of `sin x ^ n` and `cos x ^ n` for `n ≥ 2` * The computation of `∫ x in 0..π, sin x ^ n` as a product for even and odd `n` (used in proving the Wallis product for pi) * Integrals of the form `sin x ^ m * cos x ^ n` With these lemmas, many simple integrals can be computed by `simp` or `norm_num`. This file also contains some facts about the interval integrability of specific functions. This file is still being developed. ## Tags integrate, integration, integrable, integrability -/ open Real Set Finset open scoped Real Interval variable {a b : ℝ} (n : ℕ) namespace intervalIntegral open MeasureTheory variable {f : ℝ → ℝ} {μ : Measure ℝ} [IsLocallyFiniteMeasure μ] (c d : ℝ) /-! ### Interval integrability -/ @[simp] theorem intervalIntegrable_pow : IntervalIntegrable (fun x => x ^ n) μ a b := (continuous_pow n).intervalIntegrable a b theorem intervalIntegrable_zpow {n : ℤ} (h : 0 ≤ n ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ n) μ a b := (continuousOn_id.zpow₀ n fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_rpow {r : ℝ} (h : 0 ≤ r ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x => x ^ r) μ a b := (continuousOn_id.rpow_const fun _ hx => h.symm.imp (ne_of_mem_of_not_mem hx) id).intervalIntegrable /-- See `intervalIntegrable_rpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_rpow' {r : ℝ} (h : -1 < r) : IntervalIntegrable (fun x => x ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => x ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => x ^ r) volume 0 c := by intro c hc rw [intervalIntegrable_iff, uIoc_of_le hc] have hderiv : ∀ x ∈ Ioo 0 c, HasDerivAt (fun x : ℝ => x ^ (r + 1) / (r + 1)) (x ^ r) x := by intro x hx convert (Real.hasDerivAt_rpow_const (p := r + 1) (Or.inl hx.1.ne')).div_const (r + 1) using 1 field_simp [(by linarith : r + 1 ≠ 0)] apply integrableOn_deriv_of_nonneg _ hderiv · intro x hx; apply rpow_nonneg hx.1.le · refine (continuousOn_id.rpow_const ?_).div_const _; intro x _; right; linarith intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).smul (cos (r * π)) rw [intervalIntegrable_iff] at m ⊢ refine m.congr_fun ?_ measurableSet_Ioc; intro x hx rw [uIoc_of_le (by linarith : 0 ≤ -c)] at hx simp only [Pi.smul_apply, Algebra.id.smul_eq_mul, log_neg_eq_log, mul_comm, rpow_def_of_pos hx.1, rpow_def_of_neg (by linarith [hx.1] : -x < 0)] /-- The power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s`. -/ lemma integrableOn_Ioo_rpow_iff {s t : ℝ} (ht : 0 < t) : IntegrableOn (fun x ↦ x ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_rpow' h (a := 0) (b := t)⟩ contrapose! h intro H have I : 0 < min 1 t := lt_min zero_lt_one ht have H' : IntegrableOn (fun x ↦ x ^ s) (Ioo 0 (min 1 t)) := H.mono (Set.Ioo_subset_Ioo le_rfl (min_le_right _ _)) le_rfl have : IntegrableOn (fun x ↦ x⁻¹) (Ioo 0 (min 1 t)) := by apply H'.mono' measurable_inv.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Ioo] with x hx simp only [norm_inv, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hx.1)] rwa [← Real.rpow_neg_one x, Real.rpow_le_rpow_left_iff_of_base_lt_one hx.1] exact lt_of_lt_of_le hx.2 (min_le_left _ _) have : IntervalIntegrable (fun x ↦ x⁻¹) volume 0 (min 1 t) := by rwa [intervalIntegrable_iff_integrableOn_Ioo_of_le I.le] simp [intervalIntegrable_inv_iff, I.ne] at this /-- See `intervalIntegrable_cpow'` for a version with a weaker hypothesis on `r`, but assuming the measure is volume. -/ theorem intervalIntegrable_cpow {r : ℂ} (h : 0 ≤ r.re ∨ (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) μ a b := by by_cases h2 : (0 : ℝ) ∉ [[a, b]] · -- Easy case #1: 0 ∉ [a, b] -- use continuity. refine (continuousOn_of_forall_continuousAt fun x hx => ?_).intervalIntegrable exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) rw [eq_false h2, or_false] at h rcases lt_or_eq_of_le h with (h' | h') · -- Easy case #2: 0 < re r -- again use continuity exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ -- Now the hard case: re r = 0 and 0 is in the interval. refine (IntervalIntegrable.intervalIntegrable_norm_iff ?_).mp ?_ · refine (measurable_of_continuousOn_compl_singleton (0 : ℝ) ?_).aestronglyMeasurable exact continuousOn_of_forall_continuousAt fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) -- reduce to case of integral over `[0, c]` suffices ∀ c : ℝ, IntervalIntegrable (fun x : ℝ => ‖(x : ℂ) ^ r‖) μ 0 c from (this a).symm.trans (this b) intro c rcases le_or_lt 0 c with (hc | hc) · -- case `0 ≤ c`: integrand is identically 1 have : IntervalIntegrable (fun _ => 1 : ℝ → ℝ) μ 0 c := intervalIntegrable_const rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc] at this ⊢ refine IntegrableOn.congr_fun this (fun x hx => ?_) measurableSet_Ioc dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] · -- case `c < 0`: integrand is identically constant, *except* at `x = 0` if `r ≠ 0`. apply IntervalIntegrable.symm rw [intervalIntegrable_iff_integrableOn_Ioc_of_le hc.le] rw [← Ioo_union_right hc, integrableOn_union, and_comm]; constructor · refine integrableOn_singleton_iff.mpr (Or.inr ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton · have : ∀ x : ℝ, x ∈ Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖(x : ℂ) ^ r‖ := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] refine IntegrableOn.congr_fun ?_ this measurableSet_Ioo rw [integrableOn_const] refine Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt ?_) exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc /-- See `intervalIntegrable_cpow` for a version applying to any locally finite measure, but with a stronger hypothesis on `r`. -/ theorem intervalIntegrable_cpow' {r : ℂ} (h : -1 < r.re) : IntervalIntegrable (fun x : ℝ => (x : ℂ) ^ r) volume a b := by suffices ∀ c : ℝ, IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c by exact IntervalIntegrable.trans (this a).symm (this b) have : ∀ c : ℝ, 0 ≤ c → IntervalIntegrable (fun x => (x : ℂ) ^ r) volume 0 c := by intro c hc rw [← IntervalIntegrable.intervalIntegrable_norm_iff] · rw [intervalIntegrable_iff] apply IntegrableOn.congr_fun · rw [← intervalIntegrable_iff]; exact intervalIntegral.intervalIntegrable_rpow' h · intro x hx rw [uIoc_of_le hc] at hx dsimp only rw [Complex.norm_cpow_eq_rpow_re_of_pos hx.1] · exact measurableSet_uIoc · refine ContinuousOn.aestronglyMeasurable ?_ measurableSet_uIoc refine continuousOn_of_forall_continuousAt fun x hx => ?_ rw [uIoc_of_le hc] at hx refine (continuousAt_cpow_const (Or.inl ?_)).comp Complex.continuous_ofReal.continuousAt rw [Complex.ofReal_re] exact hx.1 intro c; rcases le_total 0 c with (hc | hc) · exact this c hc · rw [IntervalIntegrable.iff_comp_neg, neg_zero] have m := (this (-c) (by linarith)).const_mul (Complex.exp (π * Complex.I * r)) rw [intervalIntegrable_iff, uIoc_of_le (by linarith : 0 ≤ -c)] at m ⊢ refine m.congr_fun (fun x hx => ?_) measurableSet_Ioc dsimp only have : -x ≤ 0 := by linarith [hx.1] rw [Complex.ofReal_cpow_of_nonpos this, mul_comm] simp /-- The complex power function `x ↦ x^s` is integrable on `(0, t)` iff `-1 < s.re`. -/ theorem integrableOn_Ioo_cpow_iff {s : ℂ} {t : ℝ} (ht : 0 < t) : IntegrableOn (fun x : ℝ ↦ (x : ℂ) ^ s) (Ioo (0 : ℝ) t) ↔ -1 < s.re := by refine ⟨fun h ↦ ?_, fun h ↦ by simpa [intervalIntegrable_iff_integrableOn_Ioo_of_le ht.le] using intervalIntegrable_cpow' h (a := 0) (b := t)⟩ have B : IntegrableOn (fun a ↦ a ^ s.re) (Ioo 0 t) := by apply (integrableOn_congr_fun _ measurableSet_Ioo).1 h.norm intro a ha simp [Complex.norm_cpow_eq_rpow_re_of_pos ha.1] rwa [integrableOn_Ioo_rpow_iff ht] at B @[simp] theorem intervalIntegrable_id : IntervalIntegrable (fun x => x) μ a b := continuous_id.intervalIntegrable a b theorem intervalIntegrable_const : IntervalIntegrable (fun _ => c) μ a b := continuous_const.intervalIntegrable a b theorem intervalIntegrable_one_div (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => 1 / f x) μ a b := (continuousOn_const.div hf h).intervalIntegrable @[simp] theorem intervalIntegrable_inv (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) (hf : ContinuousOn f [[a, b]]) : IntervalIntegrable (fun x => (f x)⁻¹) μ a b := by simpa only [one_div] using intervalIntegrable_one_div h hf @[simp] theorem intervalIntegrable_exp : IntervalIntegrable exp μ a b := continuous_exp.intervalIntegrable a b @[simp] theorem _root_.IntervalIntegrable.log (hf : ContinuousOn f [[a, b]]) (h : ∀ x : ℝ, x ∈ [[a, b]] → f x ≠ 0) : IntervalIntegrable (fun x => log (f x)) μ a b := (ContinuousOn.log hf h).intervalIntegrable /-- See `intervalIntegrable_log'` for a version without any hypothesis on the interval, but assuming the measure is volume. -/ @[simp] theorem intervalIntegrable_log (h : (0 : ℝ) ∉ [[a, b]]) : IntervalIntegrable log μ a b := IntervalIntegrable.log continuousOn_id fun _ hx => ne_of_mem_of_not_mem hx h /-- The real logarithm is interval integrable (with respect to the volume measure) on every interval. See `intervalIntegrable_log` for a version applying to any locally finite measure, but with an additional hypothesis on the interval. -/ @[simp] theorem intervalIntegrable_log' : IntervalIntegrable log volume a b := by -- Log is even, so it suffices to consider the case 0 < a and b = 0 apply intervalIntegrable_of_even (log_neg_eq_log · |>.symm) intro x hx -- Split integral apply IntervalIntegrable.trans (b := 1) · -- Show integrability on [0…1] using non-negativity of the derivative rw [← neg_neg log] apply IntervalIntegrable.neg apply intervalIntegrable_deriv_of_nonneg (g := fun x ↦ -(x * log x - x)) · exact (continuous_mul_log.continuousOn.sub continuous_id.continuousOn).neg · intro s ⟨hs, _⟩ norm_num at * simpa using (hasDerivAt_id s).sub (hasDerivAt_mul_log hs.ne.symm) · intro s ⟨hs₁, hs₂⟩ norm_num at * exact (log_nonpos_iff hs₁.le).mpr hs₂.le · -- Show integrability on [1…t] by continuity apply ContinuousOn.intervalIntegrable apply Real.continuousOn_log.mono apply Set.not_mem_uIcc_of_lt zero_lt_one at hx simpa @[simp] theorem intervalIntegrable_sin : IntervalIntegrable sin μ a b := continuous_sin.intervalIntegrable a b @[simp] theorem intervalIntegrable_cos : IntervalIntegrable cos μ a b := continuous_cos.intervalIntegrable a b theorem intervalIntegrable_one_div_one_add_sq : IntervalIntegrable (fun x : ℝ => 1 / (↑1 + x ^ 2)) μ a b := by refine (continuous_const.div ?_ fun x => ?_).intervalIntegrable a b · fun_prop · nlinarith @[simp] theorem intervalIntegrable_inv_one_add_sq : IntervalIntegrable (fun x : ℝ => (↑1 + x ^ 2)⁻¹) μ a b := by field_simp; exact mod_cast intervalIntegrable_one_div_one_add_sq /-! ### Integrals of the form `c * ∫ x in a..b, f (c * x + d)` -/ section @[simp] theorem mul_integral_comp_mul_right : (c * ∫ x in a..b, f (x * c)) = ∫ x in a * c..b * c, f x := smul_integral_comp_mul_right f c @[simp] theorem mul_integral_comp_mul_left : (c * ∫ x in a..b, f (c * x)) = ∫ x in c * a..c * b, f x := smul_integral_comp_mul_left f c @[simp] theorem inv_mul_integral_comp_div : (c⁻¹ * ∫ x in a..b, f (x / c)) = ∫ x in a / c..b / c, f x := inv_smul_integral_comp_div f c @[simp] theorem mul_integral_comp_mul_add : (c * ∫ x in a..b, f (c * x + d)) = ∫ x in c * a + d..c * b + d, f x := smul_integral_comp_mul_add f c d @[simp] theorem mul_integral_comp_add_mul : (c * ∫ x in a..b, f (d + c * x)) = ∫ x in d + c * a..d + c * b, f x := smul_integral_comp_add_mul f c d @[simp] theorem inv_mul_integral_comp_div_add : (c⁻¹ * ∫ x in a..b, f (x / c + d)) = ∫ x in a / c + d..b / c + d, f x := inv_smul_integral_comp_div_add f c d @[simp] theorem inv_mul_integral_comp_add_div : (c⁻¹ * ∫ x in a..b, f (d + x / c)) = ∫ x in d + a / c..d + b / c, f x := inv_smul_integral_comp_add_div f c d @[simp] theorem mul_integral_comp_mul_sub : (c * ∫ x in a..b, f (c * x - d)) = ∫ x in c * a - d..c * b - d, f x := smul_integral_comp_mul_sub f c d @[simp] theorem mul_integral_comp_sub_mul : (c * ∫ x in a..b, f (d - c * x)) = ∫ x in d - c * b..d - c * a, f x := smul_integral_comp_sub_mul f c d @[simp] theorem inv_mul_integral_comp_div_sub : (c⁻¹ * ∫ x in a..b, f (x / c - d)) = ∫ x in a / c - d..b / c - d, f x := inv_smul_integral_comp_div_sub f c d @[simp] theorem inv_mul_integral_comp_sub_div : (c⁻¹ * ∫ x in a..b, f (d - x / c)) = ∫ x in d - b / c..d - a / c, f x := inv_smul_integral_comp_sub_div f c d end end intervalIntegral open intervalIntegral /-! ### Integrals of simple functions -/ theorem integral_cpow {r : ℂ} (h : -1 < r.re ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : (∫ x : ℝ in a..b, (x : ℂ) ^ r) = ((b : ℂ) ^ (r + 1) - (a : ℂ) ^ (r + 1)) / (r + 1) := by rw [sub_div] have hr : r + 1 ≠ 0 := by rcases h with h | h · apply_fun Complex.re rw [Complex.add_re, Complex.one_re, Complex.zero_re, Ne, add_eq_zero_iff_eq_neg] exact h.ne' · rw [Ne, ← add_eq_zero_iff_eq_neg] at h; exact h.1 by_cases hab : (0 : ℝ) ∉ [[a, b]] · apply integral_eq_sub_of_hasDerivAt (fun x hx => ?_) (intervalIntegrable_cpow (r := r) <| Or.inr hab) refine hasDerivAt_ofReal_cpow_const' (ne_of_mem_of_not_mem hx hab) ?_ contrapose! hr; rwa [add_eq_zero_iff_eq_neg] replace h : -1 < r.re := by tauto suffices ∀ c : ℝ, (∫ x : ℝ in (0)..c, (x : ℂ) ^ r) = (c : ℂ) ^ (r + 1) / (r + 1) - (0 : ℂ) ^ (r + 1) / (r + 1) by rw [← integral_add_adjacent_intervals (@intervalIntegrable_cpow' a 0 r h) (@intervalIntegrable_cpow' 0 b r h), integral_symm, this a, this b, Complex.zero_cpow hr] ring intro c apply integral_eq_sub_of_hasDeriv_right · refine ((Complex.continuous_ofReal_cpow_const ?_).div_const _).continuousOn rwa [Complex.add_re, Complex.one_re, ← neg_lt_iff_pos_add] · refine fun x hx => (hasDerivAt_ofReal_cpow_const' ?_ ?_).hasDerivWithinAt · rcases le_total c 0 with (hc | hc) · rw [max_eq_left hc] at hx; exact hx.2.ne · rw [min_eq_left hc] at hx; exact hx.1.ne' · contrapose! hr; rw [hr]; ring · exact intervalIntegrable_cpow' h theorem integral_rpow {r : ℝ} (h : -1 < r ∨ r ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ r = (b ^ (r + 1) - a ^ (r + 1)) / (r + 1) := by have h' : -1 < (r : ℂ).re ∨ (r : ℂ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := by cases h · left; rwa [Complex.ofReal_re] · right; rwa [← Complex.ofReal_one, ← Complex.ofReal_neg, Ne, Complex.ofReal_inj] have : (∫ x in a..b, (x : ℂ) ^ (r : ℂ)) = ((b : ℂ) ^ (r + 1 : ℂ) - (a : ℂ) ^ (r + 1 : ℂ)) / (r + 1) := integral_cpow h' apply_fun Complex.re at this; convert this · simp_rw [intervalIntegral_eq_integral_uIoc, Complex.real_smul, Complex.re_ofReal_mul, rpow_def, ← RCLike.re_eq_complex_re, smul_eq_mul] rw [integral_re] refine intervalIntegrable_iff.mp ?_ rcases h' with h' | h' · exact intervalIntegrable_cpow' h' · exact intervalIntegrable_cpow (Or.inr h'.2) · rw [(by push_cast; rfl : (r : ℂ) + 1 = ((r + 1 : ℝ) : ℂ))] simp_rw [div_eq_inv_mul, ← Complex.ofReal_inv, Complex.re_ofReal_mul, Complex.sub_re, rpow_def] theorem integral_zpow {n : ℤ} (h : 0 ≤ n ∨ n ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by replace h : -1 < (n : ℝ) ∨ (n : ℝ) ≠ -1 ∧ (0 : ℝ) ∉ [[a, b]] := mod_cast h exact mod_cast integral_rpow h @[simp] theorem integral_pow : ∫ x in a..b, x ^ n = (b ^ (n + 1) - a ^ (n + 1)) / (n + 1) := by simpa only [← Int.natCast_succ, zpow_natCast] using integral_zpow (Or.inl n.cast_nonneg) /-- Integral of `|x - a| ^ n` over `Ι a b`. This integral appears in the proof of the Picard-Lindelöf/Cauchy-Lipschitz theorem. -/ theorem integral_pow_abs_sub_uIoc : ∫ x in Ι a b, |x - a| ^ n = |b - a| ^ (n + 1) / (n + 1) := by rcases le_or_lt a b with hab | hab · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in a..b, |x - a| ^ n := by rw [uIoc_of_le hab, ← integral_of_le hab] _ = ∫ x in (0)..(b - a), x ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonneg <| ?_) rfl rw [uIcc_of_le (sub_nonneg.2 hab)] at hx exact hx.1 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [abs_of_nonneg (sub_nonneg.2 hab)] · calc ∫ x in Ι a b, |x - a| ^ n = ∫ x in b..a, |x - a| ^ n := by rw [uIoc_of_ge hab.le, ← integral_of_le hab.le] _ = ∫ x in b - a..0, (-x) ^ n := by simp only [integral_comp_sub_right fun x => |x| ^ n, sub_self] refine integral_congr fun x hx => congr_arg₂ Pow.pow (abs_of_nonpos <| ?_) rfl rw [uIcc_of_le (sub_nonpos.2 hab.le)] at hx exact hx.2 _ = |b - a| ^ (n + 1) / (n + 1) := by simp [integral_comp_neg fun x => x ^ n, abs_of_neg (sub_neg.2 hab)] @[simp] theorem integral_id : ∫ x in a..b, x = (b ^ 2 - a ^ 2) / 2 := by have := @integral_pow a b 1 norm_num at this exact this theorem integral_one : (∫ _ in a..b, (1 : ℝ)) = b - a := by simp only [mul_one, smul_eq_mul, integral_const] theorem integral_const_on_unit_interval : ∫ _ in a..a + 1, b = b := by simp @[simp] theorem integral_inv (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x in a..b, x⁻¹ = log (b / a) := by have h' := fun x (hx : x ∈ [[a, b]]) => ne_of_mem_of_not_mem hx h rw [integral_deriv_eq_sub' _ deriv_log' (fun x hx => differentiableAt_log (h' x hx)) (continuousOn_inv₀.mono <| subset_compl_singleton_iff.mpr h), log_div (h' b right_mem_uIcc) (h' a left_mem_uIcc)] @[simp] theorem integral_inv_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_lt ha hb @[simp] theorem integral_inv_of_neg (ha : a < 0) (hb : b < 0) : ∫ x in a..b, x⁻¹ = log (b / a) := integral_inv <| not_mem_uIcc_of_gt ha hb theorem integral_one_div (h : (0 : ℝ) ∉ [[a, b]]) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv h] theorem integral_one_div_of_pos (ha : 0 < a) (hb : 0 < b) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_pos ha hb] theorem integral_one_div_of_neg (ha : a < 0) (hb : b < 0) : ∫ x : ℝ in a..b, 1 / x = log (b / a) := by simp only [one_div, integral_inv_of_neg ha hb] @[simp] theorem integral_exp : ∫ x in a..b, exp x = exp b - exp a := by rw [integral_deriv_eq_sub'] · simp · exact fun _ _ => differentiableAt_exp · exact continuousOn_exp theorem integral_exp_mul_complex {c : ℂ} (hc : c ≠ 0) : (∫ x in a..b, Complex.exp (c * x)) = (Complex.exp (c * b) - Complex.exp (c * a)) / c := by have D : ∀ x : ℝ, HasDerivAt (fun y : ℝ => Complex.exp (c * y) / c) (Complex.exp (c * x)) x := by intro x conv => congr rw [← mul_div_cancel_right₀ (Complex.exp (c * x)) hc] apply ((Complex.hasDerivAt_exp _).comp x _).div_const c simpa only [mul_one] using ((hasDerivAt_id (x : ℂ)).const_mul _).comp_ofReal rw [integral_deriv_eq_sub' _ (funext fun x => (D x).deriv) fun x _ => (D x).differentiableAt] · ring · fun_prop /-- Helper lemma for `integral_log`: case where `a = 0` and `b` is positive. -/ lemma integral_log_from_zero_of_pos (ht : 0 < b) : ∫ s in (0)..b, log s = b * log b - b := by -- Compute the integral by giving a primitive and considering it limit as x approaches 0 from the -- right. The following lines were suggested by Gareth Ma on Zulip. rw [integral_eq_sub_of_hasDerivAt_of_tendsto (f := fun x ↦ x * log x - x) (fa := 0) (fb := b * log b - b) (hint := intervalIntegrable_log')] · abel · exact ht · intro s ⟨hs, _ ⟩ simpa using (hasDerivAt_mul_log hs.ne.symm).sub (hasDerivAt_id s) · simpa [mul_comm] using ((tendsto_log_mul_rpow_nhdsGT_zero zero_lt_one).sub (tendsto_nhdsWithin_of_tendsto_nhds Filter.tendsto_id)) · exact tendsto_nhdsWithin_of_tendsto_nhds (ContinuousAt.tendsto (by fun_prop)) /-- Helper lemma for `integral_log`: case where `a = 0`. -/ lemma integral_log_from_zero {b : ℝ} : ∫ s in (0)..b, log s = b * log b - b := by rcases lt_trichotomy b 0 with h | h | h · -- If t is negative, use that log is an even function to reduce to the positive case. conv => arg 1; arg 1; intro t; rw [← log_neg_eq_log] rw [intervalIntegral.integral_comp_neg, intervalIntegral.integral_symm, neg_zero, integral_log_from_zero_of_pos (Left.neg_pos_iff.mpr h), log_neg_eq_log] ring · simp [h] · exact integral_log_from_zero_of_pos h @[simp] theorem integral_log : ∫ s in a..b, log s = b * log b - a * log a - b + a := by rw [← intervalIntegral.integral_add_adjacent_intervals (b := 0)] · rw [intervalIntegral.integral_symm, integral_log_from_zero, integral_log_from_zero] ring all_goals exact intervalIntegrable_log' @[deprecated (since := "2025-01-12")] alias integral_log_of_pos := integral_log @[deprecated (since := "2025-01-12")] alias integral_log_of_neg := integral_log @[simp] theorem integral_sin : ∫ x in a..b, sin x = cos a - cos b := by rw [integral_deriv_eq_sub' fun x => -cos x] · ring · norm_num · simp only [differentiableAt_neg_iff, differentiableAt_cos, implies_true] · exact continuousOn_sin @[simp] theorem integral_cos : ∫ x in a..b, cos x = sin b - sin a := by rw [integral_deriv_eq_sub'] · norm_num · simp only [differentiableAt_sin, implies_true] · exact continuousOn_cos theorem integral_cos_mul_complex {z : ℂ} (hz : z ≠ 0) (a b : ℝ) : (∫ x in a..b, Complex.cos (z * x)) = Complex.sin (z * b) / z - Complex.sin (z * a) / z := by apply integral_eq_sub_of_hasDerivAt swap · apply Continuous.intervalIntegrable exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal) intro x _ have a := Complex.hasDerivAt_sin (↑x * z) have b : HasDerivAt (fun y => y * z : ℂ → ℂ) z ↑x := hasDerivAt_mul_const _ have c : HasDerivAt (Complex.sin ∘ fun y : ℂ => (y * z)) _ ↑x := HasDerivAt.comp (𝕜 := ℂ) x a b have d := HasDerivAt.comp_ofReal (c.div_const z) simp only [mul_comm] at d convert d using 1 conv_rhs => arg 1; rw [mul_comm] rw [mul_div_cancel_right₀ _ hz] theorem integral_cos_sq_sub_sin_sq : ∫ x in a..b, cos x ^ 2 - sin x ^ 2 = sin b * cos b - sin a * cos a := by simpa only [sq, sub_eq_add_neg, neg_mul_eq_mul_neg] using integral_deriv_mul_eq_sub (fun x _ => hasDerivAt_sin x) (fun x _ => hasDerivAt_cos x) continuousOn_cos.intervalIntegrable continuousOn_sin.neg.intervalIntegrable theorem integral_one_div_one_add_sq : (∫ x : ℝ in a..b, ↑1 / (↑1 + x ^ 2)) = arctan b - arctan a := by refine integral_deriv_eq_sub' _ Real.deriv_arctan (fun _ _ => differentiableAt_arctan _) (continuous_const.div ?_ fun x => ?_).continuousOn · fun_prop · nlinarith @[simp] theorem integral_inv_one_add_sq : (∫ x : ℝ in a..b, (↑1 + x ^ 2)⁻¹) = arctan b - arctan a := by simp only [← one_div, integral_one_div_one_add_sq] section RpowCpow open Complex theorem integral_mul_cpow_one_add_sq {t : ℂ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, (x : ℂ) * ((1 : ℂ) + ↑x ^ 2) ^ t) = ((1 : ℂ) + (b : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) - ((1 : ℂ) + (a : ℂ) ^ 2) ^ (t + 1) / (2 * (t + ↑1)) := by have : t + 1 ≠ 0 := by contrapose! ht; rwa [add_eq_zero_iff_eq_neg] at ht apply integral_eq_sub_of_hasDerivAt · intro x _ have f : HasDerivAt (fun y : ℂ => 1 + y ^ 2) (2 * x : ℂ) x := by convert (hasDerivAt_pow 2 (x : ℂ)).const_add 1 simp have g : ∀ {z : ℂ}, 0 < z.re → HasDerivAt (fun z => z ^ (t + 1) / (2 * (t + 1))) (z ^ t / 2) z := by intro z hz convert (HasDerivAt.cpow_const (c := t + 1) (hasDerivAt_id _) (Or.inl hz)).div_const (2 * (t + 1)) using 1 field_simp
ring convert (HasDerivAt.comp (↑x) (g _) f).comp_ofReal using 1 · field_simp; ring · exact mod_cast add_pos_of_pos_of_nonneg zero_lt_one (sq_nonneg x) · apply Continuous.intervalIntegrable refine continuous_ofReal.mul ?_ apply Continuous.cpow · exact continuous_const.add (continuous_ofReal.pow 2) · exact continuous_const · intro a norm_cast exact ofReal_mem_slitPlane.2 <| add_pos_of_pos_of_nonneg one_pos <| sq_nonneg a theorem integral_mul_rpow_one_add_sq {t : ℝ} (ht : t ≠ -1) : (∫ x : ℝ in a..b, x * (↑1 + x ^ 2) ^ t) = (↑1 + b ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) - (↑1 + a ^ 2) ^ (t + 1) / (↑2 * (t + ↑1)) := by have : ∀ x s : ℝ, (((↑1 + x ^ 2) ^ s : ℝ) : ℂ) = (1 + (x : ℂ) ^ 2) ^ (s : ℂ) := by intro x s norm_cast rw [ofReal_cpow, ofReal_add, ofReal_pow, ofReal_one] exact add_nonneg zero_le_one (sq_nonneg x) rw [← ofReal_inj] convert integral_mul_cpow_one_add_sq (_ : (t : ℂ) ≠ -1) · rw [← intervalIntegral.integral_ofReal] congr with x : 1 rw [ofReal_mul, this x t] · simp_rw [ofReal_sub, ofReal_div, this a (t + 1), this b (t + 1)] push_cast; rfl
Mathlib/Analysis/SpecialFunctions/Integrals.lean
588
615
/- 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.Data.Ordmap.Invariants /-! # Verification of `Ordnode` This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`, a wrapper around `Ordnode α` which includes the correctness invariant of the type. It exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree. * `Ordset α`: A well formed set of values of type `α`. ## Implementation notes Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. -/ variable {α : Type*} namespace Ordnode section Valid variable [Preorder α] /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/ structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where ord : t.Bounded lo hi sz : t.Sized bal : t.Balanced /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. -/ def Valid (t : Ordnode α) : Prop := Valid' ⊥ t ⊤ theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) : Valid' x t o := ⟨h.1.mono_left xy, h.2, h.3⟩ theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) : Valid' o t y := ⟨h.1.mono_right xy, h.2, h.3⟩ theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x) (H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ := ⟨h.trans_left H.1, H.2, H.3⟩ theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x) (h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ := ⟨H.1.trans_right h, H.2, H.3⟩ theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x) (h₂ : All (· < x) t) : Valid' o₁ t x := ⟨H.1.of_lt h₁ h₂, H.2, H.3⟩ theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂) (h₂ : All (· > x) t) : Valid' x t o₂ := ⟨H.1.of_gt h₁ h₂, H.2, H.3⟩ theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t := ⟨h.1.weak, h.2, h.3⟩ theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ := ⟨h, ⟨⟩, ⟨⟩⟩ theorem valid_nil : Valid (@nil α) := valid'_nil ⟨⟩ theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) : Valid' o₁ (@node α s l x r) o₂ := ⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩ theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁ | .nil, _, _, h => valid'_nil h.1.dual | .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ => let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩ let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩ ⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩, ⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩ theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ := ⟨Valid'.dual, fun h => by have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩ theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) := Valid'.dual theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) := Valid'.dual_iff theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x := ⟨H.1.1, H.2.2.1, H.3.2.1⟩ theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ := ⟨H.1.2, H.2.2.2, H.3.2.2⟩ nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l := H.left.valid nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r := H.right.valid theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.2.1 theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ := hl.node hr H rfl theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) : Valid' o₁ (singleton x : Ordnode α) o₂ := (valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) := valid'_singleton ⟨⟩ ⟨⟩ theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m)) (H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ := (hl.node' hm H1).node' hr H2 theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1)) (H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ := hl.node' (hm.node' hr H2) H1 theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) : d ≤ 3 * c := by omega theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' (↑y) r o₂) (Hm : 0 < size m) (H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨ 0 < size l ∧ ratio * size r ≤ size m ∧ delta * size l ≤ size m + size r ∧ 3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) : Valid' o₁ (@node4L α l x m y r) o₂ := by obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm suffices BalancedSz (size l) (size ml) ∧ BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2 rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩) · rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1 rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;> [decide; decide; (intro r0; unfold BalancedSz delta; omega)] · rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0] at mr₂; cases not_le_of_lt Hm mr₂ rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂ by_cases mm : size ml + size mr ≤ 1 · have r1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0 rw [r1, add_assoc] at lr₁ have l1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1)) l0 rw [l1, r1] revert mm; cases size ml <;> cases size mr <;> intro mm · decide · rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) decide · rcases mm with (_ | ⟨⟨⟩⟩); decide · rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩ rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0 · rw [ml0, mul_zero, Nat.le_zero] at mm₂ rw [ml0, mm₂] at mm; cases mm (by decide) have : 2 * size l ≤ size ml + size mr + 1 := by have := Nat.mul_le_mul_left ratio lr₁ rw [mul_left_comm, mul_add] at this have := le_trans this (add_le_add_left mr₁ _) rw [← Nat.succ_mul] at this exact (mul_le_mul_left (by decide)).1 this refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · refine (mul_le_mul_left (by decide)).1 (le_trans this ?_) rw [two_mul, Nat.succ_le_iff] refine add_lt_add_of_lt_of_le ?_ mm₂ simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3) · exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁) · exact Valid'.node4L_lemma₂ mr₂ · exact Valid'.node4L_lemma₃ mr₁ mm₁ · exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁ · exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂ theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by omega theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) : b < 3 * a + 1 := by omega theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by omega theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by omega theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r) (H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2 rw [hr.2.size_eq, Nat.lt_succ_iff] at H2 rw [hr.2.size_eq] at H3 replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 := H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by intro l0; rw [l0] at H3 exact (or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3 have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l => (or_iff_left_of_imp <| by omega).1 H3 have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb => absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide) rw [Ordnode.rotateL_node]; split_ifs with h · have rr0 : size rr > 0 := (mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _) suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by exact hl.node3L hr.left hr.right this.1 this.2 rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; replace H3 := H3_0 l0 have := hr.3.1 rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0] at this ⊢ rw [le_antisymm (balancedSz_zero.1 this.symm) rr0] decide have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0 rw [add_comm] at H3 rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0] decide replace H3 := H3p l0 rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩ refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · exact Valid'.rotateL_lemma₁ H2 hb₂ · exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h) · exact Valid'.rotateL_lemma₃ H2 h · exact le_trans hb₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _)) · rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h replace h := h.resolve_left (by decide) rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2 rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1 cases H1 (by decide) refine hl.node4L hr.left hr.right rl0 ?_ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · replace H3 := H3_0 l0 rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0 · have := hr.3.1 rw [rr0] at this exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩ exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩ exact Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩ theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l) (H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by refine Valid'.dual_iff.2 ?_ rw [dual_rotateR] refine hr.dual.rotateL hl.dual ?_ ?_ ?_ · rwa [size_dual, size_dual, add_comm] · rwa [size_dual, size_dual] · rwa [size_dual, size_dual] theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) (H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by rw [balance']; split_ifs with h h_1 h_2 · exact hl.node' hr (Or.inl h) · exact hl.rotateL hr h h_1 H₁ · exact hl.rotateR hr h h_2 H₂ · exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩) theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r') (H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by suffices @size α r ≤ 3 * (size l + 1) by omega rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩) · exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _)) · exact le_trans h₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _)) · exact le_trans (Nat.dist_tri_left' _ _) (le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega)) · rw [Nat.mul_succ] exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide))) theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance' α l x r) o₂ := let ⟨_, _, H1, H2⟩ := H Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm) theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance α l x r) o₂ := by rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) (H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2] refine hl.balance'_aux hr (Or.inl ?_) H₃ rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0]; exact Nat.zero_le _ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide) replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H] refine hl.balance' hr ?_ rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩) · exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩ · exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩ theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r) (H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR] have := hr.dual.balanceL_aux hl.dual rw [size_dual, size_dual] at this exact this H₁ H₂ H₃ theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H) theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧ size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by have := H.2.eq_node'; rw [this] at H; clear this induction r generalizing l x o₁ with | nil => exact ⟨H.left, rfl⟩ | node rs rl rx rr _ IHrr => have := H.2.2.2.eq_node'; rw [this] at H ⊢ rcases IHrr H.right with ⟨h, e⟩ refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩ rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)] rw [size_node, e]; rfl theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧ size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by have := H.dual.eraseMax_aux rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual] at this theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t) | nil, _ => valid_nil | node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) : Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩ obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩ dsimp [glue]; split_ifs · rw [splitMax_eq] · obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl suffices H : _ by refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩ · refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂) lx lr hl.1.2.to_nil (sep.2.2.imp ?_) exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1) · exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2 · rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl refine Or.inl ⟨_, Or.inr e, ?_⟩ rwa [hl.2.eq_node'] at bal · rw [splitMin_eq] · obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr suffices H : _ by refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩ · refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α)) _ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h) · exact @findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx (all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx) (sep.imp fun y hy => hy.2.1) · rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl refine Or.inr ⟨_, Or.inr e, ?_⟩ rwa [hr.2.eq_node'] at bal theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) : BalancedSz (size l) (size r) → Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r := Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1) theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) : 2 * (a + b) ≤ 9 * c + 5 := by omega theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t} (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂) (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) : Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by rw [hl.2.1] at e rw [hl.2.1, hr.2.1, delta] at h rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega suffices H₂ : _ by suffices H₁ : _ by refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩ · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁) · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2, size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1] abel · rw [e, add_right_comm]; rintro ⟨⟩ intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) : Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by induction l generalizing o₁ o₂ r with | nil => exact ⟨hr, (zero_add _).symm⟩ | node ls ll lx lr _ IHlr => ?_ induction r generalizing o₁ o₂ with | nil => exact ⟨hl, rfl⟩ | node rs rl rx rr IHrl _ => ?_ rw [merge_node]; split_ifs with h h_1 · obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left (sep.imp fun x h => h.1) exact Valid'.merge_aux₁ hl hr h v e · obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual, add_comm rs] at this exact this e · refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩) theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r) (sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) := (Valid'.merge_aux hl hr sep).1 theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) : ∀ {t o₁ o₂}, Valid' o₁ t o₂ → Bounded nil o₁ x → Bounded nil x o₂ → Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t)) | nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩ | node sz l y r, o₁, o₂, h, bl, br => by rw [insertWith, cmpLE] split_ifs with h_1 h_2 <;> dsimp only · rcases h with ⟨⟨lx, xr⟩, hs, hb⟩ rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩ refine ⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩ · rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩ suffices H : _ by refine ⟨vl.balanceL h.right H, ?_⟩ rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq] exact (e.add_right _).add_right _ exact Or.inl ⟨_, e, h.3.1⟩ · have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1 rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩ suffices H : _ by refine ⟨h.left.balanceR vr H, ?_⟩ rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq] exact (e.add_left _).add_right _ exact Or.inr ⟨_, e, h.3.1⟩ theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) := (insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1 theorem insert_eq_insertWith [DecidableLE α] (x : α) : ∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t | nil => rfl | node _ l y r => by unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith] theorem insert.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (Ordnode.insert x t) := by rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h theorem insert'_eq_insertWith [DecidableLE α] (x : α) : ∀ t, insert' x t = insertWith id x t | nil => rfl | node _ l y r => by unfold insert' insertWith; cases cmpLE x y <;> simp [insert'_eq_insertWith] theorem insert'.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (insert' x t) := by rw [insert'_eq_insertWith]; exact insertWith.valid _ _ (fun _ => id) h theorem Valid'.map_aux {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t a₁ a₂} (h : Valid' a₁ t a₂) : Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ (map f t).size = t.size := by induction t generalizing a₁ a₂ with | nil => simp only [map, size_nil, and_true]; apply valid'_nil cases a₁; · trivial cases a₂; · trivial simp only [Option.map, Bounded] exact f_strict_mono h.ord | node _ _ _ _ t_ih_l t_ih_r => have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l' obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r' simp only [map, size_node, and_true] constructor · exact And.intro t_l_valid.ord t_r_valid.ord · constructor · rw [t_l_size, t_r_size]; exact h.sz.1 · constructor · exact t_l_valid.sz · exact t_r_valid.sz · constructor · rw [t_l_size, t_r_size]; exact h.bal.1 · constructor · exact t_l_valid.bal · exact t_r_valid.bal theorem map.valid {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t} (h : Valid t) : Valid (map f t) := (Valid'.map_aux f_strict_mono h).1 theorem Valid'.erase_aux [DecidableLE α] (x : α) {t a₁ a₂} (h : Valid' a₁ t a₂) : Valid' a₁ (erase x t) a₂ ∧ Raised (erase x t).size t.size := by induction t generalizing a₁ a₂ with | nil => simpa [erase, Raised] | node _ t_l t_x t_r t_ih_l t_ih_r => simp only [erase, size_node] have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l' obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r' cases cmpLE x t_x <;> rw [h.sz.1] · suffices h_balanceable : _ by constructor · exact Valid'.balanceR t_l_valid h.right h_balanceable · rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable] repeat apply Raised.add_right exact t_l_size left; exists t_l.size; exact And.intro t_l_size h.bal.1 · have h_glue := Valid'.glue h.left h.right h.bal.1 obtain ⟨h_glue_valid, h_glue_sized⟩ := h_glue constructor · exact h_glue_valid · right; rw [h_glue_sized] · suffices h_balanceable : _ by constructor · exact Valid'.balanceL h.left t_r_valid h_balanceable · rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable] apply Raised.add_right apply Raised.add_left exact t_r_size right; exists t_r.size; exact And.intro t_r_size h.bal.1 theorem erase.valid [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (erase x t) := (Valid'.erase_aux x h).1 theorem size_erase_of_mem [DecidableLE α] {x : α} {t a₁ a₂} (h : Valid' a₁ t a₂) (h_mem : x ∈ t) : size (erase x t) = size t - 1 := by induction t generalizing a₁ a₂ with | nil => contradiction | node _ t_l t_x t_r t_ih_l t_ih_r => have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r dsimp only [Membership.mem, mem] at h_mem unfold erase revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢ · have t_ih_l := t_ih_l' h_mem clear t_ih_l' t_ih_r' have t_l_h := Valid'.erase_aux x h.left obtain ⟨t_l_valid, t_l_size⟩ := t_l_h rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))] rw [t_ih_l, h.sz.1] have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem revert h_pos_t_l_size; rcases t_l.size with - | t_l_size <;> intro h_pos_t_l_size · cases h_pos_t_l_size · simp [Nat.add_right_comm] · rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl · have t_ih_r := t_ih_r' h_mem clear t_ih_l' t_ih_r' have t_r_h := Valid'.erase_aux x h.right obtain ⟨t_r_valid, t_r_size⟩ := t_r_h rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))] rw [t_ih_r, h.sz.1] have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem revert h_pos_t_r_size; rcases t_r.size with - | t_r_size <;> intro h_pos_t_r_size · cases h_pos_t_r_size · simp [Nat.add_assoc] end Valid end Ordnode /-- An `Ordset α` is a finite set of values, represented as a tree. The operations on this type maintain that the tree is balanced and correctly stores subtree sizes at each level. The correctness property of the tree is baked into the type, so all operations on this type are correct by construction. -/ def Ordset (α : Type*) [Preorder α] := { t : Ordnode α // t.Valid } namespace Ordset open Ordnode variable [Preorder α] /-- O(1). The empty set. -/ nonrec def nil : Ordset α := ⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩ /-- O(1). Get the size of the set. -/ def size (s : Ordset α) : ℕ := s.1.size /-- O(1). Construct a singleton set containing value `a`. -/ protected def singleton (a : α) : Ordset α := ⟨singleton a, valid_singleton⟩ instance instEmptyCollection : EmptyCollection (Ordset α) := ⟨nil⟩ instance instInhabited : Inhabited (Ordset α) := ⟨nil⟩ instance instSingleton : Singleton α (Ordset α) := ⟨Ordset.singleton⟩ /-- O(1). Is the set empty? -/ def Empty (s : Ordset α) : Prop := s = ∅ theorem empty_iff {s : Ordset α} : s = ∅ ↔ s.1.empty := ⟨fun h => by cases h; exact rfl, fun h => by cases s with | mk s_val _ => cases s_val <;> [rfl; cases h]⟩ instance Empty.instDecidablePred : DecidablePred (@Empty α _) := fun _ => decidable_of_iff' _ empty_iff /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, this replaces it. -/ protected def insert [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨Ordnode.insert x s.1, insert.valid _ s.2⟩ instance instInsert [IsTotal α (· ≤ ·)] [DecidableLE α] : Insert α (Ordset α) := ⟨Ordset.insert⟩ /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, the set is returned as is. -/ nonrec def insert' [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨insert' x s.1, insert'.valid _ s.2⟩ section variable [DecidableLE α] /-- O(log n). Does the set contain the element `x`? That is, is there an element that is equivalent to `x` in the order? -/ def mem (x : α) (s : Ordset α) : Bool := x ∈ s.val /-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order, if it exists. -/ def find (x : α) (s : Ordset α) : Option α := Ordnode.find x s.val instance instMembership : Membership α (Ordset α) := ⟨fun s x => mem x s⟩ instance mem.decidable (x : α) (s : Ordset α) : Decidable (x ∈ s) := instDecidableEqBool _ _ theorem pos_size_of_mem {x : α} {t : Ordset α} (h_mem : x ∈ t) : 0 < size t := by simp? [Membership.mem, mem] at h_mem says simp only [Membership.mem, mem, Bool.decide_eq_true] at h_mem apply Ordnode.pos_size_of_mem t.property.sz h_mem end /-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there is no such element. -/ def erase [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨Ordnode.erase x s.val, Ordnode.erase.valid x s.property⟩ /-- O(n). Map a function across a tree, without changing the structure. -/ def map {β} [Preorder β] (f : α → β) (f_strict_mono : StrictMono f) (s : Ordset α) : Ordset β := ⟨Ordnode.map f s.val, Ordnode.map.valid f_strict_mono s.property⟩ end Ordset
Mathlib/Data/Ordmap/Ordset.lean
1,390
1,400
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.StoneCech /-! # Extremally disconnected spaces An extremally disconnected topological space is a space in which the closure of every open set is open. Such spaces are also called Stonean spaces. They are the projective objects in the category of compact Hausdorff spaces. ## Main declarations * `ExtremallyDisconnected`: Predicate for a space to be extremally disconnected. * `CompactT2.Projective`: Predicate for a topological space to be a projective object in the category of compact Hausdorff spaces. * `CompactT2.Projective.extremallyDisconnected`: Compact Hausdorff spaces that are projective are extremally disconnected. * `CompactT2.ExtremallyDisconnected.projective`: Extremally disconnected spaces are projective objects in the category of compact Hausdorff spaces. ## References [Gleason, *Projective topological spaces*][gleason1958] -/ noncomputable section open Function Set universe u variable (X : Type u) [TopologicalSpace X] /-- An extremally disconnected topological space is a space in which the closure of every open set is open. -/ class ExtremallyDisconnected : Prop where /-- The closure of every open set is open. -/ open_closure : ∀ U : Set X, IsOpen U → IsOpen (closure U) theorem extremallyDisconnected_of_homeo {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] [ExtremallyDisconnected X] (e : X ≃ₜ Y) : ExtremallyDisconnected Y where open_closure U hU := by rw [e.symm.isInducing.closure_eq_preimage_closure_image, Homeomorph.isOpen_preimage] exact ExtremallyDisconnected.open_closure _ (e.symm.isOpen_image.mpr hU) section TotallySeparated /-- Extremally disconnected spaces are totally separated. -/ instance [ExtremallyDisconnected X] [T2Space X] : TotallySeparatedSpace X := { isTotallySeparated_univ := by intro x _ y _ hxy obtain ⟨U, V, hUV⟩ := T2Space.t2 hxy refine ⟨closure U, (closure U)ᶜ, ExtremallyDisconnected.open_closure U hUV.1, by simp only [isOpen_compl_iff, isClosed_closure], subset_closure hUV.2.2.1, ?_, by simp only [Set.union_compl_self, Set.subset_univ], disjoint_compl_right⟩ rw [Set.mem_compl_iff, mem_closure_iff] push_neg refine ⟨V, ⟨hUV.2.1, hUV.2.2.2.1, ?_⟩⟩ rw [← Set.disjoint_iff_inter_eq_empty, disjoint_comm] exact hUV.2.2.2.2 } end TotallySeparated section /-- The assertion `CompactT2.Projective` states that given continuous maps `f : X → Z` and `g : Y → Z` with `g` surjective between `t_2`, compact topological spaces, there exists a continuous lift `h : X → Y`, such that `f = g ∘ h`. -/ def CompactT2.Projective : Prop := ∀ {Y Z : Type u} [TopologicalSpace Y] [TopologicalSpace Z], ∀ [CompactSpace Y] [T2Space Y] [CompactSpace Z] [T2Space Z], ∀ {f : X → Z} {g : Y → Z} (_ : Continuous f) (_ : Continuous g) (_ : Surjective g), ∃ h : X → Y, Continuous h ∧ g ∘ h = f variable {X} theorem StoneCech.projective [DiscreteTopology X] : CompactT2.Projective (StoneCech X) := by intro Y Z _tsY _tsZ _csY _t2Y _csZ _csZ f g hf hg g_sur let s : Z → Y := fun z => Classical.choose <| g_sur z have hs : g ∘ s = id := funext fun z => Classical.choose_spec (g_sur z) let t := s ∘ f ∘ stoneCechUnit have ht : Continuous t := continuous_of_discreteTopology let h : StoneCech X → Y := stoneCechExtend ht have hh : Continuous h := continuous_stoneCechExtend ht refine ⟨h, hh, denseRange_stoneCechUnit.equalizer (hg.comp hh) hf ?_⟩ rw [comp_assoc, stoneCechExtend_extends ht, ← comp_assoc, hs, id_comp] protected theorem CompactT2.Projective.extremallyDisconnected [CompactSpace X] [T2Space X] (h : CompactT2.Projective X) : ExtremallyDisconnected X := by refine { open_closure := fun U hU => ?_ } let Z₁ : Set (X × Bool) := Uᶜ ×ˢ {true} let Z₂ : Set (X × Bool) := closure U ×ˢ {false} let Z : Set (X × Bool) := Z₁ ∪ Z₂ have hZ₁₂ : Disjoint Z₁ Z₂ := disjoint_left.2 fun x hx₁ hx₂ => by cases hx₁.2.symm.trans hx₂.2 have hZ₁ : IsClosed Z₁ := hU.isClosed_compl.prod (T1Space.t1 _) have hZ₂ : IsClosed Z₂ := isClosed_closure.prod (T1Space.t1 false) have hZ : IsClosed Z := hZ₁.union hZ₂ let f : Z → X := Prod.fst ∘ Subtype.val have f_cont : Continuous f := continuous_fst.comp continuous_subtype_val have f_sur : Surjective f := by intro x by_cases hx : x ∈ U · exact ⟨⟨(x, false), Or.inr ⟨subset_closure hx, mem_singleton _⟩⟩, rfl⟩ · exact ⟨⟨(x, true), Or.inl ⟨hx, mem_singleton _⟩⟩, rfl⟩ haveI : CompactSpace Z := isCompact_iff_compactSpace.mp hZ.isCompact obtain ⟨g, hg, g_sec⟩ := h continuous_id f_cont f_sur let φ := Subtype.val ∘ g have hφ : Continuous φ := continuous_subtype_val.comp hg have hφ₁ : ∀ x, (φ x).1 = x := congr_fun g_sec suffices closure U = φ ⁻¹' Z₂ by rw [this, preimage_comp, ← isClosed_compl_iff, ← preimage_compl, ← preimage_subtype_coe_eq_compl Subset.rfl] · exact hZ₁.preimage hφ · rw [hZ₁₂.inter_eq, inter_empty] refine (closure_minimal ?_ <| hZ₂.preimage hφ).antisymm fun x hx => ?_ · intro x hx have : φ x ∈ Z₁ ∪ Z₂ := (g x).2 rcases this with hφ | hφ · exact ((hφ₁ x ▸ hφ.1) hx).elim · exact hφ · rw [← hφ₁ x] exact hx.1 end section variable {A D E : Type u} [TopologicalSpace A] [TopologicalSpace D] [TopologicalSpace E] /-- Lemma 2.4 in [Gleason, *Projective topological spaces*][gleason1958]: a continuous surjection $\pi$ from a compact space $D$ to a Fréchet space $A$ restricts to a compact subset $E$ of $D$, such that $\pi$ maps $E$ onto $A$ and satisfies the "Zorn subset condition", where $\pi(E_0) \ne A$ for any proper closed subset $E_0 \subsetneq E$. -/ lemma exists_compact_surjective_zorn_subset [T1Space A] [CompactSpace D] {π : D → A} (π_cont : Continuous π) (π_surj : π.Surjective) : ∃ E : Set D, CompactSpace E ∧ π '' E = univ ∧ ∀ E₀ : Set E, E₀ ≠ univ → IsClosed E₀ → E.restrict π '' E₀ ≠ univ := by -- suffices to apply Zorn's lemma on the subsets of $D$ that are closed and mapped onto $A$ let S : Set <| Set D := {E : Set D | IsClosed E ∧ π '' E = univ} suffices ∀ (C : Set <| Set D) (_ : C ⊆ S) (_ : IsChain (· ⊆ ·) C), ∃ s ∈ S, ∀ c ∈ C, s ⊆ c by
rcases zorn_superset S this with ⟨E, E_min⟩ obtain ⟨E_closed, E_surj⟩ := E_min.prop refine ⟨E, isCompact_iff_compactSpace.mp E_closed.isCompact, E_surj, ?_⟩ intro E₀ E₀_min E₀_closed contrapose! E₀_min exact eq_univ_of_image_val_eq <| E_min.eq_of_subset ⟨E₀_closed.trans E_closed, image_image_val_eq_restrict_image ▸ E₀_min⟩ image_val_subset -- suffices to prove intersection of chain is minimal intro C C_sub C_chain -- prove intersection of chain is closed refine ⟨iInter (fun c : C => c), ⟨isClosed_iInter fun ⟨_, h⟩ => (C_sub h).left, ?_⟩, fun c hc _ h => mem_iInter.mp h ⟨c, hc⟩⟩ -- prove intersection of chain is mapped onto $A$ by_cases hC : Nonempty C · refine eq_univ_of_forall fun a => inter_nonempty_iff_exists_left.mp ?_ -- apply Cantor's intersection theorem refine iInter_inter (ι := C) (π ⁻¹' {a}) _ ▸ IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ ?_ (fun c => ?_) (fun c => IsClosed.isCompact ?_) (fun c => ?_) · replace C_chain : IsChain (· ⊇ ·) C := C_chain.symm have : ∀ s t : Set D, s ⊇ t → _ ⊇ _ := fun _ _ => inter_subset_inter_left <| π ⁻¹' {a} exact (directedOn_iff_directed.mp C_chain.directedOn).mono_comp (· ⊇ ·) this · rw [← image_inter_nonempty_iff, (C_sub c.mem).right, univ_inter] exact singleton_nonempty a all_goals exact (C_sub c.mem).left.inter <| (T1Space.t1 a).preimage π_cont · rw [@iInter_of_empty _ _ <| not_nonempty_iff.mp hC, image_univ_of_surjective π_surj] /-- Lemma 2.1 in [Gleason, *Projective topological spaces*][gleason1958]: if $\rho$ is a continuous surjection from a topological space $E$ to a topological space $A$ satisfying the "Zorn subset condition", then $\rho(G)$ is contained in the closure of $A \setminus \rho(E \setminus G)$ for any open set $G$ of $E$. -/ lemma image_subset_closure_compl_image_compl_of_isOpen {ρ : E → A} (ρ_cont : Continuous ρ) (ρ_surj : ρ.Surjective) (zorn_subset : ∀ E₀ : Set E, E₀ ≠ univ → IsClosed E₀ → ρ '' E₀ ≠ univ) {G : Set E} (hG : IsOpen G) : ρ '' G ⊆ closure ((ρ '' Gᶜ)ᶜ) := by -- suffices to prove for nonempty $G$
Mathlib/Topology/ExtremallyDisconnected.lean
145
180
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import Mathlib.Order.Filter.Tendsto import Mathlib.Data.Set.Accumulate import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Ultrafilter import Mathlib.Topology.Defs.Ultrafilter /-! # Compact sets and compact spaces ## Main results * `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets is compact. -/ open Set Filter Topology TopologicalSpace Function universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} {f : X → Y} -- compact sets section Compact lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) : ∃ x ∈ s, ClusterPt x f := hs hf lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f] {u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) : ∃ x ∈ s, MapClusterPt x f u := hs hf lemma IsCompact.exists_clusterPt_of_frequently {l : Filter X} (hs : IsCompact s) (hl : ∃ᶠ x in l, x ∈ s) : ∃ a ∈ s, ClusterPt a l := let ⟨a, has, ha⟩ := @hs _ (frequently_mem_iff_neBot.mp hl) inf_le_right ⟨a, has, ha.mono inf_le_left⟩ lemma IsCompact.exists_mapClusterPt_of_frequently {l : Filter ι} {f : ι → X} (hs : IsCompact s) (hf : ∃ᶠ x in l, f x ∈ s) : ∃ a ∈ s, MapClusterPt a l f := hs.exists_clusterPt_of_frequently hf /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, sᶜ ∈ 𝓝 x ⊓ f) : sᶜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊢ exact @hs _ hf inf_le_right /-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx => ?_ rcases hf x hx with ⟨t, ht, hst⟩ replace ht := mem_inf_principal.1 ht apply mem_inf_of_inter ht hst rintro x ⟨h₁, h₂⟩ hs exact h₂ (h₁ hs) /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a compact set and a closed set is a compact set. -/ theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by intro f hnf hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs (le_trans hstf (le_principal_iff.2 inter_subset_left)) have : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right) exact ⟨x, ⟨hsx, this⟩, hx⟩ /-- The intersection of a closed set and a compact set is a compact set. -/ theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a compact set and an open set is a compact set. -/ theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a compact set is a compact set. -/ theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) : IsCompact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) : IsCompact (f '' s) := by intro l lne ls have : NeBot (l.comap f ⊓ 𝓟 s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : ∃ x ∈ s, ClusterPt x (l.comap f ⊓ 𝓟 s) := @hs _ this inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x ⊓ (comap f l ⊓ 𝓟 s)) (𝓝 (f x) ⊓ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) => let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ this) have A : 𝓝[tᶜ] x = ⊥ := empty_mem_iff_bot.1 <| compl_inter_self t ▸ this have : 𝓝[tᶜ] x ≠ ⊥ := hfx.of_inf_right.ne absurd A this theorem isCompact_iff_ultrafilter_le_nhds : IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by refine (forall_neBot_le_iff ?_).trans ?_ · rintro f g hle ⟨x, hxs, hxf⟩ exact ⟨x, hxs, hxf.mono hle⟩ · simp only [Ultrafilter.clusterPt_iff] alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds theorem isCompact_iff_ultrafilter_le_nhds' : IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe] alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds' /-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set, then the filter is less than or equal to `𝓝 y`. -/ lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X} (hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by refine le_iff_ultrafilter.2 fun f hf ↦ ?_ rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩ convert ← hx exact h x hxs (.mono (.of_le_nhds hx) hf) /-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l` and `y` is a unique `MapClusterPt` for `f` along `l` in `s`, then `f` tends to `𝓝 y` along `l`. -/ lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {Y} {l : Filter Y} {y : X} {f : Y → X} (hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) : ∃ i, s ⊆ U i := hι.elim fun i₀ => IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩) (fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ => let ⟨k, hki, hkj⟩ := hdU i j ⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩) fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) ⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩ /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i) (iUnion_eq_iUnion_finset U ▸ hsU) (directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h) lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by rcases hs.elim_finite_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ with ⟨t, hst⟩ refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩ refine mem_of_superset ?_ (subset_biUnion_of_mem hyt) exact mem_interior_iff_mem_nhds.1 hy lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X} (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := by let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU classical exact ⟨t.image (↑), fun x hx => let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx hyx ▸ y.2, by rwa [Finset.set_biUnion_finset_image]⟩ theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := (hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet theorem IsCompact.elim_nhdsWithin_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x hx ∈ 𝓝[s] x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U x x.2 := by choose V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx) refine (hs.elim_nhds_subcover' V V_nhds).imp fun t ht => subset_trans ?_ (iUnion₂_mono fun x _ => hV x x.2) simpa [← iUnion_inter, ← iUnion_coe_set] theorem IsCompact.elim_nhdsWithin_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝[s] x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by choose! V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx) refine (hs.elim_nhds_subcover V V_nhds).imp fun t ⟨t_sub_s, ht⟩ => ⟨t_sub_s, subset_trans ?_ (iUnion₂_mono fun x hx => hV x (t_sub_s x hx))⟩ simpa [← iUnion_inter] /-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact s) : Disjoint (𝓝ˢ s) l ↔ ∀ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx => h.mono_left <| nhds_le_nhdsSet hx, fun H => ?_⟩ choose! U hxU hUl using fun x hx => (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx => (hUo x hx).mem_nhds (hxU x hx) with ⟨t, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 ⟨⋃ x ∈ t, U x, ⟨isOpen_biUnion fun x hx => hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnion₂, biInter_finset_mem] exact fun x hx => hUl x (hts x hx) /-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left -- TODO: reformulate using `Disjoint` /-- For every directed family of closed sets whose intersection avoids a compact set, there exists a single element of the family which itself avoids this compact set. -/ theorem IsCompact.elim_directed_family_closed {ι : Type v} [Nonempty ι] (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) (hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ := let ⟨t, ht⟩ := hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using hst) (hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr) ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using ht⟩ -- TODO: reformulate using `Disjoint` /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := hs.elim_directed_family_closed _ (fun _ ↦ isClosed_biInter fun _ _ ↦ htc _) (by rwa [← iInter_eq_iInter_finset]) (directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h) /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst exact hs.elim_finite_subfamily_closed t htc hst /-- Cantor's intersection theorem for `iInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed {ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t) (htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := by let i₀ := hι.some suffices (t i₀ ∩ ⋂ i, t i).Nonempty by rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this simp only [nonempty_iff_ne_empty] at htn ⊢ apply mt ((htc i₀).elim_directed_family_closed t htcl) push_neg simp only [← nonempty_iff_ne_empty] at htn ⊢ refine ⟨htd, fun i => ?_⟩ rcases htd i₀ i with ⟨j, hji₀, hji⟩ exact (htn j).mono (subset_inter hji₀ hji) /-- Cantor's intersection theorem for `sInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed {S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty) (hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by rw [sInter_eq_iInter] exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2) /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X) (htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := have tmono : Antitone t := antitone_nat_of_succ_le htd have htd : Directed (· ⊇ ·) t := tmono.directed_ge have : ∀ i, t i ⊆ t 0 := fun i => tmono <| Nat.zero_le i have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i) IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩ · simp · rwa [biUnion_image] /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_of_finite_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) : IsCompact s := fun f hf hfs => by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose U hU hUf using h refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩ refine compl_not_mem (le_principal_iff.1 hfs) ?_ refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_ rw [subset_compl_comm, compl_iInter₂] simpa only [compl_compl] -- TODO: reformulate using `Disjoint` /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) : IsCompact s := isCompact_of_finite_subcover fun U hUo hsU => by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i => (U i)ᶜ) (fun i => (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnion₂, disjoint_iff] /-- A set `s` is compact if and only if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_iff_finite_subcover : IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := ⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩ /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_iff_finite_subfamily_closed : IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩ /-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ×ˢ l`, i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {Y} {l : Filter Y} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_ · exact prod_mono (nhdsSet_mono ht) le_rfl hs · simp [sup_prod, *] · rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx) with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩ refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩ exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) {Y} (l : Filter Y) : (𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l := le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs) (iSup₂_le fun _ hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl) theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) {X} (l : Filter X) : l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup] /-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`, then it belongs to `l ×ˢ (𝓝ˢ K)`, i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/ theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {X} {l : Filter X} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K := (hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs -- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ? -- That would seem a bit more natural. theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : (𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup] theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup] /-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ⊓ l`, i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l := (hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs /-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`, then it belongs to `l ⊓ (𝓝ˢ K)`, i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/ theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K := (hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs /-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact, it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough to `(x₀, y₀)`. Provided for backwards compatibility, see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement. -/ theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K) {P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) : ∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf => Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf theorem isCompact_singleton {x : X} : IsCompact ({x} : Set X) := fun _ hf hfa => ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ theorem Set.Subsingleton.isCompact (hs : s.Subsingleton) : IsCompact s := Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl rcases hl with ⟨i, his, hi⟩ rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩ exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩ theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := s.finite_toSet.isCompact_biUnion hf theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) : IsCompact (Accumulate K n) := (finite_le_nat n).isCompact_biUnion fun k _ => hK k theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) : IsCompact (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) : IsCompact (⋃ i, f i) := (finite_range f).isCompact_sUnion <| forall_mem_range.2 h @[simp] theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s := biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := by have : ∀ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, _, hst⟩ simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst exact t.finite_toSet.subset hst theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite := ⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩ theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) := isCompact_singleton.union hs -- TODO: reformulate using `𝓝ˢ` /-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/ theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU by_contra! H replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i) have : (⋂ i, V i ∩ Wᶜ).Nonempty := by refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H (fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i => (hV_closed i).inter W_op.isClosed_compl rcases hV i j with ⟨k, hki, hkj⟩ refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;> tauto have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff] contradiction namespace Filter theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl := hasBasis_biInf_principal' (fun s hs t ht => ⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩) ⟨∅, isCompact_empty⟩ theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s := hasBasis_cocompact.mem_iff theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t := mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X := hasBasis_cocompact.mem_of_mem hs theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs => compl_compl s ▸ hs.isCompact.compl_mem_cocompact theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] : cocompact X = cofinite := by simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite] /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_left (f : Filter X) : Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl] tauto /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_right (f : Filter X) : Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl] tauto theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y} (hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by intro l hne hle by_cases hy : ClusterPt y l · exact ⟨y, Or.inl rfl, hy⟩ simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy rcases hy with ⟨s, hsy, t, htl, hd⟩ rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩ have : f '' K ∈ l := by filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf rcases hyf with (rfl | ⟨x, rfl⟩) exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim, mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)] rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩ exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩ theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) : IsCompact (insert x (range f)) := by letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩ rw [← cocompact_eq_cofinite ι] at hf exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology theorem Tendsto.isCompact_insert_range {f : ℕ → X} {x} (hf : Tendsto f atTop (𝓝 x)) : IsCompact (insert x (range f)) := Filter.Tendsto.isCompact_insert_range_of_cofinite <| Nat.cofinite_eq_atTop.symm ▸ hf theorem hasBasis_coclosedCompact : (Filter.coclosedCompact X).HasBasis (fun s => IsClosed s ∧ IsCompact s) compl := by simp only [Filter.coclosedCompact, iInf_and'] refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isCompact_empty⟩ rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩⟩ /-- A set belongs to `coclosedCompact` if and only if the closure of its complement is compact. -/ theorem mem_coclosedCompact_iff : s ∈ coclosedCompact X ↔ IsCompact (closure sᶜ) := by refine hasBasis_coclosedCompact.mem_iff.trans ⟨?_, fun h ↦ ?_⟩ · rintro ⟨t, ⟨htcl, htco⟩, hst⟩ exact htco.of_isClosed_subset isClosed_closure <| closure_minimal (compl_subset_comm.2 hst) htcl · exact ⟨closure sᶜ, ⟨isClosed_closure, h⟩, compl_subset_comm.2 subset_closure⟩ /-- Complement of a set belongs to `coclosedCompact` if and only if its closure is compact. -/ theorem compl_mem_coclosedCompact : sᶜ ∈ coclosedCompact X ↔ IsCompact (closure s) := by rw [mem_coclosedCompact_iff, compl_compl] theorem cocompact_le_coclosedCompact : cocompact X ≤ coclosedCompact X := iInf_mono fun _ => le_iInf fun _ => le_rfl end Filter theorem IsCompact.compl_mem_coclosedCompact_of_isClosed (hs : IsCompact s) (hs' : IsClosed s) : sᶜ ∈ Filter.coclosedCompact X := hasBasis_coclosedCompact.mem_of_mem ⟨hs', hs⟩ namespace Bornology variable (X) in /-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is `Filter.cocompact`. See also `Bornology.relativelyCompact` the bornology of sets with compact closure. -/ def inCompact : Bornology X where cobounded' := Filter.cocompact X le_cofinite' := Filter.cocompact_le_cofinite theorem inCompact.isBounded_iff : @IsBounded _ (inCompact X) s ↔ ∃ t, IsCompact t ∧ s ⊆ t := by change sᶜ ∈ Filter.cocompact X ↔ _ rw [Filter.mem_cocompact] simp end Bornology /-- If `s` and `t` are compact sets, then the set neighborhoods filter of `s ×ˢ t` is the product of set neighborhoods filters for `s` and `t`. For general sets, only the `≤` inequality holds, see `nhdsSet_prod_le`. -/ theorem IsCompact.nhdsSet_prod_eq {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) : 𝓝ˢ (s ×ˢ t) = 𝓝ˢ s ×ˢ 𝓝ˢ t := by simp_rw [hs.nhdsSet_prod_eq_biSup, ht.prod_nhdsSet_eq_biSup, nhdsSet, sSup_image, biSup_prod, nhds_prod_eq] theorem nhdsSet_prod_le_of_disjoint_cocompact {f : Filter Y} (hs : IsCompact s) (hf : Disjoint f (Filter.cocompact Y)) : 𝓝ˢ s ×ˢ f ≤ 𝓝ˢ (s ×ˢ Set.univ) := by obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf calc 𝓝ˢ s ×ˢ f _ ≤ 𝓝ˢ s ×ˢ 𝓟 K := Filter.prod_mono_right _ (Filter.le_principal_iff.mpr hKf) _ ≤ 𝓝ˢ s ×ˢ 𝓝ˢ K := Filter.prod_mono_right _ principal_le_nhdsSet _ = 𝓝ˢ (s ×ˢ K) := (hs.nhdsSet_prod_eq hK).symm _ ≤ 𝓝ˢ (s ×ˢ Set.univ) := nhdsSet_mono (prod_mono_right le_top) theorem prod_nhdsSet_le_of_disjoint_cocompact {t : Set Y} {f : Filter X} (ht : IsCompact t) (hf : Disjoint f (Filter.cocompact X)) : f ×ˢ 𝓝ˢ t ≤ 𝓝ˢ (Set.univ ×ˢ t) := by obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf calc f ×ˢ 𝓝ˢ t _ ≤ (𝓟 K) ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ (Filter.le_principal_iff.mpr hKf) _ ≤ 𝓝ˢ K ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ principal_le_nhdsSet _ = 𝓝ˢ (K ×ˢ t) := (hK.nhdsSet_prod_eq ht).symm _ ≤ 𝓝ˢ (Set.univ ×ˢ t) := nhdsSet_mono (prod_mono_left le_top) theorem nhds_prod_le_of_disjoint_cocompact {f : Filter Y} (x : X) (hf : Disjoint f (Filter.cocompact Y)) : 𝓝 x ×ˢ f ≤ 𝓝ˢ ({x} ×ˢ Set.univ) := by simpa using nhdsSet_prod_le_of_disjoint_cocompact isCompact_singleton hf theorem prod_nhds_le_of_disjoint_cocompact {f : Filter X} (y : Y) (hf : Disjoint f (Filter.cocompact X)) : f ×ˢ 𝓝 y ≤ 𝓝ˢ (Set.univ ×ˢ {y}) := by simpa using prod_nhdsSet_le_of_disjoint_cocompact isCompact_singleton hf /-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. See also `IsCompact.nhdsSet_prod_eq`. -/ theorem generalized_tube_lemma (hs : IsCompact s) {t : Set Y} (ht : IsCompact t) {n : Set (X × Y)} (hn : IsOpen n) (hp : s ×ˢ t ⊆ n) : ∃ (u : Set X) (v : Set Y), IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ u ×ˢ v ⊆ n := by rw [← hn.mem_nhdsSet, hs.nhdsSet_prod_eq ht, ((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).mem_iff] at hp rcases hp with ⟨⟨u, v⟩, ⟨⟨huo, hsu⟩, hvo, htv⟩, hn⟩ exact ⟨u, v, huo, hvo, hsu, htv, hn⟩ -- see Note [lower instance priority] instance (priority := 10) Subsingleton.compactSpace [Subsingleton X] : CompactSpace X := ⟨subsingleton_univ.isCompact⟩ theorem isCompact_univ_iff : IsCompact (univ : Set X) ↔ CompactSpace X := ⟨fun h => ⟨h⟩, fun h => h.1⟩ theorem isCompact_univ [h : CompactSpace X] : IsCompact (univ : Set X) := h.isCompact_univ theorem exists_clusterPt_of_compactSpace [CompactSpace X] (f : Filter X) [NeBot f] : ∃ x, ClusterPt x f := by simpa using isCompact_univ (show f ≤ 𝓟 univ by simp) nonrec theorem Ultrafilter.le_nhds_lim [CompactSpace X] (F : Ultrafilter X) : ↑F ≤ 𝓝 F.lim := by rcases isCompact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩ exact le_nhds_lim ⟨x, h⟩ theorem CompactSpace.elim_nhds_subcover [CompactSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, U x = ⊤ := by obtain ⟨t, -, s⟩ := IsCompact.elim_nhds_subcover isCompact_univ U fun x _ => hU x exact ⟨t, top_unique s⟩ theorem compactSpace_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ → ∃ u : Finset ι, ⋂ i ∈ u, t i = ∅) : CompactSpace X where isCompact_univ := isCompact_of_finite_subfamily_closed fun t => by simpa using h t theorem IsClosed.isCompact [CompactSpace X] (h : IsClosed s) : IsCompact s := isCompact_univ.of_isClosed_subset h (subset_univ _) /-- If a filter has a unique cluster point `y` in a compact topological space, then the filter is less than or equal to `𝓝 y`. -/ lemma le_nhds_of_unique_clusterPt [CompactSpace X] {l : Filter X} {y : X} (h : ∀ x, ClusterPt x l → x = y) : l ≤ 𝓝 y := isCompact_univ.le_nhds_of_unique_clusterPt univ_mem fun x _ ↦ h x /-- If `y` is a unique `MapClusterPt` for `f` along `l` and the codomain of `f` is a compact space, then `f` tends to `𝓝 y` along `l`. -/ lemma tendsto_nhds_of_unique_mapClusterPt [CompactSpace X] {Y} {l : Filter Y} {y : X} {f : Y → X} (h : ∀ x, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := le_nhds_of_unique_clusterPt h lemma noncompact_univ (X : Type*) [TopologicalSpace X] [NoncompactSpace X] : ¬IsCompact (univ : Set X) := NoncompactSpace.noncompact_univ theorem IsCompact.ne_univ [NoncompactSpace X] (hs : IsCompact s) : s ≠ univ := fun h => noncompact_univ X (h ▸ hs) instance [NoncompactSpace X] : NeBot (Filter.cocompact X) := by refine Filter.hasBasis_cocompact.neBot_iff.2 fun hs => ?_ contrapose hs; rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs rw [hs]; exact noncompact_univ X @[simp] theorem Filter.cocompact_eq_bot [CompactSpace X] : Filter.cocompact X = ⊥ := Filter.hasBasis_cocompact.eq_bot_iff.mpr ⟨Set.univ, isCompact_univ, Set.compl_univ⟩ instance [NoncompactSpace X] : NeBot (Filter.coclosedCompact X) := neBot_of_le Filter.cocompact_le_coclosedCompact theorem noncompactSpace_of_neBot (_ : NeBot (Filter.cocompact X)) : NoncompactSpace X := ⟨fun h' => (Filter.nonempty_of_mem h'.compl_mem_cocompact).ne_empty compl_univ⟩ theorem Filter.cocompact_neBot_iff : NeBot (Filter.cocompact X) ↔ NoncompactSpace X := ⟨noncompactSpace_of_neBot, fun _ => inferInstance⟩ theorem not_compactSpace_iff : ¬CompactSpace X ↔ NoncompactSpace X := ⟨fun h₁ => ⟨fun h₂ => h₁ ⟨h₂⟩⟩, fun ⟨h₁⟩ ⟨h₂⟩ => h₁ h₂⟩ instance : NoncompactSpace ℤ := noncompactSpace_of_neBot <| by simp only [Filter.cocompact_eq_cofinite, Filter.cofinite_neBot] -- Note: We can't make this into an instance because it loops with `Finite.compactSpace`. /-- A compact discrete space is finite. -/ theorem finite_of_compact_of_discrete [CompactSpace X] [DiscreteTopology X] : Finite X := Finite.of_finite_univ <| isCompact_univ.finite_of_discrete lemma Set.Infinite.exists_accPt_cofinite_inf_principal_of_subset_isCompact {K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (cofinite ⊓ 𝓟 s) := (@hK _ hs.cofinite_inf_principal_neBot (inf_le_right.trans <| principal_mono.2 hsub)).imp fun x hx ↦ by rwa [accPt_iff_clusterPt, inf_comm, inf_right_comm, (finite_singleton _).cofinite_inf_principal_compl] lemma Set.Infinite.exists_accPt_of_subset_isCompact {K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (𝓟 s) := let ⟨x, hxK, hx⟩ := hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact hK hsub ⟨x, hxK, hx.mono inf_le_right⟩ lemma Set.Infinite.exists_accPt_cofinite_inf_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (cofinite ⊓ 𝓟 s) := by simpa only [mem_univ, true_and] using hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact isCompact_univ s.subset_univ lemma Set.Infinite.exists_accPt_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (𝓟 s) := hs.exists_accPt_cofinite_inf_principal.imp fun _x hx ↦ hx.mono inf_le_right theorem exists_nhds_ne_neBot (X : Type*) [TopologicalSpace X] [CompactSpace X] [Infinite X] : ∃ z : X, (𝓝[≠] z).NeBot := by simpa [AccPt] using (@infinite_univ X _).exists_accPt_principal theorem finite_cover_nhds_interior [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, interior (U x) = univ := let ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover (fun x => interior (U x)) (fun _ => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩ ⟨t, univ_subset_iff.1 ht⟩ theorem finite_cover_nhds [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, U x = univ := let ⟨t, ht⟩ := finite_cover_nhds_interior hU ⟨t, univ_subset_iff.1 <| ht.symm.subset.trans <| iUnion₂_mono fun _ _ => interior_subset⟩ /-- The comap of the cocompact filter on `Y` by a continuous function `f : X → Y` is less than or equal to the cocompact filter on `X`. This is a reformulation of the fact that images of compact sets are compact. -/ theorem Filter.comap_cocompact_le {f : X → Y} (hf : Continuous f) : (Filter.cocompact Y).comap f ≤ Filter.cocompact X := by rw [(Filter.hasBasis_cocompact.comap f).le_basis_iff Filter.hasBasis_cocompact] intro t ht refine ⟨f '' t, ht.image hf, ?_⟩ simpa using t.subset_preimage_image f /-- If a filter is disjoint from the cocompact filter, so is its image under any continuous function. -/ theorem disjoint_map_cocompact {g : X → Y} {f : Filter X} (hg : Continuous g) (hf : Disjoint f (Filter.cocompact X)) : Disjoint (map g f) (Filter.cocompact Y) := by rw [← Filter.disjoint_comap_iff_map, disjoint_iff_inf_le] calc f ⊓ (comap g (cocompact Y)) _ ≤ f ⊓ Filter.cocompact X := inf_le_inf_left f (Filter.comap_cocompact_le hg) _ = ⊥ := disjoint_iff.mp hf theorem isCompact_range [CompactSpace X] {f : X → Y} (hf : Continuous f) : IsCompact (range f) := by rw [← image_univ]; exact isCompact_univ.image hf theorem isCompact_diagonal [CompactSpace X] : IsCompact (diagonal X) := @range_diag X ▸ isCompact_range (continuous_id.prodMk continuous_id) /-- If `X` is a compact topological space, then `Prod.snd : X × Y → Y` is a closed map. -/ theorem isClosedMap_snd_of_compactSpace [CompactSpace X] : IsClosedMap (Prod.snd : X × Y → Y) := fun s hs => by rw [← isOpen_compl_iff, isOpen_iff_mem_nhds] intro y hy have : univ ×ˢ {y} ⊆ sᶜ := by exact fun (x, y') ⟨_, rfl⟩ hs => hy ⟨(x, y'), hs, rfl⟩ rcases generalized_tube_lemma isCompact_univ isCompact_singleton hs.isOpen_compl this with ⟨U, V, -, hVo, hU, hV, hs⟩ refine mem_nhds_iff.2 ⟨V, ?_, hVo, hV rfl⟩ rintro _ hzV ⟨z, hzs, rfl⟩ exact hs ⟨hU trivial, hzV⟩ hzs /-- If `Y` is a compact topological space, then `Prod.fst : X × Y → X` is a closed map. -/ theorem isClosedMap_fst_of_compactSpace [CompactSpace Y] : IsClosedMap (Prod.fst : X × Y → X) := isClosedMap_snd_of_compactSpace.comp isClosedMap_swap theorem exists_subset_nhds_of_compactSpace [CompactSpace X] [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := exists_subset_nhds_of_isCompact' hV (fun i => (hV_closed i).isCompact) hV_closed hU /-- If `f : X → Y` is an inducing map, the image `f '' s` of a set `s` is compact if and only if `s` is compact. -/ theorem Topology.IsInducing.isCompact_iff {f : X → Y} (hf : IsInducing f) : IsCompact s ↔ IsCompact (f '' s) := by refine ⟨fun hs => hs.image hf.continuous, fun hs F F_ne_bot F_le => ?_⟩ obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : ClusterPt (f x) (map f F)⟩ := hs ((map_mono F_le).trans_eq map_principal) exact ⟨x, x_in, hf.mapClusterPt_iff.1 hx⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_iff := IsInducing.isCompact_iff /-- If `f : X → Y` is an embedding, the image `f '' s` of a set `s` is compact if and only if `s` is compact. -/ theorem Topology.IsEmbedding.isCompact_iff {f : X → Y} (hf : IsEmbedding f) : IsCompact s ↔ IsCompact (f '' s) := hf.isInducing.isCompact_iff @[deprecated (since := "2024-10-26")] alias Embedding.isCompact_iff := IsEmbedding.isCompact_iff /-- The preimage of a compact set under an inducing map is a compact set. -/ theorem Topology.IsInducing.isCompact_preimage (hf : IsInducing f) (hf' : IsClosed (range f)) {K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := by replace hK := hK.inter_right hf' rwa [hf.isCompact_iff, image_preimage_eq_inter_range] @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage := IsInducing.isCompact_preimage lemma Topology.IsInducing.isCompact_preimage_iff {f : X → Y} (hf : IsInducing f) {K : Set Y} (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) ↔ IsCompact K := by rw [hf.isCompact_iff, image_preimage_eq_of_subset Kf] @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage_iff := IsInducing.isCompact_preimage_iff /-- The preimage of a compact set in the image of an inducing map is compact. -/ lemma Topology.IsInducing.isCompact_preimage' (hf : IsInducing f) {K : Set Y} (hK : IsCompact K) (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) := (hf.isCompact_preimage_iff Kf).2 hK @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage' := IsInducing.isCompact_preimage' /-- The preimage of a compact set under a closed embedding is a compact set. -/ theorem Topology.IsClosedEmbedding.isCompact_preimage (hf : IsClosedEmbedding f) {K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := hf.isInducing.isCompact_preimage (hf.isClosed_range) hK /-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts. Moreover, the preimage of a compact set is compact, see `IsClosedEmbedding.isCompact_preimage`. -/ theorem Topology.IsClosedEmbedding.tendsto_cocompact (hf : IsClosedEmbedding f) : Tendsto f (Filter.cocompact X) (Filter.cocompact Y) := Filter.hasBasis_cocompact.tendsto_right_iff.mpr fun _K hK => (hf.isCompact_preimage hK).compl_mem_cocompact /-- Sets of subtype are compact iff the image under a coercion is. -/ theorem Subtype.isCompact_iff {p : X → Prop} {s : Set { x // p x }} : IsCompact s ↔ IsCompact ((↑) '' s : Set X) := IsEmbedding.subtypeVal.isCompact_iff theorem isCompact_iff_isCompact_univ : IsCompact s ↔ IsCompact (univ : Set s) := by rw [Subtype.isCompact_iff, image_univ, Subtype.range_coe] theorem isCompact_iff_compactSpace : IsCompact s ↔ CompactSpace s := isCompact_iff_isCompact_univ.trans isCompact_univ_iff theorem IsCompact.finite (hs : IsCompact s) (hs' : DiscreteTopology s) : s.Finite := finite_coe_iff.mp (@finite_of_compact_of_discrete _ _ (isCompact_iff_compactSpace.mp hs) hs') theorem exists_nhds_ne_inf_principal_neBot (hs : IsCompact s) (hs' : s.Infinite) : ∃ z ∈ s, (𝓝[≠] z ⊓ 𝓟 s).NeBot := hs'.exists_accPt_of_subset_isCompact hs Subset.rfl protected theorem Topology.IsClosedEmbedding.noncompactSpace [NoncompactSpace X] {f : X → Y} (hf : IsClosedEmbedding f) : NoncompactSpace Y := noncompactSpace_of_neBot hf.tendsto_cocompact.neBot protected theorem Topology.IsClosedEmbedding.compactSpace [h : CompactSpace Y] {f : X → Y} (hf : IsClosedEmbedding f) : CompactSpace X := ⟨by rw [hf.isInducing.isCompact_iff, image_univ]; exact hf.isClosed_range.isCompact⟩ theorem IsCompact.prod {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ×ˢ t) := by rw [isCompact_iff_ultrafilter_le_nhds'] at hs ht ⊢ intro f hfs obtain ⟨x : X, sx : x ∈ s, hx : map Prod.fst f.1 ≤ 𝓝 x⟩ := hs (f.map Prod.fst) (mem_map.2 <| mem_of_superset hfs fun x => And.left) obtain ⟨y : Y, ty : y ∈ t, hy : map Prod.snd f.1 ≤ 𝓝 y⟩ := ht (f.map Prod.snd) (mem_map.2 <| mem_of_superset hfs fun x => And.right) rw [map_le_iff_le_comap] at hx hy refine ⟨⟨x, y⟩, ⟨sx, ty⟩, ?_⟩ rw [nhds_prod_eq]; exact le_inf hx hy /-- Finite topological spaces are compact. -/ instance (priority := 100) Finite.compactSpace [Finite X] : CompactSpace X where isCompact_univ := finite_univ.isCompact instance ULift.compactSpace [CompactSpace X] : CompactSpace (ULift.{v} X) := IsClosedEmbedding.uliftDown.compactSpace /-- The product of two compact spaces is compact. -/ instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X × Y) := ⟨by rw [← univ_prod_univ]; exact isCompact_univ.prod isCompact_univ⟩ /-- The disjoint union of two compact spaces is compact. -/ instance [CompactSpace X] [CompactSpace Y] : CompactSpace (X ⊕ Y) := ⟨by rw [← range_inl_union_range_inr] exact (isCompact_range continuous_inl).union (isCompact_range continuous_inr)⟩ instance {X : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (X i)] [∀ i, CompactSpace (X i)] : CompactSpace (Σi, X i) := by refine ⟨?_⟩ rw [Sigma.univ] exact isCompact_iUnion fun i => isCompact_range continuous_sigmaMk /-- The coproduct of the cocompact filters on two topological spaces is the cocompact filter on their product. -/ theorem Filter.coprod_cocompact : (Filter.cocompact X).coprod (Filter.cocompact Y) = Filter.cocompact (X × Y) := by apply le_antisymm · exact sup_le (comap_cocompact_le continuous_fst) (comap_cocompact_le continuous_snd) · refine (hasBasis_cocompact.coprod hasBasis_cocompact).ge_iff.2 fun K hK ↦ ?_ rw [← univ_prod, ← prod_univ, ← compl_prod_eq_union] exact (hK.1.prod hK.2).compl_mem_cocompact theorem Prod.noncompactSpace_iff : NoncompactSpace (X × Y) ↔ NoncompactSpace X ∧ Nonempty Y ∨ Nonempty X ∧ NoncompactSpace Y := by simp [← Filter.cocompact_neBot_iff, ← Filter.coprod_cocompact, Filter.coprod_neBot_iff] -- See Note [lower instance priority] instance (priority := 100) Prod.noncompactSpace_left [NoncompactSpace X] [Nonempty Y] : NoncompactSpace (X × Y) := Prod.noncompactSpace_iff.2 (Or.inl ⟨‹_›, ‹_›⟩) -- See Note [lower instance priority] instance (priority := 100) Prod.noncompactSpace_right [Nonempty X] [NoncompactSpace Y] : NoncompactSpace (X × Y) := Prod.noncompactSpace_iff.2 (Or.inr ⟨‹_›, ‹_›⟩) section Tychonoff variable {X : ι → Type*} [∀ i, TopologicalSpace (X i)] /-- **Tychonoff's theorem**: product of compact sets is compact. -/ theorem isCompact_pi_infinite {s : ∀ i, Set (X i)} : (∀ i, IsCompact (s i)) → IsCompact { x : ∀ i, X i | ∀ i, x i ∈ s i } := by simp only [isCompact_iff_ultrafilter_le_nhds, nhds_pi, le_pi, le_principal_iff] intro h f hfs have : ∀ i : ι, ∃ x, x ∈ s i ∧ Tendsto (Function.eval i) f (𝓝 x) := by refine fun i => h i (f.map _) (mem_map.2 ?_) exact mem_of_superset hfs fun x hx => hx i choose x hx using this exact ⟨x, fun i => (hx i).left, fun i => (hx i).right⟩ /-- **Tychonoff's theorem** formulated using `Set.pi`: product of compact sets is compact. -/ theorem isCompact_univ_pi {s : ∀ i, Set (X i)} (h : ∀ i, IsCompact (s i)) : IsCompact (pi univ s) := by convert isCompact_pi_infinite h simp only [← mem_univ_pi, setOf_mem_eq] instance Pi.compactSpace [∀ i, CompactSpace (X i)] : CompactSpace (∀ i, X i) := ⟨by rw [← pi_univ univ]; exact isCompact_univ_pi fun i => isCompact_univ⟩ instance Function.compactSpace [CompactSpace Y] : CompactSpace (ι → Y) := Pi.compactSpace lemma Pi.isCompact_iff_of_isClosed {s : Set (Π i, X i)} (hs : IsClosed s) : IsCompact s ↔ ∀ i, IsCompact (eval i '' s) := by constructor <;> intro H · exact fun i ↦ H.image <| continuous_apply i · exact IsCompact.of_isClosed_subset (isCompact_univ_pi H) hs (subset_pi_eval_image univ s) protected lemma Pi.exists_compact_superset_iff {s : Set (Π i, X i)} : (∃ K, IsCompact K ∧ s ⊆ K) ↔ ∀ i, ∃ Ki, IsCompact Ki ∧ s ⊆ eval i ⁻¹' Ki := by constructor · intro ⟨K, hK, hsK⟩ i exact ⟨eval i '' K, hK.image <| continuous_apply i, hsK.trans <| K.subset_preimage_image _⟩ · intro H choose K hK hsK using H exact ⟨pi univ K, isCompact_univ_pi hK, fun _ hx i _ ↦ hsK i hx⟩ /-- **Tychonoff's theorem** formulated in terms of filters: `Filter.cocompact` on an indexed product type `Π d, X d` the `Filter.coprodᵢ` of filters `Filter.cocompact` on `X d`. -/ theorem Filter.coprodᵢ_cocompact {X : ι → Type*} [∀ d, TopologicalSpace (X d)] : (Filter.coprodᵢ fun d => Filter.cocompact (X d)) = Filter.cocompact (∀ d, X d) := by refine le_antisymm (iSup_le fun i => Filter.comap_cocompact_le (continuous_apply i)) ?_ refine compl_surjective.forall.2 fun s H => ?_ simp only [compl_mem_coprodᵢ, Filter.mem_cocompact, compl_subset_compl, image_subset_iff] at H ⊢ choose K hKc htK using H exact ⟨Set.pi univ K, isCompact_univ_pi hKc, fun f hf i _ => htK i hf⟩ end Tychonoff instance Quot.compactSpace {r : X → X → Prop} [CompactSpace X] : CompactSpace (Quot r) := ⟨by rw [← range_quot_mk] exact isCompact_range continuous_quot_mk⟩ instance Quotient.compactSpace {s : Setoid X} [CompactSpace X] : CompactSpace (Quotient s) := Quot.compactSpace theorem IsClosed.exists_minimal_nonempty_closed_subset [CompactSpace X] {S : Set X} (hS : IsClosed S) (hne : S.Nonempty) : ∃ V : Set X, V ⊆ S ∧ V.Nonempty ∧ IsClosed V ∧ ∀ V' : Set X, V' ⊆ V → V'.Nonempty → IsClosed V' → V' = V := by let opens := { U : Set X | Sᶜ ⊆ U ∧ IsOpen U ∧ Uᶜ.Nonempty } obtain ⟨U, h⟩ := zorn_subset opens fun c hc hz => by by_cases hcne : c.Nonempty · obtain ⟨U₀, hU₀⟩ := hcne haveI : Nonempty { U // U ∈ c } := ⟨⟨U₀, hU₀⟩⟩ obtain ⟨U₀compl, -, -⟩ := hc hU₀ use ⋃₀ c refine ⟨⟨?_, ?_, ?_⟩, fun U hU _ hx => ⟨U, hU, hx⟩⟩ · exact fun _ hx => ⟨U₀, hU₀, U₀compl hx⟩ · exact isOpen_sUnion fun _ h => (hc h).2.1 · convert_to (⋂ U : { U // U ∈ c }, U.1ᶜ).Nonempty · ext simp only [not_exists, exists_prop, not_and, Set.mem_iInter, Subtype.forall, mem_setOf_eq, mem_compl_iff, mem_sUnion] apply IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed · rintro ⟨U, hU⟩ ⟨U', hU'⟩ obtain ⟨V, hVc, hVU, hVU'⟩ := hz.directedOn U hU U' hU' exact ⟨⟨V, hVc⟩, Set.compl_subset_compl.mpr hVU, Set.compl_subset_compl.mpr hVU'⟩ · exact fun U => (hc U.2).2.2 · exact fun U => (hc U.2).2.1.isClosed_compl.isCompact · exact fun U => (hc U.2).2.1.isClosed_compl · use Sᶜ refine ⟨⟨Set.Subset.refl _, isOpen_compl_iff.mpr hS, ?_⟩, fun U Uc => (hcne ⟨U, Uc⟩).elim⟩ rw [compl_compl] exact hne obtain ⟨Uc, Uo, Ucne⟩ := h.prop refine ⟨Uᶜ, Set.compl_subset_comm.mp Uc, Ucne, Uo.isClosed_compl, ?_⟩ intro V' V'sub V'ne V'cls have : V'ᶜ = U := by refine h.eq_of_ge ⟨?_, isOpen_compl_iff.mpr V'cls, ?_⟩ (subset_compl_comm.2 V'sub) · exact Set.Subset.trans Uc (Set.subset_compl_comm.mp V'sub) · simp only [compl_compl, V'ne] rw [← this, compl_compl] end Compact
Mathlib/Topology/Compactness/Compact.lean
1,137
1,145
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.Polynomial.Inductions import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Ring.Regular import Mathlib.RingTheory.Multiplicity import Mathlib.Data.Nat.Lattice /-! # Division of univariate polynomials The main defs are `divByMonic` and `modByMonic`. The compatibility between these is given by `modByMonic_add_div`. We also define `rootMultiplicity`. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ} section Semiring variable [Semiring R] theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 := ⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf => ⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩ theorem X_pow_dvd_iff {f : R[X]} {n : ℕ} : X ^ n ∣ f ↔ ∀ d < n, f.coeff d = 0 := ⟨fun ⟨g, hgf⟩ d hd => by simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff], fun hd => by induction n with | zero => simp [pow_zero, one_dvd] | succ n hn => obtain ⟨g, hgf⟩ := hn fun d : ℕ => fun H : d < n => hd _ (Nat.lt_succ_of_lt H) have := coeff_X_pow_mul g n 0 rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm use k rwa [pow_succ, mul_assoc, ← hgk]⟩ variable {p q : R[X]} theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot ℕ) < degree p) (hmp : Monic p) (hq : q ≠ 0) : FiniteMultiplicity p q := have zn0 : (0 : R) ≠ 1 := haveI := Nontrivial.of_polynomial_ne hq zero_ne_one ⟨natDegree q, fun ⟨r, hr⟩ => by have hp0 : p ≠ 0 := fun hp0 => by simp [hp0] at hp have hr0 : r ≠ 0 := fun hr0 => by subst hr0; simp [hq] at hr have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp] have hpn0' : leadingCoeff p ^ (natDegree q + 1) ≠ 0 := hpn1.symm ▸ zn0.symm have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r ≠ 0 := by simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne, hr0, not_false_eq_true] have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by rw [← degree_eq_natDegree hp0]; exact hp have := congr_arg natDegree hr rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp) (add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _))) this⟩ @[deprecated (since := "2024-11-30")] alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic end Semiring section Ring variable [Ring R] {p q : R[X]} theorem div_wf_lemma (h : degree q ≤ degree p ∧ p ≠ 0) (hq : Monic q) : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p := have hp : leadingCoeff p ≠ 0 := mt leadingCoeff_eq_zero.1 h.2 have hq0 : q ≠ 0 := hq.ne_zero_of_polynomial_ne h.2 have hlt : natDegree q ≤ natDegree p := (Nat.cast_le (α := WithBot ℕ)).1 (by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1) degree_sub_lt (by rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2, degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt]) h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C]) /-- See `divByMonic`. -/ noncomputable def divModByMonicAux : ∀ (_p : R[X]) {q : R[X]}, Monic q → R[X] × R[X] | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q) have _wf := div_wf_lemma h hq let dm := divModByMonicAux (p - q * z) hq ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ termination_by p => p /-- `divByMonic`, denoted as `p /ₘ q`, gives the quotient of `p` by a monic polynomial `q`. -/ def divByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).1 else 0 /-- `modByMonic`, denoted as `p %ₘ q`, gives the remainder of `p` by a monic polynomial `q`. -/ def modByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).2 else p @[inherit_doc] infixl:70 " /ₘ " => divByMonic @[inherit_doc] infixl:70 " %ₘ " => modByMonic theorem degree_modByMonic_lt [Nontrivial R] : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %ₘ q) < degree q | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq have := degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic at this ⊢ unfold divModByMonicAux dsimp rw [dif_pos hq] at this ⊢ rw [if_pos h] exact this else Or.casesOn (not_and_or.1 h) (by unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h] exact lt_of_not_ge) (by intro hp unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, Classical.not_not.1 hp] exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero))) termination_by p => p theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q ≠ 1) : natDegree (p %ₘ q) < q.natDegree := by by_cases hpq : p %ₘ q = 0 · rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero] contrapose! hq exact eq_one_of_monic_natDegree_zero hmq hq · haveI := Nontrivial.of_polynomial_ne hpq exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq) @[simp] theorem zero_modByMonic (p : R[X]) : 0 %ₘ p = 0 := by classical unfold modByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero] · rw [dif_neg hp] @[simp] theorem zero_divByMonic (p : R[X]) : 0 /ₘ p = 0 := by classical unfold divByMonic divModByMonicAux dsimp by_cases hp : Monic p · rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero] · rw [dif_neg hp] @[simp] theorem modByMonic_zero (p : R[X]) : p %ₘ 0 = p := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold modByMonic divModByMonicAux; rw [dif_neg h] @[simp] theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold divByMonic divModByMonicAux; rw [dif_neg h] theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p /ₘ q = 0 := dif_neg hq theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : ¬Monic q) : p %ₘ q = p := dif_neg hq theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q := ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by nontriviality R exact (degree_modByMonic_lt _ hq).le theorem degree_modByMonic_le_left : degree (p %ₘ q) ≤ degree p := by nontriviality R by_cases hq : q.Monic · cases lt_or_ge (degree p) (degree q) · rw [(modByMonic_eq_self_iff hq).mpr ‹_›] · exact (degree_modByMonic_le p hq).trans ‹_› · rw [modByMonic_eq_of_not_monic p hq] theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) : natDegree (p %ₘ g) ≤ g.natDegree := natDegree_le_natDegree (degree_modByMonic_le p hg) theorem natDegree_modByMonic_le_left : natDegree (p %ₘ q) ≤ natDegree p := natDegree_le_natDegree degree_modByMonic_le_left theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by simp [X_dvd_iff, coeff_C] theorem modByMonic_eq_sub_mul_div : ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q) | p, q, hq => letI := Classical.decEq R if h : degree q ≤ degree p ∧ p ≠ 0 then by have _wf := div_wf_lemma h hq have ih := modByMonic_eq_sub_mul_div (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_pos h] rw [modByMonic, dif_pos hq] at ih refine ih.trans ?_ unfold divByMonic rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub] else by unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] termination_by p => p theorem modByMonic_add_div (p : R[X]) {q : R[X]} (hq : Monic q) : p %ₘ q + q * (p /ₘ q) = p := eq_sub_iff_add_eq.1 (modByMonic_eq_sub_mul_div p hq) theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q := ⟨fun h => by have := modByMonic_add_div p hq rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this, fun h => by classical have : ¬degree q ≤ degree p := not_le_of_gt h unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_add_divByMonic (hq : Monic q) (h : degree q ≤ degree p) : degree q + degree (p /ₘ q) = degree p := by nontriviality R have hdiv0 : p /ₘ q ≠ 0 := by rwa [Ne, divByMonic_eq_zero_iff hq, not_lt] have hlc : leadingCoeff q * leadingCoeff (p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul, Ne, leadingCoeff_eq_zero] have hmod : degree (p %ₘ q) < degree (q * (p /ₘ q)) := calc degree (p %ₘ q) < degree q := degree_modByMonic_lt _ hq _ ≤ _ := by rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree hdiv0, ← Nat.cast_add, Nat.cast_le] exact Nat.le_add_right _ _ calc degree q + degree (p /ₘ q) = degree (q * (p /ₘ q)) := Eq.symm (degree_mul' hlc) _ = degree (p %ₘ q + q * (p /ₘ q)) := (degree_add_eq_right_of_degree_lt hmod).symm _ = _ := congr_arg _ (modByMonic_add_div _ hq) theorem degree_divByMonic_le (p q : R[X]) : degree (p /ₘ q) ≤ degree p := letI := Classical.decEq R if hp0 : p = 0 then by simp only [hp0, zero_divByMonic, le_refl] else if hq : Monic q then if h : degree q ≤ degree p then by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq h, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 (not_lt.2 h))] exact WithBot.coe_le_coe.2 (Nat.le_add_left _ _) else by unfold divByMonic divModByMonicAux simp [dif_pos hq, h, if_false, degree_zero, bot_le] else (divByMonic_eq_of_not_monic p hq).symm ▸ bot_le theorem degree_divByMonic_lt (p : R[X]) {q : R[X]} (hq : Monic q) (hp0 : p ≠ 0) (h0q : 0 < degree q) : degree (p /ₘ q) < degree p := if hpq : degree p < degree q then by haveI := Nontrivial.of_polynomial_ne hp0 rw [(divByMonic_eq_zero_iff hq).2 hpq, degree_eq_natDegree hp0] exact WithBot.bot_lt_coe _ else by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq (not_lt.1 hpq), degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 hpq)] exact Nat.cast_lt.2 (Nat.lt_add_of_pos_left (Nat.cast_lt.1 <| by simpa [degree_eq_natDegree hq.ne_zero] using h0q)) theorem natDegree_divByMonic (f : R[X]) {g : R[X]} (hg : g.Monic) : natDegree (f /ₘ g) = natDegree f - natDegree g := by nontriviality R by_cases hfg : f /ₘ g = 0 · rw [hfg, natDegree_zero] rw [divByMonic_eq_zero_iff hg] at hfg rw [tsub_eq_zero_iff_le.mpr (natDegree_le_natDegree <| le_of_lt hfg)] have hgf := hfg rw [divByMonic_eq_zero_iff hg] at hgf push_neg at hgf have := degree_add_divByMonic hg hgf have hf : f ≠ 0 := by intro hf apply hfg rw [hf, zero_divByMonic] rw [degree_eq_natDegree hf, degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hfg, ← Nat.cast_add, Nat.cast_inj] at this rw [← this, add_tsub_cancel_left] theorem div_modByMonic_unique {f g} (q r : R[X]) (hg : Monic g) (h : r + g * q = f ∧ degree r < degree g) : f /ₘ g = q ∧ f %ₘ g = r := by nontriviality R have h₁ : r - f %ₘ g = -g * (q - f /ₘ g) := eq_of_sub_eq_zero (by rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)] simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]) have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)) := by simp [h₁] have h₄ : degree (r - f %ₘ g) < degree g := calc degree (r - f %ₘ g) ≤ max (degree r) (degree (f %ₘ g)) := degree_sub_le _ _ _ < degree g := max_lt_iff.2 ⟨h.2, degree_modByMonic_lt _ hg⟩ have h₅ : q - f /ₘ g = 0 := _root_.by_contradiction fun hqf => not_le_of_gt h₄ <| calc degree g ≤ degree g + degree (q - f /ₘ g) := by rw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf] norm_cast exact Nat.le_add_right _ _ _ = degree (r - f %ₘ g) := by rw [h₂, degree_mul']; simpa [Monic.def.1 hg] exact ⟨Eq.symm <| eq_of_sub_eq_zero h₅, Eq.symm <| eq_of_sub_eq_zero <| by simpa [h₅] using h₁⟩ theorem map_mod_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f ∧ (p %ₘ q).map f = p.map f %ₘ q.map f := by nontriviality S haveI : Nontrivial R := f.domain_nontrivial have : map f p /ₘ map f q = map f (p /ₘ q) ∧ map f p %ₘ map f q = map f (p %ₘ q) := div_modByMonic_unique ((p /ₘ q).map f) _ (hq.map f) ⟨Eq.symm <| by rw [← Polynomial.map_mul, ← Polynomial.map_add, modByMonic_add_div _ hq], calc _ ≤ degree (p %ₘ q) := degree_map_le _ < degree q := degree_modByMonic_lt _ hq _ = _ := Eq.symm <| degree_map_eq_of_leadingCoeff_ne_zero _ (by rw [Monic.def.1 hq, f.map_one]; exact one_ne_zero)⟩ exact ⟨this.1.symm, this.2.symm⟩ theorem map_divByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p /ₘ q).map f = p.map f /ₘ q.map f := (map_mod_divByMonic f hq).1 theorem map_modByMonic [Ring S] (f : R →+* S) (hq : Monic q) : (p %ₘ q).map f = p.map f %ₘ q.map f := (map_mod_divByMonic f hq).2 theorem modByMonic_eq_zero_iff_dvd (hq : Monic q) : p %ₘ q = 0 ↔ q ∣ p := ⟨fun h => by rw [← modByMonic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, fun h => by nontriviality R obtain ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h by_contra hpq0 have hmod : p %ₘ q = q * (r - p /ₘ q) := by rw [modByMonic_eq_sub_mul_div _ hq, mul_sub, ← hr] have : degree (q * (r - p /ₘ q)) < degree q := hmod ▸ degree_modByMonic_lt _ hq have hrpq0 : leadingCoeff (r - p /ₘ q) ≠ 0 := fun h => hpq0 <| leadingCoeff_eq_zero.1 (by rw [hmod, leadingCoeff_eq_zero.1 h, mul_zero, leadingCoeff_zero]) have hlc : leadingCoeff q * leadingCoeff (r - p /ₘ q) ≠ 0 := by rwa [Monic.def.1 hq, one_mul] rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt leadingCoeff_eq_zero.2 hrpq0)] at this exact not_lt_of_ge (Nat.le_add_right _ _) (WithBot.coe_lt_coe.1 this)⟩ /-- See `Polynomial.mul_self_modByMonic` for the other multiplication order. That version, unlike this one, requires commutativity. -/ @[simp] lemma self_mul_modByMonic (hq : q.Monic) : (q * p) %ₘ q = 0 := by rw [modByMonic_eq_zero_iff_dvd hq] exact dvd_mul_right q p theorem map_dvd_map [Ring S] (f : R →+* S) (hf : Function.Injective f) {x y : R[X]} (hx : x.Monic) : x.map f ∣ y.map f ↔ x ∣ y := by rw [← modByMonic_eq_zero_iff_dvd hx, ← modByMonic_eq_zero_iff_dvd (hx.map f), ← map_modByMonic f hx] exact ⟨fun H => map_injective f hf <| by rw [H, Polynomial.map_zero], fun H => by rw [H, Polynomial.map_zero]⟩ @[simp] theorem modByMonic_one (p : R[X]) : p %ₘ 1 = 0 := (modByMonic_eq_zero_iff_dvd (by convert monic_one (R := R))).2 (one_dvd _) @[simp] theorem divByMonic_one (p : R[X]) : p /ₘ 1 = p := by conv_rhs => rw [← modByMonic_add_div p monic_one]; simp theorem sum_modByMonic_coeff (hq : q.Monic) {n : ℕ} (hn : q.degree ≤ n) : (∑ i : Fin n, monomial i ((p %ₘ q).coeff i)) = p %ₘ q := by nontriviality R exact (sum_fin (fun i c => monomial i c) (by simp) ((degree_modByMonic_lt _ hq).trans_le hn)).trans (sum_monomial_eq _) theorem mul_divByMonic_cancel_left (p : R[X]) {q : R[X]} (hmo : q.Monic) : q * p /ₘ q = p := by nontriviality R refine (div_modByMonic_unique _ 0 hmo ⟨by rw [zero_add], ?_⟩).1 rw [degree_zero] exact Ne.bot_lt fun h => hmo.ne_zero (degree_eq_bot.1 h) lemma coeff_divByMonic_X_sub_C_rec (p : R[X]) (a : R) (n : ℕ) : (p /ₘ (X - C a)).coeff n = coeff p (n + 1) + a * (p /ₘ (X - C a)).coeff (n + 1) := by nontriviality R have := monic_X_sub_C a set q := p /ₘ (X - C a) rw [← p.modByMonic_add_div this] have : degree (p %ₘ (X - C a)) < ↑(n + 1) := degree_X_sub_C a ▸ p.degree_modByMonic_lt this |>.trans_le <| WithBot.coe_le_coe.mpr le_add_self simp [q, sub_mul, add_sub, coeff_eq_zero_of_degree_lt this] theorem coeff_divByMonic_X_sub_C (p : R[X]) (a : R) (n : ℕ) : (p /ₘ (X - C a)).coeff n = ∑ i ∈ Icc (n + 1) p.natDegree, a ^ (i - (n + 1)) * p.coeff i := by wlog h : p.natDegree ≤ n generalizing n · refine Nat.decreasingInduction' (fun n hn _ ih ↦ ?_) (le_of_not_le h) ?_ · rw [coeff_divByMonic_X_sub_C_rec, ih, eq_comm, Icc_eq_cons_Ioc (Nat.succ_le.mpr hn), sum_cons, Nat.sub_self, pow_zero, one_mul, mul_sum] congr 1; refine sum_congr ?_ fun i hi ↦ ?_ · ext; simp [Nat.succ_le] rw [← mul_assoc, ← pow_succ', eq_comm, i.sub_succ', Nat.sub_add_cancel] apply Nat.le_sub_of_add_le rw [add_comm]; exact (mem_Icc.mp hi).1 · exact this _ le_rfl rw [Icc_eq_empty (Nat.lt_succ.mpr h).not_le, sum_empty] nontriviality R by_cases hp : p.natDegree = 0 · rw [(divByMonic_eq_zero_iff <| monic_X_sub_C a).mpr, coeff_zero] apply degree_lt_degree; rw [hp, natDegree_X_sub_C]; norm_num · apply coeff_eq_zero_of_natDegree_lt rw [natDegree_divByMonic p (monic_X_sub_C a), natDegree_X_sub_C] exact (Nat.pred_lt hp).trans_le h variable (R) in theorem not_isField : ¬IsField R[X] := by nontriviality R intro h letI := h.toField simpa using congr_arg natDegree (monic_X.eq_one_of_isUnit <| monic_X (R := R).ne_zero.isUnit) section multiplicity /-- An algorithm for deciding polynomial divisibility. The algorithm is "compute `p %ₘ q` and compare to `0`". See `Polynomial.modByMonic` for the algorithm that computes `%ₘ`. -/ def decidableDvdMonic [DecidableEq R] (p : R[X]) (hq : Monic q) : Decidable (q ∣ p) := decidable_of_iff (p %ₘ q = 0) (modByMonic_eq_zero_iff_dvd hq) theorem finiteMultiplicity_X_sub_C (a : R) (h0 : p ≠ 0) : FiniteMultiplicity (X - C a) p := by haveI := Nontrivial.of_polynomial_ne h0 refine finiteMultiplicity_of_degree_pos_of_monic ?_ (monic_X_sub_C _) h0 rw [degree_X_sub_C] decide @[deprecated (since := "2024-11-30")] alias multiplicity_X_sub_C_finite := finiteMultiplicity_X_sub_C /- Porting note: stripping out classical for decidability instance parameter might make for better ergonomics -/ /-- The largest power of `X - C a` which divides `p`. This *could be* computable via the divisibility algorithm `Polynomial.decidableDvdMonic`, as shown by `Polynomial.rootMultiplicity_eq_nat_find_of_nonzero` which has a computable RHS. -/ def rootMultiplicity (a : R) (p : R[X]) : ℕ := letI := Classical.decEq R if h0 : p = 0 then 0 else let _ : DecidablePred fun n : ℕ => ¬(X - C a) ^ (n + 1) ∣ p := fun n => have := decidableDvdMonic p ((monic_X_sub_C a).pow (n + 1)) inferInstanceAs (Decidable ¬_) Nat.find (finiteMultiplicity_X_sub_C a h0) /- Porting note: added the following due to diamond with decidableProp and decidableDvdMonic see also [Zulip] (https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/non-defeq.20aliased.20instance) -/ theorem rootMultiplicity_eq_nat_find_of_nonzero [DecidableEq R] {p : R[X]} (p0 : p ≠ 0) {a : R} : letI : DecidablePred fun n : ℕ => ¬(X - C a) ^ (n + 1) ∣ p := fun n => have := decidableDvdMonic p ((monic_X_sub_C a).pow (n + 1)) inferInstanceAs (Decidable ¬_) rootMultiplicity a p = Nat.find (finiteMultiplicity_X_sub_C a p0) := by dsimp [rootMultiplicity] cases Subsingleton.elim ‹DecidableEq R› (Classical.decEq R) rw [dif_neg p0] theorem rootMultiplicity_eq_multiplicity [DecidableEq R] (p : R[X]) (a : R) : rootMultiplicity a p = if p = 0 then 0 else multiplicity (X - C a) p := by simp only [rootMultiplicity, multiplicity, emultiplicity] split · rfl rename_i h simp only [finiteMultiplicity_X_sub_C a h, ↓reduceDIte] rw [← ENat.some_eq_coe, WithTop.untopD_coe] congr @[simp] theorem rootMultiplicity_zero {x : R} : rootMultiplicity x 0 = 0 := dif_pos rfl @[simp] theorem rootMultiplicity_C (r a : R) : rootMultiplicity a (C r) = 0 := by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (C r) 0, rootMultiplicity_zero] classical rw [rootMultiplicity_eq_multiplicity] split_ifs with hr · rfl
have h : natDegree (C r) < natDegree (X - C a) := by simp simp_rw [multiplicity_eq_zero.mpr ((monic_X_sub_C a).not_dvd_of_natDegree_lt hr h)] theorem pow_rootMultiplicity_dvd (p : R[X]) (a : R) : (X - C a) ^ rootMultiplicity a p ∣ p := letI := Classical.decEq R
Mathlib/Algebra/Polynomial/Div.lean
544
548
/- 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.Analysis.InnerProductSpace.Orientation import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar /-! # Volume forms and measures on inner product spaces A volume form induces a Lebesgue measure on general finite-dimensional real vector spaces. In this file, we discuss the specific situation of inner product spaces, where an orientation gives rise to a canonical volume form. We show that the measure coming from this volume form gives measure `1` to the parallelepiped spanned by any orthonormal basis, and that it coincides with the canonical `volume` from the `MeasureSpace` instance. -/ open Module MeasureTheory MeasureTheory.Measure Set variable {ι E F : Type*} variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] [NormedAddCommGroup E] [InnerProductSpace ℝ E] [MeasurableSpace E] [BorelSpace E] [MeasurableSpace F] [BorelSpace F] namespace LinearIsometryEquiv variable (f : E ≃ₗᵢ[ℝ] F) /-- Every linear isometry equivalence is a measurable equivalence. -/ def toMeasurableEquiv : E ≃ᵐ F where toEquiv := f measurable_toFun := f.continuous.measurable measurable_invFun := f.symm.continuous.measurable @[deprecated (since := "2025-03-22")] alias toMeasureEquiv := toMeasurableEquiv @[simp] theorem coe_toMeasurableEquiv : (f.toMeasurableEquiv : E → F) = f := rfl @[deprecated (since := "2025-03-22")] alias coe_toMeasureEquiv := coe_toMeasurableEquiv theorem toMeasurableEquiv_symm : f.toMeasurableEquiv.symm = f.symm.toMeasurableEquiv := rfl @[deprecated (since := "2025-03-22")] alias toMeasureEquiv_symm := toMeasurableEquiv_symm end LinearIsometryEquiv variable [Fintype ι] variable [FiniteDimensional ℝ E] [FiniteDimensional ℝ F] section variable {m n : ℕ} [_i : Fact (finrank ℝ F = n)] /-- The volume form coming from an orientation in an inner product space gives measure `1` to the parallelepiped associated to any orthonormal basis. This is a rephrasing of `abs_volumeForm_apply_of_orthonormal` in terms of measures. -/ theorem Orientation.measure_orthonormalBasis (o : Orientation ℝ F (Fin n)) (b : OrthonormalBasis ι ℝ F) : o.volumeForm.measure (parallelepiped b) = 1 := by have e : ι ≃ Fin n := by refine Fintype.equivFinOfCardEq ?_ rw [← _i.out, finrank_eq_card_basis b.toBasis] have A : ⇑b = b.reindex e ∘ e := by ext x simp only [OrthonormalBasis.coe_reindex, Function.comp_apply, Equiv.symm_apply_apply] rw [A, parallelepiped_comp_equiv, AlternatingMap.measure_parallelepiped, o.abs_volumeForm_apply_of_orthonormal, ENNReal.ofReal_one] /-- In an oriented inner product space, the measure coming from the canonical volume form associated to an orientation coincides with the volume. -/ theorem Orientation.measure_eq_volume (o : Orientation ℝ F (Fin n)) : o.volumeForm.measure = volume := by have A : o.volumeForm.measure (stdOrthonormalBasis ℝ F).toBasis.parallelepiped = 1 := Orientation.measure_orthonormalBasis o (stdOrthonormalBasis ℝ F) rw [addHaarMeasure_unique o.volumeForm.measure (stdOrthonormalBasis ℝ F).toBasis.parallelepiped, A, one_smul] simp only [volume, Basis.addHaar] end /-- The volume measure in a finite-dimensional inner product space gives measure `1` to the parallelepiped spanned by any orthonormal basis. -/ theorem OrthonormalBasis.volume_parallelepiped (b : OrthonormalBasis ι ℝ F) :
volume (parallelepiped b) = 1 := by haveI : Fact (finrank ℝ F = finrank ℝ F) := ⟨rfl⟩ let o := (stdOrthonormalBasis ℝ F).toBasis.orientation rw [← o.measure_eq_volume] exact o.measure_orthonormalBasis b
Mathlib/MeasureTheory/Measure/Haar/InnerProductSpace.lean
84
89
/- Copyright (c) 2018 Rohan Mitta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl, Yury Kudryashov, Winston Yin -/ import Mathlib.Algebra.Group.End import Mathlib.Topology.EMetricSpace.Diam /-! # Lipschitz continuous functions A map `f : α → β` between two (extended) metric spaces is called *Lipschitz continuous* with constant `K ≥ 0` if for all `x, y` we have `edist (f x) (f y) ≤ K * edist x y`. For a metric space, the latter inequality is equivalent to `dist (f x) (f y) ≤ K * dist x y`. There is also a version asserting this inequality only for `x` and `y` in some set `s`. Finally, `f : α → β` is called *locally Lipschitz continuous* if each `x : α` has a neighbourhood on which `f` is Lipschitz continuous (with some constant). In this file we provide various ways to prove that various combinations of Lipschitz continuous functions are Lipschitz continuous. We also prove that Lipschitz continuous functions are uniformly continuous, and that locally Lipschitz functions are continuous. ## Main definitions and lemmas * `LipschitzWith K f`: states that `f` is Lipschitz with constant `K : ℝ≥0` * `LipschitzOnWith K f s`: states that `f` is Lipschitz with constant `K : ℝ≥0` on a set `s` * `LipschitzWith.uniformContinuous`: a Lipschitz function is uniformly continuous * `LipschitzOnWith.uniformContinuousOn`: a function which is Lipschitz on a set `s` is uniformly continuous on `s`. * `LocallyLipschitz f`: states that `f` is locally Lipschitz * `LocallyLipschitzOn f s`: states that `f` is locally Lipschitz on `s`. * `LocallyLipschitz.continuous`: a locally Lipschitz function is continuous. ## Implementation notes The parameter `K` has type `ℝ≥0`. This way we avoid conjunction in the definition and have coercions both to `ℝ` and `ℝ≥0∞`. Constructors whose names end with `'` take `K : ℝ` as an argument, and return `LipschitzWith (Real.toNNReal K) f`. -/ universe u v w x open Filter Function Set Topology NNReal ENNReal Bornology variable {α : Type u} {β : Type v} {γ : Type w} {ι : Type x} section PseudoEMetricSpace variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {K : ℝ≥0} {s t : Set α} {f : α → β} /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` if for all `x, y` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzWith (K : ℝ≥0) (f : α → β) := ∀ x y, edist (f x) (f y) ≤ K * edist x y /-- A function `f` is **Lipschitz continuous** with constant `K ≥ 0` **on `s`** if for all `x, y` in `s` we have `dist (f x) (f y) ≤ K * dist x y`. -/ def LipschitzOnWith (K : ℝ≥0) (f : α → β) (s : Set α) := ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → edist (f x) (f y) ≤ K * edist x y /-- `f : α → β` is called **locally Lipschitz continuous** iff every point `x` has a neighbourhood on which `f` is Lipschitz. -/ def LocallyLipschitz (f : α → β) : Prop := ∀ x, ∃ K, ∃ t ∈ 𝓝 x, LipschitzOnWith K f t /-- `f : α → β` is called **locally Lipschitz continuous** on `s` iff every point `x` of `s` has a neighbourhood within `s` on which `f` is Lipschitz. -/ def LocallyLipschitzOn (s : Set α) (f : α → β) : Prop := ∀ ⦃x⦄, x ∈ s → ∃ K, ∃ t ∈ 𝓝[s] x, LipschitzOnWith K f t /-- Every function is Lipschitz on the empty set (with any Lipschitz constant). -/ @[simp] theorem lipschitzOnWith_empty (K : ℝ≥0) (f : α → β) : LipschitzOnWith K f ∅ := fun _ => False.elim @[simp] lemma locallyLipschitzOn_empty (f : α → β) : LocallyLipschitzOn ∅ f := fun _ ↦ False.elim /-- Being Lipschitz on a set is monotone w.r.t. that set. -/ theorem LipschitzOnWith.mono (hf : LipschitzOnWith K f t) (h : s ⊆ t) : LipschitzOnWith K f s := fun _x x_in _y y_in => hf (h x_in) (h y_in) lemma LocallyLipschitzOn.mono (hf : LocallyLipschitzOn t f) (h : s ⊆ t) : LocallyLipschitzOn s f := fun x hx ↦ by obtain ⟨K, u, hu, hfu⟩ := hf (h hx); exact ⟨K, u, nhdsWithin_mono _ h hu, hfu⟩ /-- `f` is Lipschitz iff it is Lipschitz on the entire space. -/ @[simp] lemma lipschitzOnWith_univ : LipschitzOnWith K f univ ↔ LipschitzWith K f := by simp [LipschitzOnWith, LipschitzWith] @[simp] lemma locallyLipschitzOn_univ : LocallyLipschitzOn univ f ↔ LocallyLipschitz f := by simp [LocallyLipschitzOn, LocallyLipschitz] protected lemma LocallyLipschitz.locallyLipschitzOn (h : LocallyLipschitz f) : LocallyLipschitzOn s f := (locallyLipschitzOn_univ.2 h).mono s.subset_univ theorem lipschitzOnWith_iff_restrict : LipschitzOnWith K f s ↔ LipschitzWith K (s.restrict f) := by simp [LipschitzOnWith, LipschitzWith] lemma lipschitzOnWith_restrict {t : Set s} : LipschitzOnWith K (s.restrict f) t ↔ LipschitzOnWith K f (s ∩ Subtype.val '' t) := by simp [LipschitzOnWith, LipschitzWith] lemma locallyLipschitzOn_iff_restrict : LocallyLipschitzOn s f ↔ LocallyLipschitz (s.restrict f) := by simp only [LocallyLipschitzOn, LocallyLipschitz, SetCoe.forall', restrict_apply, Subtype.edist_mk_mk, ← lipschitzOnWith_iff_restrict, lipschitzOnWith_restrict, nhds_subtype_eq_comap_nhdsWithin, mem_comap] congr! with x K constructor · rintro ⟨t, ht, hft⟩ exact ⟨_, ⟨t, ht, Subset.rfl⟩, hft.mono <| inter_subset_right.trans <| image_preimage_subset ..⟩ · rintro ⟨t, ⟨u, hu, hut⟩, hft⟩ exact ⟨s ∩ u, Filter.inter_mem self_mem_nhdsWithin hu, hft.mono fun x hx ↦ ⟨hx.1, ⟨x, hx.1⟩, hut hx.2, rfl⟩⟩ alias ⟨LipschitzOnWith.to_restrict, _⟩ := lipschitzOnWith_iff_restrict alias ⟨LocallyLipschitzOn.restrict, _⟩ := locallyLipschitzOn_iff_restrict lemma Set.MapsTo.lipschitzOnWith_iff_restrict {t : Set β} (h : MapsTo f s t) : LipschitzOnWith K f s ↔ LipschitzWith K (h.restrict f s t) := _root_.lipschitzOnWith_iff_restrict alias ⟨LipschitzOnWith.to_restrict_mapsTo, _⟩ := Set.MapsTo.lipschitzOnWith_iff_restrict end PseudoEMetricSpace namespace LipschitzWith open EMetric variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] [PseudoEMetricSpace γ] variable {K : ℝ≥0} {f : α → β} {x y : α} {r : ℝ≥0∞} {s : Set α} protected theorem lipschitzOnWith (h : LipschitzWith K f) : LipschitzOnWith K f s := fun x _ y _ => h x y theorem edist_le_mul (h : LipschitzWith K f) (x y : α) : edist (f x) (f y) ≤ K * edist x y := h x y theorem edist_le_mul_of_le (h : LipschitzWith K f) (hr : edist x y ≤ r) : edist (f x) (f y) ≤ K * r := (h x y).trans <| mul_left_mono hr theorem edist_lt_mul_of_lt (h : LipschitzWith K f) (hK : K ≠ 0) (hr : edist x y < r) : edist (f x) (f y) < K * r := (h x y).trans_lt <| (ENNReal.mul_lt_mul_left (ENNReal.coe_ne_zero.2 hK) ENNReal.coe_ne_top).2 hr theorem mapsTo_emetric_closedBall (h : LipschitzWith K f) (x : α) (r : ℝ≥0∞) : MapsTo f (closedBall x r) (closedBall (f x) (K * r)) := fun _y hy => h.edist_le_mul_of_le hy
theorem mapsTo_emetric_ball (h : LipschitzWith K f) (hK : K ≠ 0) (x : α) (r : ℝ≥0∞) : MapsTo f (ball x r) (ball (f x) (K * r)) := fun _y hy => h.edist_lt_mul_of_lt hK hy
Mathlib/Topology/EMetricSpace/Lipschitz.lean
147
148
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kevin Buzzard -/ import Mathlib.Algebra.BigOperators.Field import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.PowerSeries.WellKnown /-! # Bernoulli numbers The Bernoulli numbers are a sequence of rational numbers that frequently show up in number theory. ## Mathematical overview The Bernoulli numbers $(B_0, B_1, B_2, \ldots)=(1, -1/2, 1/6, 0, -1/30, \ldots)$ are a sequence of rational numbers. They show up in the formula for the sums of $k$th powers. They are related to the Taylor series expansions of $x/\tan(x)$ and of $\coth(x)$, and also show up in the values that the Riemann Zeta function takes both at both negative and positive integers (and hence in the theory of modular forms). For example, if $1 \leq n$ then $$\zeta(2n)=\sum_{t\geq1}t^{-2n}=(-1)^{n+1}\frac{(2\pi)^{2n}B_{2n}}{2(2n)!}.$$ This result is formalised in Lean: `riemannZeta_two_mul_nat`. The Bernoulli numbers can be formally defined using the power series $$\sum B_n\frac{t^n}{n!}=\frac{t}{1-e^{-t}}$$ although that happens to not be the definition in mathlib (this is an *implementation detail* and need not concern the mathematician). Note that $B_1=-1/2$, meaning that we are using the $B_n^-$ of [from Wikipedia](https://en.wikipedia.org/wiki/Bernoulli_number). ## Implementation detail The Bernoulli numbers are defined using well-founded induction, by the formula $$B_n=1-\sum_{k\lt n}\frac{\binom{n}{k}}{n-k+1}B_k.$$ This formula is true for all $n$ and in particular $B_0=1$. Note that this is the definition for positive Bernoulli numbers, which we call `bernoulli'`. The negative Bernoulli numbers are then defined as `bernoulli := (-1)^n * bernoulli'`. ## Main theorems `sum_bernoulli : ∑ k ∈ Finset.range n, (n.choose k : ℚ) * bernoulli k = if n = 1 then 1 else 0` -/ open Nat Finset Finset.Nat PowerSeries variable (A : Type*) [CommRing A] [Algebra ℚ A] /-! ### Definitions -/ /-- The Bernoulli numbers: the $n$-th Bernoulli number $B_n$ is defined recursively via $$B_n = 1 - \sum_{k < n} \binom{n}{k}\frac{B_k}{n+1-k}$$ -/ def bernoulli' : ℕ → ℚ := WellFounded.fix Nat.lt_wfRel.wf fun n bernoulli' => 1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k k.2 theorem bernoulli'_def' (n : ℕ) : bernoulli' n = 1 - ∑ k : Fin n, n.choose k / (n - k + 1) * bernoulli' k := WellFounded.fix_eq _ _ _ theorem bernoulli'_def (n : ℕ) : bernoulli' n = 1 - ∑ k ∈ range n, n.choose k / (n - k + 1) * bernoulli' k := by rw [bernoulli'_def', ← Fin.sum_univ_eq_sum_range] theorem bernoulli'_spec (n : ℕ) : (∑ k ∈ range n.succ, (n.choose (n - k) : ℚ) / (n - k + 1) * bernoulli' k) = 1 := by rw [sum_range_succ_comm, bernoulli'_def n, tsub_self, choose_zero_right, sub_self, zero_add, div_one, cast_one, one_mul, sub_add, ← sum_sub_distrib, ← sub_eq_zero, sub_sub_cancel_left, neg_eq_zero] exact Finset.sum_eq_zero (fun x hx => by rw [choose_symm (le_of_lt (mem_range.1 hx)), sub_self]) theorem bernoulli'_spec' (n : ℕ) : (∑ k ∈ antidiagonal n, ((k.1 + k.2).choose k.2 : ℚ) / (k.2 + 1) * bernoulli' k.1) = 1 := by refine ((sum_antidiagonal_eq_sum_range_succ_mk _ n).trans ?_).trans (bernoulli'_spec n) refine sum_congr rfl fun x hx => ?_ simp only [add_tsub_cancel_of_le, mem_range_succ_iff.mp hx, cast_sub] /-! ### Examples -/ section Examples @[simp] theorem bernoulli'_zero : bernoulli' 0 = 1 := by rw [bernoulli'_def] norm_num @[simp] theorem bernoulli'_one : bernoulli' 1 = 1 / 2 := by rw [bernoulli'_def] norm_num @[simp] theorem bernoulli'_two : bernoulli' 2 = 1 / 6 := by rw [bernoulli'_def] norm_num [sum_range_succ, sum_range_succ, sum_range_zero] @[simp] theorem bernoulli'_three : bernoulli' 3 = 0 := by rw [bernoulli'_def] norm_num [sum_range_succ, sum_range_succ, sum_range_zero] @[simp] theorem bernoulli'_four : bernoulli' 4 = -1 / 30 := by have : Nat.choose 4 2 = 6 := by decide -- shrug rw [bernoulli'_def] norm_num [sum_range_succ, sum_range_succ, sum_range_zero, this] end Examples @[simp] theorem sum_bernoulli' (n : ℕ) : (∑ k ∈ range n, (n.choose k : ℚ) * bernoulli' k) = n := by cases n with | zero => simp | succ n => suffices ((n + 1 : ℚ) * ∑ k ∈ range n, ↑(n.choose k) / (n - k + 1) * bernoulli' k) = ∑ x ∈ range n, ↑(n.succ.choose x) * bernoulli' x by rw_mod_cast [sum_range_succ, bernoulli'_def, ← this, choose_succ_self_right]
ring simp_rw [mul_sum, ← mul_assoc] refine sum_congr rfl fun k hk => ?_ congr
Mathlib/NumberTheory/Bernoulli.lean
128
131
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Data.List.NatAntidiagonal import Mathlib.Data.Multiset.MapFold /-! # Antidiagonals in ℕ × ℕ as multisets This file defines the antidiagonals of ℕ × ℕ as multisets: the `n`-th antidiagonal is the multiset of pairs `(i, j)` such that `i + j = n`. This is useful for polynomial multiplication and more generally for sums going from `0` to `n`. ## Notes This refines file `Data.List.NatAntidiagonal` and is further refined by file `Data.Finset.NatAntidiagonal`. -/ assert_not_exists Monoid namespace Multiset namespace Nat /-- The antidiagonal of a natural number `n` is the multiset of pairs `(i, j)` such that `i + j = n`. -/ def antidiagonal (n : ℕ) : Multiset (ℕ × ℕ) := List.Nat.antidiagonal n /-- A pair (i, j) is contained in the antidiagonal of `n` if and only if `i + j = n`. -/ @[simp] theorem mem_antidiagonal {n : ℕ} {x : ℕ × ℕ} : x ∈ antidiagonal n ↔ x.1 + x.2 = n := by rw [antidiagonal, mem_coe, List.Nat.mem_antidiagonal] /-- The cardinality of the antidiagonal of `n` is `n+1`. -/ @[simp] theorem card_antidiagonal (n : ℕ) : card (antidiagonal n) = n + 1 := by rw [antidiagonal, coe_card, List.Nat.length_antidiagonal] /-- The antidiagonal of `0` is the list `[(0, 0)]` -/ @[simp] theorem antidiagonal_zero : antidiagonal 0 = {(0, 0)} := rfl /-- The antidiagonal of `n` does not contain duplicate entries. -/ @[simp] theorem nodup_antidiagonal (n : ℕ) : Nodup (antidiagonal n) := coe_nodup.2 <| List.Nat.nodup_antidiagonal n @[simp] theorem antidiagonal_succ {n : ℕ} : antidiagonal (n + 1) = (0, n + 1) ::ₘ (antidiagonal n).map (Prod.map Nat.succ id) := by simp only [antidiagonal, List.Nat.antidiagonal_succ, map_coe, cons_coe] theorem antidiagonal_succ' {n : ℕ} : antidiagonal (n + 1) = (n + 1, 0) ::ₘ (antidiagonal n).map (Prod.map id Nat.succ) := by rw [antidiagonal, List.Nat.antidiagonal_succ', ← coe_add, Multiset.add_comm, antidiagonal, map_coe, coe_add, List.singleton_append, cons_coe] theorem antidiagonal_succ_succ' {n : ℕ} : antidiagonal (n + 2) = (0, n + 2) ::ₘ (n + 2, 0) ::ₘ (antidiagonal n).map (Prod.map Nat.succ Nat.succ) := by rw [antidiagonal_succ, antidiagonal_succ', map_cons, map_map, Prod.map_apply] rfl theorem map_swap_antidiagonal {n : ℕ} : (antidiagonal n).map Prod.swap = antidiagonal n := by rw [antidiagonal, map_coe, List.Nat.map_swap_antidiagonal, coe_reverse] end Nat end Multiset
Mathlib/Data/Multiset/NatAntidiagonal.lean
77
78
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland -/ import Mathlib.Tactic.Ring import Mathlib.Data.PNat.Prime /-! # Euclidean algorithm for ℕ This file sets up a version of the Euclidean algorithm that only works with natural numbers. Given `0 < a, b`, it computes the unique `(w, x, y, z, d)` such that the following identities hold: * `a = (w + x) d` * `b = (y + z) d` * `w * z = x * y + 1` `d` is then the gcd of `a` and `b`, and `a' := a / d = w + x` and `b' := b / d = y + z` are coprime. This story is closely related to the structure of SL₂(ℕ) (as a free monoid on two generators) and the theory of continued fractions. ## Main declarations * `XgcdType`: Helper type in defining the gcd. Encapsulates `(wp, x, y, zp, ap, bp)`. where `wp` `zp`, `ap`, `bp` are the variables getting changed through the algorithm. * `IsSpecial`: States `wp * zp = x * y + 1` * `IsReduced`: States `ap = a ∧ bp = b` ## Notes See `Nat.Xgcd` for a very similar algorithm allowing values in `ℤ`. -/ open Nat namespace PNat /-- A term of `XgcdType` is a system of six naturals. They should be thought of as representing the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] together with the vector [a, b] = [ap + 1, bp + 1]. -/ structure XgcdType where /-- `wp` is a variable which changes through the algorithm. -/ wp : ℕ /-- `x` satisfies `a / d = w + x` at the final step. -/ x : ℕ /-- `y` satisfies `b / d = z + y` at the final step. -/ y : ℕ /-- `zp` is a variable which changes through the algorithm. -/ zp : ℕ /-- `ap` is a variable which changes through the algorithm. -/ ap : ℕ /-- `bp` is a variable which changes through the algorithm. -/ bp : ℕ deriving Inhabited namespace XgcdType variable (u : XgcdType) instance : SizeOf XgcdType := ⟨fun u => u.bp⟩ /-- The `Repr` instance converts terms to strings in a way that reflects the matrix/vector interpretation as above. -/ instance : Repr XgcdType where reprPrec | g, _ => s!"[[[{repr (g.wp + 1)}, {repr g.x}], \ [{repr g.y}, {repr (g.zp + 1)}]], \ [{repr (g.ap + 1)}, {repr (g.bp + 1)}]]" /-- Another `mk` using ℕ and ℕ+ -/ def mk' (w : ℕ+) (x : ℕ) (y : ℕ) (z : ℕ+) (a : ℕ+) (b : ℕ+) : XgcdType := mk w.val.pred x y z.val.pred a.val.pred b.val.pred /-- `w = wp + 1` -/ def w : ℕ+ := succPNat u.wp /-- `z = zp + 1` -/ def z : ℕ+ := succPNat u.zp /-- `a = ap + 1` -/ def a : ℕ+ := succPNat u.ap /-- `b = bp + 1` -/ def b : ℕ+ := succPNat u.bp /-- `r = a % b`: remainder -/ def r : ℕ := (u.ap + 1) % (u.bp + 1) /-- `q = ap / bp`: quotient -/ def q : ℕ := (u.ap + 1) / (u.bp + 1) /-- `qp = q - 1` -/ def qp : ℕ := u.q - 1 /-- The map `v` gives the product of the matrix [[w, x], [y, z]] = [[wp + 1, x], [y, zp + 1]] and the vector [a, b] = [ap + 1, bp + 1]. The map `vp` gives [sp, tp] such that v = [sp + 1, tp + 1]. -/ def vp : ℕ × ℕ := ⟨u.wp + u.x + u.ap + u.wp * u.ap + u.x * u.bp, u.y + u.zp + u.bp + u.y * u.ap + u.zp * u.bp⟩ /-- `v = [sp + 1, tp + 1]`, check `vp` -/ def v : ℕ × ℕ := ⟨u.w * u.a + u.x * u.b, u.y * u.a + u.z * u.b⟩ /-- `succ₂ [t.1, t.2] = [t.1.succ, t.2.succ]` -/ def succ₂ (t : ℕ × ℕ) : ℕ × ℕ := ⟨t.1.succ, t.2.succ⟩ theorem v_eq_succ_vp : u.v = succ₂ u.vp := by ext <;> dsimp [v, vp, w, z, a, b, succ₂] <;> ring_nf /-- `IsSpecial` holds if the matrix has determinant one. -/ def IsSpecial : Prop := u.wp + u.zp + u.wp * u.zp = u.x * u.y /-- `IsSpecial'` is an alternative of `IsSpecial`. -/ def IsSpecial' : Prop := u.w * u.z = succPNat (u.x * u.y) theorem isSpecial_iff : u.IsSpecial ↔ u.IsSpecial' := by dsimp [IsSpecial, IsSpecial'] let ⟨wp, x, y, zp, ap, bp⟩ := u constructor <;> intro h <;> simp only [w, succPNat, succ_eq_add_one, z] at * <;> simp only [← coe_inj, mul_coe, mk_coe] at * · simp_all [← h]; ring · simp [Nat.mul_add, Nat.add_mul, ← Nat.add_assoc] at h; rw [← h]; ring /-- `IsReduced` holds if the two entries in the vector are the same. The reduction algorithm will produce a system with this property, whose product vector is the same as for the original system. -/ def IsReduced : Prop := u.ap = u.bp /-- `IsReduced'` is an alternative of `IsReduced`. -/ def IsReduced' : Prop := u.a = u.b theorem isReduced_iff : u.IsReduced ↔ u.IsReduced' := succPNat_inj.symm /-- `flip` flips the placement of variables during the algorithm. -/ def flip : XgcdType where wp := u.zp x := u.y y := u.x zp := u.wp ap := u.bp bp := u.ap @[simp] theorem flip_w : (flip u).w = u.z := rfl @[simp] theorem flip_x : (flip u).x = u.y := rfl @[simp] theorem flip_y : (flip u).y = u.x := rfl @[simp] theorem flip_z : (flip u).z = u.w := rfl @[simp] theorem flip_a : (flip u).a = u.b := rfl @[simp] theorem flip_b : (flip u).b = u.a := rfl theorem flip_isReduced : (flip u).IsReduced ↔ u.IsReduced := by dsimp [IsReduced, flip] constructor <;> intro h <;> exact h.symm theorem flip_isSpecial : (flip u).IsSpecial ↔ u.IsSpecial := by dsimp [IsSpecial, flip] rw [mul_comm u.x, mul_comm u.zp, add_comm u.zp] theorem flip_v : (flip u).v = u.v.swap := by dsimp [v] ext · simp only ring · simp only ring /-- Properties of division with remainder for a / b. -/ theorem rq_eq : u.r + (u.bp + 1) * u.q = u.ap + 1 := Nat.mod_add_div (u.ap + 1) (u.bp + 1) theorem qp_eq (hr : u.r = 0) : u.q = u.qp + 1 := by by_cases hq : u.q = 0 · let h := u.rq_eq rw [hr, hq, mul_zero, add_zero] at h cases h · exact (Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hq)).symm /-- The following function provides the starting point for our algorithm. We will apply an iterative reduction process to it, which will produce a system satisfying IsReduced. The gcd can be read off from this final system. -/ def start (a b : ℕ+) : XgcdType := ⟨0, 0, 0, 0, a - 1, b - 1⟩ theorem start_isSpecial (a b : ℕ+) : (start a b).IsSpecial := by dsimp [start, IsSpecial] theorem start_v (a b : ℕ+) : (start a b).v = ⟨a, b⟩ := by dsimp [start, v, XgcdType.a, XgcdType.b, w, z] rw [one_mul, one_mul, zero_mul, zero_mul] have := a.pos have := b.pos congr <;> omega /-- `finish` happens when the reducing process ends. -/ def finish : XgcdType := XgcdType.mk u.wp ((u.wp + 1) * u.qp + u.x) u.y (u.y * u.qp + u.zp) u.bp u.bp theorem finish_isReduced : u.finish.IsReduced := by dsimp [IsReduced] rfl theorem finish_isSpecial (hs : u.IsSpecial) : u.finish.IsSpecial := by dsimp [IsSpecial, finish] at hs ⊢ rw [add_mul _ _ u.y, add_comm _ (u.x * u.y), ← hs] ring theorem finish_v (hr : u.r = 0) : u.finish.v = u.v := by let ha : u.r + u.b * u.q = u.a := u.rq_eq rw [hr, zero_add] at ha ext · change (u.wp + 1) * u.b + ((u.wp + 1) * u.qp + u.x) * u.b = u.w * u.a + u.x * u.b have : u.wp + 1 = u.w := rfl rw [this, ← ha, u.qp_eq hr] ring · change u.y * u.b + (u.y * u.qp + u.z) * u.b = u.y * u.a + u.z * u.b rw [← ha, u.qp_eq hr] ring /-- This is the main reduction step, which is used when u.r ≠ 0, or equivalently b does not divide a. -/ def step : XgcdType := XgcdType.mk (u.y * u.q + u.zp) u.y ((u.wp + 1) * u.q + u.x) u.wp u.bp (u.r - 1) /-- We will apply the above step recursively. The following result is used to ensure that the process terminates. -/ theorem step_wf (hr : u.r ≠ 0) : SizeOf.sizeOf u.step < SizeOf.sizeOf u := by change u.r - 1 < u.bp have h₀ : u.r - 1 + 1 = u.r := Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero hr) have h₁ : u.r < u.bp + 1 := Nat.mod_lt (u.ap + 1) u.bp.succ_pos rw [← h₀] at h₁ exact lt_of_succ_lt_succ h₁ theorem step_isSpecial (hs : u.IsSpecial) : u.step.IsSpecial := by dsimp [IsSpecial, step] at hs ⊢ rw [mul_add, mul_comm u.y u.x, ← hs] ring /-- The reduction step does not change the product vector. -/ theorem step_v (hr : u.r ≠ 0) : u.step.v = u.v.swap := by let ha : u.r + u.b * u.q = u.a := u.rq_eq let hr : u.r - 1 + 1 = u.r := (add_comm _ 1).trans (add_tsub_cancel_of_le (Nat.pos_of_ne_zero hr)) ext · change ((u.y * u.q + u.z) * u.b + u.y * (u.r - 1 + 1) : ℕ) = u.y * u.a + u.z * u.b rw [← ha, hr] ring · change ((u.w * u.q + u.x) * u.b + u.w * (u.r - 1 + 1) : ℕ) = u.w * u.a + u.x * u.b rw [← ha, hr] ring /-- We can now define the full reduction function, which applies step as long as possible, and then applies finish. Note that the "have" statement puts a fact in the local context, and the equation compiler uses this fact to help construct the full definition in terms of well-founded recursion. The same fact needs to be introduced in all the inductive proofs of properties given below. -/ def reduce (u : XgcdType) : XgcdType := dite (u.r = 0) (fun _ => u.finish) fun _h => flip (reduce u.step) decreasing_by apply u.step_wf _h theorem reduce_a {u : XgcdType} (h : u.r = 0) : u.reduce = u.finish := by rw [reduce] exact if_pos h theorem reduce_b {u : XgcdType} (h : u.r ≠ 0) : u.reduce = u.step.reduce.flip := by rw [reduce] exact if_neg h theorem reduce_isReduced : ∀ u : XgcdType, u.reduce.IsReduced | u => dite (u.r = 0) (fun h => by rw [reduce_a h] exact u.finish_isReduced) fun h => by have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h rw [reduce_b h, flip_isReduced] apply reduce_isReduced theorem reduce_isReduced' (u : XgcdType) : u.reduce.IsReduced' := (isReduced_iff _).mp u.reduce_isReduced theorem reduce_isSpecial : ∀ u : XgcdType, u.IsSpecial → u.reduce.IsSpecial | u => dite (u.r = 0) (fun h hs => by rw [reduce_a h] exact u.finish_isSpecial hs) fun h hs => by have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h rw [reduce_b h] exact (flip_isSpecial _).mpr (reduce_isSpecial _ (u.step_isSpecial hs)) theorem reduce_isSpecial' (u : XgcdType) (hs : u.IsSpecial) : u.reduce.IsSpecial' := (isSpecial_iff _).mp (u.reduce_isSpecial hs) theorem reduce_v : ∀ u : XgcdType, u.reduce.v = u.v | u => dite (u.r = 0) (fun h => by rw [reduce_a h, finish_v u h]) fun h => by have : SizeOf.sizeOf u.step < SizeOf.sizeOf u := u.step_wf h rw [reduce_b h, flip_v, reduce_v (step u), step_v u h, Prod.swap_swap] end XgcdType section gcd variable (a b : ℕ+) /-- Extended Euclidean algorithm -/ def xgcd : XgcdType := (XgcdType.start a b).reduce /-- `gcdD a b = gcd a b` -/ def gcdD : ℕ+ := (xgcd a b).a /-- Final value of `w` -/ def gcdW : ℕ+ := (xgcd a b).w /-- Final value of `x` -/ def gcdX : ℕ := (xgcd a b).x /-- Final value of `y` -/ def gcdY : ℕ := (xgcd a b).y /-- Final value of `z` -/ def gcdZ : ℕ+ := (xgcd a b).z /-- Final value of `a / d` -/ def gcdA' : ℕ+ := succPNat ((xgcd a b).wp + (xgcd a b).x) /-- Final value of `b / d` -/ def gcdB' : ℕ+ := succPNat ((xgcd a b).y + (xgcd a b).zp) theorem gcdA'_coe : (gcdA' a b : ℕ) = gcdW a b + gcdX a b := by dsimp [gcdA', gcdX, gcdW, XgcdType.w] rw [add_right_comm] theorem gcdB'_coe : (gcdB' a b : ℕ) = gcdY a b + gcdZ a b := by dsimp [gcdB', gcdY, gcdZ, XgcdType.z] rw [add_assoc] theorem gcd_props : let d := gcdD a b let w := gcdW a b let x := gcdX a b let y := gcdY a b let z := gcdZ a b let a' := gcdA' a b let b' := gcdB' a b w * z = succPNat (x * y) ∧ a = a' * d ∧ b = b' * d ∧ z * a' = succPNat (x * b') ∧ w * b' = succPNat (y * a') ∧ (z * a : ℕ) = x * b + d ∧ (w * b : ℕ) = y * a + d := by intros d w x y z a' b' let u := XgcdType.start a b let ur := u.reduce have _ : d = ur.a := rfl have hb : d = ur.b := u.reduce_isReduced' have ha' : (a' : ℕ) = w + x := gcdA'_coe a b have hb' : (b' : ℕ) = y + z := gcdB'_coe a b have hdet : w * z = succPNat (x * y) := u.reduce_isSpecial' rfl constructor · exact hdet have hdet' : (w * z : ℕ) = x * y + 1 := by rw [← mul_coe, hdet, succPNat_coe] have _ : u.v = ⟨a, b⟩ := XgcdType.start_v a b let hv : Prod.mk (w * d + x * ur.b : ℕ) (y * d + z * ur.b : ℕ) = ⟨a, b⟩ := u.reduce_v.trans (XgcdType.start_v a b) rw [← hb, ← add_mul, ← add_mul, ← ha', ← hb'] at hv have ha'' : (a : ℕ) = a' * d := (congr_arg Prod.fst hv).symm have hb'' : (b : ℕ) = b' * d := (congr_arg Prod.snd hv).symm constructor · exact eq ha'' constructor · exact eq hb'' have hza' : (z * a' : ℕ) = x * b' + 1 := by rw [ha', hb', mul_add, mul_add, mul_comm (z : ℕ), hdet'] ring have hwb' : (w * b' : ℕ) = y * a' + 1 := by rw [ha', hb', mul_add, mul_add, hdet'] ring constructor · apply eq rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hza'] constructor · apply eq rw [succPNat_coe, Nat.succ_eq_add_one, mul_coe, hwb'] rw [ha'', hb''] repeat rw [← @mul_assoc] rw [hza', hwb'] constructor <;> ring theorem gcd_eq : gcdD a b = gcd a b := by rcases gcd_props a b with ⟨_, h₁, h₂, _, _, h₅, _⟩ apply dvd_antisymm · apply dvd_gcd · exact Dvd.intro (gcdA' a b) (h₁.trans (mul_comm _ _)).symm · exact Dvd.intro (gcdB' a b) (h₂.trans (mul_comm _ _)).symm · have h₇ : (gcd a b : ℕ) ∣ gcdZ a b * a := (Nat.gcd_dvd_left a b).trans (dvd_mul_left _ _) have h₈ : (gcd a b : ℕ) ∣ gcdX a b * b := (Nat.gcd_dvd_right a b).trans (dvd_mul_left _ _) rw [h₅] at h₇ rw [dvd_iff] exact (Nat.dvd_add_iff_right h₈).mpr h₇
theorem gcd_det_eq : gcdW a b * gcdZ a b = succPNat (gcdX a b * gcdY a b) := (gcd_props a b).1 theorem gcd_a_eq : a = gcdA' a b * gcd a b := gcd_eq a b ▸ (gcd_props a b).2.1 theorem gcd_b_eq : b = gcdB' a b * gcd a b := gcd_eq a b ▸ (gcd_props a b).2.2.1 theorem gcd_rel_left' : gcdZ a b * gcdA' a b = succPNat (gcdX a b * gcdB' a b) := (gcd_props a b).2.2.2.1 theorem gcd_rel_right' : gcdW a b * gcdB' a b = succPNat (gcdY a b * gcdA' a b) := (gcd_props a b).2.2.2.2.1 theorem gcd_rel_left : (gcdZ a b * a : ℕ) = gcdX a b * b + gcd a b := gcd_eq a b ▸ (gcd_props a b).2.2.2.2.2.1 theorem gcd_rel_right : (gcdW a b * b : ℕ) = gcdY a b * a + gcd a b := gcd_eq a b ▸ (gcd_props a b).2.2.2.2.2.2 end gcd end PNat
Mathlib/Data/PNat/Xgcd.lean
453
503
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.Group.Units.Equiv import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.HomCongr /-! # Conjugate morphisms by isomorphisms An isomorphism `α : X ≅ Y` defines - a monoid isomorphism `CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`; - a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by `α.conjAut f = α.symm ≪≫ f ≪≫ α` using `CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)` and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)` which are defined in `CategoryTheory.HomCongr`. -/ universe v u namespace CategoryTheory namespace Iso variable {C : Type u} [Category.{v} C] variable {X Y : C} (α : X ≅ Y) /-- An isomorphism between two objects defines a monoid isomorphism between their monoid of endomorphisms. -/ def conj : End X ≃* End Y := { homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f } theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom := rfl @[simp] theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g := map_mul α.conj g f @[simp] theorem conj_id : α.conj (𝟙 X) = 𝟙 Y := map_one α.conj @[simp] theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id] @[simp] theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) := homCongr_trans α α β β f @[simp] theorem symm_self_conj (f : End X) : α.symm.conj (α.conj f) = f := by rw [← trans_conj, α.self_symm_id, refl_conj] @[simp] theorem self_symm_conj (f : End Y) : α.conj (α.symm.conj f) = f := α.symm.symm_self_conj f @[simp] theorem conj_pow (f : End X) (n : ℕ) : α.conj (f ^ n) = α.conj f ^ n := α.conj.toMonoidHom.map_pow f n -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: change definition so that `conjAut_apply` becomes a `rfl`? /-- `conj` defines a group isomorphisms between groups of automorphisms -/ def conjAut : Aut X ≃* Aut Y := (Aut.unitsEndEquivAut X).symm.trans <| (Units.mapEquiv α.conj).trans <| Aut.unitsEndEquivAut Y theorem conjAut_apply (f : Aut X) : α.conjAut f = α.symm ≪≫ f ≪≫ α := by aesop_cat @[simp] theorem conjAut_hom (f : Aut X) : (α.conjAut f).hom = α.conj f.hom := rfl @[simp] theorem trans_conjAut {Z : C} (β : Y ≅ Z) (f : Aut X) : (α ≪≫ β).conjAut f = β.conjAut (α.conjAut f) := by simp only [conjAut_apply, Iso.trans_symm, Iso.trans_assoc] @[simp] theorem conjAut_mul (f g : Aut X) : α.conjAut (f * g) = α.conjAut f * α.conjAut g := map_mul α.conjAut f g @[simp] theorem conjAut_trans (f g : Aut X) : α.conjAut (f ≪≫ g) = α.conjAut f ≪≫ α.conjAut g := conjAut_mul α g f @[simp] theorem conjAut_pow (f : Aut X) (n : ℕ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_pow α.conjAut f n @[simp] theorem conjAut_zpow (f : Aut X) (n : ℤ) : α.conjAut (f ^ n) = α.conjAut f ^ n := map_zpow α.conjAut f n end Iso namespace Functor universe v₁ u₁ variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] (F : C ⥤ D) theorem map_conj {X Y : C} (α : X ≅ Y) (f : End X) : F.map (α.conj f) = (F.mapIso α).conj (F.map f) := map_homCongr F α α f theorem map_conjAut (F : C ⥤ D) {X Y : C} (α : X ≅ Y) (f : Aut X) : F.mapIso (α.conjAut f) = (F.mapIso α).conjAut (F.mapIso f) := by ext; simp only [mapIso_hom, Iso.conjAut_hom, F.map_conj] -- alternative proof: by simp only [Iso.conjAut_apply, F.mapIso_trans, F.mapIso_symm] end Functor end CategoryTheory
Mathlib/CategoryTheory/Conj.lean
194
195
/- 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.Action.End import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic import Mathlib.Algebra.Group.Action.Prod import Mathlib.Algebra.Group.Subgroup.Map import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.NoZeroSMulDivisors.Defs import Mathlib.Data.Finite.Sigma import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Setoid.Basic import Mathlib.GroupTheory.GroupAction.Defs /-! # Basic properties of group actions This file primarily concerns itself with orbits, stabilizers, and other objects defined in terms of actions. Despite this file being called `basic`, low-level helper lemmas for algebraic manipulation of `•` belong elsewhere. ## Main definitions * `MulAction.orbit` * `MulAction.fixedPoints` * `MulAction.fixedBy` * `MulAction.stabilizer` -/ universe u v open Pointwise open Function namespace MulAction variable (M : Type u) [Monoid M] (α : Type v) [MulAction M α] {β : Type*} [MulAction M β] section Orbit variable {α M} @[to_additive] lemma fst_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.1 ∈ MulAction.orbit M y.1 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma snd_mem_orbit_of_mem_orbit {x y : α × β} (h : x ∈ MulAction.orbit M y) : x.2 ∈ MulAction.orbit M y.2 := by rcases h with ⟨g, rfl⟩ exact mem_orbit _ _ @[to_additive] lemma _root_.Finite.finite_mulAction_orbit [Finite M] (a : α) : Set.Finite (orbit M a) := Set.finite_range _ variable (M) @[to_additive] theorem orbit_eq_univ [IsPretransitive M α] (a : α) : orbit M a = Set.univ := (surjective_smul M a).range_eq end Orbit section FixedPoints variable {M α} @[to_additive (attr := simp)] theorem subsingleton_orbit_iff_mem_fixedPoints {a : α} : (orbit M a).Subsingleton ↔ a ∈ fixedPoints M α := by rw [mem_fixedPoints] constructor · exact fun h m ↦ h (mem_orbit a m) (mem_orbit_self a) · rintro h _ ⟨m, rfl⟩ y ⟨p, rfl⟩ simp only [h] @[to_additive mem_fixedPoints_iff_card_orbit_eq_one] theorem mem_fixedPoints_iff_card_orbit_eq_one {a : α} [Fintype (orbit M a)] : a ∈ fixedPoints M α ↔ Fintype.card (orbit M a) = 1 := by simp only [← subsingleton_orbit_iff_mem_fixedPoints, le_antisymm_iff, Fintype.card_le_one_iff_subsingleton, Nat.add_one_le_iff, Fintype.card_pos_iff, Set.subsingleton_coe, iff_self_and, Set.nonempty_coe_sort, orbit_nonempty, implies_true] @[to_additive instDecidablePredMemSetFixedByAddOfDecidableEq] instance (m : M) [DecidableEq β] : DecidablePred fun b : β => b ∈ MulAction.fixedBy β m := fun b ↦ by simp only [MulAction.mem_fixedBy, Equiv.Perm.smul_def] infer_instance end FixedPoints end MulAction /-- `smul` by a `k : M` over a group is injective, if `k` is not a zero divisor. The general theory of such `k` is elaborated by `IsSMulRegular`. The typeclass that restricts all terms of `M` to have this property is `NoZeroSMulDivisors`. -/ theorem smul_cancel_of_non_zero_divisor {M G : Type*} [Monoid M] [AddGroup G] [DistribMulAction M G] (k : M) (h : ∀ x : G, k • x = 0 → x = 0) {a b : G} (h' : k • a = k • b) : a = b := by rw [← sub_eq_zero] refine h _ ?_ rw [smul_sub, h', sub_self] namespace MulAction variable {G α β : Type*} [Group G] [MulAction G α] [MulAction G β] @[to_additive] theorem fixedPoints_of_subsingleton [Subsingleton α] : fixedPoints G α = .univ := by apply Set.eq_univ_of_forall simp only [mem_fixedPoints] intro x hx apply Subsingleton.elim .. /-- If a group acts nontrivially, then the type is nontrivial -/ @[to_additive "If a subgroup acts nontrivially, then the type is nontrivial."] theorem nontrivial_of_fixedPoints_ne_univ (h : fixedPoints G α ≠ .univ) : Nontrivial α := (subsingleton_or_nontrivial α).resolve_left fun _ ↦ h fixedPoints_of_subsingleton section Orbit -- TODO: This proof is redoing a special case of `MulAction.IsInvariantBlock.isBlock`. Can we move -- this lemma earlier to golf? @[to_additive (attr := simp)] theorem smul_orbit (g : G) (a : α) : g • orbit G a = orbit G a := (smul_orbit_subset g a).antisymm <| calc orbit G a = g • g⁻¹ • orbit G a := (smul_inv_smul _ _).symm _ ⊆ g • orbit G a := Set.image_subset _ (smul_orbit_subset _ _) /-- The action of a group on an orbit is transitive. -/ @[to_additive "The action of an additive group on an orbit is transitive."] instance (a : α) : IsPretransitive G (orbit G a) := ⟨by rintro ⟨_, g, rfl⟩ ⟨_, h, rfl⟩ use h * g⁻¹ ext1 simp [mul_smul]⟩ @[to_additive] lemma orbitRel_subgroup_le (H : Subgroup G) : orbitRel H α ≤ orbitRel G α := Setoid.le_def.2 mem_orbit_of_mem_orbit_subgroup @[to_additive] lemma orbitRel_subgroupOf (H K : Subgroup G) : orbitRel (H.subgroupOf K) α = orbitRel (H ⊓ K : Subgroup G) α := by rw [← Subgroup.subgroupOf_map_subtype] ext x simp_rw [orbitRel_apply] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h with ⟨⟨gv, gp⟩, rfl⟩ simp only [Submonoid.mk_smul] refine mem_orbit _ (⟨gv, ?_⟩ : Subgroup.map K.subtype (H.subgroupOf K)) simpa using gp · rcases h with ⟨⟨gv, gp⟩, rfl⟩ simp only [Submonoid.mk_smul] simp only [Subgroup.subgroupOf_map_subtype, Subgroup.mem_inf] at gp refine mem_orbit _ (⟨⟨gv, ?_⟩, ?_⟩ : H.subgroupOf K) · exact gp.2 · simp only [Subgroup.mem_subgroupOf] exact gp.1 variable (G α) /-- An action is pretransitive if and only if the quotient by `MulAction.orbitRel` is a subsingleton. -/ @[to_additive "An additive action is pretransitive if and only if the quotient by `AddAction.orbitRel` is a subsingleton."] theorem pretransitive_iff_subsingleton_quotient : IsPretransitive G α ↔ Subsingleton (orbitRel.Quotient G α) := by refine ⟨fun _ ↦ ⟨fun a b ↦ ?_⟩, fun _ ↦ ⟨fun a b ↦ ?_⟩⟩ · refine Quot.inductionOn a (fun x ↦ ?_) exact Quot.inductionOn b (fun y ↦ Quot.sound <| exists_smul_eq G y x) · have h : Quotient.mk (orbitRel G α) b = ⟦a⟧ := Subsingleton.elim _ _ exact Quotient.eq''.mp h /-- If `α` is non-empty, an action is pretransitive if and only if the quotient has exactly one element. -/ @[to_additive "If `α` is non-empty, an additive action is pretransitive if and only if the quotient has exactly one element."] theorem pretransitive_iff_unique_quotient_of_nonempty [Nonempty α] : IsPretransitive G α ↔ Nonempty (Unique <| orbitRel.Quotient G α) := by rw [unique_iff_subsingleton_and_nonempty, pretransitive_iff_subsingleton_quotient, iff_self_and] exact fun _ ↦ (nonempty_quotient_iff _).mpr inferInstance variable {G α} @[to_additive] instance (x : orbitRel.Quotient G α) : IsPretransitive G x.orbit where exists_smul_eq := by induction x using Quotient.inductionOn' rintro ⟨y, yh⟩ ⟨z, zh⟩ rw [orbitRel.Quotient.mem_orbit, Quotient.eq''] at yh zh rcases yh with ⟨g, rfl⟩ rcases zh with ⟨h, rfl⟩ refine ⟨h * g⁻¹, ?_⟩ ext simp [mul_smul] variable (G) (α) local notation "Ω" => orbitRel.Quotient G α @[to_additive] lemma _root_.Finite.of_finite_mulAction_orbitRel_quotient [Finite G] [Finite Ω] : Finite α := by rw [(selfEquivSigmaOrbits' G _).finite_iff] have : ∀ g : Ω, Finite g.orbit := by intro g induction g using Quotient.inductionOn' simpa [Set.finite_coe_iff] using Finite.finite_mulAction_orbit _ exact Finite.instSigma variable (β) @[to_additive] lemma orbitRel_le_fst : orbitRel G (α × β) ≤ (orbitRel G α).comap Prod.fst := Setoid.le_def.2 fst_mem_orbit_of_mem_orbit @[to_additive] lemma orbitRel_le_snd : orbitRel G (α × β) ≤ (orbitRel G β).comap Prod.snd := Setoid.le_def.2 snd_mem_orbit_of_mem_orbit end Orbit section Stabilizer variable (G) variable {G} /-- If the stabilizer of `a` is `S`, then the stabilizer of `g • a` is `gSg⁻¹`. -/ theorem stabilizer_smul_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g • a) = (stabilizer G a).map (MulAut.conj g).toMonoidHom := by ext h rw [mem_stabilizer_iff, ← smul_left_cancel_iff g⁻¹, smul_smul, smul_smul, smul_smul, inv_mul_cancel, one_smul, ← mem_stabilizer_iff, Subgroup.mem_map_equiv, MulAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) : stabilizer G a ≃* stabilizer G b := let g : G := Classical.choose h have hg : g • b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (MulAut.conj g).toMonoidHom := by rw [← hg, stabilizer_smul_eq_stabilizer_map_conj] (MulEquiv.subgroupCongr this).trans ((MulAut.conj g).subgroupMap <| stabilizer G b).symm end Stabilizer end MulAction namespace AddAction variable {G α : Type*} [AddGroup G] [AddAction G α] /-- If the stabilizer of `x` is `S`, then the stabilizer of `g +ᵥ x` is `g + S + (-g)`. -/ theorem stabilizer_vadd_eq_stabilizer_map_conj (g : G) (a : α) : stabilizer G (g +ᵥ a) = (stabilizer G a).map (AddAut.conj g).toMul.toAddMonoidHom := by ext h rw [mem_stabilizer_iff, ← vadd_left_cancel_iff (-g), vadd_vadd, vadd_vadd, vadd_vadd, neg_add_cancel, zero_vadd, ← mem_stabilizer_iff, AddSubgroup.mem_map_equiv, AddAut.conj_symm_apply] /-- A bijection between the stabilizers of two elements in the same orbit. -/ noncomputable def stabilizerEquivStabilizerOfOrbitRel {a b : α} (h : orbitRel G α a b) : stabilizer G a ≃+ stabilizer G b := let g : G := Classical.choose h have hg : g +ᵥ b = a := Classical.choose_spec h have this : stabilizer G a = (stabilizer G b).map (AddAut.conj g).toMul.toAddMonoidHom := by rw [← hg, stabilizer_vadd_eq_stabilizer_map_conj] (AddEquiv.addSubgroupCongr this).trans ((AddAut.conj g).addSubgroupMap <| stabilizer G b).symm end AddAction attribute [to_additive existing] MulAction.stabilizer_smul_eq_stabilizer_map_conj attribute [to_additive existing] MulAction.stabilizerEquivStabilizerOfOrbitRel theorem Equiv.swap_mem_stabilizer {α : Type*} [DecidableEq α] {S : Set α} {a b : α} : Equiv.swap a b ∈ MulAction.stabilizer (Equiv.Perm α) S ↔ (a ∈ S ↔ b ∈ S) := by rw [MulAction.mem_stabilizer_iff, Set.ext_iff, ← swap_inv] simp_rw [Set.mem_inv_smul_set_iff, Perm.smul_def, swap_apply_def] exact ⟨fun h ↦ by simpa [Iff.comm] using h a, by intros; split_ifs <;> simp [*]⟩ namespace MulAction variable {G : Type*} [Group G] {α : Type*} [MulAction G α] /-- To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions. -/ @[to_additive "To prove inclusion of a *subgroup* in a stabilizer, it is enough to prove inclusions."] theorem le_stabilizer_iff_smul_le (s : Set α) (H : Subgroup G) : H ≤ stabilizer G s ↔ ∀ g ∈ H, g • s ⊆ s := by constructor · intro hyp g hg apply Eq.subset rw [← mem_stabilizer_iff] exact hyp hg · intro hyp g hg rw [mem_stabilizer_iff] apply subset_antisymm (hyp g hg) intro x hx use g⁻¹ • x constructor · apply hyp g⁻¹ (inv_mem hg) simp only [Set.smul_mem_smul_set_iff, hx] · simp only [smul_inv_smul] end MulAction section variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M] [NoZeroSMulDivisors R M] variable {M} in lemma Module.stabilizer_units_eq_bot_of_ne_zero {x : M} (hx : x ≠ 0) : MulAction.stabilizer Rˣ x = ⊥ := by rw [eq_bot_iff] intro g (hg : g.val • x = x) ext rw [← sub_eq_zero, ← smul_eq_zero_iff_left hx, Units.val_one, sub_smul, hg, one_smul, sub_self] end
Mathlib/GroupTheory/GroupAction/Basic.lean
585
589
/- Copyright (c) 2023 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Affine import Mathlib.LinearAlgebra.FreeModule.Norm import Mathlib.RingTheory.ClassGroup import Mathlib.RingTheory.Polynomial.UniqueFactorization /-! # Group law on Weierstrass curves This file proves that the nonsingular rational points on a Weierstrass curve form an abelian group under the geometric group law defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`. ## Mathematical background Let `W` be a Weierstrass curve over a field `F` given by a Weierstrass equation `W(X, Y) = 0` in affine coordinates. As in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine.lean`, the set of nonsingular rational points `W⟮F⟯` of `W` consist of the unique point at infinity `𝓞` and nonsingular affine points `(x, y)`. With this description, there is an addition-preserving injection between `W⟮F⟯` and the ideal class group of the *affine coordinate ring* `F[W] := F[X, Y] / ⟨W(X, Y)⟩` of `W`. This is given by mapping `𝓞` to the trivial ideal class and a nonsingular affine point `(x, y)` to the ideal class of the invertible ideal `⟨X - x, Y - y⟩`. Proving that this is well-defined and preserves addition reduces to equalities of integral ideals checked in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul` and in `WeierstrassCurve.Affine.CoordinateRing.XYIdeal_mul_XYIdeal` via explicit ideal computations. Now `F[W]` is a free rank two `F[X]`-algebra with basis `{1, Y}`, so every element of `F[W]` is of the form `p + qY` for some `p, q` in `F[X]`, and there is an algebra norm `N : F[W] → F[X]`. Injectivity can then be shown by computing the degree of such a norm `N(p + qY)` in two different ways, which is done in `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis` and in the auxiliary lemmas in the proof of `WeierstrassCurve.Affine.Point.instAddCommGroup`. ## Main definitions * `WeierstrassCurve.Affine.CoordinateRing`: the coordinate ring `F[W]` of a Weierstrass curve `W`. * `WeierstrassCurve.Affine.CoordinateRing.basis`: the power basis of `F[W]` over `F[X]`. ## Main statements * `WeierstrassCurve.Affine.CoordinateRing.instIsDomainCoordinateRing`: the affine coordinate ring of a Weierstrass curve is an integral domain. * `WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis`: the degree of the norm of an element in the affine coordinate ring in terms of its power basis. * `WeierstrassCurve.Affine.Point.instAddCommGroup`: the type of nonsingular points `W⟮F⟯` in affine coordinates forms an abelian group under addition. ## References https://drops.dagstuhl.de/storage/00lipics/lipics-vol268-itp2023/LIPIcs.ITP.2023.6/LIPIcs.ITP.2023.6.pdf ## Tags elliptic curve, group law, class group -/ open Ideal Polynomial open scoped nonZeroDivisors Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "eval_simp" : tactic => `(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow]) universe u v namespace WeierstrassCurve.Affine /-! ## Weierstrass curves in affine coordinates -/ variable {R : Type u} {S : Type v} [CommRing R] [CommRing S] (W : Affine R) (f : R →+* S) -- Porting note: in Lean 3, this is a `def` under a `derive comm_ring` tag. -- This generates a reducible instance of `comm_ring` for `coordinate_ring`. In certain -- circumstances this might be extremely slow, because all instances in its definition are unified -- exponentially many times. In this case, one solution is to manually add the local attribute -- `local attribute [irreducible] coordinate_ring.comm_ring` to block this type-level unification. -- In Lean 4, this is no longer an issue and is now an `abbrev`. See Zulip thread: -- https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/.E2.9C.94.20class_group.2Emk /-- The affine coordinate ring `R[W] := R[X, Y] / ⟨W(X, Y)⟩` of a Weierstrass curve `W`. -/ abbrev CoordinateRing : Type u := AdjoinRoot W.polynomial /-- The function field `R(W) := Frac(R[W])` of a Weierstrass curve `W`. -/ abbrev FunctionField : Type u := FractionRing W.CoordinateRing namespace CoordinateRing section Algebra /-! ### The coordinate ring as an `R[X]`-algebra -/ noncomputable instance : Algebra R W.CoordinateRing := Quotient.algebra R noncomputable instance : Algebra R[X] W.CoordinateRing := Quotient.algebra R[X] instance : IsScalarTower R R[X] W.CoordinateRing := Quotient.isScalarTower R R[X] _ instance [Subsingleton R] : Subsingleton W.CoordinateRing := Module.subsingleton R[X] _ /-- The natural ring homomorphism mapping `R[X][Y]` to `R[W]`. -/ noncomputable abbrev mk : R[X][Y] →+* W.CoordinateRing := AdjoinRoot.mk W.polynomial /-- The power basis `{1, Y}` for `R[W]` over `R[X]`. -/ protected noncomputable def basis : Basis (Fin 2) R[X] W.CoordinateRing := by classical exact (subsingleton_or_nontrivial R).by_cases (fun _ => default) fun _ => (AdjoinRoot.powerBasis' W.monic_polynomial).basis.reindex <| finCongr W.natDegree_polynomial lemma basis_apply (n : Fin 2) : CoordinateRing.basis W n = (AdjoinRoot.powerBasis' W.monic_polynomial).gen ^ (n : ℕ) := by classical nontriviality R rw [CoordinateRing.basis, Or.by_cases, dif_neg <| not_subsingleton R, Basis.reindex_apply, PowerBasis.basis_eq_pow] rfl @[simp] lemma basis_zero : CoordinateRing.basis W 0 = 1 := by simpa only [basis_apply] using pow_zero _ @[simp] lemma basis_one : CoordinateRing.basis W 1 = mk W Y := by simpa only [basis_apply] using pow_one _ lemma coe_basis : (CoordinateRing.basis W : Fin 2 → W.CoordinateRing) = ![1, mk W Y] := by ext n fin_cases n exacts [basis_zero W, basis_one W] variable {W} in
lemma smul (x : R[X]) (y : W.CoordinateRing) : x • y = mk W (C x) * y := (algebraMap_smul W.CoordinateRing x y).symm
Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean
140
142
/- Copyright (c) 2023 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Pi import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Data.Finset.Sups import Mathlib.Order.Birkhoff import Mathlib.Order.Booleanisation import Mathlib.Order.Sublattice import Mathlib.Tactic.Positivity.Basic import Mathlib.Tactic.Ring /-! # The four functions theorem and corollaries This file proves the four functions theorem. The statement is that if `f₁ a * f₂ b ≤ f₃ (a ⊓ b) * f₄ (a ⊔ b)` for all `a`, `b` in a finite distributive lattice, then `(∑ x ∈ s, f₁ x) * (∑ x ∈ t, f₂ x) ≤ (∑ x ∈ s ⊼ t, f₃ x) * (∑ x ∈ s ⊻ t, f₄ x)` where `s ⊼ t = {a ⊓ b | a ∈ s, b ∈ t}`, `s ⊻ t = {a ⊔ b | a ∈ s, b ∈ t}`. The proof uses Birkhoff's representation theorem to restrict to the case where the finite distributive lattice is in fact a finite powerset algebra, namely `Finset α` for some finite `α`. Then it proves this new statement by induction on the size of `α`. ## Main declarations The two versions of the four functions theorem are * `Finset.four_functions_theorem` for finite powerset algebras. * `four_functions_theorem` for any finite distributive lattices. We deduce a number of corollaries: * `Finset.le_card_infs_mul_card_sups`: Daykin inequality. `|s| |t| ≤ |s ⊼ t| |s ⊻ t|` * `holley`: Holley inequality. * `fkg`: Fortuin-Kastelyn-Ginibre inequality. * `Finset.card_le_card_diffs`: Marica-Schönheim inequality. `|s| ≤ |{a \ b | a, b ∈ s}|` ## TODO Prove that lattices in which `Finset.le_card_infs_mul_card_sups` holds are distributive. See Daykin, *A lattice is distributive iff |A| |B| <= |A ∨ B| |A ∧ B|* Prove the Fishburn-Shepp inequality. Is `collapse` a construct generally useful for set family inductions? If so, we should move it to an earlier file and give it a proper API. ## References [*Applications of the FKG Inequality and Its Relatives*, Graham][Graham1983] -/ open Finset Fintype Function open scoped FinsetFamily variable {α β : Type*} section Finset variable [DecidableEq α] [CommSemiring β] [LinearOrder β] [IsStrictOrderedRing β] {𝒜 : Finset (Finset α)} {a : α} {f f₁ f₂ f₃ f₄ : Finset α → β} {s t u : Finset α} /-- The `n = 1` case of the Ahlswede-Daykin inequality. Note that we can't just expand everything out and bound termwise since `c₀ * d₁` appears twice on the RHS of the assumptions while `c₁ * d₀` does not appear. -/ private lemma ineq [ExistsAddOfLE β] {a₀ a₁ b₀ b₁ c₀ c₁ d₀ d₁ : β} (ha₀ : 0 ≤ a₀) (ha₁ : 0 ≤ a₁) (hb₀ : 0 ≤ b₀) (hb₁ : 0 ≤ b₁) (hc₀ : 0 ≤ c₀) (hc₁ : 0 ≤ c₁) (hd₀ : 0 ≤ d₀) (hd₁ : 0 ≤ d₁) (h₀₀ : a₀ * b₀ ≤ c₀ * d₀) (h₁₀ : a₁ * b₀ ≤ c₀ * d₁) (h₀₁ : a₀ * b₁ ≤ c₀ * d₁) (h₁₁ : a₁ * b₁ ≤ c₁ * d₁) : (a₀ + a₁) * (b₀ + b₁) ≤ (c₀ + c₁) * (d₀ + d₁) := by calc _ = a₀ * b₀ + (a₀ * b₁ + a₁ * b₀) + a₁ * b₁ := by ring _ ≤ c₀ * d₀ + (c₀ * d₁ + c₁ * d₀) + c₁ * d₁ := add_le_add_three h₀₀ ?_ h₁₁ _ = (c₀ + c₁) * (d₀ + d₁) := by ring obtain hcd | hcd := (mul_nonneg hc₀ hd₁).eq_or_gt · rw [hcd] at h₀₁ h₁₀ rw [h₀₁.antisymm, h₁₀.antisymm, add_zero] <;> positivity refine le_of_mul_le_mul_right ?_ hcd calc (a₀ * b₁ + a₁ * b₀) * (c₀ * d₁) = a₀ * b₁ * (c₀ * d₁) + c₀ * d₁ * (a₁ * b₀) := by ring _ ≤ a₀ * b₁ * (a₁ * b₀) + c₀ * d₁ * (c₀ * d₁) := mul_add_mul_le_mul_add_mul h₀₁ h₁₀ _ = a₀ * b₀ * (a₁ * b₁) + c₀ * d₁ * (c₀ * d₁) := by ring _ ≤ c₀ * d₀ * (c₁ * d₁) + c₀ * d₁ * (c₀ * d₁) := add_le_add_right (mul_le_mul h₀₀ h₁₁ (by positivity) <| by positivity) _ _ = (c₀ * d₁ + c₁ * d₀) * (c₀ * d₁) := by ring private def collapse (𝒜 : Finset (Finset α)) (a : α) (f : Finset α → β) (s : Finset α) : β := ∑ t ∈ 𝒜 with t.erase a = s, f t private lemma erase_eq_iff (hs : a ∉ s) : t.erase a = s ↔ t = s ∨ t = insert a s := by by_cases ht : a ∈ t <;> · simp [ne_of_mem_of_not_mem', erase_eq_iff_eq_insert, *] aesop private lemma filter_collapse_eq (ha : a ∉ s) (𝒜 : Finset (Finset α)) : {t ∈ 𝒜 | t.erase a = s} = if s ∈ 𝒜 then (if insert a s ∈ 𝒜 then {s, insert a s} else {s}) else (if insert a s ∈ 𝒜 then {insert a s} else ∅) := by ext t; split_ifs <;> simp [erase_eq_iff ha] <;> aesop omit [LinearOrder β] [IsStrictOrderedRing β] in lemma collapse_eq (ha : a ∉ s) (𝒜 : Finset (Finset α)) (f : Finset α → β) : collapse 𝒜 a f s = (if s ∈ 𝒜 then f s else 0) + if insert a s ∈ 𝒜 then f (insert a s) else 0 := by rw [collapse, filter_collapse_eq ha] split_ifs <;> simp [(ne_of_mem_of_not_mem' (mem_insert_self a s) ha).symm, *] omit [LinearOrder β] [IsStrictOrderedRing β] in lemma collapse_of_mem (ha : a ∉ s) (ht : t ∈ 𝒜) (hu : u ∈ 𝒜) (hts : t = s) (hus : u = insert a s) : collapse 𝒜 a f s = f t + f u := by subst hts; subst hus; simp_rw [collapse_eq ha, if_pos ht, if_pos hu] lemma le_collapse_of_mem (ha : a ∉ s) (hf : 0 ≤ f) (hts : t = s) (ht : t ∈ 𝒜) : f t ≤ collapse 𝒜 a f s := by subst hts rw [collapse_eq ha, if_pos ht] split_ifs · exact le_add_of_nonneg_right <| hf _ · rw [add_zero] lemma le_collapse_of_insert_mem (ha : a ∉ s) (hf : 0 ≤ f) (hts : t = insert a s) (ht : t ∈ 𝒜) : f t ≤ collapse 𝒜 a f s := by rw [collapse_eq ha, ← hts, if_pos ht] split_ifs · exact le_add_of_nonneg_left <| hf _ · rw [zero_add] lemma collapse_nonneg (hf : 0 ≤ f) : 0 ≤ collapse 𝒜 a f := fun _s ↦ sum_nonneg fun _t _ ↦ hf _ lemma collapse_modular [ExistsAddOfLE β] (hu : a ∉ u) (h₁ : 0 ≤ f₁) (h₂ : 0 ≤ f₂) (h₃ : 0 ≤ f₃) (h₄ : 0 ≤ f₄) (h : ∀ ⦃s⦄, s ⊆ insert a u → ∀ ⦃t⦄, t ⊆ insert a u → f₁ s * f₂ t ≤ f₃ (s ∩ t) * f₄ (s ∪ t)) (𝒜 ℬ : Finset (Finset α)) : ∀ ⦃s⦄, s ⊆ u → ∀ ⦃t⦄, t ⊆ u → collapse 𝒜 a f₁ s * collapse ℬ a f₂ t ≤ collapse (𝒜 ⊼ ℬ) a f₃ (s ∩ t) * collapse (𝒜 ⊻ ℬ) a f₄ (s ∪ t) := by rintro s hsu t htu -- Gather a bunch of facts we'll need a lot have := hsu.trans <| subset_insert a _ have := htu.trans <| subset_insert a _ have := insert_subset_insert a hsu have := insert_subset_insert a htu have has := not_mem_mono hsu hu have hat := not_mem_mono htu hu have : a ∉ s ∩ t := not_mem_mono (inter_subset_left.trans hsu) hu have := not_mem_union.2 ⟨has, hat⟩ rw [collapse_eq has] split_ifs · rw [collapse_eq hat] split_ifs · rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) rfl (insert_inter_distrib _ _ _).symm, collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (insert_union_distrib _ _ _).symm] refine ineq (h₁ _) (h₁ _) (h₂ _) (h₂ _) (h₃ _) (h₃ _) (h₄ _) (h₄ _) (h ‹_› ‹_›) ?_ ?_ ?_ · simpa [*] using h ‹insert a s ⊆ _› ‹t ⊆ _› · simpa [*] using h ‹s ⊆ _› ‹insert a t ⊆ _› · simpa [*] using h ‹insert a s ⊆ _› ‹insert a t ⊆ _› · rw [add_zero, add_mul] refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (insert_union _ _ _), insert_inter_of_not_mem ‹_›, ← mul_add] exact mul_le_mul_of_nonneg_right (le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›) <| add_nonneg (h₄ _) <| h₄ _ · rw [zero_add, add_mul] refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) (inter_insert_of_not_mem ‹_›) (insert_inter_distrib _ _ _).symm, union_insert, insert_union_distrib, ← add_mul] exact mul_le_mul_of_nonneg_left (le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm <| union_mem_sups ‹_› ‹_›) <| add_nonneg (h₃ _) <| h₃ _ · rw [add_zero, mul_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ · rw [add_zero, collapse_eq hat, mul_add] split_ifs · refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (union_mem_sups ‹_› ‹_›) (union_mem_sups ‹_› ‹_›) rfl (union_insert _ _ _), inter_insert_of_not_mem ‹_›, ← mul_add] exact mul_le_mul_of_nonneg_right (le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›) <| add_nonneg (h₄ _) <| h₄ _ · rw [mul_zero, add_zero] exact (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_mem ‹_› h₃ rfl <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_mem ‹_› h₄ rfl <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · rw [mul_zero, zero_add] refine (h ‹_› ‹_›).trans <| mul_le_mul ?_ (le_collapse_of_insert_mem ‹_› h₄ (union_insert _ _ _) <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ exact le_collapse_of_mem (not_mem_mono inter_subset_left ‹_›) h₃ (inter_insert_of_not_mem ‹_›) <| inter_mem_infs ‹_› ‹_› · simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ · rw [zero_add, collapse_eq hat, mul_add] split_ifs · refine (add_le_add (h ‹_› ‹_›) <| h ‹_› ‹_›).trans ?_ rw [collapse_of_mem ‹_› (inter_mem_infs ‹_› ‹_›) (inter_mem_infs ‹_› ‹_›) (insert_inter_of_not_mem ‹_›) (insert_inter_distrib _ _ _).symm, insert_inter_of_not_mem ‹_›, ← insert_inter_distrib, insert_union, insert_union_distrib, ← add_mul] exact mul_le_mul_of_nonneg_left (le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm <| union_mem_sups ‹_› ‹_›) <| add_nonneg (h₃ _) <| h₃ _ · rw [mul_zero, add_zero] refine (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_mem ‹_› h₃ (insert_inter_of_not_mem ‹_›) <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_insert_mem ‹_› h₄ (insert_union _ _ _) <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · rw [mul_zero, zero_add] exact (h ‹_› ‹_›).trans <| mul_le_mul (le_collapse_of_insert_mem ‹_› h₃ (insert_inter_distrib _ _ _).symm <| inter_mem_infs ‹_› ‹_›) (le_collapse_of_insert_mem ‹_› h₄ (insert_union_distrib _ _ _).symm <| union_mem_sups ‹_› ‹_›) (h₄ _) <| collapse_nonneg h₃ _ · simp_rw [mul_zero, add_zero] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _
· simp_rw [add_zero, zero_mul] exact mul_nonneg (collapse_nonneg h₃ _) <| collapse_nonneg h₄ _ omit [LinearOrder β] [IsStrictOrderedRing β] in lemma sum_collapse (h𝒜 : 𝒜 ⊆ (insert a u).powerset) (hu : a ∉ u) : ∑ s ∈ u.powerset, collapse 𝒜 a f s = ∑ s ∈ 𝒜, f s := by calc _ = ∑ s ∈ u.powerset ∩ 𝒜, f s + ∑ s ∈ u.powerset.image (insert a) ∩ 𝒜, f s := ?_ _ = ∑ s ∈ u.powerset ∩ 𝒜, f s + ∑ s ∈ ((insert a u).powerset \ u.powerset) ∩ 𝒜, f s := ?_ _ = ∑ s ∈ 𝒜, f s := ?_ · rw [← Finset.sum_ite_mem, ← Finset.sum_ite_mem, sum_image, ← sum_add_distrib] · exact sum_congr rfl fun s hs ↦ collapse_eq (not_mem_mono (mem_powerset.1 hs) hu) _ _ · exact (insert_erase_invOn.2.injOn).mono fun s hs ↦ not_mem_mono (mem_powerset.1 hs) hu · congr with s simp only [mem_image, mem_powerset, mem_sdiff, subset_insert_iff] refine ⟨?_, fun h ↦ ⟨_, h.1, ?_⟩⟩ · rintro ⟨s, hs, rfl⟩ exact ⟨subset_insert_iff.1 <| insert_subset_insert _ hs, fun h ↦ hu <| h <| mem_insert_self _ _⟩ · rw [insert_erase (erase_ne_self.1 fun hs ↦ ?_)] rw [hs] at h
Mathlib/Combinatorics/SetFamily/FourFunctions.lean
215
235
/- Copyright (c) 2023 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.Analysis.Normed.Lp.ProdLp /-! # `L²` inner product space structure on products of inner product spaces The `L²` norm on product of two inner product spaces is compatible with an inner product $$ \langle x, y\rangle = \langle x_1, y_1 \rangle + \langle x_2, y_2 \rangle. $$ This is recorded in this file as an inner product space instance on `WithLp 2 (E × F)`. -/ variable {𝕜 ι₁ ι₂ E F : Type*} variable [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] namespace WithLp variable (E F) noncomputable instance instProdInnerProductSpace : InnerProductSpace 𝕜 (WithLp 2 (E × F)) where inner x y := inner x.fst y.fst + inner x.snd y.snd norm_sq_eq_re_inner x := by simp [prod_norm_sq_eq_of_L2, ← norm_sq_eq_re_inner] conj_inner_symm x y := by simp add_left x y z := by simp only [add_fst, add_snd, inner_add_left] ring smul_left x y r := by simp only [smul_fst, inner_smul_left, smul_snd] ring variable {E F} @[simp] theorem prod_inner_apply (x y : WithLp 2 (E × F)) : inner (𝕜 := 𝕜) x y = inner x.fst y.fst + inner x.snd y.snd := rfl end WithLp noncomputable section namespace OrthonormalBasis variable [Fintype ι₁] [Fintype ι₂] /-- The product of two orthonormal bases is a basis for the L2-product. -/ def prod (v : OrthonormalBasis ι₁ 𝕜 E) (w : OrthonormalBasis ι₂ 𝕜 F) : OrthonormalBasis (ι₁ ⊕ ι₂) 𝕜 (WithLp 2 (E × F)) := ((v.toBasis.prod w.toBasis).map (WithLp.linearEquiv 2 𝕜 (E × F)).symm).toOrthonormalBasis (by constructor · simp only [Sum.forall, norm_eq_sqrt_re_inner (𝕜 := 𝕜), Real.sqrt_eq_one] simp [← Real.sqrt_eq_one, ← norm_eq_sqrt_re_inner (𝕜 := 𝕜), v.orthonormal.1, w.orthonormal.1] · unfold Pairwise simp only [ne_eq, Basis.map_apply, Basis.prod_apply, LinearMap.coe_inl, OrthonormalBasis.coe_toBasis, LinearMap.coe_inr, WithLp.linearEquiv_symm_apply, WithLp.prod_inner_apply, WithLp.equiv_symm_fst, WithLp.equiv_symm_snd, Sum.forall, Sum.elim_inl, Function.comp_apply, inner_zero_right, add_zero, Sum.elim_inr, zero_add, Sum.inl.injEq, not_false_eq_true, inner_zero_left, forall_true_left, implies_true, and_true, Sum.inr.injEq, true_and] exact ⟨v.orthonormal.2, w.orthonormal.2⟩)
@[simp] theorem prod_apply (v : OrthonormalBasis ι₁ 𝕜 E) (w : OrthonormalBasis ι₂ 𝕜 F) : ∀ i : ι₁ ⊕ ι₂, v.prod w i = Sum.elim ((LinearMap.inl 𝕜 E F) ∘ v) ((LinearMap.inr 𝕜 E F) ∘ w) i := by rw [Sum.forall] unfold OrthonormalBasis.prod aesop
Mathlib/Analysis/InnerProductSpace/ProdL2.lean
71
76
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Linear.Basic import Mathlib.Algebra.Homology.ComplexShapeSigns import Mathlib.Algebra.Homology.HomologicalBicomplex import Mathlib.Algebra.Module.Basic /-! # The total complex of a bicomplex Given a preadditive category `C`, two complex shapes `c₁ : ComplexShape I₁`, `c₂ : ComplexShape I₂`, a bicomplex `K : HomologicalComplex₂ C c₁ c₂`, and a third complex shape `c₁₂ : ComplexShape I₁₂` equipped with `[TotalComplexShape c₁ c₂ c₁₂]`, we construct the total complex `K.total c₁₂ : HomologicalComplex C c₁₂`. In particular, if `c := ComplexShape.up ℤ` and `K : HomologicalComplex₂ c c`, then for any `n : ℤ`, `(K.total c).X n` identifies to the coproduct of the `(K.X p).X q` such that `p + q = n`, and the differential on `(K.total c).X n` is induced by the sum of horizontal differentials `(K.X p).X q ⟶ (K.X (p + 1)).X q` and `(-1) ^ p` times the vertical differentials `(K.X p).X q ⟶ (K.X p).X (q + 1)`. -/ assert_not_exists TwoSidedIdeal open CategoryTheory Category Limits Preadditive namespace HomologicalComplex₂ variable {C : Type*} [Category C] [Preadditive C] {I₁ I₂ I₁₂ : Type*} {c₁ : ComplexShape I₁} {c₂ : ComplexShape I₂} (K L M : HomologicalComplex₂ C c₁ c₂) (φ : K ⟶ L) (e : K ≅ L) (ψ : L ⟶ M) (c₁₂ : ComplexShape I₁₂) [TotalComplexShape c₁ c₂ c₁₂] /-- A bicomplex has a total bicomplex if for any `i₁₂ : I₁₂`, the coproduct of the objects `(K.X i₁).X i₂` such that `ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂⟩ = i₁₂` exists. -/ abbrev HasTotal := K.toGradedObject.HasMap (ComplexShape.π c₁ c₂ c₁₂) include e in variable {K L} in lemma hasTotal_of_iso [K.HasTotal c₁₂] : L.HasTotal c₁₂ := GradedObject.hasMap_of_iso (GradedObject.isoMk K.toGradedObject L.toGradedObject (fun ⟨i₁, i₂⟩ => (HomologicalComplex.eval _ _ i₁ ⋙ HomologicalComplex.eval _ _ i₂).mapIso e)) _ variable [DecidableEq I₁₂] [K.HasTotal c₁₂] section variable (i₁ : I₁) (i₂ : I₂) (i₁₂ : I₁₂) /-- The horizontal differential in the total complex on a given summand. -/ noncomputable def d₁ : (K.X i₁).X i₂ ⟶ (K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂)) i₁₂ := ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ (c₁.next i₁)).f i₂ ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨_, i₂⟩ i₁₂) /-- The vertical differential in the total complex on a given summand. -/ noncomputable def d₂ : (K.X i₁).X i₂ ⟶ (K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂)) i₁₂ := ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ (c₂.next i₂) ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, _⟩ i₁₂) lemma d₁_eq_zero (h : ¬ c₁.Rel i₁ (c₁.next i₁)) : K.d₁ c₁₂ i₁ i₂ i₁₂ = 0 := by dsimp [d₁] rw [K.shape_f _ _ h, zero_comp, smul_zero] lemma d₂_eq_zero (h : ¬ c₂.Rel i₂ (c₂.next i₂)) : K.d₂ c₁₂ i₁ i₂ i₁₂ = 0 := by dsimp [d₂] rw [HomologicalComplex.shape _ _ _ h, zero_comp, smul_zero] end namespace totalAux /-! Lemmas in the `totalAux` namespace should be used only in the internals of the construction of the total complex `HomologicalComplex₂.total`. Once that definition is done, similar lemmas shall be restated, but with terms like `K.toGradedObject.ιMapObj` replaced by `K.ιTotal`. This is done in order to prevent API leakage from definitions involving graded objects. -/ lemma d₁_eq' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁', i₂⟩ i₁₂) := by obtain rfl := c₁.next_eq' h rfl lemma d₁_eq {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ = i₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₁ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.d i₁ i₁').f i₂ ≫ K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁', i₂⟩ i₁₂ h') := by rw [d₁_eq' K c₁₂ h i₂ i₁₂, K.toGradedObject.ιMapObjOrZero_eq] lemma d₂_eq' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.toGradedObject.ιMapObjOrZero (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂'⟩ i₁₂) := by obtain rfl := c₂.next_eq' h rfl lemma d₂_eq (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ = i₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = ComplexShape.ε₂ c₁ c₂ c₁₂ ⟨i₁, i₂⟩ • ((K.X i₁).d i₂ i₂' ≫ K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) ⟨i₁, i₂'⟩ i₁₂ h') := by rw [d₂_eq' K c₁₂ i₁ h i₁₂, K.toGradedObject.ιMapObjOrZero_eq] end totalAux lemma d₁_eq_zero' {i₁ i₁' : I₁} (h : c₁.Rel i₁ i₁') (i₂ : I₂) (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁', i₂⟩ ≠ i₁₂) : K.d₁ c₁₂ i₁ i₂ i₁₂ = 0 := by rw [totalAux.d₁_eq' K c₁₂ h i₂ i₁₂, K.toGradedObject.ιMapObjOrZero_eq_zero, comp_zero, smul_zero] exact h' lemma d₂_eq_zero' (i₁ : I₁) {i₂ i₂' : I₂} (h : c₂.Rel i₂ i₂') (i₁₂ : I₁₂) (h' : ComplexShape.π c₁ c₂ c₁₂ ⟨i₁, i₂'⟩ ≠ i₁₂) : K.d₂ c₁₂ i₁ i₂ i₁₂ = 0 := by rw [totalAux.d₂_eq' K c₁₂ i₁ h i₁₂, K.toGradedObject.ιMapObjOrZero_eq_zero, comp_zero, smul_zero] exact h' /-- The horizontal differential in the total complex. -/ noncomputable def D₁ (i₁₂ i₁₂' : I₁₂) : K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂ ⟶ K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂' := GradedObject.descMapObj _ (ComplexShape.π c₁ c₂ c₁₂) (fun ⟨i₁, i₂⟩ _ => K.d₁ c₁₂ i₁ i₂ i₁₂') /-- The vertical differential in the total complex. -/ noncomputable def D₂ (i₁₂ i₁₂' : I₁₂) : K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂ ⟶ K.toGradedObject.mapObj (ComplexShape.π c₁ c₂ c₁₂) i₁₂' := GradedObject.descMapObj _ (ComplexShape.π c₁ c₂ c₁₂) (fun ⟨i₁, i₂⟩ _ => K.d₂ c₁₂ i₁ i₂ i₁₂') namespace totalAux @[reassoc (attr := simp)] lemma ιMapObj_D₁ (i₁₂ i₁₂' : I₁₂) (i : I₁ × I₂) (h : ComplexShape.π c₁ c₂ c₁₂ i = i₁₂) : K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) i i₁₂ h ≫ K.D₁ c₁₂ i₁₂ i₁₂' = K.d₁ c₁₂ i.1 i.2 i₁₂' := by simp [D₁] @[reassoc (attr := simp)] lemma ιMapObj_D₂ (i₁₂ i₁₂' : I₁₂) (i : I₁ × I₂) (h : ComplexShape.π c₁ c₂ c₁₂ i = i₁₂) : K.toGradedObject.ιMapObj (ComplexShape.π c₁ c₂ c₁₂) i i₁₂ h ≫ K.D₂ c₁₂ i₁₂ i₁₂' = K.d₂ c₁₂ i.1 i.2 i₁₂' := by simp [D₂]
end totalAux lemma D₁_shape (i₁₂ i₁₂' : I₁₂) (h₁₂ : ¬ c₁₂.Rel i₁₂ i₁₂') : K.D₁ c₁₂ i₁₂ i₁₂' = 0 := by ext ⟨i₁, i₂⟩ h simp only [totalAux.ιMapObj_D₁, comp_zero] by_cases h₁ : c₁.Rel i₁ (c₁.next i₁) · rw [K.d₁_eq_zero' c₁₂ h₁ i₂ i₁₂']
Mathlib/Algebra/Homology/TotalComplex.lean
152
159
/- Copyright (c) 2023 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Peter Pfaffelhuber, Yaël Dillies, Kin Yau James Wong -/ import Mathlib.MeasureTheory.MeasurableSpace.Constructions import Mathlib.MeasureTheory.PiSystem import Mathlib.Topology.Constructions /-! # π-systems of cylinders and square cylinders The instance `MeasurableSpace.pi` on `∀ i, α i`, where each `α i` has a `MeasurableSpace` `m i`, is defined as `⨆ i, (m i).comap (fun a => a i)`. That is, a function `g : β → ∀ i, α i` is measurable iff for all `i`, the function `b ↦ g b i` is measurable. We define two π-systems generating `MeasurableSpace.pi`, cylinders and square cylinders. ## Main definitions Given a finite set `s` of indices, a cylinder is the product of a set of `∀ i : s, α i` and of `univ` on the other indices. A square cylinder is a cylinder for which the set on `∀ i : s, α i` is a product set. * `cylinder s S`: cylinder with base set `S : Set (∀ i : s, α i)` where `s` is a `Finset` * `squareCylinders C` with `C : ∀ i, Set (Set (α i))`: set of all square cylinders such that for all `i` in the finset defining the box, the projection to `α i` belongs to `C i`. The main application of this is with `C i = {s : Set (α i) | MeasurableSet s}`. * `measurableCylinders`: set of all cylinders with measurable base sets. * `cylinderEvents Δ`: The σ-algebra of cylinder events on `Δ`. It is the smallest σ-algebra making the projections on the `i`-th coordinate continuous for all `i ∈ Δ`. ## Main statements * `generateFrom_squareCylinders`: square cylinders formed from measurable sets generate the product σ-algebra * `generateFrom_measurableCylinders`: cylinders formed from measurable sets generate the product σ-algebra -/ open Function Set namespace MeasureTheory variable {ι : Type _} {α : ι → Type _} section squareCylinders /-- Given a finite set `s` of indices, a square cylinder is the product of a set `S` of `∀ i : s, α i` and of `univ` on the other indices. The set `S` is a product of sets `t i` such that for all `i : s`, `t i ∈ C i`. `squareCylinders` is the set of all such squareCylinders. -/ def squareCylinders (C : ∀ i, Set (Set (α i))) : Set (Set (∀ i, α i)) := {S | ∃ s : Finset ι, ∃ t ∈ univ.pi C, S = (s : Set ι).pi t} theorem squareCylinders_eq_iUnion_image (C : ∀ i, Set (Set (α i))) : squareCylinders C = ⋃ s : Finset ι, (fun t ↦ (s : Set ι).pi t) '' univ.pi C := by ext1 f simp only [squareCylinders, mem_iUnion, mem_image, mem_univ_pi, exists_prop, mem_setOf_eq, eq_comm (a := f)] theorem isPiSystem_squareCylinders {C : ∀ i, Set (Set (α i))} (hC : ∀ i, IsPiSystem (C i)) (hC_univ : ∀ i, univ ∈ C i) : IsPiSystem (squareCylinders C) := by rintro S₁ ⟨s₁, t₁, h₁, rfl⟩ S₂ ⟨s₂, t₂, h₂, rfl⟩ hst_nonempty classical let t₁' := s₁.piecewise t₁ (fun i ↦ univ) let t₂' := s₂.piecewise t₂ (fun i ↦ univ) have h1 : ∀ i ∈ (s₁ : Set ι), t₁ i = t₁' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h1' : ∀ i ∉ (s₁ : Set ι), t₁' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi have h2 : ∀ i ∈ (s₂ : Set ι), t₂ i = t₂' i := fun i hi ↦ (Finset.piecewise_eq_of_mem _ _ _ hi).symm have h2' : ∀ i ∉ (s₂ : Set ι), t₂' i = univ := fun i hi ↦ Finset.piecewise_eq_of_not_mem _ _ _ hi rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, ← union_pi_inter h1' h2'] refine ⟨s₁ ∪ s₂, fun i ↦ t₁' i ∩ t₂' i, ?_, ?_⟩ · rw [mem_univ_pi] intro i have : (t₁' i ∩ t₂' i).Nonempty := by obtain ⟨f, hf⟩ := hst_nonempty rw [Set.pi_congr rfl h1, Set.pi_congr rfl h2, mem_inter_iff, mem_pi, mem_pi] at hf refine ⟨f i, ⟨?_, ?_⟩⟩ · by_cases hi₁ : i ∈ s₁ · exact hf.1 i hi₁ · rw [h1' i hi₁] exact mem_univ _ · by_cases hi₂ : i ∈ s₂ · exact hf.2 i hi₂ · rw [h2' i hi₂] exact mem_univ _ refine hC i _ ?_ _ ?_ this · by_cases hi₁ : i ∈ s₁ · rw [← h1 i hi₁] exact h₁ i (mem_univ _) · rw [h1' i hi₁] exact hC_univ i · by_cases hi₂ : i ∈ s₂ · rw [← h2 i hi₂] exact h₂ i (mem_univ _) · rw [h2' i hi₂] exact hC_univ i · rw [Finset.coe_union] theorem comap_eval_le_generateFrom_squareCylinders_singleton (α : ι → Type*) [m : ∀ i, MeasurableSpace (α i)] (i : ι) : MeasurableSpace.comap (Function.eval i) (m i) ≤ MeasurableSpace.generateFrom ((fun t ↦ ({i} : Set ι).pi t) '' univ.pi fun i ↦ {s : Set (α i) | MeasurableSet s}) := by simp only [Function.eval, singleton_pi] rw [MeasurableSpace.comap_eq_generateFrom] refine MeasurableSpace.generateFrom_mono fun S ↦ ?_ simp only [mem_setOf_eq, mem_image, mem_univ_pi, forall_exists_index, and_imp] intro t ht h classical refine ⟨fun j ↦ if hji : j = i then by convert t else univ, fun j ↦ ?_, ?_⟩ · by_cases hji : j = i · simp only [hji, eq_self_iff_true, eq_mpr_eq_cast, dif_pos] convert ht simp only [id_eq, cast_heq] · simp only [hji, not_false_iff, dif_neg, MeasurableSet.univ] · simp only [id_eq, eq_mpr_eq_cast, ← h] ext1 x simp only [singleton_pi, Function.eval, cast_eq, dite_eq_ite, ite_true, mem_preimage] /-- The square cylinders formed from measurable sets generate the product σ-algebra. -/ theorem generateFrom_squareCylinders [∀ i, MeasurableSpace (α i)] : MeasurableSpace.generateFrom (squareCylinders fun i ↦ {s : Set (α i) | MeasurableSet s}) = MeasurableSpace.pi := by apply le_antisymm · rw [MeasurableSpace.generateFrom_le_iff] rintro S ⟨s, t, h, rfl⟩ simp only [mem_univ_pi, mem_setOf_eq] at h exact MeasurableSet.pi (Finset.countable_toSet _) (fun i _ ↦ h i) · refine iSup_le fun i ↦ ?_ refine (comap_eval_le_generateFrom_squareCylinders_singleton α i).trans ?_ refine MeasurableSpace.generateFrom_mono ?_ rw [← Finset.coe_singleton, squareCylinders_eq_iUnion_image] exact subset_iUnion (fun (s : Finset ι) ↦ (fun t : ∀ i, Set (α i) ↦ (s : Set ι).pi t) '' univ.pi (fun i ↦ setOf MeasurableSet)) ({i} : Finset ι) end squareCylinders section cylinder /-- Given a finite set `s` of indices, a cylinder is the preimage of a set `S` of `∀ i : s, α i` by the projection from `∀ i, α i` to `∀ i : s, α i`. -/ def cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : Set (∀ i, α i) := s.restrict ⁻¹' S @[simp] theorem mem_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) (f : ∀ i, α i) : f ∈ cylinder s S ↔ s.restrict f ∈ S := mem_preimage @[simp] theorem cylinder_empty (s : Finset ι) : cylinder s (∅ : Set (∀ i : s, α i)) = ∅ := by rw [cylinder, preimage_empty] @[simp] theorem cylinder_univ (s : Finset ι) : cylinder s (univ : Set (∀ i : s, α i)) = univ := by rw [cylinder, preimage_univ] @[simp] theorem cylinder_eq_empty_iff [h_nonempty : Nonempty (∀ i, α i)] (s : Finset ι) (S : Set (∀ i : s, α i)) : cylinder s S = ∅ ↔ S = ∅ := by refine ⟨fun h ↦ ?_, fun h ↦ by (rw [h]; exact cylinder_empty _)⟩ by_contra hS rw [← Ne, ← nonempty_iff_ne_empty] at hS let f := hS.some have hf : f ∈ S := hS.choose_spec classical let f' : ∀ i, α i := fun i ↦ if hi : i ∈ s then f ⟨i, hi⟩ else h_nonempty.some i have hf' : f' ∈ cylinder s S := by rw [mem_cylinder] simpa only [Finset.restrict_def, Finset.coe_mem, dif_pos, f'] rw [h] at hf' exact not_mem_empty _ hf' theorem inter_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∩ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∩ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_inter_iff, mem_cylinder, mem_setOf_eq]; rfl theorem inter_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∩ cylinder s S₂ = cylinder s (S₁ ∩ S₂) := by classical rw [inter_cylinder]; rfl theorem union_cylinder (s₁ s₂ : Finset ι) (S₁ : Set (∀ i : s₁, α i)) (S₂ : Set (∀ i : s₂, α i)) [DecidableEq ι] : cylinder s₁ S₁ ∪ cylinder s₂ S₂ = cylinder (s₁ ∪ s₂) (Finset.restrict₂ Finset.subset_union_left ⁻¹' S₁ ∪ Finset.restrict₂ Finset.subset_union_right ⁻¹' S₂) := by ext1 f; simp only [mem_union, mem_cylinder, mem_setOf_eq]; rfl theorem union_cylinder_same (s : Finset ι) (S₁ : Set (∀ i : s, α i)) (S₂ : Set (∀ i : s, α i)) : cylinder s S₁ ∪ cylinder s S₂ = cylinder s (S₁ ∪ S₂) := by classical rw [union_cylinder]; rfl theorem compl_cylinder (s : Finset ι) (S : Set (∀ i : s, α i)) : (cylinder s S)ᶜ = cylinder s (Sᶜ) := by ext1 f; simp only [mem_compl_iff, mem_cylinder]
theorem diff_cylinder_same (s : Finset ι) (S T : Set (∀ i : s, α i)) : cylinder s S \ cylinder s T = cylinder s (S \ T) := by
Mathlib/MeasureTheory/Constructions/Cylinders.lean
213
215
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Limits.HasLimits import Mathlib.CategoryTheory.Products.Basic import Mathlib.CategoryTheory.Functor.Currying import Mathlib.CategoryTheory.Products.Bifunctor /-! # A Fubini theorem for categorical (co)limits We prove that $lim_{J × K} G = lim_J (lim_K G(j, -))$ for a functor `G : J × K ⥤ C`, when all the appropriate limits exist. We begin working with a functor `F : J ⥤ K ⥤ C`. We'll write `G : J × K ⥤ C` for the associated "uncurried" functor. In the first part, given a coherent family `D` of limit cones over the functors `F.obj j`, and a cone `c` over `G`, we construct a cone over the cone points of `D`. We then show that if `c` is a limit cone, the constructed cone is also a limit cone. In the second part, we state the Fubini theorem in the setting where limits are provided by suitable `HasLimit` classes. We construct `limitUncurryIsoLimitCompLim F : limit (uncurry.obj F) ≅ limit (F ⋙ lim)` and give simp lemmas characterising it. For convenience, we also provide `limitIsoLimitCurryCompLim G : limit G ≅ limit ((curry.obj G) ⋙ lim)` in terms of the uncurried functor. All statements have their counterpart for colimits. -/ open CategoryTheory namespace CategoryTheory.Limits variable {J K : Type*} [Category J] [Category K] variable {C : Type*} [Category C] variable (F : J ⥤ K ⥤ C) (G : J × K ⥤ C) -- We could try introducing a "dependent functor type" to handle this? /-- A structure carrying a diagram of cones over the functors `F.obj j`. -/ structure DiagramOfCones where /-- For each object, a cone. -/ obj : ∀ j : J, Cone (F.obj j) /-- For each map, a map of cones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (Cones.postcompose (F.map f)).obj (obj j) ⟶ obj j' id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat /-- A structure carrying a diagram of cocones over the functors `F.obj j`. -/ structure DiagramOfCocones where /-- For each object, a cocone. -/ obj : ∀ j : J, Cocone (F.obj j) /-- For each map, a map of cocones. -/ map : ∀ {j j' : J} (f : j ⟶ j'), (obj j) ⟶ (Cocones.precompose (F.map f)).obj (obj j') id : ∀ j : J, (map (𝟙 j)).hom = 𝟙 _ := by aesop_cat comp : ∀ {j₁ j₂ j₃ : J} (f : j₁ ⟶ j₂) (g : j₂ ⟶ j₃), (map (f ≫ g)).hom = (map f).hom ≫ (map g).hom := by aesop_cat variable {F} /-- Extract the functor `J ⥤ C` consisting of the cone points and the maps between them, from a `DiagramOfCones`. -/ @[simps] def DiagramOfCones.conePoints (D : DiagramOfCones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Extract the functor `J ⥤ C` consisting of the cocone points and the maps between them, from a `DiagramOfCocones`. -/ @[simps] def DiagramOfCocones.coconePoints (D : DiagramOfCocones F) : J ⥤ C where obj j := (D.obj j).pt map f := (D.map f).hom map_id j := D.id j map_comp f g := D.comp f g /-- Given a diagram `D` of limit cones over the `F.obj j`, and a cone over `uncurry.obj F`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone (uncurry.obj F)) : Cone D.conePoints where pt := c.pt π := { app := fun j => (Q j).lift { pt := c.pt π := { app := fun k => c.π.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.id_comp] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j, k') (𝟙 j, f) dsimp at this simp? at this says simp only [Category.id_comp, Functor.map_id, NatTrans.id_app] at this exact this } } naturality := fun j j' f => (Q j').hom_ext (by dsimp intro k simp only [Limits.ConeMorphism.w, Limits.Cones.postcompose_obj_π, Limits.IsLimit.fac_assoc, Limits.IsLimit.fac, NatTrans.comp_app, Category.id_comp, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.π (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- Given a diagram `D` of limit cones over the `curry.obj G j`, and a cone over `G`, we can construct a cone over the diagram consisting of the cone points from `D`. -/ @[simps] def coneOfConeCurry {D : DiagramOfCones (curry.obj G)} (Q : ∀ j, IsLimit (D.obj j)) (c : Cone G) : Cone D.conePoints where pt := c.pt π := { app j := (Q j).lift { pt := c.pt π := { app k := c.π.app (j, k) } } naturality {_ j'} _ := (Q j').hom_ext (by simp) } /-- Given a diagram `D` of colimit cocones over the `F.obj j`, and a cocone over `uncurry.obj F`, we can construct a cocone over the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone (uncurry.obj F)) : Cocone D.coconePoints where pt := c.pt ι := { app := fun j => (Q j).desc { pt := c.pt ι := { app := fun k => c.ι.app (j, k) naturality := fun k k' f => by dsimp; simp only [Category.comp_id] conv_lhs => arg 1; equals (F.map (𝟙 _)).app _ ≫ (F.obj j).map f => simp conv_lhs => arg 1; rw [← uncurry_obj_map F ((𝟙 j,f) : (j,k) ⟶ (j,k'))] rw [c.w] } } naturality := fun j j' f => (Q j).hom_ext (by dsimp intro k simp only [Limits.CoconeMorphism.w_assoc, Limits.Cocones.precompose_obj_ι, Limits.IsColimit.fac_assoc, Limits.IsColimit.fac, NatTrans.comp_app, Category.comp_id, Category.assoc] have := @NatTrans.naturality _ _ _ _ _ _ c.ι (j, k) (j', k) (f, 𝟙 k) dsimp at this simp only [Category.id_comp, Category.comp_id, CategoryTheory.Functor.map_id, NatTrans.id_app] at this exact this) } /-- Given a diagram `D` of colimit cocones under the `curry.obj G j`, and a cocone under `G`, we can construct a cocone under the diagram consisting of the cocone points from `D`. -/ @[simps] def coconeOfCoconeCurry {D : DiagramOfCocones (curry.obj G)} (Q : ∀ j, IsColimit (D.obj j)) (c : Cocone G) : Cocone D.coconePoints where pt := c.pt ι := { app j := (Q j).desc { pt := c.pt ι := { app k := c.ι.app (j, k) } } naturality {j _} _ := (Q j).hom_ext (by simp) } /-- `coneOfConeUncurry Q c` is a limit cone when `c` is a limit cone. -/ def coneOfConeUncurryIsLimit {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit c) : IsLimit (coneOfConeUncurry Q c) where lift s := P.lift { pt := s.pt π := { app := fun p => s.π.app p.1 ≫ (D.obj p.1).π.app p.2 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_rhs 3 4 => rw [← NatTrans.naturality] slice_rhs 2 3 => rw [← (D.obj j).π.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k' dsimp at w rw [← w] have n := s.π.naturality fj dsimp at n simp only [Category.id_comp] at n rw [n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt π := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp /-- If `coneOfConeUncurry Q c` is a limit cone then `c` is in fact a limit cone. -/ def IsLimit.ofConeOfConeUncurry {D : DiagramOfCones F} (Q : ∀ j, IsLimit (D.obj j)) {c : Cone (uncurry.obj F)} (P : IsLimit (coneOfConeUncurry Q c)) : IsLimit c := -- These constructions are used in various fields of the proof so we abstract them here. letI E (j : J) : Prod.sectR j K ⋙ uncurry.obj F ≅ F.obj j := NatIso.ofComponents (fun _ ↦ Iso.refl _) letI S (s : Cone (uncurry.obj F)) : Cone D.conePoints := { pt := s.pt π := { app j := (Q j).lift <| (Cones.postcompose (E j).hom).obj <| s.whisker (Prod.sectR j K) naturality {j' j} f := (Q j).hom_ext <| fun k ↦ by simpa [E] using s.π.naturality ((Prod.sectL J k).map f) } } { lift s := P.lift (S s) fac s p := by have h1 := (Q p.1).fac ((Cones.postcompose (E p.1).hom).obj <| s.whisker (Prod.sectR p.1 K)) p.2 simp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Cones.postcompose_obj_pt, Cone.whisker_pt, Cones.postcompose_obj_π, Cone.whisker_π, NatTrans.comp_app, Functor.const_obj_obj, whiskerLeft_app, NatIso.ofComponents_hom_app, Iso.refl_hom, Category.comp_id, E] at h1 have h2 := (P.fac (S s) p.1) dsimp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Functor.const_obj_obj, DiagramOfCones.conePoints_obj, DiagramOfCones.conePoints_map, Functor.const_obj_map, id_eq, Cones.postcompose_obj_pt, Cone.whisker_pt, Cones.postcompose_obj_π, Cone.whisker_π, NatTrans.comp_app, whiskerLeft_app, NatIso.ofComponents_hom_app, Iso.refl_hom, Prod.sectL_obj, Prod.sectL_map, eq_mp_eq_cast, eq_mpr_eq_cast, coneOfConeUncurry_pt, coneOfConeUncurry_π_app, S, E] at h2 ⊢ simp [← h1, ← h2] uniq s f hf := P.uniq (s := S s) _ <| fun j ↦ (Q j).hom_ext <| fun k ↦ by simpa [S, E] using hf (j, k) } /-- `coconeOfCoconeUncurry Q c` is a colimit cocone when `c` is a colimit cocone. -/ def coconeOfCoconeUncurryIsColimit {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit c) : IsColimit (coconeOfCoconeUncurry Q c) where desc s := P.desc { pt := s.pt ι := { app := fun p => (D.obj p.1).ι.app p.2 ≫ s.ι.app p.1 naturality := fun p p' f => by dsimp; simp only [Category.id_comp, Category.assoc] rcases p with ⟨j, k⟩ rcases p' with ⟨j', k'⟩ rcases f with ⟨fj, fk⟩ dsimp slice_lhs 2 3 => rw [(D.obj j').ι.naturality] simp only [Functor.const_obj_map, Category.id_comp, Category.assoc] have w := (D.map fj).w k dsimp at w slice_lhs 1 2 => rw [← w] have n := s.ι.naturality fj dsimp at n simp only [Category.comp_id] at n rw [← n] simp } } fac s j := by apply (Q j).hom_ext intro k simp uniq s m w := by refine P.uniq { pt := s.pt ι := _ } m ?_ rintro ⟨j, k⟩ dsimp rw [← w j] simp /-- If `coconeOfCoconeUncurry Q c` is a colimit cocone then `c` is in fact a colimit cocone. -/ def IsColimit.ofCoconeUncurry {D : DiagramOfCocones F} (Q : ∀ j, IsColimit (D.obj j)) {c : Cocone (uncurry.obj F)} (P : IsColimit (coconeOfCoconeUncurry Q c)) : IsColimit c := -- These constructions are used in various fields of the proof so we abstract them here. letI E (j : J) : (Prod.sectR j K ⋙ uncurry.obj F ≅ F.obj j) := NatIso.ofComponents (fun _ ↦ Iso.refl _) letI S (s : Cocone (uncurry.obj F)) : Cocone D.coconePoints := { pt := s.pt ι := { app j := (Q j).desc <| (Cocones.precompose (E j).inv).obj <| s.whisker (Prod.sectR j K) naturality {j j'} f := (Q j).hom_ext <| fun k ↦ by simpa [E] using s.ι.naturality ((Prod.sectL J k).map f) } } { desc s := P.desc (S s) fac s p := by have h1 := (Q p.1).fac ((Cocones.precompose (E p.1).inv).obj <| s.whisker (Prod.sectR p.1 K)) p.2 simp only [Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Cocones.precompose_obj_pt, Cocone.whisker_pt, Functor.const_obj_obj, Cocones.precompose_obj_ι, Cocone.whisker_ι, NatTrans.comp_app, NatIso.ofComponents_inv_app, Iso.refl_inv, whiskerLeft_app, Category.id_comp, E] at h1 have h2 := (P.fac (S s) p.1) dsimp only [DiagramOfCocones.coconePoints_obj, Functor.comp_obj, Prod.sectR_obj, uncurry_obj_obj, NatTrans.id_app, Functor.const_obj_obj, DiagramOfCocones.coconePoints_map, Functor.const_obj_map, id_eq, Cocones.precompose_obj_pt, Cocone.whisker_pt, Cocones.precompose_obj_ι, Cocone.whisker_ι, NatTrans.comp_app, NatIso.ofComponents_inv_app, Iso.refl_inv, whiskerLeft_app, Prod.sectL_obj, Prod.sectL_map, eq_mp_eq_cast, eq_mpr_eq_cast, coconeOfCoconeUncurry_pt, coconeOfCoconeUncurry_ι_app, S, E] at h2 ⊢ simp [← h1, ← h2] uniq s f hf := P.uniq (s := S s) _ <| fun j ↦ (Q j).hom_ext <| fun k ↦ by simpa [S, E] using hf (j, k) } section variable (F) variable [HasLimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed limits, we can construct a diagram consisting of the limit cone over each functor `F.obj j`, and the universal cone morphisms between these. -/ @[simps] noncomputable def DiagramOfCones.mkOfHasLimits : DiagramOfCones F where obj j := limit.cone (F.obj j) map f := { hom := lim.map (F.map f) } -- Satisfying the inhabited linter. noncomputable instance diagramOfConesInhabited : Inhabited (DiagramOfCones F) := ⟨DiagramOfCones.mkOfHasLimits F⟩ @[simp] theorem DiagramOfCones.mkOfHasLimits_conePoints : (DiagramOfCones.mkOfHasLimits F).conePoints = F ⋙ lim := rfl section variable [HasLimit (curry.obj G ⋙ lim)] /-- Given a functor `G : J × K ⥤ C` such that `(curry.obj G ⋙ lim)` makes sense and has a limit, we can construct a cone over `G` with `limit (curry.obj G ⋙ lim)` as a cone point -/ noncomputable def coneOfHasLimitCurryCompLim : Cone G := let Q : DiagramOfCones (curry.obj G) := .mkOfHasLimits _ { pt := limit (curry.obj G ⋙ lim), π := { app x := limit.π (curry.obj G ⋙ lim) x.fst ≫ (Q.obj x.fst).π.app x.snd naturality {x y} := fun ⟨f₁, f₂⟩ ↦ by have := (Q.obj x.1).w f₂ dsimp [Q] at this ⊢ rw [← limit.w (F := curry.obj G ⋙ lim) (f := f₁)] dsimp simp only [Category.assoc, Category.id_comp, Prod.fac (f₁, f₂), G.map_comp, limMap_π, curry_obj_map_app, reassoc_of% this] } } /-- The cone `coneOfHasLimitCurryCompLim` is in fact a limit cone. -/ noncomputable def isLimitConeOfHasLimitCurryCompLim : IsLimit (coneOfHasLimitCurryCompLim G) := let Q : DiagramOfCones (curry.obj G) := .mkOfHasLimits _ let Q' : ∀ j, IsLimit (Q.obj j) := fun j => limit.isLimit _ { lift c' := limit.lift (F := curry.obj G ⋙ lim) (coneOfConeCurry G Q' c') fac c' f := by simp [coneOfHasLimitCurryCompLim, Q, Q'] uniq c' f h := by dsimp [coneOfHasLimitCurryCompLim] at f h ⊢ refine limit.hom_ext (F := curry.obj G ⋙ lim) (fun j ↦ limit.hom_ext (fun k ↦ ?_)) simp [h ⟨j, k⟩, Q'] } /-- The functor `G` has a limit if `C` has `K`-shaped limits and `(curry.obj G ⋙ lim)` has a limit. -/ instance : HasLimit G where exists_limit := ⟨ { cone := coneOfHasLimitCurryCompLim G isLimit := isLimitConeOfHasLimitCurryCompLim G }⟩ end variable [HasLimit (uncurry.obj F)] [HasLimit (F ⋙ lim)] /-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the limit of `uncurry.obj F` can be computed as the limit of the limits of the functors `F.obj j`. -/ noncomputable def limitUncurryIsoLimitCompLim : limit (uncurry.obj F) ≅ limit (F ⋙ lim) := by let c := limit.cone (uncurry.obj F) let P : IsLimit c := limit.isLimit _ let G := DiagramOfCones.mkOfHasLimits F let Q : ∀ j, IsLimit (G.obj j) := fun j => limit.isLimit _ have Q' := coneOfConeUncurryIsLimit Q P have Q'' := limit.isLimit (F ⋙ lim) exact IsLimit.conePointUniqueUpToIso Q' Q'' @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_hom_π_π {j} {k} : (limitUncurryIsoLimitCompLim F).hom ≫ limit.π _ j ≫ limit.π _ k = limit.π _ (j, k) := by dsimp [limitUncurryIsoLimitCompLim, IsLimit.conePointUniqueUpToIso, IsLimit.uniqueUpToIso] simp @[simp, reassoc] theorem limitUncurryIsoLimitCompLim_inv_π {j} {k} : (limitUncurryIsoLimitCompLim F).inv ≫ limit.π _ (j, k) = (limit.π _ j ≫ limit.π _ k) := by rw [← cancel_epi (limitUncurryIsoLimitCompLim F).hom] simp end section variable (F) variable [HasColimitsOfShape K C] /-- Given a functor `F : J ⥤ K ⥤ C`, with all needed colimits, we can construct a diagram consisting of the colimit cocone over each functor `F.obj j`, and the universal cocone morphisms between these. -/ @[simps] noncomputable def DiagramOfCocones.mkOfHasColimits : DiagramOfCocones F where obj j := colimit.cocone (F.obj j) map f := { hom := colim.map (F.map f) } -- Satisfying the inhabited linter. noncomputable instance diagramOfCoconesInhabited : Inhabited (DiagramOfCocones F) := ⟨DiagramOfCocones.mkOfHasColimits F⟩ @[simp] theorem DiagramOfCocones.mkOfHasColimits_coconePoints : (DiagramOfCocones.mkOfHasColimits F).coconePoints = F ⋙ colim := rfl section variable [HasColimit (curry.obj G ⋙ colim)] /-- Given a functor `G : J × K ⥤ C` such that `(curry.obj G ⋙ colim)` makes sense and has a colimit, we can construct a cocone under `G` with `colimit (curry.obj G ⋙ colim)` as a cocone point -/ noncomputable def coconeOfHasColimitCurryCompColim : Cocone G := let Q : DiagramOfCocones (curry.obj G) := .mkOfHasColimits _ { pt := colimit (curry.obj G ⋙ colim), ι := { app x := (Q.obj x.fst).ι.app x.snd ≫ colimit.ι (curry.obj G ⋙ colim) x.fst naturality {x y} := fun ⟨f₁, f₂⟩ ↦ by have := (Q.obj y.1).w f₂ dsimp [Q] at this ⊢ rw [← colimit.w (F := curry.obj G ⋙ colim) (f := f₁)] dsimp simp [Category.assoc, Category.comp_id, Prod.fac' (f₁, f₂), G.map_comp, ι_colimMap_assoc, curry_obj_map_app, reassoc_of% this] } } /-- The cocone `coconeOfHasColimitCurryCompColim` is in fact a limit cocone. -/ noncomputable def isColimitCoconeOfHasColimitCurryCompColim : IsColimit (coconeOfHasColimitCurryCompColim G) := let Q : DiagramOfCocones (curry.obj G) := .mkOfHasColimits _ let Q' : ∀ j, IsColimit (Q.obj j) := fun j => colimit.isColimit _ { desc c' := colimit.desc (F := curry.obj G ⋙ colim) (coconeOfCoconeCurry G Q' c') fac c' f := by simp [coconeOfHasColimitCurryCompColim, Q, Q'] uniq c' f h := by dsimp [coconeOfHasColimitCurryCompColim] at f h ⊢ refine colimit.hom_ext (F := curry.obj G ⋙ colim) (fun j ↦ colimit.hom_ext (fun k ↦ ?_)) simp [← h ⟨j, k⟩, Q'] } /-- The functor `G` has a colimit if `C` has `K`-shaped colimits and `(curry.obj G ⋙ colim)` has a colimit. -/ instance : HasColimit G where exists_colimit := ⟨ { cocone := coconeOfHasColimitCurryCompColim G isColimit := isColimitCoconeOfHasColimitCurryCompColim G }⟩ end variable [HasColimit (uncurry.obj F)] [HasColimit (F ⋙ colim)]
/-- The Fubini theorem for a functor `F : J ⥤ K ⥤ C`, showing that the colimit of `uncurry.obj F` can be computed as the colimit of the colimits of the functors `F.obj j`. -/ noncomputable def colimitUncurryIsoColimitCompColim : colimit (uncurry.obj F) ≅ colimit (F ⋙ colim) := by
Mathlib/CategoryTheory/Limits/Fubini.lean
489
494
/- 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 /-! # 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) 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 } end Defs namespace FractionalIdeal open Set Submodule variable {R : Type*} [CommRing R] {S : Submonoid R} {P : Type*} [CommRing P] variable [Algebra R 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 /-- 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) (FaithfulSMul.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 @[ext] theorem ext {I J : FractionalIdeal S P} : (∀ x, x ∈ I ↔ x ∈ J) → I = J := SetLike.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⟩ @[simp] theorem coe_copy (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : ↑(p.copy s hs) = s := rfl theorem coe_eq (p : FractionalIdeal S P) (s : Set P) (hs : s = ↑p) : p.copy s hs = p := SetLike.coe_injective hs end SetLike lemma zero_mem (I : FractionalIdeal S P) : 0 ∈ I := I.coeToSubmodule.zero_mem -- 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 -- 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 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 theorem coeToSubmodule_inj {I J : FractionalIdeal S P} : (I : Submodule R P) = J ↔ I = J := coeToSubmodule_injective.eq_iff 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⟩ := mem_one.mp (h hb) exact Set.mem_range_self b' 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) /-- 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 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 _ _ 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⟩ 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 @[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 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]⟩⟩ variable {S} @[simp, norm_cast] theorem coe_zero : ↑(0 : FractionalIdeal S P) = (⊥ : Submodule R P) := Submodule.ext fun _ => mem_zero_iff S @[simp, norm_cast] theorem coeIdeal_bot : ((⊥ : Ideal R) : FractionalIdeal S P) = 0 := rfl section variable [loc : IsLocalization S P] variable (P) in @[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⟩⟩ 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) theorem coeIdeal_inj' (h : S ≤ nonZeroDivisors R) {I J : Ideal R} : (I : FractionalIdeal S P) = J ↔ I = J := (coeIdeal_injective' h).eq_iff -- 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 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 end 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]⟩ theorem coeToSubmodule_ne_bot {I : FractionalIdeal S P} : ↑I ≠ (⊥ : Submodule R P) ↔ I ≠ 0 := not_iff_not.mpr coeToSubmodule_eq_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 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⟩ theorem coe_mem_one (x : R) : algebraMap R P x ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨x, rfl⟩ theorem one_mem_one : (1 : P) ∈ (1 : FractionalIdeal S P) := (mem_one_iff S).mpr ⟨1, RingHom.map_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 @[simp, norm_cast] theorem coe_one : (↑(1 : FractionalIdeal S P) : Submodule R P) = 1 := by rw [coe_one_eq_coeSubmodule_top, coeSubmodule_top] 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 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 instance orderBot : OrderBot (FractionalIdeal S P) where bot := 0 bot_le := zero_le @[simp] theorem bot_eq_zero : (⊥ : FractionalIdeal S P) = 0 := rfl @[simp] theorem le_zero_iff {I : FractionalIdeal S P} : I ≤ 0 ↔ I = 0 := le_bot_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)⟩ 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)⟩ 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⟩ instance : Min (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 instance : Max (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 instance lattice : Lattice (FractionalIdeal S P) := Function.Injective.lattice _ Subtype.coe_injective coe_sup coe_inf 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 @[simp, norm_cast] theorem coe_add (I J : FractionalIdeal S P) : (↑(I + J) : Submodule R P) = I + J := rfl theorem mem_add (I J : FractionalIdeal S P) (x : P) : x ∈ I + J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = x := by rw [← mem_coe, coe_add, Submodule.add_eq_sup]; exact Submodule.mem_sup @[simp, norm_cast] theorem coeIdeal_sup (I J : Ideal R) : ↑(I ⊔ J) = (I + J : FractionalIdeal S P) := coeToSubmodule_injective <| coeSubmodule_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 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 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⟩ 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 /-- `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⟩ -- 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 theorem mul_def (I J : FractionalIdeal S P) : I * J = ⟨I * J, I.isFractional.mul J.isFractional⟩ := by simp only [← mul_eq_mul, 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] @[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 _ _ _) 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) 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 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 theorem mul_le {I J K : FractionalIdeal S P} : I * J ≤ K ↔ ∀ i ∈ I, ∀ j ∈ J, i * j ∈ K := by simp only [mul_def] exact Submodule.mul_le instance : Pow (FractionalIdeal S P) ℕ := ⟨fun I n => ⟨(I : Submodule R P) ^ n, I.isFractional.pow n⟩⟩ @[simp, norm_cast] theorem coe_pow (I : FractionalIdeal S P) (n : ℕ) : ↑(I ^ n) = (I : Submodule R P) ^ n := rfl @[elab_as_elim] protected theorem mul_induction_on {I J : FractionalIdeal S P} {C : P → Prop} {r : P} (hr : r ∈ I * J) (hm : ∀ i ∈ I, ∀ j ∈ J, C (i * j)) (ha : ∀ x y, C x → C y → C (x + y)) : C r := by simp only [mul_def] at hr exact Submodule.mul_induction_on hr hm ha instance : NatCast (FractionalIdeal S P) := ⟨Nat.unaryCast⟩ theorem coe_natCast (n : ℕ) : ((n : FractionalIdeal S P) : Submodule R P) = n := show ((n.unaryCast : FractionalIdeal S P) : Submodule R P) = n by induction n <;> simp [*, Nat.unaryCast] instance commSemiring : CommSemiring (FractionalIdeal S P) := Function.Injective.commSemiring _ Subtype.coe_injective coe_zero coe_one coe_add coe_mul (fun _ _ => coe_nsmul _ _) coe_pow coe_natCast end Semiring variable (S P) /-- `FractionalIdeal.coeToSubmodule` as a bundled `RingHom`. -/ @[simps] def coeSubmoduleHom : FractionalIdeal S P →+* Submodule R P where toFun := coeToSubmodule map_one' := coe_one map_mul' := coe_mul map_zero' := coe_zero (S := S) map_add' := coe_add variable {S P} section Order theorem add_le_add_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' + I ≤ J' + J := sup_le_sup_left hIJ J' theorem mul_le_mul_left {I J : FractionalIdeal S P} (hIJ : I ≤ J) (J' : FractionalIdeal S P) : J' * I ≤ J' * J := mul_le.mpr fun _ hk _ hj => mul_mem_mul hk (hIJ hj) theorem le_self_mul_self {I : FractionalIdeal S P} (hI : 1 ≤ I) : I ≤ I * I := by convert mul_left_mono I hI exact (mul_one I).symm theorem mul_self_le_self {I : FractionalIdeal S P} (hI : I ≤ 1) : I * I ≤ I := by convert mul_left_mono I hI exact (mul_one I).symm theorem coeIdeal_le_one {I : Ideal R} : (I : FractionalIdeal S P) ≤ 1 := fun _ hx => let ⟨y, _, hy⟩ := (mem_coeIdeal S).mp hx (mem_one_iff S).mpr ⟨y, hy⟩ theorem le_one_iff_exists_coeIdeal {J : FractionalIdeal S P} : J ≤ (1 : FractionalIdeal S P) ↔ ∃ I : Ideal R, ↑I = J := by constructor · intro hJ refine ⟨⟨⟨⟨{ x : R | algebraMap R P x ∈ J }, ?_⟩, ?_⟩, ?_⟩, ?_⟩ · intro a b ha hb rw [mem_setOf, RingHom.map_add] exact J.val.add_mem ha hb · rw [mem_setOf, RingHom.map_zero] exact J.zero_mem · intro c x hx rw [smul_eq_mul, mem_setOf, RingHom.map_mul, ← Algebra.smul_def] exact J.val.smul_mem c hx · ext x constructor · rintro ⟨y, hy, eq_y⟩ rwa [← eq_y] · intro hx obtain ⟨y, rfl⟩ := (mem_one_iff S).mp (hJ hx) exact mem_setOf.mpr ⟨y, hx, rfl⟩ · rintro ⟨I, hI⟩ rw [← hI] apply coeIdeal_le_one @[simp] theorem one_le {I : FractionalIdeal S P} : 1 ≤ I ↔ (1 : P) ∈ I := by rw [← coe_le_coe, coe_one, Submodule.one_le, mem_coe] variable (S P) /-- `coeIdealHom (S : Submonoid R) P` is `(↑) : Ideal R → FractionalIdeal S P` as a ring hom -/ @[simps] def coeIdealHom : Ideal R →+* FractionalIdeal S P where toFun := coeIdeal map_add' := coeIdeal_sup map_mul' := coeIdeal_mul map_one' := by rw [Ideal.one_eq_top, coeIdeal_top] map_zero' := coeIdeal_bot theorem coeIdeal_pow (I : Ideal R) (n : ℕ) : ↑(I ^ n) = (I : FractionalIdeal S P) ^ n := (coeIdealHom S P).map_pow _ n theorem coeIdeal_finprod [IsLocalization S P] {α : Sort*} {f : α → Ideal R} (hS : S ≤ nonZeroDivisors R) : ((∏ᶠ a : α, f a : Ideal R) : FractionalIdeal S P) = ∏ᶠ a : α, (f a : FractionalIdeal S P) := MonoidHom.map_finprod_of_injective (coeIdealHom S P).toMonoidHom (coeIdeal_injective' hS) f end Order section FG variable {R : Type*} [CommRing R] [Nontrivial R] {S : Submonoid R} variable {P : Type*} [Nontrivial P] [CommRing P] [Algebra R P] [NoZeroSMulDivisors R P] /-- The fractional ideals of a Noetherian ring are finitely generated. -/ lemma fg_of_isNoetherianRing [hR : IsNoetherianRing R] (hS : S ≤ R⁰) (I : FractionalIdeal S P) : FG I.coeToSubmodule := by have := hR.noetherian I.num rw [← fg_top] at this ⊢ exact fg_of_linearEquiv (I.equivNum <| coe_ne_zero ⟨(I.den : R), hS (SetLike.coe_mem I.den)⟩) this
end FG
Mathlib/RingTheory/FractionalIdeal/Basic.lean
681
683
/- 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.Divisibility.Hom import Mathlib.Algebra.Group.Even import Mathlib.Algebra.Group.Nat.Hom import Mathlib.Algebra.Ring.Hom.Defs import Mathlib.Algebra.Ring.Nat /-! # Cast of natural numbers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the natural numbers into an additive monoid with a one (`Nat.cast`). ## Main declarations * `castAddMonoidHom`: `cast` bundled as an `AddMonoidHom`. * `castRingHom`: `cast` bundled as a `RingHom`. -/ assert_not_exists OrderedCommGroup Commute.zero_right Commute.add_right abs_eq_max_neg NeZero.natCast_ne -- TODO: `MulOpposite.op_natCast` was not intended to be imported -- assert_not_exists MulOpposite.op_natCast open Additive Multiplicative variable {α β : Type*} namespace Nat /-- `Nat.cast : ℕ → α` as an `AddMonoidHom`. -/ def castAddMonoidHom (α : Type*) [AddMonoidWithOne α] : ℕ →+ α where toFun := Nat.cast map_add' := cast_add map_zero' := cast_zero @[simp] theorem coe_castAddMonoidHom [AddMonoidWithOne α] : (castAddMonoidHom α : ℕ → α) = Nat.cast := rfl lemma _root_.Even.natCast [AddMonoidWithOne α] {n : ℕ} (hn : Even n) : Even (n : α) := hn.map <| Nat.castAddMonoidHom α section NonAssocSemiring variable [NonAssocSemiring α] @[simp, norm_cast] lemma cast_mul (m n : ℕ) : ((m * n : ℕ) : α) = m * n := by induction n <;> simp [mul_succ, mul_add, *] variable (α) in /-- `Nat.cast : ℕ → α` as a `RingHom` -/ def castRingHom : ℕ →+* α := { castAddMonoidHom α with toFun := Nat.cast, map_one' := cast_one, map_mul' := cast_mul } @[simp, norm_cast] lemma coe_castRingHom : (castRingHom α : ℕ → α) = Nat.cast := rfl lemma _root_.nsmul_eq_mul' (a : α) (n : ℕ) : n • a = a * n := by induction n with | zero => rw [zero_nsmul, Nat.cast_zero, mul_zero] | succ n ih => rw [succ_nsmul, ih, Nat.cast_succ, mul_add, mul_one] @[simp] lemma _root_.nsmul_eq_mul (n : ℕ) (a : α) : n • a = n * a := by induction n with | zero => rw [zero_nsmul, Nat.cast_zero, zero_mul] | succ n ih => rw [succ_nsmul, ih, Nat.cast_succ, add_mul, one_mul] end NonAssocSemiring section Semiring variable [Semiring α] {m n : ℕ} @[simp, norm_cast] lemma cast_pow (m : ℕ) : ∀ n : ℕ, ↑(m ^ n) = (m ^ n : α) | 0 => by simp | n + 1 => by rw [_root_.pow_succ', _root_.pow_succ', cast_mul, cast_pow m n] lemma cast_dvd_cast (h : m ∣ n) : (m : α) ∣ (n : α) := map_dvd (Nat.castRingHom α) h alias _root_.Dvd.dvd.natCast := cast_dvd_cast end Semiring end Nat section AddMonoidHomClass variable {A B F : Type*} [AddMonoidWithOne B] [FunLike F ℕ A] [AddMonoidWithOne A] -- these versions are primed so that the `RingHomClass` versions aren't theorem eq_natCast' [AddMonoidHomClass F ℕ A] (f : F) (h1 : f 1 = 1) : ∀ n : ℕ, f n = n | 0 => by simp | n + 1 => by rw [map_add, h1, eq_natCast' f h1 n, Nat.cast_add_one] theorem map_natCast' {A} [AddMonoidWithOne A] [FunLike F A B] [AddMonoidHomClass F A B] (f : F) (h : f 1 = 1) : ∀ n : ℕ, f n = n := eq_natCast' ((f : A →+ B).comp <| Nat.castAddMonoidHom _) (by simpa) theorem map_ofNat' {A} [AddMonoidWithOne A] [FunLike F A B] [AddMonoidHomClass F A B] (f : F) (h : f 1 = 1) (n : ℕ) [n.AtLeastTwo] : f (OfNat.ofNat n) = OfNat.ofNat n := map_natCast' f h n end AddMonoidHomClass section MonoidWithZeroHomClass variable {A F : Type*} [MulZeroOneClass A] [FunLike F ℕ A] /-- If two `MonoidWithZeroHom`s agree on the positive naturals they are equal. -/ theorem ext_nat'' [ZeroHomClass F ℕ A] (f g : F) (h_pos : ∀ {n : ℕ}, 0 < n → f n = g n) : f = g := by apply DFunLike.ext rintro (_ | n) · simp · exact h_pos n.succ_pos @[ext] theorem MonoidWithZeroHom.ext_nat {f g : ℕ →*₀ A} : (∀ {n : ℕ}, 0 < n → f n = g n) → f = g := ext_nat'' f g end MonoidWithZeroHomClass section RingHomClass variable {R S F : Type*} [NonAssocSemiring R] [NonAssocSemiring S] @[simp] theorem eq_natCast [FunLike F ℕ R] [RingHomClass F ℕ R] (f : F) : ∀ n, f n = n := eq_natCast' f <| map_one f @[simp] theorem map_natCast [FunLike F R S] [RingHomClass F R S] (f : F) : ∀ n : ℕ, f (n : R) = n := map_natCast' f <| map_one f /-- This lemma is not marked `@[simp]` lemma because its `#discr_tree_key` (for the LHS) would just be `DFunLike.coe _ _`, due to the `ofNat` that https://github.com/leanprover/lean4/issues/2867 forces us to include, and therefore it would negatively impact performance. If that issue is resolved, this can be marked `@[simp]`. -/ theorem map_ofNat [FunLike F R S] [RingHomClass F R S] (f : F) (n : ℕ) [Nat.AtLeastTwo n] : (f ofNat(n) : S) = OfNat.ofNat n := map_natCast f n theorem ext_nat [FunLike F ℕ R] [RingHomClass F ℕ R] (f g : F) : f = g := ext_nat' f g <| by simp theorem NeZero.nat_of_neZero {R S} [NonAssocSemiring R] [NonAssocSemiring S] {F} [FunLike F R S] [RingHomClass F R S] (f : F) {n : ℕ} [hn : NeZero (n : S)] : NeZero (n : R) := .of_map (f := f) (neZero := by simp only [map_natCast, hn]) end RingHomClass namespace RingHom /-- This is primed to match `eq_intCast'`. -/ theorem eq_natCast' {R} [NonAssocSemiring R] (f : ℕ →+* R) : f = Nat.castRingHom R := RingHom.ext <| eq_natCast f end RingHom @[simp, norm_cast] theorem Nat.cast_id (n : ℕ) : n.cast = n := rfl @[simp] theorem Nat.castRingHom_nat : Nat.castRingHom ℕ = RingHom.id ℕ := rfl /-- We don't use `RingHomClass` here, since that might cause type-class slowdown for `Subsingleton`. -/ instance Nat.uniqueRingHom {R : Type*} [NonAssocSemiring R] : Unique (ℕ →+* R) where default := Nat.castRingHom R uniq := RingHom.eq_natCast' namespace Pi variable {π : α → Type*} section NatCast variable [∀ a, NatCast (π a)] instance instNatCast : NatCast (∀ a, π a) where natCast n _ := n @[simp] theorem natCast_apply (n : ℕ) (a : α) : (n : ∀ a, π a) a = n := rfl theorem natCast_def (n : ℕ) : (n : ∀ a, π a) = fun _ ↦ ↑n := rfl end NatCast section OfNat -- This instance is low priority, as `to_additive` only works with the one that comes from `One` -- and `Zero`. instance (priority := low) instOfNat (n : ℕ) [∀ i, OfNat (π i) n] : OfNat ((i : α) → π i) n where ofNat _ := OfNat.ofNat n @[simp] theorem ofNat_apply (n : ℕ) [∀ i, OfNat (π i) n] (a : α) : (ofNat(n) : ∀ a, π a) a = ofNat(n) := rfl lemma ofNat_def (n : ℕ) [∀ i, OfNat (π i) n] : (ofNat(n) : ∀ a, π a) = fun _ ↦ ofNat(n) := rfl end OfNat end Pi theorem Sum.elim_natCast_natCast {α β γ : Type*} [NatCast γ] (n : ℕ) : Sum.elim (n : α → γ) (n : β → γ) = n := Sum.elim_lam_const_lam_const (γ := γ) n
Mathlib/Data/Nat/Cast/Basic.lean
271
273
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, David Kurniadi Angdinata -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.CubicDiscriminant import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination /-! # Weierstrass equations of elliptic curves This file defines the structure of an elliptic curve as a nonsingular Weierstrass curve given by a Weierstrass equation, which is mathematically accurate in many cases but also good for computation. ## Mathematical background Let `S` be a scheme. The actual category of elliptic curves over `S` is a large category, whose objects are schemes `E` equipped with a map `E → S`, a section `S → E`, and some axioms (the map is smooth and proper and the fibres are geometrically-connected one-dimensional group varieties). In the special case where `S` is the spectrum of some commutative ring `R` whose Picard group is zero (this includes all fields, all PIDs, and many other commutative rings) it can be shown (using a lot of algebro-geometric machinery) that every elliptic curve `E` is a projective plane cubic isomorphic to a Weierstrass curve given by the equation `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` for some `aᵢ` in `R`, and such that a certain quantity called the discriminant of `E` is a unit in `R`. If `R` is a field, this quantity divides the discriminant of a cubic polynomial whose roots over a splitting field of `R` are precisely the `X`-coordinates of the non-zero 2-torsion points of `E`. ## Main definitions * `WeierstrassCurve`: a Weierstrass curve over a commutative ring. * `WeierstrassCurve.Δ`: the discriminant of a Weierstrass curve. * `WeierstrassCurve.map`: the Weierstrass curve mapped over a ring homomorphism. * `WeierstrassCurve.twoTorsionPolynomial`: the 2-torsion polynomial of a Weierstrass curve. * `WeierstrassCurve.IsElliptic`: typeclass asserting that a Weierstrass curve is an elliptic curve. * `WeierstrassCurve.j`: the j-invariant of an elliptic curve. ## Main statements * `WeierstrassCurve.twoTorsionPolynomial_disc`: the discriminant of a Weierstrass curve is a constant factor of the cubic discriminant of its 2-torsion polynomial. ## Implementation notes The definition of elliptic curves in this file makes sense for all commutative rings `R`, but it only gives a type which can be beefed up to a category which is equivalent to the category of elliptic curves over the spectrum `Spec(R)` of `R` in the case that `R` has trivial Picard group `Pic(R)` or, slightly more generally, when its 12-torsion is trivial. The issue is that for a general ring `R`, there might be elliptic curves over `Spec(R)` in the sense of algebraic geometry which are not globally defined by a cubic equation valid over the entire base. ## References * [N Katz and B Mazur, *Arithmetic Moduli of Elliptic Curves*][katz_mazur] * [P Deligne, *Courbes Elliptiques: Formulaire (d'après J. Tate)*][deligne_formulaire] * [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, weierstrass equation, j invariant -/ local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow]) universe s u v w /-! ## Weierstrass curves -/ /-- A Weierstrass curve `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` with parameters `aᵢ`. -/ @[ext] structure WeierstrassCurve (R : Type u) where /-- The `a₁` coefficient of a Weierstrass curve. -/ a₁ : R /-- The `a₂` coefficient of a Weierstrass curve. -/ a₂ : R /-- The `a₃` coefficient of a Weierstrass curve. -/ a₃ : R /-- The `a₄` coefficient of a Weierstrass curve. -/ a₄ : R /-- The `a₆` coefficient of a Weierstrass curve. -/ a₆ : R namespace WeierstrassCurve instance {R : Type u} [Inhabited R] : Inhabited <| WeierstrassCurve R := ⟨⟨default, default, default, default, default⟩⟩ variable {R : Type u} [CommRing R] (W : WeierstrassCurve R) section Quantity /-! ### Standard quantities -/ /-- The `b₂` coefficient of a Weierstrass curve. -/ def b₂ : R := W.a₁ ^ 2 + 4 * W.a₂ /-- The `b₄` coefficient of a Weierstrass curve. -/ def b₄ : R := 2 * W.a₄ + W.a₁ * W.a₃ /-- The `b₆` coefficient of a Weierstrass curve. -/ def b₆ : R := W.a₃ ^ 2 + 4 * W.a₆ /-- The `b₈` coefficient of a Weierstrass curve. -/ def b₈ : R := W.a₁ ^ 2 * W.a₆ + 4 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 lemma b_relation : 4 * W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by simp only [b₂, b₄, b₆, b₈] ring1 /-- The `c₄` coefficient of a Weierstrass curve. -/ def c₄ : R := W.b₂ ^ 2 - 24 * W.b₄ /-- The `c₆` coefficient of a Weierstrass curve. -/ def c₆ : R := -W.b₂ ^ 3 + 36 * W.b₂ * W.b₄ - 216 * W.b₆ /-- The discriminant `Δ` of a Weierstrass curve. If `R` is a field, then this polynomial vanishes if and only if the cubic curve cut out by this equation is singular. Sometimes only defined up to sign in the literature; we choose the sign used by the LMFDB. For more discussion, see [the LMFDB page on discriminants](https://www.lmfdb.org/knowledge/show/ec.discriminant). -/ def Δ : R := -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 - 27 * W.b₆ ^ 2 + 9 * W.b₂ * W.b₄ * W.b₆ lemma c_relation : 1728 * W.Δ = W.c₄ ^ 3 - W.c₆ ^ 2 := by simp only [b₂, b₄, b₆, b₈, c₄, c₆, Δ] ring1 section CharTwo variable [CharP R 2] lemma b₂_of_char_two : W.b₂ = W.a₁ ^ 2 := by rw [b₂] linear_combination 2 * W.a₂ * CharP.cast_eq_zero R 2 lemma b₄_of_char_two : W.b₄ = W.a₁ * W.a₃ := by rw [b₄] linear_combination W.a₄ * CharP.cast_eq_zero R 2 lemma b₆_of_char_two : W.b₆ = W.a₃ ^ 2 := by rw [b₆] linear_combination 2 * W.a₆ * CharP.cast_eq_zero R 2 lemma b₈_of_char_two : W.b₈ = W.a₁ ^ 2 * W.a₆ + W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 + W.a₄ ^ 2 := by rw [b₈] linear_combination (2 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ - W.a₄ ^ 2) * CharP.cast_eq_zero R 2 lemma c₄_of_char_two : W.c₄ = W.a₁ ^ 4 := by rw [c₄, b₂_of_char_two] linear_combination -12 * W.b₄ * CharP.cast_eq_zero R 2 lemma c₆_of_char_two : W.c₆ = W.a₁ ^ 6 := by rw [c₆, b₂_of_char_two] linear_combination (18 * W.a₁ ^ 2 * W.b₄ - 108 * W.b₆ - W.a₁ ^ 6) * CharP.cast_eq_zero R 2 lemma Δ_of_char_two : W.Δ = W.a₁ ^ 4 * W.b₈ + W.a₃ ^ 4 + W.a₁ ^ 3 * W.a₃ ^ 3 := by rw [Δ, b₂_of_char_two, b₄_of_char_two, b₆_of_char_two] linear_combination (-W.a₁ ^ 4 * W.b₈ - 14 * W.a₃ ^ 4) * CharP.cast_eq_zero R 2 lemma b_relation_of_char_two : W.b₂ * W.b₆ = W.b₄ ^ 2 := by linear_combination -W.b_relation + 2 * W.b₈ * CharP.cast_eq_zero R 2 lemma c_relation_of_char_two : W.c₄ ^ 3 = W.c₆ ^ 2 := by linear_combination -W.c_relation + 864 * W.Δ * CharP.cast_eq_zero R 2 end CharTwo section CharThree variable [CharP R 3] lemma b₂_of_char_three : W.b₂ = W.a₁ ^ 2 + W.a₂ := by rw [b₂] linear_combination W.a₂ * CharP.cast_eq_zero R 3 lemma b₄_of_char_three : W.b₄ = -W.a₄ + W.a₁ * W.a₃ := by rw [b₄] linear_combination W.a₄ * CharP.cast_eq_zero R 3 lemma b₆_of_char_three : W.b₆ = W.a₃ ^ 2 + W.a₆ := by rw [b₆] linear_combination W.a₆ * CharP.cast_eq_zero R 3 lemma b₈_of_char_three : W.b₈ = W.a₁ ^ 2 * W.a₆ + W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 := by rw [b₈] linear_combination W.a₂ * W.a₆ * CharP.cast_eq_zero R 3 lemma c₄_of_char_three : W.c₄ = W.b₂ ^ 2 := by rw [c₄] linear_combination -8 * W.b₄ * CharP.cast_eq_zero R 3 lemma c₆_of_char_three : W.c₆ = -W.b₂ ^ 3 := by rw [c₆] linear_combination (12 * W.b₂ * W.b₄ - 72 * W.b₆) * CharP.cast_eq_zero R 3 lemma Δ_of_char_three : W.Δ = -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 := by rw [Δ] linear_combination (-9 * W.b₆ ^ 2 + 3 * W.b₂ * W.b₄ * W.b₆) * CharP.cast_eq_zero R 3 lemma b_relation_of_char_three : W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by linear_combination W.b_relation - W.b₈ * CharP.cast_eq_zero R 3 lemma c_relation_of_char_three : W.c₄ ^ 3 = W.c₆ ^ 2 := by linear_combination -W.c_relation + 576 * W.Δ * CharP.cast_eq_zero R 3 end CharThree end Quantity section BaseChange /-! ### Maps and base changes -/ variable {A : Type v} [CommRing A] (f : R →+* A) /-- The Weierstrass curve mapped over a ring homomorphism `f : R →+* A`. -/ @[simps] def map : WeierstrassCurve A := ⟨f W.a₁, f W.a₂, f W.a₃, f W.a₄, f W.a₆⟩ variable (A) in /-- The Weierstrass curve base changed to an algebra `A` over `R`. -/ abbrev baseChange [Algebra R A] : WeierstrassCurve A := W.map <| algebraMap R A @[simp] lemma map_b₂ : (W.map f).b₂ = f W.b₂ := by simp only [b₂, map_a₁, map_a₂] map_simp @[simp] lemma map_b₄ : (W.map f).b₄ = f W.b₄ := by simp only [b₄, map_a₁, map_a₃, map_a₄] map_simp @[simp] lemma map_b₆ : (W.map f).b₆ = f W.b₆ := by simp only [b₆, map_a₃, map_a₆] map_simp @[simp] lemma map_b₈ : (W.map f).b₈ = f W.b₈ := by simp only [b₈, map_a₁, map_a₂, map_a₃, map_a₄, map_a₆] map_simp @[simp] lemma map_c₄ : (W.map f).c₄ = f W.c₄ := by simp only [c₄, map_b₂, map_b₄] map_simp @[simp] lemma map_c₆ : (W.map f).c₆ = f W.c₆ := by simp only [c₆, map_b₂, map_b₄, map_b₆] map_simp @[simp] lemma map_Δ : (W.map f).Δ = f W.Δ := by simp only [Δ, map_b₂, map_b₄, map_b₆, map_b₈] map_simp @[simp] lemma map_id : W.map (RingHom.id R) = W := rfl lemma map_map {B : Type w} [CommRing B] (g : A →+* B) : (W.map f).map g = W.map (g.comp f) := rfl @[simp] lemma map_baseChange {S : Type s} [CommRing S] [Algebra R S] {A : Type v} [CommRing A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {B : Type w} [CommRing B] [Algebra R B] [Algebra S B] [IsScalarTower R S B] (g : A →ₐ[S] B) : (W.baseChange A).map g = W.baseChange B := congr_arg W.map <| g.comp_algebraMap_of_tower R lemma map_injective {f : R →+* A} (hf : Function.Injective f) : Function.Injective <| map (f := f) := fun _ _ h => by rcases mk.inj h with ⟨_, _, _, _, _⟩ ext <;> apply_fun _ using hf <;> assumption end BaseChange section TorsionPolynomial /-! ### 2-torsion polynomials -/ /-- A cubic polynomial whose discriminant is a multiple of the Weierstrass curve discriminant. If `W` is an elliptic curve over a field `R` of characteristic different from 2, then its roots over a splitting field of `R` are precisely the `X`-coordinates of the non-zero 2-torsion points of `W`. -/ def twoTorsionPolynomial : Cubic R := ⟨4, W.b₂, 2 * W.b₄, W.b₆⟩ lemma twoTorsionPolynomial_disc : W.twoTorsionPolynomial.disc = 16 * W.Δ := by simp only [b₂, b₄, b₆, b₈, Δ, twoTorsionPolynomial, Cubic.disc] ring1 section CharTwo variable [CharP R 2] lemma twoTorsionPolynomial_of_char_two : W.twoTorsionPolynomial = ⟨0, W.b₂, 0, W.b₆⟩ := by rw [twoTorsionPolynomial] ext <;> dsimp · linear_combination 2 * CharP.cast_eq_zero R 2 · linear_combination W.b₄ * CharP.cast_eq_zero R 2 lemma twoTorsionPolynomial_disc_of_char_two : W.twoTorsionPolynomial.disc = 0 := by linear_combination W.twoTorsionPolynomial_disc + 8 * W.Δ * CharP.cast_eq_zero R 2 end CharTwo section CharThree variable [CharP R 3] lemma twoTorsionPolynomial_of_char_three : W.twoTorsionPolynomial = ⟨1, W.b₂, -W.b₄, W.b₆⟩ := by rw [twoTorsionPolynomial] ext <;> dsimp · linear_combination CharP.cast_eq_zero R 3 · linear_combination W.b₄ * CharP.cast_eq_zero R 3 lemma twoTorsionPolynomial_disc_of_char_three : W.twoTorsionPolynomial.disc = W.Δ := by linear_combination W.twoTorsionPolynomial_disc + 5 * W.Δ * CharP.cast_eq_zero R 3 end CharThree -- TODO: change to `[IsUnit ...]` once #17458 is merged lemma twoTorsionPolynomial_disc_isUnit (hu : IsUnit (2 : R)) : IsUnit W.twoTorsionPolynomial.disc ↔ IsUnit W.Δ := by rw [twoTorsionPolynomial_disc, IsUnit.mul_iff, show (16 : R) = 2 ^ 4 by norm_num1] exact and_iff_right <| hu.pow 4 -- TODO: change to `[IsUnit ...]` once #17458 is merged -- TODO: In this case `IsUnit W.Δ` is just `W.IsElliptic`, consider removing/rephrasing this result lemma twoTorsionPolynomial_disc_ne_zero [Nontrivial R] (hu : IsUnit (2 : R)) (hΔ : IsUnit W.Δ) : W.twoTorsionPolynomial.disc ≠ 0 := ((W.twoTorsionPolynomial_disc_isUnit hu).mpr hΔ).ne_zero end TorsionPolynomial /-! ## Elliptic curves -/ -- TODO: change to `protected abbrev IsElliptic := IsUnit W.Δ` once #17458 is merged /-- `WeierstrassCurve.IsElliptic` is a typeclass which asserts that a Weierstrass curve is an elliptic curve: that its discriminant is a unit. Note that this definition is only mathematically accurate for certain rings whose Picard group has trivial 12-torsion, such as a field or a PID. -/ @[mk_iff] protected class IsElliptic : Prop where isUnit : IsUnit W.Δ variable [W.IsElliptic] lemma isUnit_Δ : IsUnit W.Δ := IsElliptic.isUnit /-- The discriminant `Δ'` of an elliptic curve over `R`, which is given as a unit in `R`. Note that to prove two equal elliptic curves have the same `Δ'`, you need to use `simp_rw`, as `rw` cannot transfer instance `WeierstrassCurve.IsElliptic` automatically. -/ noncomputable def Δ' : Rˣ := W.isUnit_Δ.unit /-- The discriminant `Δ'` of an elliptic curve is equal to the discriminant `Δ` of it as a Weierstrass curve. -/ @[simp] lemma coe_Δ' : W.Δ' = W.Δ := rfl /-- The j-invariant `j` of an elliptic curve, which is invariant under isomorphisms over `R`. Note that to prove two equal elliptic curves have the same `j`, you need to use `simp_rw`, as `rw` cannot transfer instance `WeierstrassCurve.IsElliptic` automatically. -/ noncomputable def j : R := W.Δ'⁻¹ * W.c₄ ^ 3 /-- A variant of `WeierstrassCurve.j_eq_zero_iff` without assuming a reduced ring. -/ lemma j_eq_zero_iff' : W.j = 0 ↔ W.c₄ ^ 3 = 0 := by rw [j, Units.mul_right_eq_zero] lemma j_eq_zero (h : W.c₄ = 0) : W.j = 0 := by rw [j_eq_zero_iff', h, zero_pow three_ne_zero] lemma j_eq_zero_iff [IsReduced R] : W.j = 0 ↔ W.c₄ = 0 := by rw [j_eq_zero_iff', IsReduced.pow_eq_zero_iff three_ne_zero] section CharTwo variable [CharP R 2] lemma j_of_char_two : W.j = W.Δ'⁻¹ * W.a₁ ^ 12 := by rw [j, W.c₄_of_char_two, ← pow_mul] /-- A variant of `WeierstrassCurve.j_eq_zero_iff_of_char_two` without assuming a reduced ring. -/ lemma j_eq_zero_iff_of_char_two' : W.j = 0 ↔ W.a₁ ^ 12 = 0 := by rw [j_of_char_two, Units.mul_right_eq_zero] lemma j_eq_zero_of_char_two (h : W.a₁ = 0) : W.j = 0 := by rw [j_eq_zero_iff_of_char_two', h, zero_pow (Nat.succ_ne_zero _)] lemma j_eq_zero_iff_of_char_two [IsReduced R] : W.j = 0 ↔ W.a₁ = 0 := by rw [j_eq_zero_iff_of_char_two', IsReduced.pow_eq_zero_iff (Nat.succ_ne_zero _)] end CharTwo section CharThree variable [CharP R 3] lemma j_of_char_three : W.j = W.Δ'⁻¹ * W.b₂ ^ 6 := by rw [j, W.c₄_of_char_three, ← pow_mul] /-- A variant of `WeierstrassCurve.j_eq_zero_iff_of_char_three` without assuming a reduced ring. -/ lemma j_eq_zero_iff_of_char_three' : W.j = 0 ↔ W.b₂ ^ 6 = 0 := by rw [j_of_char_three, Units.mul_right_eq_zero] lemma j_eq_zero_of_char_three (h : W.b₂ = 0) : W.j = 0 := by rw [j_eq_zero_iff_of_char_three', h, zero_pow (Nat.succ_ne_zero _)] lemma j_eq_zero_iff_of_char_three [IsReduced R] : W.j = 0 ↔ W.b₂ = 0 := by rw [j_eq_zero_iff_of_char_three', IsReduced.pow_eq_zero_iff (Nat.succ_ne_zero _)] end CharThree -- TODO: this is defeq to `twoTorsionPolynomial_disc_ne_zero` once #17458 is merged, -- TODO: consider removing/rephrasing this result lemma twoTorsionPolynomial_disc_ne_zero_of_isElliptic [Nontrivial R] (hu : IsUnit (2 : R)) : W.twoTorsionPolynomial.disc ≠ 0 := W.twoTorsionPolynomial_disc_ne_zero hu W.isUnit_Δ section BaseChange /-! ### Maps and base changes -/ variable {A : Type v} [CommRing A] (f : R →+* A) instance : (W.map f).IsElliptic := by simp only [isElliptic_iff, map_Δ, W.isUnit_Δ.map] set_option linter.docPrime false in lemma coe_map_Δ' : (W.map f).Δ' = f W.Δ' := by rw [coe_Δ', map_Δ, coe_Δ'] set_option linter.docPrime false in @[simp] lemma map_Δ' : (W.map f).Δ' = Units.map f W.Δ' := by ext exact W.coe_map_Δ' f set_option linter.docPrime false in lemma coe_inv_map_Δ' : (W.map f).Δ'⁻¹ = f ↑W.Δ'⁻¹ := by simp set_option linter.docPrime false in lemma inv_map_Δ' : (W.map f).Δ'⁻¹ = Units.map f W.Δ'⁻¹ := by simp @[simp] lemma map_j : (W.map f).j = f W.j := by rw [j, coe_inv_map_Δ', map_c₄, j, map_mul, map_pow] end BaseChange end WeierstrassCurve
Mathlib/AlgebraicGeometry/EllipticCurve/Weierstrass.lean
703
706
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, David Kurniadi Angdinata -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.CubicDiscriminant import Mathlib.RingTheory.Nilpotent.Defs import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.LinearCombination /-! # Weierstrass equations of elliptic curves This file defines the structure of an elliptic curve as a nonsingular Weierstrass curve given by a Weierstrass equation, which is mathematically accurate in many cases but also good for computation. ## Mathematical background Let `S` be a scheme. The actual category of elliptic curves over `S` is a large category, whose objects are schemes `E` equipped with a map `E → S`, a section `S → E`, and some axioms (the map is smooth and proper and the fibres are geometrically-connected one-dimensional group varieties). In the special case where `S` is the spectrum of some commutative ring `R` whose Picard group is zero (this includes all fields, all PIDs, and many other commutative rings) it can be shown (using a lot of algebro-geometric machinery) that every elliptic curve `E` is a projective plane cubic isomorphic to a Weierstrass curve given by the equation `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` for some `aᵢ` in `R`, and such that a certain quantity called the discriminant of `E` is a unit in `R`. If `R` is a field, this quantity divides the discriminant of a cubic polynomial whose roots over a splitting field of `R` are precisely the `X`-coordinates of the non-zero 2-torsion points of `E`. ## Main definitions * `WeierstrassCurve`: a Weierstrass curve over a commutative ring. * `WeierstrassCurve.Δ`: the discriminant of a Weierstrass curve. * `WeierstrassCurve.map`: the Weierstrass curve mapped over a ring homomorphism. * `WeierstrassCurve.twoTorsionPolynomial`: the 2-torsion polynomial of a Weierstrass curve. * `WeierstrassCurve.IsElliptic`: typeclass asserting that a Weierstrass curve is an elliptic curve. * `WeierstrassCurve.j`: the j-invariant of an elliptic curve. ## Main statements * `WeierstrassCurve.twoTorsionPolynomial_disc`: the discriminant of a Weierstrass curve is a constant factor of the cubic discriminant of its 2-torsion polynomial. ## Implementation notes The definition of elliptic curves in this file makes sense for all commutative rings `R`, but it only gives a type which can be beefed up to a category which is equivalent to the category of elliptic curves over the spectrum `Spec(R)` of `R` in the case that `R` has trivial Picard group `Pic(R)` or, slightly more generally, when its 12-torsion is trivial. The issue is that for a general ring `R`, there might be elliptic curves over `Spec(R)` in the sense of algebraic geometry which are not globally defined by a cubic equation valid over the entire base. ## References * [N Katz and B Mazur, *Arithmetic Moduli of Elliptic Curves*][katz_mazur] * [P Deligne, *Courbes Elliptiques: Formulaire (d'après J. Tate)*][deligne_formulaire] * [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, weierstrass equation, j invariant -/ local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow]) universe s u v w /-! ## Weierstrass curves -/ /-- A Weierstrass curve `Y² + a₁XY + a₃Y = X³ + a₂X² + a₄X + a₆` with parameters `aᵢ`. -/ @[ext] structure WeierstrassCurve (R : Type u) where /-- The `a₁` coefficient of a Weierstrass curve. -/ a₁ : R /-- The `a₂` coefficient of a Weierstrass curve. -/ a₂ : R /-- The `a₃` coefficient of a Weierstrass curve. -/ a₃ : R /-- The `a₄` coefficient of a Weierstrass curve. -/ a₄ : R /-- The `a₆` coefficient of a Weierstrass curve. -/ a₆ : R namespace WeierstrassCurve instance {R : Type u} [Inhabited R] : Inhabited <| WeierstrassCurve R := ⟨⟨default, default, default, default, default⟩⟩ variable {R : Type u} [CommRing R] (W : WeierstrassCurve R) section Quantity /-! ### Standard quantities -/ /-- The `b₂` coefficient of a Weierstrass curve. -/ def b₂ : R := W.a₁ ^ 2 + 4 * W.a₂ /-- The `b₄` coefficient of a Weierstrass curve. -/ def b₄ : R := 2 * W.a₄ + W.a₁ * W.a₃ /-- The `b₆` coefficient of a Weierstrass curve. -/ def b₆ : R := W.a₃ ^ 2 + 4 * W.a₆ /-- The `b₈` coefficient of a Weierstrass curve. -/ def b₈ : R := W.a₁ ^ 2 * W.a₆ + 4 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 lemma b_relation : 4 * W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by simp only [b₂, b₄, b₆, b₈] ring1 /-- The `c₄` coefficient of a Weierstrass curve. -/ def c₄ : R := W.b₂ ^ 2 - 24 * W.b₄ /-- The `c₆` coefficient of a Weierstrass curve. -/ def c₆ : R := -W.b₂ ^ 3 + 36 * W.b₂ * W.b₄ - 216 * W.b₆ /-- The discriminant `Δ` of a Weierstrass curve. If `R` is a field, then this polynomial vanishes if and only if the cubic curve cut out by this equation is singular. Sometimes only defined up to sign in the literature; we choose the sign used by the LMFDB. For more discussion, see [the LMFDB page on discriminants](https://www.lmfdb.org/knowledge/show/ec.discriminant). -/ def Δ : R := -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 - 27 * W.b₆ ^ 2 + 9 * W.b₂ * W.b₄ * W.b₆ lemma c_relation : 1728 * W.Δ = W.c₄ ^ 3 - W.c₆ ^ 2 := by simp only [b₂, b₄, b₆, b₈, c₄, c₆, Δ] ring1 section CharTwo variable [CharP R 2] lemma b₂_of_char_two : W.b₂ = W.a₁ ^ 2 := by rw [b₂] linear_combination 2 * W.a₂ * CharP.cast_eq_zero R 2 lemma b₄_of_char_two : W.b₄ = W.a₁ * W.a₃ := by rw [b₄] linear_combination W.a₄ * CharP.cast_eq_zero R 2 lemma b₆_of_char_two : W.b₆ = W.a₃ ^ 2 := by rw [b₆] linear_combination 2 * W.a₆ * CharP.cast_eq_zero R 2 lemma b₈_of_char_two : W.b₈ = W.a₁ ^ 2 * W.a₆ + W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 + W.a₄ ^ 2 := by rw [b₈] linear_combination (2 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ - W.a₄ ^ 2) * CharP.cast_eq_zero R 2 lemma c₄_of_char_two : W.c₄ = W.a₁ ^ 4 := by rw [c₄, b₂_of_char_two] linear_combination -12 * W.b₄ * CharP.cast_eq_zero R 2 lemma c₆_of_char_two : W.c₆ = W.a₁ ^ 6 := by rw [c₆, b₂_of_char_two] linear_combination (18 * W.a₁ ^ 2 * W.b₄ - 108 * W.b₆ - W.a₁ ^ 6) * CharP.cast_eq_zero R 2 lemma Δ_of_char_two : W.Δ = W.a₁ ^ 4 * W.b₈ + W.a₃ ^ 4 + W.a₁ ^ 3 * W.a₃ ^ 3 := by rw [Δ, b₂_of_char_two, b₄_of_char_two, b₆_of_char_two] linear_combination (-W.a₁ ^ 4 * W.b₈ - 14 * W.a₃ ^ 4) * CharP.cast_eq_zero R 2 lemma b_relation_of_char_two : W.b₂ * W.b₆ = W.b₄ ^ 2 := by linear_combination -W.b_relation + 2 * W.b₈ * CharP.cast_eq_zero R 2 lemma c_relation_of_char_two : W.c₄ ^ 3 = W.c₆ ^ 2 := by linear_combination -W.c_relation + 864 * W.Δ * CharP.cast_eq_zero R 2 end CharTwo section CharThree variable [CharP R 3] lemma b₂_of_char_three : W.b₂ = W.a₁ ^ 2 + W.a₂ := by rw [b₂] linear_combination W.a₂ * CharP.cast_eq_zero R 3 lemma b₄_of_char_three : W.b₄ = -W.a₄ + W.a₁ * W.a₃ := by rw [b₄] linear_combination W.a₄ * CharP.cast_eq_zero R 3 lemma b₆_of_char_three : W.b₆ = W.a₃ ^ 2 + W.a₆ := by rw [b₆] linear_combination W.a₆ * CharP.cast_eq_zero R 3 lemma b₈_of_char_three : W.b₈ = W.a₁ ^ 2 * W.a₆ + W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 := by rw [b₈] linear_combination W.a₂ * W.a₆ * CharP.cast_eq_zero R 3 lemma c₄_of_char_three : W.c₄ = W.b₂ ^ 2 := by rw [c₄] linear_combination -8 * W.b₄ * CharP.cast_eq_zero R 3 lemma c₆_of_char_three : W.c₆ = -W.b₂ ^ 3 := by rw [c₆] linear_combination (12 * W.b₂ * W.b₄ - 72 * W.b₆) * CharP.cast_eq_zero R 3 lemma Δ_of_char_three : W.Δ = -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 := by rw [Δ] linear_combination (-9 * W.b₆ ^ 2 + 3 * W.b₂ * W.b₄ * W.b₆) * CharP.cast_eq_zero R 3 lemma b_relation_of_char_three : W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by linear_combination W.b_relation - W.b₈ * CharP.cast_eq_zero R 3 lemma c_relation_of_char_three : W.c₄ ^ 3 = W.c₆ ^ 2 := by linear_combination -W.c_relation + 576 * W.Δ * CharP.cast_eq_zero R 3 end CharThree end Quantity section BaseChange /-! ### Maps and base changes -/ variable {A : Type v} [CommRing A] (f : R →+* A) /-- The Weierstrass curve mapped over a ring homomorphism `f : R →+* A`. -/ @[simps] def map : WeierstrassCurve A := ⟨f W.a₁, f W.a₂, f W.a₃, f W.a₄, f W.a₆⟩ variable (A) in /-- The Weierstrass curve base changed to an algebra `A` over `R`. -/ abbrev baseChange [Algebra R A] : WeierstrassCurve A := W.map <| algebraMap R A @[simp] lemma map_b₂ : (W.map f).b₂ = f W.b₂ := by simp only [b₂, map_a₁, map_a₂] map_simp @[simp] lemma map_b₄ : (W.map f).b₄ = f W.b₄ := by simp only [b₄, map_a₁, map_a₃, map_a₄] map_simp @[simp] lemma map_b₆ : (W.map f).b₆ = f W.b₆ := by simp only [b₆, map_a₃, map_a₆] map_simp @[simp] lemma map_b₈ : (W.map f).b₈ = f W.b₈ := by simp only [b₈, map_a₁, map_a₂, map_a₃, map_a₄, map_a₆] map_simp @[simp] lemma map_c₄ : (W.map f).c₄ = f W.c₄ := by simp only [c₄, map_b₂, map_b₄] map_simp @[simp] lemma map_c₆ : (W.map f).c₆ = f W.c₆ := by simp only [c₆, map_b₂, map_b₄, map_b₆] map_simp @[simp] lemma map_Δ : (W.map f).Δ = f W.Δ := by simp only [Δ, map_b₂, map_b₄, map_b₆, map_b₈] map_simp @[simp] lemma map_id : W.map (RingHom.id R) = W := rfl lemma map_map {B : Type w} [CommRing B] (g : A →+* B) : (W.map f).map g = W.map (g.comp f) := rfl @[simp] lemma map_baseChange {S : Type s} [CommRing S] [Algebra R S] {A : Type v} [CommRing A] [Algebra R A] [Algebra S A] [IsScalarTower R S A] {B : Type w} [CommRing B] [Algebra R B] [Algebra S B] [IsScalarTower R S B] (g : A →ₐ[S] B) : (W.baseChange A).map g = W.baseChange B := congr_arg W.map <| g.comp_algebraMap_of_tower R lemma map_injective {f : R →+* A} (hf : Function.Injective f) : Function.Injective <| map (f := f) := fun _ _ h => by rcases mk.inj h with ⟨_, _, _, _, _⟩ ext <;> apply_fun _ using hf <;> assumption end BaseChange section TorsionPolynomial /-! ### 2-torsion polynomials -/ /-- A cubic polynomial whose discriminant is a multiple of the Weierstrass curve discriminant. If `W` is an elliptic curve over a field `R` of characteristic different from 2, then its roots over a splitting field of `R` are precisely the `X`-coordinates of the non-zero 2-torsion points of `W`. -/ def twoTorsionPolynomial : Cubic R := ⟨4, W.b₂, 2 * W.b₄, W.b₆⟩ lemma twoTorsionPolynomial_disc : W.twoTorsionPolynomial.disc = 16 * W.Δ := by simp only [b₂, b₄, b₆, b₈, Δ, twoTorsionPolynomial, Cubic.disc] ring1 section CharTwo variable [CharP R 2] lemma twoTorsionPolynomial_of_char_two : W.twoTorsionPolynomial = ⟨0, W.b₂, 0, W.b₆⟩ := by rw [twoTorsionPolynomial] ext <;> dsimp · linear_combination 2 * CharP.cast_eq_zero R 2 · linear_combination W.b₄ * CharP.cast_eq_zero R 2 lemma twoTorsionPolynomial_disc_of_char_two : W.twoTorsionPolynomial.disc = 0 := by linear_combination W.twoTorsionPolynomial_disc + 8 * W.Δ * CharP.cast_eq_zero R 2 end CharTwo section CharThree variable [CharP R 3] lemma twoTorsionPolynomial_of_char_three : W.twoTorsionPolynomial = ⟨1, W.b₂, -W.b₄, W.b₆⟩ := by rw [twoTorsionPolynomial] ext <;> dsimp · linear_combination CharP.cast_eq_zero R 3 · linear_combination W.b₄ * CharP.cast_eq_zero R 3 lemma twoTorsionPolynomial_disc_of_char_three : W.twoTorsionPolynomial.disc = W.Δ := by linear_combination W.twoTorsionPolynomial_disc + 5 * W.Δ * CharP.cast_eq_zero R 3 end CharThree -- TODO: change to `[IsUnit ...]` once #17458 is merged lemma twoTorsionPolynomial_disc_isUnit (hu : IsUnit (2 : R)) : IsUnit W.twoTorsionPolynomial.disc ↔ IsUnit W.Δ := by rw [twoTorsionPolynomial_disc, IsUnit.mul_iff, show (16 : R) = 2 ^ 4 by norm_num1] exact and_iff_right <| hu.pow 4 -- TODO: change to `[IsUnit ...]` once #17458 is merged -- TODO: In this case `IsUnit W.Δ` is just `W.IsElliptic`, consider removing/rephrasing this result lemma twoTorsionPolynomial_disc_ne_zero [Nontrivial R] (hu : IsUnit (2 : R)) (hΔ : IsUnit W.Δ) : W.twoTorsionPolynomial.disc ≠ 0 := ((W.twoTorsionPolynomial_disc_isUnit hu).mpr hΔ).ne_zero end TorsionPolynomial /-! ## Elliptic curves -/ -- TODO: change to `protected abbrev IsElliptic := IsUnit W.Δ` once #17458 is merged /-- `WeierstrassCurve.IsElliptic` is a typeclass which asserts that a Weierstrass curve is an elliptic curve: that its discriminant is a unit. Note that this definition is only mathematically accurate for certain rings whose Picard group has trivial 12-torsion, such as a field or a PID. -/ @[mk_iff] protected class IsElliptic : Prop where isUnit : IsUnit W.Δ variable [W.IsElliptic] lemma isUnit_Δ : IsUnit W.Δ := IsElliptic.isUnit /-- The discriminant `Δ'` of an elliptic curve over `R`, which is given as a unit in `R`. Note that to prove two equal elliptic curves have the same `Δ'`, you need to use `simp_rw`, as `rw` cannot transfer instance `WeierstrassCurve.IsElliptic` automatically. -/ noncomputable def Δ' : Rˣ := W.isUnit_Δ.unit /-- The discriminant `Δ'` of an elliptic curve is equal to the discriminant `Δ` of it as a Weierstrass curve. -/ @[simp] lemma coe_Δ' : W.Δ' = W.Δ := rfl /-- The j-invariant `j` of an elliptic curve, which is invariant under isomorphisms over `R`. Note that to prove two equal elliptic curves have the same `j`, you need to use `simp_rw`, as `rw` cannot transfer instance `WeierstrassCurve.IsElliptic` automatically. -/ noncomputable def j : R := W.Δ'⁻¹ * W.c₄ ^ 3 /-- A variant of `WeierstrassCurve.j_eq_zero_iff` without assuming a reduced ring. -/ lemma j_eq_zero_iff' : W.j = 0 ↔ W.c₄ ^ 3 = 0 := by rw [j, Units.mul_right_eq_zero] lemma j_eq_zero (h : W.c₄ = 0) : W.j = 0 := by rw [j_eq_zero_iff', h, zero_pow three_ne_zero] lemma j_eq_zero_iff [IsReduced R] : W.j = 0 ↔ W.c₄ = 0 := by rw [j_eq_zero_iff', IsReduced.pow_eq_zero_iff three_ne_zero] section CharTwo variable [CharP R 2] lemma j_of_char_two : W.j = W.Δ'⁻¹ * W.a₁ ^ 12 := by rw [j, W.c₄_of_char_two, ← pow_mul] /-- A variant of `WeierstrassCurve.j_eq_zero_iff_of_char_two` without assuming a reduced ring. -/ lemma j_eq_zero_iff_of_char_two' : W.j = 0 ↔ W.a₁ ^ 12 = 0 := by rw [j_of_char_two, Units.mul_right_eq_zero] lemma j_eq_zero_of_char_two (h : W.a₁ = 0) : W.j = 0 := by rw [j_eq_zero_iff_of_char_two', h, zero_pow (Nat.succ_ne_zero _)] lemma j_eq_zero_iff_of_char_two [IsReduced R] : W.j = 0 ↔ W.a₁ = 0 := by rw [j_eq_zero_iff_of_char_two', IsReduced.pow_eq_zero_iff (Nat.succ_ne_zero _)] end CharTwo section CharThree variable [CharP R 3] lemma j_of_char_three : W.j = W.Δ'⁻¹ * W.b₂ ^ 6 := by rw [j, W.c₄_of_char_three, ← pow_mul] /-- A variant of `WeierstrassCurve.j_eq_zero_iff_of_char_three` without assuming a reduced ring. -/ lemma j_eq_zero_iff_of_char_three' : W.j = 0 ↔ W.b₂ ^ 6 = 0 := by rw [j_of_char_three, Units.mul_right_eq_zero] lemma j_eq_zero_of_char_three (h : W.b₂ = 0) : W.j = 0 := by rw [j_eq_zero_iff_of_char_three', h, zero_pow (Nat.succ_ne_zero _)] lemma j_eq_zero_iff_of_char_three [IsReduced R] : W.j = 0 ↔ W.b₂ = 0 := by rw [j_eq_zero_iff_of_char_three', IsReduced.pow_eq_zero_iff (Nat.succ_ne_zero _)] end CharThree -- TODO: this is defeq to `twoTorsionPolynomial_disc_ne_zero` once #17458 is merged, -- TODO: consider removing/rephrasing this result lemma twoTorsionPolynomial_disc_ne_zero_of_isElliptic [Nontrivial R] (hu : IsUnit (2 : R)) : W.twoTorsionPolynomial.disc ≠ 0 := W.twoTorsionPolynomial_disc_ne_zero hu W.isUnit_Δ section BaseChange /-! ### Maps and base changes -/ variable {A : Type v} [CommRing A] (f : R →+* A) instance : (W.map f).IsElliptic := by simp only [isElliptic_iff, map_Δ, W.isUnit_Δ.map] set_option linter.docPrime false in lemma coe_map_Δ' : (W.map f).Δ' = f W.Δ' := by rw [coe_Δ', map_Δ, coe_Δ'] set_option linter.docPrime false in @[simp] lemma map_Δ' : (W.map f).Δ' = Units.map f W.Δ' := by ext exact W.coe_map_Δ' f
set_option linter.docPrime false in lemma coe_inv_map_Δ' : (W.map f).Δ'⁻¹ = f ↑W.Δ'⁻¹ := by simp
Mathlib/AlgebraicGeometry/EllipticCurve/Weierstrass.lean
453
457
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Multiset.ZeroCons /-! # Basic results on multisets -/ -- No algebra should be required assert_not_exists Monoid universe v open List Subtype Nat Function variable {α : Type*} {β : Type v} {γ : Type*} namespace Multiset /-! ### `Multiset.toList` -/ section ToList /-- Produces a list of the elements in the multiset using choice. -/ noncomputable def toList (s : Multiset α) := s.out @[simp, norm_cast] theorem coe_toList (s : Multiset α) : (s.toList : Multiset α) = s := s.out_eq' @[simp] theorem toList_eq_nil {s : Multiset α} : s.toList = [] ↔ s = 0 := by rw [← coe_eq_zero, coe_toList] theorem empty_toList {s : Multiset α} : s.toList.isEmpty ↔ s = 0 := by simp @[simp] theorem toList_zero : (Multiset.toList 0 : List α) = [] := toList_eq_nil.mpr rfl @[simp] theorem mem_toList {a : α} {s : Multiset α} : a ∈ s.toList ↔ a ∈ s := by rw [← mem_coe, coe_toList] @[simp] theorem toList_eq_singleton_iff {a : α} {m : Multiset α} : m.toList = [a] ↔ m = {a} := by rw [← perm_singleton, ← coe_eq_coe, coe_toList, coe_singleton] @[simp] theorem toList_singleton (a : α) : ({a} : Multiset α).toList = [a] := Multiset.toList_eq_singleton_iff.2 rfl @[simp] theorem length_toList (s : Multiset α) : s.toList.length = card s := by rw [← coe_card, coe_toList] end ToList /-! ### Induction principles -/ /-- The strong induction principle for multisets. -/ @[elab_as_elim] def strongInductionOn {p : Multiset α → Sort*} (s : Multiset α) (ih : ∀ s, (∀ t < s, p t) → p s) : p s := (ih s) fun t _h => strongInductionOn t ih termination_by card s decreasing_by exact card_lt_card _h theorem strongInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) (H) : @strongInductionOn _ p s H = H s fun t _h => @strongInductionOn _ p t H := by rw [strongInductionOn] @[elab_as_elim] theorem case_strongInductionOn {p : Multiset α → Prop} (s : Multiset α) (h₀ : p 0) (h₁ : ∀ a s, (∀ t ≤ s, p t) → p (a ::ₘ s)) : p s := Multiset.strongInductionOn s fun s => Multiset.induction_on s (fun _ => h₀) fun _a _s _ ih => (h₁ _ _) fun _t h => ih _ <| lt_of_le_of_lt h <| lt_cons_self _ _ /-- Suppose that, given that `p t` can be defined on all supersets of `s` of cardinality less than `n`, one knows how to define `p s`. Then one can inductively define `p s` for all multisets `s` of cardinality less than `n`, starting from multisets of card `n` and iterating. This can be used either to define data, or to prove properties. -/ def strongDownwardInduction {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : card s ≤ n → p s := H s fun {t} ht _h => strongDownwardInduction H t ht termination_by n - card s decreasing_by simp_wf; have := (card_lt_card _h); omega theorem strongDownwardInduction_eq {p : Multiset α → Sort*} {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) (s : Multiset α) : strongDownwardInduction H s = H s fun ht _hst => strongDownwardInduction H _ ht := by rw [strongDownwardInduction] /-- Analogue of `strongDownwardInduction` with order of arguments swapped. -/ @[elab_as_elim] def strongDownwardInductionOn {p : Multiset α → Sort*} {n : ℕ} : ∀ s : Multiset α, (∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) → card s ≤ n → p s := fun s H => strongDownwardInduction H s theorem strongDownwardInductionOn_eq {p : Multiset α → Sort*} (s : Multiset α) {n : ℕ} (H : ∀ t₁, (∀ {t₂ : Multiset α}, card t₂ ≤ n → t₁ < t₂ → p t₂) → card t₁ ≤ n → p t₁) : s.strongDownwardInductionOn H = H s fun {t} ht _h => t.strongDownwardInductionOn H ht := by dsimp only [strongDownwardInductionOn] rw [strongDownwardInduction] section Choose variable (p : α → Prop) [DecidablePred p] (l : Multiset α) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `chooseX p l hp` returns that `a` together with proofs of `a ∈ l` and `p a`. -/ def chooseX : ∀ _hp : ∃! a, a ∈ l ∧ p a, { a // a ∈ l ∧ p a } := Quotient.recOn l (fun l' ex_unique => List.chooseX p l' (ExistsUnique.exists ex_unique)) (by intros a b _ funext hp suffices all_equal : ∀ x y : { t // t ∈ b ∧ p t }, x = y by apply all_equal rintro ⟨x, px⟩ ⟨y, py⟩ rcases hp with ⟨z, ⟨_z_mem_l, _pz⟩, z_unique⟩ congr calc x = z := z_unique x px _ = y := (z_unique y py).symm ) /-- Given a proof `hp` that there exists a unique `a ∈ l` such that `p a`, `choose p l hp` returns that `a`. -/ def choose (hp : ∃! a, a ∈ l ∧ p a) : α := chooseX p l hp theorem choose_spec (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃! a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃! a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose variable (α) in /-- The equivalence between lists and multisets of a subsingleton type. -/ def subsingletonEquiv [Subsingleton α] : List α ≃ Multiset α where toFun := ofList invFun := (Quot.lift id) fun (a b : List α) (h : a ~ b) => (List.ext_get h.length_eq) fun _ _ _ => Subsingleton.elim _ _ left_inv _ := rfl right_inv m := Quot.inductionOn m fun _ => rfl @[simp] theorem coe_subsingletonEquiv [Subsingleton α] : (subsingletonEquiv α : List α → Multiset α) = ofList := rfl section SizeOf set_option linter.deprecated false in @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {s : Multiset α} (hx : x ∈ s) : SizeOf.sizeOf x < SizeOf.sizeOf s := by induction s using Quot.inductionOn exact List.sizeOf_lt_sizeOf_of_mem hx end SizeOf end Multiset
Mathlib/Data/Multiset/Basic.lean
2,874
2,876
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.Equalizers import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Mono import Mathlib.CategoryTheory.Limits.Shapes.StrongEpi import Mathlib.CategoryTheory.MorphismProperty.Factorization /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `MonoFactorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `IsImage F` means that a given mono factorisation `F` has the universal property of the image. * `HasImage f` means that there is some image factorization for the morphism `f : X ⟶ Y`. * In this case, `image f` is some image object (selected with choice), `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factorThruImage f : X ⟶ image f` is the morphism `e`. * `HasImages C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `Arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `HasImageMap sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `HasImages`, then `HasImageMaps` means that every commutative square admits an image map. * If a category `HasImages`, then `HasStrongEpiImages` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable section universe v u open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure MonoFactorisation (f : X ⟶ Y) where I : C -- Porting note: violates naming conventions but can't think a better replacement m : I ⟶ Y [m_mono : Mono m] e : X ⟶ I fac : e ≫ m = f := by aesop_cat attribute [inherit_doc MonoFactorisation] MonoFactorisation.I MonoFactorisation.m MonoFactorisation.m_mono MonoFactorisation.e MonoFactorisation.fac attribute [reassoc (attr := simp)] MonoFactorisation.fac attribute [instance] MonoFactorisation.m_mono namespace MonoFactorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [Mono f] : MonoFactorisation f where I := X m := f e := 𝟙 X -- I'm not sure we really need this, but the linter says that an inhabited instance -- ought to exist... instance [Mono f] : Inhabited (MonoFactorisation f) := ⟨self f⟩ variable {f} /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext (iff := false)] theorem ext {F F' : MonoFactorisation f} (hI : F.I = F'.I) (hm : F.m = eqToHom hI ≫ F'.m) : F = F' := by obtain ⟨_, Fm, _, Ffac⟩ := F; obtain ⟨_, Fm', _, Ffac'⟩ := F' cases hI simp? at hm says simp only [eqToHom_refl, Category.id_comp] at hm congr apply (cancel_mono Fm).1 rw [Ffac, hm, Ffac'] /-- Any mono factorisation of `f` gives a mono factorisation of `f ≫ g` when `g` is a mono. -/ @[simps] def compMono (F : MonoFactorisation f) {Y' : C} (g : Y ⟶ Y') [Mono g] : MonoFactorisation (f ≫ g) where I := F.I m := F.m ≫ g m_mono := mono_comp _ _ e := F.e /-- A mono factorisation of `f ≫ g`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofCompIso {Y' : C} {g : Y ⟶ Y'} [IsIso g] (F : MonoFactorisation (f ≫ g)) : MonoFactorisation f where I := F.I m := F.m ≫ inv g m_mono := mono_comp _ _ e := F.e /-- Any mono factorisation of `f` gives a mono factorisation of `g ≫ f`. -/ @[simps] def isoComp (F : MonoFactorisation f) {X' : C} (g : X' ⟶ X) : MonoFactorisation (g ≫ f) where I := F.I m := F.m e := g ≫ F.e /-- A mono factorisation of `g ≫ f`, where `g` is an isomorphism, gives a mono factorisation of `f`. -/ @[simps] def ofIsoComp {X' : C} (g : X' ⟶ X) [IsIso g] (F : MonoFactorisation (g ≫ f)) : MonoFactorisation f where I := F.I m := F.m e := inv g ≫ F.e /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` gives a mono factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : MonoFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : MonoFactorisation g.hom where I := F.I m := F.m ≫ sq.right e := inv sq.left ≫ F.e m_mono := mono_comp _ _ fac := by simp only [fac_assoc, Arrow.w, IsIso.inv_comp_eq, Category.assoc] end MonoFactorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure IsImage (F : MonoFactorisation f) where lift : ∀ F' : MonoFactorisation f, F.I ⟶ F'.I lift_fac : ∀ F' : MonoFactorisation f, lift F' ≫ F'.m = F.m := by aesop_cat attribute [inherit_doc IsImage] IsImage.lift IsImage.lift_fac attribute [reassoc (attr := simp)] IsImage.lift_fac namespace IsImage @[reassoc (attr := simp)] theorem fac_lift {F : MonoFactorisation f} (hF : IsImage F) (F' : MonoFactorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 <| by simp variable (f) /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [Mono f] : IsImage (MonoFactorisation.self f) where lift F' := F'.e instance [Mono f] : Inhabited (IsImage (MonoFactorisation.self f)) := ⟨self f⟩ variable {f} -- TODO this is another good candidate for a future `UniqueUpToCanonicalIso`. /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ @[simps] def isoExt {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') : F.I ≅ F'.I where hom := hF.lift F' inv := hF'.lift F hom_inv_id := (cancel_mono F.m).1 (by simp) inv_hom_id := (cancel_mono F'.m).1 (by simp) variable {F F' : MonoFactorisation f} (hF : IsImage F) (hF' : IsImage F') theorem isoExt_hom_m : (isoExt hF hF').hom ≫ F'.m = F.m := by simp theorem isoExt_inv_m : (isoExt hF hF').inv ≫ F.m = F'.m := by simp theorem e_isoExt_hom : F.e ≫ (isoExt hF hF').hom = F'.e := by simp theorem e_isoExt_inv : F'.e ≫ (isoExt hF hF').inv = F.e := by simp /-- If `f` and `g` are isomorphic arrows, then a mono factorisation of `f` that is an image gives a mono factorisation of `g` that is an image -/ @[simps] def ofArrowIso {f g : Arrow C} {F : MonoFactorisation f.hom} (hF : IsImage F) (sq : f ⟶ g) [IsIso sq] : IsImage (F.ofArrowIso sq) where lift F' := hF.lift (F'.ofArrowIso (inv sq)) lift_fac F' := by simpa only [MonoFactorisation.ofArrowIso_m, Arrow.inv_right, ← Category.assoc, IsIso.comp_inv_eq] using hF.lift_fac (F'.ofArrowIso (inv sq)) end IsImage variable (f) /-- Data exhibiting that a morphism `f` has an image. -/ structure ImageFactorisation (f : X ⟶ Y) where F : MonoFactorisation f -- Porting note: another violation of the naming convention isImage : IsImage F attribute [inherit_doc ImageFactorisation] ImageFactorisation.F ImageFactorisation.isImage namespace ImageFactorisation instance [Mono f] : Inhabited (ImageFactorisation f) := ⟨⟨_, IsImage.self f⟩⟩ /-- If `f` and `g` are isomorphic arrows, then an image factorisation of `f` gives an image factorisation of `g` -/ @[simps] def ofArrowIso {f g : Arrow C} (F : ImageFactorisation f.hom) (sq : f ⟶ g) [IsIso sq] : ImageFactorisation g.hom where F := F.F.ofArrowIso sq isImage := F.isImage.ofArrowIso sq end ImageFactorisation /-- `HasImage f` means that there exists an image factorisation of `f`. -/ class HasImage (f : X ⟶ Y) : Prop where mk' :: exists_image : Nonempty (ImageFactorisation f) attribute [inherit_doc HasImage] HasImage.exists_image theorem HasImage.mk {f : X ⟶ Y} (F : ImageFactorisation f) : HasImage f := ⟨Nonempty.intro F⟩ theorem HasImage.of_arrow_iso {f g : Arrow C} [h : HasImage f.hom] (sq : f ⟶ g) [IsIso sq] : HasImage g.hom := ⟨⟨h.exists_image.some.ofArrowIso sq⟩⟩ instance (priority := 100) mono_hasImage (f : X ⟶ Y) [Mono f] : HasImage f := HasImage.mk ⟨_, IsImage.self f⟩ section variable [HasImage f] /-- Some factorisation of `f` through a monomorphism (selected with choice). -/ def Image.monoFactorisation : MonoFactorisation f := (Classical.choice HasImage.exists_image).F /-- The witness of the universal property for the chosen factorisation of `f` through a monomorphism. -/ def Image.isImage : IsImage (Image.monoFactorisation f) := (Classical.choice HasImage.exists_image).isImage /-- The categorical image of a morphism. -/ def image : C := (Image.monoFactorisation f).I /-- The inclusion of the image of a morphism into the target. -/ def image.ι : image f ⟶ Y := (Image.monoFactorisation f).m @[simp] theorem image.as_ι : (Image.monoFactorisation f).m = image.ι f := rfl instance : Mono (image.ι f) := (Image.monoFactorisation f).m_mono /-- The map from the source to the image of a morphism. -/ def factorThruImage : X ⟶ image f := (Image.monoFactorisation f).e /-- Rewrite in terms of the `factorThruImage` interface. -/ @[simp] theorem as_factorThruImage : (Image.monoFactorisation f).e = factorThruImage f := rfl @[reassoc (attr := simp)] theorem image.fac : factorThruImage f ≫ image.ι f = f := (Image.monoFactorisation f).fac variable {f} /-- Any other factorisation of the morphism `f` through a monomorphism receives a map from the image. -/ def image.lift (F' : MonoFactorisation f) : image f ⟶ F'.I := (Image.isImage f).lift F' @[reassoc (attr := simp)] theorem image.lift_fac (F' : MonoFactorisation f) : image.lift F' ≫ F'.m = image.ι f := (Image.isImage f).lift_fac F' @[reassoc (attr := simp)] theorem image.fac_lift (F' : MonoFactorisation f) : factorThruImage f ≫ image.lift F' = F'.e := (Image.isImage f).fac_lift F' @[simp] theorem image.isImage_lift (F : MonoFactorisation f) : (Image.isImage f).lift F = image.lift F := rfl @[reassoc (attr := simp)] theorem IsImage.lift_ι {F : MonoFactorisation f} (hF : IsImage F) : hF.lift (Image.monoFactorisation f) ≫ image.ι f = F.m := hF.lift_fac _ -- TODO we could put a category structure on `MonoFactorisation f`, -- with the morphisms being `g : I ⟶ I'` commuting with the `m`s -- (they then automatically commute with the `e`s) -- and show that an `imageOf f` gives an initial object there -- (uniqueness of the lift comes for free). instance image.lift_mono (F' : MonoFactorisation f) : Mono (image.lift F') := by refine @mono_of_mono _ _ _ _ _ _ F'.m ?_ simpa using MonoFactorisation.m_mono _ theorem HasImage.uniq (F' : MonoFactorisation f) (l : image f ⟶ F'.I) (w : l ≫ F'.m = image.ι f) : l = image.lift F' := (cancel_mono F'.m).1 (by simp [w]) /-- If `has_image g`, then `has_image (f ≫ g)` when `f` is an isomorphism. -/ instance {X Y Z : C} (f : X ⟶ Y) [IsIso f] (g : Y ⟶ Z) [HasImage g] : HasImage (f ≫ g) where exists_image := ⟨{ F := { I := image g m := image.ι g e := f ≫ factorThruImage g } isImage := { lift := fun F' => image.lift { I := F'.I m := F'.m e := inv f ≫ F'.e } } }⟩ end section variable (C) /-- `HasImages` asserts that every morphism has an image. -/ class HasImages : Prop where has_image : ∀ {X Y : C} (f : X ⟶ Y), HasImage f attribute [inherit_doc HasImages] HasImages.has_image attribute [instance 100] HasImages.has_image end section /-- The image of a monomorphism is isomorphic to the source. -/ def imageMonoIsoSource [Mono f] : image f ≅ X := IsImage.isoExt (Image.isImage f) (IsImage.self f) @[reassoc (attr := simp)] theorem imageMonoIsoSource_inv_ι [Mono f] : (imageMonoIsoSource f).inv ≫ image.ι f = f := by simp [imageMonoIsoSource] @[reassoc (attr := simp)] theorem imageMonoIsoSource_hom_self [Mono f] : (imageMonoIsoSource f).hom ≫ f = image.ι f := by simp only [← imageMonoIsoSource_inv_ι f] rw [← Category.assoc, Iso.hom_inv_id, Category.id_comp] -- This is the proof that `factorThruImage f` is an epimorphism -- from https://en.wikipedia.org/wiki/Image_%28category_theory%29, which is in turn taken from: -- Mitchell, Barry (1965), Theory of categories, MR 0202787, p.12, Proposition 10.1 @[ext (iff := false)] theorem image.ext [HasImage f] {W : C} {g h : image f ⟶ W} [HasLimit (parallelPair g h)] (w : factorThruImage f ≫ g = factorThruImage f ≫ h) : g = h := by let q := equalizer.ι g h let e' := equalizer.lift _ w let F' : MonoFactorisation f := { I := equalizer g h m := q ≫ image.ι f m_mono := mono_comp _ _ e := e' } let v := image.lift F' have t₀ : v ≫ q ≫ image.ι f = image.ι f := image.lift_fac F' have t : v ≫ q = 𝟙 (image f) := (cancel_mono_id (image.ι f)).1 (by convert t₀ using 1 rw [Category.assoc]) -- The proof from wikipedia next proves `q ≫ v = 𝟙 _`, -- and concludes that `equalizer g h ≅ image f`, -- but this isn't necessary. calc g = 𝟙 (image f) ≫ g := by rw [Category.id_comp] _ = v ≫ q ≫ g := by rw [← t, Category.assoc] _ = v ≫ q ≫ h := by rw [equalizer.condition g h] _ = 𝟙 (image f) ≫ h := by rw [← Category.assoc, t] _ = h := by rw [Category.id_comp] instance [HasImage f] [∀ {Z : C} (g h : image f ⟶ Z), HasLimit (parallelPair g h)] : Epi (factorThruImage f) := ⟨fun _ _ w => image.ext f w⟩ theorem epi_image_of_epi {X Y : C} (f : X ⟶ Y) [HasImage f] [E : Epi f] : Epi (image.ι f) := by rw [← image.fac f] at E exact epi_of_epi (factorThruImage f) (image.ι f) theorem epi_of_epi_image {X Y : C} (f : X ⟶ Y) [HasImage f] [Epi (image.ι f)] [Epi (factorThruImage f)] : Epi f := by rw [← image.fac f] apply epi_comp end section variable {f} variable {f' : X ⟶ Y} [HasImage f] [HasImage f'] /-- An equation between morphisms gives a comparison map between the images (which momentarily we prove is an iso). -/ def image.eqToHom (h : f = f') : image f ⟶ image f' := image.lift { I := image f' m := image.ι f' e := factorThruImage f' fac := by rw [h]; simp only [image.fac]} instance (h : f = f') : IsIso (image.eqToHom h) := ⟨⟨image.eqToHom h.symm, ⟨(cancel_mono (image.ι f)).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by aesop_cat)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by aesop_cat)⟩ rw [image.lift_fac F'] ), (cancel_mono (image.ι f')).1 (by -- Porting note: added let's for used to be a simp [image.eqToHom] let F' : MonoFactorisation f := ⟨image f', image.ι f', factorThruImage f', (by aesop_cat)⟩ dsimp [image.eqToHom] rw [Category.id_comp,Category.assoc,image.lift_fac F'] let F : MonoFactorisation f' := ⟨image f, image.ι f, factorThruImage f, (by aesop_cat)⟩ rw [image.lift_fac F])⟩⟩⟩ /-- An equation between morphisms gives an isomorphism between the images. -/ def image.eqToIso (h : f = f') : image f ≅ image f' := asIso (image.eqToHom h) /-- As long as the category has equalizers, the image inclusion maps commute with `image.eqToIso`. -/ theorem image.eq_fac [HasEqualizers C] (h : f = f') : image.ι f = (image.eqToIso h).hom ≫ image.ι f' := by apply image.ext dsimp [asIso,image.eqToIso, image.eqToHom] rw [image.lift_fac] -- Porting note: simp did not fire with this it seems end section variable {Z : C} (g : Y ⟶ Z) /-- The comparison map `image (f ≫ g) ⟶ image g`. -/ def image.preComp [HasImage g] [HasImage (f ≫ g)] : image (f ≫ g) ⟶ image g := image.lift { I := image g m := image.ι g e := f ≫ factorThruImage g } @[reassoc (attr := simp)] theorem image.preComp_ι [HasImage g] [HasImage (f ≫ g)] : image.preComp f g ≫ image.ι g = image.ι (f ≫ g) := by dsimp [image.preComp] rw [image.lift_fac] -- Porting note: also here, see image.eq_fac @[reassoc (attr := simp)] theorem image.factorThruImage_preComp [HasImage g] [HasImage (f ≫ g)] : factorThruImage (f ≫ g) ≫ image.preComp f g = f ≫ factorThruImage g := by simp [image.preComp] /-- `image.preComp f g` is a monomorphism. -/ instance image.preComp_mono [HasImage g] [HasImage (f ≫ g)] : Mono (image.preComp f g) := by refine @mono_of_mono _ _ _ _ _ _ (image.ι g) ?_ simp only [image.preComp_ι] infer_instance /-- The two step comparison map `image (f ≫ (g ≫ h)) ⟶ image (g ≫ h) ⟶ image h` agrees with the one step comparison map `image (f ≫ (g ≫ h)) ≅ image ((f ≫ g) ≫ h) ⟶ image h`. -/ theorem image.preComp_comp {W : C} (h : Z ⟶ W) [HasImage (g ≫ h)] [HasImage (f ≫ g ≫ h)] [HasImage h] [HasImage ((f ≫ g) ≫ h)] : image.preComp f (g ≫ h) ≫ image.preComp g h = image.eqToHom (Category.assoc f g h).symm ≫ image.preComp (f ≫ g) h := by apply (cancel_mono (image.ι h)).1 dsimp [image.preComp, image.eqToHom] repeat (rw [Category.assoc,image.lift_fac]) rw [image.lift_fac,image.lift_fac] variable [HasEqualizers C] /-- `image.preComp f g` is an epimorphism when `f` is an epimorphism (we need `C` to have equalizers to prove this). -/ instance image.preComp_epi_of_epi [HasImage g] [HasImage (f ≫ g)] [Epi f] : Epi (image.preComp f g) := by apply @epi_of_epi_fac _ _ _ _ _ _ _ _ ?_ (image.factorThruImage_preComp _ _) exact epi_comp _ _ instance hasImage_iso_comp [IsIso f] [HasImage g] : HasImage (f ≫ g) := HasImage.mk { F := (Image.monoFactorisation g).isoComp f isImage := { lift := fun F' => image.lift (F'.ofIsoComp f) lift_fac := fun F' => by dsimp have : (MonoFactorisation.ofIsoComp f F').m = F'.m := rfl rw [← this,image.lift_fac (MonoFactorisation.ofIsoComp f F')] } } /-- `image.preComp f g` is an isomorphism when `f` is an isomorphism (we need `C` to have equalizers to prove this). -/ instance image.isIso_precomp_iso (f : X ⟶ Y) [IsIso f] [HasImage g] : IsIso (image.preComp f g) := ⟨⟨image.lift { I := image (f ≫ g) m := image.ι (f ≫ g) e := inv f ≫ factorThruImage (f ≫ g) }, ⟨by ext simp [image.preComp], by ext simp [image.preComp]⟩⟩⟩
-- Note that in general we don't have the other comparison map you might expect -- `image f ⟶ image (f ≫ g)`.
Mathlib/CategoryTheory/Limits/Shapes/Images.lean
552
553
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Neil Strickland -/ import Mathlib.Data.Nat.Prime.Defs import Mathlib.Data.PNat.Basic /-! # Primality and GCD on pnat This file extends the theory of `ℕ+` with `gcd`, `lcm` and `Prime` functions, analogous to those on `Nat`. -/ namespace Nat.Primes /-- The canonical map from `Nat.Primes` to `ℕ+` -/ @[coe] def toPNat : Nat.Primes → ℕ+ := fun p => ⟨(p : ℕ), p.property.pos⟩ instance coePNat : Coe Nat.Primes ℕ+ := ⟨toPNat⟩ @[norm_cast] theorem coe_pnat_nat (p : Nat.Primes) : ((p : ℕ+) : ℕ) = p := rfl theorem coe_pnat_injective : Function.Injective ((↑) : Nat.Primes → ℕ+) := fun p q h => Subtype.ext (by injection h) @[norm_cast] theorem coe_pnat_inj (p q : Nat.Primes) : (p : ℕ+) = (q : ℕ+) ↔ p = q := coe_pnat_injective.eq_iff end Nat.Primes namespace PNat open Nat /-- The greatest common divisor (gcd) of two positive natural numbers, viewed as positive natural number. -/ def gcd (n m : ℕ+) : ℕ+ := ⟨Nat.gcd (n : ℕ) (m : ℕ), Nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩ /-- The least common multiple (lcm) of two positive natural numbers, viewed as positive natural number. -/ def lcm (n m : ℕ+) : ℕ+ := ⟨Nat.lcm (n : ℕ) (m : ℕ), by let h := mul_pos n.pos m.pos rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : ℕ) (m : ℕ)) rfl) h⟩ @[simp, norm_cast] theorem gcd_coe (n m : ℕ+) : (gcd n m : ℕ) = Nat.gcd n m := rfl @[simp, norm_cast] theorem lcm_coe (n m : ℕ+) : (lcm n m : ℕ) = Nat.lcm n m := rfl theorem gcd_dvd_left (n m : ℕ+) : gcd n m ∣ n := dvd_iff.2 (Nat.gcd_dvd_left (n : ℕ) (m : ℕ)) theorem gcd_dvd_right (n m : ℕ+) : gcd n m ∣ m := dvd_iff.2 (Nat.gcd_dvd_right (n : ℕ) (m : ℕ)) theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n := dvd_iff.2 (Nat.dvd_gcd (dvd_iff.1 hm) (dvd_iff.1 hn)) theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m := dvd_iff.2 (Nat.dvd_lcm_left (n : ℕ) (m : ℕ)) theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m := dvd_iff.2 (Nat.dvd_lcm_right (n : ℕ) (m : ℕ)) theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k := dvd_iff.2 (@Nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) (dvd_iff.1 hm) (dvd_iff.1 hn)) theorem gcd_mul_lcm (n m : ℕ+) : gcd n m * lcm n m = n * m := Subtype.eq (Nat.gcd_mul_lcm (n : ℕ) (m : ℕ)) theorem eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 := by intro h; apply le_antisymm; swap · apply PNat.one_le · exact PNat.lt_add_one_iff.1 h section Prime /-! ### Prime numbers -/ /-- Primality predicate for `ℕ+`, defined in terms of `Nat.Prime`. -/ def Prime (p : ℕ+) : Prop := (p : ℕ).Prime theorem Prime.one_lt {p : ℕ+} : p.Prime → 1 < p := Nat.Prime.one_lt theorem prime_two : (2 : ℕ+).Prime := Nat.prime_two instance {p : ℕ+} [h : Fact p.Prime] : Fact (p : ℕ).Prime := h instance fact_prime_two : Fact (2 : ℕ+).Prime := ⟨prime_two⟩ theorem prime_three : (3 : ℕ+).Prime := Nat.prime_three instance fact_prime_three : Fact (3 : ℕ+).Prime := ⟨prime_three⟩ theorem prime_five : (5 : ℕ+).Prime := Nat.prime_five instance fact_prime_five : Fact (5 : ℕ+).Prime := ⟨prime_five⟩ theorem dvd_prime {p m : ℕ+} (pp : p.Prime) : m ∣ p ↔ m = 1 ∨ m = p := by rw [PNat.dvd_iff] rw [Nat.dvd_prime pp] simp theorem Prime.ne_one {p : ℕ+} : p.Prime → p ≠ 1 := by intro pp intro contra apply Nat.Prime.ne_one pp rw [PNat.coe_eq_one_iff] apply contra @[simp] theorem not_prime_one : ¬(1 : ℕ+).Prime := Nat.not_prime_one theorem Prime.not_dvd_one {p : ℕ+} : p.Prime → ¬p ∣ 1 := fun pp : p.Prime => by rw [dvd_iff] apply Nat.Prime.not_dvd_one pp theorem exists_prime_and_dvd {n : ℕ+} (hn : n ≠ 1) : ∃ p : ℕ+, p.Prime ∧ p ∣ n := by obtain ⟨p, hp⟩ := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn) exists (⟨p, Nat.Prime.pos hp.left⟩ : ℕ+); rw [dvd_iff]; apply hp end Prime section Coprime /-! ### Coprime numbers and gcd -/ /-- Two pnats are coprime if their gcd is 1. -/ def Coprime (m n : ℕ+) : Prop := m.gcd n = 1 @[simp, norm_cast] theorem coprime_coe {m n : ℕ+} : Nat.Coprime ↑m ↑n ↔ m.Coprime n := by unfold Nat.Coprime Coprime rw [← coe_inj] simp theorem Coprime.mul {k m n : ℕ+} : m.Coprime k → n.Coprime k → (m * n).Coprime k := by repeat rw [← coprime_coe] rw [mul_coe] apply Nat.Coprime.mul theorem Coprime.mul_right {k m n : ℕ+} : k.Coprime m → k.Coprime n → k.Coprime (m * n) := by repeat rw [← coprime_coe] rw [mul_coe] apply Nat.Coprime.mul_right theorem gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m := by apply eq simp only [gcd_coe] apply Nat.gcd_comm theorem gcd_eq_left_iff_dvd {m n : ℕ+} : m.gcd n = m ↔ m ∣ n := by rw [dvd_iff, ← Nat.gcd_eq_left_iff_dvd, ← coe_inj] simp theorem gcd_eq_right_iff_dvd {m n : ℕ+} : n.gcd m = m ↔ m ∣ n := by rw [gcd_comm] apply gcd_eq_left_iff_dvd theorem Coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} : k.Coprime n → (k * m).gcd n = m.gcd n := by intro h; apply eq; simp only [gcd_coe, mul_coe] apply Nat.Coprime.gcd_mul_left_cancel; simpa theorem Coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} : k.Coprime n → (m * k).gcd n = m.gcd n := by rw [mul_comm]; apply Coprime.gcd_mul_left_cancel theorem Coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} : k.Coprime m → m.gcd (k * n) = m.gcd n := by intro h; iterate 2 rw [gcd_comm]; symm apply Coprime.gcd_mul_left_cancel _ h theorem Coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} : k.Coprime m → m.gcd (n * k) = m.gcd n := by rw [mul_comm] apply Coprime.gcd_mul_left_cancel_right @[simp] theorem one_gcd {n : ℕ+} : gcd 1 n = 1 := by rw [gcd_eq_left_iff_dvd] apply one_dvd @[simp] theorem gcd_one {n : ℕ+} : gcd n 1 = 1 := by rw [gcd_comm] apply one_gcd @[symm] theorem Coprime.symm {m n : ℕ+} : m.Coprime n → n.Coprime m := by unfold Coprime rw [gcd_comm] simp @[simp] theorem one_coprime {n : ℕ+} : (1 : ℕ+).Coprime n := one_gcd @[simp] theorem coprime_one {n : ℕ+} : n.Coprime 1 := Coprime.symm one_coprime theorem Coprime.coprime_dvd_left {m k n : ℕ+} : m ∣ k → k.Coprime n → m.Coprime n := by rw [dvd_iff] repeat rw [← coprime_coe] apply Nat.Coprime.coprime_dvd_left theorem Coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = (a * b).gcd m := by rw [← gcd_eq_left_iff_dvd] at am conv_lhs => rw [← am] rw [eq_comm] apply Coprime.gcd_mul_right_cancel a apply Coprime.coprime_dvd_left bn cop.symm theorem Coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = (b * a).gcd m := by rw [mul_comm]; apply Coprime.factor_eq_gcd_left cop am bn theorem Coprime.factor_eq_gcd_left_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (a * b) := by rw [gcd_comm]; apply Coprime.factor_eq_gcd_left cop am bn theorem Coprime.factor_eq_gcd_right_right {a b m n : ℕ+} (cop : m.Coprime n) (am : a ∣ m) (bn : b ∣ n) : a = m.gcd (b * a) := by rw [gcd_comm] apply Coprime.factor_eq_gcd_right cop am bn theorem Coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h : m.Coprime n) : k.gcd (m * n) = k.gcd m * k.gcd n := by rw [← coprime_coe] at h; apply eq simp only [gcd_coe, mul_coe]; apply Nat.Coprime.gcd_mul k h theorem gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m := by rw [dvd_iff] intro h apply eq simp only [gcd_coe] apply Nat.gcd_eq_left h theorem Coprime.pow {m n : ℕ+} (k l : ℕ) (h : m.Coprime n) : (m ^ k : ℕ).Coprime (n ^ l) := by rw [← coprime_coe] at *; apply Nat.Coprime.pow; apply h end Coprime end PNat
Mathlib/Data/PNat/Prime.lean
316
317
/- 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.ModelTheory.Ultraproducts import Mathlib.ModelTheory.Bundled import Mathlib.ModelTheory.Skolem import Mathlib.Order.Filter.AtTopBot.Basic /-! # First-Order Satisfiability This file deals with the satisfiability of first-order theories, as well as equivalence over them. ## Main Definitions - `FirstOrder.Language.Theory.IsSatisfiable`: `T.IsSatisfiable` indicates that `T` has a nonempty model. - `FirstOrder.Language.Theory.IsFinitelySatisfiable`: `T.IsFinitelySatisfiable` indicates that every finite subset of `T` is satisfiable. - `FirstOrder.Language.Theory.IsComplete`: `T.IsComplete` indicates that `T` is satisfiable and models each sentence or its negation. - `Cardinal.Categorical`: A theory is `κ`-categorical if all models of size `κ` are isomorphic. ## Main Results - The Compactness Theorem, `FirstOrder.Language.Theory.isSatisfiable_iff_isFinitelySatisfiable`, shows that a theory is satisfiable iff it is finitely satisfiable. - `FirstOrder.Language.completeTheory.isComplete`: The complete theory of a structure is complete. - `FirstOrder.Language.Theory.exists_large_model_of_infinite_model` shows that any theory with an infinite model has arbitrarily large models. - `FirstOrder.Language.Theory.exists_elementaryEmbedding_card_eq`: The Upward Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. ## Implementation Details - Satisfiability of an `L.Theory` `T` is defined in the minimal universe containing all the symbols of `L`. By Löwenheim-Skolem, this is equivalent to satisfiability in any universe. -/ universe u v w w' open Cardinal CategoryTheory open Cardinal FirstOrder namespace FirstOrder namespace Language variable {L : Language.{u, v}} {T : L.Theory} {α : Type w} {n : ℕ} namespace Theory variable (T) /-- A theory is satisfiable if a structure models it. -/ def IsSatisfiable : Prop := Nonempty (ModelType.{u, v, max u v} T) /-- A theory is finitely satisfiable if all of its finite subtheories are satisfiable. -/ def IsFinitelySatisfiable : Prop := ∀ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T → IsSatisfiable (T0 : L.Theory) variable {T} {T' : L.Theory} theorem Model.isSatisfiable (M : Type w) [Nonempty M] [L.Structure M] [M ⊨ T] : T.IsSatisfiable := ⟨((⊥ : Substructure _ (ModelType.of T M)).elementarySkolem₁Reduct.toModel T).shrink⟩ theorem IsSatisfiable.mono (h : T'.IsSatisfiable) (hs : T ⊆ T') : T.IsSatisfiable := ⟨(Theory.Model.mono (ModelType.is_model h.some) hs).bundled⟩ theorem isSatisfiable_empty (L : Language.{u, v}) : IsSatisfiable (∅ : L.Theory) := ⟨default⟩ theorem isSatisfiable_of_isSatisfiable_onTheory {L' : Language.{w, w'}} (φ : L →ᴸ L') (h : (φ.onTheory T).IsSatisfiable) : T.IsSatisfiable := Model.isSatisfiable (h.some.reduct φ) theorem isSatisfiable_onTheory_iff {L' : Language.{w, w'}} {φ : L →ᴸ L'} (h : φ.Injective) : (φ.onTheory T).IsSatisfiable ↔ T.IsSatisfiable := by classical refine ⟨isSatisfiable_of_isSatisfiable_onTheory φ, fun h' => ?_⟩ haveI : Inhabited h'.some := Classical.inhabited_of_nonempty' exact Model.isSatisfiable (h'.some.defaultExpansion h) theorem IsSatisfiable.isFinitelySatisfiable (h : T.IsSatisfiable) : T.IsFinitelySatisfiable := fun _ => h.mono /-- The **Compactness Theorem of first-order logic**: A theory is satisfiable if and only if it is finitely satisfiable. -/ theorem isSatisfiable_iff_isFinitelySatisfiable {T : L.Theory} : T.IsSatisfiable ↔ T.IsFinitelySatisfiable := ⟨Theory.IsSatisfiable.isFinitelySatisfiable, fun h => by classical set M : Finset T → Type max u v := fun T0 : Finset T => (h (T0.map (Function.Embedding.subtype fun x => x ∈ T)) T0.map_subtype_subset).some.Carrier let M' := Filter.Product (Ultrafilter.of (Filter.atTop : Filter (Finset T))) M have h' : M' ⊨ T := by refine ⟨fun φ hφ => ?_⟩ rw [Ultraproduct.sentence_realize] refine Filter.Eventually.filter_mono (Ultrafilter.of_le _) (Filter.eventually_atTop.2 ⟨{⟨φ, hφ⟩}, fun s h' => Theory.realize_sentence_of_mem (s.map (Function.Embedding.subtype fun x => x ∈ T)) ?_⟩) simp only [Finset.coe_map, Function.Embedding.coe_subtype, Set.mem_image, Finset.mem_coe, Subtype.exists, Subtype.coe_mk, exists_and_right, exists_eq_right] exact ⟨hφ, h' (Finset.mem_singleton_self _)⟩ exact ⟨ModelType.of T M'⟩⟩ theorem isSatisfiable_directed_union_iff {ι : Type*} [Nonempty ι] {T : ι → L.Theory} (h : Directed (· ⊆ ·) T) : Theory.IsSatisfiable (⋃ i, T i) ↔ ∀ i, (T i).IsSatisfiable := by refine ⟨fun h' i => h'.mono (Set.subset_iUnion _ _), fun h' => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] intro T0 hT0 obtain ⟨i, hi⟩ := h.exists_mem_subset_of_finset_subset_biUnion hT0 exact (h' i).mono hi theorem isSatisfiable_union_distinctConstantsTheory_of_card_le (T : L.Theory) (s : Set α) (M : Type w') [Nonempty M] [L.Structure M] [M ⊨ T] (h : Cardinal.lift.{w'} #s ≤ Cardinal.lift.{w} #M) : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by haveI : Inhabited M := Classical.inhabited_of_nonempty inferInstance rw [Cardinal.lift_mk_le'] at h letI : (constantsOn α).Structure M := constantsOn.structure (Function.extend (↑) h.some default) have : M ⊨ (L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s := by refine ((LHom.onTheory_model _ _).2 inferInstance).union ?_ rw [model_distinctConstantsTheory] refine fun a as b bs ab => ?_ rw [← Subtype.coe_mk a as, ← Subtype.coe_mk b bs, ← Subtype.ext_iff] exact h.some.injective ((Subtype.coe_injective.extend_apply h.some default ⟨a, as⟩).symm.trans (ab.trans (Subtype.coe_injective.extend_apply h.some default ⟨b, bs⟩))) exact Model.isSatisfiable M theorem isSatisfiable_union_distinctConstantsTheory_of_infinite (T : L.Theory) (s : Set α) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ((L.lhomWithConstants α).onTheory T ∪ L.distinctConstantsTheory s).IsSatisfiable := by classical rw [distinctConstantsTheory_eq_iUnion, Set.union_iUnion, isSatisfiable_directed_union_iff] · exact fun t => isSatisfiable_union_distinctConstantsTheory_of_card_le T _ M ((lift_le_aleph0.2 (finset_card_lt_aleph0 _).le).trans (aleph0_le_lift.2 (aleph0_le_mk M))) · apply Monotone.directed_le refine monotone_const.union (monotone_distinctConstantsTheory.comp ?_) simp only [Finset.coe_map, Function.Embedding.coe_subtype] exact Monotone.comp (g := Set.image ((↑) : s → α)) (f := ((↑) : Finset s → Set s)) Set.monotone_image fun _ _ => Finset.coe_subset.2 /-- Any theory with an infinite model has arbitrarily large models. -/ theorem exists_large_model_of_infinite_model (T : L.Theory) (κ : Cardinal.{w}) (M : Type w') [L.Structure M] [M ⊨ T] [Infinite M] : ∃ N : ModelType.{_, _, max u v w} T, Cardinal.lift.{max u v w} κ ≤ #N := by obtain ⟨N⟩ := isSatisfiable_union_distinctConstantsTheory_of_infinite T (Set.univ : Set κ.out) M refine ⟨(N.is_model.mono Set.subset_union_left).bundled.reduct _, ?_⟩ haveI : N ⊨ distinctConstantsTheory _ _ := N.is_model.mono Set.subset_union_right rw [ModelType.reduct_Carrier, coe_of] refine _root_.trans (lift_le.2 (le_of_eq (Cardinal.mk_out κ).symm)) ?_ rw [← mk_univ] refine (card_le_of_model_distinctConstantsTheory L Set.univ N).trans (lift_le.{max u v w}.1 ?_) rw [lift_lift] theorem isSatisfiable_iUnion_iff_isSatisfiable_iUnion_finset {ι : Type*} (T : ι → L.Theory) : IsSatisfiable (⋃ i, T i) ↔ ∀ s : Finset ι, IsSatisfiable (⋃ i ∈ s, T i) := by classical refine ⟨fun h s => h.mono (Set.iUnion_mono fun _ => Set.iUnion_subset_iff.2 fun _ => refl _), fun h => ?_⟩ rw [isSatisfiable_iff_isFinitelySatisfiable] intro s hs rw [Set.iUnion_eq_iUnion_finset] at hs obtain ⟨t, ht⟩ := Directed.exists_mem_subset_of_finset_subset_biUnion (by exact Monotone.directed_le fun t1 t2 (h : ∀ ⦃x⦄, x ∈ t1 → x ∈ t2) => Set.iUnion_mono fun _ => Set.iUnion_mono' fun h1 => ⟨h h1, refl _⟩) hs exact (h t).mono ht end Theory variable (L) /-- A version of The Downward Löwenheim–Skolem theorem where the structure `N` elementarily embeds into `M`, but is not by type a substructure of `M`, and thus can be chosen to belong to the universe of the cardinal `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_le (M : Type w') [L.Structure M] [Nonempty M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h3 : lift.{w'} κ ≤ Cardinal.lift.{w} #M) : ∃ N : Bundled L.Structure, Nonempty (N ↪ₑ[L] M) ∧ #N = κ := by obtain ⟨S, _, hS⟩ := exists_elementarySubstructure_card_eq L ∅ κ h1 (by simp) h2 h3 have : Small.{w} S := by rw [← lift_inj.{_, w + 1}, lift_lift, lift_lift] at hS exact small_iff_lift_mk_lt_univ.2 (lt_of_eq_of_lt hS κ.lift_lt_univ') refine ⟨(equivShrink S).bundledInduced L, ⟨S.subtype.comp (Equiv.bundledInducedEquiv L _).symm.toElementaryEmbedding⟩, lift_inj.1 (_root_.trans ?_ hS)⟩ simp only [Equiv.bundledInduced_α, lift_mk_shrink'] section /-- The **Upward Löwenheim–Skolem Theorem**: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then `M` has an elementary extension of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq_of_ge (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (h2 : Cardinal.lift.{w} #M ≤ Cardinal.lift.{w'} κ) : ∃ N : Bundled L.Structure, Nonempty (M ↪ₑ[L] N) ∧ #N = κ := by obtain ⟨N0, hN0⟩ := (L.elementaryDiagram M).exists_large_model_of_infinite_model κ M rw [← lift_le.{max u v}, lift_lift, lift_lift] at h2 obtain ⟨N, ⟨NN0⟩, hN⟩ := exists_elementaryEmbedding_card_eq_of_le (L[[M]]) N0 κ (aleph0_le_lift.1 ((aleph0_le_lift.2 (aleph0_le_mk M)).trans h2)) (by simp only [card_withConstants, lift_add, lift_lift] rw [add_comm, add_eq_max (aleph0_le_lift.2 (infinite_iff.1 iM)), max_le_iff] rw [← lift_le.{w'}, lift_lift, lift_lift] at h1 exact ⟨h2, h1⟩) (hN0.trans (by rw [← lift_umax, lift_id])) letI := (lhomWithConstants L M).reduct N haveI h : N ⊨ L.elementaryDiagram M := (NN0.theory_model_iff (L.elementaryDiagram M)).2 inferInstance refine ⟨Bundled.of N, ⟨?_⟩, hN⟩ apply ElementaryEmbedding.ofModelsElementaryDiagram L M N end /-- The Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is an elementary embedding in the appropriate direction between then `M` and a structure of cardinality `κ`. -/ theorem exists_elementaryEmbedding_card_eq (M : Type w') [L.Structure M] [iM : Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : Bundled L.Structure, (Nonempty (N ↪ₑ[L] M) ∨ Nonempty (M ↪ₑ[L] N)) ∧ #N = κ := by cases le_or_gt (lift.{w'} κ) (Cardinal.lift.{w} #M) with | inl h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_le L M κ h1 h2 h exact ⟨N, Or.inl hN1, hN2⟩ | inr h => obtain ⟨N, hN1, hN2⟩ := exists_elementaryEmbedding_card_eq_of_ge L M κ h2 (le_of_lt h) exact ⟨N, Or.inr hN1, hN2⟩ /-- A consequence of the Löwenheim–Skolem Theorem: If `κ` is a cardinal greater than the cardinalities of `L` and an infinite `L`-structure `M`, then there is a structure of cardinality `κ` elementarily equivalent to `M`. -/ theorem exists_elementarilyEquivalent_card_eq (M : Type w') [L.Structure M] [Infinite M] (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : CategoryTheory.Bundled L.Structure, (M ≅[L] N) ∧ #N = κ := by obtain ⟨N, NM | MN, hNκ⟩ := exists_elementaryEmbedding_card_eq L M κ h1 h2 · exact ⟨N, NM.some.elementarilyEquivalent.symm, hNκ⟩ · exact ⟨N, MN.some.elementarilyEquivalent, hNκ⟩ variable {L} namespace Theory theorem exists_model_card_eq (h : ∃ M : ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w}) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) : ∃ N : ModelType.{u, v, w} T, #N = κ := by cases h with | intro M MI => haveI := MI obtain ⟨N, hN, rfl⟩ := exists_elementarilyEquivalent_card_eq L M κ h1 h2 haveI : Nonempty N := hN.nonempty exact ⟨hN.theory_model.bundled, rfl⟩ variable (T) /-- A theory models a (bounded) formula when any of its nonempty models realizes that formula on all inputs. -/ def ModelsBoundedFormula (φ : L.BoundedFormula α n) : Prop := ∀ (M : ModelType.{u, v, max u v w} T) (v : α → M) (xs : Fin n → M), φ.Realize v xs @[inherit_doc FirstOrder.Language.Theory.ModelsBoundedFormula] infixl:51 " ⊨ᵇ " => ModelsBoundedFormula -- input using \|= or \vDash, but not using \models variable {T} theorem models_formula_iff {φ : L.Formula α} : T ⊨ᵇ φ ↔ ∀ (M : ModelType.{u, v, max u v w} T) (v : α → M), φ.Realize v := forall_congr' fun _ => forall_congr' fun _ => Unique.forall_iff theorem models_sentence_iff {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∀ M : ModelType.{u, v, max u v} T, M ⊨ φ := models_formula_iff.trans (forall_congr' fun _ => Unique.forall_iff) theorem models_sentence_of_mem {φ : L.Sentence} (h : φ ∈ T) : T ⊨ᵇ φ := models_sentence_iff.2 fun _ => realize_sentence_of_mem T h theorem models_iff_not_satisfiable (φ : L.Sentence) : T ⊨ᵇ φ ↔ ¬IsSatisfiable (T ∪ {φ.not}) := by rw [models_sentence_iff, IsSatisfiable] refine ⟨fun h1 h2 => (Sentence.realize_not _).1 (realize_sentence_of_mem (T ∪ {Formula.not φ}) (Set.subset_union_right (Set.mem_singleton _))) (h1 (h2.some.subtheoryModel Set.subset_union_left)), fun h M => ?_⟩ contrapose! h rw [← Sentence.realize_not] at h refine ⟨{ Carrier := M is_model := ⟨fun ψ hψ => hψ.elim (realize_sentence_of_mem _) fun h' => ?_⟩ }⟩ rw [Set.mem_singleton_iff.1 h'] exact h theorem ModelsBoundedFormula.realize_sentence {φ : L.Sentence} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ := by rw [models_iff_not_satisfiable] at h contrapose! h have : M ⊨ T ∪ {Formula.not φ} := by simp only [Set.union_singleton, model_iff, Set.mem_insert_iff, forall_eq_or_imp, Sentence.realize_not] rw [← model_iff] exact ⟨h, inferInstance⟩ exact Model.isSatisfiable M theorem models_formula_iff_onTheory_models_equivSentence {φ : L.Formula α} : T ⊨ᵇ φ ↔ (L.lhomWithConstants α).onTheory T ⊨ᵇ Formula.equivSentence φ := by refine ⟨fun h => models_sentence_iff.2 (fun M => ?_), fun h => models_formula_iff.2 (fun M v => ?_)⟩ · letI := (L.lhomWithConstants α).reduct M have : (L.lhomWithConstants α).IsExpansionOn M := LHom.isExpansionOn_reduct _ _ -- why doesn't that instance just work? rw [Formula.realize_equivSentence] have : M ⊨ T := (LHom.onTheory_model _ _).1 M.is_model -- why isn't M.is_model inferInstance? let M' := Theory.ModelType.of T M exact h M' (fun a => (L.con a : M)) _ · letI : (constantsOn α).Structure M := constantsOn.structure v have : M ⊨ (L.lhomWithConstants α).onTheory T := (LHom.onTheory_model _ _).2 inferInstance exact (Formula.realize_equivSentence _ _).1 (h.realize_sentence M) theorem ModelsBoundedFormula.realize_formula {φ : L.Formula α} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] {v : α → M} : φ.Realize v := by rw [models_formula_iff_onTheory_models_equivSentence] at h letI : (constantsOn α).Structure M := constantsOn.structure v have : M ⊨ (L.lhomWithConstants α).onTheory T := (LHom.onTheory_model _ _).2 inferInstance exact (Formula.realize_equivSentence _ _).1 (h.realize_sentence M) theorem models_toFormula_iff {φ : L.BoundedFormula α n} : T ⊨ᵇ φ.toFormula ↔ T ⊨ᵇ φ := by refine ⟨fun h M v xs => ?_, ?_⟩ · have h' : φ.toFormula.Realize (Sum.elim v xs) := h.realize_formula M simp only [BoundedFormula.realize_toFormula, Sum.elim_comp_inl, Sum.elim_comp_inr] at h' exact h' · simp only [models_formula_iff, BoundedFormula.realize_toFormula] exact fun h M v => h M _ _ theorem ModelsBoundedFormula.realize_boundedFormula {φ : L.BoundedFormula α n} (h : T ⊨ᵇ φ) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] {v : α → M} {xs : Fin n → M} : φ.Realize v xs := by have h' : φ.toFormula.Realize (Sum.elim v xs) := (models_toFormula_iff.2 h).realize_formula M simp only [BoundedFormula.realize_toFormula, Sum.elim_comp_inl, Sum.elim_comp_inr] at h' exact h' theorem models_of_models_theory {T' : L.Theory} (h : ∀ φ : L.Sentence, φ ∈ T' → T ⊨ᵇ φ) {φ : L.Formula α} (hφ : T' ⊨ᵇ φ) : T ⊨ᵇ φ := fun M => by have hM : M ⊨ T' := T'.model_iff.2 (fun ψ hψ => (h ψ hψ).realize_sentence M) let M' : ModelType T' := ⟨M⟩ exact hφ M' /-- An alternative statement of the Compactness Theorem. A formula `φ` is modeled by a theory iff there is a finite subset `T0` of the theory such that `φ` is modeled by `T0` -/ theorem models_iff_finset_models {φ : L.Sentence} : T ⊨ᵇ φ ↔ ∃ T0 : Finset L.Sentence, (T0 : L.Theory) ⊆ T ∧ (T0 : L.Theory) ⊨ᵇ φ := by simp only [models_iff_not_satisfiable] rw [← not_iff_not, not_not, isSatisfiable_iff_isFinitelySatisfiable, IsFinitelySatisfiable] push_neg letI := Classical.decEq (Sentence L) constructor · intro h T0 hT0 simpa using h (T0 ∪ {Formula.not φ}) (by simp only [Finset.coe_union, Finset.coe_singleton] exact Set.union_subset_union hT0 (Set.Subset.refl _)) · intro h T0 hT0 exact IsSatisfiable.mono (h (T0.erase (Formula.not φ)) (by simpa using hT0)) (by simp) /-- A theory is complete when it is satisfiable and models each sentence or its negation. -/ def IsComplete (T : L.Theory) : Prop := T.IsSatisfiable ∧ ∀ φ : L.Sentence, T ⊨ᵇ φ ∨ T ⊨ᵇ φ.not namespace IsComplete theorem models_not_iff (h : T.IsComplete) (φ : L.Sentence) : T ⊨ᵇ φ.not ↔ ¬T ⊨ᵇ φ := by rcases h.2 φ with hφ | hφn · simp only [hφ, not_true, iff_false] rw [models_sentence_iff, not_forall] refine ⟨h.1.some, ?_⟩ simp only [Sentence.realize_not, Classical.not_not] exact models_sentence_iff.1 hφ _ · simp only [hφn, true_iff] intro hφ rw [models_sentence_iff] at * exact hφn h.1.some (hφ _) theorem realize_sentence_iff (h : T.IsComplete) (φ : L.Sentence) (M : Type*) [L.Structure M] [M ⊨ T] [Nonempty M] : M ⊨ φ ↔ T ⊨ᵇ φ := by rcases h.2 φ with hφ | hφn · exact iff_of_true (hφ.realize_sentence M) hφ · exact iff_of_false ((Sentence.realize_not M).1 (hφn.realize_sentence M)) ((h.models_not_iff φ).1 hφn) end IsComplete /-- A theory is maximal when it is satisfiable and contains each sentence or its negation. Maximal theories are complete. -/ def IsMaximal (T : L.Theory) : Prop := T.IsSatisfiable ∧ ∀ φ : L.Sentence, φ ∈ T ∨ φ.not ∈ T theorem IsMaximal.isComplete (h : T.IsMaximal) : T.IsComplete := h.imp_right (forall_imp fun _ => Or.imp models_sentence_of_mem models_sentence_of_mem) theorem IsMaximal.mem_or_not_mem (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ∨ φ.not ∈ T := h.2 φ theorem IsMaximal.mem_of_models (h : T.IsMaximal) {φ : L.Sentence} (hφ : T ⊨ᵇ φ) : φ ∈ T := by refine (h.mem_or_not_mem φ).resolve_right fun con => ?_ rw [models_iff_not_satisfiable, Set.union_singleton, Set.insert_eq_of_mem con] at hφ exact hφ h.1 theorem IsMaximal.mem_iff_models (h : T.IsMaximal) (φ : L.Sentence) : φ ∈ T ↔ T ⊨ᵇ φ := ⟨models_sentence_of_mem, h.mem_of_models⟩ end Theory namespace completeTheory variable (L) (M : Type w) variable [L.Structure M] theorem isSatisfiable [Nonempty M] : (L.completeTheory M).IsSatisfiable := Theory.Model.isSatisfiable M theorem mem_or_not_mem (φ : L.Sentence) : φ ∈ L.completeTheory M ∨ φ.not ∈ L.completeTheory M := by simp_rw [completeTheory, Set.mem_setOf_eq, Sentence.Realize, Formula.realize_not, or_not] theorem isMaximal [Nonempty M] : (L.completeTheory M).IsMaximal := ⟨isSatisfiable L M, mem_or_not_mem L M⟩ theorem isComplete [Nonempty M] : (L.completeTheory M).IsComplete := (completeTheory.isMaximal L M).isComplete end completeTheory end Language end FirstOrder namespace Cardinal open FirstOrder FirstOrder.Language variable {L : Language.{u, v}} (κ : Cardinal.{w}) (T : L.Theory) /-- A theory is `κ`-categorical if all models of size `κ` are isomorphic. -/ def Categorical : Prop := ∀ M N : T.ModelType, #M = κ → #N = κ → Nonempty (M ≃[L] N) /-- The Łoś–Vaught Test : a criterion for categorical theories to be complete. -/ theorem Categorical.isComplete (h : κ.Categorical T) (h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) (hS : T.IsSatisfiable) (hT : ∀ M : Theory.ModelType.{u, v, max u v} T, Infinite M) : T.IsComplete := ⟨hS, fun φ => by obtain ⟨_, _⟩ := Theory.exists_model_card_eq ⟨hS.some, hT hS.some⟩ κ h1 h2 rw [Theory.models_sentence_iff, Theory.models_sentence_iff] by_contra! con obtain ⟨⟨MF, hMF⟩, MT, hMT⟩ := con rw [Sentence.realize_not, Classical.not_not] at hMT refine hMF ?_ haveI := hT MT haveI := hT MF obtain ⟨NT, MNT, hNT⟩ := exists_elementarilyEquivalent_card_eq L MT κ h1 h2 obtain ⟨NF, MNF, hNF⟩ := exists_elementarilyEquivalent_card_eq L MF κ h1 h2 obtain ⟨TF⟩ := h (MNT.toModel T) (MNF.toModel T) hNT hNF exact ((MNT.realize_sentence φ).trans ((StrongHomClass.realize_sentence TF φ).trans (MNF.realize_sentence φ).symm)).1 hMT⟩ theorem empty_theory_categorical (T : Language.empty.Theory) : κ.Categorical T := fun M N hM hN => by rw [empty.nonempty_equiv_iff, hM, hN] theorem empty_infinite_Theory_isComplete : Language.empty.infiniteTheory.IsComplete := (empty_theory_categorical.{0} ℵ₀ _).isComplete ℵ₀ _ le_rfl (by simp) ⟨by haveI : Language.empty.Structure ℕ := emptyStructure exact ((model_infiniteTheory_iff Language.empty).2 (inferInstanceAs (Infinite ℕ))).bundled⟩ fun M => (model_infiniteTheory_iff Language.empty).1 M.is_model end Cardinal
Mathlib/ModelTheory/Satisfiability.lean
570
572
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Joël Riou -/ import Mathlib.Algebra.Homology.Homotopy import Mathlib.Algebra.Homology.ShortComplex.Retract import Mathlib.CategoryTheory.MorphismProperty.Composition /-! # Quasi-isomorphisms A chain map is a quasi-isomorphism if it induces isomorphisms on homology. -/ open CategoryTheory Limits universe v u open HomologicalComplex section variable {ι : Type*} {C : Type u} [Category.{v} C] [HasZeroMorphisms C] {c : ComplexShape ι} {K L M K' L' : HomologicalComplex C c} /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism in degree `i` when it induces a quasi-isomorphism of short complexes `K.sc i ⟶ L.sc i`. -/ class QuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : Prop where quasiIso : ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) lemma quasiIsoAt_iff (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ ShortComplex.QuasiIso ((shortComplexFunctor C c i).map f) := by constructor · intro h exact h.quasiIso · intro h exact ⟨h⟩ instance quasiIsoAt_of_isIso (f : K ⟶ L) [IsIso f] (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] infer_instance lemma quasiIsoAt_iff' (f : K ⟶ L) (i j k : ι) (hi : c.prev j = i) (hk : c.next j = k) [K.HasHomology j] [L.HasHomology j] [(K.sc' i j k).HasHomology] [(L.sc' i j k).HasHomology] : QuasiIsoAt f j ↔ ShortComplex.QuasiIso ((shortComplexFunctor' C c i j k).map f) := by rw [quasiIsoAt_iff] exact ShortComplex.quasiIso_iff_of_arrow_mk_iso _ _ (Arrow.isoOfNatIso (natIsoSc' C c i j k hi hk) (Arrow.mk f)) lemma quasiIsoAt_of_retract {f : K ⟶ L} {f' : K' ⟶ L'} (h : RetractArrow f f') (i : ι) [K.HasHomology i] [L.HasHomology i] [K'.HasHomology i] [L'.HasHomology i] [hf' : QuasiIsoAt f' i] : QuasiIsoAt f i := by rw [quasiIsoAt_iff] at hf' ⊢ have : RetractArrow ((shortComplexFunctor C c i).map f) ((shortComplexFunctor C c i).map f') := h.map (shortComplexFunctor C c i).mapArrow exact ShortComplex.quasiIso_of_retract this lemma quasiIsoAt_iff_isIso_homologyMap (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] : QuasiIsoAt f i ↔ IsIso (homologyMap f i) := by rw [quasiIsoAt_iff, ShortComplex.quasiIso_iff] rfl lemma quasiIsoAt_iff_exactAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hK : K.ExactAt i) : QuasiIsoAt f i ↔ L.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hK ⊢ constructor · intro h exact IsZero.of_iso hK (@asIso _ _ _ _ _ h).symm · intro hL exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ lemma quasiIsoAt_iff_exactAt' (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] (hL : L.ExactAt i) : QuasiIsoAt f i ↔ K.ExactAt i := by simp only [quasiIsoAt_iff, ShortComplex.quasiIso_iff, exactAt_iff, ShortComplex.exact_iff_isZero_homology] at hL ⊢ constructor · intro h exact IsZero.of_iso hL (@asIso _ _ _ _ _ h) · intro hK exact ⟨⟨0, IsZero.eq_of_src hK _ _, IsZero.eq_of_tgt hL _ _⟩⟩ lemma exactAt_iff_of_quasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : K.ExactAt i ↔ L.ExactAt i := ⟨fun hK => (quasiIsoAt_iff_exactAt f i hK).1 inferInstance, fun hL => (quasiIsoAt_iff_exactAt' f i hL).1 inferInstance⟩ instance (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [hf : QuasiIsoAt f i] : IsIso (homologyMap f i) := by simpa only [quasiIsoAt_iff, ShortComplex.quasiIso_iff] using hf /-- The isomorphism `K.homology i ≅ L.homology i` induced by a morphism `f : K ⟶ L` such that `[QuasiIsoAt f i]` holds. -/ @[simps! hom] noncomputable def isoOfQuasiIsoAt (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : K.homology i ≅ L.homology i := asIso (homologyMap f i) @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_hom_inv_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : homologyMap f i ≫ (isoOfQuasiIsoAt f i).inv = 𝟙 _ := (isoOfQuasiIsoAt f i).hom_inv_id @[reassoc (attr := simp)] lemma isoOfQuasiIsoAt_inv_hom_id (f : K ⟶ L) (i : ι) [K.HasHomology i] [L.HasHomology i] [QuasiIsoAt f i] : (isoOfQuasiIsoAt f i).inv ≫ homologyMap f i = 𝟙 _ := (isoOfQuasiIsoAt f i).inv_hom_id lemma CochainComplex.quasiIsoAt₀_iff {K L : CochainComplex C ℕ} (f : K ⟶ L) [K.HasHomology 0] [L.HasHomology 0] [(K.sc' 0 0 1).HasHomology] [(L.sc' 0 0 1).HasHomology] : QuasiIsoAt f 0 ↔ ShortComplex.QuasiIso ((HomologicalComplex.shortComplexFunctor' C _ 0 0 1).map f) := quasiIsoAt_iff' _ _ _ _ (by simp) (by simp) lemma ChainComplex.quasiIsoAt₀_iff {K L : ChainComplex C ℕ} (f : K ⟶ L) [K.HasHomology 0] [L.HasHomology 0] [(K.sc' 1 0 0).HasHomology] [(L.sc' 1 0 0).HasHomology] : QuasiIsoAt f 0 ↔ ShortComplex.QuasiIso ((HomologicalComplex.shortComplexFunctor' C _ 1 0 0).map f) := quasiIsoAt_iff' _ _ _ _ (by simp) (by simp) /-- A morphism of homological complexes `f : K ⟶ L` is a quasi-isomorphism when it is so in every degree, i.e. when the induced maps `homologyMap f i : K.homology i ⟶ L.homology i` are all isomorphisms (see `quasiIso_iff` and `quasiIsoAt_iff_isIso_homologyMap`). -/ class QuasiIso (f : K ⟶ L) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : Prop where quasiIsoAt : ∀ i, QuasiIsoAt f i := by infer_instance lemma quasiIso_iff (f : K ⟶ L) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : QuasiIso f ↔ ∀ i, QuasiIsoAt f i := ⟨fun h => h.quasiIsoAt, fun h => ⟨h⟩⟩ attribute [instance] QuasiIso.quasiIsoAt instance quasiIso_of_isIso (f : K ⟶ L) [IsIso f] [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] : QuasiIso f where instance quasiIsoAt_comp (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ : QuasiIsoAt φ i] [hφ' : QuasiIsoAt φ' i] : QuasiIsoAt (φ ≫ φ') i := by rw [quasiIsoAt_iff] at hφ hφ' ⊢ rw [Functor.map_comp] exact ShortComplex.quasiIso_comp _ _ instance quasiIso_comp (φ : K ⟶ L) (φ' : L ⟶ M) [∀ i, K.HasHomology i] [∀ i, L.HasHomology i] [∀ i, M.HasHomology i] [hφ : QuasiIso φ] [hφ' : QuasiIso φ'] :
QuasiIso (φ ≫ φ') where lemma quasiIsoAt_of_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i] [hφ : QuasiIsoAt φ i] [hφφ' : QuasiIsoAt (φ ≫ φ') i] : QuasiIsoAt φ' i := by rw [quasiIsoAt_iff_isIso_homologyMap] at hφ hφφ' ⊢ rw [homologyMap_comp] at hφφ' exact IsIso.of_isIso_comp_left (homologyMap φ i) (homologyMap φ' i) lemma quasiIsoAt_iff_comp_left (φ : K ⟶ L) (φ' : L ⟶ M) (i : ι) [K.HasHomology i] [L.HasHomology i] [M.HasHomology i]
Mathlib/Algebra/Homology/QuasiIso.lean
160
171
/- Copyright (c) 2024 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Topology.Separation.CompletelyRegular import Mathlib.MeasureTheory.Measure.ProbabilityMeasure /-! # Dirac deltas as probability measures and embedding of a space into probability measures on it ## Main definitions * `diracProba`: The Dirac delta mass at a point as a probability measure. ## Main results * `isEmbedding_diracProba`: If `X` is a completely regular T0 space with its Borel sigma algebra, then the mapping that takes a point `x : X` to the delta-measure `diracProba x` is an embedding `X ↪ ProbabilityMeasure X`. ## Tags probability measure, Dirac delta, embedding -/ open Topology Metric Filter Set ENNReal NNReal BoundedContinuousFunction open scoped Topology ENNReal NNReal BoundedContinuousFunction lemma CompletelyRegularSpace.exists_BCNN {X : Type*} [TopologicalSpace X] [CompletelyRegularSpace X] {K : Set X} (K_closed : IsClosed K) {x : X} (x_notin_K : x ∉ K) : ∃ (f : X →ᵇ ℝ≥0), f x = 1 ∧ (∀ y ∈ K, f y = 0) := by obtain ⟨g, g_cont, gx_zero, g_one_on_K⟩ := CompletelyRegularSpace.completely_regular x K K_closed x_notin_K have g_bdd : ∀ x y, dist (Real.toNNReal (g x)) (Real.toNNReal (g y)) ≤ 1 := by refine fun x y ↦ ((Real.lipschitzWith_toNNReal).dist_le_mul (g x) (g y)).trans ?_ simpa using Real.dist_le_of_mem_Icc_01 (g x).prop (g y).prop set g' := BoundedContinuousFunction.mkOfBound ⟨fun x ↦ Real.toNNReal (g x), continuous_real_toNNReal.comp g_cont.subtype_val⟩ 1 g_bdd set f := 1 - g' refine ⟨f, by simp [f, g', gx_zero], fun y y_in_K ↦ by simp [f, g', g_one_on_K y_in_K, tsub_self]⟩ namespace MeasureTheory section embed_to_probabilityMeasure variable {X : Type*} [MeasurableSpace X] /-- The Dirac delta mass at a point `x : X` as a `ProbabilityMeasure`. -/ noncomputable def diracProba (x : X) : ProbabilityMeasure X := ⟨Measure.dirac x, Measure.dirac.isProbabilityMeasure⟩ /-- The assignment `x ↦ diracProba x` is injective if all singletons are measurable. -/ lemma injective_diracProba {X : Type*} [MeasurableSpace X] [MeasurableSpace.SeparatesPoints X] : Function.Injective (fun (x : X) ↦ diracProba x) := by intro x y x_eq_y rw [← dirac_eq_dirac_iff] rwa [Subtype.ext_iff] at x_eq_y @[simp] lemma diracProba_toMeasure_apply' (x : X) {A : Set X} (A_mble : MeasurableSet A) : (diracProba x).toMeasure A = A.indicator 1 x := Measure.dirac_apply' x A_mble @[simp] lemma diracProba_toMeasure_apply_of_mem {x : X} {A : Set X} (x_in_A : x ∈ A) : (diracProba x).toMeasure A = 1 := Measure.dirac_apply_of_mem x_in_A @[simp] lemma diracProba_toMeasure_apply [MeasurableSingletonClass X] (x : X) (A : Set X) : (diracProba x).toMeasure A = A.indicator 1 x := Measure.dirac_apply _ _ variable [TopologicalSpace X] [OpensMeasurableSpace X] /-- The assignment `x ↦ diracProba x` is continuous `X → ProbabilityMeasure X`. -/ lemma continuous_diracProba : Continuous (fun (x : X) ↦ diracProba x) := by rw [continuous_iff_continuousAt] apply fun x ↦ ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto.mpr fun f ↦ ?_ have f_mble : Measurable (fun X ↦ (f X : ℝ≥0∞)) := measurable_coe_nnreal_ennreal_iff.mpr f.continuous.measurable simp only [diracProba, ProbabilityMeasure.coe_mk, lintegral_dirac' _ f_mble] exact (ENNReal.continuous_coe.comp f.continuous).continuousAt /-- In a T0 topological space equipped with a sigma algebra which contains all open sets, the assignment `x ↦ diracProba x` is injective. -/ lemma injective_diracProba_of_T0 [T0Space X] : Function.Injective (fun (x : X) ↦ diracProba x) := by intro x y δx_eq_δy by_contra x_ne_y exact dirac_ne_dirac x_ne_y <| congr_arg Subtype.val δx_eq_δy lemma not_tendsto_diracProba_of_not_tendsto [CompletelyRegularSpace X] {x : X} (L : Filter X) (h : ¬ Tendsto id L (𝓝 x)) : ¬ Tendsto diracProba L (𝓝 (diracProba x)) := by obtain ⟨U, U_nhd, hU⟩ : ∃ U, U ∈ 𝓝 x ∧ ∃ᶠ x in L, x ∉ U := by by_contra! con apply h intro U U_nhd simpa only [not_frequently, not_not] using con U U_nhd have Uint_nhd : interior U ∈ 𝓝 x := by simpa only [interior_mem_nhds] using U_nhd obtain ⟨f, fx_eq_one, f_vanishes_outside⟩ := CompletelyRegularSpace.exists_BCNN isOpen_interior.isClosed_compl (by simpa only [mem_compl_iff, not_not] using mem_of_mem_nhds Uint_nhd) rw [ProbabilityMeasure.tendsto_iff_forall_lintegral_tendsto, not_forall] use f simp only [diracProba, ProbabilityMeasure.coe_mk, fx_eq_one, lintegral_dirac' _ (measurable_coe_nnreal_ennreal_iff.mpr f.continuous.measurable)] apply not_tendsto_iff_exists_frequently_nmem.mpr refine ⟨Ioi 0, Ioi_mem_nhds (by simp only [ENNReal.coe_one, zero_lt_one]), hU.mp (Eventually.of_forall ?_)⟩ intro x x_notin_U rw [f_vanishes_outside x (compl_subset_compl.mpr (show interior U ⊆ U from interior_subset) x_notin_U)] simp only [ENNReal.coe_zero, mem_Ioi, lt_self_iff_false, not_false_eq_true] lemma tendsto_diracProba_iff_tendsto [CompletelyRegularSpace X] {x : X} (L : Filter X) : Tendsto diracProba L (𝓝 (diracProba x)) ↔ Tendsto id L (𝓝 x) := by constructor · contrapose exact not_tendsto_diracProba_of_not_tendsto L · intro h have aux := (@continuous_diracProba X _ _ _).continuousAt (x := x) simp only [ContinuousAt] at aux exact aux.comp h /-- An inverse function to `diracProba` (only really an inverse under hypotheses that guarantee injectivity of `diracProba`). -/ noncomputable def diracProbaInverse : range (diracProba (X := X)) → X := fun μ' ↦ (mem_range.mp μ'.prop).choose -- We redeclare `X` here to temporarily avoid the `[TopologicalSpace X]` instance. @[simp] lemma diracProba_diracProbaInverse {X : Type*} [MeasurableSpace X] (μ : range (diracProba (X := X))) : diracProba (diracProbaInverse μ) = μ := (mem_range.mp μ.prop).choose_spec lemma diracProbaInverse_eq [T0Space X] {x : X} {μ : range (diracProba (X := X))} (h : μ = diracProba x) : diracProbaInverse μ = x := by apply injective_diracProba_of_T0 (X := X) simp only [← h] exact (mem_range.mp μ.prop).choose_spec /-- In a T0 topological space `X`, the assignment `x ↦ diracProba x` is a bijection to its range in `ProbabilityMeasure X`. -/ noncomputable def diracProbaEquiv [T0Space X] : X ≃ range (diracProba (X := X)) where toFun := fun x ↦ ⟨diracProba x, by exact mem_range_self x⟩ invFun := diracProbaInverse left_inv x := by apply diracProbaInverse_eq; rfl
right_inv μ := Subtype.ext (by simp only [diracProba_diracProbaInverse]) /-- The composition of `diracProbaEquiv.symm` and `diracProba` is the subtype inclusion. -/ lemma diracProba_comp_diracProbaEquiv_symm_eq_val [T0Space X] :
Mathlib/MeasureTheory/Measure/DiracProba.lean
143
146
/- 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.Control.Basic import Mathlib.Data.Nat.Basic import Mathlib.Data.Option.Basic import Mathlib.Data.List.Defs import Mathlib.Data.List.Monad import Mathlib.Logic.OpClass import Mathlib.Logic.Unique import Mathlib.Order.Basic import Mathlib.Tactic.Common /-! # Basic properties of lists -/ assert_not_exists GroupWithZero assert_not_exists Lattice assert_not_exists Prod.swap_eq_iff_eq_swap assert_not_exists Ring assert_not_exists Set.range open Function open Nat hiding one_pos namespace List universe u v w variable {ι : Type*} {α : Type u} {β : Type v} {γ : Type w} {l₁ l₂ : List α} /-- 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 } 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 @[simp] theorem cons_injective {a : α} : Injective (cons a) := fun _ _ => tail_eq_of_cons_eq theorem singleton_injective : Injective fun a : α => [a] := fun _ _ h => (cons_eq_cons.1 h).1 theorem set_of_mem_cons (l : List α) (a : α) : { x | x ∈ a :: l } = insert a { x | x ∈ l } := Set.ext fun _ => mem_cons /-! ### 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⟩)) lemma mem_pair {a b c : α} : a ∈ [b, c] ↔ a = b ∨ a = c := by rw [mem_cons, mem_singleton] -- The simpNF linter says that the LHS can be simplified via `List.mem_map`. -- However this is a higher priority lemma. -- It seems the side condition `hf` is not applied by `simpNF`. -- 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⟩ @[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 _⟩⟩ 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] /-! ### length -/ alias ⟨_, length_pos_of_ne_nil⟩ := length_pos_iff theorem length_pos_iff_ne_nil {l : List α} : 0 < length l ↔ l ≠ [] := ⟨ne_nil_of_length_pos, length_pos_of_ne_nil⟩ 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⟩ @[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 · subsingleton · apply ih; simpa using hl @[simp default+1] -- Raise priority above `length_injective_iff`. lemma length_injective [Subsingleton α] : Injective (length : List α → ℕ) := length_injective_iff.mpr inferInstance 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⟩ 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⟩ /-! ### set-theoretic notation of lists -/ instance instSingletonList : Singleton α (List α) := ⟨fun x => [x]⟩ instance [DecidableEq α] : Insert α (List α) := ⟨List.insert⟩ instance [DecidableEq α] : LawfulSingleton α (List α) := { insert_empty_eq := fun x => show (if x ∈ ([] : List α) then [] else [x]) = [x] from if_neg not_mem_nil } theorem singleton_eq (x : α) : ({x} : List α) = [x] := rfl theorem insert_neg [DecidableEq α] {x : α} {l : List α} (h : x ∉ l) : Insert.insert x l = x :: l := insert_of_not_mem h theorem insert_pos [DecidableEq α] {x : α} {l : List α} (h : x ∈ l) : Insert.insert x l = l := insert_of_mem h 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] /-! ### bounded quantifiers over lists -/ 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 theorem exists_mem_cons_of {p : α → Prop} {a : α} (l : List α) (h : p a) : ∃ x ∈ a :: l, p x := ⟨a, mem_cons_self, h⟩ 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⟩ 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⟩ 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 /-! ### list 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⟩ 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 _) 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 hx)) with ⟨x', hx', hxx'⟩ cases h hxx'; exact hx' /-! ### append -/ theorem append_eq_has_append {L₁ L₂ : List α} : List.append L₁ L₂ = L₁ ++ L₂ := rfl theorem append_right_injective (s : List α) : Injective fun t ↦ s ++ t := fun _ _ ↦ append_cancel_left theorem append_left_injective (t : List α) : Injective fun s ↦ s ++ t := fun _ _ ↦ append_cancel_right /-! ### 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, replicate_succ] theorem replicate_add (m n) (a : α) : replicate (m + n) a = replicate m a ++ replicate n a := by rw [replicate_append_replicate] theorem replicate_subset_singleton (n) (a : α) : replicate n a ⊆ [a] := fun _ h => mem_singleton.2 (eq_of_mem_replicate h) theorem subset_singleton_iff {a : α} {L : List α} : L ⊆ [a] ↔ ∃ n, L = replicate n a := by simp only [eq_replicate_iff, subset_def, mem_singleton, exists_eq_left'] theorem replicate_right_injective {n : ℕ} (hn : n ≠ 0) : Injective (@replicate α n) := fun _ _ h => (eq_replicate_iff.1 h).2 _ <| mem_replicate.2 ⟨hn, rfl⟩ theorem replicate_right_inj {a b : α} {n : ℕ} (hn : n ≠ 0) : replicate n a = replicate n b ↔ a = b := (replicate_right_injective hn).eq_iff 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] theorem replicate_left_injective (a : α) : Injective (replicate · a) := LeftInverse.injective (length_replicate (n := ·)) theorem replicate_left_inj {a : α} {n m : ℕ} : replicate n a = replicate m a ↔ n = m := (replicate_left_injective a).eq_iff @[simp] theorem head?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.head? = l.head? := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero h induction l <;> simp [replicate] @[simp] theorem getLast?_flatten_replicate {n : ℕ} (h : n ≠ 0) (l : List α) : (List.replicate n l).flatten.getLast? = l.getLast? := by rw [← List.head?_reverse, ← List.head?_reverse, List.reverse_flatten, List.map_replicate, List.reverse_replicate, head?_flatten_replicate h] /-! ### pure -/ theorem mem_pure (x y : α) : x ∈ (pure y : List α) ↔ x = y := by simp /-! ### bind -/ @[simp] theorem bind_eq_flatMap {α β} (f : α → List β) (l : List α) : l >>= f = l.flatMap f := rfl /-! ### concat -/ /-! ### reverse -/ theorem reverse_cons' (a : α) (l : List α) : reverse (a :: l) = concat (reverse l) a := by simp only [reverse_cons, concat_eq_append] theorem reverse_concat' (l : List α) (a : α) : (l ++ [a]).reverse = a :: l.reverse := by rw [reverse_append]; rfl @[simp] theorem reverse_singleton (a : α) : reverse [a] = [a] := rfl @[simp] theorem reverse_involutive : Involutive (@reverse α) := reverse_reverse @[simp] theorem reverse_injective : Injective (@reverse α) := reverse_involutive.injective theorem reverse_surjective : Surjective (@reverse α) := reverse_involutive.surjective theorem reverse_bijective : Bijective (@reverse α) := reverse_involutive.bijective 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] 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] -- TODO: Rename `List.reverse_perm` to `List.reverse_perm_self` @[simp] lemma reverse_perm' : l₁.reverse ~ l₂ ↔ l₁ ~ l₂ where mp := l₁.reverse_perm.symm.trans mpr := l₁.reverse_perm.trans @[simp] lemma perm_reverse : l₁ ~ l₂.reverse ↔ l₁ ~ l₂ where mp hl := hl.trans l₂.reverse_perm mpr hl := hl.trans l₂.reverse_perm.symm /-! ### getLast -/ attribute [simp] getLast_cons theorem getLast_append_singleton {a : α} (l : List α) : getLast (l ++ [a]) (append_ne_nil_of_right_ne_nil l (cons_ne_nil a _)) = a := by simp [getLast_append] theorem getLast_append_of_right_ne_nil (l₁ l₂ : List α) (h : l₂ ≠ []) : getLast (l₁ ++ l₂) (append_ne_nil_of_right_ne_nil l₁ h) = getLast l₂ h := by induction l₁ with | nil => simp | cons _ _ ih => simp only [cons_append]; rw [List.getLast_cons]; exact ih @[deprecated (since := "2025-02-06")] alias getLast_append' := getLast_append_of_right_ne_nil theorem getLast_concat' {a : α} (l : List α) : getLast (concat l a) (by simp) = a := by simp @[simp] theorem getLast_singleton' (a : α) : getLast [a] (cons_ne_nil a []) = a := rfl @[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 theorem dropLast_append_getLast : ∀ {l : List α} (h : l ≠ []), dropLast l ++ [getLast l h] = l | [], h => absurd rfl 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) theorem getLast_congr {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂) : getLast l₁ h₁ = getLast l₂ h₂ := by subst l₁; rfl theorem getLast_replicate_succ (m : ℕ) (a : α) : (replicate (m + 1) a).getLast (ne_nil_of_length_eq_add_one length_replicate) = a := by simp only [replicate_succ'] exact getLast_append_singleton _ @[deprecated (since := "2025-02-07")] alias getLast_filter' := getLast_filter_of_pos /-! ### getLast? -/ 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 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 _ _) theorem mem_getLast?_cons {x y : α} : ∀ {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast? | [], _ => by contradiction | _ :: _, h => h 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] theorem getLastI_eq_getLast? [Inhabited α] : ∀ l : List α, l.getLastI = l.getLast?.iget | [] => by simp [getLastI, Inhabited.default] | [_] => rfl | [_, _] => rfl | [_, _, _] => rfl | _ :: _ :: c :: l => by simp [getLastI, getLastI_eq_getLast? (c :: l)] theorem getLast?_append_cons : ∀ (l₁ : List α) (a : α) (l₂ : List α), getLast? (l₁ ++ a :: l₂) = getLast? (a :: l₂) | [], _, _ => rfl | [_], _, _ => rfl | b :: c :: l₁, a, l₂ => by rw [cons_append, cons_append, getLast?_cons_cons, ← cons_append, getLast?_append_cons (c :: l₁)] 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₂ theorem mem_getLast?_append_of_mem_getLast? {l₁ l₂ : List α} {x : α} (h : x ∈ l₂.getLast?) : x ∈ (l₁ ++ l₂).getLast? := by cases l₂ · contradiction · rw [List.getLast?_append_cons] exact h /-! ### 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_getElem_zero {l : List α} (hl : l ≠ []) : l.head hl = l[0]'(length_pos_iff.2 hl) := (getElem_zero _).symm theorem head!_eq_head? [Inhabited α] (l : List α) : head! l = (head? l).iget := by cases l <;> rfl theorem surjective_head! [Inhabited α] : Surjective (@head! α _) := fun x => ⟨[x], rfl⟩ theorem surjective_head? : Surjective (@head? α) := Option.forall.2 ⟨⟨[], rfl⟩, fun x => ⟨[x], rfl⟩⟩ theorem surjective_tail : Surjective (@tail α) | [] => ⟨[], rfl⟩ | a :: l => ⟨a :: a :: l, rfl⟩ 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 @[simp] theorem head!_cons [Inhabited α] (a : α) (l : List α) : head! (a :: l) = a := rfl @[simp] theorem head!_append [Inhabited α] (t : List α) {s : List α} (h : s ≠ []) : head! (s ++ t) = head! s := by induction s · contradiction · rfl theorem mem_head?_append_of_mem_head? {s t : List α} {x : α} (h : x ∈ s.head?) : x ∈ (s ++ t).head? := by cases s · contradiction · exact h theorem head?_append_of_ne_nil : ∀ (l₁ : List α) {l₂ : List α} (_ : l₁ ≠ []), head? (l₁ ++ l₂) = head? l₁ | _ :: _, _, _ => rfl 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] 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] theorem head!_mem_head? [Inhabited α] : ∀ {l : List α}, l ≠ [] → head! l ∈ head? l | [], h => by contradiction | _ :: _, _ => rfl theorem cons_head!_tail [Inhabited α] {l : List α} (h : l ≠ []) : head! l :: tail l = l := cons_head?_tail (head!_mem_head? h) theorem head!_mem_self [Inhabited α] {l : List α} (h : l ≠ nil) : l.head! ∈ l := by have h' : l.head! ∈ l.head! :: l.tail := mem_cons_self rwa [cons_head!_tail h] at h' theorem get_eq_getElem? (l : List α) (i : Fin l.length) : l.get i = l[i]?.get (by simp [getElem?_eq_getElem]) := by simp @[deprecated (since := "2025-02-15")] alias get_eq_get? := get_eq_getElem? theorem exists_mem_iff_getElem {l : List α} {p : α → Prop} : (∃ x ∈ l, p x) ↔ ∃ (i : ℕ) (_ : i < l.length), p l[i] := by simp only [mem_iff_getElem] exact ⟨fun ⟨_x, ⟨i, hi, hix⟩, hxp⟩ ↦ ⟨i, hi, hix ▸ hxp⟩, fun ⟨i, hi, hp⟩ ↦ ⟨_, ⟨i, hi, rfl⟩, hp⟩⟩ theorem forall_mem_iff_getElem {l : List α} {p : α → Prop} : (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (_ : i < l.length), p l[i] := by simp [mem_iff_getElem, @forall_swap α] theorem get_tail (l : List α) (i) (h : i < l.tail.length) (h' : i + 1 < l.length := (by simp only [length_tail] at h; omega)) : l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩ := by cases l <;> [cases h; rfl] /-! ### sublists -/ attribute [refl] List.Sublist.refl theorem Sublist.cons_cons {l₁ l₂ : List α} (a : α) (s : l₁ <+ l₂) : a :: l₁ <+ a :: l₂ := Sublist.cons₂ _ s lemma cons_sublist_cons' {a b : α} : a :: l₁ <+ b :: l₂ ↔ a :: l₁ <+ l₂ ∨ a = b ∧ l₁ <+ l₂ := by constructor · rintro (_ | _) · exact Or.inl ‹_› · exact Or.inr ⟨rfl, ‹_›⟩ · rintro (h | ⟨rfl, h⟩) · exact h.cons _ · rwa [cons_sublist_cons] theorem sublist_cons_of_sublist (a : α) (h : l₁ <+ l₂) : l₁ <+ a :: l₂ := h.cons _ @[deprecated (since := "2025-02-07")] alias sublist_nil_iff_eq_nil := sublist_nil @[simp] lemma sublist_singleton {l : List α} {a : α} : l <+ [a] ↔ l = [] ∨ l = [a] := by constructor <;> rintro (_ | _) <;> aesop theorem Sublist.antisymm (s₁ : l₁ <+ l₂) (s₂ : l₂ <+ l₁) : l₁ = l₂ := s₁.eq_of_length_le s₂.length_le /-- If the first element of two lists are different, then a sublist relation can be reduced. -/ theorem Sublist.of_cons_of_ne {a b} (h₁ : a ≠ b) (h₂ : a :: l₁ <+ b :: l₂) : a :: l₁ <+ l₂ := match h₁, h₂ with | _, .cons _ h => h /-! ### indexOf -/ section IndexOf variable [DecidableEq α] theorem idxOf_cons_eq {a b : α} (l : List α) : b = a → idxOf a (b :: l) = 0 | e => by rw [← e]; exact idxOf_cons_self @[deprecated (since := "2025-01-30")] alias indexOf_cons_eq := idxOf_cons_eq @[simp] theorem idxOf_cons_ne {a b : α} (l : List α) : b ≠ a → idxOf a (b :: l) = succ (idxOf a l) | h => by simp only [idxOf_cons, Bool.cond_eq_ite, beq_iff_eq, if_neg h] @[deprecated (since := "2025-01-30")] alias indexOf_cons_ne := idxOf_cons_ne theorem idxOf_eq_length_iff {a : α} {l : List α} : idxOf a l = length l ↔ a ∉ l := by induction l with | nil => exact iff_of_true rfl not_mem_nil | cons b l ih => simp only [length, mem_cons, idxOf_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] rw [← ih] exact succ_inj @[simp] theorem idxOf_of_not_mem {l : List α} {a : α} : a ∉ l → idxOf a l = length l := idxOf_eq_length_iff.2 @[deprecated (since := "2025-01-30")] alias indexOf_of_not_mem := idxOf_of_not_mem theorem idxOf_le_length {a : α} {l : List α} : idxOf a l ≤ length l := by induction l with | nil => rfl | cons b l ih => ?_ simp only [length, idxOf_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 @[deprecated (since := "2025-01-30")] alias indexOf_le_length := idxOf_le_length theorem idxOf_lt_length_iff {a} {l : List α} : idxOf a l < length l ↔ a ∈ l := ⟨fun h => Decidable.byContradiction fun al => Nat.ne_of_lt h <| idxOf_eq_length_iff.2 al, fun al => (lt_of_le_of_ne idxOf_le_length) fun h => idxOf_eq_length_iff.1 h al⟩ @[deprecated (since := "2025-01-30")] alias indexOf_lt_length_iff := idxOf_lt_length_iff theorem idxOf_append_of_mem {a : α} (h : a ∈ l₁) : idxOf a (l₁ ++ l₂) = idxOf a l₁ := by induction l₁ with | nil => exfalso exact not_mem_nil h | cons d₁ t₁ ih => rw [List.cons_append] by_cases hh : d₁ = a · iterate 2 rw [idxOf_cons_eq _ hh] rw [idxOf_cons_ne _ hh, idxOf_cons_ne _ hh, ih (mem_of_ne_of_mem (Ne.symm hh) h)] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_mem := idxOf_append_of_mem theorem idxOf_append_of_not_mem {a : α} (h : a ∉ l₁) : idxOf a (l₁ ++ l₂) = l₁.length + idxOf a l₂ := by induction l₁ with | nil => rw [List.nil_append, List.length, Nat.zero_add] | cons d₁ t₁ ih => rw [List.cons_append, idxOf_cons_ne _ (ne_of_not_mem_cons h).symm, List.length, ih (not_mem_of_not_mem_cons h), Nat.succ_add] @[deprecated (since := "2025-01-30")] alias indexOf_append_of_not_mem := idxOf_append_of_not_mem end IndexOf /-! ### nth element -/ section deprecated @[simp] theorem getElem?_length (l : List α) : l[l.length]? = none := getElem?_eq_none le_rfl /-- A version of `getElem_map` that can be used for rewriting. -/ theorem getElem_map_rev (f : α → β) {l} {n : Nat} {h : n < l.length} : f l[n] = (map f l)[n]'((l.length_map f).symm ▸ h) := Eq.symm (getElem_map _) 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_getElem _).symm 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_getElem_cons h, take, take] simp theorem ext_getElem?' {l₁ l₂ : List α} (h' : ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) : l₁ = l₂ := by apply ext_getElem? 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, getElem?_eq_none] @[deprecated (since := "2025-02-15")] alias ext_get?' := ext_getElem?' @[deprecated (since := "2025-02-15")] alias ext_get?_iff := List.ext_getElem?_iff 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_getElem?_iff' {l₁ l₂ : List α} : l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]? := ⟨by rintro rfl _ _; rfl, ext_getElem?'⟩ @[deprecated (since := "2025-02-15")] alias ext_get?_iff' := ext_getElem?_iff' /-- If two lists `l₁` and `l₂` are the same length and `l₁[n]! = l₂[n]!` for all `n`, then the lists are equal. -/ theorem ext_getElem! [Inhabited α] (hl : length l₁ = length l₂) (h : ∀ n : ℕ, l₁[n]! = l₂[n]!) : l₁ = l₂ := ext_getElem hl fun n h₁ h₂ ↦ by simpa only [← getElem!_pos] using h n @[simp] theorem getElem_idxOf [DecidableEq α] {a : α} : ∀ {l : List α} (h : idxOf a l < l.length), l[idxOf a l] = a | b :: l, h => by by_cases h' : b = a <;> simp [h', if_pos, if_false, getElem_idxOf] @[deprecated (since := "2025-01-30")] alias getElem_indexOf := getElem_idxOf -- This is incorrectly named and should be `get_idxOf`; -- this already exists, so will require a deprecation dance. theorem idxOf_get [DecidableEq α] {a : α} {l : List α} (h) : get l ⟨idxOf a l, h⟩ = a := by simp @[deprecated (since := "2025-01-30")] alias indexOf_get := idxOf_get @[simp] theorem getElem?_idxOf [DecidableEq α] {a : α} {l : List α} (h : a ∈ l) : l[idxOf a l]? = some a := by rw [getElem?_eq_getElem, getElem_idxOf (idxOf_lt_length_iff.2 h)] @[deprecated (since := "2025-01-30")] alias getElem?_indexOf := getElem?_idxOf @[deprecated (since := "2025-02-15")] alias idxOf_get? := getElem?_idxOf @[deprecated (since := "2025-01-30")] alias indexOf_get? := getElem?_idxOf theorem idxOf_inj [DecidableEq α] {l : List α} {x y : α} (hx : x ∈ l) (hy : y ∈ l) : idxOf x l = idxOf y l ↔ x = y := ⟨fun h => by have x_eq_y : get l ⟨idxOf x l, idxOf_lt_length_iff.2 hx⟩ = get l ⟨idxOf y l, idxOf_lt_length_iff.2 hy⟩ := by simp only [h] simp only [idxOf_get] at x_eq_y; exact x_eq_y, fun h => by subst h; rfl⟩ @[deprecated (since := "2025-01-30")] alias indexOf_inj := idxOf_inj theorem get_reverse' (l : List α) (n) (hn') : l.reverse.get n = l.get ⟨l.length - 1 - n, hn'⟩ := by simp theorem eq_cons_of_length_one {l : List α} (h : l.length = 1) : l = [l.get ⟨0, by omega⟩] := by refine ext_get (by convert h) fun n h₁ h₂ => ?_ simp congr omega end deprecated @[simp] theorem getElem_set_of_ne {l : List α} {i j : ℕ} (h : i ≠ j) (a : α) (hj : j < (l.set i a).length) : (l.set i a)[j] = l[j]'(by simpa using hj) := by rw [← Option.some_inj, ← List.getElem?_eq_getElem, List.getElem?_set_ne h, List.getElem?_eq_getElem] /-! ### map -/ -- `List.map_const` (the version with `Function.const` instead of a lambda) is already tagged -- `simp` in Core -- TODO: Upstream the tagging to Core? attribute [simp] map_const' theorem flatMap_pure_eq_map (f : α → β) (l : List α) : l.flatMap (pure ∘ f) = map f l := .symm <| map_eq_flatMap .. theorem flatMap_congr {l : List α} {f g : α → List β} (h : ∀ x ∈ l, f x = g x) : l.flatMap f = l.flatMap g := (congr_arg List.flatten <| map_congr_left h :) theorem infix_flatMap_of_mem {a : α} {as : List α} (h : a ∈ as) (f : α → List α) : f a <:+: as.flatMap f := infix_of_mem_flatten (mem_map_of_mem h) @[simp] theorem map_eq_map {α β} (f : α → β) (l : List α) : f <$> l = map f l := rfl /-- 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 /-- 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] 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] 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 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 /-- `eq_nil_or_concat` in simp normal form -/ lemma eq_nil_or_concat' (l : List α) : l = [] ∨ ∃ L b, l = L ++ [b] := by simpa using l.eq_nil_or_concat /-! ### 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] 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 | nil => rfl | cons hd tl ih => ?_ simp only [mem_cons, or_imp, forall_and, forall_eq] at H simp only [foldr, ih H.2, H.1] 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] 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] @[simp] theorem foldl_fixed {a : α} : ∀ l : List β, foldl (fun a _ => a) a l = a := foldl_fixed' fun _ => rfl @[simp] theorem foldr_fixed {b : β} : ∀ l : List α, foldr (fun _ b => b) b l = b := foldr_fixed' fun _ => rfl @[deprecated foldr_cons_nil (since := "2025-02-10")] theorem foldr_eta (l : List α) : foldr cons [] l = l := foldr_cons_nil theorem reverse_foldl {l : List α} : reverse (foldl (fun t h => h :: t) [] l) = l := by simp 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]] 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]] 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 generalizing f with | nil => exact hf | cons lh lt l_ih => apply l_ih fun _ h => hl _ (List.mem_cons_of_mem _ h) apply Function.Injective.comp hf apply hl _ mem_cons_self /-- 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_iff, 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 FoldlEqFoldr -- foldl and foldr coincide when f is commutative and associative variable {f : α → α → α} theorem foldl1_eq_foldr1 [hassoc : Std.Associative f] : ∀ a b l, foldl f a (l ++ [b]) = foldr f b (a :: l) | _, _, nil => rfl | a, b, c :: l => by simp only [cons_append, foldl_cons, foldr_cons, foldl1_eq_foldr1 _ _ l] rw [hassoc.assoc] theorem foldl_eq_of_comm_of_assoc [hcomm : Std.Commutative f] [hassoc : Std.Associative f] : ∀ a b l, foldl f a (b :: l) = f b (foldl f a l) | a, b, nil => hcomm.comm a b | a, b, c :: l => by simp only [foldl_cons] have : RightCommutative f := inferInstance rw [← foldl_eq_of_comm_of_assoc .., this.right_comm, foldl_cons] theorem foldl_eq_foldr [Std.Commutative f] [Std.Associative f] : ∀ a l, foldl f a l = foldr f a l | _, nil => rfl | a, b :: l => by simp only [foldr_cons, foldl_eq_of_comm_of_assoc] rw [foldl_eq_foldr a l] end FoldlEqFoldr section FoldlEqFoldlr' variable {f : α → β → α} variable (hf : ∀ a b c, f (f a b) c = f (f a c) b) include hf theorem foldl_eq_of_comm' : ∀ a b l, foldl f a (b :: l) = f (foldl f a l) b | _, _, [] => rfl | a, b, c :: l => by rw [foldl, foldl, foldl, ← foldl_eq_of_comm' .., foldl, hf] theorem foldl_eq_foldr' : ∀ a l, foldl f a l = foldr (flip f) a l | _, [] => rfl | a, b :: l => by rw [foldl_eq_of_comm' hf, foldr, foldl_eq_foldr' ..]; rfl end FoldlEqFoldlr' section FoldlEqFoldlr' variable {f : α → β → β} theorem foldr_eq_of_comm' (hf : ∀ a b c, f a (f b c) = f b (f a c)) : ∀ a b l, foldr f a (b :: l) = foldr f (f b a) l | _, _, [] => rfl | a, b, c :: l => by rw [foldr, foldr, foldr, hf, ← foldr_eq_of_comm' hf ..]; rfl end FoldlEqFoldlr' section variable {op : α → α → α} [ha : Std.Associative 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_op_eq_op_foldr_assoc : ∀ {l : List α} {a₁ a₂}, ((l <*> a₁) ⋆ a₂) = a₁ ⋆ l.foldr (· ⋆ ·) a₂ | [], _, _ => rfl | a :: l, a₁, a₂ => by simp only [foldl_cons, foldr_cons, foldl_assoc, ha.assoc]; rw [foldl_op_eq_op_foldr_assoc] variable [hc : Std.Commutative op] theorem foldl_assoc_comm_cons {l : List α} {a₁ a₂} : ((a₁ :: l) <*> a₂) = a₁ ⋆ l <*> a₂ := by rw [foldl_cons, hc.comm, foldl_assoc] end /-! ### foldlM, foldrM, mapM -/ section FoldlMFoldrM variable {m : Type v → Type w} [Monad m] 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 [*] 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] end FoldlMFoldrM /-! ### intersperse -/ @[deprecated (since := "2025-02-07")] alias intersperse_singleton := intersperse_single @[deprecated (since := "2025-02-07")] alias intersperse_cons_cons := intersperse_cons₂ /-! ### map for partial functions -/ @[deprecated "Deprecated without replacement." (since := "2025-02-07")] theorem sizeOf_lt_sizeOf_of_mem [SizeOf α] {x : α} {l : List α} (hx : x ∈ l) : SizeOf.sizeOf x < SizeOf.sizeOf l := by induction l with | nil => ?_ | cons h t ih => ?_ <;> cases hx <;> rw [cons.sizeOf_spec] · omega · specialize ih ‹_› omega /-! ### 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 -/ theorem filterMap_eq_flatMap_toList (f : α → Option β) (l : List α) : l.filterMap f = l.flatMap fun a ↦ (f a).toList := by induction l with | nil => ?_ | cons a l ih => ?_ <;> simp [filterMap_cons] 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 <;> simp_all [filterMap_cons] 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 | nil => simp | cons a l ih => ?_ rcases ha : f a with - | b <;> simp [ha, filterMap_cons] · 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 filterMap_eq_map _) /-! ### filter -/ section Filter variable {p : α → Bool} theorem filter_singleton {a : α} : [a].filter p = bif p a then [a] else [] := rfl 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 #adaptation_note /-- nightly-2024-07-27 This has to be temporarily renamed to avoid an unintentional collision. The prime should be removed at nightly-2024-07-27. -/ @[simp] theorem filter_subset' (l : List α) : filter p l ⊆ l := filter_sublist.subset theorem of_mem_filter {a : α} {l} (h : a ∈ filter p l) : p a := (mem_filter.1 h).2 theorem mem_of_mem_filter {a : α} {l} (h : a ∈ filter p l) : a ∈ l := filter_subset' l h theorem mem_filter_of_mem {a : α} {l} (h₁ : a ∈ l) (h₂ : p a) : a ∈ filter p l := mem_filter.2 ⟨h₁, h₂⟩ @[deprecated (since := "2025-02-07")] alias monotone_filter_left := filter_subset variable (p) 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 | nil => rfl | cons hd tl IH => 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 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 [comp_def, filter_map, hf.eq_iff] @[deprecated (since := "2025-02-07")] alias map_filter' := 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 _ => mem_of_mem_filter) := by classical refine map_injective_iff.2 Subtype.coe_injective ?_ simp [comp_def, map_filter _ Subtype.coe_injective] 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 _ => mem_of_mem_filter) := map_injective_iff.2 Subtype.coe_injective <| by simp_rw [map_map, comp_def, Subtype.map, id, ← Function.comp_apply (g := Subtype.val), ← filter_map, attach_map_subtype_val] lemma filter_comm (q) (l : List α) : filter p (filter q l) = filter q (filter p l) := by simp [Bool.and_comm] @[simp] theorem filter_true (l : List α) : filter (fun _ => true) l = l := by induction l <;> simp [*, filter] @[simp] theorem filter_false (l : List α) : filter (fun _ => false) l = [] := by induction l <;> simp [*, filter] end Filter /-! ### eraseP -/ section eraseP variable {p : α → Bool} @[simp] theorem length_eraseP_add_one {l : List α} {a} (al : a ∈ l) (pa : p a) : (l.eraseP p).length + 1 = l.length := by let ⟨_, l₁, l₂, _, _, h₁, h₂⟩ := exists_of_eraseP al pa rw [h₂, h₁, length_append, length_append] rfl end eraseP /-! ### erase -/ section Erase variable [DecidableEq α] @[simp] theorem length_erase_add_one {a : α} {l : List α} (h : a ∈ l) : (l.erase a).length + 1 = l.length := by rw [erase_eq_eraseP, length_eraseP_add_one h (decide_eq_true rfl)] theorem map_erase [DecidableEq β] {f : α → β} (finj : Injective f) {a : α} (l : List α) : map f (l.erase a) = (map f l).erase (f a) := by have this : (a == ·) = (f a == f ·) := by ext b; simp [beq_eq_decide, finj.eq_iff] rw [erase_eq_eraseP, erase_eq_eraseP, eraseP_map, this]; rfl theorem map_foldl_erase [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (foldl List.erase l₁ l₂) = foldl (fun l a => l.erase (f a)) (map f l₁) l₂ := by induction l₂ generalizing l₁ <;> [rfl; simp only [foldl_cons, map_erase finj, *]] theorem erase_getElem [DecidableEq ι] {l : List ι} {i : ℕ} (hi : i < l.length) : Perm (l.erase l[i]) (l.eraseIdx i) := by induction l generalizing i with | nil => simp | cons a l IH => cases i with | zero => simp | succ i => have hi' : i < l.length := by simpa using hi if ha : a = l[i] then simpa [ha] using .trans (perm_cons_erase (getElem_mem _)) (.cons _ (IH hi')) else simpa [ha] using IH hi' theorem length_eraseIdx_add_one {l : List ι} {i : ℕ} (h : i < l.length) : (l.eraseIdx i).length + 1 = l.length := by rw [length_eraseIdx] split <;> omega end Erase /-! ### diff -/ section Diff variable [DecidableEq α] @[simp] theorem map_diff [DecidableEq β] {f : α → β} (finj : Injective f) {l₁ l₂ : List α} : map f (l₁.diff l₂) = (map f l₁).diff (map f l₂) := by simp only [diff_eq_foldl, foldl_map, map_foldl_erase finj] @[deprecated (since := "2025-04-10")] alias erase_diff_erase_sublist_of_sublist := Sublist.erase_diff_erase_sublist end Diff section Choose variable (p : α → Prop) [DecidablePred p] (l : List α) theorem choose_spec (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l ∧ p (choose p l hp) := (chooseX p l hp).property theorem choose_mem (hp : ∃ a, a ∈ l ∧ p a) : choose p l hp ∈ l := (choose_spec _ _ _).1 theorem choose_property (hp : ∃ a, a ∈ l ∧ p a) : p (choose p l hp) := (choose_spec _ _ _).2 end Choose /-! ### Forall -/ section Forall variable {p q : α → Prop} {l : List α} @[simp] theorem forall_cons (p : α → Prop) (x : α) : ∀ l : List α, Forall p (x :: l) ↔ p x ∧ Forall p l | [] => (and_iff_left_of_imp fun _ ↦ trivial).symm | _ :: _ => Iff.rfl @[simp] theorem forall_append {p : α → Prop} : ∀ {xs ys : List α}, Forall p (xs ++ ys) ↔ Forall p xs ∧ Forall p ys | [] => by simp | _ :: _ => by simp [forall_append, and_assoc] theorem forall_iff_forall_mem : ∀ {l : List α}, Forall p l ↔ ∀ x ∈ l, p x | [] => (iff_true_intro <| forall_mem_nil _).symm | x :: l => by rw [forall_mem_cons, forall_cons, forall_iff_forall_mem] theorem Forall.imp (h : ∀ x, p x → q x) : ∀ {l : List α}, Forall p l → Forall q l | [] => id | x :: l => by simp only [forall_cons, and_imp] rw [← and_imp] exact And.imp (h x) (Forall.imp h) @[simp] theorem forall_map_iff {p : β → Prop} (f : α → β) : Forall p (l.map f) ↔ Forall (p ∘ f) l := by induction l <;> simp [*] instance (p : α → Prop) [DecidablePred p] : DecidablePred (Forall p) := fun _ => decidable_of_iff' _ forall_iff_forall_mem end Forall /-! ### Miscellaneous lemmas -/ theorem get_attach (l : List α) (i) : (l.attach.get i).1 = l.get ⟨i, length_attach (l := l) ▸ i.2⟩ := by simp section Disjoint /-- The images of disjoint lists under a partially defined map are disjoint -/ theorem disjoint_pmap {p : α → Prop} {f : ∀ a : α, p a → β} {s t : List α} (hs : ∀ a ∈ s, p a) (ht : ∀ a ∈ t, p a) (hf : ∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') (h : Disjoint s t) : Disjoint (s.pmap f hs) (t.pmap f ht) := by simp only [Disjoint, mem_pmap] rintro b ⟨a, ha, rfl⟩ ⟨a', ha', ha''⟩ apply h ha rwa [hf a a' (hs a ha) (ht a' ha') ha''.symm] /-- The images of disjoint lists under an injective map are disjoint -/ theorem disjoint_map {f : α → β} {s t : List α} (hf : Function.Injective f) (h : Disjoint s t) : Disjoint (s.map f) (t.map f) := by rw [← pmap_eq_map (fun _ _ ↦ trivial), ← pmap_eq_map (fun _ _ ↦ trivial)] exact disjoint_pmap _ _ (fun _ _ _ _ h' ↦ hf h') h alias Disjoint.map := disjoint_map theorem Disjoint.of_map {f : α → β} {s t : List α} (h : Disjoint (s.map f) (t.map f)) : Disjoint s t := fun _a has hat ↦ h (mem_map_of_mem has) (mem_map_of_mem hat) theorem Disjoint.map_iff {f : α → β} {s t : List α} (hf : Function.Injective f) : Disjoint (s.map f) (t.map f) ↔ Disjoint s t := ⟨fun h ↦ h.of_map, fun h ↦ h.map hf⟩ theorem Perm.disjoint_left {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l₁ l ↔ Disjoint l₂ l := by simp_rw [List.disjoint_left, p.mem_iff] theorem Perm.disjoint_right {l₁ l₂ l : List α} (p : List.Perm l₁ l₂) : Disjoint l l₁ ↔ Disjoint l l₂ := by simp_rw [List.disjoint_right, p.mem_iff] @[simp] theorem disjoint_reverse_left {l₁ l₂ : List α} : Disjoint l₁.reverse l₂ ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_left @[simp] theorem disjoint_reverse_right {l₁ l₂ : List α} : Disjoint l₁ l₂.reverse ↔ Disjoint l₁ l₂ := reverse_perm _ |>.disjoint_right end Disjoint section lookup variable [BEq α] [LawfulBEq α] lemma lookup_graph (f : α → β) {a : α} {as : List α} (h : a ∈ as) : lookup a (as.map fun x => (x, f x)) = some (f a) := by induction as with | nil => exact (not_mem_nil h).elim | cons a' as ih => by_cases ha : a = a' · simp [ha, lookup_cons] · simpa [lookup_cons, beq_false_of_ne ha] using ih (List.mem_of_ne_of_mem ha h) end lookup section range' @[simp] lemma range'_0 (a b : ℕ) : range' a b 0 = replicate b a := by induction b with | zero => simp | succ b ih => simp [range'_succ, ih, replicate_succ] lemma left_le_of_mem_range' {a b s x : ℕ} (hx : x ∈ List.range' a b s) : a ≤ x := by obtain ⟨i, _, rfl⟩ := List.mem_range'.mp hx exact le_add_right a (s * i) end range' end List
Mathlib/Data/List/Basic.lean
1,439
1,443
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, Yaël Dillies -/ import Mathlib.Analysis.Convex.Cone.Extension import Mathlib.Analysis.Convex.Gauge import Mathlib.Topology.Algebra.Module.FiniteDimension import Mathlib.Topology.Algebra.Module.LocallyConvex import Mathlib.Topology.Algebra.MulAction import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.NormedSpace.Extend /-! # Separation Hahn-Banach theorem In this file we prove the geometric Hahn-Banach theorem. For any two disjoint convex sets, there exists a continuous linear functional separating them, geometrically meaning that we can intercalate a plane between them. We provide many variations to stricten the result under more assumptions on the convex sets: * `geometric_hahn_banach_open`: One set is open. Weak separation. * `geometric_hahn_banach_open_point`, `geometric_hahn_banach_point_open`: One set is open, the other is a singleton. Weak separation. * `geometric_hahn_banach_open_open`: Both sets are open. Semistrict separation. * `geometric_hahn_banach_compact_closed`, `geometric_hahn_banach_closed_compact`: One set is closed, the other one is compact. Strict separation. * `geometric_hahn_banach_point_closed`, `geometric_hahn_banach_closed_point`: One set is closed, the other one is a singleton. Strict separation. * `geometric_hahn_banach_point_point`: Both sets are singletons. Strict separation. ## TODO * Eidelheit's theorem * `Convex ℝ s → interior (closure s) ⊆ s` -/ open Set open Pointwise variable {𝕜 E : Type*} /-- Given a set `s` which is a convex neighbourhood of `0` and a point `x₀` outside of it, there is a continuous linear functional `f` separating `x₀` and `s`, in the sense that it sends `x₀` to 1 and all of `s` to values strictly below `1`. -/ theorem separate_convex_open_set [TopologicalSpace E] [AddCommGroup E] [IsTopologicalAddGroup E] [Module ℝ E] [ContinuousSMul ℝ E] {s : Set E} (hs₀ : (0 : E) ∈ s) (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) {x₀ : E} (hx₀ : x₀ ∉ s) : ∃ f : E →L[ℝ] ℝ, f x₀ = 1 ∧ ∀ x ∈ s, f x < 1 := by let f : E →ₗ.[ℝ] ℝ := LinearPMap.mkSpanSingleton x₀ 1 (ne_of_mem_of_not_mem hs₀ hx₀).symm have := exists_extension_of_le_sublinear f (gauge s) (fun c hc => gauge_smul_of_nonneg hc.le) (gauge_add_le hs₁ <| absorbent_nhds_zero <| hs₂.mem_nhds hs₀) ?_ · obtain ⟨φ, hφ₁, hφ₂⟩ := this have hφ₃ : φ x₀ = 1 := by rw [← f.domain.coe_mk x₀ (Submodule.mem_span_singleton_self _), hφ₁, LinearPMap.mkSpanSingleton'_apply_self] have hφ₄ : ∀ x ∈ s, φ x < 1 := fun x hx => (hφ₂ x).trans_lt (gauge_lt_one_of_mem_of_isOpen hs₂ hx) refine ⟨⟨φ, ?_⟩, hφ₃, hφ₄⟩ refine φ.continuous_of_nonzero_on_open _ (hs₂.vadd (-x₀)) (Nonempty.vadd_set ⟨0, hs₀⟩) (vadd_set_subset_iff.mpr fun x hx => ?_) change φ (-x₀ + x) ≠ 0 rw [map_add, map_neg] specialize hφ₄ x hx linarith rintro ⟨x, hx⟩ obtain ⟨y, rfl⟩ := Submodule.mem_span_singleton.1 hx rw [LinearPMap.mkSpanSingleton'_apply] simp only [mul_one, Algebra.id.smul_eq_mul, Submodule.coe_mk] obtain h | h := le_or_lt y 0 · exact h.trans (gauge_nonneg _) · rw [gauge_smul_of_nonneg h.le, smul_eq_mul, le_mul_iff_one_le_right h] exact one_le_gauge_of_not_mem (hs₁.starConvex hs₀) (absorbent_nhds_zero <| hs₂.mem_nhds hs₀).absorbs hx₀ variable [TopologicalSpace E] [AddCommGroup E] [Module ℝ E] {s t : Set E} {x y : E} section variable [IsTopologicalAddGroup E] [ContinuousSMul ℝ E] /-- A version of the **Hahn-Banach theorem**: given disjoint convex sets `s`, `t` where `s` is open, there is a continuous linear functional which separates them. -/ theorem geometric_hahn_banach_open (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) (ht : Convex ℝ t) (disj : Disjoint s t) : ∃ (f : E →L[ℝ] ℝ) (u : ℝ), (∀ a ∈ s, f a < u) ∧ ∀ b ∈ t, u ≤ f b := by obtain rfl | ⟨a₀, ha₀⟩ := s.eq_empty_or_nonempty · exact ⟨0, 0, by simp, fun b _hb => le_rfl⟩ obtain rfl | ⟨b₀, hb₀⟩ := t.eq_empty_or_nonempty · exact ⟨0, 1, fun a _ha => zero_lt_one, by simp⟩ let x₀ := b₀ - a₀ let C := x₀ +ᵥ (s - t) have : (0 : E) ∈ C := ⟨a₀ - b₀, sub_mem_sub ha₀ hb₀, by simp_rw [x₀, vadd_eq_add, sub_add_sub_cancel', sub_self]⟩ have : Convex ℝ C := (hs₁.sub ht).vadd _ have : x₀ ∉ C := by intro hx₀ rw [← add_zero x₀] at hx₀ exact disj.zero_not_mem_sub_set (vadd_mem_vadd_set_iff.1 hx₀) obtain ⟨f, hf₁, hf₂⟩ := separate_convex_open_set ‹0 ∈ C› ‹_› (hs₂.sub_right.vadd _) ‹x₀ ∉ C› have : f b₀ = f a₀ + 1 := by simp [x₀, ← hf₁] have forall_le : ∀ a ∈ s, ∀ b ∈ t, f a ≤ f b := by intro a ha b hb have := hf₂ (x₀ + (a - b)) (vadd_mem_vadd_set <| sub_mem_sub ha hb) simp only [f.map_add, f.map_sub, hf₁] at this linarith refine ⟨f, sInf (f '' t), image_subset_iff.1 (?_ : f '' s ⊆ Iio (sInf (f '' t))), fun b hb => ?_⟩ · rw [← interior_Iic] refine interior_maximal (image_subset_iff.2 fun a ha => ?_) (f.isOpenMap_of_ne_zero ?_ _ hs₂) · exact le_csInf (Nonempty.image _ ⟨_, hb₀⟩) (forall_mem_image.2 <| forall_le _ ha) · rintro rfl simp at hf₁ · exact csInf_le ⟨f a₀, forall_mem_image.2 <| forall_le _ ha₀⟩ (mem_image_of_mem _ hb) theorem geometric_hahn_banach_open_point (hs₁ : Convex ℝ s) (hs₂ : IsOpen s) (disj : x ∉ s) : ∃ f : E →L[ℝ] ℝ, ∀ a ∈ s, f a < f x := let ⟨f, _s, hs, hx⟩ := geometric_hahn_banach_open hs₁ hs₂ (convex_singleton x) (disjoint_singleton_right.2 disj) ⟨f, fun a ha => lt_of_lt_of_le (hs a ha) (hx x (mem_singleton _))⟩
theorem geometric_hahn_banach_point_open (ht₁ : Convex ℝ t) (ht₂ : IsOpen t) (disj : x ∉ t) : ∃ f : E →L[ℝ] ℝ, ∀ b ∈ t, f x < f b := let ⟨f, hf⟩ := geometric_hahn_banach_open_point ht₁ ht₂ disj
Mathlib/Analysis/NormedSpace/HahnBanach/Separation.lean
122
125
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl, Sander Dahmen, Kim Morrison -/ import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Basis Cardinal Function Module Set Submodule /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by nontriviality R constructor · contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank · intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] : 0 < Module.rank R M := have := Module.nontrivial R M (pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le (Free.chooseBasis R M).linearIndependent.cardinal_le_rank variable [Nontrivial R] section variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr ‹_› end variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ @[nontriviality] theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ @[simp] theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _ variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : ∃ b : M, b ∈ s ∧ b ≠ 0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm section variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Fintype ι := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M) (h : Module.rank R M < ℵ₀) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) end namespace LinearIndependent variable [StrongRankCondition R] theorem cardinalMk_le_finrank [Module.Finite R M] {ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank @[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) : Fintype.card ι ≤ finrank R M := by simpa using h.cardinalMk_le_finrank theorem finset_card_le_finrank [Module.Finite R M] {b : Finset M} (h : LinearIndependent R (fun x => x : b → M)) : b.card ≤ finrank R M := by rw [← Fintype.card_coe] exact h.fintype_card_le_finrank theorem lt_aleph0_of_finite {ι : Type w} [Module.Finite R M] {v : ι → M} (h : LinearIndependent R v) : #ι < ℵ₀ := by apply Cardinal.lift_lt.1 apply lt_of_le_of_lt · apply h.cardinal_lift_le_rank · rw [← finrank_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_natCast] apply Cardinal.nat_lt_aleph0 theorem finite [Module.Finite R M] {ι : Type*} {f : ι → M} (h : LinearIndependent R f) : Finite ι := Cardinal.lt_aleph0_iff_finite.1 <| h.lt_aleph0_of_finite theorem setFinite [Module.Finite R M] {b : Set M} (h : LinearIndependent R fun x : b => (x : M)) : b.Finite := Cardinal.lt_aleph0_iff_set_finite.mp h.lt_aleph0_of_finite end LinearIndependent lemma exists_set_linearIndependent_of_lt_rank {n : Cardinal} (hn : n < Module.rank R M) : ∃ s : Set M, #s = n ∧ LinearIndepOn R id s := by obtain ⟨⟨s, hs⟩, hs'⟩ := exists_lt_of_lt_ciSup' (hn.trans_eq (Module.rank_def R M)) obtain ⟨t, ht, ht'⟩ := le_mk_iff_exists_subset.mp hs'.le exact ⟨t, ht', hs.mono ht⟩ lemma exists_finset_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndepOn R id (s : Set M) := by have := nonempty_linearIndependent_set rcases hn.eq_or_lt with h | h · obtain ⟨⟨s, hs⟩, hs'⟩ := Cardinal.exists_eq_natCast_of_iSup_eq _ (Cardinal.bddAbove_range _) _ (h.trans (Module.rank_def R M)).symm have : Finite s := lt_aleph0_iff_finite.mp (hs' ▸ nat_lt_aleph0 n) cases nonempty_fintype s refine ⟨s.toFinset, by simpa using hs', by simpa⟩ · obtain ⟨s, hs, hs'⟩ := exists_set_linearIndependent_of_lt_rank h have : Finite s := lt_aleph0_iff_finite.mp (hs ▸ nat_lt_aleph0 n) cases nonempty_fintype s exact ⟨s.toFinset, by simpa using hs, by simpa⟩ lemma exists_linearIndependent_of_le_rank {n : ℕ} (hn : n ≤ Module.rank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_rank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ lemma natCast_le_rank_iff [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ f : Fin n → M, LinearIndependent R f := ⟨exists_linearIndependent_of_le_rank, fun H ↦ by simpa using H.choose_spec.cardinal_lift_le_rank⟩ lemma natCast_le_rank_iff_finset [Nontrivial R] {n : ℕ} : n ≤ Module.rank R M ↔ ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := ⟨exists_finset_linearIndependent_of_le_rank, fun ⟨s, h₁, h₂⟩ ↦ by simpa [h₁] using h₂.cardinal_le_rank⟩ lemma exists_finset_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ s : Finset M, s.card = n ∧ LinearIndependent R ((↑) : s → M) := by by_cases h : finrank R M = 0 · rw [le_zero_iff.mp (hn.trans_eq h)] exact ⟨∅, rfl, by convert linearIndependent_empty R M using 2 <;> aesop⟩ exact exists_finset_linearIndependent_of_le_rank ((Nat.cast_le.mpr hn).trans_eq (cast_toNat_of_lt_aleph0 (toNat_ne_zero.mp h).2)) lemma exists_linearIndependent_of_le_finrank {n : ℕ} (hn : n ≤ finrank R M) : ∃ f : Fin n → M, LinearIndependent R f := have ⟨_, hs, hs'⟩ := exists_finset_linearIndependent_of_le_finrank hn ⟨_, (linearIndependent_equiv (Finset.equivFinOfCardEq hs).symm).mpr hs'⟩ variable [Module.Finite R M] [StrongRankCondition R] in theorem Module.Finite.not_linearIndependent_of_infinite {ι : Type*} [Infinite ι] (v : ι → M) : ¬LinearIndependent R v := mt LinearIndependent.finite <| @not_finite _ _ section variable [NoZeroSMulDivisors R M] theorem iSupIndep.subtype_ne_bot_le_rank [Nontrivial R] {V : ι → Submodule R M} (hV : iSupIndep V) : Cardinal.lift.{v} #{ i : ι // V i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := by set I := { i : ι // V i ≠ ⊥ } have hI : ∀ i : I, ∃ v ∈ V i, v ≠ (0 : M) := by intro i rw [← Submodule.ne_bot_iff] exact i.prop choose v hvV hv using hI have : LinearIndependent R v := (hV.comp Subtype.coe_injective).linearIndependent _ hvV hv exact this.cardinal_lift_le_rank @[deprecated (since := "2024-11-24")] alias CompleteLattice.Independent.subtype_ne_bot_le_rank := iSupIndep.subtype_ne_bot_le_rank variable [Module.Finite R M] [StrongRankCondition R] theorem iSupIndep.subtype_ne_bot_le_finrank_aux {p : ι → Submodule R M} (hp : iSupIndep p) : #{ i // p i ≠ ⊥ } ≤ (finrank R M : Cardinal.{w}) := by suffices Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{v} (finrank R M : Cardinal.{w}) by rwa [Cardinal.lift_le] at this calc Cardinal.lift.{v} #{ i // p i ≠ ⊥ } ≤ Cardinal.lift.{w} (Module.rank R M) := hp.subtype_ne_bot_le_rank _ = Cardinal.lift.{w} (finrank R M : Cardinal.{v}) := by rw [finrank_eq_rank] _ = Cardinal.lift.{v} (finrank R M : Cardinal.{w}) := by simp /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is finite. -/ noncomputable def iSupIndep.fintypeNeBotOfFiniteDimensional {p : ι → Submodule R M} (hp : iSupIndep p) : Fintype { i : ι // p i ≠ ⊥ } := by suffices #{ i // p i ≠ ⊥ } < (ℵ₀ : Cardinal.{w}) by rw [Cardinal.lt_aleph0_iff_fintype] at this exact this.some refine lt_of_le_of_lt hp.subtype_ne_bot_le_finrank_aux ?_ simp [Cardinal.nat_lt_aleph0] /-- If `p` is an independent family of submodules of a `R`-finite module `M`, then the number of nontrivial subspaces in the family `p` is bounded above by the dimension of `M`. Note that the `Fintype` hypothesis required here can be provided by `iSupIndep.fintypeNeBotOfFiniteDimensional`. -/ theorem iSupIndep.subtype_ne_bot_le_finrank {p : ι → Submodule R M} (hp : iSupIndep p) [Fintype { i // p i ≠ ⊥ }] : Fintype.card { i // p i ≠ ⊥ } ≤ finrank R M := by simpa using hp.subtype_ne_bot_le_finrank_aux end variable [Module.Finite R M] [StrongRankCondition R] section open Finset /-- If a finset has cardinality larger than the rank of a module, then there is a nontrivial linear relation amongst its elements. -/ theorem Module.exists_nontrivial_relation_of_finrank_lt_card {t : Finset M} (h : finrank R M < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by obtain ⟨g, sum, z, nonzero⟩ := Fintype.not_linearIndependent_iff.mp (mt LinearIndependent.finset_card_le_finrank h.not_le) refine ⟨Subtype.val.extend g 0, ?_, z, z.2, by rwa [Subtype.val_injective.extend_apply]⟩ rw [← Finset.sum_finset_coe]; convert sum; apply Subtype.val_injective.extend_apply /-- If a finset has cardinality larger than `finrank + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ theorem Module.exists_nontrivial_relation_sum_zero_of_finrank_succ_lt_card {t : Finset M} (h : finrank R M + 1 < t.card) : ∃ f : M → R, ∑ e ∈ t, f e • e = 0 ∧ ∑ e ∈ t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := by -- Pick an element x₀ ∈ t, obtain ⟨x₀, x₀_mem⟩ := card_pos.1 ((Nat.succ_pos _).trans h) -- and apply the previous lemma to the {xᵢ - x₀} let shift : M ↪ M := ⟨(· - x₀), sub_left_injective⟩ classical let t' := (t.erase x₀).map shift have h' : finrank R M < t'.card := by rw [card_map, card_erase_of_mem x₀_mem] exact Nat.lt_pred_iff.mpr h -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_finrank_lt_card h' -- Then obtain `f` by translating back by `x₀`, -- and setting the value of `f` at `x₀` to ensure `∑ e ∈ t, f e = 0`. let f : M → R := fun z ↦ if z = x₀ then -∑ z ∈ t.erase x₀, g (z - x₀) else g (z - x₀) refine ⟨f, ?_, ?_, ?_⟩ -- After this, it's a matter of verifying the properties, -- based on the corresponding properties for `g`. · rw [sum_map, Embedding.coeFn_mk] at gsum simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, neg_smul, sum_smul, ← sub_eq_add_neg, ← sum_sub_distrib, ← gsum, smul_sub] refine sum_congr rfl fun x x_mem ↦ ?_ rw [if_neg (mem_erase.mp x_mem).1] · simp_rw [f, ← t.sum_erase_add _ x₀_mem, if_pos, add_neg_eq_zero] exact sum_congr rfl fun x x_mem ↦ if_neg (mem_erase.mp x_mem).1 · obtain ⟨x₁, x₁_mem', rfl⟩ := Finset.mem_map.mp x₁_mem have := mem_erase.mp x₁_mem' exact ⟨x₁, by simpa only [f, Embedding.coeFn_mk, sub_add_cancel, this.2, true_and, if_neg this.1]⟩ end end Finite section FinrankZero section variable [Nontrivial R] /-- A (finite dimensional) space that is a subsingleton has zero `finrank`. -/ @[nontriviality] theorem Module.finrank_zero_of_subsingleton [Subsingleton M] : finrank R M = 0 := by rw [finrank, rank_subsingleton', map_zero] lemma LinearIndependent.finrank_eq_zero_of_infinite {ι} [Infinite ι] {v : ι → M} (hv : LinearIndependent R v) : finrank R M = 0 := toNat_eq_zero.mpr <| .inr hv.aleph0_le_rank section variable [NoZeroSMulDivisors R M] /-- A finite dimensional space is nontrivial if it has positive `finrank`. -/ theorem Module.nontrivial_of_finrank_pos (h : 0 < finrank R M) : Nontrivial M := rank_pos_iff_nontrivial.mp (lt_rank_of_lt_finrank h) /-- A finite dimensional space is nontrivial if it has `finrank` equal to the successor of a natural number. -/ theorem Module.nontrivial_of_finrank_eq_succ {n : ℕ} (hn : finrank R M = n.succ) : Nontrivial M := nontrivial_of_finrank_pos (R := R) (by rw [hn]; exact n.succ_pos) end variable (R M) @[simp] theorem finrank_bot : finrank R (⊥ : Submodule R M) = 0 := finrank_eq_of_rank_eq (rank_bot _ _) end section StrongRankCondition variable [StrongRankCondition R] [Module.Finite R M] /-- A finite rank torsion-free module has positive `finrank` iff it has a nonzero element. -/ theorem Module.finrank_pos_iff_exists_ne_zero [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ ∃ x : M, x ≠ 0 := by rw [← @rank_pos_iff_exists_ne_zero R M, ← finrank_eq_rank] norm_cast /-- An `R`-finite torsion-free module has positive `finrank` iff it is nontrivial. -/ theorem Module.finrank_pos_iff [NoZeroSMulDivisors R M] : 0 < finrank R M ↔ Nontrivial M := by rw [← rank_pos_iff_nontrivial (R := R), ← finrank_eq_rank] norm_cast /-- A nontrivial finite dimensional space has positive `finrank`. -/ theorem Module.finrank_pos [NoZeroSMulDivisors R M] [h : Nontrivial M] : 0 < finrank R M := finrank_pos_iff.mpr h /-- See `Module.finrank_zero_iff` for the stronger version with `NoZeroSMulDivisors R M`. -/ theorem Module.finrank_eq_zero_iff : finrank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by rw [← rank_eq_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- A finite dimensional space has zero `finrank` iff it is a subsingleton. This is the `finrank` version of `rank_zero_iff`. -/ theorem Module.finrank_zero_iff [NoZeroSMulDivisors R M] : finrank R M = 0 ↔ Subsingleton M := by rw [← rank_zero_iff (R := R), ← finrank_eq_rank] norm_cast /-- Similar to `rank_quotient_add_rank_le` but for `finrank` and a finite `M`. -/ lemma Module.finrank_quotient_add_finrank_le (N : Submodule R M) : finrank R (M ⧸ N) + finrank R N ≤ finrank R M := by haveI := nontrivial_of_invariantBasisNumber R have := rank_quotient_add_rank_le N rw [← finrank_eq_rank R M, ← finrank_eq_rank R, ← N.finrank_eq_rank] at this exact mod_cast this end StrongRankCondition theorem Module.finrank_eq_zero_of_rank_eq_zero (h : Module.rank R M = 0) : finrank R M = 0 := by
delta finrank rw [h, zero_toNat] theorem Submodule.bot_eq_top_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) :
Mathlib/LinearAlgebra/Dimension/Finite.lean
453
456
/- Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jordan Brown, Thomas Browning, Patrick Lutz -/ import Mathlib.GroupTheory.Abelianization import Mathlib.GroupTheory.Perm.ViaEmbedding import Mathlib.GroupTheory.Subgroup.Simple /-! # Solvable Groups In this file we introduce the notion of a solvable group. We define a solvable group as one whose derived series is eventually trivial. This requires defining the commutator of two subgroups and the derived series of a group. ## Main definitions * `derivedSeries G n` : the `n`th term in the derived series of `G`, defined by iterating `general_commutator` starting with the top subgroup * `IsSolvable G` : the group `G` is solvable -/ open Subgroup variable {G G' : Type*} [Group G] [Group G'] {f : G →* G'} section derivedSeries variable (G) /-- The derived series of the group `G`, obtained by starting from the subgroup `⊤` and repeatedly taking the commutator of the previous subgroup with itself for `n` times. -/ def derivedSeries : ℕ → Subgroup G | 0 => ⊤ | n + 1 => ⁅derivedSeries n, derivedSeries n⁆ @[simp] theorem derivedSeries_zero : derivedSeries G 0 = ⊤ := rfl @[simp] theorem derivedSeries_succ (n : ℕ) : derivedSeries G (n + 1) = ⁅derivedSeries G n, derivedSeries G n⁆ := rfl theorem derivedSeries_normal (n : ℕ) : (derivedSeries G n).Normal := by induction n with | zero => exact (⊤ : Subgroup G).normal_of_characteristic | succ n ih => exact Subgroup.commutator_normal (derivedSeries G n) (derivedSeries G n) @[simp 1100] theorem derivedSeries_one : derivedSeries G 1 = commutator G := rfl end derivedSeries section CommutatorMap section DerivedSeriesMap variable (f) in theorem map_derivedSeries_le_derivedSeries (n : ℕ) : (derivedSeries G n).map f ≤ derivedSeries G' n := by induction n with | zero => exact le_top | succ n ih => simp only [derivedSeries_succ, map_commutator, commutator_mono, ih] theorem derivedSeries_le_map_derivedSeries (hf : Function.Surjective f) (n : ℕ) : derivedSeries G' n ≤ (derivedSeries G n).map f := by induction n with | zero => exact (map_top_of_surjective f hf).ge | succ n ih => exact commutator_le_map_commutator ih ih theorem map_derivedSeries_eq (hf : Function.Surjective f) (n : ℕ) : (derivedSeries G n).map f = derivedSeries G' n := le_antisymm (map_derivedSeries_le_derivedSeries f n) (derivedSeries_le_map_derivedSeries hf n) end DerivedSeriesMap end CommutatorMap section Solvable
variable (G) /-- A group `G` is solvable if its derived series is eventually trivial. We use this definition because it's the most convenient one to work with. -/
Mathlib/GroupTheory/Solvable.lean
85
89
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.LeftHomology import Mathlib.CategoryTheory.Limits.Opposites /-! # Right Homology of short complexes In this file, we define the dual notions to those defined in `Algebra.Homology.ShortComplex.LeftHomology`. In particular, if `S : ShortComplex C` is a short complex consisting of two composable maps `f : X₁ ⟶ X₂` and `g : X₂ ⟶ X₃` such that `f ≫ g = 0`, we define `h : S.RightHomologyData` to be the datum of morphisms `p : X₂ ⟶ Q` and `ι : H ⟶ Q` such that `Q` identifies to the cokernel of `f` and `H` to the kernel of the induced map `g' : Q ⟶ X₃`. When such a `S.RightHomologyData` exists, we shall say that `[S.HasRightHomology]` and we define `S.rightHomology` to be the `H` field of a chosen right homology data. Similarly, we define `S.opcycles` to be the `Q` field. In `Homology.lean`, when `S` has two compatible left and right homology data (i.e. they give the same `H` up to a canonical isomorphism), we shall define `[S.HasHomology]` and `S.homology`. -/ namespace CategoryTheory open Category Limits namespace ShortComplex variable {C : Type*} [Category C] [HasZeroMorphisms C] (S : ShortComplex C) {S₁ S₂ S₃ : ShortComplex C} /-- A right homology data for a short complex `S` consists of morphisms `p : S.X₂ ⟶ Q` and `ι : H ⟶ Q` such that `p` identifies `Q` to the kernel of `f : S.X₁ ⟶ S.X₂`, and that `ι` identifies `H` to the kernel of the induced map `g' : Q ⟶ S.X₃` -/ structure RightHomologyData where /-- a choice of cokernel of `S.f : S.X₁ ⟶ S.X₂` -/ Q : C /-- a choice of kernel of the induced morphism `S.g' : S.Q ⟶ X₃` -/ H : C /-- the projection from `S.X₂` -/ p : S.X₂ ⟶ Q /-- the inclusion of the (right) homology in the chosen cokernel of `S.f` -/ ι : H ⟶ Q /-- the cokernel condition for `p` -/ wp : S.f ≫ p = 0 /-- `p : S.X₂ ⟶ Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂` -/ hp : IsColimit (CokernelCofork.ofπ p wp) /-- the kernel condition for `ι` -/ wι : ι ≫ hp.desc (CokernelCofork.ofπ _ S.zero) = 0 /-- `ι : H ⟶ Q` is a kernel of `S.g' : Q ⟶ S.X₃` -/ hι : IsLimit (KernelFork.ofι ι wι) initialize_simps_projections RightHomologyData (-hp, -hι) namespace RightHomologyData /-- The chosen cokernels and kernels of the limits API give a `RightHomologyData` -/ @[simps] noncomputable def ofHasCokernelOfHasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.RightHomologyData := { Q := cokernel S.f, H := kernel (cokernel.desc S.f S.g S.zero), p := cokernel.π _, ι := kernel.ι _, wp := cokernel.condition _, hp := cokernelIsCokernel _, wι := kernel.condition _, hι := kernelIsKernel _, } attribute [reassoc (attr := simp)] wp wι variable {S} variable (h : S.RightHomologyData) {A : C} instance : Epi h.p := ⟨fun _ _ => Cofork.IsColimit.hom_ext h.hp⟩ instance : Mono h.ι := ⟨fun _ _ => Fork.IsLimit.hom_ext h.hι⟩ /-- Any morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0` descends to a morphism `Q ⟶ A` -/ def descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.Q ⟶ A := h.hp.desc (CokernelCofork.ofπ k hk) @[reassoc (attr := simp)] lemma p_descQ (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.p ≫ h.descQ k hk = k := h.hp.fac _ WalkingParallelPair.one /-- The morphism from the (right) homology attached to a morphism `k : S.X₂ ⟶ A` such that `S.f ≫ k = 0`. -/ @[simp] def descH (k : S.X₂ ⟶ A) (hk : S.f ≫ k = 0) : h.H ⟶ A := h.ι ≫ h.descQ k hk /-- The morphism `h.Q ⟶ S.X₃` induced by `S.g : S.X₂ ⟶ S.X₃` and the fact that `h.Q` is a cokernel of `S.f : S.X₁ ⟶ S.X₂`. -/ def g' : h.Q ⟶ S.X₃ := h.descQ S.g S.zero @[reassoc (attr := simp)] lemma p_g' : h.p ≫ h.g' = S.g := p_descQ _ _ _ @[reassoc (attr := simp)] lemma ι_g' : h.ι ≫ h.g' = 0 := h.wι @[reassoc] lemma ι_descQ_eq_zero_of_boundary (k : S.X₂ ⟶ A) (x : S.X₃ ⟶ A) (hx : k = S.g ≫ x) : h.ι ≫ h.descQ k (by rw [hx, S.zero_assoc, zero_comp]) = 0 := by rw [show 0 = h.ι ≫ h.g' ≫ x by simp] congr 1 simp only [← cancel_epi h.p, hx, p_descQ, p_g'_assoc] /-- For `h : S.RightHomologyData`, this is a restatement of `h.hι`, saying that `ι : h.H ⟶ h.Q` is a kernel of `h.g' : h.Q ⟶ S.X₃`. -/ def hι' : IsLimit (KernelFork.ofι h.ι h.ι_g') := h.hι /-- The morphism `A ⟶ H` induced by a morphism `k : A ⟶ Q` such that `k ≫ g' = 0` -/ def liftH (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : A ⟶ h.H := h.hι.lift (KernelFork.ofι k hk) @[reassoc (attr := simp)] lemma liftH_ι (k : A ⟶ h.Q) (hk : k ≫ h.g' = 0) : h.liftH k hk ≫ h.ι = k := h.hι.fac (KernelFork.ofι k hk) WalkingParallelPair.zero lemma isIso_p (hf : S.f = 0) : IsIso h.p := ⟨h.descQ (𝟙 S.X₂) (by rw [hf, comp_id]), p_descQ _ _ _, by simp only [← cancel_epi h.p, p_descQ_assoc, id_comp, comp_id]⟩ lemma isIso_ι (hg : S.g = 0) : IsIso h.ι := by have ⟨φ, hφ⟩ := KernelFork.IsLimit.lift' h.hι' (𝟙 _) (by rw [← cancel_epi h.p, id_comp, p_g', comp_zero, hg]) dsimp at hφ exact ⟨φ, by rw [← cancel_mono h.ι, assoc, hφ, comp_id, id_comp], hφ⟩ variable (S) /-- When the first map `S.f` is zero, this is the right homology data on `S` given by any limit kernel fork of `S.g` -/ @[simps] def ofIsLimitKernelFork (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : S.RightHomologyData where Q := S.X₂ H := c.pt p := 𝟙 _ ι := c.ι wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wι := KernelFork.condition _ hι := IsLimit.ofIsoLimit hc (Fork.ext (Iso.refl _) (by simp)) @[simp] lemma ofIsLimitKernelFork_g' (hf : S.f = 0) (c : KernelFork S.g) (hc : IsLimit c) : (ofIsLimitKernelFork S hf c hc).g' = S.g := by rw [← cancel_epi (ofIsLimitKernelFork S hf c hc).p, p_g', ofIsLimitKernelFork_p, id_comp] /-- When the first map `S.f` is zero, this is the right homology data on `S` given by the chosen `kernel S.g` -/ @[simps!] noncomputable def ofHasKernel [HasKernel S.g] (hf : S.f = 0) : S.RightHomologyData := ofIsLimitKernelFork S hf _ (kernelIsKernel _) /-- When the second map `S.g` is zero, this is the right homology data on `S` given by any colimit cokernel cofork of `S.g` -/ @[simps] def ofIsColimitCokernelCofork (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : S.RightHomologyData where Q := c.pt H := c.pt p := c.π ι := 𝟙 _ wp := CokernelCofork.condition _ hp := IsColimit.ofIsoColimit hc (Cofork.ext (Iso.refl _) (by simp)) wι := Cofork.IsColimit.hom_ext hc (by simp [hg]) hι := KernelFork.IsLimit.ofId _ (Cofork.IsColimit.hom_ext hc (by simp [hg])) @[simp] lemma ofIsColimitCokernelCofork_g' (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : (ofIsColimitCokernelCofork S hg c hc).g' = 0 := by rw [← cancel_epi (ofIsColimitCokernelCofork S hg c hc).p, p_g', hg, comp_zero] /-- When the second map `S.g` is zero, this is the right homology data on `S` given by the chosen `cokernel S.f` -/ @[simp] noncomputable def ofHasCokernel [HasCokernel S.f] (hg : S.g = 0) : S.RightHomologyData := ofIsColimitCokernelCofork S hg _ (cokernelIsCokernel _) /-- When both `S.f` and `S.g` are zero, the middle object `S.X₂` gives a right homology data on S -/ @[simps] def ofZeros (hf : S.f = 0) (hg : S.g = 0) : S.RightHomologyData where Q := S.X₂ H := S.X₂ p := 𝟙 _ ι := 𝟙 _ wp := by rw [comp_id, hf] hp := CokernelCofork.IsColimit.ofId _ hf wι := by change 𝟙 _ ≫ S.g = 0 simp only [hg, comp_zero] hι := KernelFork.IsLimit.ofId _ hg @[simp] lemma ofZeros_g' (hf : S.f = 0) (hg : S.g = 0) : (ofZeros S hf hg).g' = 0 := by rw [← cancel_epi ((ofZeros S hf hg).p), comp_zero, p_g', hg] end RightHomologyData /-- A short complex `S` has right homology when there exists a `S.RightHomologyData` -/ class HasRightHomology : Prop where condition : Nonempty S.RightHomologyData /-- A chosen `S.RightHomologyData` for a short complex `S` that has right homology -/ noncomputable def rightHomologyData [HasRightHomology S] : S.RightHomologyData := HasRightHomology.condition.some variable {S} namespace HasRightHomology lemma mk' (h : S.RightHomologyData) : HasRightHomology S := ⟨Nonempty.intro h⟩ instance of_hasCokernel_of_hasKernel [HasCokernel S.f] [HasKernel (cokernel.desc S.f S.g S.zero)] : S.HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernelOfHasKernel S) instance of_hasKernel {Y Z : C} (g : Y ⟶ Z) (X : C) [HasKernel g] : (ShortComplex.mk (0 : X ⟶ Y) g zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasKernel _ rfl) instance of_hasCokernel {X Y : C} (f : X ⟶ Y) (Z : C) [HasCokernel f] : (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofHasCokernel _ rfl) instance of_zeros (X Y Z : C) : (ShortComplex.mk (0 : X ⟶ Y) (0 : Y ⟶ Z) zero_comp).HasRightHomology := HasRightHomology.mk' (RightHomologyData.ofZeros _ rfl rfl) end HasRightHomology namespace RightHomologyData /-- A right homology data for a short complex `S` induces a left homology data for `S.op`. -/ @[simps] def op (h : S.RightHomologyData) : S.op.LeftHomologyData where K := Opposite.op h.Q H := Opposite.op h.H i := h.p.op π := h.ι.op wi := Quiver.Hom.unop_inj h.wp hi := CokernelCofork.IsColimit.ofπOp _ _ h.hp wπ := Quiver.Hom.unop_inj h.wι hπ := KernelFork.IsLimit.ofιOp _ _ h.hι @[simp] lemma op_f' (h : S.RightHomologyData) : h.op.f' = h.g'.op := rfl /-- A right homology data for a short complex `S` in the opposite category induces a left homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.RightHomologyData) : S.unop.LeftHomologyData where K := Opposite.unop h.Q H := Opposite.unop h.H i := h.p.unop π := h.ι.unop wi := Quiver.Hom.op_inj h.wp hi := CokernelCofork.IsColimit.ofπUnop _ _ h.hp wπ := Quiver.Hom.op_inj h.wι hπ := KernelFork.IsLimit.ofιUnop _ _ h.hι @[simp] lemma unop_f' {S : ShortComplex Cᵒᵖ} (h : S.RightHomologyData) : h.unop.f' = h.g'.unop := rfl end RightHomologyData namespace LeftHomologyData /-- A left homology data for a short complex `S` induces a right homology data for `S.op`. -/ @[simps] def op (h : S.LeftHomologyData) : S.op.RightHomologyData where Q := Opposite.op h.K H := Opposite.op h.H p := h.i.op ι := h.π.op wp := Quiver.Hom.unop_inj h.wi hp := KernelFork.IsLimit.ofιOp _ _ h.hi wι := Quiver.Hom.unop_inj h.wπ hι := CokernelCofork.IsColimit.ofπOp _ _ h.hπ @[simp] lemma op_g' (h : S.LeftHomologyData) : h.op.g' = h.f'.op := rfl /-- A left homology data for a short complex `S` in the opposite category induces a right homology data for `S.unop`. -/ @[simps] def unop {S : ShortComplex Cᵒᵖ} (h : S.LeftHomologyData) : S.unop.RightHomologyData where Q := Opposite.unop h.K H := Opposite.unop h.H p := h.i.unop ι := h.π.unop wp := Quiver.Hom.op_inj h.wi hp := KernelFork.IsLimit.ofιUnop _ _ h.hi wι := Quiver.Hom.op_inj h.wπ hι := CokernelCofork.IsColimit.ofπUnop _ _ h.hπ @[simp] lemma unop_g' {S : ShortComplex Cᵒᵖ} (h : S.LeftHomologyData) : h.unop.g' = h.f'.unop := rfl end LeftHomologyData instance [S.HasLeftHomology] : HasRightHomology S.op := HasRightHomology.mk' S.leftHomologyData.op instance [S.HasRightHomology] : HasLeftHomology S.op := HasLeftHomology.mk' S.rightHomologyData.op lemma hasLeftHomology_iff_op (S : ShortComplex C) : S.HasLeftHomology ↔ S.op.HasRightHomology := ⟨fun _ => inferInstance, fun _ => HasLeftHomology.mk' S.op.rightHomologyData.unop⟩ lemma hasRightHomology_iff_op (S : ShortComplex C) : S.HasRightHomology ↔ S.op.HasLeftHomology := ⟨fun _ => inferInstance, fun _ => HasRightHomology.mk' S.op.leftHomologyData.unop⟩ lemma hasLeftHomology_iff_unop (S : ShortComplex Cᵒᵖ) : S.HasLeftHomology ↔ S.unop.HasRightHomology := S.unop.hasRightHomology_iff_op.symm lemma hasRightHomology_iff_unop (S : ShortComplex Cᵒᵖ) : S.HasRightHomology ↔ S.unop.HasLeftHomology := S.unop.hasLeftHomology_iff_op.symm section variable (φ : S₁ ⟶ S₂) (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) /-- Given right homology data `h₁` and `h₂` for two short complexes `S₁` and `S₂`, a `RightHomologyMapData` for a morphism `φ : S₁ ⟶ S₂` consists of a description of the induced morphisms on the `Q` (opcycles) and `H` (right homology) fields of `h₁` and `h₂`. -/ structure RightHomologyMapData where /-- the induced map on opcycles -/ φQ : h₁.Q ⟶ h₂.Q /-- the induced map on right homology -/ φH : h₁.H ⟶ h₂.H /-- commutation with `p` -/ commp : h₁.p ≫ φQ = φ.τ₂ ≫ h₂.p := by aesop_cat /-- commutation with `g'` -/ commg' : φQ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by aesop_cat /-- commutation with `ι` -/ commι : φH ≫ h₂.ι = h₁.ι ≫ φQ := by aesop_cat namespace RightHomologyMapData attribute [reassoc (attr := simp)] commp commg' commι /-- The right homology map data associated to the zero morphism between two short complexes. -/ @[simps] def zero (h₁ : S₁.RightHomologyData) (h₂ : S₂.RightHomologyData) : RightHomologyMapData 0 h₁ h₂ where φQ := 0 φH := 0 /-- The right homology map data associated to the identity morphism of a short complex. -/ @[simps] def id (h : S.RightHomologyData) : RightHomologyMapData (𝟙 S) h h where φQ := 𝟙 _ φH := 𝟙 _ /-- The composition of right homology map data. -/ @[simps] def comp {φ : S₁ ⟶ S₂} {φ' : S₂ ⟶ S₃} {h₁ : S₁.RightHomologyData} {h₂ : S₂.RightHomologyData} {h₃ : S₃.RightHomologyData} (ψ : RightHomologyMapData φ h₁ h₂) (ψ' : RightHomologyMapData φ' h₂ h₃) : RightHomologyMapData (φ ≫ φ') h₁ h₃ where φQ := ψ.φQ ≫ ψ'.φQ φH := ψ.φH ≫ ψ'.φH instance : Subsingleton (RightHomologyMapData φ h₁ h₂) := ⟨fun ψ₁ ψ₂ => by have hQ : ψ₁.φQ = ψ₂.φQ := by rw [← cancel_epi h₁.p, commp, commp] have hH : ψ₁.φH = ψ₂.φH := by rw [← cancel_mono h₂.ι, commι, commι, hQ] cases ψ₁ cases ψ₂ congr⟩ instance : Inhabited (RightHomologyMapData φ h₁ h₂) := ⟨by let φQ : h₁.Q ⟶ h₂.Q := h₁.descQ (φ.τ₂ ≫ h₂.p) (by rw [← φ.comm₁₂_assoc, h₂.wp, comp_zero]) have commg' : φQ ≫ h₂.g' = h₁.g' ≫ φ.τ₃ := by rw [← cancel_epi h₁.p, RightHomologyData.p_descQ_assoc, assoc, RightHomologyData.p_g', φ.comm₂₃, RightHomologyData.p_g'_assoc] let φH : h₁.H ⟶ h₂.H := h₂.liftH (h₁.ι ≫ φQ) (by rw [assoc, commg', RightHomologyData.ι_g'_assoc, zero_comp]) exact ⟨φQ, φH, by simp [φQ], commg', by simp [φH]⟩⟩ instance : Unique (RightHomologyMapData φ h₁ h₂) := Unique.mk' _ variable {φ h₁ h₂} lemma congr_φH {γ₁ γ₂ : RightHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φH = γ₂.φH := by rw [eq] lemma congr_φQ {γ₁ γ₂ : RightHomologyMapData φ h₁ h₂} (eq : γ₁ = γ₂) : γ₁.φQ = γ₂.φQ := by rw [eq] /-- When `S₁.f`, `S₁.g`, `S₂.f` and `S₂.g` are all zero, the action on right homology of a morphism `φ : S₁ ⟶ S₂` is given by the action `φ.τ₂` on the middle objects. -/ @[simps] def ofZeros (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (hg₁ : S₁.g = 0) (hf₂ : S₂.f = 0) (hg₂ : S₂.g = 0) : RightHomologyMapData φ (RightHomologyData.ofZeros S₁ hf₁ hg₁) (RightHomologyData.ofZeros S₂ hf₂ hg₂) where φQ := φ.τ₂ φH := φ.τ₂ /-- When `S₁.f` and `S₂.f` are zero and we have chosen limit kernel forks `c₁` and `c₂` for `S₁.g` and `S₂.g` respectively, the action on right homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι`. -/ @[simps] def ofIsLimitKernelFork (φ : S₁ ⟶ S₂) (hf₁ : S₁.f = 0) (c₁ : KernelFork S₁.g) (hc₁ : IsLimit c₁) (hf₂ : S₂.f = 0) (c₂ : KernelFork S₂.g) (hc₂ : IsLimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : c₁.ι ≫ φ.τ₂ = f ≫ c₂.ι) : RightHomologyMapData φ (RightHomologyData.ofIsLimitKernelFork S₁ hf₁ c₁ hc₁) (RightHomologyData.ofIsLimitKernelFork S₂ hf₂ c₂ hc₂) where φQ := φ.τ₂ φH := f commg' := by simp only [RightHomologyData.ofIsLimitKernelFork_g', φ.comm₂₃] commι := comm.symm /-- When `S₁.g` and `S₂.g` are zero and we have chosen colimit cokernel coforks `c₁` and `c₂` for `S₁.f` and `S₂.f` respectively, the action on right homology of a morphism `φ : S₁ ⟶ S₂` of short complexes is given by the unique morphism `f : c₁.pt ⟶ c₂.pt` such that `φ.τ₂ ≫ c₂.π = c₁.π ≫ f`. -/ @[simps] def ofIsColimitCokernelCofork (φ : S₁ ⟶ S₂) (hg₁ : S₁.g = 0) (c₁ : CokernelCofork S₁.f) (hc₁ : IsColimit c₁) (hg₂ : S₂.g = 0) (c₂ : CokernelCofork S₂.f) (hc₂ : IsColimit c₂) (f : c₁.pt ⟶ c₂.pt) (comm : φ.τ₂ ≫ c₂.π = c₁.π ≫ f) : RightHomologyMapData φ (RightHomologyData.ofIsColimitCokernelCofork S₁ hg₁ c₁ hc₁) (RightHomologyData.ofIsColimitCokernelCofork S₂ hg₂ c₂ hc₂) where φQ := f φH := f commp := comm.symm variable (S) /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `RightHomologyData.ofIsLimitKernelFork` and `ofZeros` . -/ @[simps] def compatibilityOfZerosOfIsLimitKernelFork (hf : S.f = 0) (hg : S.g = 0) (c : KernelFork S.g) (hc : IsLimit c) : RightHomologyMapData (𝟙 S) (RightHomologyData.ofIsLimitKernelFork S hf c hc) (RightHomologyData.ofZeros S hf hg) where φQ := 𝟙 _ φH := c.ι /-- When both maps `S.f` and `S.g` of a short complex `S` are zero, this is the right homology map data (for the identity of `S`) which relates the right homology data `ofZeros` and `ofIsColimitCokernelCofork`. -/ @[simps] def compatibilityOfZerosOfIsColimitCokernelCofork (hf : S.f = 0) (hg : S.g = 0) (c : CokernelCofork S.f) (hc : IsColimit c) : RightHomologyMapData (𝟙 S) (RightHomologyData.ofZeros S hf hg) (RightHomologyData.ofIsColimitCokernelCofork S hg c hc) where φQ := c.π φH := c.π end RightHomologyMapData end section variable (S) variable [S.HasRightHomology] /-- The right homology of a short complex, given by the `H` field of a chosen right homology data. -/ noncomputable def rightHomology : C := S.rightHomologyData.H -- `S.rightHomology` is the simp normal form. @[simp] lemma rightHomologyData_H : S.rightHomologyData.H = S.rightHomology := rfl /-- The "opcycles" of a short complex, given by the `Q` field of a chosen right homology data. This is the dual notion to cycles. -/ noncomputable def opcycles : C := S.rightHomologyData.Q /-- The canonical map `S.rightHomology ⟶ S.opcycles`. -/ noncomputable def rightHomologyι : S.rightHomology ⟶ S.opcycles := S.rightHomologyData.ι /-- The projection `S.X₂ ⟶ S.opcycles`. -/ noncomputable def pOpcycles : S.X₂ ⟶ S.opcycles := S.rightHomologyData.p /-- The canonical map `S.opcycles ⟶ X₃`. -/ noncomputable def fromOpcycles : S.opcycles ⟶ S.X₃ := S.rightHomologyData.g' @[reassoc (attr := simp)] lemma f_pOpcycles : S.f ≫ S.pOpcycles = 0 := S.rightHomologyData.wp @[reassoc (attr := simp)] lemma p_fromOpcycles : S.pOpcycles ≫ S.fromOpcycles = S.g := S.rightHomologyData.p_g' instance : Epi S.pOpcycles := by dsimp only [pOpcycles] infer_instance instance : Mono S.rightHomologyι := by dsimp only [rightHomologyι] infer_instance lemma rightHomology_ext_iff {A : C} (f₁ f₂ : A ⟶ S.rightHomology) : f₁ = f₂ ↔ f₁ ≫ S.rightHomologyι = f₂ ≫ S.rightHomologyι := by rw [cancel_mono] @[ext] lemma rightHomology_ext {A : C} (f₁ f₂ : A ⟶ S.rightHomology) (h : f₁ ≫ S.rightHomologyι = f₂ ≫ S.rightHomologyι) : f₁ = f₂ := by simpa only [rightHomology_ext_iff] lemma opcycles_ext_iff {A : C} (f₁ f₂ : S.opcycles ⟶ A) : f₁ = f₂ ↔ S.pOpcycles ≫ f₁ = S.pOpcycles ≫ f₂ := by
rw [cancel_epi] @[ext] lemma opcycles_ext {A : C} (f₁ f₂ : S.opcycles ⟶ A)
Mathlib/Algebra/Homology/ShortComplex/RightHomology.lean
527
530
/- 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, Mitchell Lee -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Data.Fintype.BigOperators import Mathlib.Topology.Algebra.InfiniteSum.Defs import Mathlib.Topology.Algebra.Monoid.Defs /-! # Lemmas on infinite sums and products in topological monoids This file contains many simple lemmas on `tsum`, `HasSum` etc, which are placed here in order to keep the basic file of definitions as short as possible. Results requiring a group (rather than monoid) structure on the target should go in `Group.lean`. -/ noncomputable section open Filter Finset Function Topology variable {α β γ : Type*} section HasProd variable [CommMonoid α] [TopologicalSpace α] variable {f g : β → α} {a b : α} /-- Constant one function has product `1` -/ @[to_additive "Constant zero function has sum `0`"] theorem hasProd_one : HasProd (fun _ ↦ 1 : β → α) 1 := by simp [HasProd, tendsto_const_nhds] @[to_additive] theorem hasProd_empty [IsEmpty β] : HasProd f 1 := by convert @hasProd_one α β _ _ @[to_additive] theorem multipliable_one : Multipliable (fun _ ↦ 1 : β → α) := hasProd_one.multipliable @[to_additive] theorem multipliable_empty [IsEmpty β] : Multipliable f := hasProd_empty.multipliable /-- See `multipliable_congr_cofinite` for a version allowing the functions to disagree on a finite set. -/ @[to_additive "See `summable_congr_cofinite` for a version allowing the functions to disagree on a finite set."] theorem multipliable_congr (hfg : ∀ b, f b = g b) : Multipliable f ↔ Multipliable g := iff_of_eq (congr_arg Multipliable <| funext hfg) /-- See `Multipliable.congr_cofinite` for a version allowing the functions to disagree on a finite set. -/ @[to_additive "See `Summable.congr_cofinite` for a version allowing the functions to disagree on a finite set."] theorem Multipliable.congr (hf : Multipliable f) (hfg : ∀ b, f b = g b) : Multipliable g := (multipliable_congr hfg).mp hf @[to_additive] lemma HasProd.congr_fun (hf : HasProd f a) (h : ∀ x : β, g x = f x) : HasProd g a := (funext h : g = f) ▸ hf @[to_additive] theorem HasProd.hasProd_of_prod_eq {g : γ → α} (h_eq : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (hf : HasProd g a) : HasProd f a := le_trans (map_atTop_finset_prod_le_of_prod_eq h_eq) hf @[to_additive] theorem hasProd_iff_hasProd {g : γ → α} (h₁ : ∀ u : Finset γ, ∃ v : Finset β, ∀ v', v ⊆ v' → ∃ u', u ⊆ u' ∧ ∏ x ∈ u', g x = ∏ b ∈ v', f b) (h₂ : ∀ v : Finset β, ∃ u : Finset γ, ∀ u', u ⊆ u' → ∃ v', v ⊆ v' ∧ ∏ b ∈ v', f b = ∏ x ∈ u', g x) : HasProd f a ↔ HasProd g a := ⟨HasProd.hasProd_of_prod_eq h₂, HasProd.hasProd_of_prod_eq h₁⟩ @[to_additive] theorem Function.Injective.multipliable_iff {g : γ → β} (hg : Injective g) (hf : ∀ x ∉ Set.range g, f x = 1) : Multipliable (f ∘ g) ↔ Multipliable f := exists_congr fun _ ↦ hg.hasProd_iff hf @[to_additive (attr := simp)] theorem hasProd_extend_one {g : β → γ} (hg : Injective g) : HasProd (extend g f 1) a ↔ HasProd f a := by rw [← hg.hasProd_iff, extend_comp hg] exact extend_apply' _ _ @[to_additive (attr := simp)] theorem multipliable_extend_one {g : β → γ} (hg : Injective g) : Multipliable (extend g f 1) ↔ Multipliable f := exists_congr fun _ ↦ hasProd_extend_one hg @[to_additive] theorem hasProd_subtype_iff_mulIndicator {s : Set β} : HasProd (f ∘ (↑) : s → α) a ↔ HasProd (s.mulIndicator f) a := by rw [← Set.mulIndicator_range_comp, Subtype.range_coe, hasProd_subtype_iff_of_mulSupport_subset Set.mulSupport_mulIndicator_subset] @[to_additive] theorem multipliable_subtype_iff_mulIndicator {s : Set β} : Multipliable (f ∘ (↑) : s → α) ↔ Multipliable (s.mulIndicator f) := exists_congr fun _ ↦ hasProd_subtype_iff_mulIndicator @[to_additive (attr := simp)] theorem hasProd_subtype_mulSupport : HasProd (f ∘ (↑) : mulSupport f → α) a ↔ HasProd f a := hasProd_subtype_iff_of_mulSupport_subset <| Set.Subset.refl _ @[to_additive] protected theorem Finset.multipliable (s : Finset β) (f : β → α) : Multipliable (f ∘ (↑) : (↑s : Set β) → α) := (s.hasProd f).multipliable @[to_additive] protected theorem Set.Finite.multipliable {s : Set β} (hs : s.Finite) (f : β → α) : Multipliable (f ∘ (↑) : s → α) := by have := hs.toFinset.multipliable f rwa [hs.coe_toFinset] at this @[to_additive] theorem multipliable_of_finite_mulSupport (h : (mulSupport f).Finite) : Multipliable f := by apply multipliable_of_ne_finset_one (s := h.toFinset); simp @[to_additive] lemma Multipliable.of_finite [Finite β] {f : β → α} : Multipliable f := multipliable_of_finite_mulSupport <| Set.finite_univ.subset (Set.subset_univ _) @[to_additive] theorem hasProd_single {f : β → α} (b : β) (hf : ∀ (b') (_ : b' ≠ b), f b' = 1) : HasProd f (f b) := suffices HasProd f (∏ b' ∈ {b}, f b') by simpa using this hasProd_prod_of_ne_finset_one <| by simpa [hf] @[to_additive (attr := simp)] lemma hasProd_unique [Unique β] (f : β → α) : HasProd f (f default) := hasProd_single default (fun _ hb ↦ False.elim <| hb <| Unique.uniq ..) @[to_additive (attr := simp)] lemma hasProd_singleton (m : β) (f : β → α) : HasProd (({m} : Set β).restrict f) (f m) := hasProd_unique (Set.restrict {m} f) @[to_additive] theorem hasProd_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : HasProd (fun b' ↦ if b' = b then a else 1) a := by convert @hasProd_single _ _ _ _ (fun b' ↦ if b' = b then a else 1) b (fun b' hb' ↦ if_neg hb') exact (if_pos rfl).symm @[to_additive] theorem Equiv.hasProd_iff (e : γ ≃ β) : HasProd (f ∘ e) a ↔ HasProd f a := e.injective.hasProd_iff <| by simp @[to_additive] theorem Function.Injective.hasProd_range_iff {g : γ → β} (hg : Injective g) : HasProd (fun x : Set.range g ↦ f x) a ↔ HasProd (f ∘ g) a := (Equiv.ofInjective g hg).hasProd_iff.symm @[to_additive] theorem Equiv.multipliable_iff (e : γ ≃ β) : Multipliable (f ∘ e) ↔ Multipliable f := exists_congr fun _ ↦ e.hasProd_iff @[to_additive] theorem Equiv.hasProd_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : HasProd f a ↔ HasProd g a := by have : (g ∘ (↑)) ∘ e = f ∘ (↑) := funext he rw [← hasProd_subtype_mulSupport, ← this, e.hasProd_iff, hasProd_subtype_mulSupport] @[to_additive] theorem hasProd_iff_hasProd_of_ne_one_bij {g : γ → α} (i : mulSupport g → β) (hi : Injective i) (hf : mulSupport f ⊆ Set.range i) (hfg : ∀ x, f (i x) = g x) : HasProd f a ↔ HasProd g a := Iff.symm <| Equiv.hasProd_iff_of_mulSupport (Equiv.ofBijective (fun x ↦ ⟨i x, fun hx ↦ x.coe_prop <| hfg x ▸ hx⟩) ⟨fun _ _ h ↦ hi <| Subtype.ext_iff.1 h, fun y ↦ (hf y.coe_prop).imp fun _ hx ↦ Subtype.ext hx⟩) hfg @[to_additive] theorem Equiv.multipliable_iff_of_mulSupport {g : γ → α} (e : mulSupport f ≃ mulSupport g) (he : ∀ x : mulSupport f, g (e x) = f x) : Multipliable f ↔ Multipliable g := exists_congr fun _ ↦ e.hasProd_iff_of_mulSupport he @[to_additive] protected theorem HasProd.map [CommMonoid γ] [TopologicalSpace γ] (hf : HasProd f a) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : HasProd (g ∘ f) (g a) := by have : (g ∘ fun s : Finset β ↦ ∏ b ∈ s, f b) = fun s : Finset β ↦ ∏ b ∈ s, (g ∘ f) b := funext <| map_prod g _ unfold HasProd rw [← this] exact (hg.tendsto a).comp hf @[to_additive] protected theorem Topology.IsInducing.hasProd_iff [CommMonoid γ] [TopologicalSpace γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) (a : α) : HasProd (g ∘ f) (g a) ↔ HasProd f a := by simp_rw [HasProd, comp_apply, ← map_prod] exact hg.tendsto_nhds_iff.symm @[deprecated (since := "2024-10-28")] alias Inducing.hasProd_iff := IsInducing.hasProd_iff @[to_additive] protected theorem Multipliable.map [CommMonoid γ] [TopologicalSpace γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : Multipliable (g ∘ f) := (hf.hasProd.map g hg).multipliable @[to_additive] protected theorem Multipliable.map_iff_of_leftInverse [CommMonoid γ] [TopologicalSpace γ] {G G'} [FunLike G α γ] [MonoidHomClass G α γ] [FunLike G' γ α] [MonoidHomClass G' γ α] (g : G) (g' : G') (hg : Continuous g) (hg' : Continuous g') (hinv : Function.LeftInverse g' g) : Multipliable (g ∘ f) ↔ Multipliable f := ⟨fun h ↦ by have := h.map _ hg' rwa [← Function.comp_assoc, hinv.id] at this, fun h ↦ h.map _ hg⟩ @[to_additive] theorem Multipliable.map_tprod [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] (hf : Multipliable f) {G} [FunLike G α γ] [MonoidHomClass G α γ] (g : G) (hg : Continuous g) : g (∏' i, f i) = ∏' i, g (f i) := (HasProd.tprod_eq (HasProd.map hf.hasProd g hg)).symm @[to_additive] lemma Topology.IsInducing.multipliable_iff_tprod_comp_mem_range [CommMonoid γ] [TopologicalSpace γ] [T2Space γ] {G} [FunLike G α γ] [MonoidHomClass G α γ] {g : G} (hg : IsInducing g) (f : β → α) : Multipliable f ↔ Multipliable (g ∘ f) ∧ ∏' i, g (f i) ∈ Set.range g := by constructor · intro hf constructor · exact hf.map g hg.continuous · use ∏' i, f i exact hf.map_tprod g hg.continuous · rintro ⟨hgf, a, ha⟩ use a have := hgf.hasProd simp_rw [comp_apply, ← ha] at this exact (hg.hasProd_iff f a).mp this @[deprecated (since := "2024-10-28")] alias Inducing.multipliable_iff_tprod_comp_mem_range := IsInducing.multipliable_iff_tprod_comp_mem_range /-- "A special case of `Multipliable.map_iff_of_leftInverse` for convenience" -/ @[to_additive "A special case of `Summable.map_iff_of_leftInverse` for convenience"] protected theorem Multipliable.map_iff_of_equiv [CommMonoid γ] [TopologicalSpace γ] {G} [EquivLike G α γ] [MulEquivClass G α γ] (g : G) (hg : Continuous g) (hg' : Continuous (EquivLike.inv g : γ → α)) : Multipliable (g ∘ f) ↔ Multipliable f := Multipliable.map_iff_of_leftInverse g (g : α ≃* γ).symm hg hg' (EquivLike.left_inv g) @[to_additive] theorem Function.Surjective.multipliable_iff_of_hasProd_iff {α' : Type*} [CommMonoid α'] [TopologicalSpace α'] {e : α' → α} (hes : Function.Surjective e) {f : β → α} {g : γ → α'} (he : ∀ {a}, HasProd f (e a) ↔ HasProd g a) : Multipliable f ↔ Multipliable g := hes.exists.trans <| exists_congr <| @he variable [ContinuousMul α] @[to_additive] theorem HasProd.mul (hf : HasProd f a) (hg : HasProd g b) : HasProd (fun b ↦ f b * g b) (a * b) := by dsimp only [HasProd] at hf hg ⊢ simp_rw [prod_mul_distrib] exact hf.mul hg @[to_additive] theorem Multipliable.mul (hf : Multipliable f) (hg : Multipliable g) : Multipliable fun b ↦ f b * g b := (hf.hasProd.mul hg.hasProd).multipliable @[to_additive] theorem hasProd_prod {f : γ → β → α} {a : γ → α} {s : Finset γ} : (∀ i ∈ s, HasProd (f i) (a i)) → HasProd (fun b ↦ ∏ i ∈ s, f i b) (∏ i ∈ s, a i) := by classical exact Finset.induction_on s (by simp only [hasProd_one, prod_empty, forall_true_iff]) <| by simp +contextual only [mem_insert, forall_eq_or_imp, not_false_iff, prod_insert, and_imp] exact fun x s _ IH hx h ↦ hx.mul (IH h) @[to_additive] theorem multipliable_prod {f : γ → β → α} {s : Finset γ} (hf : ∀ i ∈ s, Multipliable (f i)) : Multipliable fun b ↦ ∏ i ∈ s, f i b := (hasProd_prod fun i hi ↦ (hf i hi).hasProd).multipliable @[to_additive] theorem HasProd.mul_disjoint {s t : Set β} (hs : Disjoint s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd (f ∘ (↑) : (s ∪ t : Set β) → α) (a * b) := by rw [hasProd_subtype_iff_mulIndicator] at * rw [Set.mulIndicator_union_of_disjoint hs] exact ha.mul hb @[to_additive] theorem hasProd_prod_disjoint {ι} (s : Finset ι) {t : ι → Set β} {a : ι → α} (hs : (s : Set ι).Pairwise (Disjoint on t)) (hf : ∀ i ∈ s, HasProd (f ∘ (↑) : t i → α) (a i)) : HasProd (f ∘ (↑) : (⋃ i ∈ s, t i) → α) (∏ i ∈ s, a i) := by simp_rw [hasProd_subtype_iff_mulIndicator] at * rw [Finset.mulIndicator_biUnion _ _ hs] exact hasProd_prod hf @[to_additive] theorem HasProd.mul_isCompl {s t : Set β} (hs : IsCompl s t) (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : t → α) b) : HasProd f (a * b) := by simpa [← hs.compl_eq] using (hasProd_subtype_iff_mulIndicator.1 ha).mul (hasProd_subtype_iff_mulIndicator.1 hb) @[to_additive] theorem HasProd.mul_compl {s : Set β} (ha : HasProd (f ∘ (↑) : s → α) a) (hb : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl hb @[to_additive] theorem Multipliable.mul_compl {s : Set β} (hs : Multipliable (f ∘ (↑) : s → α)) (hsc : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) : Multipliable f := (hs.hasProd.mul_compl hsc.hasProd).multipliable @[to_additive] theorem HasProd.compl_mul {s : Set β} (ha : HasProd (f ∘ (↑) : (sᶜ : Set β) → α) a) (hb : HasProd (f ∘ (↑) : s → α) b) : HasProd f (a * b) := ha.mul_isCompl isCompl_compl.symm hb @[to_additive] theorem Multipliable.compl_add {s : Set β} (hs : Multipliable (f ∘ (↑) : (sᶜ : Set β) → α)) (hsc : Multipliable (f ∘ (↑) : s → α)) : Multipliable f := (hs.hasProd.compl_mul hsc.hasProd).multipliable /-- Version of `HasProd.update` for `CommMonoid` rather than `CommGroup`. Rather than showing that `f.update` has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `f.update` given that both exist. -/ @[to_additive "Version of `HasSum.update` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that `f.update` has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `f.update` given that both exist."] theorem HasProd.update' {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a a' : α} (hf : HasProd f a) (b : β) (x : α) (hf' : HasProd (update f b x) a') : a * x = a' * f b := by have : ∀ b', f b' * ite (b' = b) x 1 = update f b x b' * ite (b' = b) (f b) 1 := by intro b' split_ifs with hb' · simpa only [Function.update_apply, hb', eq_self_iff_true] using mul_comm (f b) x · simp only [Function.update_apply, hb', if_false] have h := hf.mul (hasProd_ite_eq b x) simp_rw [this] at h exact HasProd.unique h (hf'.mul (hasProd_ite_eq b (f b))) /-- Version of `hasProd_ite_div_hasProd` for `CommMonoid` rather than `CommGroup`. Rather than showing that the `ite` expression has a specific product in terms of `HasProd`, it gives a relationship between the products of `f` and `ite (n = b) 0 (f n)` given that both exist. -/ @[to_additive "Version of `hasSum_ite_sub_hasSum` for `AddCommMonoid` rather than `AddCommGroup`. Rather than showing that the `ite` expression has a specific sum in terms of `HasSum`, it gives a relationship between the sums of `f` and `ite (n = b) 0 (f n)` given that both exist."] theorem eq_mul_of_hasProd_ite {α β : Type*} [TopologicalSpace α] [CommMonoid α] [T2Space α] [ContinuousMul α] [DecidableEq β] {f : β → α} {a : α} (hf : HasProd f a) (b : β) (a' : α) (hf' : HasProd (fun n ↦ ite (n = b) 1 (f n)) a') : a = a' * f b := by refine (mul_one a).symm.trans (hf.update' b 1 ?_) convert hf' apply update_apply end HasProd section tprod variable [CommMonoid α] [TopologicalSpace α] {f g : β → α} @[to_additive] theorem tprod_congr_set_coe (f : β → α) {s t : Set β} (h : s = t) : ∏' x : s, f x = ∏' x : t, f x := by rw [h] @[to_additive] theorem tprod_congr_subtype (f : β → α) {P Q : β → Prop} (h : ∀ x, P x ↔ Q x) : ∏' x : {x // P x}, f x = ∏' x : {x // Q x}, f x := tprod_congr_set_coe f <| Set.ext h @[to_additive] theorem tprod_eq_finprod (hf : (mulSupport f).Finite) : ∏' b, f b = ∏ᶠ b, f b := by simp [tprod_def, multipliable_of_finite_mulSupport hf, hf] @[to_additive] theorem tprod_eq_prod' {s : Finset β} (hf : mulSupport f ⊆ s) : ∏' b, f b = ∏ b ∈ s, f b := by rw [tprod_eq_finprod (s.finite_toSet.subset hf), finprod_eq_prod_of_mulSupport_subset _ hf] @[to_additive] theorem tprod_eq_prod {s : Finset β} (hf : ∀ b ∉ s, f b = 1) : ∏' b, f b = ∏ b ∈ s, f b := tprod_eq_prod' <| mulSupport_subset_iff'.2 hf @[to_additive (attr := simp)] theorem tprod_one : ∏' _ : β, (1 : α) = 1 := by rw [tprod_eq_finprod] <;> simp @[to_additive (attr := simp)] theorem tprod_empty [IsEmpty β] : ∏' b, f b = 1 := by rw [tprod_eq_prod (s := (∅ : Finset β))] <;> simp @[to_additive] theorem tprod_congr {f g : β → α} (hfg : ∀ b, f b = g b) : ∏' b, f b = ∏' b, g b := congr_arg tprod (funext hfg) @[to_additive] theorem tprod_fintype [Fintype β] (f : β → α) : ∏' b, f b = ∏ b, f b := by apply tprod_eq_prod; simp @[to_additive] theorem prod_eq_tprod_mulIndicator (f : β → α) (s : Finset β) : ∏ x ∈ s, f x = ∏' x, Set.mulIndicator (↑s) f x := by rw [tprod_eq_prod' (Set.mulSupport_mulIndicator_subset), Finset.prod_mulIndicator_subset _ Finset.Subset.rfl] @[to_additive] theorem tprod_bool (f : Bool → α) : ∏' i : Bool, f i = f false * f true := by rw [tprod_fintype, Fintype.prod_bool, mul_comm] @[to_additive] theorem tprod_eq_mulSingle {f : β → α} (b : β) (hf : ∀ b' ≠ b, f b' = 1) : ∏' b, f b = f b := by rw [tprod_eq_prod (s := {b}), prod_singleton] exact fun b' hb' ↦ hf b' (by simpa using hb') @[to_additive] theorem tprod_tprod_eq_mulSingle (f : β → γ → α) (b : β) (c : γ) (hfb : ∀ b' ≠ b, f b' c = 1) (hfc : ∀ b', ∀ c' ≠ c, f b' c' = 1) : ∏' (b') (c'), f b' c' = f b c := calc ∏' (b') (c'), f b' c' = ∏' b', f b' c := tprod_congr fun b' ↦ tprod_eq_mulSingle _ (hfc b') _ = f b c := tprod_eq_mulSingle _ hfb @[to_additive (attr := simp)] theorem tprod_ite_eq (b : β) [DecidablePred (· = b)] (a : α) : ∏' b', (if b' = b then a else 1) = a := by rw [tprod_eq_mulSingle b] · simp · intro b' hb'; simp [hb'] @[to_additive (attr := simp)] theorem Finset.tprod_subtype (s : Finset β) (f : β → α) : ∏' x : { x // x ∈ s }, f x = ∏ x ∈ s, f x := by rw [← prod_attach]; exact tprod_fintype _ @[to_additive] theorem Finset.tprod_subtype' (s : Finset β) (f : β → α) : ∏' x : (s : Set β), f x = ∏ x ∈ s, f x := by simp @[to_additive (attr := simp)] theorem tprod_singleton (b : β) (f : β → α) : ∏' x : ({b} : Set β), f x = f b := by rw [← coe_singleton, Finset.tprod_subtype', prod_singleton] open scoped Classical in @[to_additive] theorem Function.Injective.tprod_eq {g : γ → β} (hg : Injective g) {f : β → α} (hf : mulSupport f ⊆ Set.range g) : ∏' c, f (g c) = ∏' b, f b := by have : mulSupport f = g '' mulSupport (f ∘ g) := by rw [mulSupport_comp_eq_preimage, Set.image_preimage_eq_iff.2 hf] rw [← Function.comp_def] by_cases hf_fin : (mulSupport f).Finite · have hfg_fin : (mulSupport (f ∘ g)).Finite := hf_fin.preimage hg.injOn lift g to γ ↪ β using hg simp_rw [tprod_eq_prod' hf_fin.coe_toFinset.ge, tprod_eq_prod' hfg_fin.coe_toFinset.ge, comp_apply, ← Finset.prod_map] refine Finset.prod_congr (Finset.coe_injective ?_) fun _ _ ↦ rfl simp [this] · have hf_fin' : ¬ Set.Finite (mulSupport (f ∘ g)) := by rwa [this, Set.finite_image_iff hg.injOn] at hf_fin simp_rw [tprod_def, if_neg hf_fin, if_neg hf_fin', Multipliable, funext fun a => propext <| hg.hasProd_iff (mulSupport_subset_iff'.1 hf) (a := a)] @[to_additive] theorem Equiv.tprod_eq (e : γ ≃ β) (f : β → α) : ∏' c, f (e c) = ∏' b, f b := e.injective.tprod_eq <| by simp /-! ### `tprod` on subsets - part 1 -/ @[to_additive] theorem tprod_subtype_eq_of_mulSupport_subset {f : β → α} {s : Set β} (hs : mulSupport f ⊆ s) : ∏' x : s, f x = ∏' x, f x := Subtype.val_injective.tprod_eq <| by simpa @[to_additive] theorem tprod_subtype_mulSupport (f : β → α) : ∏' x : mulSupport f, f x = ∏' x, f x := tprod_subtype_eq_of_mulSupport_subset Set.Subset.rfl @[to_additive] theorem tprod_subtype (s : Set β) (f : β → α) : ∏' x : s, f x = ∏' x, s.mulIndicator f x := by rw [← tprod_subtype_eq_of_mulSupport_subset Set.mulSupport_mulIndicator_subset, tprod_congr] simp @[to_additive (attr := simp)] theorem tprod_univ (f : β → α) : ∏' x : (Set.univ : Set β), f x = ∏' x, f x := tprod_subtype_eq_of_mulSupport_subset <| Set.subset_univ _
@[to_additive] theorem tprod_image {g : γ → β} (f : β → α) {s : Set γ} (hg : Set.InjOn g s) :
Mathlib/Topology/Algebra/InfiniteSum/Basic.lean
485
486
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Dual import Mathlib.Analysis.InnerProductSpace.Orientation import Mathlib.Data.Complex.FiniteDimensional import Mathlib.Data.Complex.Orientation import Mathlib.Tactic.LinearCombination /-! # Oriented two-dimensional real inner product spaces This file defines constructions specific to the geometry of an oriented two-dimensional real inner product space `E`. ## Main declarations * `Orientation.areaForm`: an antisymmetric bilinear form `E →ₗ[ℝ] E →ₗ[ℝ] ℝ` (usual notation `ω`). Morally, when `ω` is evaluated on two vectors, it gives the oriented area of the parallelogram they span. (But mathlib does not yet have a construction of oriented area, and in fact the construction of oriented area should pass through `ω`.) * `Orientation.rightAngleRotation`: an isometric automorphism `E ≃ₗᵢ[ℝ] E` (usual notation `J`). This automorphism squares to -1. In a later file, rotations (`Orientation.rotation`) are defined, in such a way that this automorphism is equal to rotation by 90 degrees. * `Orientation.basisRightAngleRotation`: for a nonzero vector `x` in `E`, the basis `![x, J x]` for `E`. * `Orientation.kahler`: a complex-valued real-bilinear map `E →ₗ[ℝ] E →ₗ[ℝ] ℂ`. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. For vectors `x` and `y` in `E`, the complex number `o.kahler x y` has modulus `‖x‖ * ‖y‖`. In a later file, oriented angles (`Orientation.oangle`) are defined, in such a way that the argument of `o.kahler x y` is the oriented angle from `x` to `y`. ## Main results * `Orientation.rightAngleRotation_rightAngleRotation`: the identity `J (J x) = - x` * `Orientation.nonneg_inner_and_areaForm_eq_zero_iff_sameRay`: `x`, `y` are in the same ray, if and only if `0 ≤ ⟪x, y⟫` and `ω x y = 0` * `Orientation.kahler_mul`: the identity `o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y` * `Complex.areaForm`, `Complex.rightAngleRotation`, `Complex.kahler`: the concrete interpretations of `areaForm`, `rightAngleRotation`, `kahler` for the oriented real inner product space `ℂ` * `Orientation.areaForm_map_complex`, `Orientation.rightAngleRotation_map_complex`, `Orientation.kahler_map_complex`: given an orientation-preserving isometry from `E` to `ℂ`, expressions for `areaForm`, `rightAngleRotation`, `kahler` as the pullback of their concrete interpretations on `ℂ` ## Implementation notes Notation `ω` for `Orientation.areaForm` and `J` for `Orientation.rightAngleRotation` should be defined locally in each file which uses them, since otherwise one would need a more cumbersome notation which mentions the orientation explicitly (something like `ω[o]`). Write ``` local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation ``` -/ noncomputable section open scoped RealInnerProductSpace ComplexConjugate open Module lemma FiniteDimensional.of_fact_finrank_eq_two {K V : Type*} [DivisionRing K] [AddCommGroup V] [Module K V] [Fact (finrank K V = 2)] : FiniteDimensional K V := .of_fact_finrank_eq_succ 1 attribute [local instance] FiniteDimensional.of_fact_finrank_eq_two variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [Fact (finrank ℝ E = 2)] (o : Orientation ℝ E (Fin 2)) namespace Orientation /-- An antisymmetric bilinear form on an oriented real inner product space of dimension 2 (usual notation `ω`). When evaluated on two vectors, it gives the oriented area of the parallelogram they span. -/ irreducible_def areaForm : E →ₗ[ℝ] E →ₗ[ℝ] ℝ := by let z : E [⋀^Fin 0]→ₗ[ℝ] ℝ ≃ₗ[ℝ] ℝ := AlternatingMap.constLinearEquivOfIsEmpty.symm let y : E [⋀^Fin 1]→ₗ[ℝ] ℝ →ₗ[ℝ] E →ₗ[ℝ] ℝ := LinearMap.llcomp ℝ E (E [⋀^Fin 0]→ₗ[ℝ] ℝ) ℝ z ∘ₗ AlternatingMap.curryLeftLinearMap exact y ∘ₗ AlternatingMap.curryLeftLinearMap (R' := ℝ) o.volumeForm local notation "ω" => o.areaForm theorem areaForm_to_volumeForm (x y : E) : ω x y = o.volumeForm ![x, y] := by simp [areaForm] @[simp] theorem areaForm_apply_self (x : E) : ω x x = 0 := by rw [areaForm_to_volumeForm] refine o.volumeForm.map_eq_zero_of_eq ![x, x] ?_ (?_ : (0 : Fin 2) ≠ 1) · simp · norm_num theorem areaForm_swap (x y : E) : ω x y = -ω y x := by simp only [areaForm_to_volumeForm] convert o.volumeForm.map_swap ![y, x] (_ : (0 : Fin 2) ≠ 1) · ext i fin_cases i <;> rfl · norm_num @[simp] theorem areaForm_neg_orientation : (-o).areaForm = -o.areaForm := by ext x y simp [areaForm_to_volumeForm] /-- Continuous linear map version of `Orientation.areaForm`, useful for calculus. -/ def areaForm' : E →L[ℝ] E →L[ℝ] ℝ := LinearMap.toContinuousLinearMap (↑(LinearMap.toContinuousLinearMap : (E →ₗ[ℝ] ℝ) ≃ₗ[ℝ] E →L[ℝ] ℝ) ∘ₗ o.areaForm) @[simp] theorem areaForm'_apply (x : E) : o.areaForm' x = LinearMap.toContinuousLinearMap (o.areaForm x) := rfl theorem abs_areaForm_le (x y : E) : |ω x y| ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.abs_volumeForm_apply_le ![x, y] theorem areaForm_le (x y : E) : ω x y ≤ ‖x‖ * ‖y‖ := by simpa [areaForm_to_volumeForm, Fin.prod_univ_succ] using o.volumeForm_apply_le ![x, y] theorem abs_areaForm_of_orthogonal {x y : E} (h : ⟪x, y⟫ = 0) : |ω x y| = ‖x‖ * ‖y‖ := by rw [o.areaForm_to_volumeForm, o.abs_volumeForm_apply_of_pairwise_orthogonal] · simp [Fin.prod_univ_succ] intro i j hij fin_cases i <;> fin_cases j · simp_all · simpa using h · simpa [real_inner_comm] using h · simp_all theorem areaForm_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).areaForm x y = o.areaForm (φ.symm x) (φ.symm y) := by have : φ.symm ∘ ![x, y] = ![φ.symm x, φ.symm y] := by ext i fin_cases i <;> rfl simp [areaForm_to_volumeForm, volumeForm_map, this] /-- The area form is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem areaForm_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.areaForm (φ x) (φ y) = o.areaForm x y := by convert o.areaForm_map φ (φ x) (φ y) · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] · simp · simp /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ irreducible_def rightAngleRotationAux₁ : E →ₗ[ℝ] E := let to_dual : E ≃ₗ[ℝ] E →ₗ[ℝ] ℝ := (InnerProductSpace.toDual ℝ E).toLinearEquiv ≪≫ₗ LinearMap.toContinuousLinearMap.symm ↑to_dual.symm ∘ₗ ω @[simp] theorem inner_rightAngleRotationAux₁_left (x y : E) : ⟪o.rightAngleRotationAux₁ x, y⟫ = ω x y := by simp only [rightAngleRotationAux₁, LinearEquiv.trans_symm, LinearIsometryEquiv.toLinearEquiv_symm, LinearMap.coe_comp, LinearEquiv.coe_coe, Function.comp_apply, LinearEquiv.trans_apply, LinearIsometryEquiv.coe_toLinearEquiv] rw [InnerProductSpace.toDual_symm_apply] norm_cast @[simp] theorem inner_rightAngleRotationAux₁_right (x y : E) : ⟪x, o.rightAngleRotationAux₁ y⟫ = -ω x y := by rw [real_inner_comm] simp [o.areaForm_swap y x] /-- Auxiliary construction for `Orientation.rightAngleRotation`, rotation by 90 degrees in an oriented real inner product space of dimension 2. -/ def rightAngleRotationAux₂ : E →ₗᵢ[ℝ] E := { o.rightAngleRotationAux₁ with norm_map' := fun x => by refine le_antisymm ?_ ?_ · rcases eq_or_lt_of_le (norm_nonneg (o.rightAngleRotationAux₁ x)) with h | h · rw [← h] positivity refine le_of_mul_le_mul_right ?_ h rw [← real_inner_self_eq_norm_mul_norm, o.inner_rightAngleRotationAux₁_left] exact o.areaForm_le x (o.rightAngleRotationAux₁ x) · let K : Submodule ℝ E := ℝ ∙ x have : Nontrivial Kᗮ := by apply nontrivial_of_finrank_pos (R := ℝ) have : finrank ℝ K ≤ Finset.card {x} := by rw [← Set.toFinset_singleton] exact finrank_span_le_card ({x} : Set E) have : Finset.card {x} = 1 := Finset.card_singleton x have : finrank ℝ K + finrank ℝ Kᗮ = finrank ℝ E := K.finrank_add_finrank_orthogonal have : finrank ℝ E = 2 := Fact.out omega obtain ⟨w, hw₀⟩ : ∃ w : Kᗮ, w ≠ 0 := exists_ne 0 have hw' : ⟪x, (w : E)⟫ = 0 := Submodule.mem_orthogonal_singleton_iff_inner_right.mp w.2 have hw : (w : E) ≠ 0 := fun h => hw₀ (Submodule.coe_eq_zero.mp h) refine le_of_mul_le_mul_right ?_ (by rwa [norm_pos_iff] : 0 < ‖(w : E)‖) rw [← o.abs_areaForm_of_orthogonal hw'] rw [← o.inner_rightAngleRotationAux₁_left x w] exact abs_real_inner_le_norm (o.rightAngleRotationAux₁ x) w } @[simp] theorem rightAngleRotationAux₁_rightAngleRotationAux₁ (x : E) : o.rightAngleRotationAux₁ (o.rightAngleRotationAux₁ x) = -x := by apply ext_inner_left ℝ intro y have : ⟪o.rightAngleRotationAux₁ y, o.rightAngleRotationAux₁ x⟫ = ⟪y, x⟫ := LinearIsometry.inner_map_map o.rightAngleRotationAux₂ y x rw [o.inner_rightAngleRotationAux₁_right, ← o.inner_rightAngleRotationAux₁_left, this, inner_neg_right] /-- An isometric automorphism of an oriented real inner product space of dimension 2 (usual notation `J`). This automorphism squares to -1. We will define rotations in such a way that this automorphism is equal to rotation by 90 degrees. -/ irreducible_def rightAngleRotation : E ≃ₗᵢ[ℝ] E := LinearIsometryEquiv.ofLinearIsometry o.rightAngleRotationAux₂ (-o.rightAngleRotationAux₁) (by ext; simp [rightAngleRotationAux₂]) (by ext; simp [rightAngleRotationAux₂]) local notation "J" => o.rightAngleRotation @[simp] theorem inner_rightAngleRotation_left (x y : E) : ⟪J x, y⟫ = ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_left x y @[simp] theorem inner_rightAngleRotation_right (x y : E) : ⟪x, J y⟫ = -ω x y := by rw [rightAngleRotation] exact o.inner_rightAngleRotationAux₁_right x y @[simp] theorem rightAngleRotation_rightAngleRotation (x : E) : J (J x) = -x := by rw [rightAngleRotation] exact o.rightAngleRotationAux₁_rightAngleRotationAux₁ x @[simp] theorem rightAngleRotation_symm : LinearIsometryEquiv.symm J = LinearIsometryEquiv.trans J (LinearIsometryEquiv.neg ℝ) := by rw [rightAngleRotation] exact LinearIsometryEquiv.toLinearIsometry_injective rfl theorem inner_rightAngleRotation_self (x : E) : ⟪J x, x⟫ = 0 := by simp theorem inner_rightAngleRotation_swap (x y : E) : ⟪x, J y⟫ = -⟪J x, y⟫ := by simp theorem inner_rightAngleRotation_swap' (x y : E) : ⟪J x, y⟫ = -⟪x, J y⟫ := by simp [o.inner_rightAngleRotation_swap x y] theorem inner_comp_rightAngleRotation (x y : E) : ⟪J x, J y⟫ = ⟪x, y⟫ := LinearIsometryEquiv.inner_map_map J x y @[simp] theorem areaForm_rightAngleRotation_left (x y : E) : ω (J x) y = -⟪x, y⟫ := by rw [← o.inner_comp_rightAngleRotation, o.inner_rightAngleRotation_right, neg_neg] @[simp] theorem areaForm_rightAngleRotation_right (x y : E) : ω x (J y) = ⟪x, y⟫ := by rw [← o.inner_rightAngleRotation_left, o.inner_comp_rightAngleRotation] theorem areaForm_comp_rightAngleRotation (x y : E) : ω (J x) (J y) = ω x y := by simp @[simp] theorem rightAngleRotation_trans_rightAngleRotation : LinearIsometryEquiv.trans J J = LinearIsometryEquiv.neg ℝ := by ext; simp theorem rightAngleRotation_neg_orientation (x : E) : (-o).rightAngleRotation x = -o.rightAngleRotation x := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] simp @[simp] theorem rightAngleRotation_trans_neg_orientation : (-o).rightAngleRotation = o.rightAngleRotation.trans (LinearIsometryEquiv.neg ℝ) := LinearIsometryEquiv.ext <| o.rightAngleRotation_neg_orientation theorem rightAngleRotation_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation x = φ (o.rightAngleRotation (φ.symm x)) := by apply ext_inner_right ℝ intro y rw [inner_rightAngleRotation_left] trans ⟪J (φ.symm x), φ.symm y⟫ · simp [o.areaForm_map] trans ⟪φ (J (φ.symm x)), φ (φ.symm y)⟫ · rw [φ.inner_map_map] · simp /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x : E) : φ (J x) = J (φ x) := by convert (o.rightAngleRotation_map φ (φ x)).symm · simp · symm rwa [← o.map_eq_iff_det_pos φ.toLinearEquiv] at hφ rw [@Fact.out (finrank ℝ E = 2), Fintype.card_fin] theorem rightAngleRotation_map' {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).rightAngleRotation = (φ.symm.trans o.rightAngleRotation).trans φ := LinearIsometryEquiv.ext <| o.rightAngleRotation_map φ /-- `J` commutes with any positively-oriented isometric automorphism. -/ theorem linearIsometryEquiv_comp_rightAngleRotation' (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) : LinearIsometryEquiv.trans J φ = φ.trans J := LinearIsometryEquiv.ext <| o.linearIsometryEquiv_comp_rightAngleRotation φ hφ /-- For a nonzero vector `x` in an oriented two-dimensional real inner product space `E`, `![x, J x]` forms an (orthogonal) basis for `E`. -/ def basisRightAngleRotation (x : E) (hx : x ≠ 0) : Basis (Fin 2) ℝ E := @basisOfLinearIndependentOfCardEqFinrank ℝ _ _ _ _ _ _ _ ![x, J x] (linearIndependent_of_ne_zero_of_inner_eq_zero (fun i => by fin_cases i <;> simp [hx]) (by intro i j hij fin_cases i <;> fin_cases j <;> simp_all)) (@Fact.out (finrank ℝ E = 2)).symm @[simp] theorem coe_basisRightAngleRotation (x : E) (hx : x ≠ 0) : ⇑(o.basisRightAngleRotation x hx) = ![x, J x] := coe_basisOfLinearIndependentOfCardEqFinrank _ _ /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. (See `Orientation.inner_mul_inner_add_areaForm_mul_areaForm` for the "applied" form.) -/ theorem inner_mul_inner_add_areaForm_mul_areaForm' (a x : E) : ⟪a, x⟫ • innerₛₗ ℝ a + ω a x • ω a = ‖a‖ ^ 2 • innerₛₗ ℝ x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm] · simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x] /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫`. -/ theorem inner_mul_inner_add_areaForm_mul_areaForm (a x y : E) : ⟪a, x⟫ * ⟪a, y⟫ + ω a x * ω a y = ‖a‖ ^ 2 * ⟪x, y⟫ := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_inner_add_areaForm_mul_areaForm' a x) theorem inner_sq_add_areaForm_sq (a b : E) : ⟪a, b⟫ ^ 2 + ω a b ^ 2 = ‖a‖ ^ 2 * ‖b‖ ^ 2 := by simpa [sq, real_inner_self_eq_norm_sq] using o.inner_mul_inner_add_areaForm_mul_areaForm a b b /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. (See `Orientation.inner_mul_areaForm_sub` for the "applied" form.) -/ theorem inner_mul_areaForm_sub' (a x : E) : ⟪a, x⟫ • ω a - ω a x • innerₛₗ ℝ a = ‖a‖ ^ 2 • ω x := by by_cases ha : a = 0 · simp [ha] apply (o.basisRightAngleRotation a ha).ext intro i fin_cases i · simp [real_inner_self_eq_norm_sq, mul_comm, o.areaForm_swap a x] · simp [real_inner_self_eq_norm_sq, mul_comm, real_inner_comm] /-- For vectors `a x y : E`, the identity `⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y`. -/ theorem inner_mul_areaForm_sub (a x y : E) : ⟪a, x⟫ * ω a y - ω a x * ⟪a, y⟫ = ‖a‖ ^ 2 * ω x y := congr_arg (fun f : E →ₗ[ℝ] ℝ => f y) (o.inner_mul_areaForm_sub' a x) theorem nonneg_inner_and_areaForm_eq_zero_iff_sameRay (x y : E) : 0 ≤ ⟪x, y⟫ ∧ ω x y = 0 ↔ SameRay ℝ x y := by by_cases hx : x = 0 · simp [hx] constructor · let a : ℝ := (o.basisRightAngleRotation x hx).repr y 0 let b : ℝ := (o.basisRightAngleRotation x hx).repr y 1 suffices ↑0 ≤ a * ‖x‖ ^ 2 ∧ b * ‖x‖ ^ 2 = 0 → SameRay ℝ x (a • x + b • J x) by rw [← (o.basisRightAngleRotation x hx).sum_repr y] simp only [Fin.sum_univ_succ, coe_basisRightAngleRotation, Matrix.cons_val_zero, Fin.succ_zero_eq_one', Finset.univ_eq_empty, Finset.sum_empty, areaForm_apply_self, map_smul, map_add, real_inner_smul_right, inner_add_right, Matrix.cons_val_one, Matrix.head_cons, Algebra.id.smul_eq_mul, areaForm_rightAngleRotation_right, mul_zero, add_zero, zero_add, neg_zero, inner_rightAngleRotation_right, real_inner_self_eq_norm_sq, zero_smul, one_smul] exact this rintro ⟨ha, hb⟩ have hx' : 0 < ‖x‖ := by simpa using hx have ha' : 0 ≤ a := nonneg_of_mul_nonneg_left ha (by positivity) have hb' : b = 0 := eq_zero_of_ne_zero_of_mul_right_eq_zero (pow_ne_zero 2 hx'.ne') hb exact (SameRay.sameRay_nonneg_smul_right x ha').add_right <| by simp [hb'] · intro h obtain ⟨r, hr, rfl⟩ := h.exists_nonneg_left hx simp only [inner_smul_right, real_inner_self_eq_norm_sq, LinearMap.map_smulₛₗ, areaForm_apply_self, Algebra.id.smul_eq_mul, mul_zero, eq_self_iff_true, and_true] positivity /-- A complex-valued real-bilinear map on an oriented real inner product space of dimension 2. Its real part is the inner product and its imaginary part is `Orientation.areaForm`. On `ℂ` with the standard orientation, `kahler w z = conj w * z`; see `Complex.kahler`. -/ def kahler : E →ₗ[ℝ] E →ₗ[ℝ] ℂ := LinearMap.llcomp ℝ E ℝ ℂ Complex.ofRealCLM ∘ₗ innerₛₗ ℝ + LinearMap.llcomp ℝ E ℝ ℂ ((LinearMap.lsmul ℝ ℂ).flip Complex.I) ∘ₗ ω theorem kahler_apply_apply (x y : E) : o.kahler x y = ⟪x, y⟫ + ω x y • Complex.I := rfl theorem kahler_swap (x y : E) : o.kahler x y = conj (o.kahler y x) := by simp only [kahler_apply_apply] rw [real_inner_comm, areaForm_swap] simp [Complex.conj_ofReal] @[simp] theorem kahler_apply_self (x : E) : o.kahler x x = ‖x‖ ^ 2 := by simp [kahler_apply_apply, real_inner_self_eq_norm_sq] @[simp] theorem kahler_rightAngleRotation_left (x y : E) : o.kahler (J x) y = -Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_left, o.inner_rightAngleRotation_left, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination ω x y * Complex.I_sq @[simp] theorem kahler_rightAngleRotation_right (x y : E) : o.kahler x (J y) = Complex.I * o.kahler x y := by simp only [o.areaForm_rightAngleRotation_right, o.inner_rightAngleRotation_right, o.kahler_apply_apply, Complex.ofReal_neg, Complex.real_smul] linear_combination -ω x y * Complex.I_sq -- @[simp] -- Porting note: simp normal form is `kahler_comp_rightAngleRotation'` theorem kahler_comp_rightAngleRotation (x y : E) : o.kahler (J x) (J y) = o.kahler x y := by simp only [kahler_rightAngleRotation_left, kahler_rightAngleRotation_right] linear_combination -o.kahler x y * Complex.I_sq theorem kahler_comp_rightAngleRotation' (x y : E) : -(Complex.I * (Complex.I * o.kahler x y)) = o.kahler x y := by linear_combination -o.kahler x y * Complex.I_sq @[simp] theorem kahler_neg_orientation (x y : E) : (-o).kahler x y = conj (o.kahler x y) := by simp [kahler_apply_apply, Complex.conj_ofReal] theorem kahler_mul (a x y : E) : o.kahler x a * o.kahler a y = ‖a‖ ^ 2 * o.kahler x y := by trans ((‖a‖ ^ 2 :) : ℂ) * o.kahler x y · apply Complex.ext · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_inner_add_areaForm_mul_areaForm a x y · simp only [o.kahler_apply_apply, Complex.add_im, Complex.add_re, Complex.I_im, Complex.I_re, Complex.mul_im, Complex.mul_re, Complex.ofReal_im, Complex.ofReal_re, Complex.real_smul] rw [real_inner_comm a x, o.areaForm_swap x a] linear_combination o.inner_mul_areaForm_sub a x y · norm_cast theorem normSq_kahler (x y : E) : Complex.normSq (o.kahler x y) = ‖x‖ ^ 2 * ‖y‖ ^ 2 := by simpa [kahler_apply_apply, Complex.normSq, sq] using o.inner_sq_add_areaForm_sq x y theorem norm_kahler (x y : E) : ‖o.kahler x y‖ = ‖x‖ * ‖y‖ := by rw [← sq_eq_sq₀, Complex.sq_norm] · linear_combination o.normSq_kahler x y · positivity · positivity @[deprecated (since := "2025-02-17")] alias abs_kahler := norm_kahler theorem eq_zero_or_eq_zero_of_kahler_eq_zero {x y : E} (hx : o.kahler x y = 0) : x = 0 ∨ y = 0 := by have : ‖x‖ * ‖y‖ = 0 := by simpa [hx] using (o.norm_kahler x y).symm rcases eq_zero_or_eq_zero_of_mul_eq_zero this with h | h · left simpa using h · right simpa using h theorem kahler_eq_zero_iff (x y : E) : o.kahler x y = 0 ↔ x = 0 ∨ y = 0 := by refine ⟨o.eq_zero_or_eq_zero_of_kahler_eq_zero, ?_⟩ rintro (rfl | rfl) <;> simp theorem kahler_ne_zero {x y : E} (hx : x ≠ 0) (hy : y ≠ 0) : o.kahler x y ≠ 0 := by apply mt o.eq_zero_or_eq_zero_of_kahler_eq_zero tauto theorem kahler_ne_zero_iff (x y : E) : o.kahler x y ≠ 0 ↔ x ≠ 0 ∧ y ≠ 0 := by refine ⟨?_, fun h => o.kahler_ne_zero h.1 h.2⟩ contrapose simp only [not_and_or, Classical.not_not, kahler_apply_apply, Complex.real_smul] rintro (rfl | rfl) <;> simp theorem kahler_map {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℝ F] [hF : Fact (finrank ℝ F = 2)] (φ : E ≃ₗᵢ[ℝ] F) (x y : F) : (Orientation.map (Fin 2) φ.toLinearEquiv o).kahler x y = o.kahler (φ.symm x) (φ.symm y) := by simp [kahler_apply_apply, areaForm_map] /-- The bilinear map `kahler` is invariant under pullback by a positively-oriented isometric automorphism. -/ theorem kahler_comp_linearIsometryEquiv (φ : E ≃ₗᵢ[ℝ] E) (hφ : 0 < LinearMap.det (φ.toLinearEquiv : E →ₗ[ℝ] E)) (x y : E) : o.kahler (φ x) (φ y) = o.kahler x y := by simp [kahler_apply_apply, o.areaForm_comp_linearIsometryEquiv φ hφ] end Orientation namespace Complex attribute [local instance] Complex.finrank_real_complex_fact @[simp] protected theorem areaForm (w z : ℂ) : Complex.orientation.areaForm w z = (conj w * z).im := by let o := Complex.orientation simp only [o, o.areaForm_to_volumeForm, o.volumeForm_robust Complex.orthonormalBasisOneI rfl, Basis.det_apply, Matrix.det_fin_two, Basis.toMatrix_apply, toBasis_orthonormalBasisOneI, Matrix.cons_val_zero, coe_basisOneI_repr, Matrix.cons_val_one, Matrix.head_cons, mul_im, conj_re, conj_im] ring @[simp] protected theorem rightAngleRotation (z : ℂ) : Complex.orientation.rightAngleRotation z = I * z := by apply ext_inner_right ℝ intro w rw [Orientation.inner_rightAngleRotation_left] simp only [Complex.areaForm, Complex.inner, mul_re, mul_im, conj_re, conj_im, map_mul, conj_I, neg_re, neg_im, I_re, I_im] ring @[simp] protected theorem kahler (w z : ℂ) : Complex.orientation.kahler w z = z * conj w := by rw [Orientation.kahler_apply_apply] apply Complex.ext <;> simp [mul_comm] end Complex namespace Orientation local notation "ω" => o.areaForm local notation "J" => o.rightAngleRotation open Complex -- Porting note: The instance `finrank_real_complex_fact` cannot be found by synthesis for -- `areaForm_map`, `rightAngleRotation_map` and `kahler_map` in the three theorems below, -- so it has to be provided by unification (i.e. by naming the instance-implicit argument where -- it belongs and using `(hF := _)`). /-- The area form on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem areaForm_map_complex (f : E ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : E) : ω x y = (conj (f x) * f y).im := by rw [← Complex.areaForm, ← hf, areaForm_map (hF := _)] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] /-- The rotation by 90 degrees on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem rightAngleRotation_map_complex (f : E ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x : E) : f (J x) = I * f x := by rw [← Complex.rightAngleRotation, ← hf, rightAngleRotation_map (hF := _), LinearIsometryEquiv.symm_apply_apply] /-- The Kahler form on an oriented real inner product space of dimension 2 can be evaluated in terms of a complex-number representation of the space. -/ theorem kahler_map_complex (f : E ≃ₗᵢ[ℝ] ℂ) (hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x y : E) : o.kahler x y = f y * conj (f x) := by rw [← Complex.kahler, ← hf, kahler_map (hF := _)] iterate 2 rw [LinearIsometryEquiv.symm_apply_apply] end Orientation
Mathlib/Analysis/InnerProductSpace/TwoDim.lean
617
624
/- 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 -/ import Mathlib.Analysis.SpecialFunctions.Pow.Continuity import Mathlib.Analysis.SpecialFunctions.Complex.LogDeriv import Mathlib.Analysis.Calculus.FDeriv.Extend import Mathlib.Analysis.Calculus.Deriv.Prod import Mathlib.Analysis.SpecialFunctions.Log.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # Derivatives of power function on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞` We also prove differentiability and provide derivatives for the power functions `x ^ y`. -/ noncomputable section open scoped Real Topology NNReal ENNReal open Filter namespace Complex theorem hasStrictFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := by have A : p.1 ≠ 0 := slitPlane_ne_zero hp have : (fun x : ℂ × ℂ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := ((isOpen_ne.preimage continuous_fst).eventually_mem A).mono fun p hp => cpow_def_of_ne_zero hp _ rw [cpow_sub _ _ A, cpow_one, mul_div_left_comm, mul_smul, mul_smul] refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, mul_smul, add_comm, smul_add] using ((hasStrictFDerivAt_fst.clog hp).mul hasStrictFDerivAt_snd).cexp theorem hasStrictFDerivAt_cpow' {x y : ℂ} (hp : x ∈ slitPlane) : HasStrictFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((y * x ^ (y - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (x ^ y * log x) • ContinuousLinearMap.snd ℂ ℂ ℂ) (x, y) := @hasStrictFDerivAt_cpow (x, y) hp theorem hasStrictDerivAt_const_cpow {x y : ℂ} (h : x ≠ 0 ∨ y ≠ 0) : HasStrictDerivAt (fun y => x ^ y) (x ^ y * log x) y := by rcases em (x = 0) with (rfl | hx) · replace h := h.neg_resolve_left rfl rw [log_zero, mul_zero] refine (hasStrictDerivAt_const y 0).congr_of_eventuallyEq ?_ exact (isOpen_ne.eventually_mem h).mono fun y hy => (zero_cpow hy).symm · simpa only [cpow_def_of_ne_zero hx, mul_one] using ((hasStrictDerivAt_id y).const_mul (log x)).cexp theorem hasFDerivAt_cpow {p : ℂ × ℂ} (hp : p.1 ∈ slitPlane) : HasFDerivAt (fun x : ℂ × ℂ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℂ ℂ ℂ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℂ ℂ ℂ) p := (hasStrictFDerivAt_cpow hp).hasFDerivAt end Complex section fderiv open Complex variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f g : E → ℂ} {f' g' : E →L[ℂ] ℂ} {x : E} {s : Set E} {c : ℂ} theorem HasStrictFDerivAt.cpow (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := (hasStrictFDerivAt_cpow (p := (f x, g x)) h0).comp x (hf.prodMk hg) theorem HasStrictFDerivAt.const_cpow (hf : HasStrictFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasStrictFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x := (hasStrictDerivAt_const_cpow h0).comp_hasStrictFDerivAt x hf theorem HasFDerivAt.cpow (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasFDerivAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp x (hf.prodMk hg) theorem HasFDerivAt.const_cpow (hf : HasFDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasFDerivAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivAt x hf theorem HasFDerivWithinAt.cpow (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasFDerivWithinAt (fun x => f x ^ g x) ((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * Complex.log (f x)) • g') s x := by convert (@Complex.hasFDerivAt_cpow ((fun x => (f x, g x)) x) h0).comp_hasFDerivWithinAt x (hf.prodMk hg) theorem HasFDerivWithinAt.const_cpow (hf : HasFDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasFDerivWithinAt (fun x => c ^ f x) ((c ^ f x * Complex.log c) • f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasFDerivWithinAt x hf theorem DifferentiableAt.cpow (hf : DifferentiableAt ℂ f x) (hg : DifferentiableAt ℂ g x) (h0 : f x ∈ slitPlane) : DifferentiableAt ℂ (fun x => f x ^ g x) x := (hf.hasFDerivAt.cpow hg.hasFDerivAt h0).differentiableAt theorem DifferentiableAt.const_cpow (hf : DifferentiableAt ℂ f x) (h0 : c ≠ 0 ∨ f x ≠ 0) : DifferentiableAt ℂ (fun x => c ^ f x) x := (hf.hasFDerivAt.const_cpow h0).differentiableAt theorem DifferentiableAt.cpow_const (hf : DifferentiableAt ℂ f x) (h0 : f x ∈ slitPlane) : DifferentiableAt ℂ (fun x => f x ^ c) x := hf.cpow (differentiableAt_const c) h0 theorem DifferentiableWithinAt.cpow (hf : DifferentiableWithinAt ℂ f s x) (hg : DifferentiableWithinAt ℂ g s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt ℂ (fun x => f x ^ g x) s x := (hf.hasFDerivWithinAt.cpow hg.hasFDerivWithinAt h0).differentiableWithinAt theorem DifferentiableWithinAt.const_cpow (hf : DifferentiableWithinAt ℂ f s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : DifferentiableWithinAt ℂ (fun x => c ^ f x) s x := (hf.hasFDerivWithinAt.const_cpow h0).differentiableWithinAt theorem DifferentiableWithinAt.cpow_const (hf : DifferentiableWithinAt ℂ f s x) (h0 : f x ∈ slitPlane) : DifferentiableWithinAt ℂ (fun x => f x ^ c) s x := hf.cpow (differentiableWithinAt_const c) h0 theorem DifferentiableOn.cpow (hf : DifferentiableOn ℂ f s) (hg : DifferentiableOn ℂ g s) (h0 : Set.MapsTo f s slitPlane) : DifferentiableOn ℂ (fun x ↦ f x ^ g x) s := fun x hx ↦ (hf x hx).cpow (hg x hx) (h0 hx) theorem DifferentiableOn.const_cpow (hf : DifferentiableOn ℂ f s) (h0 : c ≠ 0 ∨ ∀ x ∈ s, f x ≠ 0) : DifferentiableOn ℂ (fun x ↦ c ^ f x) s := fun x hx ↦ (hf x hx).const_cpow (h0.imp_right fun h ↦ h x hx) theorem DifferentiableOn.cpow_const (hf : DifferentiableOn ℂ f s) (h0 : ∀ x ∈ s, f x ∈ slitPlane) : DifferentiableOn ℂ (fun x => f x ^ c) s := hf.cpow (differentiableOn_const c) h0 theorem Differentiable.cpow (hf : Differentiable ℂ f) (hg : Differentiable ℂ g) (h0 : ∀ x, f x ∈ slitPlane) : Differentiable ℂ (fun x ↦ f x ^ g x) := fun x ↦ (hf x).cpow (hg x) (h0 x) theorem Differentiable.const_cpow (hf : Differentiable ℂ f) (h0 : c ≠ 0 ∨ ∀ x, f x ≠ 0) : Differentiable ℂ (fun x ↦ c ^ f x) := fun x ↦ (hf x).const_cpow (h0.imp_right fun h ↦ h x) @[fun_prop] lemma differentiable_const_cpow_of_neZero (z : ℂ) [NeZero z] : Differentiable ℂ fun s : ℂ ↦ z ^ s := differentiable_id.const_cpow (.inl <| NeZero.ne z) @[fun_prop] lemma differentiableAt_const_cpow_of_neZero (z : ℂ) [NeZero z] (t : ℂ) : DifferentiableAt ℂ (fun s : ℂ ↦ z ^ s) t := differentiableAt_id.const_cpow (.inl <| NeZero.ne z) end fderiv section deriv open Complex variable {f g : ℂ → ℂ} {s : Set ℂ} {f' g' x c : ℂ} /-- A private lemma that rewrites the output of lemmas like `HasFDerivAt.cpow` to the form expected by lemmas like `HasDerivAt.cpow`. -/ private theorem aux : ((g x * f x ^ (g x - 1)) • (1 : ℂ →L[ℂ] ℂ).smulRight f' + (f x ^ g x * log (f x)) • (1 : ℂ →L[ℂ] ℂ).smulRight g') 1 = g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' := by simp only [Algebra.id.smul_eq_mul, one_mul, ContinuousLinearMap.one_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul'] nonrec theorem HasStrictDerivAt.cpow (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa using (hf.cpow hg h0).hasStrictDerivAt theorem HasStrictDerivAt.const_cpow (hf : HasStrictDerivAt f f' x) (h : c ≠ 0 ∨ f x ≠ 0) : HasStrictDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h).comp x hf theorem Complex.hasStrictDerivAt_cpow_const (h : x ∈ slitPlane) : HasStrictDerivAt (fun z : ℂ => z ^ c) (c * x ^ (c - 1)) x := by simpa only [mul_zero, add_zero, mul_one] using (hasStrictDerivAt_id x).cpow (hasStrictDerivAt_const x c) h theorem HasStrictDerivAt.cpow_const (hf : HasStrictDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasStrictDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).comp x hf theorem HasDerivAt.cpow (hf : HasDerivAt f f' x) (hg : HasDerivAt g g' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') x := by simpa only [aux] using (hf.hasFDerivAt.cpow hg h0).hasDerivAt theorem HasDerivAt.const_cpow (hf : HasDerivAt f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasDerivAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp x hf theorem HasDerivAt.cpow_const (hf : HasDerivAt f f' x) (h0 : f x ∈ slitPlane) : HasDerivAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp x hf theorem HasDerivWithinAt.cpow (hf : HasDerivWithinAt f f' s x) (hg : HasDerivWithinAt g g' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * Complex.log (f x) * g') s x := by simpa only [aux] using (hf.hasFDerivWithinAt.cpow hg h0).hasDerivWithinAt theorem HasDerivWithinAt.const_cpow (hf : HasDerivWithinAt f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) : HasDerivWithinAt (fun x => c ^ f x) (c ^ f x * Complex.log c * f') s x := (hasStrictDerivAt_const_cpow h0).hasDerivAt.comp_hasDerivWithinAt x hf theorem HasDerivWithinAt.cpow_const (hf : HasDerivWithinAt f f' s x) (h0 : f x ∈ slitPlane) : HasDerivWithinAt (fun x => f x ^ c) (c * f x ^ (c - 1) * f') s x := (Complex.hasStrictDerivAt_cpow_const h0).hasDerivAt.comp_hasDerivWithinAt x hf /-- Although `fun x => x ^ r` for fixed `r` is *not* complex-differentiable along the negative real line, it is still real-differentiable, and the derivative is what one would formally expect. See `hasDerivAt_ofReal_cpow_const` for an alternate formulation. -/ theorem hasDerivAt_ofReal_cpow_const' {x : ℝ} (hx : x ≠ 0) {r : ℂ} (hr : r ≠ -1) : HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1) / (r + 1)) (x ^ r) x := by rw [Ne, ← add_eq_zero_iff_eq_neg, ← Ne] at hr rcases lt_or_gt_of_ne hx.symm with (hx | hx) · -- easy case : `0 < x` apply HasDerivAt.comp_ofReal (e := fun y => (y : ℂ) ^ (r + 1) / (r + 1)) convert HasDerivAt.div_const (𝕜 := ℂ) ?_ (r + 1) using 1 · exact (mul_div_cancel_right₀ _ hr).symm · convert HasDerivAt.cpow_const ?_ ?_ using 1 · rw [add_sub_cancel_right, mul_comm]; exact (mul_one _).symm · exact hasDerivAt_id (x : ℂ) · simp [hx] · -- harder case : `x < 0` have : ∀ᶠ y : ℝ in 𝓝 x, (y : ℂ) ^ (r + 1) / (r + 1) = (-y : ℂ) ^ (r + 1) * exp (π * I * (r + 1)) / (r + 1) := by refine Filter.eventually_of_mem (Iio_mem_nhds hx) fun y hy => ?_ rw [ofReal_cpow_of_nonpos (le_of_lt hy)] refine HasDerivAt.congr_of_eventuallyEq ?_ this rw [ofReal_cpow_of_nonpos (le_of_lt hx)] suffices HasDerivAt (fun y : ℝ => (-↑y) ^ (r + 1) * exp (↑π * I * (r + 1))) ((r + 1) * (-↑x) ^ r * exp (↑π * I * r)) x by convert this.div_const (r + 1) using 1 conv_rhs => rw [mul_assoc, mul_comm, mul_div_cancel_right₀ _ hr] rw [mul_add ((π : ℂ) * _), mul_one, exp_add, exp_pi_mul_I, mul_comm (_ : ℂ) (-1 : ℂ), neg_one_mul] simp_rw [mul_neg, ← neg_mul, ← ofReal_neg] suffices HasDerivAt (fun y : ℝ => (↑(-y) : ℂ) ^ (r + 1)) (-(r + 1) * ↑(-x) ^ r) x by convert this.neg.mul_const _ using 1; ring suffices HasDerivAt (fun y : ℝ => (y : ℂ) ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) (-x) by convert @HasDerivAt.scomp ℝ _ ℂ _ _ x ℝ _ _ _ _ _ _ _ _ this (hasDerivAt_neg x) using 1 rw [real_smul, ofReal_neg 1, ofReal_one]; ring suffices HasDerivAt (fun y : ℂ => y ^ (r + 1)) ((r + 1) * ↑(-x) ^ r) ↑(-x) by exact this.comp_ofReal conv in ↑_ ^ _ => rw [(by ring : r = r + 1 - 1)] convert HasDerivAt.cpow_const ?_ ?_ using 1 · rw [add_sub_cancel_right, add_sub_cancel_right]; exact (mul_one _).symm · exact hasDerivAt_id ((-x : ℝ) : ℂ) · simp [hx] @[deprecated (since := "2024-12-15")] alias hasDerivAt_ofReal_cpow := hasDerivAt_ofReal_cpow_const' /-- An alternate formulation of `hasDerivAt_ofReal_cpow_const'`. -/ theorem hasDerivAt_ofReal_cpow_const {x : ℝ} (hx : x ≠ 0) {r : ℂ} (hr : r ≠ 0) : HasDerivAt (fun y : ℝ => (y : ℂ) ^ r) (r * x ^ (r - 1)) x := by have := HasDerivAt.const_mul r <| hasDerivAt_ofReal_cpow_const' hx (by rwa [ne_eq, sub_eq_neg_self]) simpa [sub_add_cancel, mul_div_cancel₀ _ hr] using this /-- A version of `DifferentiableAt.cpow_const` for a real function. -/ theorem DifferentiableAt.ofReal_cpow_const {f : ℝ → ℝ} {x : ℝ} (hf : DifferentiableAt ℝ f x) (h0 : f x ≠ 0) (h1 : c ≠ 0) : DifferentiableAt ℝ (fun (y : ℝ) => (f y : ℂ) ^ c) x := (hasDerivAt_ofReal_cpow_const h0 h1).differentiableAt.comp x hf theorem Complex.deriv_cpow_const (hx : x ∈ Complex.slitPlane) : deriv (fun (x : ℂ) ↦ x ^ c) x = c * x ^ (c - 1) := (hasStrictDerivAt_cpow_const hx).hasDerivAt.deriv /-- A version of `Complex.deriv_cpow_const` for a real variable. -/ theorem Complex.deriv_ofReal_cpow_const {x : ℝ} (hx : x ≠ 0) (hc : c ≠ 0) : deriv (fun x : ℝ ↦ (x : ℂ) ^ c) x = c * x ^ (c - 1) := (hasDerivAt_ofReal_cpow_const hx hc).deriv theorem deriv_cpow_const (hf : DifferentiableAt ℂ f x) (hx : f x ∈ Complex.slitPlane) : deriv (fun (x : ℂ) ↦ f x ^ c) x = c * f x ^ (c - 1) * deriv f x := (hf.hasDerivAt.cpow_const hx).deriv theorem isTheta_deriv_ofReal_cpow_const_atTop {c : ℂ} (hc : c ≠ 0) : deriv (fun (x : ℝ) => (x : ℂ) ^ c) =Θ[atTop] fun x => x ^ (c.re - 1) := by calc _ =ᶠ[atTop] fun x : ℝ ↦ c * x ^ (c - 1) := by filter_upwards [eventually_ne_atTop 0] with x hx using by rw [deriv_ofReal_cpow_const hx hc] _ =Θ[atTop] fun x : ℝ ↦ ‖(x : ℂ) ^ (c - 1)‖ := (Asymptotics.IsTheta.of_norm_eventuallyEq EventuallyEq.rfl).const_mul_left hc _ =ᶠ[atTop] fun x ↦ x ^ (c.re - 1) := by filter_upwards [eventually_gt_atTop 0] with x hx rw [norm_cpow_eq_rpow_re_of_pos hx, sub_re, one_re] theorem isBigO_deriv_ofReal_cpow_const_atTop (c : ℂ) : deriv (fun (x : ℝ) => (x : ℂ) ^ c) =O[atTop] fun x => x ^ (c.re - 1) := by obtain rfl | hc := eq_or_ne c 0 · simp_rw [cpow_zero, deriv_const', Asymptotics.isBigO_zero] · exact (isTheta_deriv_ofReal_cpow_const_atTop hc).1 end deriv namespace Real variable {x y z : ℝ} /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `0 < p.fst`. -/ theorem hasStrictFDerivAt_rpow_of_pos (p : ℝ × ℝ) (hp : 0 < p.1) : HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) := (continuousAt_fst.eventually (lt_mem_nhds hp)).mono fun p hp => rpow_def_of_pos hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne').mul hasStrictFDerivAt_snd).exp using 1 rw [rpow_sub_one hp.ne', ← rpow_def_of_pos hp, smul_add, smul_smul, mul_div_left_comm, div_eq_mul_inv, smul_smul, smul_smul, mul_assoc, add_comm] /-- `(x, y) ↦ x ^ y` is strictly differentiable at `p : ℝ × ℝ` such that `p.fst < 0`. -/ theorem hasStrictFDerivAt_rpow_of_neg (p : ℝ × ℝ) (hp : p.1 < 0) : HasStrictFDerivAt (fun x : ℝ × ℝ => x.1 ^ x.2) ((p.2 * p.1 ^ (p.2 - 1)) • ContinuousLinearMap.fst ℝ ℝ ℝ + (p.1 ^ p.2 * log p.1 - exp (log p.1 * p.2) * sin (p.2 * π) * π) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by have : (fun x : ℝ × ℝ => x.1 ^ x.2) =ᶠ[𝓝 p] fun x => exp (log x.1 * x.2) * cos (x.2 * π) := (continuousAt_fst.eventually (gt_mem_nhds hp)).mono fun p hp => rpow_def_of_neg hp _ refine HasStrictFDerivAt.congr_of_eventuallyEq ?_ this.symm convert ((hasStrictFDerivAt_fst.log hp.ne).mul hasStrictFDerivAt_snd).exp.mul (hasStrictFDerivAt_snd.mul_const π).cos using 1 simp_rw [rpow_sub_one hp.ne, smul_add, ← add_assoc, smul_smul, ← add_smul, ← mul_assoc, mul_comm (cos _), ← rpow_def_of_neg hp] rw [div_eq_mul_inv, add_comm]; congr 2 <;> ring /-- The function `fun (x, y) => x ^ y` is infinitely smooth at `(x, y)` unless `x = 0`. -/ theorem contDiffAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) {n : WithTop ℕ∞} : ContDiffAt ℝ n (fun p : ℝ × ℝ => p.1 ^ p.2) p := by rcases hp.lt_or_lt with hneg | hpos exacts [(((contDiffAt_fst.log hneg.ne).mul contDiffAt_snd).exp.mul (contDiffAt_snd.mul contDiffAt_const).cos).congr_of_eventuallyEq ((continuousAt_fst.eventually (gt_mem_nhds hneg)).mono fun p hp => rpow_def_of_neg hp _), ((contDiffAt_fst.log hpos.ne').mul contDiffAt_snd).exp.congr_of_eventuallyEq ((continuousAt_fst.eventually (lt_mem_nhds hpos)).mono fun p hp => rpow_def_of_pos hp _)] theorem differentiableAt_rpow_of_ne (p : ℝ × ℝ) (hp : p.1 ≠ 0) : DifferentiableAt ℝ (fun p : ℝ × ℝ => p.1 ^ p.2) p := (contDiffAt_rpow_of_ne p hp).differentiableAt le_rfl theorem _root_.HasStrictDerivAt.rpow {f g : ℝ → ℝ} {f' g' : ℝ} (hf : HasStrictDerivAt f f' x) (hg : HasStrictDerivAt g g' x) (h : 0 < f x) : HasStrictDerivAt (fun x => f x ^ g x) (f' * g x * f x ^ (g x - 1) + g' * f x ^ g x * Real.log (f x)) x := by convert (hasStrictFDerivAt_rpow_of_pos ((fun x => (f x, g x)) x) h).comp_hasStrictDerivAt x (hf.prodMk hg) using 1 simp [mul_assoc, mul_comm, mul_left_comm] theorem hasStrictDerivAt_rpow_const_of_ne {x : ℝ} (hx : x ≠ 0) (p : ℝ) : HasStrictDerivAt (fun x => x ^ p) (p * x ^ (p - 1)) x := by rcases hx.lt_or_lt with hx | hx · have := (hasStrictFDerivAt_rpow_of_neg (x, p) hx).comp_hasStrictDerivAt x
((hasStrictDerivAt_id x).prodMk (hasStrictDerivAt_const x p)) convert this using 1; simp · simpa using (hasStrictDerivAt_id x).rpow (hasStrictDerivAt_const x p) hx theorem hasStrictDerivAt_const_rpow {a : ℝ} (ha : 0 < a) (x : ℝ) : HasStrictDerivAt (fun x => a ^ x) (a ^ x * log a) x := by simpa using (hasStrictDerivAt_const _ _).rpow (hasStrictDerivAt_id x) ha lemma differentiableAt_rpow_const_of_ne (p : ℝ) {x : ℝ} (hx : x ≠ 0) :
Mathlib/Analysis/SpecialFunctions/Pow/Deriv.lean
366
374
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Computability.Primrec import Mathlib.Data.Nat.PSub import Mathlib.Data.PFun /-! # The partial recursive functions The partial recursive functions are defined similarly to the primitive recursive functions, but now all functions are partial, implemented using the `Part` monad, and there is an additional operation, called μ-recursion, which performs unbounded minimization: `μ f` returns the least natural number `n` for which `f n = 0`, or diverges if such `n` doesn't exist. ## Main definitions - `Nat.Partrec f`: `f` is partial recursive, for functions `f : ℕ →. ℕ` - `Partrec f`: `f` is partial recursive, for partial functions between `Primcodable` types - `Computable f`: `f` is partial recursive, for total functions between `Primcodable` types ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Encodable Denumerable Part attribute [-simp] not_forall namespace Nat section Rfind variable (p : ℕ →. Bool) private def lbp (m n : ℕ) : Prop := m = n + 1 ∧ ∀ k ≤ n, false ∈ p k private def wf_lbp (H : ∃ n, true ∈ p n ∧ ∀ k < n, (p k).Dom) : WellFounded (lbp p) := ⟨by let ⟨n, pn⟩ := H suffices ∀ m k, n ≤ k + m → Acc (lbp p) k by exact fun a => this _ _ (Nat.le_add_left _ _) intro m k kn induction' m with m IH generalizing k <;> refine ⟨_, fun y r => ?_⟩ <;> rcases r with ⟨rfl, a⟩ · injection mem_unique pn.1 (a _ kn) · exact IH _ (by rw [Nat.add_right_comm]; exact kn)⟩ variable (H : ∃ n, true ∈ p n ∧ ∀ k < n, (p k).Dom) /-- Find the smallest `n` satisfying `p n`, where all `p k` for `k < n` are defined as false. Returns a subtype. -/ def rfindX : { n // true ∈ p n ∧ ∀ m < n, false ∈ p m } := suffices ∀ k, (∀ n < k, false ∈ p n) → { n // true ∈ p n ∧ ∀ m < n, false ∈ p m } from this 0 fun _ => (Nat.not_lt_zero _).elim @WellFounded.fix _ _ (lbp p) (wf_lbp p H) (by intro m IH al have pm : (p m).Dom := by rcases H with ⟨n, h₁, h₂⟩ rcases lt_trichotomy m n with (h₃ | h₃ | h₃) · exact h₂ _ h₃ · rw [h₃] exact h₁.fst · injection mem_unique h₁ (al _ h₃) cases e : (p m).get pm · suffices ∀ᵉ k ≤ m, false ∈ p k from IH _ ⟨rfl, this⟩ fun n h => this _ (le_of_lt_succ h) intro n h rcases h.lt_or_eq_dec with h | h · exact al _ h · rw [h] exact ⟨_, e⟩ · exact ⟨m, ⟨_, e⟩, al⟩) end Rfind /-- Find the smallest `n` satisfying `p n`, where all `p k` for `k < n` are defined as false. Returns a `Part`. -/ def rfind (p : ℕ →. Bool) : Part ℕ := ⟨_, fun h => (rfindX p h).1⟩ theorem rfind_spec {p : ℕ →. Bool} {n : ℕ} (h : n ∈ rfind p) : true ∈ p n := h.snd ▸ (rfindX p h.fst).2.1 theorem rfind_min {p : ℕ →. Bool} {n : ℕ} (h : n ∈ rfind p) : ∀ {m : ℕ}, m < n → false ∈ p m := @(h.snd ▸ @((rfindX p h.fst).2.2)) @[simp] theorem rfind_dom {p : ℕ →. Bool} : (rfind p).Dom ↔ ∃ n, true ∈ p n ∧ ∀ {m : ℕ}, m < n → (p m).Dom := Iff.rfl theorem rfind_dom' {p : ℕ →. Bool} : (rfind p).Dom ↔ ∃ n, true ∈ p n ∧ ∀ {m : ℕ}, m ≤ n → (p m).Dom := exists_congr fun _ => and_congr_right fun pn => ⟨fun H _ h => (Decidable.eq_or_lt_of_le h).elim (fun e => e.symm ▸ pn.fst) (H _), fun H _ h => H (le_of_lt h)⟩ @[simp] theorem mem_rfind {p : ℕ →. Bool} {n : ℕ} : n ∈ rfind p ↔ true ∈ p n ∧ ∀ {m : ℕ}, m < n → false ∈ p m := ⟨fun h => ⟨rfind_spec h, @rfind_min _ _ h⟩, fun ⟨h₁, h₂⟩ => by let ⟨m, hm⟩ := dom_iff_mem.1 <| (@rfind_dom p).2 ⟨_, h₁, fun {m} mn => (h₂ mn).fst⟩ rcases lt_trichotomy m n with (h | h | h) · injection mem_unique (h₂ h) (rfind_spec hm) · rwa [← h] · injection mem_unique h₁ (rfind_min hm h)⟩ theorem rfind_min' {p : ℕ → Bool} {m : ℕ} (pm : p m) : ∃ n ∈ rfind p, n ≤ m := have : true ∈ (p : ℕ →. Bool) m := ⟨trivial, pm⟩ let ⟨n, hn⟩ := dom_iff_mem.1 <| (@rfind_dom p).2 ⟨m, this, fun {_} _ => ⟨⟩⟩ ⟨n, hn, not_lt.1 fun h => by injection mem_unique this (rfind_min hn h)⟩ theorem rfind_zero_none (p : ℕ →. Bool) (p0 : p 0 = Part.none) : rfind p = Part.none := eq_none_iff.2 fun _ h => let ⟨_, _, h₂⟩ := rfind_dom'.1 h.fst (p0 ▸ h₂ (zero_le _) : (@Part.none Bool).Dom) /-- Find the smallest `n` satisfying `f n`, where all `f k` for `k < n` are defined as false. Returns a `Part`. -/ def rfindOpt {α} (f : ℕ → Option α) : Part α := (rfind fun n => (f n).isSome).bind fun n => f n theorem rfindOpt_spec {α} {f : ℕ → Option α} {a} (h : a ∈ rfindOpt f) : ∃ n, a ∈ f n := let ⟨n, _, h₂⟩ := mem_bind_iff.1 h ⟨n, mem_coe.1 h₂⟩ theorem rfindOpt_dom {α} {f : ℕ → Option α} : (rfindOpt f).Dom ↔ ∃ n a, a ∈ f n := ⟨fun h => (rfindOpt_spec ⟨h, rfl⟩).imp fun _ h => ⟨_, h⟩, fun h => by have h' : ∃ n, (f n).isSome := h.imp fun n => Option.isSome_iff_exists.2 have s := Nat.find_spec h' have fd : (rfind fun n => (f n).isSome).Dom := ⟨Nat.find h', by simpa using s.symm, fun _ _ => trivial⟩ refine ⟨fd, ?_⟩ have := rfind_spec (get_mem fd) simpa using this⟩ theorem rfindOpt_mono {α} {f : ℕ → Option α} (H : ∀ {a m n}, m ≤ n → a ∈ f m → a ∈ f n) {a} : a ∈ rfindOpt f ↔ ∃ n, a ∈ f n := ⟨rfindOpt_spec, fun ⟨n, h⟩ => by have h' := rfindOpt_dom.2 ⟨_, _, h⟩ obtain ⟨k, hk⟩ := rfindOpt_spec ⟨h', rfl⟩ have := (H (le_max_left _ _) h).symm.trans (H (le_max_right _ _) hk) simp at this; simp [this, get_mem]⟩ /-- `Partrec f` means that the partial function `f : ℕ → ℕ` is partially recursive. -/ inductive Partrec : (ℕ →. ℕ) → Prop | zero : Partrec (pure 0) | succ : Partrec succ | left : Partrec ↑fun n : ℕ => n.unpair.1 | right : Partrec ↑fun n : ℕ => n.unpair.2 | pair {f g} : Partrec f → Partrec g → Partrec fun n => pair <$> f n <*> g n | comp {f g} : Partrec f → Partrec g → Partrec fun n => g n >>= f | prec {f g} : Partrec f → Partrec g → Partrec (unpaired fun a n => n.rec (f a) fun y IH => do let i ← IH; g (pair a (pair y i))) | rfind {f} : Partrec f → Partrec fun a => rfind fun n => (fun m => m = 0) <$> f (pair a n) namespace Partrec theorem of_eq {f g : ℕ →. ℕ} (hf : Partrec f) (H : ∀ n, f n = g n) : Partrec g := (funext H : f = g) ▸ hf theorem of_eq_tot {f : ℕ →. ℕ} {g : ℕ → ℕ} (hf : Partrec f) (H : ∀ n, g n ∈ f n) : Partrec g := hf.of_eq fun n => eq_some_iff.2 (H n) theorem of_primrec {f : ℕ → ℕ} (hf : Nat.Primrec f) : Partrec f := by induction hf with | zero => exact zero | succ => exact succ | left => exact left | right => exact right | pair _ _ pf pg => refine (pf.pair pg).of_eq_tot fun n => ?_ simp [Seq.seq] | comp _ _ pf pg => refine (pf.comp pg).of_eq_tot fun n => (by simp) | prec _ _ pf pg => refine (pf.prec pg).of_eq_tot fun n => ?_ simp only [unpaired, PFun.coe_val, bind_eq_bind] induction n.unpair.2 with | zero => simp | succ m IH => simp only [mem_bind_iff, mem_some_iff] exact ⟨_, IH, rfl⟩ protected theorem some : Partrec some := of_primrec Primrec.id theorem none : Partrec fun _ => none := (of_primrec (Nat.Primrec.const 1)).rfind.of_eq fun _ => eq_none_iff.2 fun _ ⟨h, _⟩ => by simp at h theorem prec' {f g h} (hf : Partrec f) (hg : Partrec g) (hh : Partrec h) : Partrec fun a => (f a).bind fun n => n.rec (g a) fun y IH => do {let i ← IH; h (Nat.pair a (Nat.pair y i))} := ((prec hg hh).comp (pair Partrec.some hf)).of_eq fun a => ext fun s => by simp [Seq.seq] theorem ppred : Partrec fun n => ppred n := have : Primrec₂ fun n m => if n = Nat.succ m then 0 else 1 := (Primrec.ite (@PrimrecRel.comp _ _ _ _ _ _ _ _ _ _ Primrec.eq Primrec.fst (_root_.Primrec.succ.comp Primrec.snd)) (_root_.Primrec.const 0) (_root_.Primrec.const 1)).to₂ (of_primrec (Primrec₂.unpaired'.2 this)).rfind.of_eq fun n => by cases n <;> simp · exact eq_none_iff.2 fun a ⟨⟨m, h, _⟩, _⟩ => by simp [show 0 ≠ m.succ by intro h; injection h] at h · refine eq_some_iff.2 ?_ simp only [mem_rfind, not_true, IsEmpty.forall_iff, decide_true, mem_some_iff, false_eq_decide_iff, true_and] intro m h simp [ne_of_gt h] end Partrec end Nat /-- Partially recursive partial functions `α → σ` between `Primcodable` types -/ def Partrec {α σ} [Primcodable α] [Primcodable σ] (f : α →. σ) := Nat.Partrec fun n => Part.bind (decode (α := α) n) fun a => (f a).map encode /-- Partially recursive partial functions `α → β → σ` between `Primcodable` types -/ def Partrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β →. σ) := Partrec fun p : α × β => f p.1 p.2 /-- Computable functions `α → σ` between `Primcodable` types: a function is computable if and only if it is partially recursive (as a partial function) -/ def Computable {α σ} [Primcodable α] [Primcodable σ] (f : α → σ) := Partrec (f : α →. σ) /-- Computable functions `α → β → σ` between `Primcodable` types -/ def Computable₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Computable fun p : α × β => f p.1 p.2 theorem Primrec.to_comp {α σ} [Primcodable α] [Primcodable σ] {f : α → σ} (hf : Primrec f) : Computable f := (Nat.Partrec.ppred.comp (Nat.Partrec.of_primrec hf)).of_eq fun n => by simp; cases decode (α := α) n <;> simp nonrec theorem Primrec₂.to_comp {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] {f : α → β → σ} (hf : Primrec₂ f) : Computable₂ f := hf.to_comp protected theorem Computable.partrec {α σ} [Primcodable α] [Primcodable σ] {f : α → σ} (hf : Computable f) : Partrec (f : α →. σ) := hf protected theorem Computable₂.partrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] {f : α → β → σ} (hf : Computable₂ f) : Partrec₂ fun a => (f a : β →. σ) := hf namespace Computable variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem of_eq {f g : α → σ} (hf : Computable f) (H : ∀ n, f n = g n) : Computable g := (funext H : f = g) ▸ hf theorem const (s : σ) : Computable fun _ : α => s := (Primrec.const _).to_comp theorem ofOption {f : α → Option β} (hf : Computable f) : Partrec fun a => (f a : Part β) := (Nat.Partrec.ppred.comp hf).of_eq fun n => by rcases decode (α := α) n with - | a <;> simp rcases f a with - | b <;> simp theorem to₂ {f : α × β → σ} (hf : Computable f) : Computable₂ fun a b => f (a, b) := hf.of_eq fun ⟨_, _⟩ => rfl protected theorem id : Computable (@id α) := Primrec.id.to_comp theorem fst : Computable (@Prod.fst α β) := Primrec.fst.to_comp theorem snd : Computable (@Prod.snd α β) := Primrec.snd.to_comp nonrec theorem pair {f : α → β} {g : α → γ} (hf : Computable f) (hg : Computable g) : Computable fun a => (f a, g a) := (hf.pair hg).of_eq fun n => by cases decode (α := α) n <;> simp [Seq.seq] theorem unpair : Computable Nat.unpair := Primrec.unpair.to_comp theorem succ : Computable Nat.succ := Primrec.succ.to_comp theorem pred : Computable Nat.pred := Primrec.pred.to_comp theorem nat_bodd : Computable Nat.bodd := Primrec.nat_bodd.to_comp theorem nat_div2 : Computable Nat.div2 := Primrec.nat_div2.to_comp theorem sumInl : Computable (@Sum.inl α β) := Primrec.sumInl.to_comp theorem sumInr : Computable (@Sum.inr α β) := Primrec.sumInr.to_comp @[deprecated (since := "2025-02-21")] alias sum_inl := Computable.sumInl @[deprecated (since := "2025-02-21")] alias sum_inr := Computable.sumInr theorem list_cons : Computable₂ (@List.cons α) := Primrec.list_cons.to_comp theorem list_reverse : Computable (@List.reverse α) := Primrec.list_reverse.to_comp theorem list_getElem? : Computable₂ ((·[·]? : List α → ℕ → Option α)) := Primrec.list_getElem?.to_comp @[deprecated (since := "2025-02-14")] alias list_get? := list_getElem? theorem list_append : Computable₂ ((· ++ ·) : List α → List α → List α) := Primrec.list_append.to_comp theorem list_concat : Computable₂ fun l (a : α) => l ++ [a] := Primrec.list_concat.to_comp theorem list_length : Computable (@List.length α) := Primrec.list_length.to_comp theorem vector_cons {n} : Computable₂ (@List.Vector.cons α n) := Primrec.vector_cons.to_comp theorem vector_toList {n} : Computable (@List.Vector.toList α n) := Primrec.vector_toList.to_comp theorem vector_length {n} : Computable (@List.Vector.length α n) := Primrec.vector_length.to_comp theorem vector_head {n} : Computable (@List.Vector.head α n) := Primrec.vector_head.to_comp theorem vector_tail {n} : Computable (@List.Vector.tail α n) := Primrec.vector_tail.to_comp theorem vector_get {n} : Computable₂ (@List.Vector.get α n) := Primrec.vector_get.to_comp theorem vector_ofFn' {n} : Computable (@List.Vector.ofFn α n) := Primrec.vector_ofFn'.to_comp theorem fin_app {n} : Computable₂ (@id (Fin n → σ)) := Primrec.fin_app.to_comp protected theorem encode : Computable (@encode α _) := Primrec.encode.to_comp protected theorem decode : Computable (decode (α := α)) := Primrec.decode.to_comp protected theorem ofNat (α) [Denumerable α] : Computable (ofNat α) := (Primrec.ofNat _).to_comp theorem encode_iff {f : α → σ} : (Computable fun a => encode (f a)) ↔ Computable f := Iff.rfl theorem option_some : Computable (@Option.some α) := Primrec.option_some.to_comp end Computable namespace Partrec variable {α : Type*} {β : Type*} {σ : Type*} [Primcodable α] [Primcodable β] [Primcodable σ] open Computable theorem of_eq {f g : α →. σ} (hf : Partrec f) (H : ∀ n, f n = g n) : Partrec g := (funext H : f = g) ▸ hf theorem of_eq_tot {f : α →. σ} {g : α → σ} (hf : Partrec f) (H : ∀ n, g n ∈ f n) : Computable g := hf.of_eq fun a => eq_some_iff.2 (H a) theorem none : Partrec fun _ : α => @Part.none σ := Nat.Partrec.none.of_eq fun n => by cases decode (α := α) n <;> simp protected theorem some : Partrec (@Part.some α) := Computable.id theorem _root_.Decidable.Partrec.const' (s : Part σ) [Decidable s.Dom] : Partrec fun _ : α => s := (Computable.ofOption (const (toOption s))).of_eq fun _ => of_toOption s theorem const' (s : Part σ) : Partrec fun _ : α => s := haveI := Classical.dec s.Dom Decidable.Partrec.const' s protected theorem bind {f : α →. β} {g : α → β →. σ} (hf : Partrec f) (hg : Partrec₂ g) : Partrec fun a => (f a).bind (g a) := (hg.comp (Nat.Partrec.some.pair hf)).of_eq fun n => by simp [Seq.seq]; rcases e : decode (α := α) n with - | a <;> simp [e, encodek] theorem map {f : α →. β} {g : α → β → σ} (hf : Partrec f) (hg : Computable₂ g) : Partrec fun a => (f a).map (g a) := by simpa [bind_some_eq_map] using Partrec.bind (g := fun a x => some (g a x)) hf hg theorem to₂ {f : α × β →. σ} (hf : Partrec f) : Partrec₂ fun a b => f (a, b) := hf.of_eq fun ⟨_, _⟩ => rfl theorem nat_rec {f : α → ℕ} {g : α →. σ} {h : α → ℕ × σ →. σ} (hf : Computable f) (hg : Partrec g) (hh : Partrec₂ h) : Partrec fun a => (f a).rec (g a) fun y IH => IH.bind fun i => h a (y, i) := (Nat.Partrec.prec' hf hg hh).of_eq fun n => by rcases e : decode (α := α) n with - | a <;> simp [e] induction' f a with m IH <;> simp rw [IH, Part.bind_map] congr; funext s simp [encodek] nonrec theorem comp {f : β →. σ} {g : α → β} (hf : Partrec f) (hg : Computable g) : Partrec fun a => f (g a) := (hf.comp hg).of_eq fun n => by simp; rcases e : decode (α := α) n with - | a <;> simp [e, encodek] theorem nat_iff {f : ℕ →. ℕ} : Partrec f ↔ Nat.Partrec f := by simp [Partrec, map_id'] theorem map_encode_iff {f : α →. σ} : (Partrec fun a => (f a).map encode) ↔ Partrec f := Iff.rfl end Partrec namespace Partrec₂ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem unpaired {f : ℕ → ℕ →. α} : Partrec (Nat.unpaired f) ↔ Partrec₂ f := ⟨fun h => by simpa using Partrec.comp (g := fun p : ℕ × ℕ => (p.1, p.2)) h Primrec₂.pair.to_comp, fun h => h.comp Primrec.unpair.to_comp⟩ theorem unpaired' {f : ℕ → ℕ →. ℕ} : Nat.Partrec (Nat.unpaired f) ↔ Partrec₂ f := Partrec.nat_iff.symm.trans unpaired nonrec theorem comp {f : β → γ →. σ} {g : α → β} {h : α → γ} (hf : Partrec₂ f) (hg : Computable g) (hh : Computable h) : Partrec fun a => f (g a) (h a) := hf.comp (hg.pair hh) theorem comp₂ {f : γ → δ →. σ} {g : α → β → γ} {h : α → β → δ} (hf : Partrec₂ f) (hg : Computable₂ g) (hh : Computable₂ h) : Partrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh end Partrec₂ namespace Computable variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] nonrec theorem comp {f : β → σ} {g : α → β} (hf : Computable f) (hg : Computable g) : Computable fun a => f (g a) := hf.comp hg theorem comp₂ {f : γ → σ} {g : α → β → γ} (hf : Computable f) (hg : Computable₂ g) : Computable₂ fun a b => f (g a b) := hf.comp hg end Computable namespace Computable₂ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Computable fun p : α × β => f p.1 p.2) : Computable₂ f := hf nonrec theorem comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Computable₂ f) (hg : Computable g) (hh : Computable h) : Computable fun a => f (g a) (h a) := hf.comp (hg.pair hh) theorem comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Computable₂ f) (hg : Computable₂ g) (hh : Computable₂ h) : Computable₂ fun a b => f (g a b) (h a b) := hf.comp hg hh end Computable₂ namespace Partrec variable {α : Type*} {σ : Type*} [Primcodable α] [Primcodable σ] open Computable theorem rfind {p : α → ℕ →. Bool} (hp : Partrec₂ p) : Partrec fun a => Nat.rfind (p a) := (Nat.Partrec.rfind <| hp.map ((Primrec.dom_bool fun b => cond b 0 1).comp Primrec.snd).to₂.to_comp).of_eq fun n => by rcases e : decode (α := α) n with - | a <;> simp [e, Nat.rfind_zero_none, map_id'] congr; funext n simp only [map_map, Function.comp] refine map_id' (fun b => ?_) _ cases b <;> rfl theorem rfindOpt {f : α → ℕ → Option σ} (hf : Computable₂ f) : Partrec fun a => Nat.rfindOpt (f a) := (rfind (Primrec.option_isSome.to_comp.comp hf).partrec.to₂).bind (ofOption hf) theorem nat_casesOn_right {f : α → ℕ} {g : α → σ} {h : α → ℕ →. σ} (hf : Computable f) (hg : Computable g) (hh : Partrec₂ h) : Partrec fun a => (f a).casesOn (some (g a)) (h a) := (nat_rec hf hg (hh.comp fst (pred.comp <| hf.comp fst)).to₂).of_eq fun a => by simp only [PFun.coe_val, Nat.pred_eq_sub_one]; rcases f a with - | n <;> simp refine ext fun b => ⟨fun H => ?_, fun H => ?_⟩ · rcases mem_bind_iff.1 H with ⟨c, _, h₂⟩ exact h₂ · have : ∀ m, (Nat.rec (motive := fun _ => Part σ) (Part.some (g a)) (fun y IH => IH.bind fun _ => h a n) m).Dom := by intro m induction m <;> simp [*, H.fst] exact ⟨⟨this n, H.fst⟩, H.snd⟩ theorem bind_decode₂_iff {f : α →. σ} : Partrec f ↔ Nat.Partrec fun n => Part.bind (decode₂ α n) fun a => (f a).map encode := ⟨fun hf => nat_iff.1 <| (Computable.ofOption Primrec.decode₂.to_comp).bind <| (map hf (Computable.encode.comp snd).to₂).comp snd, fun h => map_encode_iff.1 <| by simpa [encodek₂] using (nat_iff.2 h).comp (@Computable.encode α _)⟩ theorem vector_mOfFn : ∀ {n} {f : Fin n → α →. σ}, (∀ i, Partrec (f i)) → Partrec fun a : α => Vector.mOfFn fun i => f i a | 0, _, _ => const _ | n + 1, f, hf => by simp only [Vector.mOfFn, Nat.add_eq, Nat.add_zero, pure_eq_some, bind_eq_bind] exact (hf 0).bind (Partrec.bind ((vector_mOfFn fun i => hf i.succ).comp fst) (Primrec.vector_cons.to_comp.comp (snd.comp fst) snd)) end Partrec @[simp] theorem Vector.mOfFn_part_some {α n} : ∀ f : Fin n → α, (List.Vector.mOfFn fun i => Part.some (f i)) = Part.some (List.Vector.ofFn f) := Vector.mOfFn_pure namespace Computable variable {α : Type*} {β : Type*} {γ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] theorem option_some_iff {f : α → σ} : (Computable fun a => Option.some (f a)) ↔ Computable f := ⟨fun h => encode_iff.1 <| Primrec.pred.to_comp.comp <| encode_iff.2 h, option_some.comp⟩ theorem bind_decode_iff {f : α → β → Option σ} : (Computable₂ fun a n => (decode (α := β) n).bind (f a)) ↔ Computable₂ f := ⟨fun hf => Nat.Partrec.of_eq (((Partrec.nat_iff.2 (Nat.Partrec.ppred.comp <| Nat.Partrec.of_primrec <| Primcodable.prim (α := β))).comp snd).bind (Computable.comp hf fst).to₂.partrec₂) fun n => by simp only [decode_prod_val, decode_nat, Option.map_some', PFun.coe_val, bind_eq_bind, bind_some, Part.map_bind, map_some] cases decode (α := α) n.unpair.1 <;> simp cases decode (α := β) n.unpair.2 <;> simp, fun hf => by have : Partrec fun a : α × ℕ => (encode (decode (α := β) a.2)).casesOn (some Option.none) fun n => Part.map (f a.1) (decode (α := β) n) := Partrec.nat_casesOn_right (h := fun (a : α × ℕ) (n : ℕ) ↦ map (fun b ↦ f a.1 b) (Part.ofOption (decode n))) (Primrec.encdec.to_comp.comp snd) (const Option.none) ((ofOption (Computable.decode.comp snd)).map (hf.comp (fst.comp <| fst.comp fst) snd).to₂) refine this.of_eq fun a => ?_ simp; cases decode (α := β) a.2 <;> simp [encodek]⟩
theorem map_decode_iff {f : α → β → σ} : (Computable₂ fun a n => (decode (α := β) n).map (f a)) ↔ Computable₂ f := by convert (bind_decode_iff (f := fun a => Option.some ∘ f a)).trans option_some_iff apply Option.map_eq_bind theorem nat_rec {f : α → ℕ} {g : α → σ} {h : α → ℕ × σ → σ} (hf : Computable f) (hg : Computable g) (hh : Computable₂ h) : Computable fun a => Nat.rec (motive := fun _ => σ) (g a) (fun y IH => h a (y, IH)) (f a) := (Partrec.nat_rec hf hg hh.partrec₂).of_eq fun a => by simp; induction f a <;> simp [*] theorem nat_casesOn {f : α → ℕ} {g : α → σ} {h : α → ℕ → σ} (hf : Computable f) (hg : Computable g) (hh : Computable₂ h) :
Mathlib/Computability/Partrec.lean
581
592
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang, Yury Kudryashov -/ import Mathlib.Order.UpperLower.Closure import Mathlib.Order.UpperLower.Fibration import Mathlib.Tactic.TFAE import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Maps.OpenQuotient /-! # Inseparable points in a topological space In this file we prove basic properties of the following notions defined elsewhere. * `Specializes` (notation: `x ⤳ y`) : a relation saying that `𝓝 x ≤ 𝓝 y`; * `Inseparable`: a relation saying that two points in a topological space have the same neighbourhoods; equivalently, they can't be separated by an open set; * `InseparableSetoid X`: same relation, as a `Setoid`; * `SeparationQuotient X`: the quotient of `X` by its `InseparableSetoid`. We also prove various basic properties of the relation `Inseparable`. ## Notations - `x ⤳ y`: notation for `Specializes x y`; - `x ~ᵢ y` is used as a local notation for `Inseparable x y`; - `𝓝 x` is the neighbourhoods filter `nhds x` of a point `x`, defined elsewhere. ## Tags topological space, separation setoid -/ open Set Filter Function Topology List variable {X Y Z α ι : Type*} {π : ι → Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [∀ i, TopologicalSpace (π i)] {x y z : X} {s : Set X} {f g : X → Y} /-! ### `Specializes` relation -/ /-- A collection of equivalent definitions of `x ⤳ y`. The public API is given by `iff` lemmas below. -/ theorem specializes_TFAE (x y : X) : TFAE [x ⤳ y, pure x ≤ 𝓝 y, ∀ s : Set X , IsOpen s → y ∈ s → x ∈ s, ∀ s : Set X , IsClosed s → x ∈ s → y ∈ s, y ∈ closure ({ x } : Set X), closure ({ y } : Set X) ⊆ closure { x }, ClusterPt y (pure x)] := by tfae_have 1 → 2 := (pure_le_nhds _).trans tfae_have 2 → 3 := fun h s hso hy => h (hso.mem_nhds hy) tfae_have 3 → 4 := fun h s hsc hx => of_not_not fun hy => h sᶜ hsc.isOpen_compl hy hx tfae_have 4 → 5 := fun h => h _ isClosed_closure (subset_closure <| mem_singleton _) tfae_have 6 ↔ 5 := isClosed_closure.closure_subset_iff.trans singleton_subset_iff tfae_have 5 ↔ 7 := by rw [mem_closure_iff_clusterPt, principal_singleton] tfae_have 5 → 1 := by refine fun h => (nhds_basis_opens _).ge_iff.2 ?_ rintro s ⟨hy, ho⟩ rcases mem_closure_iff.1 h s ho hy with ⟨z, hxs, rfl : z = x⟩ exact ho.mem_nhds hxs tfae_finish theorem specializes_iff_nhds : x ⤳ y ↔ 𝓝 x ≤ 𝓝 y := Iff.rfl theorem Specializes.not_disjoint (h : x ⤳ y) : ¬Disjoint (𝓝 x) (𝓝 y) := fun hd ↦ absurd (hd.mono_right h) <| by simp [NeBot.ne'] theorem specializes_iff_pure : x ⤳ y ↔ pure x ≤ 𝓝 y := (specializes_TFAE x y).out 0 1 alias ⟨Specializes.nhds_le_nhds, _⟩ := specializes_iff_nhds alias ⟨Specializes.pure_le_nhds, _⟩ := specializes_iff_pure theorem ker_nhds_eq_specializes : (𝓝 x).ker = {y | y ⤳ x} := by ext; simp [specializes_iff_pure, le_def] theorem specializes_iff_forall_open : x ⤳ y ↔ ∀ s : Set X, IsOpen s → y ∈ s → x ∈ s := (specializes_TFAE x y).out 0 2 theorem Specializes.mem_open (h : x ⤳ y) (hs : IsOpen s) (hy : y ∈ s) : x ∈ s := specializes_iff_forall_open.1 h s hs hy theorem IsOpen.not_specializes (hs : IsOpen s) (hx : x ∉ s) (hy : y ∈ s) : ¬x ⤳ y := fun h => hx <| h.mem_open hs hy theorem specializes_iff_forall_closed : x ⤳ y ↔ ∀ s : Set X, IsClosed s → x ∈ s → y ∈ s := (specializes_TFAE x y).out 0 3 theorem Specializes.mem_closed (h : x ⤳ y) (hs : IsClosed s) (hx : x ∈ s) : y ∈ s := specializes_iff_forall_closed.1 h s hs hx theorem IsClosed.not_specializes (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬x ⤳ y := fun h => hy <| h.mem_closed hs hx theorem specializes_iff_mem_closure : x ⤳ y ↔ y ∈ closure ({x} : Set X) := (specializes_TFAE x y).out 0 4 alias ⟨Specializes.mem_closure, _⟩ := specializes_iff_mem_closure theorem specializes_iff_closure_subset : x ⤳ y ↔ closure ({y} : Set X) ⊆ closure {x} := (specializes_TFAE x y).out 0 5 alias ⟨Specializes.closure_subset, _⟩ := specializes_iff_closure_subset theorem specializes_iff_clusterPt : x ⤳ y ↔ ClusterPt y (pure x) := (specializes_TFAE x y).out 0 6 theorem Filter.HasBasis.specializes_iff {ι} {p : ι → Prop} {s : ι → Set X} (h : (𝓝 y).HasBasis p s) : x ⤳ y ↔ ∀ i, p i → x ∈ s i := specializes_iff_pure.trans h.ge_iff theorem specializes_rfl : x ⤳ x := le_rfl @[refl] theorem specializes_refl (x : X) : x ⤳ x := specializes_rfl @[trans] theorem Specializes.trans : x ⤳ y → y ⤳ z → x ⤳ z := le_trans theorem specializes_of_eq (e : x = y) : x ⤳ y := e ▸ specializes_refl x alias Specializes.of_eq := specializes_of_eq theorem specializes_of_nhdsWithin (h₁ : 𝓝[s] x ≤ 𝓝[s] y) (h₂ : x ∈ s) : x ⤳ y := specializes_iff_pure.2 <| calc pure x ≤ 𝓝[s] x := le_inf (pure_le_nhds _) (le_principal_iff.2 h₂) _ ≤ 𝓝[s] y := h₁ _ ≤ 𝓝 y := inf_le_left theorem Specializes.map_of_continuousAt (h : x ⤳ y) (hy : ContinuousAt f y) : f x ⤳ f y := specializes_iff_pure.2 fun _s hs => mem_pure.2 <| mem_preimage.1 <| mem_of_mem_nhds <| hy.mono_left h hs theorem Specializes.map (h : x ⤳ y) (hf : Continuous f) : f x ⤳ f y := h.map_of_continuousAt hf.continuousAt theorem Topology.IsInducing.specializes_iff (hf : IsInducing f) : f x ⤳ f y ↔ x ⤳ y := by simp only [specializes_iff_mem_closure, hf.closure_eq_preimage_closure_image, image_singleton, mem_preimage] @[deprecated (since := "2024-10-28")] alias Inducing.specializes_iff := IsInducing.specializes_iff theorem subtype_specializes_iff {p : X → Prop} (x y : Subtype p) : x ⤳ y ↔ (x : X) ⤳ y := IsInducing.subtypeVal.specializes_iff.symm @[simp] theorem specializes_prod {x₁ x₂ : X} {y₁ y₂ : Y} : (x₁, y₁) ⤳ (x₂, y₂) ↔ x₁ ⤳ x₂ ∧ y₁ ⤳ y₂ := by simp only [Specializes, nhds_prod_eq, prod_le_prod] theorem Specializes.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ⤳ x₂) (hy : y₁ ⤳ y₂) : (x₁, y₁) ⤳ (x₂, y₂) := specializes_prod.2 ⟨hx, hy⟩ theorem Specializes.fst {a b : X × Y} (h : a ⤳ b) : a.1 ⤳ b.1 := (specializes_prod.1 h).1 theorem Specializes.snd {a b : X × Y} (h : a ⤳ b) : a.2 ⤳ b.2 := (specializes_prod.1 h).2 @[simp] theorem specializes_pi {f g : ∀ i, π i} : f ⤳ g ↔ ∀ i, f i ⤳ g i := by simp only [Specializes, nhds_pi, pi_le_pi] theorem not_specializes_iff_exists_open : ¬x ⤳ y ↔ ∃ S : Set X, IsOpen S ∧ y ∈ S ∧ x ∉ S := by rw [specializes_iff_forall_open] push_neg rfl theorem not_specializes_iff_exists_closed : ¬x ⤳ y ↔ ∃ S : Set X, IsClosed S ∧ x ∈ S ∧ y ∉ S := by rw [specializes_iff_forall_closed] push_neg rfl theorem IsOpen.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsOpen s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, f x ⤳ g x) : Continuous (s.piecewise f g) := by have : ∀ U, IsOpen U → g ⁻¹' U ⊆ f ⁻¹' U := fun U hU x hx ↦ (hspec x).mem_open hU hx rw [continuous_def] intro U hU rw [piecewise_preimage, ite_eq_of_subset_right _ (this U hU)] exact hU.preimage hf |>.inter hs |>.union (hU.preimage hg) theorem IsClosed.continuous_piecewise_of_specializes [DecidablePred (· ∈ s)] (hs : IsClosed s) (hf : Continuous f) (hg : Continuous g) (hspec : ∀ x, g x ⤳ f x) : Continuous (s.piecewise f g) := by simpa only [piecewise_compl] using hs.isOpen_compl.continuous_piecewise_of_specializes hg hf hspec attribute [local instance] specializationPreorder /-- A continuous function is monotone with respect to the specialization preorders on the domain and the codomain. -/ theorem Continuous.specialization_monotone (hf : Continuous f) : Monotone f := fun _ _ h => h.map hf lemma closure_singleton_eq_Iic (x : X) : closure {x} = Iic x := Set.ext fun _ ↦ specializes_iff_mem_closure.symm /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `x ⤳ y`. -/ def StableUnderSpecialization (s : Set X) : Prop := ∀ ⦃x y⦄, x ⤳ y → x ∈ s → y ∈ s /-- A subset `S` of a topological space is stable under specialization if `x ∈ S → y ∈ S` for all `y ⤳ x`. -/ def StableUnderGeneralization (s : Set X) : Prop := ∀ ⦃x y⦄, y ⤳ x → x ∈ s → y ∈ s example {s : Set X} : StableUnderSpecialization s ↔ IsLowerSet s := Iff.rfl example {s : Set X} : StableUnderGeneralization s ↔ IsUpperSet s := Iff.rfl lemma IsClosed.stableUnderSpecialization {s : Set X} (hs : IsClosed s) : StableUnderSpecialization s := fun _ _ e ↦ e.mem_closed hs lemma IsOpen.stableUnderGeneralization {s : Set X} (hs : IsOpen s) : StableUnderGeneralization s := fun _ _ e ↦ e.mem_open hs @[simp] lemma stableUnderSpecialization_compl_iff {s : Set X} : StableUnderSpecialization sᶜ ↔ StableUnderGeneralization s := isLowerSet_compl @[simp] lemma stableUnderGeneralization_compl_iff {s : Set X} : StableUnderGeneralization sᶜ ↔ StableUnderSpecialization s := isUpperSet_compl alias ⟨_, StableUnderGeneralization.compl⟩ := stableUnderSpecialization_compl_iff alias ⟨_, StableUnderSpecialization.compl⟩ := stableUnderGeneralization_compl_iff lemma stableUnderSpecialization_univ : StableUnderSpecialization (univ : Set X) := isLowerSet_univ lemma stableUnderSpecialization_empty : StableUnderSpecialization (∅ : Set X) := isLowerSet_empty lemma stableUnderGeneralization_univ : StableUnderGeneralization (univ : Set X) := isUpperSet_univ lemma stableUnderGeneralization_empty : StableUnderGeneralization (∅ : Set X) := isUpperSet_empty lemma stableUnderSpecialization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋃₀ S) := isLowerSet_sUnion H lemma stableUnderSpecialization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderSpecialization s) : StableUnderSpecialization (⋂₀ S) := isLowerSet_sInter H lemma stableUnderGeneralization_sUnion (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋃₀ S) := isUpperSet_sUnion H lemma stableUnderGeneralization_sInter (S : Set (Set X)) (H : ∀ s ∈ S, StableUnderGeneralization s) : StableUnderGeneralization (⋂₀ S) := isUpperSet_sInter H lemma stableUnderSpecialization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋃ i, S i) := isLowerSet_iUnion H lemma stableUnderSpecialization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderSpecialization (S i)) : StableUnderSpecialization (⋂ i, S i) := isLowerSet_iInter H lemma stableUnderGeneralization_iUnion {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋃ i, S i) := isUpperSet_iUnion H lemma stableUnderGeneralization_iInter {ι : Sort*} (S : ι → Set X) (H : ∀ i, StableUnderGeneralization (S i)) : StableUnderGeneralization (⋂ i, S i) := isUpperSet_iInter H lemma Union_closure_singleton_eq_iff {s : Set X} : (⋃ x ∈ s, closure {x}) = s ↔ StableUnderSpecialization s := show _ ↔ IsLowerSet s by simp only [closure_singleton_eq_Iic, ← lowerClosure_eq, coe_lowerClosure] lemma stableUnderSpecialization_iff_Union_eq {s : Set X} : StableUnderSpecialization s ↔ (⋃ x ∈ s, closure {x}) = s := Union_closure_singleton_eq_iff.symm alias ⟨StableUnderSpecialization.Union_eq, _⟩ := stableUnderSpecialization_iff_Union_eq /-- A set is stable under specialization iff it is a union of closed sets. -/ lemma stableUnderSpecialization_iff_exists_sUnion_eq {s : Set X} : StableUnderSpecialization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsClosed s) ∧ ⋃₀ S = s := by refine ⟨fun H ↦ ⟨(fun x : X ↦ closure {x}) '' s, ?_, ?_⟩, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderSpecialization_sUnion S (fun x hx ↦ (hS x hx).stableUnderSpecialization)⟩ · rintro _ ⟨_, _, rfl⟩; exact isClosed_closure · conv_rhs => rw [← H.Union_eq] simp /-- A set is stable under generalization iff it is an intersection of open sets. -/ lemma stableUnderGeneralization_iff_exists_sInter_eq {s : Set X} : StableUnderGeneralization s ↔ ∃ (S : Set (Set X)), (∀ s ∈ S, IsOpen s) ∧ ⋂₀ S = s := by refine ⟨?_, fun ⟨S, hS, e⟩ ↦ e ▸ stableUnderGeneralization_sInter S (fun x hx ↦ (hS x hx).stableUnderGeneralization)⟩ rw [← stableUnderSpecialization_compl_iff, stableUnderSpecialization_iff_exists_sUnion_eq] exact fun ⟨S, h₁, h₂⟩ ↦ ⟨(·ᶜ) '' S, fun s ⟨t, ht, e⟩ ↦ e ▸ (h₁ t ht).isOpen_compl, compl_injective ((sUnion_eq_compl_sInter_compl S).symm.trans h₂)⟩ lemma StableUnderSpecialization.preimage {s : Set Y} (hs : StableUnderSpecialization s) (hf : Continuous f) : StableUnderSpecialization (f ⁻¹' s) := IsLowerSet.preimage hs hf.specialization_monotone lemma StableUnderGeneralization.preimage {s : Set Y} (hs : StableUnderGeneralization s) (hf : Continuous f) : StableUnderGeneralization (f ⁻¹' s) := IsUpperSet.preimage hs hf.specialization_monotone /-- A map `f` between topological spaces is specializing if specializations lifts along `f`, i.e. for each `f x' ⤳ y` there is some `x` with `x' ⤳ x` whose image is `y`. -/ def SpecializingMap (f : X → Y) : Prop := Relation.Fibration (flip (· ⤳ ·)) (flip (· ⤳ ·)) f /-- A map `f` between topological spaces is generalizing if generalizations lifts along `f`, i.e. for each `y ⤳ f x'` there is some `x ⤳ x'` whose image is `y`. -/ def GeneralizingMap (f : X → Y) : Prop := Relation.Fibration (· ⤳ ·) (· ⤳ ·) f lemma specializingMap_iff_closure_singleton_subset : SpecializingMap f ↔ ∀ x, closure {f x} ⊆ f '' closure {x} := by simp only [SpecializingMap, Relation.Fibration, flip, specializes_iff_mem_closure]; rfl alias ⟨SpecializingMap.closure_singleton_subset, _⟩ := specializingMap_iff_closure_singleton_subset lemma SpecializingMap.stableUnderSpecialization_image (hf : SpecializingMap f) {s : Set X} (hs : StableUnderSpecialization s) : StableUnderSpecialization (f '' s) := IsLowerSet.image_fibration hf hs alias StableUnderSpecialization.image := SpecializingMap.stableUnderSpecialization_image lemma specializingMap_iff_stableUnderSpecialization_image_singleton : SpecializingMap f ↔ ∀ x, StableUnderSpecialization (f '' closure {x}) := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_isLowerSet_image_Iic lemma specializingMap_iff_stableUnderSpecialization_image : SpecializingMap f ↔ ∀ s, StableUnderSpecialization s → StableUnderSpecialization (f '' s) := Relation.fibration_iff_isLowerSet_image lemma specializingMap_iff_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, f '' closure {x} = closure {f x} := by simpa only [closure_singleton_eq_Iic] using Relation.fibration_iff_image_Iic hf.specialization_monotone lemma specializingMap_iff_isClosed_image_closure_singleton (hf : Continuous f) : SpecializingMap f ↔ ∀ x, IsClosed (f '' closure {x}) := by refine ⟨fun h x ↦ ?_, fun h ↦ specializingMap_iff_stableUnderSpecialization_image_singleton.mpr (fun x ↦ (h x).stableUnderSpecialization)⟩ rw [(specializingMap_iff_closure_singleton hf).mp h x] exact isClosed_closure lemma SpecializingMap.comp {f : X → Y} {g : Y → Z} (hf : SpecializingMap f) (hg : SpecializingMap g) : SpecializingMap (g ∘ f) := by simp only [specializingMap_iff_stableUnderSpecialization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) lemma IsClosedMap.specializingMap (hf : IsClosedMap f) : SpecializingMap f := specializingMap_iff_stableUnderSpecialization_image_singleton.mpr <| fun _ ↦ (hf _ isClosed_closure).stableUnderSpecialization lemma Topology.IsInducing.specializingMap (hf : IsInducing f) (h : StableUnderSpecialization (range f)) : SpecializingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ @[deprecated (since := "2024-10-28")] alias Inducing.specializingMap := IsInducing.specializingMap lemma Topology.IsInducing.generalizingMap (hf : IsInducing f) (h : StableUnderGeneralization (range f)) : GeneralizingMap f := by intros x y e obtain ⟨y, rfl⟩ := h e ⟨x, rfl⟩ exact ⟨_, hf.specializes_iff.mp e, rfl⟩ @[deprecated (since := "2024-10-28")] alias Inducing.generalizingMap := IsInducing.generalizingMap lemma IsOpenEmbedding.generalizingMap (hf : IsOpenEmbedding f) : GeneralizingMap f := hf.isInducing.generalizingMap hf.isOpen_range.stableUnderGeneralization lemma SpecializingMap.stableUnderSpecialization_range (h : SpecializingMap f) : StableUnderSpecialization (range f) := @image_univ _ _ f ▸ stableUnderSpecialization_univ.image h lemma GeneralizingMap.stableUnderGeneralization_image (hf : GeneralizingMap f) {s : Set X} (hs : StableUnderGeneralization s) : StableUnderGeneralization (f '' s) := IsUpperSet.image_fibration hf hs lemma GeneralizingMap_iff_stableUnderGeneralization_image : GeneralizingMap f ↔ ∀ s, StableUnderGeneralization s → StableUnderGeneralization (f '' s) := Relation.fibration_iff_isUpperSet_image alias StableUnderGeneralization.image := GeneralizingMap.stableUnderGeneralization_image lemma GeneralizingMap.stableUnderGeneralization_range (h : GeneralizingMap f) : StableUnderGeneralization (range f) := @image_univ _ _ f ▸ stableUnderGeneralization_univ.image h lemma GeneralizingMap.comp {f : X → Y} {g : Y → Z} (hf : GeneralizingMap f) (hg : GeneralizingMap g) : GeneralizingMap (g ∘ f) := by simp only [GeneralizingMap_iff_stableUnderGeneralization_image, Set.image_comp] at * exact fun s h ↦ hg _ (hf _ h) /-! ### `Inseparable` relation -/ local infixl:0 " ~ᵢ " => Inseparable theorem inseparable_def : (x ~ᵢ y) ↔ 𝓝 x = 𝓝 y := Iff.rfl theorem inseparable_iff_specializes_and : (x ~ᵢ y) ↔ x ⤳ y ∧ y ⤳ x := le_antisymm_iff theorem Inseparable.specializes (h : x ~ᵢ y) : x ⤳ y := h.le theorem Inseparable.specializes' (h : x ~ᵢ y) : y ⤳ x := h.ge theorem Specializes.antisymm (h₁ : x ⤳ y) (h₂ : y ⤳ x) : x ~ᵢ y := le_antisymm h₁ h₂ theorem inseparable_iff_forall_isOpen : (x ~ᵢ y) ↔ ∀ s : Set X, IsOpen s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_open, ← forall_and, ← iff_def, Iff.comm] @[deprecated (since := "2024-11-18")] alias inseparable_iff_forall_open := inseparable_iff_forall_isOpen theorem not_inseparable_iff_exists_open : ¬(x ~ᵢ y) ↔ ∃ s : Set X, IsOpen s ∧ Xor' (x ∈ s) (y ∈ s) := by simp [inseparable_iff_forall_isOpen, ← xor_iff_not_iff] theorem inseparable_iff_forall_isClosed : (x ~ᵢ y) ↔ ∀ s : Set X, IsClosed s → (x ∈ s ↔ y ∈ s) := by simp only [inseparable_iff_specializes_and, specializes_iff_forall_closed, ← forall_and, ← iff_def] @[deprecated (since := "2024-11-18")] alias inseparable_iff_forall_closed := inseparable_iff_forall_isClosed theorem inseparable_iff_mem_closure : (x ~ᵢ y) ↔ x ∈ closure ({y} : Set X) ∧ y ∈ closure ({x} : Set X) := inseparable_iff_specializes_and.trans <| by simp only [specializes_iff_mem_closure, and_comm] theorem inseparable_iff_closure_eq : (x ~ᵢ y) ↔ closure ({x} : Set X) = closure {y} := by simp only [inseparable_iff_specializes_and, specializes_iff_closure_subset, ← subset_antisymm_iff, eq_comm] theorem inseparable_of_nhdsWithin_eq (hx : x ∈ s) (hy : y ∈ s) (h : 𝓝[s] x = 𝓝[s] y) : x ~ᵢ y := (specializes_of_nhdsWithin h.le hx).antisymm (specializes_of_nhdsWithin h.ge hy) theorem Topology.IsInducing.inseparable_iff (hf : IsInducing f) : (f x ~ᵢ f y) ↔ (x ~ᵢ y) := by simp only [inseparable_iff_specializes_and, hf.specializes_iff] @[deprecated (since := "2024-10-28")] alias Inducing.inseparable_iff := IsInducing.inseparable_iff theorem subtype_inseparable_iff {p : X → Prop} (x y : Subtype p) : (x ~ᵢ y) ↔ ((x : X) ~ᵢ y) := IsInducing.subtypeVal.inseparable_iff.symm @[simp] theorem inseparable_prod {x₁ x₂ : X} {y₁ y₂ : Y} : ((x₁, y₁) ~ᵢ (x₂, y₂)) ↔ (x₁ ~ᵢ x₂) ∧ (y₁ ~ᵢ y₂) := by simp only [Inseparable, nhds_prod_eq, prod_inj] theorem Inseparable.prod {x₁ x₂ : X} {y₁ y₂ : Y} (hx : x₁ ~ᵢ x₂) (hy : y₁ ~ᵢ y₂) : (x₁, y₁) ~ᵢ (x₂, y₂) := inseparable_prod.2 ⟨hx, hy⟩ @[simp] theorem inseparable_pi {f g : ∀ i, π i} : (f ~ᵢ g) ↔ ∀ i, f i ~ᵢ g i := by simp only [Inseparable, nhds_pi, funext_iff, pi_inj] namespace Inseparable @[refl] theorem refl (x : X) : x ~ᵢ x := Eq.refl (𝓝 x) theorem rfl : x ~ᵢ x := refl x theorem of_eq (e : x = y) : Inseparable x y := e ▸ refl x @[symm] nonrec theorem symm (h : x ~ᵢ y) : y ~ᵢ x := h.symm @[trans] nonrec theorem trans (h₁ : x ~ᵢ y) (h₂ : y ~ᵢ z) : x ~ᵢ z := h₁.trans h₂ theorem nhds_eq (h : x ~ᵢ y) : 𝓝 x = 𝓝 y := h theorem mem_open_iff (h : x ~ᵢ y) (hs : IsOpen s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isOpen.1 h s hs theorem mem_closed_iff (h : x ~ᵢ y) (hs : IsClosed s) : x ∈ s ↔ y ∈ s := inseparable_iff_forall_isClosed.1 h s hs theorem map_of_continuousAt (h : x ~ᵢ y) (hx : ContinuousAt f x) (hy : ContinuousAt f y) : f x ~ᵢ f y := (h.specializes.map_of_continuousAt hy).antisymm (h.specializes'.map_of_continuousAt hx) theorem map (h : x ~ᵢ y) (hf : Continuous f) : f x ~ᵢ f y := h.map_of_continuousAt hf.continuousAt hf.continuousAt end Inseparable theorem IsClosed.not_inseparable (hs : IsClosed s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_closed_iff hs).1 hx theorem IsOpen.not_inseparable (hs : IsOpen s) (hx : x ∈ s) (hy : y ∉ s) : ¬(x ~ᵢ y) := fun h => hy <| (h.mem_open_iff hs).1 hx /-! ### Separation quotient In this section we define the quotient of a topological space by the `Inseparable` relation. -/ variable (X) in instance : TopologicalSpace (SeparationQuotient X) := instTopologicalSpaceQuotient variable {t : Set (SeparationQuotient X)} namespace SeparationQuotient /-- The natural map from a topological space to its separation quotient. -/ def mk : X → SeparationQuotient X := Quotient.mk'' theorem isQuotientMap_mk : IsQuotientMap (mk : X → SeparationQuotient X) := isQuotientMap_quot_mk @[deprecated (since := "2024-10-22")] alias quotientMap_mk := isQuotientMap_mk @[fun_prop, continuity] theorem continuous_mk : Continuous (mk : X → SeparationQuotient X) := continuous_quot_mk @[simp]
theorem mk_eq_mk : mk x = mk y ↔ (x ~ᵢ y) := Quotient.eq''
Mathlib/Topology/Inseparable.lean
550
552
/- 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.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we 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)`. ## 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*} open Uniformity section UniformSpace variable [UniformSpace α] /-- 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 generalizing s with | zero => simpa | succ _ ihn => 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⟩ /-- 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 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ @[deprecated (since := "2024-11-18")] alias isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β] {pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by rcases (((𝓤 α).basis_sets.uniformity_prod (𝓤 β).basis_sets).mem_iff' s).1 h with ⟨w, hw⟩ use w.1, hw.1.1, w.2, hw.1.2, hw.2 theorem tendsto_prod_uniformity_fst [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono inf_le_left) map_comap_le theorem tendsto_prod_uniformity_snd [UniformSpace α] [UniformSpace β] : Tendsto (fun p : (α × β) × α × β => (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) := le_trans (map_mono inf_le_right) map_comap_le theorem uniformContinuous_fst [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.1 := tendsto_prod_uniformity_fst theorem uniformContinuous_snd [UniformSpace α] [UniformSpace β] : UniformContinuous fun p : α × β => p.2 := tendsto_prod_uniformity_snd variable [UniformSpace α] [UniformSpace β] [UniformSpace γ] theorem UniformContinuous.prodMk {f₁ : α → β} {f₂ : α → γ} (h₁ : UniformContinuous f₁) (h₂ : UniformContinuous f₂) : UniformContinuous fun a => (f₁ a, f₂ a) := by rw [UniformContinuous, uniformity_prod] exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk := UniformContinuous.prodMk theorem UniformContinuous.prodMk_left {f : α × β → γ} (h : UniformContinuous f) (b) : UniformContinuous fun a => f (a, b) := h.comp (uniformContinuous_id.prodMk uniformContinuous_const) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_left := UniformContinuous.prodMk_left theorem UniformContinuous.prodMk_right {f : α × β → γ} (h : UniformContinuous f) (a) : UniformContinuous fun b => f (a, b) := h.comp (uniformContinuous_const.prodMk uniformContinuous_id) @[deprecated (since := "2025-03-10")] alias UniformContinuous.prod_mk_right := UniformContinuous.prodMk_right theorem UniformContinuous.prodMap [UniformSpace δ] {f : α → γ} {g : β → δ} (hf : UniformContinuous f) (hg : UniformContinuous g) : UniformContinuous (Prod.map f g) := (hf.comp uniformContinuous_fst).prodMk (hg.comp uniformContinuous_snd) theorem toTopologicalSpace_prod {α} {β} [u : UniformSpace α] [v : UniformSpace β] : @UniformSpace.toTopologicalSpace (α × β) instUniformSpaceProd = @instTopologicalSpaceProd α β u.toTopologicalSpace v.toTopologicalSpace := rfl /-- A version of `UniformContinuous.inf_dom_left` for binary functions -/ theorem uniformContinuous_inf_dom_left₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua1; haveI := ub1; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_left₂` have ha := @UniformContinuous.inf_dom_left _ _ id ua1 ua2 ua1 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_left _ _ id ub1 ub2 ub1 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua1 ub1 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `UniformContinuous.inf_dom_right` for binary functions -/ theorem uniformContinuous_inf_dom_right₂ {α β γ} {f : α → β → γ} {ua1 ua2 : UniformSpace α} {ub1 ub2 : UniformSpace β} {uc1 : UniformSpace γ} (h : by haveI := ua2; haveI := ub2; exact UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := ua1 ⊓ ua2; haveI := ub1 ⊓ ub2 exact UniformContinuous fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_inf_dom_right₂` have ha := @UniformContinuous.inf_dom_right _ _ id ua1 ua2 ua2 (@uniformContinuous_id _ (id _)) have hb := @UniformContinuous.inf_dom_right _ _ id ub1 ub2 ub2 (@uniformContinuous_id _ (id _)) have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (ua1 ⊓ ua2) (ub1 ⊓ ub2) ua2 ub2 _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ h h_unif_cont_id /-- A version of `uniformContinuous_sInf_dom` for binary functions -/ theorem uniformContinuous_sInf_dom₂ {α β γ} {f : α → β → γ} {uas : Set (UniformSpace α)} {ubs : Set (UniformSpace β)} {ua : UniformSpace α} {ub : UniformSpace β} {uc : UniformSpace γ} (ha : ua ∈ uas) (hb : ub ∈ ubs) (hf : UniformContinuous fun p : α × β => f p.1 p.2) : by haveI := sInf uas; haveI := sInf ubs exact @UniformContinuous _ _ _ uc fun p : α × β => f p.1 p.2 := by -- proof essentially copied from `continuous_sInf_dom` let _ : UniformSpace (α × β) := instUniformSpaceProd have ha := uniformContinuous_sInf_dom ha uniformContinuous_id have hb := uniformContinuous_sInf_dom hb uniformContinuous_id have h_unif_cont_id := @UniformContinuous.prodMap _ _ _ _ (sInf uas) (sInf ubs) ua ub _ _ ha hb exact @UniformContinuous.comp _ _ _ (id _) (id _) _ _ _ hf h_unif_cont_id end Prod section open UniformSpace Function variable {δ' : Type*} [UniformSpace α] [UniformSpace β] [UniformSpace γ] [UniformSpace δ] [UniformSpace δ'] local notation f " ∘₂ " g => Function.bicompr f g /-- Uniform continuity for functions of two variables. -/ def UniformContinuous₂ (f : α → β → γ) := UniformContinuous (uncurry f) theorem uniformContinuous₂_def (f : α → β → γ) : UniformContinuous₂ f ↔ UniformContinuous (uncurry f) := Iff.rfl theorem UniformContinuous₂.uniformContinuous {f : α → β → γ} (h : UniformContinuous₂ f) : UniformContinuous (uncurry f) := h theorem uniformContinuous₂_curry (f : α × β → γ) : UniformContinuous₂ (Function.curry f) ↔ UniformContinuous f := by rw [UniformContinuous₂, uncurry_curry] theorem UniformContinuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : UniformContinuous g) (hf : UniformContinuous₂ f) : UniformContinuous₂ (g ∘₂ f) := hg.comp hf theorem UniformContinuous₂.bicompl {f : α → β → γ} {ga : δ → α} {gb : δ' → β} (hf : UniformContinuous₂ f) (hga : UniformContinuous ga) (hgb : UniformContinuous gb) : UniformContinuous₂ (bicompl f ga gb) := hf.uniformContinuous.comp (hga.prodMap hgb) end theorem toTopologicalSpace_subtype [u : UniformSpace α] {p : α → Prop} : @UniformSpace.toTopologicalSpace (Subtype p) instUniformSpaceSubtype = @instTopologicalSpaceSubtype α p u.toTopologicalSpace := rfl section Sum variable [UniformSpace α] [UniformSpace β] open Sum -- Obsolete auxiliary definitions and lemmas /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ instance Sum.instUniformSpace : UniformSpace (α ⊕ β) where uniformity := map (fun p : α × α => (inl p.1, inl p.2)) (𝓤 α) ⊔ map (fun p : β × β => (inr p.1, inr p.2)) (𝓤 β) symm := fun _ hs ↦ ⟨symm_le_uniformity hs.1, symm_le_uniformity hs.2⟩ comp := fun s hs ↦ by rcases comp_mem_uniformity_sets hs.1 with ⟨tα, htα, Htα⟩ rcases comp_mem_uniformity_sets hs.2 with ⟨tβ, htβ, Htβ⟩ filter_upwards [mem_lift' (union_mem_sup (image_mem_map htα) (image_mem_map htβ))] rintro ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩ exacts [@Htα (_, _) ⟨b, hab, hbc⟩, @Htβ (_, _) ⟨b, hab, hbc⟩] nhds_eq_comap_uniformity x := by ext cases x <;> simp [mem_comap', -mem_comap, nhds_inl, nhds_inr, nhds_eq_comap_uniformity, Prod.ext_iff] /-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage of the diagonal. -/ theorem union_mem_uniformity_sum {a : Set (α × α)} (ha : a ∈ 𝓤 α) {b : Set (β × β)} (hb : b ∈ 𝓤 β) : Prod.map inl inl '' a ∪ Prod.map inr inr '' b ∈ 𝓤 (α ⊕ β) := union_mem_sup (image_mem_map ha) (image_mem_map hb) theorem Sum.uniformity : 𝓤 (α ⊕ β) = map (Prod.map inl inl) (𝓤 α) ⊔ map (Prod.map inr inr) (𝓤 β) := rfl lemma uniformContinuous_inl : UniformContinuous (Sum.inl : α → α ⊕ β) := le_sup_left lemma uniformContinuous_inr : UniformContinuous (Sum.inr : β → α ⊕ β) := le_sup_right instance [IsCountablyGenerated (𝓤 α)] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α ⊕ β)) := by rw [Sum.uniformity] infer_instance end Sum end Constructions /-! ### Expressing continuity properties in uniform spaces We reformulate the various continuity properties of functions taking values in a uniform space in terms of the uniformity in the target. Since the same lemmas (essentially with the same names) also exist for metric spaces and emetric spaces (reformulating things in terms of the distance or the edistance in the target), we put them in a namespace `Uniform` here. In the metric and emetric space setting, there are also similar lemmas where one assumes that both the source and the target are metric spaces, reformulating things in terms of the distance on both sides. These lemmas are generally written without primes, and the versions where only the target is a metric space is primed. We follow the same convention here, thus giving lemmas with primes. -/ namespace Uniform variable [UniformSpace α] theorem tendsto_nhds_right {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (a, u x)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity, tendsto_comap_iff]; rfl theorem tendsto_nhds_left {f : Filter β} {u : β → α} {a : α} : Tendsto u f (𝓝 a) ↔ Tendsto (fun x => (u x, a)) f (𝓤 α) := by rw [nhds_eq_comap_uniformity', tendsto_comap_iff]; rfl theorem continuousAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_right] theorem continuousAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := by rw [ContinuousAt, tendsto_nhds_left] theorem continuousAt_iff_prod [TopologicalSpace β] {f : β → α} {b : β} : ContinuousAt f b ↔ Tendsto (fun x : β × β => (f x.1, f x.2)) (𝓝 (b, b)) (𝓤 α) := ⟨fun H => le_trans (H.prodMap' H) (nhds_le_uniformity _), fun H => continuousAt_iff'_left.2 <| H.comp <| tendsto_id.prodMk_nhds tendsto_const_nhds⟩ theorem continuousWithinAt_iff'_right [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_right] theorem continuousWithinAt_iff'_left [TopologicalSpace β] {f : β → α} {b : β} {s : Set β} : ContinuousWithinAt f s b ↔ Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by rw [ContinuousWithinAt, tendsto_nhds_left] theorem continuousOn_iff'_right [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f b, f x)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_right] theorem continuousOn_iff'_left [TopologicalSpace β] {f : β → α} {s : Set β} : ContinuousOn f s ↔ ∀ b ∈ s, Tendsto (fun x => (f x, f b)) (𝓝[s] b) (𝓤 α) := by simp [ContinuousOn, continuousWithinAt_iff'_left]
theorem continuous_iff'_right [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f b, f x)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_right theorem continuous_iff'_left [TopologicalSpace β] {f : β → α} : Continuous f ↔ ∀ b, Tendsto (fun x => (f x, f b)) (𝓝 b) (𝓤 α) := continuous_iff_continuousAt.trans <| forall_congr' fun _ => tendsto_nhds_left
Mathlib/Topology/UniformSpace/Basic.lean
951
958
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
853
861
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Order.Field.Power import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.RingTheory.Polynomial.Bernstein import Mathlib.Topology.ContinuousMap.Polynomial import Mathlib.Topology.ContinuousMap.Compact /-! # Bernstein approximations and Weierstrass' theorem We prove that the Bernstein approximations ``` ∑ k : Fin (n+1), f (k/n : ℝ) * n.choose k * x^k * (1-x)^(n-k) ``` for a continuous function `f : C([0,1], ℝ)` converge uniformly to `f` as `n` tends to infinity. Our proof follows [Richard Beals' *Analysis, an introduction*][beals-analysis], §7D. The original proof, due to [Bernstein](bernstein1912) in 1912, is probabilistic, and relies on Bernoulli's theorem, which gives bounds for how quickly the observed frequencies in a Bernoulli trial approach the underlying probability. The proof here does not directly rely on Bernoulli's theorem, but can also be given a probabilistic account. * Consider a weighted coin which with probability `x` produces heads, and with probability `1-x` produces tails. * The value of `bernstein n k x` is the probability that such a coin gives exactly `k` heads in a sequence of `n` tosses. * If such an appearance of `k` heads results in a payoff of `f(k / n)`, the `n`-th Bernstein approximation for `f` evaluated at `x` is the expected payoff. * The main estimate in the proof bounds the probability that the observed frequency of heads differs from `x` by more than some `δ`, obtaining a bound of `(4 * n * δ^2)⁻¹`, irrespective of `x`. * This ensures that for `n` large, the Bernstein approximation is (uniformly) close to the payoff function `f`. (You don't need to think in these terms to follow the proof below: it's a giant `calc` block!) This result proves Weierstrass' theorem that polynomials are dense in `C([0,1], ℝ)`, although we defer an abstract statement of this until later. -/ noncomputable section open scoped BoundedContinuousFunction unitInterval /-- The Bernstein polynomials, as continuous functions on `[0,1]`. -/ def bernstein (n ν : ℕ) : C(I, ℝ) := (bernsteinPolynomial ℝ n ν).toContinuousMapOn I @[simp] theorem bernstein_apply (n ν : ℕ) (x : I) : bernstein n ν x = (n.choose ν : ℝ) * (x : ℝ) ^ ν * (1 - (x : ℝ)) ^ (n - ν) := by dsimp [bernstein, Polynomial.toContinuousMapOn, Polynomial.toContinuousMap, bernsteinPolynomial] simp theorem bernstein_nonneg {n ν : ℕ} {x : I} : 0 ≤ bernstein n ν x := by simp only [bernstein_apply] have h₁ : (0 : ℝ) ≤ x := by unit_interval have h₂ : (0 : ℝ) ≤ 1 - x := by unit_interval positivity
namespace Mathlib.Meta.Positivity open Lean Meta Qq Function
Mathlib/Analysis/SpecialFunctions/Bernstein.lean
67
71
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Aaron Anderson, Yakov Pechersky -/ import Mathlib.Data.Fintype.Card import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.End import Mathlib.Data.Finset.NoncommProd /-! # support of a permutation ## Main definitions In the following, `f g : Equiv.Perm α`. * `Equiv.Perm.Disjoint`: two permutations `f` and `g` are `Disjoint` if every element is fixed either by `f`, or by `g`. Equivalently, `f` and `g` are `Disjoint` iff their `support` are disjoint. * `Equiv.Perm.IsSwap`: `f = swap x y` for `x ≠ y`. * `Equiv.Perm.support`: the elements `x : α` that are not fixed by `f`. Assume `α` is a Fintype: * `Equiv.Perm.fixed_point_card_lt_of_ne_one f` says that `f` has strictly less than `Fintype.card α - 1` fixed points, unless `f = 1`. (Equivalently, `f.support` has at least 2 elements.) -/ open Equiv Finset Function namespace Equiv.Perm variable {α : Type*} section Disjoint /-- Two permutations `f` and `g` are `Disjoint` if their supports are disjoint, i.e., every element is fixed either by `f`, or by `g`. -/ def Disjoint (f g : Perm α) := ∀ x, f x = x ∨ g x = x variable {f g h : Perm α} @[symm] theorem Disjoint.symm : Disjoint f g → Disjoint g f := by simp only [Disjoint, or_comm, imp_self] theorem Disjoint.symmetric : Symmetric (@Disjoint α) := fun _ _ => Disjoint.symm instance : IsSymm (Perm α) Disjoint := ⟨Disjoint.symmetric⟩ theorem disjoint_comm : Disjoint f g ↔ Disjoint g f := ⟨Disjoint.symm, Disjoint.symm⟩ theorem Disjoint.commute (h : Disjoint f g) : Commute f g := Equiv.ext fun x => (h x).elim (fun hf => (h (g x)).elim (fun hg => by simp [mul_apply, hf, hg]) fun hg => by simp [mul_apply, hf, g.injective hg]) fun hg => (h (f x)).elim (fun hf => by simp [mul_apply, f.injective hf, hg]) fun hf => by simp [mul_apply, hf, hg] @[simp] theorem disjoint_one_left (f : Perm α) : Disjoint 1 f := fun _ => Or.inl rfl @[simp] theorem disjoint_one_right (f : Perm α) : Disjoint f 1 := fun _ => Or.inr rfl theorem disjoint_iff_eq_or_eq : Disjoint f g ↔ ∀ x : α, f x = x ∨ g x = x := Iff.rfl @[simp] theorem disjoint_refl_iff : Disjoint f f ↔ f = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ disjoint_one_left 1⟩ ext x rcases h x with hx | hx <;> simp [hx] theorem Disjoint.inv_left (h : Disjoint f g) : Disjoint f⁻¹ g := by intro x rw [inv_eq_iff_eq, eq_comm] exact h x theorem Disjoint.inv_right (h : Disjoint f g) : Disjoint f g⁻¹ := h.symm.inv_left.symm @[simp] theorem disjoint_inv_left_iff : Disjoint f⁻¹ g ↔ Disjoint f g := by refine ⟨fun h => ?_, Disjoint.inv_left⟩ convert h.inv_left @[simp] theorem disjoint_inv_right_iff : Disjoint f g⁻¹ ↔ Disjoint f g := by rw [disjoint_comm, disjoint_inv_left_iff, disjoint_comm] theorem Disjoint.mul_left (H1 : Disjoint f h) (H2 : Disjoint g h) : Disjoint (f * g) h := fun x => by cases H1 x <;> cases H2 x <;> simp [*] theorem Disjoint.mul_right (H1 : Disjoint f g) (H2 : Disjoint f h) : Disjoint f (g * h) := by rw [disjoint_comm] exact H1.symm.mul_left H2.symm -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: make it `@[simp]` theorem disjoint_conj (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) ↔ Disjoint f g := (h⁻¹).forall_congr fun {_} ↦ by simp only [mul_apply, eq_inv_iff_eq] theorem Disjoint.conj (H : Disjoint f g) (h : Perm α) : Disjoint (h * f * h⁻¹) (h * g * h⁻¹) := (disjoint_conj h).2 H theorem disjoint_prod_right (l : List (Perm α)) (h : ∀ g ∈ l, Disjoint f g) : Disjoint f l.prod := by induction' l with g l ih · exact disjoint_one_right _ · rw [List.prod_cons] exact (h _ List.mem_cons_self).mul_right (ih fun g hg => h g (List.mem_cons_of_mem _ hg)) theorem disjoint_noncommProd_right {ι : Type*} {k : ι → Perm α} {s : Finset ι} (hs : Set.Pairwise s fun i j ↦ Commute (k i) (k j)) (hg : ∀ i ∈ s, g.Disjoint (k i)) : Disjoint g (s.noncommProd k (hs)) := noncommProd_induction s k hs g.Disjoint (fun _ _ ↦ Disjoint.mul_right) (disjoint_one_right g) hg open scoped List in theorem disjoint_prod_perm {l₁ l₂ : List (Perm α)} (hl : l₁.Pairwise Disjoint) (hp : l₁ ~ l₂) : l₁.prod = l₂.prod := hp.prod_eq' <| hl.imp Disjoint.commute theorem nodup_of_pairwise_disjoint {l : List (Perm α)} (h1 : (1 : Perm α) ∉ l) (h2 : l.Pairwise Disjoint) : l.Nodup := by refine List.Pairwise.imp_of_mem ?_ h2 intro τ σ h_mem _ h_disjoint _ subst τ suffices (σ : Perm α) = 1 by rw [this] at h_mem exact h1 h_mem exact ext fun a => or_self_iff.mp (h_disjoint a) theorem pow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℕ, (f ^ n) x = x | 0 => rfl | n + 1 => by rw [pow_succ, mul_apply, hfx, pow_apply_eq_self_of_apply_eq_self hfx n] theorem zpow_apply_eq_self_of_apply_eq_self {x : α} (hfx : f x = x) : ∀ n : ℤ, (f ^ n) x = x | (n : ℕ) => pow_apply_eq_self_of_apply_eq_self hfx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, pow_apply_eq_self_of_apply_eq_self hfx] theorem pow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ n : ℕ, (f ^ n) x = x ∨ (f ^ n) x = f x | 0 => Or.inl rfl | n + 1 => (pow_apply_eq_of_apply_apply_eq_self hffx n).elim (fun h => Or.inr (by rw [pow_succ', mul_apply, h])) fun h => Or.inl (by rw [pow_succ', mul_apply, h, hffx]) theorem zpow_apply_eq_of_apply_apply_eq_self {x : α} (hffx : f (f x) = x) : ∀ i : ℤ, (f ^ i) x = x ∨ (f ^ i) x = f x | (n : ℕ) => pow_apply_eq_of_apply_apply_eq_self hffx n | Int.negSucc n => by rw [zpow_negSucc, inv_eq_iff_eq, ← f.injective.eq_iff, ← mul_apply, ← pow_succ', eq_comm, inv_eq_iff_eq, ← mul_apply, ← pow_succ, @eq_comm _ x, or_comm] exact pow_apply_eq_of_apply_apply_eq_self hffx _ theorem Disjoint.mul_apply_eq_iff {σ τ : Perm α} (hστ : Disjoint σ τ) {a : α} : (σ * τ) a = a ↔ σ a = a ∧ τ a = a := by refine ⟨fun h => ?_, fun h => by rw [mul_apply, h.2, h.1]⟩ rcases hστ a with hσ | hτ · exact ⟨hσ, σ.injective (h.trans hσ.symm)⟩ · exact ⟨(congr_arg σ hτ).symm.trans h, hτ⟩ theorem Disjoint.mul_eq_one_iff {σ τ : Perm α} (hστ : Disjoint σ τ) : σ * τ = 1 ↔ σ = 1 ∧ τ = 1 := by simp_rw [Perm.ext_iff, one_apply, hστ.mul_apply_eq_iff, forall_and] theorem Disjoint.zpow_disjoint_zpow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℤ) : Disjoint (σ ^ m) (τ ^ n) := fun x => Or.imp (fun h => zpow_apply_eq_self_of_apply_eq_self h m) (fun h => zpow_apply_eq_self_of_apply_eq_self h n) (hστ x) theorem Disjoint.pow_disjoint_pow {σ τ : Perm α} (hστ : Disjoint σ τ) (m n : ℕ) : Disjoint (σ ^ m) (τ ^ n) := hστ.zpow_disjoint_zpow m n end Disjoint section IsSwap variable [DecidableEq α] /-- `f.IsSwap` indicates that the permutation `f` is a transposition of two elements. -/ def IsSwap (f : Perm α) : Prop := ∃ x y, x ≠ y ∧ f = swap x y @[simp] theorem ofSubtype_swap_eq {p : α → Prop} [DecidablePred p] (x y : Subtype p) : ofSubtype (Equiv.swap x y) = Equiv.swap ↑x ↑y := Equiv.ext fun z => by by_cases hz : p z · rw [swap_apply_def, ofSubtype_apply_of_mem _ hz] split_ifs with hzx hzy · simp_rw [hzx, Subtype.coe_eta, swap_apply_left] · simp_rw [hzy, Subtype.coe_eta, swap_apply_right] · rw [swap_apply_of_ne_of_ne] <;> simp [Subtype.ext_iff, *] · rw [ofSubtype_apply_of_not_mem _ hz, swap_apply_of_ne_of_ne] · intro h apply hz rw [h] exact Subtype.prop x intro h apply hz rw [h] exact Subtype.prop y theorem IsSwap.of_subtype_isSwap {p : α → Prop} [DecidablePred p] {f : Perm (Subtype p)} (h : f.IsSwap) : (ofSubtype f).IsSwap := let ⟨⟨x, hx⟩, ⟨y, hy⟩, hxy⟩ := h ⟨x, y, by simp only [Ne, Subtype.ext_iff] at hxy exact hxy.1, by rw [hxy.2, ofSubtype_swap_eq]⟩ theorem ne_and_ne_of_swap_mul_apply_ne_self {f : Perm α} {x y : α} (hy : (swap x (f x) * f) y ≠ y) : f y ≠ y ∧ y ≠ x := by simp only [swap_apply_def, mul_apply, f.injective.eq_iff] at * by_cases h : f y = x · constructor <;> intro <;> simp_all only [if_true, eq_self_iff_true, not_true, Ne] · split_ifs at hy with h <;> try { simp [*] at * } end IsSwap section support section Set variable (p q : Perm α) theorem set_support_inv_eq : { x | p⁻¹ x ≠ x } = { x | p x ≠ x } := by ext x simp only [Set.mem_setOf_eq, Ne] rw [inv_def, symm_apply_eq, eq_comm] theorem set_support_apply_mem {p : Perm α} {a : α} : p a ∈ { x | p x ≠ x } ↔ a ∈ { x | p x ≠ x } := by simp theorem set_support_zpow_subset (n : ℤ) : { x | (p ^ n) x ≠ x } ⊆ { x | p x ≠ x } := by intro x simp only [Set.mem_setOf_eq, Ne] intro hx H simp [zpow_apply_eq_self_of_apply_eq_self H] at hx theorem set_support_mul_subset : { x | (p * q) x ≠ x } ⊆ { x | p x ≠ x } ∪ { x | q x ≠ x } := by intro x simp only [Perm.coe_mul, Function.comp_apply, Ne, Set.mem_union, Set.mem_setOf_eq] by_cases hq : q x = x <;> simp [hq] end Set @[simp] theorem apply_pow_apply_eq_iff (f : Perm α) (n : ℕ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_pow f, mul_apply, apply_eq_iff_eq] @[simp] theorem apply_zpow_apply_eq_iff (f : Perm α) (n : ℤ) {x : α} : f ((f ^ n) x) = (f ^ n) x ↔ f x = x := by rw [← mul_apply, Commute.self_zpow f, mul_apply, apply_eq_iff_eq] variable [DecidableEq α] [Fintype α] {f g : Perm α} /-- The `Finset` of nonfixed points of a permutation. -/ def support (f : Perm α) : Finset α := {x | f x ≠ x} @[simp] theorem mem_support {x : α} : x ∈ f.support ↔ f x ≠ x := by rw [support, mem_filter, and_iff_right (mem_univ x)] theorem not_mem_support {x : α} : x ∉ f.support ↔ f x = x := by simp theorem coe_support_eq_set_support (f : Perm α) : (f.support : Set α) = { x | f x ≠ x } := by ext simp @[simp] theorem support_eq_empty_iff {σ : Perm α} : σ.support = ∅ ↔ σ = 1 := by simp_rw [Finset.ext_iff, mem_support, Finset.not_mem_empty, iff_false, not_not, Equiv.Perm.ext_iff, one_apply] @[simp] theorem support_one : (1 : Perm α).support = ∅ := by rw [support_eq_empty_iff] @[simp] theorem support_refl : support (Equiv.refl α) = ∅ := support_one theorem support_congr (h : f.support ⊆ g.support) (h' : ∀ x ∈ g.support, f x = g x) : f = g := by ext x by_cases hx : x ∈ g.support · exact h' x hx · rw [not_mem_support.mp hx, ← not_mem_support] exact fun H => hx (h H) /-- If g and c commute, then g stabilizes the support of c -/ theorem mem_support_iff_of_commute {g c : Perm α} (hgc : Commute g c) (x : α) : x ∈ c.support ↔ g x ∈ c.support := by simp only [mem_support, not_iff_not, ← mul_apply] rw [← hgc, mul_apply, Equiv.apply_eq_iff_eq] theorem support_mul_le (f g : Perm α) : (f * g).support ≤ f.support ⊔ g.support := fun x => by simp only [sup_eq_union] rw [mem_union, mem_support, mem_support, mem_support, mul_apply, ← not_and_or, not_imp_not] rintro ⟨hf, hg⟩ rw [hg, hf] theorem exists_mem_support_of_mem_support_prod {l : List (Perm α)} {x : α} (hx : x ∈ l.prod.support) : ∃ f : Perm α, f ∈ l ∧ x ∈ f.support := by contrapose! hx simp_rw [mem_support, not_not] at hx ⊢ induction' l with f l ih · rfl · rw [List.prod_cons, mul_apply, ih, hx] · simp only [List.find?, List.mem_cons, true_or] intros f' hf' refine hx f' ?_ simp only [List.find?, List.mem_cons] exact Or.inr hf' theorem support_pow_le (σ : Perm α) (n : ℕ) : (σ ^ n).support ≤ σ.support := fun _ h1 => mem_support.mpr fun h2 => mem_support.mp h1 (pow_apply_eq_self_of_apply_eq_self h2 n) @[simp] theorem support_inv (σ : Perm α) : support σ⁻¹ = σ.support := by simp_rw [Finset.ext_iff, mem_support, not_iff_not, inv_eq_iff_eq.trans eq_comm, imp_true_iff] theorem apply_mem_support {x : α} : f x ∈ f.support ↔ x ∈ f.support := by rw [mem_support, mem_support, Ne, Ne, apply_eq_iff_eq]
/-- The support of a permutation is invariant -/ theorem isInvariant_of_support_le {c : Perm α} {s : Finset α} (hcs : c.support ≤ s) (x : α) : x ∈ s ↔ c x ∈ s := by by_cases hx' : x ∈ c.support · simp only [hcs hx', true_iff, hcs (apply_mem_support.mpr hx')] · rw [not_mem_support.mp hx'] /-- A permutation c is the extension of a restriction of g to s iff its support is contained in s and its restriction is that of g -/ lemma ofSubtype_eq_iff {g c : Equiv.Perm α} {s : Finset α} (hg : ∀ x, x ∈ s ↔ g x ∈ s) :
Mathlib/GroupTheory/Perm/Support.lean
339
350
/- 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 /-! # 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}) 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) /-- 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 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 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 /-- 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 theorem approx_eta {n : ℕ} (x : CofixA F (n + 1)) : x = CofixA.intro (head' x) (children' x) := by cases x; rfl /-- 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') /-- 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)) @[simp] theorem agree_trivial {x : CofixA F 0} {y : CofixA F 1} : Agree x y := by constructor @[deprecated (since := "2024-12-25")] alias agree_trival := agree_trivial 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 obtain - | ⟨_, _, hagree⟩ := h₁; cases h₀ apply hagree /-- `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 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_def, eq_self_iff_true, heq_iff_eq] -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): 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₁ 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) _ 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 obtain ⟨y, g⟩ := f i constructor introv apply n_ih /-- `Path F` provides indices to access internal nodes in `Corec F` -/ def Path (F : PFunctor.{u}) := List F.Idx instance Path.inhabited : Inhabited (Path F) := ⟨[]⟩ 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 rcases h₀ : x (succ n) with - | ⟨_, f₀⟩ cases h₁ : x 1 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) rw [h₀, h₂] at H apply n_ih (truncate ∘ f₀) rw [h₂] obtain - | ⟨_, _, hagree⟩ := H congr funext j dsimp only [comp_apply] rw [truncate_eq_of_agree] apply hagree end Approx open Approx /-- Internal definition for `M`. It is needed to avoid name clashes between `M.mk` and `M.casesOn` 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 /-- For polynomial functor `F`, `M F` is its final coalgebra -/ def M := MIntl F 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 instance M.inhabited [Inhabited F.A] : Inhabited (M F) := ⟨{ approx := default consistent := M.default_consistent _ }⟩ instance MIntl.inhabited [Inhabited F.A] : Inhabited (MIntl F) := show Inhabited (M F) by infer_instance 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 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 _ _ /-- 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) /-- 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 } /-- 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 theorem head_succ (n m : ℕ) (x : M F) : head' (x.approx (succ n)) = head' (x.approx (succ m)) := head_succ' n m _ x.consistent theorem head_eq_head' : ∀ (x : M F) (n : ℕ), head x = head' (x.approx <| n + 1) | ⟨_, h⟩, _ => head_succ' _ _ _ h theorem head'_eq_head : ∀ (x : M F) (n : ℕ), head' (x.approx <| n + 1) = head x | ⟨_, h⟩, _ => head_succ' _ _ _ h theorem truncate_approx (x : M F) (n : ℕ) : truncate (x.approx <| n + 1) = x.approx n := truncate_eq_of_agree _ _ (x.consistent _) /-- unfold an M-type -/ def dest : M F → F (M F) | x => ⟨head x, fun i => children x i⟩ 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 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 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 /-- `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' @[simp] theorem dest_mk (x : F (M F)) : dest (M.mk x) = x := rfl @[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] rcases h : x.approx (succ n) with - | ⟨hd, ch⟩ have h' : hd = head' (x.approx 1) := by rw [← head_succ' n, h, head'] 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 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] /-- 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 _ /-- 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 /-- 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) 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 @[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 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 obtain - | ⟨_, _, hagree⟩ := h constructor <;> try rfl intro i apply n_ih apply hagree · induction' n with _ n_ih generalizing x y · constructor · obtain - | @⟨_, a, x', y'⟩ := h 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 [*] @[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 @[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 @[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) /-- `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 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 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 /-- follow a path through a value of `M F` and return the subtree found at the end of the path if it is a valid path for that value and return a default tree -/ def isubtree [DecidableEq F.A] [Inhabited (M F)] : Path F → M F → M F | [], x => x | ⟨a, i⟩ :: ps, x => PFunctor.M.casesOn' (r := fun _ => M F) x (fun a' f => if h : a = a' then isubtree ps (f <| cast (by rw [h]) i) else default (α := M F) ) /-- similar to `isubtree` but returns the data at the end of the path instead of the whole subtree -/ def iselect [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) : M F → F.A := fun x : M F => head <| isubtree ps x theorem iselect_eq_default [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) (x : M F) (h : ¬IsPath ps x) : iselect ps x = head default := by induction' ps with ps_hd ps_tail ps_ih generalizing x · exfalso apply h constructor · obtain ⟨a, i⟩ := ps_hd induction' x using PFunctor.M.casesOn' with x_a x_f simp only [iselect, isubtree] at ps_ih ⊢ by_cases h'' : a = x_a · subst x_a simp only [dif_pos, eq_self_iff_true, casesOn_mk'] rw [ps_ih] intro h' apply h constructor <;> try rfl apply h' · simp [*] @[simp] theorem head_mk (x : F (M F)) : head (M.mk x) = x.1 := Eq.symm <| calc x.1 = (dest (M.mk x)).1 := by rw [dest_mk] _ = head (M.mk x) := rfl theorem children_mk {a} (x : F.B a → M F) (i : F.B (head (M.mk ⟨a, x⟩))) : children (M.mk ⟨a, x⟩) i = x (cast (by rw [head_mk]) i) := by apply ext'; intro n; rfl @[simp] theorem ichildren_mk [DecidableEq F.A] [Inhabited (M F)] (x : F (M F)) (i : F.Idx) : ichildren i (M.mk x) = x.iget i := by dsimp only [ichildren, PFunctor.Obj.iget] congr with h @[simp] theorem isubtree_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F) {i : F.B a} : isubtree (⟨_, i⟩ :: ps) (M.mk ⟨a, f⟩) = isubtree ps (f i) := by simp only [isubtree, ichildren_mk, PFunctor.Obj.iget, dif_pos, isubtree, M.casesOn_mk']; rfl @[simp] theorem iselect_nil [DecidableEq F.A] [Inhabited (M F)] {a} (f : F.B a → M F) : iselect nil (M.mk ⟨a, f⟩) = a := rfl @[simp] theorem iselect_cons [DecidableEq F.A] [Inhabited (M F)] (ps : Path F) {a} (f : F.B a → M F) {i} : iselect (⟨a, i⟩ :: ps) (M.mk ⟨a, f⟩) = iselect ps (f i) := by simp only [iselect, isubtree_cons] theorem corec_def {X} (f : X → F X) (x₀ : X) : M.corec f x₀ = M.mk (F.map (M.corec f) (f x₀)) := by dsimp only [M.corec, M.mk] congr with n rcases n with - | n · dsimp only [sCorec, Approx.sMk] · dsimp only [sCorec, Approx.sMk] cases f x₀ dsimp only [PFunctor.map] congr theorem ext_aux [Inhabited (M F)] [DecidableEq F.A] {n : ℕ} (x y z : M F) (hx : Agree' n z x) (hy : Agree' n z y) (hrec : ∀ ps : Path F, n = ps.length → iselect ps x = iselect ps y) : x.approx (n + 1) = y.approx (n + 1) := by induction' n with n n_ih generalizing x y z · specialize hrec [] rfl induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' simp only [iselect_nil] at hrec subst hrec simp only [approx_mk, eq_self_iff_true, heq_iff_eq, zero_eq, CofixA.intro.injEq, heq_eq_eq, eq_iff_true_of_subsingleton, and_self] · cases hx cases hy induction x using PFunctor.M.casesOn' induction y using PFunctor.M.casesOn' subst z iterate 3 (have := mk_inj ‹_›; cases this) rename_i n_ih a f₃ f₂ hAgree₂ _ _ h₂ _ _ f₁ h₁ hAgree₁ clr simp only [approx_mk, eq_self_iff_true, heq_iff_eq] have := mk_inj h₁ cases this; clear h₁ have := mk_inj h₂ cases this; clear h₂ congr ext i apply n_ih · solve_by_elim · solve_by_elim introv h specialize hrec (⟨_, i⟩ :: ps) (congr_arg _ h) simp only [iselect_cons] at hrec exact hrec open PFunctor.Approx theorem ext [Inhabited (M F)] [DecidableEq F.A] (x y : M F) (H : ∀ ps : Path F, iselect ps x = iselect ps y) : x = y := by apply ext'; intro i induction' i with i i_ih · cases x.approx 0 cases y.approx 0 constructor · apply ext_aux x y x · rw [← agree_iff_agree'] apply x.consistent · rw [← agree_iff_agree', i_ih] apply y.consistent introv H' dsimp only [iselect] at H cases H' apply H ps section Bisim variable (R : M F → M F → Prop) local infixl:50 " ~ " => R /-- Bisimulation is the standard proof technique for equality between infinite tree-like structures -/ structure IsBisimulation : Prop where /-- The head of the trees are equal -/ head : ∀ {a a'} {f f'}, M.mk ⟨a, f⟩ ~ M.mk ⟨a', f'⟩ → a = a' /-- The tails are equal -/ tail : ∀ {a} {f f' : F.B a → M F}, M.mk ⟨a, f⟩ ~ M.mk ⟨a, f'⟩ → ∀ i : F.B a, f i ~ f' i theorem nth_of_bisim [Inhabited (M F)] [DecidableEq F.A] (bisim : IsBisimulation R) (s₁ s₂) (ps : Path F) : (R s₁ s₂) → IsPath ps s₁ ∨ IsPath ps s₂ → iselect ps s₁ = iselect ps s₂ ∧ ∃ (a : _) (f f' : F.B a → M F), isubtree ps s₁ = M.mk ⟨a, f⟩ ∧ isubtree ps s₂ = M.mk ⟨a, f'⟩ ∧ ∀ i : F.B a, f i ~ f' i := by intro h₀ hh induction' s₁ using PFunctor.M.casesOn' with a f induction' s₂ using PFunctor.M.casesOn' with a' f' obtain rfl : a = a' := bisim.head h₀ induction' ps with i ps ps_ih generalizing a f f' · exists rfl, a, f, f', rfl, rfl apply bisim.tail h₀ obtain ⟨a', i⟩ := i obtain rfl : a = a' := by rcases hh with hh|hh <;> cases isPath_cons hh <;> rfl dsimp only [iselect] at ps_ih ⊢ have h₁ := bisim.tail h₀ i induction' h : f i using PFunctor.M.casesOn' with a₀ f₀ induction' h' : f' i using PFunctor.M.casesOn' with a₁ f₁ simp only [h, h', isubtree_cons] at ps_ih ⊢ rw [h, h'] at h₁ obtain rfl : a₀ = a₁ := bisim.head h₁ apply ps_ih _ _ _ h₁ rw [← h, ← h'] apply Or.imp isPath_cons' isPath_cons' hh theorem eq_of_bisim [Nonempty (M F)] (bisim : IsBisimulation R) : ∀ s₁ s₂, R s₁ s₂ → s₁ = s₂ := by inhabit M F classical introv Hr; apply ext introv by_cases h : IsPath ps s₁ ∨ IsPath ps s₂ · have H := nth_of_bisim R bisim _ _ ps Hr h exact H.left · rw [not_or] at h obtain ⟨h₀, h₁⟩ := h simp only [iselect_eq_default, *, not_false_iff] end Bisim universe u' v' /-- corecursor for `M F` with swapped arguments -/ def corecOn {X : Type*} (x₀ : X) (f : X → F X) : M F := M.corec f x₀ variable {P : PFunctor.{u}} {α : Type*} theorem dest_corec (g : α → P α) (x : α) : M.dest (M.corec g x) = P.map (M.corec g) (g x) := by rw [corec_def, dest_mk] theorem bisim (R : M P → M P → Prop) (h : ∀ x y, R x y → ∃ a f f', M.dest x = ⟨a, f⟩ ∧ M.dest y = ⟨a, f'⟩ ∧ ∀ i, R (f i) (f' i)) : ∀ x y, R x y → x = y := by introv h' haveI := Inhabited.mk x.head apply eq_of_bisim R _ _ _ h'; clear h' x y constructor <;> introv ih <;> rcases h _ _ ih with ⟨a'', g, g', h₀, h₁, h₂⟩ <;> clear h · replace h₀ := congr_arg Sigma.fst h₀ replace h₁ := congr_arg Sigma.fst h₁ simp only [dest_mk] at h₀ h₁ rw [h₀, h₁] · simp only [dest_mk] at h₀ h₁ cases h₀ cases h₁ apply h₂ theorem bisim' {α : Type*} (Q : α → Prop) (u v : α → M P) (h : ∀ x, Q x → ∃ a f f', M.dest (u x) = ⟨a, f⟩ ∧ M.dest (v x) = ⟨a, f'⟩ ∧ ∀ i, ∃ x', Q x' ∧ f i = u x' ∧ f' i = v x') : ∀ x, Q x → u x = v x := fun x Qx => let R := fun w z : M P => ∃ x', Q x' ∧ w = u x' ∧ z = v x' @M.bisim P R (fun _ _ ⟨x', Qx', xeq, yeq⟩ => let ⟨a, f, f', ux'eq, vx'eq, h'⟩ := h x' Qx' ⟨a, f, f', xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, h'⟩) _ _ ⟨x, Qx, rfl, rfl⟩ -- for the record, show M_bisim follows from _bisim' theorem bisim_equiv (R : M P → M P → Prop) (h : ∀ x y, R x y → ∃ a f f', M.dest x = ⟨a, f⟩ ∧ M.dest y = ⟨a, f'⟩ ∧ ∀ i, R (f i) (f' i)) : ∀ x y, R x y → x = y := fun x y Rxy => let Q : M P × M P → Prop := fun p => R p.fst p.snd bisim' Q Prod.fst Prod.snd (fun p Qp => let ⟨a, f, f', hx, hy, h'⟩ := h p.fst p.snd Qp ⟨a, f, f', hx, hy, fun i => ⟨⟨f i, f' i⟩, h' i, rfl, rfl⟩⟩) ⟨x, y⟩ Rxy theorem corec_unique (g : α → P α) (f : α → M P) (hyp : ∀ x, M.dest (f x) = P.map f (g x)) : f = M.corec g := by ext x apply bisim' (fun _ => True) _ _ _ _ trivial clear x intro x _ rcases gxeq : g x with ⟨a, f'⟩ have h₀ : M.dest (f x) = ⟨a, f ∘ f'⟩ := by rw [hyp, gxeq, PFunctor.map_eq] have h₁ : M.dest (M.corec g x) = ⟨a, M.corec g ∘ f'⟩ := by rw [dest_corec, gxeq, PFunctor.map_eq] refine ⟨_, _, _, h₀, h₁, ?_⟩ intro i exact ⟨f' i, trivial, rfl, rfl⟩ /-- corecursor where the state of the computation can be sent downstream in the form of a recursive call -/ def corec₁ {α : Type u} (F : ∀ X, (α → X) → α → P X) : α → M P := M.corec (F _ id) /-- corecursor where it is possible to return a fully formed value at any point of the computation -/ def corec' {α : Type u} (F : ∀ {X : Type u}, (α → X) → α → M P ⊕ P X) (x : α) : M P := corec₁ (fun _ rec (a : M P ⊕ α) => let y := a >>= F (rec ∘ Sum.inr) match y with | Sum.inr y => y | Sum.inl y => P.map (rec ∘ Sum.inl) (M.dest y)) (@Sum.inr (M P) _ x) end M end PFunctor
Mathlib/Data/PFunctor/Univariate/M.lean
715
716
/- Copyright (c) 2023 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform import Mathlib.Analysis.Fourier.PoissonSummation /-! # Poisson summation applied to the Gaussian In `Real.tsum_exp_neg_mul_int_sq` and `Complex.tsum_exp_neg_mul_int_sq`, we use Poisson summation to prove the identity `∑' (n : ℤ), exp (-π * a * n ^ 2) = 1 / a ^ (1 / 2) * ∑' (n : ℤ), exp (-π / a * n ^ 2)` for positive real `a`, or complex `a` with positive real part. (See also `NumberTheory.ModularForms.JacobiTheta`.) -/ open Real Set MeasureTheory Filter Asymptotics intervalIntegral open scoped Real Topology FourierTransform RealInnerProductSpace open Complex hiding exp continuous_exp abs_of_nonneg sq_abs noncomputable section section GaussianPoisson /-! First we show that Gaussian-type functions have rapid decay along `cocompact ℝ`. -/ lemma rexp_neg_quadratic_isLittleO_rpow_atTop {a : ℝ} (ha : a < 0) (b s : ℝ) : (fun x ↦ rexp (a * x ^ 2 + b * x)) =o[atTop] (· ^ s) := by suffices (fun x ↦ rexp (a * x ^ 2 + b * x)) =o[atTop] (fun x ↦ rexp (-x)) by refine this.trans ?_ simpa only [neg_one_mul] using isLittleO_exp_neg_mul_rpow_atTop zero_lt_one s rw [isLittleO_exp_comp_exp_comp] have : (fun x ↦ -x - (a * x ^ 2 + b * x)) = fun x ↦ x * (-a * x - (b + 1)) := by ext1 x; ring_nf rw [this] exact tendsto_id.atTop_mul_atTop₀ <| tendsto_atTop_add_const_right _ _ <| tendsto_id.const_mul_atTop (neg_pos.mpr ha) lemma cexp_neg_quadratic_isLittleO_rpow_atTop {a : ℂ} (ha : a.re < 0) (b : ℂ) (s : ℝ) : (fun x : ℝ ↦ cexp (a * x ^ 2 + b * x)) =o[atTop] (· ^ s) := by
apply Asymptotics.IsLittleO.of_norm_left convert rexp_neg_quadratic_isLittleO_rpow_atTop ha b.re s with x simp_rw [Complex.norm_exp, add_re, ← ofReal_pow, mul_comm (_ : ℂ) ↑(_ : ℝ), re_ofReal_mul, mul_comm _ (re _)] lemma cexp_neg_quadratic_isLittleO_abs_rpow_cocompact {a : ℂ} (ha : a.re < 0) (b : ℂ) (s : ℝ) :
Mathlib/Analysis/SpecialFunctions/Gaussian/PoissonSummation.lean
48
53
/- 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, Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Dynamics.Ergodic.MeasurePreserving import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Matrix.Diagonal import Mathlib.LinearAlgebra.Matrix.Transvection import Mathlib.MeasureTheory.Group.LIntegral import Mathlib.MeasureTheory.Integral.Marginal import Mathlib.MeasureTheory.Measure.Stieltjes import Mathlib.MeasureTheory.Measure.Haar.OfBasis /-! # Lebesgue measure on the real line and on `ℝⁿ` We show that the Lebesgue measure on the real line (constructed as a particular case of additive Haar measure on inner product spaces) coincides with the Stieltjes measure associated to the function `x ↦ x`. We deduce properties of this measure on `ℝ`, and then of the product Lebesgue measure on `ℝⁿ`. In particular, we prove that they are translation invariant. We show that, on `ℝⁿ`, a linear map acts on Lebesgue measure by rescaling it through the absolute value of its determinant, in `Real.map_linearMap_volume_pi_eq_smul_volume_pi`. More properties of the Lebesgue measure are deduced from this in `Mathlib/MeasureTheory/Measure/Lebesgue/EqHaar.lean`, where they are proved more generally for any additive Haar measure on a finite-dimensional real vector space. -/ assert_not_exists MeasureTheory.integral noncomputable section open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace open ENNReal (ofReal) open scoped ENNReal NNReal Topology /-! ### Definition of the Lebesgue measure and lengths of intervals -/ namespace Real variable {ι : Type*} [Fintype ι] /-- The volume on the real line (as a particular case of the volume on a finite-dimensional inner product space) coincides with the Stieltjes measure coming from the identity function. -/ theorem volume_eq_stieltjes_id : (volume : Measure ℝ) = StieltjesFunction.id.measure := by haveI : IsAddLeftInvariant StieltjesFunction.id.measure := ⟨fun a => Eq.symm <| Real.measure_ext_Ioo_rat fun p q => by simp only [Measure.map_apply (measurable_const_add a) measurableSet_Ioo, sub_sub_sub_cancel_right, StieltjesFunction.measure_Ioo, StieltjesFunction.id_leftLim, StieltjesFunction.id_apply, id, preimage_const_add_Ioo]⟩ have A : StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped = 1 := by change StieltjesFunction.id.measure (parallelepiped (stdOrthonormalBasis ℝ ℝ)) = 1 rcases parallelepiped_orthonormalBasis_one_dim (stdOrthonormalBasis ℝ ℝ) with (H | H) <;> simp only [H, StieltjesFunction.measure_Icc, StieltjesFunction.id_apply, id, tsub_zero, StieltjesFunction.id_leftLim, sub_neg_eq_add, zero_add, ENNReal.ofReal_one] conv_rhs => rw [addHaarMeasure_unique StieltjesFunction.id.measure (stdOrthonormalBasis ℝ ℝ).toBasis.parallelepiped, A] simp only [volume, Basis.addHaar, one_smul] theorem volume_val (s) : volume s = StieltjesFunction.id.measure s := by simp [volume_eq_stieltjes_id] @[simp] theorem volume_Ico {a b : ℝ} : volume (Ico a b) = ofReal (b - a) := by simp [volume_val] @[simp] theorem volume_real_Ico {a b : ℝ} : volume.real (Ico a b) = max (b - a) 0 := by simp [measureReal_def, ENNReal.toReal_ofReal'] theorem volume_real_Ico_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Ico a b) = b - a := by simp [hab] @[simp] theorem volume_Icc {a b : ℝ} : volume (Icc a b) = ofReal (b - a) := by simp [volume_val] @[simp] theorem volume_real_Icc {a b : ℝ} : volume.real (Icc a b) = max (b - a) 0 := by simp [measureReal_def, ENNReal.toReal_ofReal'] theorem volume_real_Icc_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Icc a b) = b - a := by simp [hab] @[simp] theorem volume_Ioo {a b : ℝ} : volume (Ioo a b) = ofReal (b - a) := by simp [volume_val] @[simp] theorem volume_real_Ioo {a b : ℝ} : volume.real (Ioo a b) = max (b - a) 0 := by simp [measureReal_def, ENNReal.toReal_ofReal'] theorem volume_real_Ioo_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Ioo a b) = b - a := by simp [hab] @[simp] theorem volume_Ioc {a b : ℝ} : volume (Ioc a b) = ofReal (b - a) := by simp [volume_val] @[simp] theorem volume_real_Ioc {a b : ℝ} : volume.real (Ioc a b) = max (b - a) 0 := by simp [measureReal_def, ENNReal.toReal_ofReal'] theorem volume_real_Ioc_of_le {a b : ℝ} (hab : a ≤ b) : volume.real (Ioc a b) = b - a := by simp [hab] theorem volume_singleton {a : ℝ} : volume ({a} : Set ℝ) = 0 := by simp [volume_val] theorem volume_univ : volume (univ : Set ℝ) = ∞ := ENNReal.eq_top_of_forall_nnreal_le fun r => calc (r : ℝ≥0∞) = volume (Icc (0 : ℝ) r) := by simp _ ≤ volume univ := measure_mono (subset_univ _) @[simp] theorem volume_ball (a r : ℝ) : volume (Metric.ball a r) = ofReal (2 * r) := by rw [ball_eq_Ioo, volume_Ioo, ← sub_add, add_sub_cancel_left, two_mul] @[simp] theorem volume_real_ball {a r : ℝ} (hr : 0 ≤ r) : volume.real (Metric.ball a r) = 2 * r := by simp [measureReal_def, hr] @[simp] theorem volume_closedBall (a r : ℝ) : volume (Metric.closedBall a r) = ofReal (2 * r) := by rw [closedBall_eq_Icc, volume_Icc, ← sub_add, add_sub_cancel_left, two_mul] @[simp] theorem volume_real_closedBall {a r : ℝ} (hr : 0 ≤ r) : volume.real (Metric.closedBall a r) = 2 * r := by simp [measureReal_def, hr] @[simp] theorem volume_emetric_ball (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.ball a r) = 2 * r := by rcases eq_or_ne r ∞ with (rfl | hr) · rw [Metric.emetric_ball_top, volume_univ, two_mul, _root_.top_add] · lift r to ℝ≥0 using hr rw [Metric.emetric_ball_nnreal, volume_ball, two_mul, ← NNReal.coe_add, ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul] @[simp] theorem volume_emetric_closedBall (a : ℝ) (r : ℝ≥0∞) : volume (EMetric.closedBall a r) = 2 * r := by rcases eq_or_ne r ∞ with (rfl | hr) · rw [EMetric.closedBall_top, volume_univ, two_mul, _root_.top_add] · lift r to ℝ≥0 using hr rw [Metric.emetric_closedBall_nnreal, volume_closedBall, two_mul, ← NNReal.coe_add, ENNReal.ofReal_coe_nnreal, ENNReal.coe_add, two_mul] instance noAtoms_volume : NoAtoms (volume : Measure ℝ) := ⟨fun _ => volume_singleton⟩ @[simp] theorem volume_interval {a b : ℝ} : volume (uIcc a b) = ofReal |b - a| := by rw [← Icc_min_max, volume_Icc, max_sub_min_eq_abs] @[simp] theorem volume_real_interval {a b : ℝ} : volume.real (uIcc a b) = |b - a| := by simp [measureReal_def] @[simp] theorem volume_Ioi {a : ℝ} : volume (Ioi a) = ∞ := top_unique <| le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n => calc (n : ℝ≥0∞) = volume (Ioo a (a + n)) := by simp _ ≤ volume (Ioi a) := measure_mono Ioo_subset_Ioi_self @[simp] theorem volume_Ici {a : ℝ} : volume (Ici a) = ∞ := by rw [← measure_congr Ioi_ae_eq_Ici]; simp @[simp] theorem volume_Iio {a : ℝ} : volume (Iio a) = ∞ := top_unique <| le_of_tendsto' ENNReal.tendsto_nat_nhds_top fun n => calc (n : ℝ≥0∞) = volume (Ioo (a - n) a) := by simp _ ≤ volume (Iio a) := measure_mono Ioo_subset_Iio_self @[simp] theorem volume_Iic {a : ℝ} : volume (Iic a) = ∞ := by rw [← measure_congr Iio_ae_eq_Iic]; simp instance locallyFinite_volume : IsLocallyFiniteMeasure (volume : Measure ℝ) := ⟨fun x => ⟨Ioo (x - 1) (x + 1), IsOpen.mem_nhds isOpen_Ioo ⟨sub_lt_self _ zero_lt_one, lt_add_of_pos_right _ zero_lt_one⟩, by simp only [Real.volume_Ioo, ENNReal.ofReal_lt_top]⟩⟩ instance isFiniteMeasure_restrict_Icc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Icc x y)) := ⟨by simp⟩ instance isFiniteMeasure_restrict_Ico (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ico x y)) := ⟨by simp⟩ instance isFiniteMeasure_restrict_Ioc (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioc x y)) := ⟨by simp⟩ instance isFiniteMeasure_restrict_Ioo (x y : ℝ) : IsFiniteMeasure (volume.restrict (Ioo x y)) := ⟨by simp⟩ theorem volume_le_diam (s : Set ℝ) : volume s ≤ EMetric.diam s := by by_cases hs : Bornology.IsBounded s · rw [Real.ediam_eq hs, ← volume_Icc] exact volume.mono hs.subset_Icc_sInf_sSup · rw [Metric.ediam_of_unbounded hs]; exact le_top theorem _root_.Filter.Eventually.volume_pos_of_nhds_real {p : ℝ → Prop} {a : ℝ} (h : ∀ᶠ x in 𝓝 a, p x) : (0 : ℝ≥0∞) < volume { x | p x } := by rcases h.exists_Ioo_subset with ⟨l, u, hx, hs⟩ refine lt_of_lt_of_le ?_ (measure_mono hs) simpa [-mem_Ioo] using hx.1.trans hx.2 /-! ### Volume of a box in `ℝⁿ` -/ theorem volume_Icc_pi {a b : ι → ℝ} : volume (Icc a b) = ∏ i, ENNReal.ofReal (b i - a i) := by rw [← pi_univ_Icc, volume_pi_pi] simp only [Real.volume_Icc] @[simp] theorem volume_Icc_pi_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (Icc a b)).toReal = ∏ i, (b i - a i) := by simp only [volume_Icc_pi, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] theorem volume_pi_Ioo {a b : ι → ℝ} : volume (pi univ fun i => Ioo (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ioo_ae_eq_Icc).trans volume_Icc_pi @[simp] theorem volume_pi_Ioo_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ioo (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ioo, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] theorem volume_pi_Ioc {a b : ι → ℝ} : volume (pi univ fun i => Ioc (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ioc_ae_eq_Icc).trans volume_Icc_pi @[simp] theorem volume_pi_Ioc_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ioc (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ioc, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] theorem volume_pi_Ico {a b : ι → ℝ} : volume (pi univ fun i => Ico (a i) (b i)) = ∏ i, ENNReal.ofReal (b i - a i) := (measure_congr Measure.univ_pi_Ico_ae_eq_Icc).trans volume_Icc_pi @[simp] theorem volume_pi_Ico_toReal {a b : ι → ℝ} (h : a ≤ b) : (volume (pi univ fun i => Ico (a i) (b i))).toReal = ∏ i, (b i - a i) := by simp only [volume_pi_Ico, ENNReal.toReal_prod, ENNReal.toReal_ofReal (sub_nonneg.2 (h _))] @[simp] nonrec theorem volume_pi_ball (a : ι → ℝ) {r : ℝ} (hr : 0 < r) : volume (Metric.ball a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by simp only [MeasureTheory.volume_pi_ball a hr, volume_ball, Finset.prod_const] exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr.le) _).symm @[simp] nonrec theorem volume_pi_closedBall (a : ι → ℝ) {r : ℝ} (hr : 0 ≤ r) : volume (Metric.closedBall a r) = ENNReal.ofReal ((2 * r) ^ Fintype.card ι) := by simp only [MeasureTheory.volume_pi_closedBall a hr, volume_closedBall, Finset.prod_const] exact (ENNReal.ofReal_pow (mul_nonneg zero_le_two hr) _).symm theorem volume_pi_le_prod_diam (s : Set (ι → ℝ)) : volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := calc volume s ≤ volume (pi univ fun i => closure (Function.eval i '' s)) := volume.mono <| Subset.trans (subset_pi_eval_image univ s) <| pi_mono fun _ _ => subset_closure _ = ∏ i, volume (closure <| Function.eval i '' s) := volume_pi_pi _ _ ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := Finset.prod_le_prod' fun _ _ => (volume_le_diam _).trans_eq (EMetric.diam_closure _) theorem volume_pi_le_diam_pow (s : Set (ι → ℝ)) : volume s ≤ EMetric.diam s ^ Fintype.card ι := calc volume s ≤ ∏ i : ι, EMetric.diam (Function.eval i '' s) := volume_pi_le_prod_diam s _ ≤ ∏ _i : ι, (1 : ℝ≥0) * EMetric.diam s := (Finset.prod_le_prod' fun i _ => (LipschitzWith.eval i).ediam_image_le s) _ = EMetric.diam s ^ Fintype.card ι := by simp only [ENNReal.coe_one, one_mul, Finset.prod_const, Fintype.card] /-! ### Images of the Lebesgue measure under multiplication in ℝ -/ theorem smul_map_volume_mul_left {a : ℝ} (h : a ≠ 0) : ENNReal.ofReal |a| • Measure.map (a * ·) volume = volume := by refine (Real.measure_ext_Ioo_rat fun p q => ?_).symm rcases lt_or_gt_of_ne h with h | h · simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt <| neg_pos.2 h), Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, neg_sub_neg, neg_mul, preimage_const_mul_Ioo_of_neg _ _ h, abs_of_neg h, mul_sub, smul_eq_mul, mul_div_cancel₀ _ (ne_of_lt h)] · simp only [Real.volume_Ioo, Measure.smul_apply, ← ENNReal.ofReal_mul (le_of_lt h), Measure.map_apply (measurable_const_mul a) measurableSet_Ioo, preimage_const_mul_Ioo _ _ h, abs_of_pos h, mul_sub, mul_div_cancel₀ _ (ne_of_gt h), smul_eq_mul] theorem map_volume_mul_left {a : ℝ} (h : a ≠ 0) : Measure.map (a * ·) volume = ENNReal.ofReal |a⁻¹| • volume := by conv_rhs => rw [← Real.smul_map_volume_mul_left h, smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel₀ h, abs_one, ENNReal.ofReal_one, one_smul] @[simp] theorem volume_preimage_mul_left {a : ℝ} (h : a ≠ 0) (s : Set ℝ) : volume ((a * ·) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s := calc volume ((a * ·) ⁻¹' s) = Measure.map (a * ·) volume s := ((Homeomorph.mulLeft₀ a h).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_left h]; rfl theorem smul_map_volume_mul_right {a : ℝ} (h : a ≠ 0) : ENNReal.ofReal |a| • Measure.map (· * a) volume = volume := by simpa only [mul_comm] using Real.smul_map_volume_mul_left h theorem map_volume_mul_right {a : ℝ} (h : a ≠ 0) : Measure.map (· * a) volume = ENNReal.ofReal |a⁻¹| • volume := by simpa only [mul_comm] using Real.map_volume_mul_left h @[simp] theorem volume_preimage_mul_right {a : ℝ} (h : a ≠ 0) (s : Set ℝ) : volume ((· * a) ⁻¹' s) = ENNReal.ofReal (abs a⁻¹) * volume s := calc volume ((· * a) ⁻¹' s) = Measure.map (· * a) volume s := ((Homeomorph.mulRight₀ a h).toMeasurableEquiv.map_apply s).symm _ = ENNReal.ofReal (abs a⁻¹) * volume s := by rw [map_volume_mul_right h]; rfl /-! ### Images of the Lebesgue measure under translation/linear maps in ℝⁿ -/ open Matrix /-- A diagonal matrix rescales Lebesgue according to its determinant. This is a special case of `Real.map_matrix_volume_pi_eq_smul_volume_pi`, that one should use instead (and whose proof uses this particular case). -/ theorem smul_map_diagonal_volume_pi [DecidableEq ι] {D : ι → ℝ} (h : det (diagonal D) ≠ 0) : ENNReal.ofReal (abs (det (diagonal D))) • Measure.map (toLin' (diagonal D)) volume = volume := by refine (Measure.pi_eq fun s hs => ?_).symm simp only [det_diagonal, Measure.coe_smul, Algebra.id.smul_eq_mul, Pi.smul_apply] rw [Measure.map_apply _ (MeasurableSet.univ_pi hs)] swap; · exact Continuous.measurable (LinearMap.continuous_on_pi _) have : (Matrix.toLin' (diagonal D) ⁻¹' Set.pi Set.univ fun i : ι => s i) = Set.pi Set.univ fun i : ι => (D i * ·) ⁻¹' s i := by ext f simp only [LinearMap.coe_proj, Algebra.id.smul_eq_mul, LinearMap.smul_apply, mem_univ_pi, mem_preimage, LinearMap.pi_apply, diagonal_toLin'] have B : ∀ i, ofReal (abs (D i)) * volume ((D i * ·) ⁻¹' s i) = volume (s i) := by intro i have A : D i ≠ 0 := by simp only [det_diagonal, Ne] at h exact Finset.prod_ne_zero_iff.1 h i (Finset.mem_univ i) rw [volume_preimage_mul_left A, ← mul_assoc, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, mul_inv_cancel₀ A, abs_one, ENNReal.ofReal_one, one_mul] rw [this, volume_pi_pi, Finset.abs_prod, ENNReal.ofReal_prod_of_nonneg fun i _ => abs_nonneg (D i), ← Finset.prod_mul_distrib] simp only [B] /-- A transvection preserves Lebesgue measure. -/ theorem volume_preserving_transvectionStruct [DecidableEq ι] (t : TransvectionStruct ι ℝ) : MeasurePreserving (toLin' t.toMatrix) := by /- We use `lmarginal` to conveniently use Fubini's theorem. Along the coordinate where there is a shearing, it acts like a translation, and therefore preserves Lebesgue. -/ have ht : Measurable (toLin' t.toMatrix) := (toLin' t.toMatrix).continuous_of_finiteDimensional.measurable refine ⟨ht, ?_⟩ refine (pi_eq fun s hs ↦ ?_).symm have h2s : MeasurableSet (univ.pi s) := .pi countable_univ fun i _ ↦ hs i simp_rw [← pi_pi, ← lintegral_indicator_one h2s] rw [lintegral_map (measurable_one.indicator h2s) ht, volume_pi] refine lintegral_eq_of_lmarginal_eq {t.i} ((measurable_one.indicator h2s).comp ht) (measurable_one.indicator h2s) ?_ simp_rw [lmarginal_singleton] ext x cases t with | mk t_i t_j t_hij t_c => simp [transvection, mulVec_stdBasisMatrix, t_hij.symm, ← Function.update_add, lintegral_add_right_eq_self fun xᵢ ↦ indicator (univ.pi s) 1 (Function.update x t_i xᵢ)] /-- Any invertible matrix rescales Lebesgue measure through the absolute value of its determinant. -/ theorem map_matrix_volume_pi_eq_smul_volume_pi [DecidableEq ι] {M : Matrix ι ι ℝ} (hM : det M ≠ 0) : Measure.map (toLin' M) volume = ENNReal.ofReal (abs (det M)⁻¹) • volume := by -- This follows from the cases we have already proved, of diagonal matrices and transvections, -- as these matrices generate all invertible matrices. apply diagonal_transvection_induction_of_det_ne_zero _ M hM · intro D hD conv_rhs => rw [← smul_map_diagonal_volume_pi hD] rw [smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, inv_mul_cancel₀ hD, abs_one, ENNReal.ofReal_one, one_smul] · intro t simp_rw [Matrix.TransvectionStruct.det, _root_.inv_one, abs_one, ENNReal.ofReal_one, one_smul, (volume_preserving_transvectionStruct _).map_eq] · intro A B _ _ IHA IHB rw [toLin'_mul, det_mul, LinearMap.coe_comp, ← Measure.map_map, IHB, Measure.map_smul, IHA, smul_smul, ← ENNReal.ofReal_mul (abs_nonneg _), ← abs_mul, mul_comm, mul_inv] · apply Continuous.measurable apply LinearMap.continuous_on_pi · apply Continuous.measurable apply LinearMap.continuous_on_pi /-- Any invertible linear map rescales Lebesgue measure through the absolute value of its determinant. -/ theorem map_linearMap_volume_pi_eq_smul_volume_pi {f : (ι → ℝ) →ₗ[ℝ] ι → ℝ} (hf : LinearMap.det f ≠ 0) : Measure.map f volume = ENNReal.ofReal (abs (LinearMap.det f)⁻¹) • volume := by classical -- this is deduced from the matrix case let M := LinearMap.toMatrix' f have A : LinearMap.det f = det M := by simp only [M, LinearMap.det_toMatrix'] have B : f = toLin' M := by simp only [M, toLin'_toMatrix'] rw [A, B] apply map_matrix_volume_pi_eq_smul_volume_pi rwa [A] at hf end Real section regionBetween variable {α : Type*} /-- The region between two real-valued functions on an arbitrary set. -/ def regionBetween (f g : α → ℝ) (s : Set α) : Set (α × ℝ) := { p : α × ℝ | p.1 ∈ s ∧ p.2 ∈ Ioo (f p.1) (g p.1) } theorem regionBetween_subset (f g : α → ℝ) (s : Set α) : regionBetween f g s ⊆ s ×ˢ univ := by simpa only [prod_univ, regionBetween, Set.preimage, setOf_subset_setOf] using fun a => And.left variable [MeasurableSpace α] {μ : Measure α} {f g : α → ℝ} {s : Set α} /-- The region between two measurable functions on a measurable set is measurable. -/ theorem measurableSet_regionBetween (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet (regionBetween f g s) := by dsimp only [regionBetween, Ioo, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter (measurableSet_lt measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graph of the upper function. -/ theorem measurableSet_region_between_oc (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ioc (f p.fst) (g p.fst) } := by dsimp only [regionBetween, Ioc, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_lt (hf.comp measurable_fst) measurable_snd).inter (measurableSet_le measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graph of the lower function. -/ theorem measurableSet_region_between_co (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Ico (f p.fst) (g p.fst) } := by dsimp only [regionBetween, Ico, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter (measurableSet_lt measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs /-- The region between two measurable functions on a measurable set is measurable; a version for the region together with the graphs of both functions. -/ theorem measurableSet_region_between_cc (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : MeasurableSet { p : α × ℝ | p.fst ∈ s ∧ p.snd ∈ Icc (f p.fst) (g p.fst) } := by dsimp only [regionBetween, Icc, mem_setOf_eq, setOf_and] refine MeasurableSet.inter ?_ ((measurableSet_le (hf.comp measurable_fst) measurable_snd).inter (measurableSet_le measurable_snd (hg.comp measurable_fst))) exact measurable_fst hs /-- The graph of a measurable function is a measurable set. -/ theorem measurableSet_graph (hf : Measurable f) : MeasurableSet { p : α × ℝ | p.snd = f p.fst } := by simpa using measurableSet_region_between_cc hf hf MeasurableSet.univ theorem volume_regionBetween_eq_lintegral' (hf : Measurable f) (hg : Measurable g) (hs : MeasurableSet s) : μ.prod volume (regionBetween f g s) = ∫⁻ y in s, ENNReal.ofReal ((g - f) y) ∂μ := by classical rw [Measure.prod_apply] · have h : (fun x => volume { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) }) = s.indicator fun x => ENNReal.ofReal (g x - f x) := by funext x rw [indicator_apply] split_ifs with h · have hx : { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) } = Ioo (f x) (g x) := by simp [h, Ioo] simp only [hx, Real.volume_Ioo, sub_zero]
· have hx : { a | x ∈ s ∧ a ∈ Ioo (f x) (g x) } = ∅ := by simp [h] simp only [hx, measure_empty] dsimp only [regionBetween, preimage_setOf_eq]
Mathlib/MeasureTheory/Measure/Lebesgue/Basic.lean
506
508
/- 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, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Module.Basic import Mathlib.MeasureTheory.Function.SimpleFuncDense /-! # Strongly measurable and finitely strongly measurable functions A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions. It is said to be finitely strongly measurable with respect to a measure `μ` if the supports of those simple functions have finite measure. If the target space has a second countable topology, strongly measurable and measurable are equivalent. If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent. The main property of finitely strongly measurable functions is `FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some results for those functions as if the measure was sigma-finite. We provide a solid API for strongly measurable functions, as a basis for the Bochner integral. ## Main definitions * `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`. * `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β` such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite. ## References * [Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces. Springer, 2016.][Hytonen_VanNeerven_Veraar_Wies_2016] -/ -- Guard against import creep assert_not_exists InnerProductSpace open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure open ENNReal Topology MeasureTheory NNReal variable {α β γ ι : Type*} [Countable ι] namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc section Definitions variable [TopologicalSpace β] /-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/ def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop := ∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) /-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/ scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m /-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple functions with support with finite measure. -/ def FinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) end Definitions open MeasureTheory /-! ## Strongly measurable functions -/ section StronglyMeasurable variable {_ : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : ℕ → α} {m : ℕ} variable [TopologicalSpace β] theorem SimpleFunc.stronglyMeasurable (f : α →ₛ β) : StronglyMeasurable f := ⟨fun _ => f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_dom [Subsingleton α] : StronglyMeasurable f := ⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩ @[simp, nontriviality] lemma StronglyMeasurable.of_subsingleton_cod [Subsingleton β] : StronglyMeasurable f := by let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩ · exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩ · simp [Set.preimage, eq_iff_true_of_subsingleton] @[deprecated StronglyMeasurable.of_subsingleton_cod (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable [Subsingleton β] (f : α → β) : StronglyMeasurable f := .of_subsingleton_cod @[deprecated StronglyMeasurable.of_subsingleton_dom (since := "2025-04-09")] lemma Subsingleton.stronglyMeasurable' [Subsingleton α] (f : α → β) : StronglyMeasurable f := .of_subsingleton_dom theorem stronglyMeasurable_const {b : β} : StronglyMeasurable fun _ : α => b := ⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩ @[to_additive] theorem stronglyMeasurable_one [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const /-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem stronglyMeasurable_const' (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by nontriviality α inhabit α convert stronglyMeasurable_const (β := β) using 1 exact funext fun x => hf x default variable [MeasurableSingletonClass α] section aux omit [TopologicalSpace β] /-- Auxiliary definition for `StronglyMeasurable.of_discrete`. -/ private noncomputable def simpleFuncAux (f : α → β) (g : ℕ → α) : ℕ → SimpleFunc α β | 0 => .const _ (f (g 0)) | n + 1 => .piecewise {g n} (.singleton _) (.const _ <| f (g n)) (simpleFuncAux f g n) private lemma simpleFuncAux_eq_of_lt : ∀ n > m, simpleFuncAux f g n (g m) = f (g m) | _, .refl => by simp [simpleFuncAux] | _, Nat.le.step (m := n) hmn => by obtain hnm | hnm := eq_or_ne (g n) (g m) <;> simp [simpleFuncAux, Set.piecewise_eq_of_not_mem , hnm.symm, simpleFuncAux_eq_of_lt _ hmn] private lemma simpleFuncAux_eventuallyEq : ∀ᶠ n in atTop, simpleFuncAux f g n (g m) = f (g m) := eventually_atTop.2 ⟨_, simpleFuncAux_eq_of_lt⟩ end aux lemma StronglyMeasurable.of_discrete [Countable α] : StronglyMeasurable f := by nontriviality α nontriviality β obtain ⟨g, hg⟩ := exists_surjective_nat α exact ⟨simpleFuncAux f g, hg.forall.2 fun m ↦ tendsto_nhds_of_eventually_eq simpleFuncAux_eventuallyEq⟩ @[deprecated StronglyMeasurable.of_discrete (since := "2025-04-09")] theorem StronglyMeasurable.of_finite [Finite α] : StronglyMeasurable f := .of_discrete end StronglyMeasurable namespace StronglyMeasurable variable {f g : α → β} section BasicPropertiesInAnyTopologicalSpace variable [TopologicalSpace β] /-- A sequence of simple functions such that `∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`. That property is given by `stronglyMeasurable.tendsto_approx`. -/ protected noncomputable def approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ℕ → α →ₛ β := hf.choose protected theorem tendsto_approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec /-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the sequence is less than `c` everywhere. If `‖f x‖ ≤ c` this sequence of simple functions verifies `Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/ noncomputable def approxBounded {_ : MeasurableSpace α} [Norm β] [SMul ℝ β] (hf : StronglyMeasurable f) (c : ℝ) : ℕ → SimpleFunc α β := fun n => (hf.approx n).map fun x => min 1 (c / ‖x‖) • x theorem tendsto_approxBounded_of_norm_le {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : α} (hfx : ‖f x‖ ≤ c) : Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by have h_tendsto := hf.tendsto_approx x simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] by_cases hfx0 : ‖f x‖ = 0 · rw [norm_eq_zero] at hfx0 rw [hfx0] at h_tendsto ⊢ have h_tendsto_norm : Tendsto (fun n => ‖hf.approx n x‖) atTop (𝓝 0) := by convert h_tendsto.norm rw [norm_zero] refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm calc ‖min 1 (c / ‖hf.approx n x‖) • hf.approx n x‖ = ‖min 1 (c / ‖hf.approx n x‖)‖ * ‖hf.approx n x‖ := norm_smul _ _ _ ≤ ‖(1 : ℝ)‖ * ‖hf.approx n x‖ := by refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) rw [norm_one, Real.norm_of_nonneg] · exact min_le_left _ _ · exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)) _ = ‖hf.approx n x‖ := by rw [norm_one, one_mul] rw [← one_smul ℝ (f x)] refine Tendsto.smul ?_ h_tendsto have : min 1 (c / ‖f x‖) = 1 := by rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))] exact hfx nth_rw 2 [this.symm] refine Tendsto.min tendsto_const_nhds ?_ exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0 theorem tendsto_approxBounded_ae {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m m0 : MeasurableSpace α} {μ : Measure α} (hf : StronglyMeasurable[m] f) {c : ℝ} (hf_bound : ∀ᵐ x ∂μ, ‖f x‖ ≤ c) : ∀ᵐ x ∂μ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx theorem norm_approxBounded_le {β} {f : α → β} [SeminormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) : ‖hf.approxBounded c n x‖ ≤ c := by simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] refine (norm_smul_le _ _).trans ?_ by_cases h0 : ‖hf.approx n x‖ = 0 · simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero] exact hc rcases le_total ‖hf.approx n x‖ c with h | h · rw [min_eq_left _] · simpa only [norm_one, one_mul] using h · rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] · rw [min_eq_right _] · rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc, inv_mul_cancel₀ h0, one_mul, Real.norm_of_nonneg hc] · rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] theorem _root_.stronglyMeasurable_bot_iff [Nonempty β] [T2Space β] : StronglyMeasurable[⊥] f ↔ ∃ c, f = fun _ => c := by rcases isEmpty_or_nonempty α with hα | hα · simp [eq_iff_true_of_subsingleton] refine ⟨fun hf => ?_, fun hf_eq => ?_⟩ · refine ⟨f hα.some, ?_⟩ let fs := hf.approx have h_fs_tendsto : ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx have : ∀ n, ∃ c, ∀ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n) let cs n := (this n).choose have h_cs_eq : ∀ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq] have h_tendsto : Tendsto cs atTop (𝓝 (f hα.some)) := h_fs_tendsto hα.some ext1 x exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto · obtain ⟨c, rfl⟩ := hf_eq exact stronglyMeasurable_const end BasicPropertiesInAnyTopologicalSpace theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace β] [Zero β] {m : MeasurableSpace α} {μ : Measure α} (hf_meas : StronglyMeasurable f) {t : Set α} (ht : MeasurableSet t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : SigmaFinite (μ.restrict t)) : FinStronglyMeasurable f μ := by haveI : SigmaFinite (μ.restrict t) := htμ let S := spanningSets (μ.restrict t) have hS_meas : ∀ n, MeasurableSet (S n) := measurableSet_spanningSets (μ.restrict t) let f_approx := hf_meas.approx let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t) have h_fs_t_compl : ∀ n, ∀ x, x ∉ t → fs n x = 0 := by intro n x hxt rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)] refine Set.indicator_of_not_mem ?_ _ simp [hxt] refine ⟨fs, ?_, fun x => ?_⟩ · simp_rw [SimpleFunc.support_eq, ← Finset.mem_coe] classical refine fun n => measure_biUnion_lt_top {y ∈ (fs n).range | y ≠ 0}.finite_toSet fun y hy => ?_ rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)] swap · letI : (y : β) → Decidable (y = 0) := fun y => Classical.propDecidable _ rw [Finset.mem_coe, Finset.mem_filter] at hy exact hy.2 refine (measure_mono Set.inter_subset_left).trans_lt ?_ have h_lt_top := measure_spanningSets_lt_top (μ.restrict t) n rwa [Measure.restrict_apply' ht] at h_lt_top · by_cases hxt : x ∈ t swap · rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt] exact tendsto_const_nhds have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x := by obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t := by rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m · exact ⟨n, fun m hnm => Set.mem_inter (hn m hnm) hxt⟩ rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n · exact ⟨n, fun m hnm => monotone_spanningSets (μ.restrict t) hnm hn⟩ rw [← Set.mem_iUnion, iUnion_spanningSets (μ.restrict t)] trivial refine ⟨n, fun m hnm => ?_⟩ simp_rw [fs, SimpleFunc.restrict_apply _ ((hS_meas m).inter ht), Set.indicator_of_mem (hn m hnm)] rw [tendsto_atTop'] at h ⊢ intro s hs obtain ⟨n₂, hn₂⟩ := h s hs refine ⟨max n₁ n₂, fun m hm => ?_⟩ rw [hn₁ m ((le_max_left _ _).trans hm.le)] exact hn₂ m ((le_max_right _ _).trans hm.le) /-- If the measure is sigma-finite, all strongly measurable functions are `FinStronglyMeasurable`. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem finStronglyMeasurable [TopologicalSpace β] [Zero β] {m0 : MeasurableSpace α} (hf : StronglyMeasurable f) (μ : Measure α) [SigmaFinite μ] : FinStronglyMeasurable f μ := hf.finStronglyMeasurable_of_set_sigmaFinite MeasurableSet.univ (by simp) (by rwa [Measure.restrict_univ]) /-- A strongly measurable function is measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem measurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : StronglyMeasurable f) : Measurable f := measurable_of_tendsto_metrizable (fun n => (hf.approx n).measurable) (tendsto_pi_nhds.mpr hf.tendsto_approx) /-- A strongly measurable function is almost everywhere measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem aemeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {μ : Measure α} (hf : StronglyMeasurable f) : AEMeasurable f μ := hf.measurable.aemeasurable theorem _root_.Continuous.comp_stronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} (hg : Continuous g) (hf : StronglyMeasurable f) : StronglyMeasurable fun x => g (f x) := ⟨fun n => SimpleFunc.map g (hf.approx n), fun x => (hg.tendsto _).comp (hf.tendsto_approx x)⟩ @[to_additive] nonrec theorem measurableSet_mulSupport {m : MeasurableSpace α} [One β] [TopologicalSpace β] [MetrizableSpace β] (hf : StronglyMeasurable f) : MeasurableSet (mulSupport f) := by borelize β exact measurableSet_mulSupport hf.measurable protected theorem mono {m m' : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable[m'] f) (h_mono : m' ≤ m) : StronglyMeasurable[m] f := by let f_approx : ℕ → @SimpleFunc α m β := fun n => @SimpleFunc.mk α m β (hf.approx n) (fun x => h_mono _ (SimpleFunc.measurableSet_fiber' _ x)) (SimpleFunc.finite_range (hf.approx n)) exact ⟨f_approx, hf.tendsto_approx⟩ protected theorem prodMk {m : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {f : α → β} {g : α → γ} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => (f x, g x) := by refine ⟨fun n => SimpleFunc.pair (hf.approx n) (hg.approx n), fun x => ?_⟩ rw [nhds_prod_eq] exact Tendsto.prodMk (hf.tendsto_approx x) (hg.tendsto_approx x) @[deprecated (since := "2025-03-05")] protected alias prod_mk := StronglyMeasurable.prodMk theorem comp_measurable [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → β} {g : γ → α} (hf : StronglyMeasurable f) (hg : Measurable g) : StronglyMeasurable (f ∘ g) := ⟨fun n => SimpleFunc.comp (hf.approx n) g hg, fun x => hf.tendsto_approx (g x)⟩ theorem of_uncurry_left [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {x : α} : StronglyMeasurable (f x) := hf.comp_measurable measurable_prodMk_left theorem of_uncurry_right [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {y : γ} : StronglyMeasurable fun x => f x y := hf.comp_measurable measurable_prodMk_right protected theorem prod_swap {_ : MeasurableSpace α} {_ : MeasurableSpace β} [TopologicalSpace γ] {f : β × α → γ} (hf : StronglyMeasurable f) : StronglyMeasurable (fun z : α × β => f z.swap) := hf.comp_measurable measurable_swap protected theorem fst {_ : MeasurableSpace α} [mβ : MeasurableSpace β] [TopologicalSpace γ] {f : α → γ} (hf : StronglyMeasurable f) : StronglyMeasurable (fun z : α × β => f z.1) := hf.comp_measurable measurable_fst protected theorem snd [mα : MeasurableSpace α] {_ : MeasurableSpace β} [TopologicalSpace γ] {f : β → γ} (hf : StronglyMeasurable f) : StronglyMeasurable (fun z : α × β => f z.2) := hf.comp_measurable measurable_snd section Arithmetic variable {mα : MeasurableSpace α} [TopologicalSpace β] @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f * g) := ⟨fun n => hf.approx n * hg.approx n, fun x => (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩ @[to_additive (attr := measurability)] theorem mul_const [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x * c := hf.mul stronglyMeasurable_const @[to_additive (attr := measurability)] theorem const_mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => c * f x := stronglyMeasurable_const.mul hf @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable])) const_nsmul] protected theorem pow [Monoid β] [ContinuousMul β] (hf : StronglyMeasurable f) (n : ℕ) : StronglyMeasurable (f ^ n) := ⟨fun k => hf.approx k ^ n, fun x => (hf.tendsto_approx x).pow n⟩ @[to_additive (attr := measurability)] protected theorem inv [Inv β] [ContinuousInv β] (hf : StronglyMeasurable f) : StronglyMeasurable f⁻¹ := ⟨fun n => (hf.approx n)⁻¹, fun x => (hf.tendsto_approx x).inv⟩ @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem div [Div β] [ContinuousDiv β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f / g) := ⟨fun n => hf.approx n / hg.approx n, fun x => (hf.tendsto_approx x).div' (hg.tendsto_approx x)⟩ @[to_additive] theorem mul_iff_right [CommGroup β] [IsTopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (f * g) ↔ StronglyMeasurable g := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem mul_iff_left [CommGroup β] [IsTopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (g * f) ↔ StronglyMeasurable g := mul_comm g f ▸ mul_iff_right hf @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem smul {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} {g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => f x • g x := continuous_smul.comp_stronglyMeasurable (hf.prodMk hg) @[to_additive (attr := measurability)] protected theorem const_smul {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable (c • f) := ⟨fun n => c • hf.approx n, fun x => (hf.tendsto_approx x).const_smul c⟩ @[to_additive (attr := measurability)] protected theorem const_smul' {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable fun x => c • f x := hf.const_smul c @[to_additive (attr := measurability)] protected theorem smul_const {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x • c := continuous_smul.comp_stronglyMeasurable (hf.prodMk stronglyMeasurable_const) /-- In a normed vector space, the addition of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.add_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddCancelMonoid E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g + f) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ g x + φ n x) atTop (𝓝 (g + f)) := tendsto_pi_nhds.2 (fun x ↦ tendsto_const_nhds.add (hφ x)) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.add_simpleFunc _ /-- In a normed vector space, the subtraction of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the subtraction of two measurable functions. -/ theorem _root_.Measurable.sub_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [ContinuousNeg E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g - f) := by rw [sub_eq_add_neg] exact hg.add_stronglyMeasurable hf.neg /-- In a normed vector space, the addition of a strongly measurable function and a measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.stronglyMeasurable_add {α E : Type*} {_ : MeasurableSpace α} [AddCancelMonoid E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (f + g) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ φ n x + g x) atTop (𝓝 (f + g)) := tendsto_pi_nhds.2 (fun x ↦ (hφ x).add tendsto_const_nhds) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.simpleFunc_add _ end Arithmetic section MulAction variable {M G G₀ : Type*} variable [TopologicalSpace β] variable [Monoid M] [MulAction M β] [ContinuousConstSMul M β] variable [Group G] [MulAction G β] [ContinuousConstSMul G β] variable [GroupWithZero G₀] [MulAction G₀ β] [ContinuousConstSMul G₀ β] theorem _root_.stronglyMeasurable_const_smul_iff {m : MeasurableSpace α} (c : G) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩ nonrec theorem _root_.IsUnit.stronglyMeasurable_const_smul_iff {_ : MeasurableSpace α} {c : M} (hc : IsUnit c) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := let ⟨u, hu⟩ := hc hu ▸ stronglyMeasurable_const_smul_iff u theorem _root_.stronglyMeasurable_const_smul_iff₀ {_ : MeasurableSpace α} {c : G₀} (hc : c ≠ 0) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := (IsUnit.mk0 _ hc).stronglyMeasurable_const_smul_iff end MulAction section Order variable [MeasurableSpace α] [TopologicalSpace β] open Filter @[aesop safe 20 (rule_sets := [Measurable])] protected theorem sup [Max β] [ContinuousSup β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊔ g) := ⟨fun n => hf.approx n ⊔ hg.approx n, fun x => (hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩ @[aesop safe 20 (rule_sets := [Measurable])] protected theorem inf [Min β] [ContinuousInf β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊓ g) := ⟨fun n => hf.approx n ⊓ hg.approx n, fun x => (hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩ end Order /-! ### Big operators: `∏` and `∑` -/ section Monoid variable {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by induction' l with f l ihl; · exact stronglyMeasurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable fun x => (l.map fun f : α → M => f x).prod := by simpa only [← Pi.list_prod_apply] using l.stronglyMeasurable_prod' hl end Monoid section CommMonoid variable {M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by rcases l with ⟨l⟩ simpa using l.stronglyMeasurable_prod' (by simpa using hl) @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod (s : Multiset (α → M)) (hs : ∀ f ∈ s, StronglyMeasurable f) : StronglyMeasurable fun x => (s.map fun f : α → M => f x).prod := by simpa only [← Pi.multiset_prod_apply] using s.stronglyMeasurable_prod' hs @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod' {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable (∏ i ∈ s, f i) := Finset.prod_induction _ _ (fun _a _b ha hb => ha.mul hb) (@stronglyMeasurable_one α M _ _ _) hf @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable fun a => ∏ i ∈ s, f i a := by simpa only [← Finset.prod_apply] using s.stronglyMeasurable_prod' hf end CommMonoid /-- The range of a strongly measurable function is separable. -/ protected theorem isSeparable_range {m : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable f) : TopologicalSpace.IsSeparable (range f) := by have : IsSeparable (closure (⋃ n, range (hf.approx n))) := .closure <| .iUnion fun n => (hf.approx n).finite_range.isSeparable apply this.mono rintro _ ⟨x, rfl⟩ apply mem_closure_of_tendsto (hf.tendsto_approx x) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ theorem separableSpace_range_union_singleton {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (hf : StronglyMeasurable f) {b : β} : SeparableSpace (range f ∪ {b} : Set β) := letI := pseudoMetrizableSpacePseudoMetric β (hf.isSeparable_range.union (finite_singleton _).isSeparable).separableSpace section SecondCountableStronglyMeasurable variable {mα : MeasurableSpace α} [MeasurableSpace β] /-- In a space with second countable topology, measurable implies strongly measurable. -/ @[aesop 90% apply (rule_sets := [Measurable])] theorem _root_.Measurable.stronglyMeasurable [TopologicalSpace β] [PseudoMetrizableSpace β] [SecondCountableTopology β] [OpensMeasurableSpace β] (hf : Measurable f) : StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric β nontriviality β; inhabit β exact ⟨SimpleFunc.approxOn f hf Set.univ default (Set.mem_univ _), fun x ↦ SimpleFunc.tendsto_approxOn hf (Set.mem_univ _) (by rw [closure_univ]; simp)⟩ /-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/ theorem _root_.stronglyMeasurable_iff_measurable [TopologicalSpace β] [MetrizableSpace β] [BorelSpace β] [SecondCountableTopology β] : StronglyMeasurable f ↔ Measurable f := ⟨fun h => h.measurable, fun h => Measurable.stronglyMeasurable h⟩ @[measurability] theorem _root_.stronglyMeasurable_id [TopologicalSpace α] [PseudoMetrizableSpace α] [OpensMeasurableSpace α] [SecondCountableTopology α] : StronglyMeasurable (id : α → α) := measurable_id.stronglyMeasurable end SecondCountableStronglyMeasurable /-- A function is strongly measurable if and only if it is measurable and has separable range. -/ theorem _root_.stronglyMeasurable_iff_measurable_separable {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] : StronglyMeasurable f ↔ Measurable f ∧ IsSeparable (range f) := by refine ⟨fun H ↦ ⟨H.measurable, H.isSeparable_range⟩, fun ⟨Hm, Hsep⟩ ↦ ?_⟩ have := Hsep.secondCountableTopology have Hm' : StronglyMeasurable (rangeFactorization f) := Hm.subtype_mk.stronglyMeasurable exact continuous_subtype_val.comp_stronglyMeasurable Hm' /-- A continuous function is strongly measurable when either the source space or the target space is second-countable. -/ theorem _root_.Continuous.stronglyMeasurable [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [TopologicalSpace β] [PseudoMetrizableSpace β] [h : SecondCountableTopologyEither α β] {f : α → β} (hf : Continuous f) : StronglyMeasurable f := by borelize β cases h.out · rw [stronglyMeasurable_iff_measurable_separable] refine ⟨hf.measurable, ?_⟩ exact isSeparable_range hf · exact hf.measurable.stronglyMeasurable /-- A continuous function whose support is contained in a compact set is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_mulSupport_subset_isCompact [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) {k : Set α} (hk : IsCompact k) (h'f : mulSupport f ⊆ k) : StronglyMeasurable f := by letI : PseudoMetricSpace β := pseudoMetrizableSpacePseudoMetric β rw [stronglyMeasurable_iff_measurable_separable] exact ⟨hf.measurable, (isCompact_range_of_mulSupport_subset_isCompact hf hk h'f).isSeparable⟩ /-- A continuous function with compact support is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_hasCompactMulSupport [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) (h'f : HasCompactMulSupport f) : StronglyMeasurable f := hf.stronglyMeasurable_of_mulSupport_subset_isCompact h'f (subset_mulTSupport f) /-- A continuous function with compact support on a product space is strongly measurable for the product sigma-algebra. The subtlety is that we do not assume that the spaces are separable, so the product of the Borel sigma algebras might not contain all open sets, but still it contains enough of them to approximate compactly supported continuous functions. -/ lemma _root_.HasCompactSupport.stronglyMeasurable_of_prod {X Y : Type*} [Zero α] [TopologicalSpace X] [TopologicalSpace Y] [MeasurableSpace X] [MeasurableSpace Y] [OpensMeasurableSpace X] [OpensMeasurableSpace Y] [TopologicalSpace α] [PseudoMetrizableSpace α] {f : X × Y → α} (hf : Continuous f) (h'f : HasCompactSupport f) : StronglyMeasurable f := by borelize α apply stronglyMeasurable_iff_measurable_separable.2 ⟨h'f.measurable_of_prod hf, ?_⟩ letI : PseudoMetricSpace α := pseudoMetrizableSpacePseudoMetric α exact IsCompact.isSeparable (s := range f) (h'f.isCompact_range hf) /-- If `g` is a topological embedding, then `f` is strongly measurable iff `g ∘ f` is. -/ theorem _root_.Embedding.comp_stronglyMeasurable_iff {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [TopologicalSpace γ] [PseudoMetrizableSpace γ] {g : β → γ} {f : α → β} (hg : IsEmbedding g) : (StronglyMeasurable fun x => g (f x)) ↔ StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric γ borelize β γ refine ⟨fun H => stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩, fun H => hg.continuous.comp_stronglyMeasurable H⟩ · let G : β → range g := rangeFactorization g have hG : IsClosedEmbedding G := { hg.codRestrict _ _ with isClosed_range := by rw [surjective_onto_range.range_eq] exact isClosed_univ } have : Measurable (G ∘ f) := Measurable.subtype_mk H.measurable exact hG.measurableEmbedding.measurable_comp_iff.1 this · have : IsSeparable (g ⁻¹' range (g ∘ f)) := hg.isSeparable_preimage H.isSeparable_range rwa [range_comp, hg.injective.preimage_image] at this /-- A sequential limit of strongly measurable functions is strongly measurable. -/ theorem _root_.stronglyMeasurable_of_tendsto {ι : Type*} {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (u : Filter ι) [NeBot u] [IsCountablyGenerated u] {f : ι → α → β} {g : α → β} (hf : ∀ i, StronglyMeasurable (f i)) (lim : Tendsto f u (𝓝 g)) : StronglyMeasurable g := by borelize β refine stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩ · exact measurable_of_tendsto_metrizable' u (fun i => (hf i).measurable) lim · rcases u.exists_seq_tendsto with ⟨v, hv⟩ have : IsSeparable (closure (⋃ i, range (f (v i)))) := .closure <| .iUnion fun i => (hf (v i)).isSeparable_range apply this.mono rintro _ ⟨x, rfl⟩ rw [tendsto_pi_nhds] at lim apply mem_closure_of_tendsto ((lim x).comp hv) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ protected theorem piecewise {m : MeasurableSpace α} [TopologicalSpace β] {s : Set α} {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (Set.piecewise s f g) := by refine ⟨fun n => SimpleFunc.piecewise s hs (hf.approx n) (hg.approx n), fun x => ?_⟩ by_cases hx : x ∈ s · simpa [@Set.piecewise_eq_of_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hf.tendsto_approx x · simpa [@Set.piecewise_eq_of_not_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hg.tendsto_approx x /-- this is slightly different from `StronglyMeasurable.piecewise`. It can be used to show `StronglyMeasurable (ite (x=0) 0 1)` by `exact StronglyMeasurable.ite (measurableSet_singleton 0) stronglyMeasurable_const stronglyMeasurable_const`, but replacing `StronglyMeasurable.ite` by `StronglyMeasurable.piecewise` in that example proof does not work. -/ protected theorem ite {_ : MeasurableSpace α} [TopologicalSpace β] {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => ite (p x) (f x) (g x) := StronglyMeasurable.piecewise hp hf hg @[measurability] theorem _root_.MeasurableEmbedding.stronglyMeasurable_extend {f : α → β} {g : α → γ} {g' : γ → β} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hg' : StronglyMeasurable g') : StronglyMeasurable (Function.extend g f g') := by refine ⟨fun n => SimpleFunc.extend (hf.approx n) g hg (hg'.approx n), ?_⟩ intro x by_cases hx : ∃ y, g y = x · rcases hx with ⟨y, rfl⟩ simpa only [SimpleFunc.extend_apply, hg.injective, Injective.extend_apply] using hf.tendsto_approx y · simpa only [hx, SimpleFunc.extend_apply', not_false_iff, extend_apply'] using hg'.tendsto_approx x theorem _root_.MeasurableEmbedding.exists_stronglyMeasurable_extend {f : α → β} {g : α → γ} {_ : MeasurableSpace α} {_ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hne : γ → Nonempty β) : ∃ f' : γ → β, StronglyMeasurable f' ∧ f' ∘ g = f := ⟨Function.extend g f fun x => Classical.choice (hne x), hg.stronglyMeasurable_extend hf (stronglyMeasurable_const' fun _ _ => rfl), funext fun _ => hg.injective.extend_apply _ _ _⟩ theorem _root_.stronglyMeasurable_of_stronglyMeasurable_union_cover {m : MeasurableSpace α} [TopologicalSpace β] {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hc : StronglyMeasurable fun a : s => f a) (hd : StronglyMeasurable fun a : t => f a) : StronglyMeasurable f := by nontriviality β; inhabit β suffices Function.extend Subtype.val (fun x : s ↦ f x) (Function.extend (↑) (fun x : t ↦ f x) fun _ ↦ default) = f from this ▸ (MeasurableEmbedding.subtype_coe hs).stronglyMeasurable_extend hc <| (MeasurableEmbedding.subtype_coe ht).stronglyMeasurable_extend hd stronglyMeasurable_const ext x by_cases hxs : x ∈ s · lift x to s using hxs simp [Subtype.coe_injective.extend_apply] · lift x to t using (h trivial).resolve_left hxs rw [extend_apply', Subtype.coe_injective.extend_apply] exact fun ⟨y, hy⟩ ↦ hxs <| hy ▸ y.2 theorem _root_.stronglyMeasurable_of_restrict_of_restrict_compl {_ : MeasurableSpace α} [TopologicalSpace β] {f : α → β} {s : Set α} (hs : MeasurableSet s) (h₁ : StronglyMeasurable (s.restrict f)) (h₂ : StronglyMeasurable (sᶜ.restrict f)) : StronglyMeasurable f := stronglyMeasurable_of_stronglyMeasurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ @[measurability] protected theorem indicator {_ : MeasurableSpace α} [TopologicalSpace β] [Zero β] (hf : StronglyMeasurable f) {s : Set α} (hs : MeasurableSet s) : StronglyMeasurable (s.indicator f) := hf.piecewise hs stronglyMeasurable_const /-- To prove that a property holds for any strongly measurable function, it is enough to show that it holds for constant indicator functions of measurable sets and that it is closed under addition and pointwise limit. To use in an induction proof, the syntax is `induction f, hf using StronglyMeasurable.induction with`. -/ theorem induction [MeasurableSpace α] [AddZeroClass β] [TopologicalSpace β] {P : (f : α → β) → StronglyMeasurable f → Prop} (ind : ∀ c ⦃s : Set α⦄ (hs : MeasurableSet s), P (s.indicator fun _ ↦ c) (stronglyMeasurable_const.indicator hs)) (add : ∀ ⦃f g : α → β⦄ (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) (hfg : StronglyMeasurable (f + g)), Disjoint f.support g.support → P f hf → P g hg → P (f + g) hfg) (lim : ∀ ⦃f : ℕ → α → β⦄ ⦃g : α → β⦄ (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g), (∀ n, P (f n) (hf n)) → (∀ x, Tendsto (f · x) atTop (𝓝 (g x))) → P g hg) (f : α → β) (hf : StronglyMeasurable f) : P f hf := by let s := hf.approx refine lim (fun n ↦ (s n).stronglyMeasurable) hf (fun n ↦ ?_) hf.tendsto_approx change P (s n) (s n).stronglyMeasurable induction s n using SimpleFunc.induction with | const c hs => exact ind c hs | @add f g h_supp hf hg => exact add f.stronglyMeasurable g.stronglyMeasurable (f + g).stronglyMeasurable h_supp hf hg open scoped Classical in /-- To prove that a property holds for any strongly measurable function, it is enough to show that it holds for constant functions and that it is closed under piecewise combination of functions and pointwise limits. To use in an induction proof, the syntax is `induction f, hf using StronglyMeasurable.induction' with`. -/ theorem induction' [MeasurableSpace α] [Nonempty β] [TopologicalSpace β] {P : (f : α → β) → StronglyMeasurable f → Prop} (const : ∀ (c), P (fun _ ↦ c) stronglyMeasurable_const) (pcw : ∀ ⦃f g : α → β⦄ {s} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) (hs : MeasurableSet s), P f hf → P g hg → P (s.piecewise f g) (hf.piecewise hs hg)) (lim : ∀ ⦃f : ℕ → α → β⦄ ⦃g : α → β⦄ (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g), (∀ n, P (f n) (hf n)) → (∀ x, Tendsto (f · x) atTop (𝓝 (g x))) → P g hg) (f : α → β) (hf : StronglyMeasurable f) : P f hf := by let s := hf.approx refine lim (fun n ↦ (s n).stronglyMeasurable) hf (fun n ↦ ?_) hf.tendsto_approx change P (s n) (s n).stronglyMeasurable induction s n with | const c => exact const c | @pcw f g s hs Pf Pg => simp_rw [SimpleFunc.coe_piecewise] exact pcw f.stronglyMeasurable g.stronglyMeasurable hs Pf Pg @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem dist {_ : MeasurableSpace α} {β : Type*} [PseudoMetricSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => dist (f x) (g x) := continuous_dist.comp_stronglyMeasurable (hf.prodMk hg) @[measurability] protected theorem norm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖ := continuous_norm.comp_stronglyMeasurable hf @[measurability] protected theorem nnnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖₊ := continuous_nnnorm.comp_stronglyMeasurable hf /-- The `enorm` of a strongly measurable function is measurable. Unlike `StrongMeasurable.norm` and `StronglyMeasurable.nnnorm`, this lemma proves measurability, **not** strong measurability. This is an intentional decision: for functions taking values in ℝ≥0∞, measurability is much more useful than strong measurability. -/ @[fun_prop, measurability] protected theorem enorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : Measurable (‖f ·‖ₑ) := (ENNReal.continuous_coe.comp_stronglyMeasurable hf.nnnorm).measurable @[deprecated (since := "2025-01-21")] alias ennnorm := StronglyMeasurable.enorm @[measurability] protected theorem real_toNNReal {_ : MeasurableSpace α} {f : α → ℝ} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => (f x).toNNReal := continuous_real_toNNReal.comp_stronglyMeasurable hf section PseudoMetrizableSpace variable {E : Type*} {m m₀ : MeasurableSpace α} {μ : Measure[m₀] α} {f g : α → E} [TopologicalSpace E] [Preorder E] [OrderClosedTopology E] [PseudoMetrizableSpace E] lemma measurableSet_le (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) : MeasurableSet[m] {a | f a ≤ g a} := by borelize (E × E) exact (hf.prodMk hg).measurable isClosed_le_prod.measurableSet lemma measurableSet_lt (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) : MeasurableSet[m] {a | f a < g a} := by simpa only [lt_iff_le_not_le] using (hf.measurableSet_le hg).inter (hg.measurableSet_le hf).compl lemma ae_le_trim_of_stronglyMeasurable (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) (hfg : f ≤ᵐ[μ] g) : f ≤ᵐ[μ.trim hm] g := by rwa [EventuallyLE, ae_iff, trim_measurableSet_eq hm] exact (hf.measurableSet_le hg).compl lemma ae_le_trim_iff (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) : f ≤ᵐ[μ.trim hm] g ↔ f ≤ᵐ[μ] g := ⟨ae_le_of_ae_le_trim, ae_le_trim_of_stronglyMeasurable hm hf hg⟩ end PseudoMetrizableSpace section MetrizableSpace variable {E : Type*} {m m₀ : MeasurableSpace α} {μ : Measure[m₀] α} {f g : α → E} [TopologicalSpace E] [MetrizableSpace E] lemma measurableSet_eq_fun (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) : MeasurableSet[m] {a | f a = g a} := by borelize (E × E) exact (hf.prodMk hg).measurable isClosed_diagonal.measurableSet lemma ae_eq_trim_of_stronglyMeasurable (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.trim hm] g := by rwa [EventuallyEq, ae_iff, trim_measurableSet_eq hm] exact (hf.measurableSet_eq_fun hg).compl lemma ae_eq_trim_iff (hm : m ≤ m₀) (hf : StronglyMeasurable[m] f) (hg : StronglyMeasurable[m] g) : f =ᵐ[μ.trim hm] g ↔ f =ᵐ[μ] g := ⟨ae_eq_of_ae_eq_trim, ae_eq_trim_of_stronglyMeasurable hm hf hg⟩ end MetrizableSpace theorem stronglyMeasurable_in_set {m : MeasurableSpace α} [TopologicalSpace β] [Zero β] {s : Set α} {f : α → β} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hf_zero : ∀ x, x ∉ s → f x = 0) : ∃ fs : ℕ → α →ₛ β, (∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))) ∧ ∀ x ∉ s, ∀ n, fs n x = 0 := by let g_seq_s : ℕ → @SimpleFunc α m β := fun n => (hf.approx n).restrict s have hg_eq : ∀ x ∈ s, ∀ n, g_seq_s n x = hf.approx n x := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_mem hx] have hg_zero : ∀ x ∉ s, ∀ n, g_seq_s n x = 0 := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_not_mem hx] refine ⟨g_seq_s, fun x => ?_, hg_zero⟩ by_cases hx : x ∈ s · simp_rw [hg_eq x hx] exact hf.tendsto_approx x · simp_rw [hg_zero x hx, hf_zero x hx] exact tendsto_const_nhds /-- 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` supported on `s` is `m`-strongly-measurable, then `f` is also `m₂`-strongly-measurable. -/ theorem stronglyMeasurable_of_measurableSpace_le_on {α E} {m m₂ : MeasurableSpace α} [TopologicalSpace E] [Zero E] {s : Set α} {f : α → E} (hs_m : MeasurableSet[m] s) (hs : ∀ t, MeasurableSet[m] (s ∩ t) → MeasurableSet[m₂] (s ∩ t)) (hf : StronglyMeasurable[m] f) (hf_zero : ∀ x ∉ s, f x = 0) : StronglyMeasurable[m₂] f := by have hs_m₂ : MeasurableSet[m₂] s := by rw [← Set.inter_univ s]
refine hs Set.univ ?_ rwa [Set.inter_univ] obtain ⟨g_seq_s, hg_seq_tendsto, hg_seq_zero⟩ := stronglyMeasurable_in_set hs_m hf hf_zero let g_seq_s₂ : ℕ → @SimpleFunc α m₂ E := fun n => { toFun := g_seq_s n measurableSet_fiber' := fun x => by rw [← Set.inter_univ (g_seq_s n ⁻¹' {x}), ← Set.union_compl_self s, Set.inter_union_distrib_left, Set.inter_comm (g_seq_s n ⁻¹' {x})] refine MeasurableSet.union (hs _ (hs_m.inter ?_)) ?_ · exact @SimpleFunc.measurableSet_fiber _ _ m _ _ by_cases hx : x = 0 · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = sᶜ by rw [this] exact hs_m₂.compl ext1 y rw [hx, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff] exact ⟨fun h => h.2, fun h => ⟨hg_seq_zero y h n, h⟩⟩ · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = ∅ by rw [this] exact MeasurableSet.empty ext1 y simp only [mem_inter_iff, mem_preimage, mem_singleton_iff, mem_compl_iff, mem_empty_iff_false, iff_false, not_and, not_not_mem] refine Function.mtr fun hys => ?_ rw [hg_seq_zero y hys n] exact Ne.symm hx finite_range' := @SimpleFunc.finite_range _ _ m (g_seq_s n) } exact ⟨g_seq_s₂, hg_seq_tendsto⟩ /-- If a function `f` is strongly measurable w.r.t. a sub-σ-algebra `m` and the measure is σ-finite on `m`, then there exists spanning measurable sets with finite measure on which `f` has bounded norm. In particular, `f` is integrable on each of those sets. -/ theorem exists_spanning_measurableSet_norm_le [SeminormedAddCommGroup β] {m m0 : MeasurableSpace α} (hm : m ≤ m0) (hf : StronglyMeasurable[m] f) (μ : Measure α) [SigmaFinite (μ.trim hm)] : ∃ s : ℕ → Set α,
Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean
950
984